summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 22:10:14 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 22:10:14 +0000
commita857dbe9dab3f8df2b452d8fac0e2f1795ac8926 (patch)
tree3417cecbbab60f2ad69f05c1157eb8a7bcd9192f /ash
parent800c8d730fc85e7bf9b548947f5842828346c485 (diff)
downloadchromium_src-a857dbe9dab3f8df2b452d8fac0e2f1795ac8926.zip
chromium_src-a857dbe9dab3f8df2b452d8fac0e2f1795ac8926.tar.gz
chromium_src-a857dbe9dab3f8df2b452d8fac0e2f1795ac8926.tar.bz2
Decouple FocusManager from RootWindow.
- Added FocusChangeObserver Store active window in ActivationController instead of in RootWindow as there will be multiple root windows. BUG=123160 TEST=no functional change. all tests must pass. Review URL: https://chromiumcodereview.appspot.com/10453019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/monitor/monitor_controller.cc28
-rw-r--r--ash/shell.cc28
-rw-r--r--ash/shell.h20
-rw-r--r--ash/wm/activation_controller.cc28
-rw-r--r--ash/wm/activation_controller.h8
-rw-r--r--ash/wm/app_list_controller.cc28
-rw-r--r--ash/wm/app_list_controller.h7
-rw-r--r--ash/wm/root_window_event_filter_unittest.cc7
8 files changed, 100 insertions, 54 deletions
diff --git a/ash/monitor/monitor_controller.cc b/ash/monitor/monitor_controller.cc
index 59c6b41..9bc85b4 100644
--- a/ash/monitor/monitor_controller.cc
+++ b/ash/monitor/monitor_controller.cc
@@ -5,13 +5,7 @@
#include "ash/monitor/monitor_controller.h"
#include "ash/monitor/multi_monitor_manager.h"
-#include "ash/monitor/secondary_monitor_view.h"
#include "ash/shell.h"
-#include "ash/wm/base_layout_manager.h"
-#include "ash/wm/root_window_layout_manager.h"
-#include "base/bind.h"
-#include "base/stl_util.h"
-#include "base/time.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
@@ -20,24 +14,6 @@
namespace ash {
namespace internal {
-namespace {
-
-void SetupAsSecondaryMonitor(aura::RootWindow* root) {
- root->SetFocusWhenShown(false);
- root->SetLayoutManager(new internal::RootWindowLayoutManager(root));
- aura::Window* container = new aura::Window(NULL);
- container->SetName("SecondaryMonitorContainer");
- container->Init(ui::LAYER_NOT_DRAWN);
- root->AddChild(container);
- container->SetLayoutManager(new internal::BaseLayoutManager(root));
- CreateSecondaryMonitorWidget(container);
- container->Show();
- root->layout_manager()->OnWindowResized();
- root->ShowRootWindow();
-}
-
-} // namespace
-
MonitorController::MonitorController() {
aura::Env::GetInstance()->monitor_manager()->AddObserver(this);
Init();
@@ -66,7 +42,7 @@ void MonitorController::OnMonitorAdded(const gfx::Monitor& monitor) {
aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()->
CreateRootWindowForMonitor(monitor);
root_windows_[monitor.id()] = root;
- SetupAsSecondaryMonitor(root);
+ Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root);
}
void MonitorController::OnMonitorRemoved(const gfx::Monitor& monitor) {
@@ -95,7 +71,7 @@ void MonitorController::Init() {
aura::RootWindow* root =
monitor_manager->CreateRootWindowForMonitor(monitor);
root_windows_[monitor.id()] = root;
- SetupAsSecondaryMonitor(root);
+ Shell::GetInstance()->InitRootWindowForSecondaryMonitor(root);
}
}
}
diff --git a/ash/shell.cc b/ash/shell.cc
index 9d4f7de..0b137f18 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -19,6 +19,7 @@
#include "ash/magnifier/magnification_controller.h"
#include "ash/monitor/monitor_controller.h"
#include "ash/monitor/multi_monitor_manager.h"
+#include "ash/monitor/secondary_monitor_view.h"
#include "ash/screen_ash.h"
#include "ash/shell_context_menu.h"
#include "ash/shell_delegate.h"
@@ -66,6 +67,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/monitor_manager.h"
#include "ui/aura/root_window.h"
@@ -652,12 +654,21 @@ aura::RootWindow* Shell::GetPrimaryRootWindow() {
return GetInstance()->root_window_.get();
}
+aura::RootWindow* Shell::GetActiveRootWindow() {
+ return GetInstance()->active_root_window_;
+}
+
void Shell::Init() {
// Install the custom factory first so that views::FocusManagers for Tray,
// Launcher, and WallPaper could be created by the factory.
views::FocusManagerFactory::Install(new AshFocusManagerFactory);
aura::RootWindow* root_window = GetPrimaryRootWindow();
+ active_root_window_ = root_window;
+
+ focus_manager_.reset(new aura::FocusManager);
+ root_window_->set_focus_manager(focus_manager_.get());
+
root_filter_ = new aura::shared::RootWindowEventFilter(root_window);
#if !defined(OS_MACOSX)
nested_dispatcher_controller_.reset(new NestedDispatcherController);
@@ -665,7 +676,7 @@ void Shell::Init() {
#endif
shell_context_menu_.reset(new internal::ShellContextMenu);
// Pass ownership of the filter to the root window.
- GetPrimaryRootWindow()->SetEventFilter(root_filter_);
+ root_window->SetEventFilter(root_filter_);
// KeyRewriterEventFilter must be the first one.
DCHECK(!GetRootWindowEventFilterCount());
@@ -920,6 +931,21 @@ bool Shell::IsInMaximizedMode() const {
return workspace_controller_->workspace_manager()->IsInMaximizedMode();
}
+void Shell::InitRootWindowForSecondaryMonitor(aura::RootWindow* root) {
+ root->set_focus_manager(focus_manager_.get());
+ root->SetFocusWhenShown(false);
+ root->SetLayoutManager(new internal::RootWindowLayoutManager(root));
+ aura::Window* container = new aura::Window(NULL);
+ container->SetName("SecondaryMonitorContainer");
+ container->Init(ui::LAYER_NOT_DRAWN);
+ root->AddChild(container);
+ container->SetLayoutManager(new internal::BaseLayoutManager(root));
+ CreateSecondaryMonitorWidget(container);
+ container->Show();
+ root->layout_manager()->OnWindowResized();
+ root->ShowRootWindow();
+}
+
////////////////////////////////////////////////////////////////////////////////
// Shell, private:
diff --git a/ash/shell.h b/ash/shell.h
index 12e7c15..e212335 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -25,6 +25,7 @@ class SkBitmap;
namespace aura {
class EventFilter;
+class FocusManager;
class Monitor;
class RootWindow;
class Window;
@@ -133,10 +134,20 @@ class ASH_EXPORT Shell {
static void DeleteInstance();
- // Gets the primary RootWindow. The primary RootWindow is the root window
+ // Gets the primary RootWindow. The primary RootWindow is the one
// that has a launcher.
static aura::RootWindow* GetPrimaryRootWindow();
+ // Gets the active RootWindow. The active RootWindow is the one that
+ // contains the current active window as a decendant child. The active
+ // RootWindow remains the same even when the active window becomes NULL,
+ // until the another window who has a different root window becomes active.
+ static aura::RootWindow* GetActiveRootWindow();
+
+ void set_active_root_window(aura::RootWindow* active_root_window) {
+ active_root_window_ = active_root_window;
+ }
+
internal::RootWindowLayoutManager* root_window_layout() const {
return root_window_layout_;
}
@@ -294,6 +305,9 @@ class ASH_EXPORT Shell {
browser_context_ = browser_context;
}
+ // Initialize the root window to be used for a secondary monitor.
+ void InitRootWindowForSecondaryMonitor(aura::RootWindow* root);
+
private:
FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, MouseEventCursors);
FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, TransformActivate);
@@ -320,6 +334,9 @@ class ASH_EXPORT Shell {
scoped_ptr<aura::RootWindow> root_window_;
ScreenAsh* screen_;
+ // Active root window. Never become NULL.
+ aura::RootWindow* active_root_window_;
+
aura::shared::RootWindowEventFilter* root_filter_; // not owned
std::vector<WindowAndBoundsPair> to_restore_;
@@ -358,6 +375,7 @@ class ASH_EXPORT Shell {
scoped_ptr<HighContrastController> high_contrast_controller_;
scoped_ptr<internal::MagnificationController> magnification_controller_;
scoped_ptr<internal::ScreenDimmer> screen_dimmer_;
+ scoped_ptr<aura::FocusManager> focus_manager_;
// An event filter that rewrites or drops a key event.
scoped_ptr<internal::KeyRewriterEventFilter> key_rewriter_filter_;
diff --git a/ash/wm/activation_controller.cc b/ash/wm/activation_controller.cc
index 8507508..0758571 100644
--- a/ash/wm/activation_controller.cc
+++ b/ash/wm/activation_controller.cc
@@ -12,6 +12,7 @@
#include "ui/aura/client/activation_delegate.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
@@ -117,15 +118,16 @@ void StackTransientParentsBelowModalWindow(aura::Window* window) {
ActivationController::ActivationController()
: updating_activation_(false),
+ active_window_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(observer_manager_(this)) {
aura::client::SetActivationClient(Shell::GetPrimaryRootWindow(), this);
aura::Env::GetInstance()->AddObserver(this);
- Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
+ Shell::GetPrimaryRootWindow()->GetFocusManager()->AddObserver(this);
}
ActivationController::~ActivationController() {
- Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this);
aura::Env::GetInstance()->RemoveObserver(this);
+ Shell::GetPrimaryRootWindow()->GetFocusManager()->RemoveObserver(this);
}
// static
@@ -165,8 +167,7 @@ void ActivationController::DeactivateWindow(aura::Window* window) {
}
aura::Window* ActivationController::GetActiveWindow() {
- return Shell::GetPrimaryRootWindow()->GetProperty(
- aura::client::kRootWindowActiveWindowKey);
+ return active_window_;
}
bool ActivationController::OnWillFocusWindow(aura::Window* window,
@@ -192,10 +193,15 @@ void ActivationController::OnWindowVisibilityChanged(aura::Window* window,
}
void ActivationController::OnWindowDestroying(aura::Window* window) {
- if (wm::IsActiveWindow(window)) {
+ // Don't use wm::IsActiveWidnow in case the |window| has
+ // removed from the root tree.
+ if (active_window_ == window) {
+ active_window_ = NULL;
// Clear the property before activating something else, since
// ActivateWindow() will attempt to notify the window stored in this value
// otherwise.
+ // TODO(oshima): NativeWidgetAura relies on this property now.
+ // Fix NativeWidgetAura not to depend on this and remove this.
Shell::GetPrimaryRootWindow()->ClearProperty(
aura::client::kRootWindowActiveWindowKey);
ActivateWindow(GetTopmostWindowToActivate(window));
@@ -258,8 +264,18 @@ void ActivationController::ActivateWindowWithEvent(aura::Window* window,
!window->Contains(window->GetFocusManager()->GetFocusedWindow())) {
window->GetFocusManager()->SetFocusedWindow(window, event);
}
+
+ active_window_ = window;
+ if (window) {
+ DCHECK(window->GetRootWindow());
+ Shell::GetInstance()->set_active_root_window(window->GetRootWindow());
+ }
+
+ // TODO(oshima): Remove this (see comment in OnWindowDestroying above)
Shell::GetPrimaryRootWindow()->SetProperty(
- aura::client::kRootWindowActiveWindowKey, window);
+ 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.
diff --git a/ash/wm/activation_controller.h b/ash/wm/activation_controller.h
index 32fe65e..b53c787 100644
--- a/ash/wm/activation_controller.h
+++ b/ash/wm/activation_controller.h
@@ -11,7 +11,7 @@
#include "base/compiler_specific.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/env_observer.h"
-#include "ui/aura/root_window_observer.h"
+#include "ui/aura/focus_change_observer.h"
#include "ui/aura/window_observer.h"
#include "ash/ash_export.h"
@@ -23,7 +23,7 @@ class ASH_EXPORT ActivationController
: public aura::client::ActivationClient,
public aura::WindowObserver,
public aura::EnvObserver,
- public aura::RootWindowObserver {
+ public aura::FocusChangeObserver {
public:
ActivationController();
virtual ~ActivationController();
@@ -50,7 +50,7 @@ class ASH_EXPORT ActivationController
// Overridden from aura::EnvObserver:
virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
- // Overridden from aura::RootWindowObserver:
+ // Overridden from aura::FocusChangeObserver:
virtual void OnWindowFocused(aura::Window* window) OVERRIDE;
private:
@@ -75,6 +75,8 @@ class ASH_EXPORT ActivationController
// change notifications causing activation.
bool updating_activation_;
+ aura::Window* active_window_;
+
ScopedObserver<aura::Window, aura::WindowObserver> observer_manager_;
DISALLOW_COPY_AND_ASSIGN(ActivationController);
diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc
index e95f4c4..fb6159b 100644
--- a/ash/wm/app_list_controller.cc
+++ b/ash/wm/app_list_controller.cc
@@ -15,6 +15,7 @@
#include "ui/app_list/app_list_view.h"
#include "ui/app_list/icon_cache.h"
#include "ui/aura/event.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
@@ -152,7 +153,7 @@ void AppListController::SetView(app_list::AppListView* view) {
widget->AddObserver(this);
Shell::GetInstance()->AddRootWindowEventFilter(this);
widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this);
-
+ widget->GetNativeView()->GetFocusManager()->AddObserver(this);
widget->SetOpacity(0);
ScheduleAnimation();
@@ -171,6 +172,7 @@ void AppListController::ResetView() {
GetLayer(widget)->GetAnimator()->RemoveObserver(this);
Shell::GetInstance()->RemoveRootWindowEventFilter(this);
widget->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this);
+ widget->GetNativeView()->GetFocusManager()->RemoveObserver(this);
view_ = NULL;
app_list::IconCache::GetInstance()->PurgeAllUnused();
@@ -292,17 +294,7 @@ ui::GestureStatus AppListController::PreHandleGestureEvent(
}
////////////////////////////////////////////////////////////////////////////////
-// AppListController, aura::RootWindowObserver implementation:
-void AppListController::OnRootWindowResized(const aura::RootWindow* root,
- const gfx::Size& old_size) {
- if (view_ && is_visible_) {
- views::Widget* launcher_widget =
- Shell::GetInstance()->launcher()->widget();
- view_->UpdateBounds(GetFullScreenBoundsForWidget(launcher_widget),
- GetWorkAreaBoundsForWidget(launcher_widget));
- }
-}
-
+// AppListController, aura::FocusObserver implementation:
void AppListController::OnWindowFocused(aura::Window* window) {
if (view_ && is_visible_) {
aura::Window* applist_container = Shell::GetInstance()->GetContainer(
@@ -317,6 +309,18 @@ void AppListController::OnWindowFocused(aura::Window* window) {
}
////////////////////////////////////////////////////////////////////////////////
+// AppListController, aura::RootWindowObserver implementation:
+void AppListController::OnRootWindowResized(const aura::RootWindow* root,
+ const gfx::Size& old_size) {
+ if (view_ && is_visible_) {
+ views::Widget* launcher_widget =
+ Shell::GetInstance()->launcher()->widget();
+ view_->UpdateBounds(GetFullScreenBoundsForWidget(launcher_widget),
+ GetWorkAreaBoundsForWidget(launcher_widget));
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
// AppListController, ui::ImplicitAnimationObserver implementation:
void AppListController::OnImplicitAnimationsCompleted() {
diff --git a/ash/wm/app_list_controller.h b/ash/wm/app_list_controller.h
index 3c7e7c2..bf6e863 100644
--- a/ash/wm/app_list_controller.h
+++ b/ash/wm/app_list_controller.h
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/timer.h"
#include "ui/aura/event_filter.h"
+#include "ui/aura/focus_change_observer.h"
#include "ui/aura/root_window_observer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/views/widget/widget.h"
@@ -27,6 +28,7 @@ namespace internal {
// While the UI is visible, it monitors things such as app list widget's
// activation state and desktop mouse click to auto dismiss the UI.
class AppListController : public aura::EventFilter,
+ public aura::FocusChangeObserver,
public aura::RootWindowObserver,
public ui::ImplicitAnimationObserver,
public views::Widget::Observer,
@@ -86,10 +88,12 @@ class AppListController : public aura::EventFilter,
aura::Window* target,
aura::GestureEvent* event) OVERRIDE;
+ // aura::FocusChangeObserver overrides:
+ virtual void OnWindowFocused(aura::Window* window) OVERRIDE;
+
// aura::RootWindowObserver overrides:
virtual void OnRootWindowResized(const aura::RootWindow* root,
const gfx::Size& old_size) OVERRIDE;
- virtual void OnWindowFocused(aura::Window* window) OVERRIDE;
// ui::ImplicitAnimationObserver overrides:
virtual void OnImplicitAnimationsCompleted() OVERRIDE;
@@ -117,4 +121,3 @@ class AppListController : public aura::EventFilter,
} // namespace ash
#endif // ASH_WM_APP_LIST_CONTROLLER_H_
-
diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc
index 5f61056..10fb0442 100644
--- a/ash/wm/root_window_event_filter_unittest.cc
+++ b/ash/wm/root_window_event_filter_unittest.cc
@@ -11,6 +11,7 @@
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/activation_delegate.h"
#include "ui/aura/event.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/shared/input_method_event_filter.h"
#include "ui/aura/shared/root_window_event_filter.h"
@@ -112,7 +113,7 @@ TEST_F(RootWindowEventFilterTest, Focus) {
w121.get());
generator.ClickLeftButton();
- aura::internal::FocusManager* focus_manager = w121->GetFocusManager();
+ aura::FocusManager* focus_manager = w121->GetFocusManager();
EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow());
// The key press should be sent to the focused sub-window.
@@ -191,7 +192,7 @@ TEST_F(RootWindowEventFilterTest, ActivateOnMouse) {
&wd, -1, gfx::Rect(70, 70, 50, 50), NULL));
d2.SetWindow(w2.get());
- aura::internal::FocusManager* focus_manager = w1->GetFocusManager();
+ aura::FocusManager* focus_manager = w1->GetFocusManager();
d1.Clear();
d2.Clear();
@@ -307,7 +308,7 @@ TEST_F(RootWindowEventFilterTest, ActivateOnTouch) {
&wd, -2, gfx::Rect(70, 70, 50, 50), NULL));
d2.SetWindow(w2.get());
- aura::internal::FocusManager* focus_manager = w1->GetFocusManager();
+ aura::FocusManager* focus_manager = w1->GetFocusManager();
d1.Clear();
d2.Clear();