OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/mus/bridge/wm_globals_mus.h" | |
6 | |
7 #include "ash/common/shell_window_ids.h" | |
8 #include "ash/common/wm/window_resizer.h" | |
9 #include "ash/common/wm/wm_activation_observer.h" | |
10 #include "ash/mus/bridge/wm_root_window_controller_mus.h" | |
11 #include "ash/mus/bridge/wm_window_mus.h" | |
12 #include "ash/mus/container_ids.h" | |
13 #include "ash/mus/drag_window_resizer.h" | |
14 #include "ash/mus/root_window_controller.h" | |
15 #include "base/memory/ptr_util.h" | |
16 #include "components/mus/common/util.h" | |
17 #include "components/mus/public/cpp/window.h" | |
18 #include "components/mus/public/cpp/window_tree_client.h" | |
19 | |
20 namespace ash { | |
21 namespace mus { | |
22 | |
23 WmGlobalsMus::WmGlobalsMus(::mus::WindowTreeClient* client) : client_(client) { | |
24 client_->AddObserver(this); | |
25 WmGlobals::Set(this); | |
26 } | |
27 | |
28 WmGlobalsMus::~WmGlobalsMus() { | |
29 RemoveClientObserver(); | |
30 WmGlobals::Set(nullptr); | |
31 } | |
32 | |
33 // static | |
34 WmGlobalsMus* WmGlobalsMus::Get() { | |
35 return static_cast<WmGlobalsMus*>(wm::WmGlobals::Get()); | |
36 } | |
37 | |
38 void WmGlobalsMus::AddRootWindowController( | |
39 WmRootWindowControllerMus* controller) { | |
40 root_window_controllers_.push_back(controller); | |
41 } | |
42 | |
43 void WmGlobalsMus::RemoveRootWindowController( | |
44 WmRootWindowControllerMus* controller) { | |
45 auto iter = std::find(root_window_controllers_.begin(), | |
46 root_window_controllers_.end(), controller); | |
47 DCHECK(iter != root_window_controllers_.end()); | |
48 root_window_controllers_.erase(iter); | |
49 } | |
50 | |
51 // static | |
52 WmWindowMus* WmGlobalsMus::GetToplevelAncestor(::mus::Window* window) { | |
53 while (window) { | |
54 if (IsActivationParent(window->parent())) | |
55 return WmWindowMus::Get(window); | |
56 window = window->parent(); | |
57 } | |
58 return nullptr; | |
59 } | |
60 | |
61 WmRootWindowControllerMus* WmGlobalsMus::GetRootWindowControllerWithDisplayId( | |
62 int64_t id) { | |
63 for (WmRootWindowControllerMus* root_window_controller : | |
64 root_window_controllers_) { | |
65 if (root_window_controller->GetDisplay().id() == id) | |
66 return root_window_controller; | |
67 } | |
68 NOTREACHED(); | |
69 return nullptr; | |
70 } | |
71 | |
72 wm::WmWindow* WmGlobalsMus::NewContainerWindow() { | |
73 return WmWindowMus::Get(client_->NewWindow()); | |
74 } | |
75 | |
76 wm::WmWindow* WmGlobalsMus::GetFocusedWindow() { | |
77 return WmWindowMus::Get(client_->GetFocusedWindow()); | |
78 } | |
79 | |
80 wm::WmWindow* WmGlobalsMus::GetActiveWindow() { | |
81 return GetToplevelAncestor(client_->GetFocusedWindow()); | |
82 } | |
83 | |
84 wm::WmWindow* WmGlobalsMus::GetPrimaryRootWindow() { | |
85 return root_window_controllers_[0]->GetWindow(); | |
86 } | |
87 | |
88 wm::WmWindow* WmGlobalsMus::GetRootWindowForDisplayId(int64_t display_id) { | |
89 return GetRootWindowControllerWithDisplayId(display_id)->GetWindow(); | |
90 } | |
91 | |
92 wm::WmWindow* WmGlobalsMus::GetRootWindowForNewWindows() { | |
93 NOTIMPLEMENTED(); | |
94 return root_window_controllers_[0]->GetWindow(); | |
95 } | |
96 | |
97 std::vector<wm::WmWindow*> WmGlobalsMus::GetMruWindowList() { | |
98 NOTIMPLEMENTED(); | |
99 return std::vector<wm::WmWindow*>(); | |
100 } | |
101 | |
102 std::vector<wm::WmWindow*> WmGlobalsMus::GetMruWindowListIgnoreModals() { | |
103 NOTIMPLEMENTED(); | |
104 return std::vector<wm::WmWindow*>(); | |
105 } | |
106 | |
107 bool WmGlobalsMus::IsForceMaximizeOnFirstRun() { | |
108 NOTIMPLEMENTED(); | |
109 return false; | |
110 } | |
111 | |
112 bool WmGlobalsMus::IsUserSessionBlocked() { | |
113 NOTIMPLEMENTED(); | |
114 return false; | |
115 } | |
116 | |
117 bool WmGlobalsMus::IsScreenLocked() { | |
118 NOTIMPLEMENTED(); | |
119 return false; | |
120 } | |
121 | |
122 void WmGlobalsMus::LockCursor() { | |
123 NOTIMPLEMENTED(); | |
124 } | |
125 | |
126 void WmGlobalsMus::UnlockCursor() { | |
127 NOTIMPLEMENTED(); | |
128 } | |
129 | |
130 std::vector<wm::WmWindow*> WmGlobalsMus::GetAllRootWindows() { | |
131 std::vector<wm::WmWindow*> wm_windows(root_window_controllers_.size()); | |
132 for (size_t i = 0; i < root_window_controllers_.size(); ++i) | |
133 wm_windows[i] = root_window_controllers_[i]->GetWindow(); | |
134 return wm_windows; | |
135 } | |
136 | |
137 void WmGlobalsMus::RecordUserMetricsAction(wm::WmUserMetricsAction action) { | |
138 NOTIMPLEMENTED(); | |
139 } | |
140 | |
141 std::unique_ptr<WindowResizer> WmGlobalsMus::CreateDragWindowResizer( | |
142 std::unique_ptr<WindowResizer> next_window_resizer, | |
143 wm::WindowState* window_state) { | |
144 return base::WrapUnique( | |
145 new DragWindowResizer(std::move(next_window_resizer), window_state)); | |
146 } | |
147 | |
148 bool WmGlobalsMus::IsOverviewModeSelecting() { | |
149 NOTIMPLEMENTED(); | |
150 return false; | |
151 } | |
152 | |
153 bool WmGlobalsMus::IsOverviewModeRestoringMinimizedWindows() { | |
154 NOTIMPLEMENTED(); | |
155 return false; | |
156 } | |
157 | |
158 void WmGlobalsMus::AddActivationObserver(wm::WmActivationObserver* observer) { | |
159 activation_observers_.AddObserver(observer); | |
160 } | |
161 | |
162 void WmGlobalsMus::RemoveActivationObserver( | |
163 wm::WmActivationObserver* observer) { | |
164 activation_observers_.RemoveObserver(observer); | |
165 } | |
166 | |
167 void WmGlobalsMus::AddDisplayObserver(wm::WmDisplayObserver* observer) { | |
168 NOTIMPLEMENTED(); | |
169 } | |
170 | |
171 void WmGlobalsMus::RemoveDisplayObserver(wm::WmDisplayObserver* observer) { | |
172 NOTIMPLEMENTED(); | |
173 } | |
174 | |
175 void WmGlobalsMus::AddOverviewModeObserver( | |
176 wm::WmOverviewModeObserver* observer) { | |
177 NOTIMPLEMENTED(); | |
178 } | |
179 | |
180 void WmGlobalsMus::RemoveOverviewModeObserver( | |
181 wm::WmOverviewModeObserver* observer) { | |
182 NOTIMPLEMENTED(); | |
183 } | |
184 | |
185 // static | |
186 bool WmGlobalsMus::IsActivationParent(::mus::Window* window) { | |
187 if (!window) | |
188 return false; | |
189 | |
190 for (size_t i = 0; i < kNumActivationContainers; ++i) { | |
191 if (window->local_id() == static_cast<int>(kActivationContainers[i])) | |
192 return true; | |
193 } | |
194 return false; | |
195 } | |
196 | |
197 void WmGlobalsMus::RemoveClientObserver() { | |
198 if (!client_) | |
199 return; | |
200 | |
201 client_->RemoveObserver(this); | |
202 client_ = nullptr; | |
203 } | |
204 | |
205 // TODO: support OnAttemptToReactivateWindow, http://crbug.com/615114. | |
206 void WmGlobalsMus::OnWindowTreeFocusChanged(::mus::Window* gained_focus, | |
207 ::mus::Window* lost_focus) { | |
208 WmWindowMus* gained_active = GetToplevelAncestor(gained_focus); | |
209 WmWindowMus* lost_active = GetToplevelAncestor(gained_focus); | |
210 if (gained_active == lost_active) | |
211 return; | |
212 | |
213 FOR_EACH_OBSERVER(wm::WmActivationObserver, activation_observers_, | |
214 OnWindowActivated(gained_active, lost_active)); | |
215 } | |
216 | |
217 void WmGlobalsMus::OnWillDestroyClient(::mus::WindowTreeClient* client) { | |
218 DCHECK_EQ(client, client_); | |
219 RemoveClientObserver(); | |
220 } | |
221 | |
222 } // namespace mus | |
223 } // namespace ash | |
OLD | NEW |