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

Unified Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 11413217: Instant API: tell page whether the browser is capturing key strokes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@focus
Patch Set: Fixed comments, mouse handling logic. Created 8 years 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/browser/ui/omnibox/omnibox_edit_model.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
index 668d9a820ea8ff5b715b1dba83d0cf0d3f6ab002..ba343a20992b9f258768317a3678789e7777bcd9 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -136,7 +136,7 @@ const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() {
}
void OmniboxEditModel::RestoreState(const State& state) {
- SetCaretVisibility(state.is_caret_visible);
+ SetCaretVisibilityInternal(state.is_caret_visible, FOCUS_CHANGE_TAB_SWITCH);
// Restore any user editing.
if (state.user_input_in_progress) {
// NOTE: Be sure and set keyword-related state BEFORE invoking
@@ -715,11 +715,16 @@ 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.
+ // If the omnibox lost focus while the caret was hidden and then regained
+ // focus, OnSetFocus() is called and should restore visibility. Note that
+ // focus can be regained without an accompanying call to
+ // OmniboxView::SetFocus(), e.g. by tabbing in.
SetCaretVisibility(true);
- if (InstantController* instant = controller_->GetInstant())
- instant->OmniboxGotFocus();
+ if (InstantController* instant = controller_->GetInstant()) {
Peter Kasting 2012/12/08 01:12:20 Oh, sorry, didn't notice this before. Please do n
samarth 2012/12/08 01:51:34 Happy to, I really don't like them either.
+ instant->OmniboxFocusChanged(FOCUS_VISIBLE,
+ FOCUS_CHANGE_EXPLICIT, NULL);
+ }
Peter Kasting 2012/12/07 23:22:03 This block seems like it duplicates SetCaretVisibi
samarth 2012/12/08 00:55:47 It's sometimes necessary. Added comment.
content::WebContents* web_contents = controller_->GetWebContents();
if (web_contents) {
@@ -736,7 +741,17 @@ void OmniboxEditModel::OnSetFocus(bool control_down) {
}
void OmniboxEditModel::SetCaretVisibility(bool visible) {
+ SetCaretVisibilityInternal(visible, FOCUS_CHANGE_EXPLICIT);
+}
+
+void OmniboxEditModel::SetCaretVisibilityInternal(
Peter Kasting 2012/12/07 23:22:03 Function definition order should match .h declarat
samarth 2012/12/08 00:55:47 Done.
+ bool visible,
+ OmniboxFocusChangeReason reason) {
if (has_focus_ && visible != is_caret_visible_) {
+ if (InstantController* instant = controller_->GetInstant()) {
+ instant->OmniboxFocusChanged(visible ? FOCUS_VISIBLE : FOCUS_INVISIBLE,
+ reason, NULL);
+ }
is_caret_visible_ = visible;
view_->ApplyCaretVisibility();
}
@@ -745,8 +760,10 @@ void OmniboxEditModel::SetCaretVisibility(bool visible) {
void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
SetInstantSuggestion(InstantSuggestion());
- if (InstantController* instant = controller_->GetInstant())
- instant->OmniboxLostFocus(view_gaining_focus);
+ if (InstantController* instant = controller_->GetInstant()) {
+ instant->OmniboxFocusChanged(FOCUS_NONE, FOCUS_CHANGE_EXPLICIT,
+ view_gaining_focus);
+ }
// TODO(jered): Rip this out along with StartZeroSuggest.
autocomplete_controller_->StopZeroSuggest();
@@ -952,7 +969,7 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text,
// Restore caret visibility whenever the user changes text or selection in the
// omnibox.
if (text_differs || selection_differs)
- SetCaretVisibility(true);
+ SetCaretVisibilityInternal(true, FOCUS_CHANGE_TYPING);
// Modifying the selection counts as accepting the autocompleted text.
const bool user_text_changed =

Powered by Google App Engine
This is Rietveld 408576698