diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index e899593125..066d189df7 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -735,12 +735,10 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target) // Do it in such a way that the user sees the Go-button go down. _InvokeButtonVisibly(fURLInputGroup->GoButton()); return; - } - // Lock the URL text control to prevent changes while user is - // typing and set a timer to unlock it after a set period - // of time. - else { - fURLInputGroup->LockURLInput(); + } else if (bytes[0] == B_ESCAPE) { + // Replace edited text with the current URL. + fURLInputGroup->LockURLInput(false); + fURLInputGroup->SetText(CurrentWebView()->MainFrameURL()); } } else if (target == fFindTextControl->TextView()) { // Handle B_RETURN when the find text control has focus. @@ -1314,6 +1312,10 @@ BrowserWindow::SetCurrentWebView(BWebView* webView) } else webView->MakeFocus(true); + bool state = fURLInputGroup->IsURLInputLocked(); + fURLInputGroup->LockURLInput(false); + // Unlock it so the following code can update the URL + if (userData != NULL) { fURLInputGroup->SetPageIcon(userData->PageIcon()); if (userData->URLInputContents().Length()) @@ -1330,6 +1332,9 @@ BrowserWindow::SetCurrentWebView(BWebView* webView) fURLInputGroup->SetText(webView->MainFrameURL()); } + fURLInputGroup->LockURLInput(state); + // Restore the state + // Trigger update of the interface to the new page, by requesting // to resend all notifications. webView->WebPage()->ResendNotifications(); @@ -1474,8 +1479,15 @@ BrowserWindow::CloseWindowRequested(BWebView* view) void BrowserWindow::LoadNegotiating(const BString& url, BWebView* view) { - if (view != CurrentWebView()) - return; + if (view != CurrentWebView()) { + // Update the userData contents instead so the user sees + // the correct URL when they switch back to that tab. + PageUserData* userData = static_cast( + view->GetUserData()); + if (userData != NULL && userData->URLInputContents().Length() == 0) { + userData->SetURLInputContents(url); + } + } fURLInputGroup->SetText(url.String()); @@ -1729,6 +1741,8 @@ void BrowserWindow::UpdateGlobalHistory(const BString& url) { BrowsingHistory::DefaultInstance()->AddItem(BrowsingHistoryItem(url)); + + fURLInputGroup->SetText(CurrentWebView()->MainFrameURL()); } diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index 010637814a..9a0437e9ae 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -151,7 +151,6 @@ public: virtual void MouseDown(BPoint where); virtual void KeyDown(const char* bytes, int32 numBytes); virtual void MakeFocus(bool focused = true); - virtual void SetPreviousText(const char* text); virtual BSize MinSize(); virtual BSize MaxSize(); @@ -170,7 +169,6 @@ private: private: URLInputGroup* fURLInputGroup; TextViewCompleter* fURLAutoCompleter; - BString fPreviousText; bool fUpdateAutoCompleterChoices; }; @@ -181,7 +179,6 @@ URLInputGroup::URLTextView::URLTextView(URLInputGroup* parent) fURLInputGroup(parent), fURLAutoCompleter(new TextViewCompleter(this, new BrowsingHistoryChoiceModel())), - fPreviousText(""), fUpdateAutoCompleterChoices(true) { MakeResizable(true); @@ -285,8 +282,8 @@ URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes) break; case B_ESCAPE: - // Revert to text as it was when we received keyboard focus. - SetText(fPreviousText.String()); + // Text already unlocked && replaced in BrowserWindow, + // now select it. SelectAll(); break; @@ -295,40 +292,37 @@ URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes) break; default: + { + BString currentText = Text(); BTextView::KeyDown(bytes, numBytes); + // Lock the URL input if it was modified + if (!fURLInputGroup->IsURLInputLocked() + && Text() != currentText) + fURLInputGroup->LockURLInput(); break; + } } } void URLInputGroup::URLTextView::MakeFocus(bool focus) { - // Unlock the URL input ahead of time if focus was lost. - if (!focus) { + // Unlock the URL input if focus was lost. + if (!focus) fURLInputGroup->LockURLInput(false); - } if (focus == IsFocus()) return; BTextView::MakeFocus(focus); - if (focus) { - fPreviousText = Text(); + if (focus) SelectAll(); - } fURLInputGroup->Invalidate(); } -void -URLInputGroup::URLTextView::SetPreviousText(const char* text) -{ - fPreviousText = text; -} - - BSize URLInputGroup::URLTextView::MinSize() { @@ -596,7 +590,6 @@ private: URLInputGroup::URLInputGroup(BMessage* goMessage) : BGroupView(B_HORIZONTAL, 0.0), - fURLLockTimeout(NULL), fWindowActive(false), fURLLocked(false) { @@ -629,7 +622,6 @@ URLInputGroup::URLInputGroup(BMessage* goMessage) URLInputGroup::~URLInputGroup() { - delete fURLLockTimeout; } @@ -683,14 +675,9 @@ URLInputGroup::TextView() const void URLInputGroup::SetText(const char* text) { - // Ignore setting the text, if the user edited the URL in the last - // couple of seconds. Instead set the previous text in the text view, - // so if the user presses ESC the input will update to show the new - // text. - if (fURLLocked) { - fTextView->SetPreviousText(text); + // Ignore setting the text, if the input is locked. + if (fURLLocked) return; - } if (!text || !Text() || strcmp(Text(), text) != 0) { fTextView->SetUpdateAutoCompleterChoices(false); @@ -721,37 +708,15 @@ URLInputGroup::SetPageIcon(const BBitmap* icon) } +bool +URLInputGroup::IsURLInputLocked() const +{ + return fURLLocked; +} + + void URLInputGroup::LockURLInput(bool lock) { fURLLocked = lock; - if (lock) { - if (fURLLockTimeout == NULL) { - fURLLockTimeout = new BMessageRunner(this, - new BMessage(MSG_LOCK_TIMEOUT), LOCK_TIMEOUT, 1); - } else { - fURLLockTimeout->SetInterval(LOCK_TIMEOUT); - } - } } - - -void -URLInputGroup::MessageReceived(BMessage* message) -{ - switch (message->what) { - case MSG_LOCK_TIMEOUT: - { - delete fURLLockTimeout; - fURLLockTimeout = NULL; - LockURLInput(false); - break; - } - default: - { - BGroupView(message); - break; - } - } -} - diff --git a/src/apps/webpositive/URLInputGroup.h b/src/apps/webpositive/URLInputGroup.h index 2e5bd72414..21bae63d28 100644 --- a/src/apps/webpositive/URLInputGroup.h +++ b/src/apps/webpositive/URLInputGroup.h @@ -6,18 +6,12 @@ #define URL_INPUT_GROUP_H #include -#include class BButton; class BTextView; class URLInputGroup : public BGroupView { -private: - static const uint32 MSG_LOCK_TIMEOUT = 'loti'; - static const bigtime_t LOCK_TIMEOUT = 1000000; - // Lock will timeout in one second - public: URLInputGroup(BMessage* goMessage); virtual ~URLInputGroup(); @@ -35,14 +29,13 @@ public: void SetPageIcon(const BBitmap* icon); + bool IsURLInputLocked() const; virtual void LockURLInput(bool lock = true); - virtual void MessageReceived(BMessage* message); private: class PageIconView; class URLTextView; - BMessageRunner* fURLLockTimeout; PageIconView* fIconView; URLTextView* fTextView; BButton* fGoButton;