Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1683)

Unified Diff: chrome/renderer/searchbox.cc

Issue 10809063: Adding Javascript support for the Extended Searchbox API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding missing file from last upload. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox.cc
diff --git a/chrome/renderer/searchbox.cc b/chrome/renderer/searchbox.cc
index a662713700c73019f9d535d4aeb35e3a77104c28..4e1084ed9760b83d9954c7b1caf5fd19bf89a262 100644
--- a/chrome/renderer/searchbox.cc
+++ b/chrome/renderer/searchbox.cc
@@ -4,6 +4,7 @@
#include "chrome/renderer/searchbox.h"
+#include "base/utf_string_conversions.h"
sreeram 2012/08/09 22:13:51 We don't need this header, right?
Shishir 2012/08/10 18:16:57 Done.
#include "chrome/common/render_messages.h"
#include "chrome/renderer/searchbox_extension.h"
#include "content/public/renderer/render_view.h"
@@ -14,18 +15,32 @@ SearchBox::SearchBox(content::RenderView* render_view)
content::RenderViewObserverTracker<SearchBox>(render_view),
verbatim_(false),
selection_start_(0),
- selection_end_(0) {
+ selection_end_(0),
+ rid_base_(0),
+ key_code_(0),
+ is_focused_(false) {
}
SearchBox::~SearchBox() {
}
-void SearchBox::SetSuggestions(const std::vector<string16>& suggestions,
- InstantCompleteBehavior behavior) {
+void SearchBox::SetSuggestions(
+ const std::vector<InstantSuggestion>& suggestions) {
+ if (!suggestions.empty() &&
+ suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) {
+ value_ = suggestions[0].text;
+ verbatim_ = true;
+ selection_start_ = selection_end_ = value_.size();
+ }
// Explicitly allow empty vector to be sent to the browser.
render_view()->Send(new ChromeViewHostMsg_SetSuggestions(
- render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions,
- behavior));
+ render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions));
+}
+
+void SearchBox::SetInstantPreviewHeight(int height, InstantSizeUnits units) {
+ render_view()->Send(new ChromeViewHostMsg_SetInstantPreviewHeight(
+ render_view()->GetRoutingID(), render_view()->GetPageId(), height,
+ units));
}
gfx::Rect SearchBox::GetRect() {
@@ -53,6 +68,13 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
OnDetermineIfPageSupportsInstant)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxInstantAutocompleteResults,
+ OnInstantAutocompleteResults)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyPress, OnKeyPress)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxLastQuery, OnLastQuery)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCurrentURL, OnCurrentURL)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocused, OnFocused)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBlurred, OnBlurred)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -111,9 +133,58 @@ void SearchBox::OnDetermineIfPageSupportsInstant() {
}
}
+void SearchBox::OnInstantAutocompleteResults(
+ const std::vector<InstantAutocompleteResult>& results) {
+ rid_base_ += instant_autocomplete_results_.size();
+ instant_autocomplete_results_ = results;
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
+ extensions_v8::SearchBoxExtension::DispatchNativeSuggestions(
+ render_view()->GetWebView()->mainFrame());
+ }
+}
+
+void SearchBox::OnKeyPress(int key_code) {
+ key_code_ = key_code;
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
+ extensions_v8::SearchBoxExtension::DispatchKeyPress(
+ render_view()->GetWebView()->mainFrame());
+ }
+}
+
+void SearchBox::OnLastQuery(const string16& last_query) {
+ last_query_ = last_query;
+}
+
+void SearchBox::OnCurrentURL(const string16& current_url) {
+ current_url_ = current_url;
+}
+
+void SearchBox::OnFocused() {
+ is_focused_ = true;
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
+ extensions_v8::SearchBoxExtension::DispatchFocus(
+ render_view()->GetWebView()->mainFrame());
+ }
+}
+
+void SearchBox::OnBlurred() {
+ is_focused_ = false;
+ if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
+ extensions_v8::SearchBoxExtension::DispatchBlur(
+ render_view()->GetWebView()->mainFrame());
+ }
+}
+
+
void SearchBox::Reset() {
value_.clear();
verbatim_ = false;
selection_start_ = selection_end_ = 0;
+ rid_base_ = 0;
rect_ = gfx::Rect();
+ instant_autocomplete_results_.clear();
+ key_code_ = 0;
+ last_query_.clear();
+ current_url_.clear();
+ is_focused_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698