diff options
-rw-r--r-- | chrome/browser/instant/instant_browsertest.cc | 32 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 4 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 22 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 5 | ||||
-rw-r--r-- | chrome/renderer/searchbox_extension.cc | 5 |
8 files changed, 59 insertions, 31 deletions
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 2409068..86c3e52 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -105,8 +105,8 @@ class InstantTest : public InProcessBrowserTest { // When the page loads, the initial searchBox values are set and only a // resize will have been sent. - ASSERT_EQ("true 0 0 0 1 a false a false", - GetSearchStateAsString(preview_)); + ASSERT_EQ("true 0 0 0 1 a false a false 1 1", + GetSearchStateAsString(preview_)); } void SetLocationBarText(const std::wstring& text) { @@ -177,6 +177,8 @@ class InstantTest : public InProcessBrowserTest { // window.beforeLoadSearchBox.verbatim // window.chrome.searchBox.value // window.chrome.searchBox.verbatim + // window.chrome.searchBox.selectionStart + // window.chrome.searchBox.selectionEnd // If determining any of the values fails, the value is 'fail'. std::string GetSearchStateAsString(TabContents* tab_contents) { bool sv = false; @@ -184,6 +186,8 @@ class InstantTest : public InProcessBrowserTest { int oncancelcalls = 0; int onchangecalls = 0; int onresizecalls = 0; + int selection_start = 0; + int selection_end = 0; std::string before_load_value; bool before_load_verbatim = false; std::string value; @@ -207,11 +211,17 @@ class InstantTest : public InProcessBrowserTest { !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value", &value) || !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim", - &verbatim)) { + &verbatim) || + !GetIntFromJavascript(tab_contents, + "window.chrome.searchBox.selectionStart", + &selection_start) || + !GetIntFromJavascript(tab_contents, + "window.chrome.searchBox.selectionEnd", + &selection_end)) { return "fail"; } - return StringPrintf("%s %d %d %d %d %s %s %s %s", + return StringPrintf("%s %d %d %d %d %s %s %s %s %d %d", sv ? "true" : "false", onsubmitcalls, oncancelcalls, @@ -220,7 +230,9 @@ class InstantTest : public InProcessBrowserTest { before_load_value.c_str(), before_load_verbatim ? "true" : "false", value.c_str(), - verbatim ? "true" : "false"); + verbatim ? "true" : "false", + selection_start, + selection_end); } void CheckStringValueFromJavascript( @@ -281,7 +293,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); // Check that the value is reflected and onchange is called. - EXPECT_EQ("true 0 0 1 1 a false abc false", + EXPECT_EQ("true 0 0 1 1 a false abc false 3 3", GetSearchStateAsString(preview_)); } @@ -589,7 +601,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { ASSERT_TRUE(contents); // Check that the value is reflected and onsubmit is called. - EXPECT_EQ("true 1 0 1 1 a false abc true", + EXPECT_EQ("true 1 0 1 1 a false abc true 3 3", GetSearchStateAsString(preview_)); } @@ -613,7 +625,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { ASSERT_TRUE(contents); // Check that the value is reflected and oncancel is called. - EXPECT_EQ("true 0 1 1 1 a false abc false", + EXPECT_EQ("true 0 1 1 1 a false abc false 3 3", GetSearchStateAsString(preview_)); } @@ -638,7 +650,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); - EXPECT_EQ("true 0 0 2 2 a false abcdef false", + EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", GetSearchStateAsString(preview_)); // Pressing tab again to accept the current instant preview. @@ -651,6 +663,6 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { ASSERT_TRUE(contents); // Check that the value is reflected and onsubmit is called. - EXPECT_EQ("true 1 0 2 2 a false abcdef true", + EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6", GetSearchStateAsString(preview_)); } diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 9f73025..d337df5 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -96,8 +96,10 @@ class InstantLoader::FrameLoadObserver : public NotificationObserver { return; } loader_->SendBoundsToPage(true); + // TODO: support real cursor position. + int text_length = static_cast<int>(text_.size()); tab_contents_->render_view_host()->DetermineIfPageSupportsInstant( - text_, verbatim_); + text_, verbatim_, text_length, text_length); break; } default: @@ -478,8 +480,10 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, preview_tab_contents_delegate_->set_user_typed_before_load(); return; } + // TODO: support real cursor position. + int text_length = static_cast<int>(user_text_.size()); preview_contents_->render_view_host()->SearchBoxChange( - user_text_, verbatim, 0, 0); + user_text_, verbatim, text_length, text_length); string16 complete_suggested_text_lower = l10n_util::ToLower( complete_suggested_text_); diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 0e8e226..35a394e 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1784,9 +1784,11 @@ void RenderViewHost::SearchBoxResize(const gfx::Rect& search_box_bounds) { } void RenderViewHost::DetermineIfPageSupportsInstant(const string16& value, - bool verbatim) { - Send(new ViewMsg_DetermineIfPageSupportsInstant(routing_id(), value, - verbatim)); + bool verbatim, + int selection_start, + int selection_end) { + Send(new ViewMsg_DetermineIfPageSupportsInstant( + routing_id(), value, verbatim, selection_start, selection_end)); } void RenderViewHost::FilterURL(ChildProcessSecurityPolicy* policy, diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index a113e1e..4959c847 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -506,7 +506,9 @@ class RenderViewHost : public RenderWidgetHost { void SearchBoxCancel(); void SearchBoxResize(const gfx::Rect& search_box_bounds); void DetermineIfPageSupportsInstant(const string16& value, - bool verbatim); + bool verbatim, + int selection_start, + int selection_end); // Send a notification to the V8 JavaScript engine to change its parameters // while performing stress testing. |cmd| is one of the values defined by diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 2af6911..4759242 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -822,19 +822,21 @@ IPC_MESSAGE_ROUTED0(ViewMsg_Move_ACK) IPC_MESSAGE_ROUTED1(ViewMsg_EnablePreferredSizeChangedMode, int /*flags*/) IPC_MESSAGE_ROUTED4(ViewMsg_SearchBoxChange, - string16 /*value*/, - bool /*verbatim*/, - int /*selection_start*/, - int /*selection_end*/) + string16 /* value */, + bool /* verbatim */, + int /* selection_start */, + int /* selection_end */) IPC_MESSAGE_ROUTED2(ViewMsg_SearchBoxSubmit, - string16 /*value*/, - bool /*verbatim*/) + string16 /* value */, + bool /* verbatim */) IPC_MESSAGE_ROUTED0(ViewMsg_SearchBoxCancel) IPC_MESSAGE_ROUTED1(ViewMsg_SearchBoxResize, - gfx::Rect /*search_box_bounds*/) -IPC_MESSAGE_ROUTED2(ViewMsg_DetermineIfPageSupportsInstant, - string16 /*value*/, - bool /* verbatim */) + gfx::Rect /* search_box_bounds */) +IPC_MESSAGE_ROUTED4(ViewMsg_DetermineIfPageSupportsInstant, + string16 /* value*/, + bool /* verbatim */, + int /* selection_start */, + int /* selection_end */) // Used to tell the renderer not to add scrollbars with height and // width below a threshold. diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 8477565..19fd677 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -4886,9 +4886,13 @@ void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) { } void RenderView::OnDetermineIfPageSupportsInstant(const string16& value, - bool verbatim) { + bool verbatim, + int selection_start, + int selection_end) { search_box_.value = value; search_box_.verbatim = verbatim; + search_box_.selection_start = selection_start; + search_box_.selection_end = selection_end; bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( webview()->mainFrame()); Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result)); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 1d1a8f9..414cff8 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -918,7 +918,10 @@ class RenderView : public RenderWidget, void OnSearchBoxSubmit(const string16& value, bool verbatim); void OnSearchBoxCancel(); void OnSearchBoxResize(const gfx::Rect& bounds); - void OnDetermineIfPageSupportsInstant(const string16& value, bool verbatim); + void OnDetermineIfPageSupportsInstant(const string16& value, + bool verbatim, + int selection_start, + int selection_end); void OnEnableViewSourceMode(); void OnExecuteCode(const ViewMsg_ExecuteCode_Params& params); void OnExecuteEditCommand(const std::string& name, const std::string& value); diff --git a/chrome/renderer/searchbox_extension.cc b/chrome/renderer/searchbox_extension.cc index 2e26864..d58d36f 100644 --- a/chrome/renderer/searchbox_extension.cc +++ b/chrome/renderer/searchbox_extension.cc @@ -73,14 +73,13 @@ static const char kResizeEventName[] = "chrome.searchBox.onresize"; // Script sent as the user is typing and the provider supports instant. // Params: // . the text the user typed. -// TODO: add support for the 3rd param. '46' forces the server to give us -// verbatim results. +// '46' forces the server to give us verbatim results. static const char kUserInputScript[] = "if (window.chrome.userInput)" " window.chrome.userInput(" " window.chrome.searchBox.value," " window.chrome.searchBox.verbatim ? 46 : 0," - " 0);"; + " window.chrome.searchBox.selectionStart);"; // Script sent when the page is committed and the provider supports instant. // Params: |