| Index: chrome/browser/instant/instant_controller.cc
|
| diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
|
| index 1e63886b896da48c173bbbb985d178fc240b5439..b2332a1061213d0b1b2a7f091591bf41943f1cad 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) {
|
| }
|
|
|
| @@ -533,41 +533,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
|
| + // 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(
|
| @@ -766,6 +762,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;
|
| @@ -784,6 +802,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.
|
| @@ -811,7 +830,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();
|
|
|