diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:35:08 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:35:08 +0000 |
commit | ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e (patch) | |
tree | 64a6413c070f83fd9c47046092c810f4155f51cb /chrome/browser/instant | |
parent | 9852f63e347fb158463f4437b7ee9422384f02e6 (diff) | |
download | chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.zip chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.tar.gz chromium_src-ba6680fcdf06ea6bbb14e78f6b32d79e6d57c03e.tar.bz2 |
Instant - move AutocompleteLosingFocus implementation to InstantController.
This way Linux and Windows can share.
BUG=58937
TEST=manual
Review URL: http://codereview.chromium.org/4157004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64657 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 49 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 2 |
3 files changed, 55 insertions, 1 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index a790b96..74df04c 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -9,8 +9,10 @@ #include "chrome/browser/instant/instant_delegate.h" #include "chrome/browser/instant/instant_loader.h" #include "chrome/browser/instant/instant_loader_manager.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -138,6 +140,53 @@ bool InstantController::IsMouseDownFromActivate() { return loader_manager_->current_loader()->IsMouseDownFromActivate(); } +void InstantController::OnAutocompleteLostFocus( + gfx::NativeView view_gaining_focus) { + if (!is_active() || !GetPreviewContents()) + return; + + RenderWidgetHostView* rwhv = + GetPreviewContents()->GetRenderWidgetHostView(); + if (!view_gaining_focus || !rwhv) + return DestroyPreviewContents(); + + gfx::NativeView tab_view = GetPreviewContents()->GetNativeView(); + // Focus is going to the renderer. + if (rwhv->GetNativeView() == view_gaining_focus || + tab_view == view_gaining_focus) { + if (!IsMouseDownFromActivate()) { + // If the mouse is not down, focus is not going to the renderer. Someone + // else moved focus and we shouldn't commit. + return DestroyPreviewContents(); + } + + if (IsShowingInstant()) { + // We're showing instant results. As instant results may shift when + // committing we commit on the mouse up. This way a slow click still + // works fine. + return SetCommitOnMouseUp(); + } + + return CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); + } + + // Walk up the view hierarchy. If the view gaining focus is a subview of the + // TabContents view (such as a windowed plugin or http auth dialog), we want + // to keep the preview contents. Otherwise, focus has gone somewhere else, + // such as the JS inspector, and we want to cancel the preview. + gfx::NativeView view_gaining_focus_ancestor = view_gaining_focus; + while (view_gaining_focus_ancestor && + view_gaining_focus_ancestor != tab_view) { + view_gaining_focus_ancestor = + platform_util::GetParent(view_gaining_focus_ancestor); + } + + if (view_gaining_focus_ancestor) + return CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); + + return DestroyPreviewContents(); +} + TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { if (!loader_manager_.get()) return NULL; diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 0430083..396ce6d 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -16,6 +16,7 @@ #include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/search_engines/template_url_id.h" #include "chrome/common/page_transition_types.h" +#include "gfx/native_widget_types.h" #include "gfx/rect.h" #include "googleurl/src/gurl.h" @@ -84,6 +85,10 @@ class InstantController : public InstantLoaderDelegate { // content. bool IsMouseDownFromActivate(); + // The autocomplete edit that was initiating the current instant session has + // lost focus. Commit or discard the preview accordingly. + void OnAutocompleteLostFocus(gfx::NativeView view_gaining_focus); + // Releases the preview TabContents passing ownership to the caller. This is // intended to be called when the preview TabContents is committed. This does // not notify the delegate. diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 06047a2..b9ba2d3 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -402,7 +402,7 @@ class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { virtual bool IsPopup(const TabContents* source) const { return false; } - virtual bool ShouldFocusConstrainedWindow(TabContents* source) { + virtual bool ShouldFocusConstrainedWindow() { // Return false so that constrained windows are not initially focused. If // we did otherwise the preview would prematurely get committed when focus // goes to the constrained window. |