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

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: Rebase. Address comments. 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..862d74d27802d56cf8dd64e69eaa58463002ba8a 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,19 @@ 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();
+ // The SetCaretVisibility call above will already send an update to the
+ // InstantController in some cases but we still need this here since it won't
+ // send an update if the caret was already visible.
Peter Kasting 2012/12/08 01:12:21 But in that case why do we need to send an update?
samarth 2012/12/08 01:51:34 It's because InstantController also needs to know
Peter Kasting 2012/12/08 02:07:52 Perhaps we should move this to the top of the func
samarth 2012/12/10 23:45:00 Done.
+ if (InstantController* instant = controller_->GetInstant()) {
+ instant->OmniboxFocusChanged(FOCUS_VISIBLE,
+ FOCUS_CHANGE_EXPLICIT, NULL);
+ }
content::WebContents* web_contents = controller_->GetWebContents();
if (web_contents) {
@@ -736,17 +744,16 @@ void OmniboxEditModel::OnSetFocus(bool control_down) {
}
void OmniboxEditModel::SetCaretVisibility(bool visible) {
- if (has_focus_ && visible != is_caret_visible_) {
- is_caret_visible_ = visible;
- view_->ApplyCaretVisibility();
- }
+ SetCaretVisibilityInternal(visible, FOCUS_CHANGE_EXPLICIT);
}
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 +959,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 =
@@ -1288,3 +1295,16 @@ void OmniboxEditModel::ClassifyStringForPasteAndGo(
AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
string16(), false, false, match, alternate_nav_url);
}
+
+void OmniboxEditModel::SetCaretVisibilityInternal(
+ 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();
+ }
+}
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698