From 1526be737a797d99f96f8f85500deca19950047b Mon Sep 17 00:00:00 2001 From: leavengood Date: Tue, 28 Dec 2010 03:02:37 +0000 Subject: [PATCH] Add a stupidly simple "search Google from the URL bar" feature, a la Chrome. It still needs a lot but this doesn't seem to break anything and it already is making my browsing more productive. The hard-coding of Google will be fixed when some proper search engine provider handling is added. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@557 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 15 ++++++++++++++- src/apps/webpositive/BrowserWindow.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 7d7d56a0b8..e2db73b96d 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -618,7 +618,10 @@ BrowserWindow::MessageReceived(BMessage* message) if (message->FindString("url", &url) != B_OK) url = fURLInputGroup->Text(); _SetPageIcon(CurrentWebView(), NULL); - CurrentWebView()->LoadURL(url.String()); + BString newUrl = _SmartURLHandler(url); + if (newUrl != url) + fURLInputGroup->TextView()->SetText(newUrl); + CurrentWebView()->LoadURL(newUrl.String()); break; } case GO_BACK: @@ -2090,6 +2093,16 @@ BrowserWindow::_NewTabURL(bool isNewWindow) const } +BString +BrowserWindow::_SmartURLHandler(const BString& url) const +{ + BString result = url; + if (url.FindFirst(".") == B_ERROR || url.FindFirst(" ") != B_ERROR) + result.Prepend("http://www.google.com/#q="); + return result; +} + + void BrowserWindow::_HandlePageSourceResult(const BMessage* message) { diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index e9f5fe3a6f..fcae9d5f7b 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -191,6 +191,7 @@ private: void _InvokeButtonVisibly(BButton* button); BString _NewTabURL(bool isNewWindow) const; + BString _SmartURLHandler(const BString& url) const; void _HandlePageSourceResult( const BMessage* message);