Index: chrome/browser/instant/instant_controller.cc |
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc |
index 613584314977744b0bce880412250ee2851d7567..30c44f805b14767e92750d2e46113439716e1894 100644 |
--- a/chrome/browser/instant/instant_controller.cc |
+++ b/chrome/browser/instant/instant_controller.cc |
@@ -152,7 +152,7 @@ InstantController::InstantController(chrome::BrowserInstantController* browser, |
last_verbatim_(false), |
last_transition_type_(content::PAGE_TRANSITION_LINK), |
last_match_was_search_(false), |
- is_omnibox_focused_(false), |
+ omnibox_focus_state_(FOCUS_NONE), |
allow_preview_to_show_search_suggestions_(false) { |
} |
@@ -531,41 +531,37 @@ bool InstantController::CommitIfCurrent(InstantCommitType type) { |
return true; |
} |
-void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
- DVLOG(1) << "OmniboxLostFocus"; |
- is_omnibox_focused_ = false; |
- |
- if (!extended_enabled_ && !instant_enabled_) |
- return; |
- |
- // If the preview isn't showing search suggestions, nothing to do. The check |
- // for GetPreviewContents() (which normally is redundant, given IsCurrent()) |
- // is to handle the case when we get here during a commit. |
- if (!IsCurrent() || !GetPreviewContents()) { |
- OnStaleLoader(); |
- return; |
- } |
- |
-#if defined(OS_MACOSX) |
- if (!loader_->is_pointer_down_from_activate()) |
- HideLoader(); |
-#else |
- if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
- loader_->contents())) |
- CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST); |
- else |
- HideLoader(); |
-#endif |
-} |
- |
-void InstantController::OmniboxGotFocus() { |
- DVLOG(1) << "OmniboxGotFocus"; |
- is_omnibox_focused_ = true; |
+void InstantController::OmniboxFocusChanged( |
+ OmniboxFocusState state, |
+ OmniboxFocusChangeReason reason, |
+ gfx::NativeView view_gaining_focus) { |
+ DVLOG(1) << "OmniboxFocusChanged: " << omnibox_focus_state_ << " to " |
+ << state << " for reason " << reason; |
+ OmniboxFocusState old_focus_state = omnibox_focus_state_; |
+ omnibox_focus_state_ = state; |
if (!extended_enabled_ && !instant_enabled_) |
return; |
- CreateDefaultLoader(); |
+ // Tell the page if the key capture mode changed unless the focus state |
+ // changed because of TYPING. This is because in that case, the browser hasn't |
+ // really stopped capturing key strokes. |
+ // |
+ // (More practically, if we don't do this check, the page would receieve |
sreeram
2012/12/05 19:48:24
Nit: receieve -> receive
samarth
2012/12/08 00:55:47
Done.
|
+ // keycapturechange before the corresponding onchange, and the page would have |
+ // no way of telling whether the keycapturechange happened because of some |
+ // actual user action or just because they started typing.) |
+ if (extended_enabled_ && GetPreviewContents() && |
+ reason != FOCUS_CHANGE_TYPING) |
+ loader_->KeyCaptureChanged(omnibox_focus_state_ == FOCUS_INVISIBLE); |
+ |
+ // If focus went from outside the omnibox to the omnibox, preload the default |
+ // search engine, in anticipation of the user typing a query. If the reverse |
+ // happened, commit or discard the preview. |
+ if (state != FOCUS_NONE && old_focus_state == FOCUS_NONE) |
+ CreateDefaultLoader(); |
+ else if (state == FOCUS_NONE && old_focus_state != FOCUS_NONE) |
+ OmniboxLostFocus(view_gaining_focus); |
} |
void InstantController::SearchModeChanged( |
@@ -761,6 +757,28 @@ void InstantController::InstantLoaderContentsFocused() { |
#endif |
} |
+void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
+ DVLOG(1) << "OmniboxLostFocus"; |
+ // If the preview isn't showing search suggestions, nothing to do. The check |
+ // for GetPreviewContents() (which normally is redundant, given IsCurrent()) |
+ // is to handle the case when we get here during a commit. |
+ if (!IsCurrent() || !GetPreviewContents()) { |
+ OnStaleLoader(); |
+ return; |
+ } |
+ |
+#if defined(OS_MACOSX) |
+ if (!loader_->is_pointer_down_from_activate()) |
+ HideLoader(); |
+#else |
+ if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
+ loader_->contents())) |
+ CommitIfCurrent(INSTANT_COMMIT_FOCUS_LOST); |
+ else |
+ HideLoader(); |
+#endif |
+} |
+ |
bool InstantController::ResetLoader(const TemplateURL* template_url, |
const content::WebContents* active_tab) { |
std::string instant_url; |
@@ -779,6 +797,7 @@ bool InstantController::ResetLoader(const TemplateURL* template_url, |
browser_->UpdateThemeInfoForPreview(); |
loader_->SetDisplayInstantResults(instant_enabled_); |
loader_->SearchModeChanged(search_mode_); |
+ loader_->KeyCaptureChanged(omnibox_focus_state_ == FOCUS_INVISIBLE); |
} |
// Restart the stale loader timer. |
@@ -806,7 +825,7 @@ void InstantController::OnStaleLoader() { |
// If the preview is showing or the omnibox has focus, don't delete the |
// loader. It will get refreshed the next time the preview is hidden or the |
// omnibox loses focus. |
- if (!stale_loader_timer_.IsRunning() && !is_omnibox_focused_ && |
+ if (!stale_loader_timer_.IsRunning() && omnibox_focus_state_ == FOCUS_NONE && |
model_.mode().is_default()) { |
loader_.reset(); |
CreateDefaultLoader(); |