Chromium Code Reviews| Index: ash/wm/aura/wm_globals_aura.cc |
| diff --git a/ash/wm/aura/wm_globals_aura.cc b/ash/wm/aura/wm_globals_aura.cc |
| index 0895ce17fda8169cb56b3f9d9b7e4b3f93a8c845..1fe39cb62c461e058190e65bfcc247e74b3fd497 100644 |
| --- a/ash/wm/aura/wm_globals_aura.cc |
| +++ b/ash/wm/aura/wm_globals_aura.cc |
| @@ -9,8 +9,10 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_delegate.h" |
| #include "ash/wm/aura/wm_window_aura.h" |
| +#include "ash/wm/common/wm_activation_observer.h" |
| #include "ash/wm/mru_window_tracker.h" |
| #include "ash/wm/window_util.h" |
| +#include "ui/aura/client/focus_client.h" |
| #include "ui/wm/public/activation_client.h" |
| namespace ash { |
| @@ -33,6 +35,10 @@ WmGlobalsAura::WmGlobalsAura() { |
| WmGlobalsAura::~WmGlobalsAura() { |
| instance_ = nullptr; |
| + if (added_activation_observer_) { |
| + aura::client::GetActivationClient(Shell::GetPrimaryRootWindow()) |
|
varkha
2016/04/21 14:56:09
I think this fails in the tests. Is that because S
|
| + ->RemoveObserver(this); |
| + } |
| } |
| // static |
| @@ -42,6 +48,12 @@ WmGlobalsAura* WmGlobalsAura::Get() { |
| return instance_; |
| } |
| +WmWindow* WmGlobalsAura::GetFocusedWindow() { |
| + return WmWindowAura::Get( |
| + aura::client::GetFocusClient(Shell::GetPrimaryRootWindow()) |
| + ->GetFocusedWindow()); |
| +} |
| + |
| WmWindow* WmGlobalsAura::GetActiveWindow() { |
| return WmWindowAura::Get(wm::GetActiveWindow()); |
| } |
| @@ -86,5 +98,27 @@ std::vector<WmWindow*> WmGlobalsAura::GetAllRootWindows() { |
| return wm_windows; |
| } |
| +void WmGlobalsAura::AddActivationObserver(WmActivationObserver* observer) { |
| + if (!added_activation_observer_) { |
| + added_activation_observer_ = true; |
| + aura::client::GetActivationClient(Shell::GetPrimaryRootWindow()) |
| + ->AddObserver(this); |
| + } |
| + activation_observers_.AddObserver(observer); |
| +} |
| + |
| +void WmGlobalsAura::RemoveActivationObserver(WmActivationObserver* observer) { |
| + activation_observers_.RemoveObserver(observer); |
| +} |
| + |
| +void WmGlobalsAura::OnWindowActivated( |
| + aura::client::ActivationChangeObserver::ActivationReason reason, |
| + aura::Window* gained_active, |
| + aura::Window* lost_active) { |
| + FOR_EACH_OBSERVER(WmActivationObserver, activation_observers_, |
| + OnWindowActivated(WmWindowAura::Get(gained_active), |
| + WmWindowAura::Get(lost_active))); |
| +} |
| + |
| } // namespace wm |
| } // namespace ash |