From 1cba0fd63a2a0442a6e41d15e2c2a24aa49c3e17 Mon Sep 17 00:00:00 2001 From: stippi Date: Sat, 27 Feb 2010 11:01:36 +0000 Subject: [PATCH] * Use the proper channels for reloading. (Added BWebView/BWebPage::Reload().) * Catch B_RETURN key down messages, when the target is the URL text view. Don't let the text view send a message, but react on B_RETURN only, in the window, also letting the Go button flash for a bonus. This fixes unprovoked (re-)loading of pages when the text control went out of focus and thought the text had changed, sending GOTO_URL. This could happen when just grabbing the scrollbar so that the text control looses focus. Also makes the m_loadedURL string superfluous, which I added for the same purpose. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@232 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/LauncherWindow.cpp | 42 ++++++++++++++++++------- src/apps/webpositive/LauncherWindow.h | 3 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/apps/webpositive/LauncherWindow.cpp b/src/apps/webpositive/LauncherWindow.cpp index d3589820c3..d2c77647ae 100644 --- a/src/apps/webpositive/LauncherWindow.cpp +++ b/src/apps/webpositive/LauncherWindow.cpp @@ -151,11 +151,11 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener, m_StopButton->TrimIcon(); // URL - m_url = new BTextControl("url", "", "", new BMessage(GOTO_URL)); + m_url = new BTextControl("url", "", "", NULL); m_url->SetDivider(50.0); // Go - BButton* button = new BButton("", "Go", new BMessage(RELOAD)); + m_goButton = new BButton("", "Go", new BMessage(GOTO_URL)); // Status Bar m_statusText = new BStringView("status", ""); @@ -201,7 +201,7 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener, .Add(m_ForwardButton, 1, 0) .Add(m_StopButton, 2, 0) .Add(m_url, 3, 0) - .Add(button, 4, 0) + .Add(m_goButton, 4, 0) .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) ) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) @@ -223,6 +223,8 @@ LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener, } else { m_BackButton = 0; m_ForwardButton = 0; + m_StopButton = 0; + m_goButton = 0; m_url = 0; m_menuBar = 0; m_statusText = 0; @@ -253,6 +255,27 @@ LauncherWindow::~LauncherWindow() { } +void LauncherWindow::DispatchMessage(BMessage* message, BHandler* target) +{ + if (m_url && message->what == B_KEY_DOWN && target == m_url->TextView()) { + // Handle B_RETURN in the URL text control. This is the easiest + // way to react *only* when the user presses the return key in the + // address bar, as opposed to trying to load whatever is in there when + // the text control just goes out of focus. + const char* bytes; + if (message->FindString("bytes", &bytes) == B_OK + && bytes[0] == B_RETURN) { + // Do it in such a way that the user sees the Go-button go down. + m_goButton->SetValue(B_CONTROL_ON); + UpdateIfNeeded(); + m_goButton->Invoke(); + snooze(1000); + m_goButton->SetValue(B_CONTROL_OFF); + } + } + BWebWindow::DispatchMessage(message, target); +} + void LauncherWindow::MessageReceived(BMessage* message) { switch (message->what) { @@ -265,13 +288,13 @@ void LauncherWindow::MessageReceived(BMessage* message) } break; case RELOAD: - CurrentWebView()->LoadURL(m_url->Text()); + CurrentWebView()->Reload(); break; case GOTO_URL: { - BString url = m_url->Text(); - message->FindString("url", &url); - if (m_loadedURL != url) - CurrentWebView()->LoadURL(url.String()); + BString url; + if (message->FindString("url", &url) != B_OK) + url = m_url->Text(); + CurrentWebView()->LoadURL(url.String()); break; } case GO_BACK: @@ -502,8 +525,6 @@ void LauncherWindow::LoadCommitted(const BString& url, BWebView* view) if (view != CurrentWebView()) return; - m_loadedURL = url; - // This hook is invoked when the load is commited. if (m_url) m_url->SetText(url.String()); @@ -542,7 +563,6 @@ void LauncherWindow::LoadFinished(const BString& url, BWebView* view) if (view != CurrentWebView()) return; - m_loadedURL = url; BString status(url); status << " finished."; StatusChanged(status, view); diff --git a/src/apps/webpositive/LauncherWindow.h b/src/apps/webpositive/LauncherWindow.h index e06837b48f..192d42786a 100644 --- a/src/apps/webpositive/LauncherWindow.h +++ b/src/apps/webpositive/LauncherWindow.h @@ -64,6 +64,7 @@ public: ToolbarPolicy = HaveToolbar); virtual ~LauncherWindow(); + virtual void DispatchMessage(BMessage* message, BHandler* target); virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); virtual void MenusBeginning(); @@ -102,8 +103,8 @@ private: IconButton* m_BackButton; IconButton* m_ForwardButton; IconButton* m_StopButton; + BButton* m_goButton; BTextControl* m_url; - BString m_loadedURL; BStringView* m_statusText; BStatusBar* m_loadingProgressBar; BLayoutItem* m_findGroup;