| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/exo/wm_helper.h" | 5 #include "components/exo/wm_helper.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ash/common/wm_shell.h" | |
| 9 #include "ash/display/display_manager.h" | |
| 10 #include "ash/shell.h" | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "ui/aura/client/focus_client.h" | |
| 13 #include "ui/wm/public/activation_client.h" | |
| 14 | 8 |
| 15 namespace exo { | 9 namespace exo { |
| 10 namespace { |
| 11 WMHelper* g_instance = nullptr; |
| 12 } |
| 16 | 13 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 14 //////////////////////////////////////////////////////////////////////////////// |
| 18 // WMHelper, public: | 15 // WMHelper, public: |
| 19 | 16 |
| 20 WMHelper::WMHelper() { | 17 WMHelper::WMHelper() {} |
| 21 ash::WmShell::Get()->AddShellObserver(this); | |
| 22 ash::Shell::GetInstance()->activation_client()->AddObserver(this); | |
| 23 aura::client::FocusClient* focus_client = | |
| 24 aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow()); | |
| 25 focus_client->AddObserver(this); | |
| 26 } | |
| 27 | 18 |
| 28 WMHelper::~WMHelper() { | 19 WMHelper::~WMHelper() {} |
| 29 if (!ash::Shell::HasInstance()) | 20 |
| 30 return; | 21 // static |
| 31 aura::client::FocusClient* focus_client = | 22 void WMHelper::SetInstance(WMHelper* helper) { |
| 32 aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow()); | 23 DCHECK_NE(!!helper, !!g_instance); |
| 33 focus_client->AddObserver(this); | 24 g_instance = helper; |
| 34 focus_client->RemoveObserver(this); | |
| 35 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); | |
| 36 ash::WmShell::Get()->RemoveShellObserver(this); | |
| 37 } | 25 } |
| 38 | 26 |
| 39 // static | 27 // static |
| 40 WMHelper* WMHelper::GetInstance() { | 28 WMHelper* WMHelper::GetInstance() { |
| 41 return base::Singleton<WMHelper>::get(); | 29 DCHECK(g_instance); |
| 42 } | 30 return g_instance; |
| 43 | |
| 44 const ash::DisplayInfo& WMHelper::GetDisplayInfo(int64_t display_id) const { | |
| 45 return ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( | |
| 46 display_id); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 aura::Window* WMHelper::GetContainer(int container_id) { | |
| 51 return ash::Shell::GetContainer(ash::Shell::GetTargetRootWindow(), | |
| 52 container_id); | |
| 53 } | |
| 54 | |
| 55 aura::Window* WMHelper::GetActiveWindow() const { | |
| 56 return ash::Shell::GetInstance()->activation_client()->GetActiveWindow(); | |
| 57 } | 31 } |
| 58 | 32 |
| 59 void WMHelper::AddActivationObserver(ActivationObserver* observer) { | 33 void WMHelper::AddActivationObserver(ActivationObserver* observer) { |
| 60 activation_observers_.AddObserver(observer); | 34 activation_observers_.AddObserver(observer); |
| 61 } | 35 } |
| 62 | 36 |
| 63 void WMHelper::RemoveActivationObserver(ActivationObserver* observer) { | 37 void WMHelper::RemoveActivationObserver(ActivationObserver* observer) { |
| 64 activation_observers_.RemoveObserver(observer); | 38 activation_observers_.RemoveObserver(observer); |
| 65 } | 39 } |
| 66 | 40 |
| 67 aura::Window* WMHelper::GetFocusedWindow() const { | |
| 68 aura::client::FocusClient* focus_client = | |
| 69 aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow()); | |
| 70 return focus_client->GetFocusedWindow(); | |
| 71 } | |
| 72 | |
| 73 void WMHelper::AddFocusObserver(FocusObserver* observer) { | 41 void WMHelper::AddFocusObserver(FocusObserver* observer) { |
| 74 focus_observers_.AddObserver(observer); | 42 focus_observers_.AddObserver(observer); |
| 75 } | 43 } |
| 76 | 44 |
| 77 void WMHelper::RemoveFocusObserver(FocusObserver* observer) { | 45 void WMHelper::RemoveFocusObserver(FocusObserver* observer) { |
| 78 focus_observers_.RemoveObserver(observer); | 46 focus_observers_.RemoveObserver(observer); |
| 79 } | 47 } |
| 80 | 48 |
| 81 ui::CursorSetType WMHelper::GetCursorSet() const { | |
| 82 return ash::Shell::GetInstance()->cursor_manager()->GetCursorSet(); | |
| 83 } | |
| 84 | |
| 85 void WMHelper::AddCursorObserver(CursorObserver* observer) { | 49 void WMHelper::AddCursorObserver(CursorObserver* observer) { |
| 86 cursor_observers_.AddObserver(observer); | 50 cursor_observers_.AddObserver(observer); |
| 87 } | 51 } |
| 88 | 52 |
| 89 void WMHelper::RemoveCursorObserver(CursorObserver* observer) { | 53 void WMHelper::RemoveCursorObserver(CursorObserver* observer) { |
| 90 cursor_observers_.RemoveObserver(observer); | 54 cursor_observers_.RemoveObserver(observer); |
| 91 } | 55 } |
| 92 | 56 |
| 93 void WMHelper::AddPreTargetHandler(ui::EventHandler* handler) { | |
| 94 ash::Shell::GetInstance()->AddPreTargetHandler(handler); | |
| 95 } | |
| 96 | |
| 97 void WMHelper::PrependPreTargetHandler(ui::EventHandler* handler) { | |
| 98 ash::Shell::GetInstance()->PrependPreTargetHandler(handler); | |
| 99 } | |
| 100 | |
| 101 void WMHelper::RemovePreTargetHandler(ui::EventHandler* handler) { | |
| 102 ash::Shell::GetInstance()->RemovePreTargetHandler(handler); | |
| 103 } | |
| 104 | |
| 105 void WMHelper::AddPostTargetHandler(ui::EventHandler* handler) { | |
| 106 ash::Shell::GetInstance()->AddPostTargetHandler(handler); | |
| 107 } | |
| 108 | |
| 109 void WMHelper::RemovePostTargetHandler(ui::EventHandler* handler) { | |
| 110 ash::Shell::GetInstance()->RemovePostTargetHandler(handler); | |
| 111 } | |
| 112 | |
| 113 bool WMHelper::IsMaximizeModeWindowManagerEnabled() const { | |
| 114 return ash::WmShell::Get() | |
| 115 ->maximize_mode_controller() | |
| 116 ->IsMaximizeModeWindowManagerEnabled(); | |
| 117 } | |
| 118 | |
| 119 void WMHelper::AddMaximizeModeObserver(MaximizeModeObserver* observer) { | 57 void WMHelper::AddMaximizeModeObserver(MaximizeModeObserver* observer) { |
| 120 maximize_mode_observers_.AddObserver(observer); | 58 maximize_mode_observers_.AddObserver(observer); |
| 121 } | 59 } |
| 122 | 60 |
| 123 void WMHelper::RemoveMaximizeModeObserver(MaximizeModeObserver* observer) { | 61 void WMHelper::RemoveMaximizeModeObserver(MaximizeModeObserver* observer) { |
| 124 maximize_mode_observers_.RemoveObserver(observer); | 62 maximize_mode_observers_.RemoveObserver(observer); |
| 125 } | 63 } |
| 126 | 64 |
| 127 void WMHelper::OnWindowActivated( | 65 void WMHelper::NotifyWindowActivated(aura::Window* gained_active, |
| 128 aura::client::ActivationChangeObserver::ActivationReason reason, | 66 aura::Window* lost_active) { |
| 129 aura::Window* gained_active, | |
| 130 aura::Window* lost_active) { | |
| 131 FOR_EACH_OBSERVER(ActivationObserver, activation_observers_, | 67 FOR_EACH_OBSERVER(ActivationObserver, activation_observers_, |
| 132 OnWindowActivated(gained_active, lost_active)); | 68 OnWindowActivated(gained_active, lost_active)); |
| 133 } | 69 } |
| 134 | 70 |
| 135 void WMHelper::OnWindowFocused(aura::Window* gained_focus, | 71 void WMHelper::NotifyWindowFocused(aura::Window* gained_focus, |
| 136 aura::Window* lost_focus) { | 72 aura::Window* lost_focus) { |
| 137 FOR_EACH_OBSERVER(FocusObserver, focus_observers_, | 73 FOR_EACH_OBSERVER(FocusObserver, focus_observers_, |
| 138 OnWindowFocused(gained_focus, lost_focus)); | 74 OnWindowFocused(gained_focus, lost_focus)); |
| 139 } | 75 } |
| 140 | 76 |
| 141 void WMHelper::OnCursorVisibilityChanged(bool is_visible) { | 77 void WMHelper::NotifyCursorVisibilityChanged(bool is_visible) { |
| 142 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, | 78 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, |
| 143 OnCursorVisibilityChanged(is_visible)); | 79 OnCursorVisibilityChanged(is_visible)); |
| 144 } | 80 } |
| 145 | 81 |
| 146 void WMHelper::OnCursorSetChanged(ui::CursorSetType cursor_set) { | 82 void WMHelper::NotifyCursorSetChanged(ui::CursorSetType cursor_set) { |
| 147 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, | 83 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, |
| 148 OnCursorSetChanged(cursor_set)); | 84 OnCursorSetChanged(cursor_set)); |
| 149 } | 85 } |
| 150 | 86 |
| 151 void WMHelper::OnMaximizeModeStarted() { | 87 void WMHelper::NotifyMaximizeModeStarted() { |
| 152 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, | 88 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, |
| 153 OnMaximizeModeStarted()); | 89 OnMaximizeModeStarted()); |
| 154 } | 90 } |
| 155 | 91 |
| 156 void WMHelper::OnMaximizeModeEnded() { | 92 void WMHelper::NotifyMaximizeModeEnded() { |
| 157 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, | 93 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, |
| 158 OnMaximizeModeEnded()); | 94 OnMaximizeModeEnded()); |
| 159 } | 95 } |
| 160 | 96 |
| 161 } // namespace exo | 97 } // namespace exo |
| OLD | NEW |