From ff135da9f97f18afc7f199a1823a79d1f5c53a6d Mon Sep 17 00:00:00 2001
From: Wiktor <vikkindhart@gmail.com>
Date: Mon, 12 Jun 2017 01:07:43 +0200
Subject: [PATCH] WebPositive: fixed a lot about how navigation works (+misc).
Changed the way navigation controls are updated, now several functions
call ResendNotifications() in order to correctly display the controls.
Also fixed (again) how URL locking works, removing the need for a timeout,
now URL input is considered locked when it is focused and original text was
changed. Removed fPreviousText from URLInputGroup::URLTextView, as now
pressing ESC will change URL input's text to the current URL. This should
fix a possible problem when URL changes while being edited and pressing ESC
would yield the old URL.
---
src/apps/webpositive/BrowserWindow.cpp | 56 ++++++++++++++++++++-----
src/apps/webpositive/URLInputGroup.cpp | 74 +++++++++-------------------------
src/apps/webpositive/URLInputGroup.h | 9 +----
3 files changed, 66 insertions(+), 73 deletions(-)
diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
index e899593..ca2f169 100644
a
|
b
|
BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)
|
735 | 735 | // Do it in such a way that the user sees the Go-button go down. |
736 | 736 | _InvokeButtonVisibly(fURLInputGroup->GoButton()); |
737 | 737 | return; |
738 | | } |
739 | | // Lock the URL text control to prevent changes while user is |
740 | | // typing and set a timer to unlock it after a set period |
741 | | // of time. |
742 | | else { |
743 | | fURLInputGroup->LockURLInput(); |
| 738 | } else if (bytes[0] == B_ESCAPE) { |
| 739 | // Replace edited text with the current URL. |
| 740 | fURLInputGroup->LockURLInput(false); |
| 741 | fURLInputGroup->SetText(CurrentWebView()->MainFrameURL()); |
744 | 742 | } |
745 | 743 | } else if (target == fFindTextControl->TextView()) { |
746 | 744 | // Handle B_RETURN when the find text control has focus. |
… |
… |
void
|
810 | 808 | BrowserWindow::MessageReceived(BMessage* message) |
811 | 809 | { |
812 | 810 | switch (message->what) { |
| 811 | case LOAD_COMMITTED: |
| 812 | { |
| 813 | fStopButton->SetEnabled(true); |
| 814 | break; |
| 815 | } |
| 816 | case LOAD_DL_COMPLETED: |
| 817 | case LOAD_FAILED: |
| 818 | case LOAD_FINISHED: |
| 819 | { |
| 820 | // Force update of navigation controls and disable the stop button |
| 821 | CurrentWebView()->WebPage()->ResendNotifications(); |
| 822 | // fStopButton->SetEnabled(false); |
| 823 | break; |
| 824 | } |
813 | 825 | case OPEN_LOCATION: |
814 | 826 | _ShowInterface(true); |
815 | 827 | if (fURLInputGroup->TextView()->IsFocus()) |
… |
… |
BrowserWindow::SetCurrentWebView(BWebView* webView)
|
1314 | 1326 | } else |
1315 | 1327 | webView->MakeFocus(true); |
1316 | 1328 | |
| 1329 | bool state = fURLInputGroup->IsURLInputLocked(); |
| 1330 | fURLInputGroup->LockURLInput(false); |
| 1331 | // Unlock it so the following code can update the URL |
| 1332 | |
1317 | 1333 | if (userData != NULL) { |
1318 | 1334 | fURLInputGroup->SetPageIcon(userData->PageIcon()); |
1319 | 1335 | if (userData->URLInputContents().Length()) |
1320 | 1336 | fURLInputGroup->SetText(userData->URLInputContents()); |
1321 | 1337 | else |
1322 | 1338 | fURLInputGroup->SetText(webView->MainFrameURL()); |
| 1339 | |
1323 | 1340 | if (userData->URLInputSelectionStart() >= 0) { |
1324 | 1341 | fURLInputGroup->TextView()->Select( |
1325 | 1342 | userData->URLInputSelectionStart(), |
… |
… |
BrowserWindow::SetCurrentWebView(BWebView* webView)
|
1330 | 1347 | fURLInputGroup->SetText(webView->MainFrameURL()); |
1331 | 1348 | } |
1332 | 1349 | |
| 1350 | fURLInputGroup->LockURLInput(state); |
| 1351 | // Restore the state |
| 1352 | |
1333 | 1353 | // Trigger update of the interface to the new page, by requesting |
1334 | 1354 | // to resend all notifications. |
1335 | 1355 | webView->WebPage()->ResendNotifications(); |
… |
… |
BrowserWindow::CloseWindowRequested(BWebView* view)
|
1474 | 1494 | void |
1475 | 1495 | BrowserWindow::LoadNegotiating(const BString& url, BWebView* view) |
1476 | 1496 | { |
1477 | | if (view != CurrentWebView()) |
| 1497 | if (view != CurrentWebView()) { |
| 1498 | // Update the userData contents instead so the user sees |
| 1499 | // the correct URL when they switch back to that tab. |
| 1500 | PageUserData* userData = static_cast<PageUserData*>( |
| 1501 | view->GetUserData()); |
| 1502 | if (userData != NULL) { |
| 1503 | if (userData->URLInputContents().Length() == 0) |
| 1504 | userData->SetURLInputContents(url); |
| 1505 | } |
1478 | 1506 | return; |
| 1507 | } |
1479 | 1508 | |
1480 | 1509 | fURLInputGroup->SetText(url.String()); |
1481 | 1510 | |
… |
… |
BrowserWindow::LoadProgress(float progress, BWebView* view)
|
1508 | 1537 | |
1509 | 1538 | if (progress < 100 && fLoadingProgressBar->IsHidden()) |
1510 | 1539 | _ShowProgressBar(true); |
1511 | | else if (progress == 100 && !fLoadingProgressBar->IsHidden()) |
1512 | | _ShowProgressBar(false); |
| 1540 | else if (progress == 100) { |
| 1541 | fStopButton->SetEnabled(false); |
| 1542 | if (!fLoadingProgressBar->IsHidden()) |
| 1543 | _ShowProgressBar(false); |
| 1544 | } |
1513 | 1545 | fLoadingProgressBar->SetTo(progress); |
1514 | 1546 | } |
1515 | 1547 | |
… |
… |
BrowserWindow::LoadFinished(const BString& url, BWebView* view)
|
1535 | 1567 | if (view != CurrentWebView()) |
1536 | 1568 | return; |
1537 | 1569 | |
1538 | | fURLInputGroup->SetText(url.String()); |
1539 | | |
1540 | 1570 | BString status(B_TRANSLATE_COMMENT("%url finished", "Loading URL " |
1541 | 1571 | "finished. Don't translate variable %url.")); |
1542 | 1572 | status.ReplaceFirst("%url", url); |
… |
… |
void
|
1729 | 1759 | BrowserWindow::UpdateGlobalHistory(const BString& url) |
1730 | 1760 | { |
1731 | 1761 | BrowsingHistory::DefaultInstance()->AddItem(BrowsingHistoryItem(url)); |
| 1762 | CurrentWebView()->WebPage()->ResendNotifications(); |
| 1763 | // Update the navigation controls |
| 1764 | |
| 1765 | fURLInputGroup->SetText(CurrentWebView()->MainFrameURL()); |
1732 | 1766 | } |
1733 | 1767 | |
1734 | 1768 | |
diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp
index 0106378..cdc0ab2 100644
a
|
b
|
public:
|
151 | 151 | virtual void MouseDown(BPoint where); |
152 | 152 | virtual void KeyDown(const char* bytes, int32 numBytes); |
153 | 153 | virtual void MakeFocus(bool focused = true); |
154 | | virtual void SetPreviousText(const char* text); |
155 | 154 | |
156 | 155 | virtual BSize MinSize(); |
157 | 156 | virtual BSize MaxSize(); |
… |
… |
private:
|
170 | 169 | private: |
171 | 170 | URLInputGroup* fURLInputGroup; |
172 | 171 | TextViewCompleter* fURLAutoCompleter; |
173 | | BString fPreviousText; |
174 | 172 | bool fUpdateAutoCompleterChoices; |
175 | 173 | }; |
176 | 174 | |
… |
… |
URLInputGroup::URLTextView::URLTextView(URLInputGroup* parent)
|
181 | 179 | fURLInputGroup(parent), |
182 | 180 | fURLAutoCompleter(new TextViewCompleter(this, |
183 | 181 | new BrowsingHistoryChoiceModel())), |
184 | | fPreviousText(""), |
185 | 182 | fUpdateAutoCompleterChoices(true) |
186 | 183 | { |
187 | 184 | MakeResizable(true); |
… |
… |
URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes)
|
285 | 282 | break; |
286 | 283 | |
287 | 284 | case B_ESCAPE: |
288 | | // Revert to text as it was when we received keyboard focus. |
289 | | SetText(fPreviousText.String()); |
| 285 | // Text already unlocked && replaced in BrowserWindow, |
| 286 | // now select it. |
290 | 287 | SelectAll(); |
291 | 288 | break; |
292 | 289 | |
… |
… |
URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes)
|
295 | 292 | break; |
296 | 293 | |
297 | 294 | default: |
| 295 | { |
| 296 | BString currentText = Text(); |
298 | 297 | BTextView::KeyDown(bytes, numBytes); |
| 298 | // Lock the URL input if it was modified |
| 299 | if (!fURLInputGroup->IsURLInputLocked() |
| 300 | && Text() != currentText) { |
| 301 | fURLInputGroup->LockURLInput(); |
| 302 | } |
299 | 303 | break; |
| 304 | } |
300 | 305 | } |
301 | 306 | } |
302 | 307 | |
303 | 308 | void |
304 | 309 | URLInputGroup::URLTextView::MakeFocus(bool focus) |
305 | 310 | { |
306 | | // Unlock the URL input ahead of time if focus was lost. |
307 | | if (!focus) { |
| 311 | // Unlock the URL input if focus was lost. |
| 312 | if (!focus) |
308 | 313 | fURLInputGroup->LockURLInput(false); |
309 | | } |
310 | 314 | |
311 | 315 | if (focus == IsFocus()) |
312 | 316 | return; |
313 | 317 | |
314 | 318 | BTextView::MakeFocus(focus); |
315 | 319 | |
316 | | if (focus) { |
317 | | fPreviousText = Text(); |
| 320 | if (focus) |
318 | 321 | SelectAll(); |
319 | | } |
320 | 322 | |
321 | 323 | fURLInputGroup->Invalidate(); |
322 | 324 | } |
323 | 325 | |
324 | 326 | |
325 | | void |
326 | | URLInputGroup::URLTextView::SetPreviousText(const char* text) |
327 | | { |
328 | | fPreviousText = text; |
329 | | } |
330 | | |
331 | | |
332 | 327 | BSize |
333 | 328 | URLInputGroup::URLTextView::MinSize() |
334 | 329 | { |
… |
… |
private:
|
596 | 591 | URLInputGroup::URLInputGroup(BMessage* goMessage) |
597 | 592 | : |
598 | 593 | BGroupView(B_HORIZONTAL, 0.0), |
599 | | fURLLockTimeout(NULL), |
600 | 594 | fWindowActive(false), |
601 | 595 | fURLLocked(false) |
602 | 596 | { |
… |
… |
URLInputGroup::URLInputGroup(BMessage* goMessage)
|
629 | 623 | |
630 | 624 | URLInputGroup::~URLInputGroup() |
631 | 625 | { |
632 | | delete fURLLockTimeout; |
633 | 626 | } |
634 | 627 | |
635 | 628 | |
… |
… |
URLInputGroup::TextView() const
|
683 | 676 | void |
684 | 677 | URLInputGroup::SetText(const char* text) |
685 | 678 | { |
686 | | // Ignore setting the text, if the user edited the URL in the last |
687 | | // couple of seconds. Instead set the previous text in the text view, |
688 | | // so if the user presses ESC the input will update to show the new |
689 | | // text. |
690 | | if (fURLLocked) { |
691 | | fTextView->SetPreviousText(text); |
| 679 | // Ignore setting the text, if the input is locked. |
| 680 | if (fURLLocked) |
692 | 681 | return; |
693 | | } |
694 | 682 | |
695 | 683 | if (!text || !Text() || strcmp(Text(), text) != 0) { |
696 | 684 | fTextView->SetUpdateAutoCompleterChoices(false); |
… |
… |
URLInputGroup::SetPageIcon(const BBitmap* icon)
|
721 | 709 | } |
722 | 710 | |
723 | 711 | |
724 | | void |
725 | | URLInputGroup::LockURLInput(bool lock) |
| 712 | bool |
| 713 | URLInputGroup::IsURLInputLocked() const |
726 | 714 | { |
727 | | fURLLocked = lock; |
728 | | if (lock) { |
729 | | if (fURLLockTimeout == NULL) { |
730 | | fURLLockTimeout = new BMessageRunner(this, |
731 | | new BMessage(MSG_LOCK_TIMEOUT), LOCK_TIMEOUT, 1); |
732 | | } else { |
733 | | fURLLockTimeout->SetInterval(LOCK_TIMEOUT); |
734 | | } |
735 | | } |
| 715 | return fURLLocked; |
736 | 716 | } |
737 | 717 | |
738 | 718 | |
739 | 719 | void |
740 | | URLInputGroup::MessageReceived(BMessage* message) |
| 720 | URLInputGroup::LockURLInput(bool lock) |
741 | 721 | { |
742 | | switch (message->what) { |
743 | | case MSG_LOCK_TIMEOUT: |
744 | | { |
745 | | delete fURLLockTimeout; |
746 | | fURLLockTimeout = NULL; |
747 | | LockURLInput(false); |
748 | | break; |
749 | | } |
750 | | default: |
751 | | { |
752 | | BGroupView(message); |
753 | | break; |
754 | | } |
755 | | } |
| 722 | fURLLocked = lock; |
756 | 723 | } |
757 | | |
diff --git a/src/apps/webpositive/URLInputGroup.h b/src/apps/webpositive/URLInputGroup.h
index 2e5bd72..21bae63 100644
a
|
b
|
|
6 | 6 | #define URL_INPUT_GROUP_H |
7 | 7 | |
8 | 8 | #include <GroupView.h> |
9 | | #include <MessageRunner.h> |
10 | 9 | |
11 | 10 | class BButton; |
12 | 11 | class BTextView; |
13 | 12 | |
14 | 13 | |
15 | 14 | class URLInputGroup : public BGroupView { |
16 | | private: |
17 | | static const uint32 MSG_LOCK_TIMEOUT = 'loti'; |
18 | | static const bigtime_t LOCK_TIMEOUT = 1000000; |
19 | | // Lock will timeout in one second |
20 | | |
21 | 15 | public: |
22 | 16 | URLInputGroup(BMessage* goMessage); |
23 | 17 | virtual ~URLInputGroup(); |
… |
… |
public:
|
35 | 29 | |
36 | 30 | void SetPageIcon(const BBitmap* icon); |
37 | 31 | |
| 32 | bool IsURLInputLocked() const; |
38 | 33 | virtual void LockURLInput(bool lock = true); |
39 | | virtual void MessageReceived(BMessage* message); |
40 | 34 | |
41 | 35 | private: |
42 | 36 | class PageIconView; |
43 | 37 | class URLTextView; |
44 | 38 | |
45 | | BMessageRunner* fURLLockTimeout; |
46 | 39 | PageIconView* fIconView; |
47 | 40 | URLTextView* fTextView; |
48 | 41 | BButton* fGoButton; |