diff options
author | samarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 00:46:26 +0000 |
---|---|---|
committer | samarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 00:46:26 +0000 |
commit | 0d0b4a4e77be5bcd40895f814241a1ea233f1a22 (patch) | |
tree | 9af16b951ba4b9a9b2cd72c9e1b43c0e61989f57 /chrome | |
parent | 41bb06f20858e038aa9fa02be5de415b757bc113 (diff) | |
download | chromium_src-0d0b4a4e77be5bcd40895f814241a1ea233f1a22.zip chromium_src-0d0b4a4e77be5bcd40895f814241a1ea233f1a22.tar.gz chromium_src-0d0b4a4e77be5bcd40895f814241a1ea233f1a22.tar.bz2 |
InstantExtended: notify Instant NTP when user input starts and ends.
BUG=248164
R=jered@chromium.org, palmer@chromium.org
Review URL: https://codereview.chromium.org/15951013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/resources/local_ntp/local_ntp.js | 2 | ||||
-rw-r--r-- | chrome/browser/ui/browser_instant_controller.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_controller.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_controller.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_page.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_page.h | 3 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 3 | ||||
-rw-r--r-- | chrome/renderer/resources/extensions/searchbox_api.js | 4 | ||||
-rw-r--r-- | chrome/renderer/searchbox/searchbox.cc | 27 | ||||
-rw-r--r-- | chrome/renderer/searchbox/searchbox.h | 3 | ||||
-rw-r--r-- | chrome/renderer/searchbox/searchbox_extension.cc | 50 | ||||
-rw-r--r-- | chrome/renderer/searchbox/searchbox_extension.h | 2 |
12 files changed, 122 insertions, 6 deletions
diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js index d1ddebe..cd7c7bb 100644 --- a/chrome/browser/resources/local_ntp/local_ntp.js +++ b/chrome/browser/resources/local_ntp/local_ntp.js @@ -203,7 +203,7 @@ var ntpApiHandle; * The state of the NTP when a query is entered into the Omnibox. * @type {NTP_DISPOSE_STATE} */ -var omniboxInputBehavior = NTP_DISPOSE_STATE.HIDE_FAKEBOX_AND_LOGO; +var omniboxInputBehavior = NTP_DISPOSE_STATE.NONE; /** diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index cacd42f..008753e 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -211,6 +211,14 @@ void BrowserInstantController::FocusOmnibox(bool caret_visibility) { GetLocationEntry(); omnibox_view->SetFocus(); omnibox_view->model()->SetCaretVisibility(caret_visibility); + if (!caret_visibility) { + // If the user clicked on the fakebox, any text already in the omnibox + // should get cleared when they start typing. Selecting all the existing + // text is a convenient way to accomplish this. It also gives a slight + // visual cue to users who really understand selection state about what will + // happen if they start typing. + omnibox_view->SelectAll(false); + } } content::WebContents* BrowserInstantController::GetActiveWebContents() const { diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index 9a3e084..f4ba1a4 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -976,8 +976,11 @@ void InstantController::OmniboxFocusChanged( if (extended_enabled()) { if (overlay_) overlay_->FocusChanged(omnibox_focus_state_, reason); - if (instant_tab_) + + if (instant_tab_) { instant_tab_->FocusChanged(omnibox_focus_state_, reason); + instant_tab_->SetInputInProgress(IsInputInProgress()); + } } if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) { @@ -1008,6 +1011,10 @@ void InstantController::SearchModeChanged(const SearchMode& old_mode, HideOverlay(); ResetInstantTab(); + + if (instant_tab_ && + old_mode.is_search_suggestions() != new_mode.is_search_suggestions()) + instant_tab_->SetInputInProgress(IsInputInProgress()); } void InstantController::ActiveTabChanged() { @@ -1655,9 +1662,15 @@ void InstantController::UpdateInfoForInstantTab() { UpdateMostVisitedItems(); instant_tab_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_); + instant_tab_->SetInputInProgress(IsInputInProgress()); } } +bool InstantController::IsInputInProgress() const { + return search_mode_.is_search_suggestions() && + omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE; +} + void InstantController::HideOverlay() { HideInternal(); ReloadOverlayIfStale(); diff --git a/chrome/browser/ui/search/instant_controller.h b/chrome/browser/ui/search/instant_controller.h index fe4cd93..cdb170b 100644 --- a/chrome/browser/ui/search/instant_controller.h +++ b/chrome/browser/ui/search/instant_controller.h @@ -402,6 +402,10 @@ class InstantController : public InstantPage::Delegate { // Sends theme info, omnibox bounds, font info, etc. down to the Instant tab. void UpdateInfoForInstantTab(); + // Returns whether input is in progress, i.e. if the omnibox has focus and the + // active tab is in mode SEARCH_SUGGESTIONS. + bool IsInputInProgress() const; + // Hide the overlay. Also sends an onchange event (with blank query) to the // overlay, telling it to clear out results for any old queries. void HideOverlay(); @@ -417,8 +421,6 @@ class InstantController : public InstantPage::Delegate { // Send the omnibox popup bounds to the page. void SendPopupBoundsToPage(); - - // If possible, tries to mutate |suggestion| to a valid suggestion. Returns // true if successful. (Note that |suggestion| may be modified even if this // returns false.) diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc index 3fe82ba..8568d2e 100644 --- a/chrome/browser/ui/search/instant_page.cc +++ b/chrome/browser/ui/search/instant_page.cc @@ -117,6 +117,11 @@ void InstantPage::FocusChanged(OmniboxFocusState state, Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); } +void InstantPage::SetInputInProgress(bool input_in_progress) { + Send(new ChromeViewMsg_SearchBoxSetInputInProgress( + routing_id(), input_in_progress)); +} + void InstantPage::SendMostVisitedItems( const std::vector<InstantMostVisitedItem>& items) { Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); diff --git a/chrome/browser/ui/search/instant_page.h b/chrome/browser/ui/search/instant_page.h index 53a3243..5bb3045 100644 --- a/chrome/browser/ui/search/instant_page.h +++ b/chrome/browser/ui/search/instant_page.h @@ -191,6 +191,9 @@ class InstantPage : public content::WebContentsObserver { // Tells the page that the omnibox focus has changed. void FocusChanged(OmniboxFocusState state, OmniboxFocusChangeReason reason); + // Tells the page that user input started or stopped. + void SetInputInProgress(bool input_in_progress); + // Tells the page about new Most Visited data. void SendMostVisitedItems( const std::vector<InstantMostVisitedItem>& items); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index a5bbb06..bb29864 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -368,6 +368,9 @@ IPC_MESSAGE_ROUTED2(ChromeViewMsg_SearchBoxFocusChanged, OmniboxFocusState /* new_focus_state */, OmniboxFocusChangeReason /* reason */) +IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxSetInputInProgress, + bool /* input_in_progress */) + IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, std::vector<InstantMostVisitedItem> /* items */) diff --git a/chrome/renderer/resources/extensions/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox_api.js index c17ae98..8a21d03 100644 --- a/chrome/renderer/resources/extensions/searchbox_api.js +++ b/chrome/renderer/resources/extensions/searchbox_api.js @@ -253,6 +253,7 @@ if (!chrome.embeddedSearch) { native function UndoAllMostVisitedDeletions(); native function UndoMostVisitedDeletion(); native function NavigateNewTabPage(); + native function IsInputInProgress(); function GetMostVisitedItemsWrapper() { var mostVisitedItems = GetMostVisitedItems(); @@ -272,6 +273,7 @@ if (!chrome.embeddedSearch) { // ======================================================================= this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper); this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo); + this.__defineGetter__('isInputInProgress', IsInputInProgress); this.deleteMostVisitedItem = function(restrictedId) { DeleteMostVisitedItem(restrictedId); @@ -288,6 +290,8 @@ if (!chrome.embeddedSearch) { this.onmostvisitedchange = null; this.onthemechange = null; + this.oninputstart = null; + this.oninputcancel = null; }; // Export legacy searchbox API. diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc index 0416889..a33edfb 100644 --- a/chrome/renderer/searchbox/searchbox.cc +++ b/chrome/renderer/searchbox/searchbox.cc @@ -70,6 +70,7 @@ SearchBox::SearchBox(content::RenderView* render_view) start_margin_(0), is_focused_(false), is_key_capture_enabled_(false), + is_input_in_progress_(false), display_instant_results_(false), omnibox_font_size_(0), autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), @@ -242,6 +243,8 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, OnSetDisplayInstantResults) IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) + IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetInputInProgress, + OnSetInputInProgress) IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, OnThemeChanged) IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, @@ -415,8 +418,28 @@ void SearchBox::OnFocusChanged(OmniboxFocusState new_focus_state, if (is_focused != is_focused_) { is_focused_ = is_focused; DVLOG(1) << render_view() << " OnFocusChange"; - extensions_v8::SearchBoxExtension::DispatchFocusChange( - render_view()->GetWebView()->mainFrame()); + if (render_view()->GetWebView() && + render_view()->GetWebView()->mainFrame()) { + extensions_v8::SearchBoxExtension::DispatchFocusChange( + render_view()->GetWebView()->mainFrame()); + } + } +} + +void SearchBox::OnSetInputInProgress(bool is_input_in_progress) { + if (is_input_in_progress_ != is_input_in_progress) { + is_input_in_progress_ = is_input_in_progress; + DVLOG(1) << render_view() << " OnSetInputInProgress"; + if (render_view()->GetWebView() && + render_view()->GetWebView()->mainFrame()) { + if (is_input_in_progress_) { + extensions_v8::SearchBoxExtension::DispatchInputStart( + render_view()->GetWebView()->mainFrame()); + } else { + extensions_v8::SearchBoxExtension::DispatchInputCancel( + render_view()->GetWebView()->mainFrame()); + } + } } } diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h index e1383e8..0a45a05 100644 --- a/chrome/renderer/searchbox/searchbox.h +++ b/chrome/renderer/searchbox/searchbox.h @@ -69,6 +69,7 @@ class SearchBox : public content::RenderViewObserver, size_t selection_end() const { return selection_end_; } bool is_focused() const { return is_focused_; } bool is_key_capture_enabled() const { return is_key_capture_enabled_; } + bool is_input_in_progress() const { return is_input_in_progress_; } bool display_instant_results() const { return display_instant_results_; } const string16& omnibox_font() const { return omnibox_font_; } size_t omnibox_font_size() const { return omnibox_font_size_; } @@ -158,6 +159,7 @@ class SearchBox : public content::RenderViewObserver, size_t selection_end); void OnFocusChanged(OmniboxFocusState new_focus_state, OmniboxFocusChangeReason reason); + void OnSetInputInProgress(bool input_in_progress); void OnSetDisplayInstantResults(bool display_instant_results); void OnThemeChanged(const ThemeBackgroundInfo& theme_info); void OnThemeAreaHeightChanged(int height); @@ -188,6 +190,7 @@ class SearchBox : public content::RenderViewObserver, gfx::Rect popup_bounds_; bool is_focused_; bool is_key_capture_enabled_; + bool is_input_in_progress_; ThemeBackgroundInfo theme_info_; bool display_instant_results_; string16 omnibox_font_; diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc index 5458a35..4a73002 100644 --- a/chrome/renderer/searchbox/searchbox_extension.cc +++ b/chrome/renderer/searchbox/searchbox_extension.cc @@ -458,6 +458,28 @@ static const char kDispatchFocusChangedScript[] = " true;" "}"; +static const char kDispatchInputStartScript[] = + "if (window.chrome &&" + " window.chrome.embeddedSearch &&" + " window.chrome.embeddedSearch.newTabPage &&" + " window.chrome.embeddedSearch.newTabPage.oninputstart &&" + " typeof window.chrome.embeddedSearch.newTabPage.oninputstart ==" + " 'function') {" + " window.chrome.embeddedSearch.newTabPage.oninputstart();" + " true;" + "}"; + +static const char kDispatchInputCancelScript[] = + "if (window.chrome &&" + " window.chrome.embeddedSearch &&" + " window.chrome.embeddedSearch.newTabPage &&" + " window.chrome.embeddedSearch.newTabPage.oninputcancel &&" + " typeof window.chrome.embeddedSearch.newTabPage.oninputcancel ==" + " 'function') {" + " window.chrome.embeddedSearch.newTabPage.oninputcancel();" + " true;" + "}"; + static const char kDispatchToggleVoiceSearchScript[] = "if (window.chrome &&" " window.chrome.embeddedSearch &&" @@ -624,6 +646,10 @@ class SearchBoxExtensionWrapper : public v8::Extension { // Gets whether the omnibox has focus or not. static void IsFocused(const v8::FunctionCallbackInfo<v8::Value>& args); + // Gets whether user input is in progress. + static void IsInputInProgress( + const v8::FunctionCallbackInfo<v8::Value>& args); + private: DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); }; @@ -709,6 +735,8 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( return v8::FunctionTemplate::New(GetMostVisitedItemData); if (name->Equals(v8::String::New("IsFocused"))) return v8::FunctionTemplate::New(IsFocused); + if (name->Equals(v8::String::New("IsInputInProgress"))) + return v8::FunctionTemplate::New(IsInputInProgress); return v8::Handle<v8::FunctionTemplate>(); } @@ -1425,6 +1453,18 @@ void SearchBoxExtensionWrapper::IsFocused( } // static +void SearchBoxExtensionWrapper::IsInputInProgress( + const v8::FunctionCallbackInfo<v8::Value>& args) { + content::RenderView* render_view = GetRenderView(); + if (!render_view) return; + + bool is_input_in_progress = + SearchBox::Get(render_view)->is_input_in_progress(); + DVLOG(1) << render_view << " IsInputInProgress: " << is_input_in_progress; + args.GetReturnValue().Set(is_input_in_progress); +} + +// static void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { Dispatch(frame, kDispatchChangeEventScript); } @@ -1495,6 +1535,16 @@ void SearchBoxExtension::DispatchFocusChange(WebKit::WebFrame* frame) { } // static +void SearchBoxExtension::DispatchInputStart(WebKit::WebFrame* frame) { + Dispatch(frame, kDispatchInputStartScript); +} + +// static +void SearchBoxExtension::DispatchInputCancel(WebKit::WebFrame* frame) { + Dispatch(frame, kDispatchInputCancelScript); +} + +// static void SearchBoxExtension::DispatchToggleVoiceSearch( WebKit::WebFrame* frame) { Dispatch(frame, kDispatchToggleVoiceSearchScript); diff --git a/chrome/renderer/searchbox/searchbox_extension.h b/chrome/renderer/searchbox/searchbox_extension.h index 45adc92..c58ea77 100644 --- a/chrome/renderer/searchbox/searchbox_extension.h +++ b/chrome/renderer/searchbox/searchbox_extension.h @@ -41,6 +41,8 @@ class SearchBoxExtension { static void DispatchThemeChange(WebKit::WebFrame* frame); static void DispatchBarsHidden(WebKit::WebFrame* frame); static void DispatchFocusChange(WebKit::WebFrame* frame); + static void DispatchInputStart(WebKit::WebFrame* frame); + static void DispatchInputCancel(WebKit::WebFrame* frame); static void DispatchToggleVoiceSearch(WebKit::WebFrame* frame); // New Tab Page API. |