diff options
author | samarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 04:42:12 +0000 |
---|---|---|
committer | samarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 04:42:12 +0000 |
commit | c18cb67d0d9e18b15dd5a8903e93d91c6c63a484 (patch) | |
tree | f159e15f4412b7640155e00436c4943ea07511cb /chrome | |
parent | a06b5b63d01fd6b84a3edc4b422af2d533261347 (diff) | |
download | chromium_src-c18cb67d0d9e18b15dd5a8903e93d91c6c63a484.zip chromium_src-c18cb67d0d9e18b15dd5a8903e93d91c6c63a484.tar.gz chromium_src-c18cb67d0d9e18b15dd5a8903e93d91c6c63a484.tar.bz2 |
Implement {Start,Stop}CapturingKeyStrokes for Instant.
Implement {Start,Stop}CapturingKeyStrokes for Instant by transferring
focus invisibly to the omnibox. This patch implements invisible focus for
Aura. Other platforms will follow.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11369137
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
27 files changed, 223 insertions, 8 deletions
diff --git a/chrome/browser/instant/instant_client.cc b/chrome/browser/instant/instant_client.cc index 5a4efc5..eb045bc 100644 --- a/chrome/browser/instant/instant_client.cc +++ b/chrome/browser/instant/instant_client.cc @@ -88,6 +88,10 @@ bool InstantClient::OnMessageReceived(const IPC::Message& message) { InstantSupportDetermined) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview, ShowInstantPreview) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes, + StartCapturingKeyStrokes); + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes, + StopCapturingKeyStrokes); IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -112,3 +116,13 @@ void InstantClient::ShowInstantPreview(int page_id, if (web_contents()->IsActiveEntry(page_id)) delegate_->ShowInstantPreview(reason, height, units); } + +void InstantClient::StartCapturingKeyStrokes(int page_id) { + if (web_contents()->IsActiveEntry(page_id)) + delegate_->StartCapturingKeyStrokes(); +} + +void InstantClient::StopCapturingKeyStrokes(int page_id) { + if (web_contents()->IsActiveEntry(page_id)) + delegate_->StopCapturingKeyStrokes(); +} diff --git a/chrome/browser/instant/instant_client.h b/chrome/browser/instant/instant_client.h index 1c213ad..95ab909 100644 --- a/chrome/browser/instant/instant_client.h +++ b/chrome/browser/instant/instant_client.h @@ -50,6 +50,14 @@ class InstantClient : public content::WebContentsObserver { int height, InstantSizeUnits units) = 0; + // Called when the page wants the browser to start capturing user key + // strokes. + virtual void StartCapturingKeyStrokes() = 0; + + // Called when the page wants the browser to stop capturing user key + // strokes. + virtual void StopCapturingKeyStrokes() = 0; + protected: virtual ~Delegate(); }; @@ -123,6 +131,8 @@ class InstantClient : public content::WebContentsObserver { InstantShownReason reason, int height, InstantSizeUnits units); + void StartCapturingKeyStrokes(int page_id); + void StopCapturingKeyStrokes(int page_id); Delegate* const delegate_; diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index f6c7725..6135843 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -742,6 +742,12 @@ void InstantController::ShowInstantPreview(InstantShownReason reason, ShowLoader(reason, height, units); } +void InstantController::StartCapturingKeyStrokes() { + // Ignore unless the loader is active and on the NTP. + if (extended_enabled_ && !instant_tab_ && model_.mode().is_ntp()) + browser_->FocusOmniboxInvisibly(); +} + void InstantController::SwappedWebContents() { model_.SetPreviewContents(GetPreviewContents()); } diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 941dd15..34e78ab 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -130,6 +130,10 @@ class InstantController { int height, InstantSizeUnits units); + // Invoked by InstantLoader to request the browser to start capturing user key + // strokes. + void StartCapturingKeyStrokes(); + // Invoked by InstantLoader when it has swapped a different WebContents into // the preview, usually because a prerendered page was navigated to. void SwappedWebContents(); diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 34fa5c0..6db8090 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -276,6 +276,17 @@ void InstantLoader::ShowInstantPreview(InstantShownReason reason, controller_->ShowInstantPreview(reason, height, units); } +void InstantLoader::StartCapturingKeyStrokes() { + InstantSupportDetermined(true); + controller_->StartCapturingKeyStrokes(); +} + +void InstantLoader::StopCapturingKeyStrokes() { + InstantSupportDetermined(true); + // NOTE(samarth): the current implementation of the key capturing (invisible + // focus) doesn't require doing anything explicitly here. +} + void InstantLoader::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index c701aa6..a605f37 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -112,6 +112,8 @@ class InstantLoader : public InstantClient::Delegate, virtual void ShowInstantPreview(InstantShownReason reason, int height, InstantSizeUnits units) OVERRIDE; + virtual void StartCapturingKeyStrokes() OVERRIDE; + virtual void StopCapturingKeyStrokes() OVERRIDE; // Overridden from content::NotificationObserver: virtual void Observe(int type, diff --git a/chrome/browser/instant/instant_tab.cc b/chrome/browser/instant/instant_tab.cc index c6821728..2308563 100644 --- a/chrome/browser/instant/instant_tab.cc +++ b/chrome/browser/instant/instant_tab.cc @@ -67,3 +67,11 @@ void InstantTab::ShowInstantPreview(InstantShownReason /* reason */, InstantSizeUnits /* units */) { // The page is a committed tab (i.e., always showing), so nothing to do. } + +void InstantTab::StartCapturingKeyStrokes() { + // We don't honor this call from committed tabs. +} + +void InstantTab::StopCapturingKeyStrokes() { + // We don't honor this call from committed tabs. +} diff --git a/chrome/browser/instant/instant_tab.h b/chrome/browser/instant/instant_tab.h index 18a51f6..9af7b13 100644 --- a/chrome/browser/instant/instant_tab.h +++ b/chrome/browser/instant/instant_tab.h @@ -52,6 +52,8 @@ class InstantTab : public InstantClient::Delegate { virtual void ShowInstantPreview(InstantShownReason reason, int height, InstantSizeUnits units) OVERRIDE; + virtual void StartCapturingKeyStrokes() OVERRIDE; + virtual void StopCapturingKeyStrokes() OVERRIDE; InstantClient client_; InstantController* const controller_; diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index b9ae096..9b82049 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -12,6 +12,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" +#include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" @@ -112,8 +113,7 @@ void BrowserInstantController::CommitInstant(content::WebContents* preview, void BrowserInstantController::SetInstantSuggestion( const InstantSuggestion& suggestion) { - if (browser_->window()->GetLocationBar()) - browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); + browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); } gfx::Rect BrowserInstantController::GetInstantBounds() { @@ -125,6 +125,13 @@ void BrowserInstantController::InstantPreviewFocused() { browser_->window()->WebContentsFocused(instant_.GetPreviewContents()); } +void BrowserInstantController::FocusOmniboxInvisibly() { + OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> + GetLocationEntry(); + omnibox_view->SetFocus(); + omnibox_view->model()->SetCaretVisibility(false); +} + content::WebContents* BrowserInstantController::GetActiveWebContents() const { return browser_->tab_strip_model()->GetActiveWebContents(); } diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index 44d21e7..0cbaa8e 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -66,6 +66,9 @@ class BrowserInstantController : public content::NotificationObserver, // to the user clicking on it. void InstantPreviewFocused(); + // Invoked by |instant_| to give the omnibox focus invisibly. + void FocusOmniboxInvisibly(); + // Invoked by |instant_| to get the currently active tab, over which the // preview would be shown. content::WebContents* GetActiveWebContents() const; diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h index 642c513..9dfdcb8 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h @@ -48,6 +48,7 @@ class OmniboxViewMac : public OmniboxView, virtual void UpdatePopup() OVERRIDE; virtual void CloseOmniboxPopup() OVERRIDE; virtual void SetFocus() OVERRIDE; + virtual void ApplyCaretVisibility() OVERRIDE; virtual void OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) OVERRIDE; diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index 9cf11b3..84e2e17 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -362,6 +362,11 @@ void OmniboxViewMac::CloseOmniboxPopup() { void OmniboxViewMac::SetFocus() { } +void OmniboxViewMac::ApplyCaretVisibility() { + // TODO(mathp): implement for Mac. + NOTIMPLEMENTED(); +} + void OmniboxViewMac::SetText(const string16& display_text) { // If we are setting the text directly, there cannot be any suggest text. suggest_text_length_ = 0; diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc index beedfb8..9394ba7 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc @@ -426,6 +426,11 @@ void OmniboxViewGtk::SetFocus() { gtk_widget_grab_focus(text_view_); } +void OmniboxViewGtk::ApplyCaretVisibility() { + // TODO(mathp): implement for Linux. + NOTIMPLEMENTED(); +} + int OmniboxViewGtk::WidthOfTextAfterCursor() { // Not used. return -1; diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h index 6b1d60b..7c2b134 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h @@ -84,6 +84,7 @@ class OmniboxViewGtk : public OmniboxView, virtual void SelectAll(bool reversed) OVERRIDE; virtual void UpdatePopup() OVERRIDE; virtual void SetFocus() OVERRIDE; + virtual void ApplyCaretVisibility() OVERRIDE; virtual void OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) OVERRIDE; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 5a89651..668d9a8 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -70,11 +70,13 @@ using predictors::AutocompleteActionPredictorFactory; OmniboxEditModel::State::State(bool user_input_in_progress, const string16& user_text, const string16& keyword, - bool is_keyword_hint) + bool is_keyword_hint, + bool is_caret_visible) : user_input_in_progress(user_input_in_progress), user_text(user_text), keyword(keyword), - is_keyword_hint(is_keyword_hint) { + is_keyword_hint(is_keyword_hint), + is_caret_visible(is_caret_visible) { } OmniboxEditModel::State::~State() { @@ -90,6 +92,7 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view, popup_(NULL), controller_(controller), has_focus_(false), + is_caret_visible_(true), user_input_in_progress_(false), just_deleted_text_(false), has_temporary_text_(false), @@ -128,10 +131,12 @@ const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() { } } - return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_); + return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_, + is_caret_visible_); } void OmniboxEditModel::RestoreState(const State& state) { + SetCaretVisibility(state.is_caret_visible); // Restore any user editing. if (state.user_input_in_progress) { // NOTE: Be sure and set keyword-related state BEFORE invoking @@ -710,6 +715,8 @@ const AutocompleteResult& OmniboxEditModel::result() const { void OmniboxEditModel::OnSetFocus(bool control_down) { has_focus_ = true; control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; + // Restore caret visibility whenever the user focuses back into the omnibox. + SetCaretVisibility(true); if (InstantController* instant = controller_->GetInstant()) instant->OmniboxGotFocus(); @@ -728,6 +735,13 @@ void OmniboxEditModel::OnSetFocus(bool control_down) { NotifySearchTabHelper(); } +void OmniboxEditModel::SetCaretVisibility(bool visible) { + if (has_focus_ && visible != is_caret_visible_) { + is_caret_visible_ = visible; + view_->ApplyCaretVisibility(); + } +} + void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { SetInstantSuggestion(InstantSuggestion()); @@ -935,6 +949,11 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text, else if (text_differs) paste_state_ = NONE; + // Restore caret visibility whenever the user changes text or selection in the + // omnibox. + if (text_differs || selection_differs) + SetCaretVisibility(true); + // Modifying the selection counts as accepting the autocompleted text. const bool user_text_changed = text_differs || (selection_differs && !inline_autocomplete_text_.empty()); diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.h b/chrome/browser/ui/omnibox/omnibox_edit_model.h index 6caf62f..f8444f6 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.h @@ -37,13 +37,15 @@ class OmniboxEditModel : public AutocompleteControllerDelegate { State(bool user_input_in_progress, const string16& user_text, const string16& keyword, - bool is_keyword_hint); + bool is_keyword_hint, + bool is_caret_visible); ~State(); bool user_input_in_progress; const string16 user_text; const string16 keyword; const bool is_keyword_hint; + const bool is_caret_visible; }; OmniboxEditModel(OmniboxView* view, @@ -190,6 +192,7 @@ class OmniboxEditModel : public AutocompleteControllerDelegate { size_t index); bool has_focus() const { return has_focus_; } + bool is_caret_visible() const { return is_caret_visible_; } // Accessors for keyword-related state (see comments on keyword_ and // is_keyword_hint_). @@ -213,6 +216,17 @@ class OmniboxEditModel : public AutocompleteControllerDelegate { // control key is down (at the time we're gaining focus). void OnSetFocus(bool control_down); + // Sets the visibility of the caret in the omnibox, if it has focus. The + // visibility of the caret is reset to visible if any of the following + // happens: + // - User starts typing in the omnibox + // - User clicks in the omnibox + // - Omnibox loses and then regains focus + // - SetFocus() is explicitly called again + // Caret visibility is tracked per-tab and updates automatically upon + // switching tabs. + void SetCaretVisibility(bool visible); + // Sent before |OnKillFocus| and before the popup is closed. void OnWillKillFocus(gfx::NativeView view_gaining_focus); @@ -404,6 +418,9 @@ class OmniboxEditModel : public AutocompleteControllerDelegate { // Whether the edit has focus. bool has_focus_; + // Is the caret visible? Only meaningful if has_focus_ is true. + bool is_caret_visible_; + // The URL of the currently displayed page. string16 permanent_text_; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index 09ceaaf..47d7b32 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -44,6 +44,7 @@ class TestingOmniboxView : public OmniboxView { virtual void RevertAll() OVERRIDE {} virtual void UpdatePopup() OVERRIDE {} virtual void SetFocus() OVERRIDE {} + virtual void ApplyCaretVisibility() OVERRIDE {} virtual void OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) OVERRIDE {} diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index 692144f..7f21b56 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -152,6 +152,10 @@ class OmniboxView { // Sets the focus to the autocomplete view. virtual void SetFocus() = 0; + // Shows or hides the caret based on whether the model's is_caret_visible() is + // true. + virtual void ApplyCaretVisibility() = 0; + // Called when the temporary text in the model may have changed. // |display_text| is the new text to show; |save_original_selection| is true // when there wasn't previously a temporary text and thus we need to save off diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 091b9f7..bda1e48 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -224,7 +224,8 @@ OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, delete_at_end_pressed_(false), location_bar_view_(location_bar), ime_candidate_window_open_(false), - select_all_on_mouse_release_(false) { + select_all_on_mouse_release_(false), + visible_caret_color_(SK_ColorBLACK) { } OmniboxViewViews::~OmniboxViewViews() { @@ -368,6 +369,10 @@ void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { select_all_on_mouse_release_ = (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && !textfield_->HasFocus(); + // Restore caret visibility whenever the user clicks in the the omnibox. This + // is not always covered by OnSetFocus() because when clicking while the + // omnibox has invisible focus does not trigger a new OnSetFocus() call. + model()->SetCaretVisibility(true); } void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { @@ -445,7 +450,7 @@ void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { } //////////////////////////////////////////////////////////////////////////////// -// OmniboxViewViews, AutocopmleteEditView implementation: +// OmniboxViewViews, OmniboxView implementation: void OmniboxViewViews::SaveStateToTab(WebContents* tab) { DCHECK(tab); @@ -574,10 +579,25 @@ void OmniboxViewViews::UpdatePopup() { } void OmniboxViewViews::SetFocus() { + // Restore caret visibility if focused explicitly. We need to do this here + // because if we already have invisible focus, the RequestFocus() call below + // will short-circuit, preventing us from reaching + // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we + // didn't previously have focus. + model()->SetCaretVisibility(true); // In views-implementation, the focus is on textfield rather than OmniboxView. textfield_->RequestFocus(); } +void OmniboxViewViews::ApplyCaretVisibility() { + if (textfield_->cursor_color() != textfield_->background_color()) + visible_caret_color_ = textfield_->cursor_color(); + // Setting the color of the text cursor (caret) to the background color + // effectively hides it. + textfield_->SetCursorColor(model()->is_caret_visible() ? + visible_caret_color_ : textfield_->background_color()); +} + void OmniboxViewViews::OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) { diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h index 23a0487..73a6116 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h @@ -111,6 +111,7 @@ class OmniboxViewViews virtual void SelectAll(bool reversed) OVERRIDE; virtual void UpdatePopup() OVERRIDE; virtual void SetFocus() OVERRIDE; + virtual void ApplyCaretVisibility() OVERRIDE; virtual void OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) OVERRIDE; @@ -221,6 +222,10 @@ class OmniboxViewViews // allow the user to select just a portion of the text. bool select_all_on_mouse_release_; + // Used to keep track of the visible caret color so that it can be restored + // after the caret has been hidden. + SkColor visible_caret_color_; + DISALLOW_COPY_AND_ASSIGN(OmniboxViewViews); }; diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index 9e18298..a881053 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -762,6 +762,11 @@ void OmniboxViewWin::SetFocus() { ::SetFocus(m_hWnd); } +void OmniboxViewWin::ApplyCaretVisibility() { + // TODO(mathp): implement for Windows. + NOTIMPLEMENTED(); +} + void OmniboxViewWin::SetDropHighlightPosition(int position) { if (drop_highlight_position_ != position) { RepaintDropHighlight(drop_highlight_position_); diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.h b/chrome/browser/ui/views/omnibox/omnibox_view_win.h index d3e7a6f..8ae1684 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.h +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.h @@ -97,6 +97,7 @@ class OmniboxViewWin virtual void RevertAll() OVERRIDE; virtual void UpdatePopup() OVERRIDE; virtual void SetFocus() OVERRIDE; + virtual void ApplyCaretVisibility() OVERRIDE; virtual void OnTemporaryTextMaybeChanged( const string16& display_text, bool save_original_selection) OVERRIDE; diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index a038150..f91f2bd 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -659,6 +659,12 @@ IPC_MESSAGE_ROUTED4(ChromeViewHostMsg_ShowInstantPreview, int /* height */, InstantSizeUnits /* units */) +IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_StartCapturingKeyStrokes, + int /* page_id */) + +IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_StopCapturingKeyStrokes, + int /* page_id */) + // The currently displayed PDF has an unsupported feature. IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_PDFHasUnsupportedFeature) diff --git a/chrome/renderer/resources/extensions/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox_api.js index 7952b3b..8d3a98a 100644 --- a/chrome/renderer/resources/extensions/searchbox_api.js +++ b/chrome/renderer/resources/extensions/searchbox_api.js @@ -40,6 +40,8 @@ if (!chrome.searchBox) { native function SetQuery(); native function SetQueryFromAutocompleteResult(); native function Show(); + native function StartCapturingKeyStrokes(); + native function StopCapturingKeyStrokes(); // Returns the |restrictedText| wrapped in a ShadowDOM. function SafeWrap(restrictedText) { @@ -205,6 +207,12 @@ if (!chrome.searchBox) { this.navigateContentWindow = function(destination) { return NavigateContentWindow(destination); }; + this.startCapturingKeyStrokes = function() { + StartCapturingKeyStrokes(); + }; + this.stopCapturingKeyStrokes = function() { + StopCapturingKeyStrokes(); + }; this.onchange = null; this.onsubmit = null; this.oncancel = null; diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc index 2a3d2c4..9f1e82c 100644 --- a/chrome/renderer/searchbox/searchbox.cc +++ b/chrome/renderer/searchbox/searchbox.cc @@ -45,6 +45,16 @@ void SearchBox::ShowInstantPreview(InstantShownReason reason, height, units)); } +void SearchBox::StartCapturingKeyStrokes() { + render_view()->Send(new ChromeViewHostMsg_StartCapturingKeyStrokes( + render_view()->GetRoutingID(), render_view()->GetPageId())); +} + +void SearchBox::StopCapturingKeyStrokes() { + render_view()->Send(new ChromeViewHostMsg_StopCapturingKeyStrokes( + render_view()->GetRoutingID(), render_view()->GetPageId())); +} + gfx::Rect SearchBox::GetRect() { // Need to adjust for scale. if (rect_.IsEmpty()) diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h index 406bf4a..6c18729e 100644 --- a/chrome/renderer/searchbox/searchbox.h +++ b/chrome/renderer/searchbox/searchbox.h @@ -33,6 +33,12 @@ class SearchBox : public content::RenderViewObserver, int height, InstantSizeUnits units); + // Sends ViewHostMsg_StartCapturingKeyStrokes to the browser. + void StartCapturingKeyStrokes(); + + // Sends ViewHostMsg_StopCapturingKeyStrokes to the browser. + void StopCapturingKeyStrokes(); + const string16& query() const { return query_; } bool verbatim() const { return verbatim_; } size_t selection_start() const { return selection_start_; } diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc index bf2cb9e..15bb23b 100644 --- a/chrome/renderer/searchbox/searchbox_extension.cc +++ b/chrome/renderer/searchbox/searchbox_extension.cc @@ -248,6 +248,14 @@ class SearchBoxExtensionWrapper : public v8::Extension { // Requests the preview be shown with the specified contents and height. static v8::Handle<v8::Value> Show(const v8::Arguments& args); + // Start capturing user key strokes. + static v8::Handle<v8::Value> StartCapturingKeyStrokes( + const v8::Arguments& args); + + // Stop capturing user key strokes. + static v8::Handle<v8::Value> StopCapturingKeyStrokes( + const v8::Arguments& args); + private: DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); }; @@ -299,6 +307,10 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); if (name->Equals(v8::String::New("Show"))) return v8::FunctionTemplate::New(Show); + if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) + return v8::FunctionTemplate::New(StartCapturingKeyStrokes); + if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) + return v8::FunctionTemplate::New(StopCapturingKeyStrokes); return v8::Handle<v8::FunctionTemplate>(); } @@ -738,6 +750,28 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::Show( } // static +v8::Handle<v8::Value> SearchBoxExtensionWrapper::StartCapturingKeyStrokes( + const v8::Arguments& args) { + content::RenderView* render_view = GetRenderView(); + if (!render_view) return v8::Undefined(); + + DVLOG(1) << render_view << " StartCapturingKeyStrokes"; + SearchBox::Get(render_view)->StartCapturingKeyStrokes(); + return v8::Undefined(); +} + +// static +v8::Handle<v8::Value> SearchBoxExtensionWrapper::StopCapturingKeyStrokes( + const v8::Arguments& args) { + content::RenderView* render_view = GetRenderView(); + if (!render_view) return v8::Undefined(); + + DVLOG(1) << render_view << " StopCapturingKeyStrokes"; + SearchBox::Get(render_view)->StopCapturingKeyStrokes(); + return v8::Undefined(); +} + +// static void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { Dispatch(frame, kDispatchChangeEventScript); } |