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 "ash/mus/root_window_controller.h" | 5 #include "ash/mus/root_window_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <sstream> | 10 #include <sstream> |
11 | 11 |
12 #include "ash/common/root_window_controller_common.h" | |
12 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
13 #include "ash/common/wm/always_on_top_controller.h" | 14 #include "ash/common/wm/always_on_top_controller.h" |
14 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 15 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
15 #include "ash/common/wm/panels/panel_layout_manager.h" | 16 #include "ash/common/wm/panels/panel_layout_manager.h" |
17 #include "ash/common/wm/root_window_layout_manager.h" | |
16 #include "ash/common/wm/workspace/workspace_layout_manager.h" | 18 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
17 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" | 19 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" |
18 #include "ash/mus/background_layout.h" | |
19 #include "ash/mus/bridge/wm_globals_mus.h" | 20 #include "ash/mus/bridge/wm_globals_mus.h" |
20 #include "ash/mus/bridge/wm_root_window_controller_mus.h" | 21 #include "ash/mus/bridge/wm_root_window_controller_mus.h" |
21 #include "ash/mus/bridge/wm_shelf_mus.h" | 22 #include "ash/mus/bridge/wm_shelf_mus.h" |
22 #include "ash/mus/bridge/wm_window_mus.h" | 23 #include "ash/mus/bridge/wm_window_mus.h" |
23 #include "ash/mus/container_ids.h" | 24 #include "ash/mus/container_ids.h" |
24 #include "ash/mus/fill_layout.h" | |
25 #include "ash/mus/screenlock_layout.h" | 25 #include "ash/mus/screenlock_layout.h" |
26 #include "ash/mus/shadow_controller.h" | 26 #include "ash/mus/shadow_controller.h" |
27 #include "ash/mus/shelf_layout_manager.h" | 27 #include "ash/mus/shelf_layout_manager.h" |
28 #include "ash/mus/status_layout_manager.h" | 28 #include "ash/mus/status_layout_manager.h" |
29 #include "ash/mus/window_manager.h" | 29 #include "ash/mus/window_manager.h" |
30 #include "ash/mus/window_manager_application.h" | 30 #include "ash/mus/window_manager_application.h" |
31 #include "base/bind.h" | 31 #include "base/bind.h" |
32 #include "base/command_line.h" | 32 #include "base/command_line.h" |
33 #include "base/memory/ptr_util.h" | 33 #include "base/memory/ptr_util.h" |
34 #include "components/mus/common/event_matcher_util.h" | 34 #include "components/mus/common/event_matcher_util.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
49 namespace ash { | 49 namespace ash { |
50 namespace mus { | 50 namespace mus { |
51 namespace { | 51 namespace { |
52 | 52 |
53 const uint32_t kWindowSwitchAccelerator = 1; | 53 const uint32_t kWindowSwitchAccelerator = 1; |
54 | 54 |
55 void AssertTrue(bool success) { | 55 void AssertTrue(bool success) { |
56 DCHECK(success); | 56 DCHECK(success); |
57 } | 57 } |
58 | 58 |
59 int ContainerToLocalId(Container container) { | |
60 return static_cast<int>(container); | |
61 } | |
62 | |
63 class WorkspaceLayoutManagerDelegateImpl | 59 class WorkspaceLayoutManagerDelegateImpl |
64 : public wm::WorkspaceLayoutManagerDelegate { | 60 : public wm::WorkspaceLayoutManagerDelegate { |
65 public: | 61 public: |
66 explicit WorkspaceLayoutManagerDelegateImpl( | 62 explicit WorkspaceLayoutManagerDelegateImpl( |
67 WmRootWindowControllerMus* root_window_controller) | 63 WmRootWindowControllerMus* root_window_controller) |
68 : root_window_controller_(root_window_controller) {} | 64 : root_window_controller_(root_window_controller) {} |
69 ~WorkspaceLayoutManagerDelegateImpl() override = default; | 65 ~WorkspaceLayoutManagerDelegateImpl() override = default; |
70 | 66 |
71 // WorkspaceLayoutManagerDelegate: | 67 // WorkspaceLayoutManagerDelegate: |
72 void UpdateShelfVisibility() override { NOTIMPLEMENTED(); } | 68 void UpdateShelfVisibility() override { NOTIMPLEMENTED(); } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 delete this; | 102 delete this; |
107 } | 103 } |
108 } | 104 } |
109 | 105 |
110 shell::Connector* RootWindowController::GetConnector() { | 106 shell::Connector* RootWindowController::GetConnector() { |
111 return app_->connector(); | 107 return app_->connector(); |
112 } | 108 } |
113 | 109 |
114 ::mus::Window* RootWindowController::GetWindowForContainer( | 110 ::mus::Window* RootWindowController::GetWindowForContainer( |
115 Container container) { | 111 Container container) { |
116 return root_->GetChildByLocalId(ContainerToLocalId(container)); | 112 WmWindowMus* wm_window = |
113 GetWindowByShellWindowId(MashContainerToAshShellWindowId(container)); | |
114 DCHECK(wm_window); | |
115 return wm_window->mus_window(); | |
117 } | 116 } |
118 | 117 |
119 bool RootWindowController::WindowIsContainer( | 118 bool RootWindowController::WindowIsContainer(::mus::Window* window) { |
120 const ::mus::Window* window) const { | 119 return window && |
121 return window && window->local_id() > ContainerToLocalId(Container::ROOT) && | 120 WmWindowMus::Get(window)->GetShellWindowId() != kShellWindowId_Invalid; |
James Cook
2016/06/03 00:24:58
It's hard to see where kShellWindowId_Invalid is r
sky
2016/06/03 03:07:03
It's actually set in aura::Window and mus::Window.
James Cook
2016/06/03 16:13:16
Yeah, I found them, but it's a magic number that h
sky
2016/06/03 17:39:04
I ended up going with a static_assert for aura and
| |
122 window->local_id() < ContainerToLocalId(Container::COUNT); | 121 } |
122 | |
123 WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) { | |
124 return WmWindowMus::AsWmWindowMus( | |
125 WmWindowMus::Get(root_)->GetChildByShellWindowId(id)); | |
123 } | 126 } |
124 | 127 |
125 ::mus::WindowManagerClient* RootWindowController::window_manager_client() { | 128 ::mus::WindowManagerClient* RootWindowController::window_manager_client() { |
126 return window_manager_->window_manager_client(); | 129 return window_manager_->window_manager_client(); |
127 } | 130 } |
128 | 131 |
129 void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) { | 132 void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) { |
130 switch (id) { | 133 switch (id) { |
131 case kWindowSwitchAccelerator: | 134 case kWindowSwitchAccelerator: |
132 window_manager_client()->ActivateNextWindow(); | 135 window_manager_client()->ActivateNextWindow(); |
(...skipping 25 matching lines...) Expand all Loading... | |
158 void RootWindowController::AddAccelerators() { | 161 void RootWindowController::AddAccelerators() { |
159 window_manager_client()->AddAccelerator( | 162 window_manager_client()->AddAccelerator( |
160 kWindowSwitchAccelerator, | 163 kWindowSwitchAccelerator, |
161 ::mus::CreateKeyMatcher(::mus::mojom::KeyboardCode::TAB, | 164 ::mus::CreateKeyMatcher(::mus::mojom::KeyboardCode::TAB, |
162 ::mus::mojom::kEventFlagControlDown), | 165 ::mus::mojom::kEventFlagControlDown), |
163 base::Bind(&AssertTrue)); | 166 base::Bind(&AssertTrue)); |
164 } | 167 } |
165 | 168 |
166 void RootWindowController::OnEmbed(::mus::Window* root) { | 169 void RootWindowController::OnEmbed(::mus::Window* root) { |
167 root_ = root; | 170 root_ = root; |
168 root_->set_local_id(ContainerToLocalId(Container::ROOT)); | |
169 root_->AddObserver(this); | 171 root_->AddObserver(this); |
170 layout_managers_[root_].reset(new FillLayout(root_)); | |
171 | 172 |
172 app_->OnRootWindowControllerGotRoot(this); | 173 app_->OnRootWindowControllerGotRoot(this); |
173 | 174 |
174 wm_root_window_controller_.reset( | 175 wm_root_window_controller_.reset( |
175 new WmRootWindowControllerMus(app_->globals(), this)); | 176 new WmRootWindowControllerMus(app_->globals(), this)); |
176 | 177 |
177 CreateContainers(); | 178 root_window_controller_common_.reset( |
179 new RootWindowControllerCommon(WmWindowMus::Get(root_))); | |
180 root_window_controller_common_->CreateContainers(); | |
181 root_window_controller_common_->CreateLayoutManagers(); | |
182 CreateLayoutManagers(); | |
183 | |
184 // Force a layout of the root, and its children, RootWindowLayout handles | |
185 // both. | |
186 root_window_controller_common_->root_window_layout()->OnWindowResized(); | |
178 | 187 |
179 for (size_t i = 0; i < kNumActivationContainers; ++i) { | 188 for (size_t i = 0; i < kNumActivationContainers; ++i) { |
180 window_manager_client()->AddActivationParent( | 189 // kShellWindowId_VirtualKeyboardContainer is lazily created. |
181 GetWindowForContainer(kActivationContainers[i])); | 190 // TODO(sky): http://crbug.com/616909 . |
191 if (kActivationContainers[i] != kShellWindowId_VirtualKeyboardContainer) { | |
192 window_manager_client()->AddActivationParent( | |
193 GetWindowByShellWindowId(kActivationContainers[i])->mus_window()); | |
194 } | |
182 } | 195 } |
183 | 196 |
184 wm::WmWindow* always_on_top_container = | 197 WmWindowMus* always_on_top_container = |
185 WmWindowMus::Get(root)->GetChildByShellWindowId( | 198 GetWindowByShellWindowId(kShellWindowId_AlwaysOnTopContainer); |
186 kShellWindowId_AlwaysOnTopContainer); | |
187 always_on_top_controller_.reset( | 199 always_on_top_controller_.reset( |
188 new AlwaysOnTopController(always_on_top_container)); | 200 new AlwaysOnTopController(always_on_top_container)); |
189 | 201 |
190 AddAccelerators(); | 202 AddAccelerators(); |
191 | 203 |
192 window_manager_->Initialize(this, app_->session()); | 204 window_manager_->Initialize(this, app_->session()); |
193 | 205 |
194 shadow_controller_.reset(new ShadowController(root->window_tree())); | 206 shadow_controller_.reset(new ShadowController(root->window_tree())); |
195 | 207 |
196 app_->OnRootWindowControllerDoneInit(this); | 208 app_->OnRootWindowControllerDoneInit(this); |
(...skipping 25 matching lines...) Expand all Loading... | |
222 ->SetShelf(wm_shelf_.get()); | 234 ->SetShelf(wm_shelf_.get()); |
223 | 235 |
224 PanelLayoutManager::Get(WmWindowMus::Get(root_))->SetShelf(wm_shelf_.get()); | 236 PanelLayoutManager::Get(WmWindowMus::Get(root_))->SetShelf(wm_shelf_.get()); |
225 | 237 |
226 // TODO: http://crbug.com/614182 Ash's ShelfLayoutManager implements | 238 // TODO: http://crbug.com/614182 Ash's ShelfLayoutManager implements |
227 // DockedWindowLayoutManagerObserver so that it can inset by the docked | 239 // DockedWindowLayoutManagerObserver so that it can inset by the docked |
228 // windows. | 240 // windows. |
229 // docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager()); | 241 // docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager()); |
230 } | 242 } |
231 | 243 |
232 void RootWindowController::CreateContainer(Container container, | 244 void RootWindowController::CreateLayoutManagers() { |
233 Container parent_container) { | 245 // Override the default layout managers for certain containers. |
234 // Set the window's name to the container name (e.g. "Container::LOGIN"), | 246 WmWindowMus* lock_screen_container = |
235 // which makes the window hierarchy easier to read. | 247 GetWindowByShellWindowId(kShellWindowId_LockScreenContainer); |
236 std::map<std::string, std::vector<uint8_t>> properties; | 248 layout_managers_[lock_screen_container->mus_window()].reset( |
237 std::ostringstream container_name; | 249 new ScreenlockLayout(lock_screen_container->mus_window())); |
238 container_name << container; | |
239 properties[::mus::mojom::WindowManager::kName_Property] = | |
240 mojo::ConvertTo<std::vector<uint8_t>>(container_name.str()); | |
241 | 250 |
242 ::mus::Window* window = root_->window_tree()->NewWindow(&properties); | 251 WmWindowMus* shelf_container = |
243 window->set_local_id(ContainerToLocalId(container)); | 252 GetWindowByShellWindowId(kShellWindowId_ShelfContainer); |
244 layout_managers_[window].reset(new FillLayout(window)); | |
245 WmWindowMus::Get(window)->SetShellWindowId( | |
246 MashContainerToAshContainer(container)); | |
247 | |
248 // User private windows are hidden by default until the window manager learns | |
249 // the lock state, so their contents are never accidentally revealed. Tests, | |
250 // however, usually assume the screen is unlocked. | |
251 const bool is_test = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
James Cook
2016/06/03 00:24:58
views_mus_unittests are OK after removing this? I'
sky
2016/06/03 03:07:03
They passed locally. I'll find out shortly if the
James Cook
2016/06/03 16:13:16
Oh, I think it's actually views_mus_interactive_ui
sky
2016/06/03 17:39:04
They pass locally. Fingers crossed.
| |
252 ::mus::switches::kUseTestConfig); | |
253 window->SetVisible(container != Container::USER_PRIVATE || is_test); | |
254 | |
255 ::mus::Window* parent = | |
256 root_->GetChildByLocalId(ContainerToLocalId(parent_container)); | |
257 parent->AddChild(window); | |
258 } | |
259 | |
260 void RootWindowController::CreateContainers() { | |
261 CreateContainer(Container::ALL_USER_BACKGROUND, Container::ROOT); | |
262 CreateContainer(Container::USER, Container::ROOT); | |
263 CreateContainer(Container::USER_BACKGROUND, Container::USER); | |
264 CreateContainer(Container::USER_PRIVATE, Container::USER); | |
265 CreateContainer(Container::USER_PRIVATE_WINDOWS, Container::USER_PRIVATE); | |
266 CreateContainer(Container::USER_PRIVATE_ALWAYS_ON_TOP_WINDOWS, | |
267 Container::USER_PRIVATE); | |
268 CreateContainer(Container::USER_PRIVATE_DOCKED_WINDOWS, | |
269 Container::USER_PRIVATE); | |
270 CreateContainer(Container::USER_PRIVATE_PRESENTATION_WINDOWS, | |
271 Container::USER_PRIVATE); | |
272 CreateContainer(Container::USER_PRIVATE_SHELF, Container::USER_PRIVATE); | |
273 CreateContainer(Container::USER_PRIVATE_PANELS, Container::USER_PRIVATE); | |
274 CreateContainer(Container::USER_PRIVATE_APP_LIST, Container::USER_PRIVATE); | |
275 CreateContainer(Container::USER_PRIVATE_SYSTEM_MODAL, | |
276 Container::USER_PRIVATE); | |
277 CreateContainer(Container::LOGIN, Container::ROOT); | |
278 CreateContainer(Container::LOGIN_WINDOWS, Container::LOGIN); | |
279 CreateContainer(Container::LOGIN_APP, Container::LOGIN); | |
280 CreateContainer(Container::LOGIN_SHELF, Container::LOGIN); | |
281 CreateContainer(Container::STATUS, Container::ROOT); | |
282 CreateContainer(Container::BUBBLES, Container::ROOT); | |
283 CreateContainer(Container::SYSTEM_MODAL_WINDOWS, Container::ROOT); | |
284 CreateContainer(Container::KEYBOARD, Container::ROOT); | |
285 CreateContainer(Container::MENUS, Container::ROOT); | |
286 CreateContainer(Container::DRAG_AND_TOOLTIPS, Container::ROOT); | |
287 | |
288 // Override the default layout managers for certain containers. | |
289 ::mus::Window* user_background = | |
290 GetWindowForContainer(Container::USER_BACKGROUND); | |
291 layout_managers_[user_background].reset( | |
292 new BackgroundLayout(user_background)); | |
293 | |
294 ::mus::Window* login_app = GetWindowForContainer(Container::LOGIN_APP); | |
295 layout_managers_[login_app].reset(new ScreenlockLayout(login_app)); | |
296 | |
297 ::mus::Window* user_shelf = | |
298 GetWindowForContainer(Container::USER_PRIVATE_SHELF); | |
299 ShelfLayoutManager* shelf_layout_manager = | 253 ShelfLayoutManager* shelf_layout_manager = |
300 new ShelfLayoutManager(user_shelf, this); | 254 new ShelfLayoutManager(shelf_container->mus_window(), this); |
301 layout_managers_[user_shelf].reset(shelf_layout_manager); | 255 layout_managers_[shelf_container->mus_window()].reset(shelf_layout_manager); |
302 | 256 |
303 wm_shelf_.reset(new WmShelfMus(shelf_layout_manager)); | 257 wm_shelf_.reset(new WmShelfMus(shelf_layout_manager)); |
304 | 258 |
305 ::mus::Window* status = GetWindowForContainer(Container::STATUS); | 259 WmWindowMus* status_container = |
306 layout_managers_[status].reset(new StatusLayoutManager(status)); | 260 GetWindowByShellWindowId(kShellWindowId_StatusContainer); |
261 layout_managers_[status_container->mus_window()].reset( | |
262 new StatusLayoutManager(status_container->mus_window())); | |
307 | 263 |
308 ::mus::Window* user_private_windows = | 264 WmWindowMus* default_container = |
309 GetWindowForContainer(Container::USER_PRIVATE_WINDOWS); | 265 GetWindowByShellWindowId(kShellWindowId_DefaultContainer); |
310 // WorkspaceLayoutManager is not a mash::wm::LayoutManager (it's a | 266 // WorkspaceLayoutManager is not a mash::wm::LayoutManager (it's a |
311 // wm::LayoutManager), so it can't be in |layout_managers_|. | 267 // wm::LayoutManager), so it can't be in |layout_managers_|. |
312 layout_managers_.erase(user_private_windows); | |
313 std::unique_ptr<WorkspaceLayoutManagerDelegateImpl> | 268 std::unique_ptr<WorkspaceLayoutManagerDelegateImpl> |
314 workspace_layout_manager_delegate(new WorkspaceLayoutManagerDelegateImpl( | 269 workspace_layout_manager_delegate(new WorkspaceLayoutManagerDelegateImpl( |
315 wm_root_window_controller_.get())); | 270 wm_root_window_controller_.get())); |
316 WmWindowMus* user_private_windows_wm = WmWindowMus::Get(user_private_windows); | 271 default_container->SetLayoutManager( |
317 user_private_windows_wm->SetSnapsChildrenToPhysicalPixelBoundary(); | |
318 user_private_windows_wm->SetChildrenUseExtendedHitRegion(); | |
319 user_private_windows_wm->SetLayoutManager( | |
320 base::WrapUnique(new WorkspaceLayoutManager( | 272 base::WrapUnique(new WorkspaceLayoutManager( |
321 user_private_windows_wm, | 273 default_container, std::move(workspace_layout_manager_delegate)))); |
322 std::move(workspace_layout_manager_delegate)))); | |
323 | 274 |
324 ::mus::Window* user_private_docked_windows = | 275 WmWindowMus* docked_container = |
325 GetWindowForContainer(Container::USER_PRIVATE_DOCKED_WINDOWS); | 276 GetWindowByShellWindowId(kShellWindowId_DockedContainer); |
326 WmWindowMus* user_private_docked_windows_wm = | 277 docked_container->SetLayoutManager( |
327 WmWindowMus::Get(user_private_docked_windows); | 278 base::WrapUnique(new DockedWindowLayoutManager(docked_container))); |
328 user_private_docked_windows_wm->SetSnapsChildrenToPhysicalPixelBoundary(); | |
329 layout_managers_.erase(user_private_docked_windows); | |
330 user_private_docked_windows_wm->SetChildrenUseExtendedHitRegion(); | |
331 user_private_docked_windows_wm->SetLayoutManager(base::WrapUnique( | |
332 new DockedWindowLayoutManager(user_private_docked_windows_wm))); | |
333 | 279 |
334 ::mus::Window* user_private_panels = | 280 WmWindowMus* panel_container = |
335 GetWindowForContainer(Container::USER_PRIVATE_PANELS); | 281 GetWindowByShellWindowId(kShellWindowId_PanelContainer); |
336 WmWindowMus* user_private_panels_wm = WmWindowMus::Get(user_private_panels); | 282 panel_container->SetLayoutManager( |
337 user_private_panels_wm->SetSnapsChildrenToPhysicalPixelBoundary(); | 283 base::WrapUnique(new PanelLayoutManager(panel_container))); |
338 layout_managers_.erase(user_private_panels); | |
339 user_private_panels_wm->SetChildrenUseExtendedHitRegion(); | |
340 user_private_panels_wm->SetLayoutManager( | |
341 base::WrapUnique(new PanelLayoutManager(user_private_panels_wm))); | |
342 | |
343 ::mus::Window* user_private_always_on_top = | |
344 GetWindowForContainer(Container::USER_PRIVATE_ALWAYS_ON_TOP_WINDOWS); | |
345 WmWindowMus* user_private_always_on_top_wm = | |
346 WmWindowMus::Get(user_private_always_on_top); | |
347 user_private_always_on_top_wm->SetChildrenUseExtendedHitRegion(); | |
348 user_private_always_on_top_wm->SetSnapsChildrenToPhysicalPixelBoundary(); | |
349 } | 284 } |
350 | 285 |
351 } // namespace mus | 286 } // namespace mus |
352 } // namespace ash | 287 } // namespace ash |
OLD | NEW |