Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: components/exo/wm_helper.cc

Issue 2250863003: exo: Run exo in mus+ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/wm_helper.h ('k') | components/exo/wm_helper_ash.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 8 #include "components/exo/wm_helper_ash.h"
9 #include "ash/display/display_manager.h" 9 #include "components/exo/wm_helper_mus.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 10
15 namespace exo { 11 namespace exo {
12 namespace {
13 WMHelper* g_instance = nullptr;
14 }
16 15
17 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
18 // WMHelper, public: 17 // WMHelper, public:
19 18
20 WMHelper::WMHelper() { 19 WMHelper::WMHelper() {
21 ash::WmShell::Get()->AddShellObserver(this); 20 DCHECK(!g_instance);
22 ash::Shell::GetInstance()->activation_client()->AddObserver(this); 21 g_instance = this;
23 aura::client::FocusClient* focus_client =
24 aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow());
25 focus_client->AddObserver(this);
26 } 22 }
27 23
28 WMHelper::~WMHelper() { 24 WMHelper::~WMHelper() {
29 if (!ash::Shell::HasInstance()) 25 DCHECK(g_instance == this);
30 return; 26 g_instance = nullptr;
31 aura::client::FocusClient* focus_client = 27 }
32 aura::client::GetFocusClient(ash::Shell::GetPrimaryRootWindow()); 28
33 focus_client->AddObserver(this); 29 // static
34 focus_client->RemoveObserver(this); 30 std::unique_ptr<WMHelper> WMHelper::Create(bool using_mus) {
reveman 2016/08/17 20:01:41 Can we add a "void SetInstance(WMHelper* helper)"
Peng 2016/08/17 20:25:36 Done.
35 ash::Shell::GetInstance()->activation_client()->RemoveObserver(this); 31 if (using_mus)
36 ash::WmShell::Get()->RemoveShellObserver(this); 32 return base::WrapUnique(new WMHelperMus);
33 return base::WrapUnique(new WMHelperAsh);
37 } 34 }
38 35
39 // static 36 // static
40 WMHelper* WMHelper::GetInstance() { 37 WMHelper* WMHelper::GetInstance() {
41 return base::Singleton<WMHelper>::get(); 38 DCHECK(g_instance);
42 } 39 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 } 40 }
58 41
59 void WMHelper::AddActivationObserver(ActivationObserver* observer) { 42 void WMHelper::AddActivationObserver(ActivationObserver* observer) {
60 activation_observers_.AddObserver(observer); 43 activation_observers_.AddObserver(observer);
61 } 44 }
62 45
63 void WMHelper::RemoveActivationObserver(ActivationObserver* observer) { 46 void WMHelper::RemoveActivationObserver(ActivationObserver* observer) {
64 activation_observers_.RemoveObserver(observer); 47 activation_observers_.RemoveObserver(observer);
65 } 48 }
66 49
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) { 50 void WMHelper::AddFocusObserver(FocusObserver* observer) {
74 focus_observers_.AddObserver(observer); 51 focus_observers_.AddObserver(observer);
75 } 52 }
76 53
77 void WMHelper::RemoveFocusObserver(FocusObserver* observer) { 54 void WMHelper::RemoveFocusObserver(FocusObserver* observer) {
78 focus_observers_.RemoveObserver(observer); 55 focus_observers_.RemoveObserver(observer);
79 } 56 }
80 57
81 ui::CursorSetType WMHelper::GetCursorSet() const {
82 return ash::Shell::GetInstance()->cursor_manager()->GetCursorSet();
83 }
84
85 void WMHelper::AddCursorObserver(CursorObserver* observer) { 58 void WMHelper::AddCursorObserver(CursorObserver* observer) {
86 cursor_observers_.AddObserver(observer); 59 cursor_observers_.AddObserver(observer);
87 } 60 }
88 61
89 void WMHelper::RemoveCursorObserver(CursorObserver* observer) { 62 void WMHelper::RemoveCursorObserver(CursorObserver* observer) {
90 cursor_observers_.RemoveObserver(observer); 63 cursor_observers_.RemoveObserver(observer);
91 } 64 }
92 65
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) { 66 void WMHelper::AddMaximizeModeObserver(MaximizeModeObserver* observer) {
120 maximize_mode_observers_.AddObserver(observer); 67 maximize_mode_observers_.AddObserver(observer);
121 } 68 }
122 69
123 void WMHelper::RemoveMaximizeModeObserver(MaximizeModeObserver* observer) { 70 void WMHelper::RemoveMaximizeModeObserver(MaximizeModeObserver* observer) {
124 maximize_mode_observers_.RemoveObserver(observer); 71 maximize_mode_observers_.RemoveObserver(observer);
125 } 72 }
126 73
127 void WMHelper::OnWindowActivated( 74 void WMHelper::NotifyWindowActivated(aura::Window* gained_active,
128 aura::client::ActivationChangeObserver::ActivationReason reason, 75 aura::Window* lost_active) {
129 aura::Window* gained_active,
130 aura::Window* lost_active) {
131 FOR_EACH_OBSERVER(ActivationObserver, activation_observers_, 76 FOR_EACH_OBSERVER(ActivationObserver, activation_observers_,
132 OnWindowActivated(gained_active, lost_active)); 77 OnWindowActivated(gained_active, lost_active));
133 } 78 }
134 79
135 void WMHelper::OnWindowFocused(aura::Window* gained_focus, 80 void WMHelper::NotifyWindowFocused(aura::Window* gained_focus,
136 aura::Window* lost_focus) { 81 aura::Window* lost_focus) {
137 FOR_EACH_OBSERVER(FocusObserver, focus_observers_, 82 FOR_EACH_OBSERVER(FocusObserver, focus_observers_,
138 OnWindowFocused(gained_focus, lost_focus)); 83 OnWindowFocused(gained_focus, lost_focus));
139 } 84 }
140 85
141 void WMHelper::OnCursorVisibilityChanged(bool is_visible) { 86 void WMHelper::NotifyCursorVisibilityChanged(bool is_visible) {
142 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, 87 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_,
143 OnCursorVisibilityChanged(is_visible)); 88 OnCursorVisibilityChanged(is_visible));
144 } 89 }
145 90
146 void WMHelper::OnCursorSetChanged(ui::CursorSetType cursor_set) { 91 void WMHelper::NotifyCursorSetChanged(ui::CursorSetType cursor_set) {
147 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_, 92 FOR_EACH_OBSERVER(CursorObserver, cursor_observers_,
148 OnCursorSetChanged(cursor_set)); 93 OnCursorSetChanged(cursor_set));
149 } 94 }
150 95
151 void WMHelper::OnMaximizeModeStarted() { 96 void WMHelper::NotifyMaximizeModeStarted() {
152 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, 97 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_,
153 OnMaximizeModeStarted()); 98 OnMaximizeModeStarted());
154 } 99 }
155 100
156 void WMHelper::OnMaximizeModeEnded() { 101 void WMHelper::NotifyMaximizeModeEnded() {
157 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_, 102 FOR_EACH_OBSERVER(MaximizeModeObserver, maximize_mode_observers_,
158 OnMaximizeModeEnded()); 103 OnMaximizeModeEnded());
159 } 104 }
160 105
161 } // namespace exo 106 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/wm_helper.h ('k') | components/exo/wm_helper_ash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698