From 4635cfdcd550912e6f35742c687f2a1661373209 Mon Sep 17 00:00:00 2001
From: Victor <vikkindhart@gmail.com>
Date: Sat, 17 Jun 2017 14:01:52 +0000
Subject: [PATCH] Fixed (again) the way URL locking works.
URL input is considered locked when it is focused and original text was
changed. Pressing ESC will now change URL input's text to the current URL.
---
src/apps/webpositive/BrowserWindow.cpp | 30 ++++++++++----
src/apps/webpositive/URLInputGroup.cpp | 73 +++++++++-------------------------
src/apps/webpositive/URLInputGroup.h | 9 +----
3 files changed, 42 insertions(+), 70 deletions(-)
diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
index e899593..066d189 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. |
… |
… |
BrowserWindow::SetCurrentWebView(BWebView* webView)
|
1314 | 1312 | } else |
1315 | 1313 | webView->MakeFocus(true); |
1316 | 1314 | |
| 1315 | bool state = fURLInputGroup->IsURLInputLocked(); |
| 1316 | fURLInputGroup->LockURLInput(false); |
| 1317 | // Unlock it so the following code can update the URL |
| 1318 | |
1317 | 1319 | if (userData != NULL) { |
1318 | 1320 | fURLInputGroup->SetPageIcon(userData->PageIcon()); |
1319 | 1321 | if (userData->URLInputContents().Length()) |
… |
… |
BrowserWindow::SetCurrentWebView(BWebView* webView)
|
1330 | 1332 | fURLInputGroup->SetText(webView->MainFrameURL()); |
1331 | 1333 | } |
1332 | 1334 | |
| 1335 | fURLInputGroup->LockURLInput(state); |
| 1336 | // Restore the state |
| 1337 | |
1333 | 1338 | // Trigger update of the interface to the new page, by requesting |
1334 | 1339 | // to resend all notifications. |
1335 | 1340 | webView->WebPage()->ResendNotifications(); |
… |
… |
BrowserWindow::CloseWindowRequested(BWebView* view)
|
1474 | 1479 | void |
1475 | 1480 | BrowserWindow::LoadNegotiating(const BString& url, BWebView* view) |
1476 | 1481 | { |
1477 | | if (view != CurrentWebView()) |
1478 | | return; |
| 1482 | if (view != CurrentWebView()) { |
| 1483 | // Update the userData contents instead so the user sees |
| 1484 | // the correct URL when they switch back to that tab. |
| 1485 | PageUserData* userData = static_cast<PageUserData*>( |
| 1486 | view->GetUserData()); |
| 1487 | if (userData != NULL && userData->URLInputContents().Length() == 0) { |
| 1488 | userData->SetURLInputContents(url); |
| 1489 | } |
| 1490 | } |
1479 | 1491 | |
1480 | 1492 | fURLInputGroup->SetText(url.String()); |
1481 | 1493 | |
… |
… |
void
|
1729 | 1741 | BrowserWindow::UpdateGlobalHistory(const BString& url) |
1730 | 1742 | { |
1731 | 1743 | BrowsingHistory::DefaultInstance()->AddItem(BrowsingHistoryItem(url)); |
| 1744 | |
| 1745 | fURLInputGroup->SetText(CurrentWebView()->MainFrameURL()); |
1732 | 1746 | } |
1733 | 1747 | |
1734 | 1748 | |
diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp
index 0106378..9a0437e 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(); |
299 | 302 | break; |
| 303 | } |
300 | 304 | } |
301 | 305 | } |
302 | 306 | |
303 | 307 | void |
304 | 308 | URLInputGroup::URLTextView::MakeFocus(bool focus) |
305 | 309 | { |
306 | | // Unlock the URL input ahead of time if focus was lost. |
307 | | if (!focus) { |
| 310 | // Unlock the URL input if focus was lost. |
| 311 | if (!focus) |
308 | 312 | fURLInputGroup->LockURLInput(false); |
309 | | } |
310 | 313 | |
311 | 314 | if (focus == IsFocus()) |
312 | 315 | return; |
313 | 316 | |
314 | 317 | BTextView::MakeFocus(focus); |
315 | 318 | |
316 | | if (focus) { |
317 | | fPreviousText = Text(); |
| 319 | if (focus) |
318 | 320 | SelectAll(); |
319 | | } |
320 | 321 | |
321 | 322 | fURLInputGroup->Invalidate(); |
322 | 323 | } |
323 | 324 | |
324 | 325 | |
325 | | void |
326 | | URLInputGroup::URLTextView::SetPreviousText(const char* text) |
327 | | { |
328 | | fPreviousText = text; |
329 | | } |
330 | | |
331 | | |
332 | 326 | BSize |
333 | 327 | URLInputGroup::URLTextView::MinSize() |
334 | 328 | { |
… |
… |
private:
|
596 | 590 | URLInputGroup::URLInputGroup(BMessage* goMessage) |
597 | 591 | : |
598 | 592 | BGroupView(B_HORIZONTAL, 0.0), |
599 | | fURLLockTimeout(NULL), |
600 | 593 | fWindowActive(false), |
601 | 594 | fURLLocked(false) |
602 | 595 | { |
… |
… |
URLInputGroup::URLInputGroup(BMessage* goMessage)
|
629 | 622 | |
630 | 623 | URLInputGroup::~URLInputGroup() |
631 | 624 | { |
632 | | delete fURLLockTimeout; |
633 | 625 | } |
634 | 626 | |
635 | 627 | |
… |
… |
URLInputGroup::TextView() const
|
683 | 675 | void |
684 | 676 | URLInputGroup::SetText(const char* text) |
685 | 677 | { |
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); |
| 678 | // Ignore setting the text, if the input is locked. |
| 679 | if (fURLLocked) |
692 | 680 | return; |
693 | | } |
694 | 681 | |
695 | 682 | if (!text || !Text() || strcmp(Text(), text) != 0) { |
696 | 683 | fTextView->SetUpdateAutoCompleterChoices(false); |
… |
… |
URLInputGroup::SetPageIcon(const BBitmap* icon)
|
721 | 708 | } |
722 | 709 | |
723 | 710 | |
724 | | void |
725 | | URLInputGroup::LockURLInput(bool lock) |
| 711 | bool |
| 712 | URLInputGroup::IsURLInputLocked() const |
726 | 713 | { |
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 | | } |
| 714 | return fURLLocked; |
736 | 715 | } |
737 | 716 | |
738 | 717 | |
739 | 718 | void |
740 | | URLInputGroup::MessageReceived(BMessage* message) |
| 719 | URLInputGroup::LockURLInput(bool lock) |
741 | 720 | { |
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 | | } |
| 721 | fURLLocked = lock; |
756 | 722 | } |
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; |