summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 16:23:28 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 16:23:28 +0000
commit09c6943d4ff83987c41826a4a8c27a9e3a462df2 (patch)
tree931443864a7dc0b49ce010d243b3c7c62076a777
parent29f16dc62ed629048ab8f890aff5ef7cf410772f (diff)
downloadchromium_src-09c6943d4ff83987c41826a4a8c27a9e3a462df2.zip
chromium_src-09c6943d4ff83987c41826a4a8c27a9e3a462df2.tar.gz
chromium_src-09c6943d4ff83987c41826a4a8c27a9e3a462df2.tar.bz2
Gets instant to correctly commit under aura. This was broke for a
couple of reasons: . RWHVA was never told it was going to become active by way of a mouse. I fixed this by wiring through the event to ActivationDelegate::ShouldActivate. . OmniboxViewViews wasn't telling the model the native view that is getting focus. I've modified OmniboxViewViews to get the focused window from the RootWindow. . OmniboxViewViews was never being told it's losing focus. The call to BrowserWindow::WebContentsFocused initiates that. There is a slew of interactive ui tests that exercise this code. They are currently disabled on linux. Separately I'll see I can reenable them. BUG=116940 TEST=make sure instant works correctly on aura. R=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/9700078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127172 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/test/test_activation_delegate.cc2
-rw-r--r--ash/test/test_activation_delegate.h4
-rw-r--r--ash/wm/activation_controller.cc114
-rw-r--r--ash/wm/activation_controller.h13
-rw-r--r--ash/wm/root_window_event_filter.cc6
-rw-r--r--ash/wm/window_util.cc2
-rw-r--r--chrome/browser/instant/instant_controller.cc29
-rw-r--r--chrome/browser/instant/instant_controller.h1
-rw-r--r--chrome/browser/instant/instant_delegate.h5
-rw-r--r--chrome/browser/instant/instant_loader.cc6
-rw-r--r--chrome/browser/instant/instant_loader_delegate.h5
-rw-r--r--chrome/browser/ui/browser.cc5
-rw-r--r--chrome/browser/ui/browser.h1
-rw-r--r--chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc8
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc17
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc4
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.h2
-rw-r--r--ui/aura/client/activation_client.h9
-rw-r--r--ui/aura/client/activation_delegate.h2
-rw-r--r--ui/aura/event_filter_unittest.cc2
-rw-r--r--ui/aura/focus_manager.h6
-rw-r--r--ui/aura/root_window.cc11
-rw-r--r--ui/aura/root_window.h4
-rw-r--r--ui/aura/test/test_activation_client.cc3
-rw-r--r--ui/aura/test/test_activation_client.h2
-rw-r--r--ui/aura/window.cc4
-rw-r--r--ui/views/controls/native/native_view_host_aura.cc2
-rw-r--r--ui/views/widget/native_widget_aura.cc6
-rw-r--r--ui/views/widget/native_widget_aura.h2
29 files changed, 173 insertions, 104 deletions
diff --git a/ash/test/test_activation_delegate.cc b/ash/test/test_activation_delegate.cc
index 6d0f1c9..0e6e5ce 100644
--- a/ash/test/test_activation_delegate.cc
+++ b/ash/test/test_activation_delegate.cc
@@ -37,7 +37,7 @@ void TestActivationDelegate::SetWindow(aura::Window* window) {
aura::client::SetActivationDelegate(window, this);
}
-bool TestActivationDelegate::ShouldActivate(aura::Event* event) {
+bool TestActivationDelegate::ShouldActivate(const aura::Event* event) {
should_activate_count_++;
return activate_;
}
diff --git a/ash/test/test_activation_delegate.h b/ash/test/test_activation_delegate.h
index 3c543a7..d9cc0f2 100644
--- a/ash/test/test_activation_delegate.h
+++ b/ash/test/test_activation_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -38,7 +38,7 @@ class TestActivationDelegate : public aura::client::ActivationDelegate {
}
// Overridden from client::ActivationDelegate:
- virtual bool ShouldActivate(aura::Event* event) OVERRIDE;
+ virtual bool ShouldActivate(const aura::Event* event) OVERRIDE;
virtual void OnActivated() OVERRIDE;
virtual void OnLostActive() OVERRIDE;
diff --git a/ash/wm/activation_controller.cc b/ash/wm/activation_controller.cc
index b3127f7..1133109 100644
--- a/ash/wm/activation_controller.cc
+++ b/ash/wm/activation_controller.cc
@@ -56,11 +56,11 @@ bool SupportsChildActivation(aura::Window* window) {
// Returns true if |window| can be activated or deactivated.
// A window manager typically defines some notion of "top level window" that
// supports activation/deactivation.
-bool CanActivateWindow(aura::Window* window) {
+bool CanActivateWindow(aura::Window* window, const aura::Event* event) {
return window &&
window->IsVisible() &&
(!aura::client::GetActivationDelegate(window) ||
- aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) &&
+ aura::client::GetActivationDelegate(window)->ShouldActivate(event)) &&
SupportsChildActivation(window->parent());
}
@@ -96,16 +96,18 @@ ActivationController::~ActivationController() {
}
// static
-aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) {
+aura::Window* ActivationController::GetActivatableWindow(
+ aura::Window* window,
+ const aura::Event* event) {
aura::Window* parent = window->parent();
aura::Window* child = window;
while (parent) {
- if (SupportsChildActivation(parent))
+ if (CanActivateWindow(child, event))
return child;
// If |child| isn't activatable, but has transient parent, trace
// that path instead.
if (child->transient_parent())
- return GetActivatableWindow(child->transient_parent());
+ return GetActivatableWindow(child->transient_parent(), event);
parent = parent->parent();
child = child->parent();
}
@@ -116,50 +118,7 @@ aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) {
// ActivationController, aura::client::ActivationClient implementation:
void ActivationController::ActivateWindow(aura::Window* window) {
- aura::Window* window_modal_transient = wm::GetWindowModalTransient(window);
- if (window_modal_transient) {
- ActivateWindow(window_modal_transient);
- return;
- }
-
- // Prevent recursion when called from focus.
- if (updating_activation_)
- return;
-
- AutoReset<bool> in_activate_window(&updating_activation_, true);
- // Nothing may actually have changed.
- aura::Window* old_active = GetActiveWindow();
- if (old_active == window)
- return;
- // The stacking client may impose rules on what window configurations can be
- // activated or deactivated.
- if (window && !CanActivateWindow(window))
- return;
- // If the screen is locked, just bring the window to top so that
- // it will be activated when the lock window is destroyed.
- if (window && !window->CanReceiveEvents()) {
- StackTransientParentsBelowModalWindow(window);
- window->parent()->StackChildAtTop(window);
- return;
- }
- if (window &&
- !window->Contains(window->GetFocusManager()->GetFocusedWindow())) {
- window->GetFocusManager()->SetFocusedWindow(window);
- }
- Shell::GetRootWindow()->SetProperty(aura::client::kRootWindowActiveWindowKey,
- window);
- // Invoke OnLostActive after we've changed the active window. That way if the
- // delegate queries for active state it doesn't think the window is still
- // active.
- if (old_active && aura::client::GetActivationDelegate(old_active))
- aura::client::GetActivationDelegate(old_active)->OnLostActive();
-
- if (window) {
- StackTransientParentsBelowModalWindow(window);
- window->parent()->StackChildAtTop(window);
- if (aura::client::GetActivationDelegate(window))
- aura::client::GetActivationDelegate(window)->OnActivated();
- }
+ ActivateWindowWithEvent(window, NULL);
}
void ActivationController::DeactivateWindow(aura::Window* window) {
@@ -172,8 +131,9 @@ aura::Window* ActivationController::GetActiveWindow() {
aura::client::kRootWindowActiveWindowKey);
}
-bool ActivationController::CanFocusWindow(aura::Window* window) const {
- return CanActivateWindow(GetActivatableWindow(window));
+bool ActivationController::OnWillFocusWindow(aura::Window* window,
+ const aura::Event* event) {
+ return CanActivateWindow(GetActivatableWindow(window, event), event);
}
////////////////////////////////////////////////////////////////////////////////
@@ -208,12 +168,60 @@ void ActivationController::OnWindowInitialized(aura::Window* window) {
// ActivationController, aura::RootWindowObserver implementation:
void ActivationController::OnWindowFocused(aura::Window* window) {
- ActivateWindow(GetActivatableWindow(window));
+ ActivateWindow(GetActivatableWindow(window, NULL));
}
////////////////////////////////////////////////////////////////////////////////
// ActivationController, private:
+void ActivationController::ActivateWindowWithEvent(aura::Window* window,
+ const aura::Event* event) {
+ aura::Window* window_modal_transient = wm::GetWindowModalTransient(window);
+ if (window_modal_transient) {
+ ActivateWindow(window_modal_transient);
+ return;
+ }
+
+ // Prevent recursion when called from focus.
+ if (updating_activation_)
+ return;
+
+ AutoReset<bool> in_activate_window(&updating_activation_, true);
+ // Nothing may actually have changed.
+ aura::Window* old_active = GetActiveWindow();
+ if (old_active == window)
+ return;
+ // The stacking client may impose rules on what window configurations can be
+ // activated or deactivated.
+ if (window && !CanActivateWindow(window, event))
+ return;
+ // If the screen is locked, just bring the window to top so that
+ // it will be activated when the lock window is destroyed.
+ if (window && !window->CanReceiveEvents()) {
+ StackTransientParentsBelowModalWindow(window);
+ window->parent()->StackChildAtTop(window);
+ return;
+ }
+ if (window &&
+ !window->Contains(window->GetFocusManager()->GetFocusedWindow())) {
+ window->GetFocusManager()->SetFocusedWindow(window, event);
+ }
+ Shell::GetRootWindow()->SetProperty(aura::client::kRootWindowActiveWindowKey,
+ window);
+ // Invoke OnLostActive after we've changed the active window. That way if the
+ // delegate queries for active state it doesn't think the window is still
+ // active.
+ if (old_active && aura::client::GetActivationDelegate(old_active))
+ aura::client::GetActivationDelegate(old_active)->OnLostActive();
+
+ if (window) {
+ StackTransientParentsBelowModalWindow(window);
+ window->parent()->StackChildAtTop(window);
+ if (aura::client::GetActivationDelegate(window))
+ aura::client::GetActivationDelegate(window)->OnActivated();
+ }
+}
+
void ActivationController::ActivateNextWindow(aura::Window* window) {
if (wm::IsActiveWindow(window))
ActivateWindow(GetTopmostWindowToActivate(window));
@@ -251,7 +259,7 @@ aura::Window* ActivationController::GetTopmostWindowToActivateInContainer(
container->children().rbegin();
i != container->children().rend();
++i) {
- if (*i != ignore && CanActivateWindow(*i))
+ if (*i != ignore && CanActivateWindow(*i, NULL))
return *i;
}
return NULL;
diff --git a/ash/wm/activation_controller.h b/ash/wm/activation_controller.h
index b798b66..dd37470 100644
--- a/ash/wm/activation_controller.h
+++ b/ash/wm/activation_controller.h
@@ -29,14 +29,17 @@ class ASH_EXPORT ActivationController
virtual ~ActivationController();
// Returns true if |window| exists within a container that supports
- // activation.
- static aura::Window* GetActivatableWindow(aura::Window* window);
+ // activation. |event| is the revent responsible for initiating the change, or
+ // NULL if there is no event.
+ static aura::Window* GetActivatableWindow(aura::Window* window,
+ const aura::Event* event);
// Overridden from aura::client::ActivationClient:
virtual void ActivateWindow(aura::Window* window) OVERRIDE;
virtual void DeactivateWindow(aura::Window* window) OVERRIDE;
virtual aura::Window* GetActiveWindow() OVERRIDE;
- virtual bool CanFocusWindow(aura::Window* window) const OVERRIDE;
+ virtual bool OnWillFocusWindow(aura::Window* window,
+ const aura::Event* event) OVERRIDE;
// Overridden from aura::WindowObserver:
virtual void OnWindowVisibilityChanged(aura::Window* window,
@@ -50,6 +53,10 @@ class ASH_EXPORT ActivationController
virtual void OnWindowFocused(aura::Window* window) OVERRIDE;
private:
+ // Implementation of ActivateWindow() with an Event.
+ void ActivateWindowWithEvent(aura::Window* window,
+ const aura::Event* event);
+
// Shifts activation to the next window, ignoring |window|.
void ActivateNextWindow(aura::Window* window);
diff --git a/ash/wm/root_window_event_filter.cc b/ash/wm/root_window_event_filter.cc
index c924446..5c79078 100644
--- a/ash/wm/root_window_event_filter.cc
+++ b/ash/wm/root_window_event_filter.cc
@@ -125,7 +125,8 @@ bool RootWindowEventFilter::PreHandleMouseEvent(aura::Window* target,
return true;
if (event->type() == ui::ET_MOUSE_PRESSED && wm::GetActiveWindow() != target)
- target->GetFocusManager()->SetFocusedWindow(FindFocusableWindowFor(target));
+ target->GetFocusManager()->SetFocusedWindow(
+ FindFocusableWindowFor(target), event);
return false;
}
@@ -141,7 +142,8 @@ ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent(
if (update_cursor_visibility_)
SetCursorVisible(target, event, false);
- target->GetFocusManager()->SetFocusedWindow(FindFocusableWindowFor(target));
+ target->GetFocusManager()->SetFocusedWindow(
+ FindFocusableWindowFor(target), event);
}
return ui::TOUCH_STATUS_UNKNOWN;
}
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index d45c061..3695f86 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -50,7 +50,7 @@ aura::Window* GetActiveWindow() {
}
aura::Window* GetActivatableWindow(aura::Window* window) {
- return internal::ActivationController::GetActivatableWindow(window);
+ return internal::ActivationController::GetActivatableWindow(window, NULL);
}
bool IsWindowNormal(aura::Window* window) {
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index a4d7ba8..b4fef39 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -324,17 +324,15 @@ void InstantController::OnAutocompleteLostFocus(
// For views the top level widget is always focused. If the focus change
// originated in views determine the child Widget from the view that is being
// focused.
- if (view_gaining_focus) {
- views::Widget* widget =
- views::Widget::GetWidgetForNativeView(view_gaining_focus);
- if (widget) {
- views::FocusManager* focus_manager = widget->GetFocusManager();
- if (focus_manager && focus_manager->is_changing_focus() &&
- focus_manager->GetFocusedView() &&
- focus_manager->GetFocusedView()->GetWidget()) {
- view_gaining_focus =
- focus_manager->GetFocusedView()->GetWidget()->GetNativeView();
- }
+ views::Widget* widget =
+ views::Widget::GetWidgetForNativeView(view_gaining_focus);
+ if (widget) {
+ views::FocusManager* focus_manager = widget->GetFocusManager();
+ if (focus_manager && focus_manager->is_changing_focus() &&
+ focus_manager->GetFocusedView() &&
+ focus_manager->GetFocusedView()->GetWidget()) {
+ view_gaining_focus =
+ focus_manager->GetFocusedView()->GetWidget()->GetNativeView();
}
}
#endif
@@ -476,6 +474,15 @@ void InstantController::SwappedTabContents(InstantLoader* loader) {
delegate_->ShowInstant(loader->preview_contents());
}
+void InstantController::InstantLoaderContentsFocused() {
+#if defined(USE_AURA)
+ // On aura the omnibox only receives a focus lost if we initiate the focus
+ // change. This does that.
+ if (!InstantFieldTrial::IsSilentExperiment(tab_contents_->profile()))
+ delegate_->InstantPreviewFocused();
+#endif
+}
+
void InstantController::UpdateIsDisplayable() {
if (!is_out_of_date_ &&
InstantFieldTrial::IsHiddenExperiment(tab_contents_->profile())) {
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index f33dd10..8526065 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -177,6 +177,7 @@ class InstantController : public InstantLoaderDelegate {
virtual void AddToBlacklist(InstantLoader* loader,
const GURL& url) OVERRIDE;
virtual void SwappedTabContents(InstantLoader* loader) OVERRIDE;
+ virtual void InstantLoaderContentsFocused() OVERRIDE;
private:
friend class InstantTest;
diff --git a/chrome/browser/instant/instant_delegate.h b/chrome/browser/instant/instant_delegate.h
index e2a867c..d577606 100644
--- a/chrome/browser/instant/instant_delegate.h
+++ b/chrome/browser/instant/instant_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,6 +37,9 @@ class InstantDelegate {
// Returns the bounds instant will be placed at in screen coordinates.
virtual gfx::Rect GetInstantBounds() = 0;
+ // Invoked when the WebContents becomes focused.
+ virtual void InstantPreviewFocused() = 0;
+
protected:
virtual ~InstantDelegate() {}
};
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index 4f6b0e3..53e1b44 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -227,6 +227,7 @@ class InstantLoader::TabContentsDelegateImpl
bool* proceed_to_fire_unload) OVERRIDE;
virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
+ virtual void WebContentsFocused(WebContents* contents) OVERRIDE;
virtual void LostCapture() OVERRIDE;
// If the user drags, we won't get a mouse up (at least on Linux). Commit the
// instant result when the drag ends, so that during the drag the page won't
@@ -477,6 +478,11 @@ bool InstantLoader::TabContentsDelegateImpl::ShouldFocusPageAfterCrash() {
return false;
}
+void InstantLoader::TabContentsDelegateImpl::WebContentsFocused(
+ WebContents* contents) {
+ loader_->delegate_->InstantLoaderContentsFocused();
+}
+
void InstantLoader::TabContentsDelegateImpl::LostCapture() {
CommitFromMouseReleaseIfNecessary();
}
diff --git a/chrome/browser/instant/instant_loader_delegate.h b/chrome/browser/instant/instant_loader_delegate.h
index 5b98257..500e35e 100644
--- a/chrome/browser/instant/instant_loader_delegate.h
+++ b/chrome/browser/instant/instant_loader_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -48,6 +48,9 @@ class InstantLoaderDelegate {
// Invoked if the loader swaps to a different TabContents.
virtual void SwappedTabContents(InstantLoader* loader) = 0;
+ // Invoked when the webcontents created by the loader is focused.
+ virtual void InstantLoaderContentsFocused() = 0;
+
protected:
virtual ~InstantLoaderDelegate() {}
};
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 15a3b04..6295d83 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -4572,6 +4572,11 @@ gfx::Rect Browser::GetInstantBounds() {
return window()->GetInstantBounds();
}
+void Browser::InstantPreviewFocused() {
+ // NOTE: This is only invoked on aura.
+ window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents());
+}
+
void Browser::OnWindowDidShow() {
if (window_has_shown_)
return;
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index b27c809..59e3387 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -1121,6 +1121,7 @@ class Browser : public TabHandlerDelegate,
virtual void SetSuggestedText(const string16& text,
InstantCompleteBehavior behavior) OVERRIDE;
virtual gfx::Rect GetInstantBounds() OVERRIDE;
+ virtual void InstantPreviewFocused() OVERRIDE;
// Command and state updating ///////////////////////////////////////////////
diff --git a/chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc b/chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc
index 2c88dc0..7fb250b 100644
--- a/chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc
+++ b/chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc
@@ -133,11 +133,13 @@ class LauncherUpdaterTest : public ChromeRenderViewHostTestHarness {
}
// aura::client::ActivationDelegate overrides.
- virtual bool ShouldActivate(aura::Event* event) { return true; }
- virtual void OnActivated() {
+ virtual bool ShouldActivate(const aura::Event* event) OVERRIDE {
+ return true;
+ }
+ virtual void OnActivated() OVERRIDE {
updater.BrowserActivationStateChanged();
}
- virtual void OnLostActive() {
+ virtual void OnLostActive() OVERRIDE {
updater.BrowserActivationStateChanged();
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 2b1d246..c79b2d7 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -41,6 +41,10 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/views_delegate.h"
+#if defined(USE_AURA)
+#include "ui/aura/root_window.h"
+#endif
+
#if defined(OS_WIN)
#include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
#endif
@@ -318,9 +322,16 @@ void OmniboxViewViews::HandleFocusIn() {
}
void OmniboxViewViews::HandleFocusOut() {
- // TODO(oshima): we don't have native view. This requires
- // further refactoring.
- model_->OnWillKillFocus(NULL);
+ gfx::NativeView native_view = NULL;
+#if defined(USE_AURA)
+ views::Widget* widget = GetWidget();
+ if (widget) {
+ aura::RootWindow* root = widget->GetNativeView()->GetRootWindow();
+ if (root)
+ native_view = root->focused_window();
+ }
+#endif
+ model_->OnWillKillFocus(native_view);
// Close the popup.
ClosePopup();
// Tell the model to reset itself.
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index 55b9b3c..b072f38 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -1020,7 +1020,9 @@ void RenderWidgetHostViewAura::OnWindowVisibilityChanged(bool visible) {
////////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
-bool RenderWidgetHostViewAura::ShouldActivate(aura::Event* event) {
+bool RenderWidgetHostViewAura::ShouldActivate(const aura::Event* event) {
+ if (event && event->type() == ui::ET_MOUSE_PRESSED)
+ host_->OnMouseActivate();
return is_fullscreen_;
}
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h
index 963fa8e..7b8f99a 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.h
+++ b/content/browser/renderer_host/render_widget_host_view_aura.h
@@ -166,7 +166,7 @@ class RenderWidgetHostViewAura
virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE;
// Overridden from aura::client::ActivationDelegate:
- virtual bool ShouldActivate(aura::Event* event) OVERRIDE;
+ virtual bool ShouldActivate(const aura::Event* event) OVERRIDE;
virtual void OnActivated() OVERRIDE;
virtual void OnLostActive() OVERRIDE;
diff --git a/ui/aura/client/activation_client.h b/ui/aura/client/activation_client.h
index 9893a34..ac5862f 100644
--- a/ui/aura/client/activation_client.h
+++ b/ui/aura/client/activation_client.h
@@ -10,7 +10,10 @@
#include "ui/aura/window.h"
namespace aura {
+
+class Event;
class RootWindow;
+
namespace client {
// An interface implemented by an object that manages window activation.
@@ -26,9 +29,9 @@ class AURA_EXPORT ActivationClient {
// Retrieves the active window, or NULL if there is none.
virtual aura::Window* GetActiveWindow() = 0;
- // Returns true if |window| can be focused. To be focusable, |window| must
- // exist inside an activatable window.
- virtual bool CanFocusWindow(Window* window) const = 0;
+ // Invoked prior to |window| getting focus as a result of the |event|. |event|
+ // may be NULL. Returning false blocks |window| from getting focus.
+ virtual bool OnWillFocusWindow(Window* window, const Event* event) = 0;
protected:
virtual ~ActivationClient() {}
diff --git a/ui/aura/client/activation_delegate.h b/ui/aura/client/activation_delegate.h
index 785b00b..8f9cf18 100644
--- a/ui/aura/client/activation_delegate.h
+++ b/ui/aura/client/activation_delegate.h
@@ -21,7 +21,7 @@ class AURA_EXPORT ActivationDelegate {
// event supplied if the activation is the result of a mouse, or the touch
// event if the activation is the result of a touch, or NULL if activation is
// attempted for another reason.
- virtual bool ShouldActivate(Event* event) = 0;
+ virtual bool ShouldActivate(const Event* event) = 0;
// Sent when the window is activated.
virtual void OnActivated() = 0;
diff --git a/ui/aura/event_filter_unittest.cc b/ui/aura/event_filter_unittest.cc
index 96a933d..f221724 100644
--- a/ui/aura/event_filter_unittest.cc
+++ b/ui/aura/event_filter_unittest.cc
@@ -99,7 +99,7 @@ TEST_F(EventFilterTest, Basic) {
w1->SetEventFilter(w1_filter);
w111->SetEventFilter(w111_filter);
- w1111->GetFocusManager()->SetFocusedWindow(w1111.get());
+ w1111->GetFocusManager()->SetFocusedWindow(w1111.get(), NULL);
// To start with, no one is going to consume any events. All three filters
// and the w1111's delegate should receive the event.
diff --git a/ui/aura/focus_manager.h b/ui/aura/focus_manager.h
index 1811455..d3ccefc 100644
--- a/ui/aura/focus_manager.h
+++ b/ui/aura/focus_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,8 @@
#include "ui/aura/aura_export.h"
namespace aura {
+
+class Event;
class Window;
namespace internal {
@@ -23,7 +25,7 @@ class AURA_EXPORT FocusManager {
// notification, and after it is changed the new focused window is sent a
// focused notification. Nothing happens if |window| and GetFocusedWindow()
// match.
- virtual void SetFocusedWindow(Window* window) = 0;
+ virtual void SetFocusedWindow(Window* window, const Event* event) = 0;
// Returns the currently focused window or NULL if there is none.
virtual Window* GetFocusedWindow() = 0;
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index f4db009..34c4793 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -690,10 +690,11 @@ void RootWindow::OnWindowHidden(Window* invisible, bool destroyed) {
if (focus_to &&
(!focus_to->IsVisible() ||
(client::GetActivationClient(this) &&
- !client::GetActivationClient(this)->CanFocusWindow(focus_to)))) {
+ !client::GetActivationClient(this)->OnWillFocusWindow(focus_to,
+ NULL)))) {
focus_to = NULL;
}
- SetFocusedWindow(focus_to);
+ SetFocusedWindow(focus_to, NULL);
}
// If the ancestor of the capture window is hidden,
// release the capture.
@@ -746,7 +747,8 @@ void RootWindow::OnLayerAnimationAborted(
ui::LayerAnimationSequence* animation) {
}
-void RootWindow::SetFocusedWindow(Window* focused_window) {
+void RootWindow::SetFocusedWindow(Window* focused_window,
+ const aura::Event* event) {
if (focused_window == focused_window_)
return;
if (focused_window && !focused_window->CanFocus())
@@ -755,7 +757,8 @@ void RootWindow::SetFocusedWindow(Window* focused_window) {
// activation client, since it is valid to clear the focus by calling
// SetFocusedWindow() to NULL.
if (focused_window && client::GetActivationClient(this) &&
- !client::GetActivationClient(this)->CanFocusWindow(focused_window)) {
+ !client::GetActivationClient(this)->OnWillFocusWindow(focused_window,
+ event)) {
return;
}
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index ba83940..7d12031 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -72,6 +72,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
bool cursor_shown() const { return cursor_shown_; }
Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
Window* capture_window() { return capture_window_; }
+ Window* focused_window() { return focused_window_; }
// Shows the root window host.
void ShowRootWindow();
@@ -245,7 +246,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
ui::LayerAnimationSequence* animation) OVERRIDE;
// Overridden from FocusManager:
- virtual void SetFocusedWindow(Window* window) OVERRIDE;
+ virtual void SetFocusedWindow(Window* window,
+ const aura::Event* event) OVERRIDE;
virtual Window* GetFocusedWindow() OVERRIDE;
virtual bool IsFocusedWindow(const Window* window) const OVERRIDE;
diff --git a/ui/aura/test/test_activation_client.cc b/ui/aura/test/test_activation_client.cc
index a1387f7..114bf91 100644
--- a/ui/aura/test/test_activation_client.cc
+++ b/ui/aura/test/test_activation_client.cc
@@ -54,7 +54,8 @@ Window* TestActivationClient::GetActiveWindow() {
return active_windows_.back();
}
-bool TestActivationClient::CanFocusWindow(Window* window) const {
+bool TestActivationClient::OnWillFocusWindow(Window* window,
+ const Event* event) {
return true;
}
diff --git a/ui/aura/test/test_activation_client.h b/ui/aura/test/test_activation_client.h
index 831cd9c..cd91c3b 100644
--- a/ui/aura/test/test_activation_client.h
+++ b/ui/aura/test/test_activation_client.h
@@ -25,7 +25,7 @@ class TestActivationClient : public client::ActivationClient,
virtual void ActivateWindow(Window* window) OVERRIDE;
virtual void DeactivateWindow(Window* window) OVERRIDE;
virtual Window* GetActiveWindow() OVERRIDE;
- virtual bool CanFocusWindow(Window* window) const OVERRIDE;
+ virtual bool OnWillFocusWindow(Window* window, const Event* event) OVERRIDE;
// Overridden from WindowObserver:
virtual void OnWindowDestroyed(Window* window) OVERRIDE;
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index fdb9145..8f08a4b 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -428,12 +428,12 @@ Window* Window::GetToplevelWindow() {
void Window::Focus() {
DCHECK(GetFocusManager());
- GetFocusManager()->SetFocusedWindow(this);
+ GetFocusManager()->SetFocusedWindow(this, NULL);
}
void Window::Blur() {
DCHECK(GetFocusManager());
- GetFocusManager()->SetFocusedWindow(NULL);
+ GetFocusManager()->SetFocusedWindow(NULL, NULL);
}
bool Window::HasFocus() const {
diff --git a/ui/views/controls/native/native_view_host_aura.cc b/ui/views/controls/native/native_view_host_aura.cc
index 331a728..8198311 100644
--- a/ui/views/controls/native/native_view_host_aura.cc
+++ b/ui/views/controls/native/native_view_host_aura.cc
@@ -85,7 +85,7 @@ void NativeViewHostAura::HideWidget() {
void NativeViewHostAura::SetFocus() {
aura::Window* window = host_->native_view();
if (window->GetFocusManager())
- window->GetFocusManager()->SetFocusedWindow(window);
+ window->GetFocusManager()->SetFocusedWindow(window, NULL);
}
gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() {
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index 67dfecf..08b3bde 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -594,12 +594,12 @@ void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
void NativeWidgetAura::ClearNativeFocus() {
if (window_ && window_->GetFocusManager() &&
window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) {
- window_->GetFocusManager()->SetFocusedWindow(window_);
+ window_->GetFocusManager()->SetFocusedWindow(window_, NULL);
}
}
void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) {
- window_->GetFocusManager()->SetFocusedWindow(native_view);
+ window_->GetFocusManager()->SetFocusedWindow(native_view, NULL);
}
gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const {
@@ -768,7 +768,7 @@ void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, aura::ActivationDelegate implementation:
-bool NativeWidgetAura::ShouldActivate(aura::Event* event) {
+bool NativeWidgetAura::ShouldActivate(const aura::Event* event) {
return can_activate_ && delegate_->CanActivate();
}
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index 7382e0a..f33f2ff 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -146,7 +146,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void OnWindowVisibilityChanged(bool visible) OVERRIDE;
// Overridden from aura::client::ActivationDelegate:
- virtual bool ShouldActivate(aura::Event* event) OVERRIDE;
+ virtual bool ShouldActivate(const aura::Event* event) OVERRIDE;
virtual void OnActivated() OVERRIDE;
virtual void OnLostActive() OVERRIDE;