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/bridge/shell_port_mash.h" | 5 #include "ash/mus/bridge/shell_port_mash.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/accelerators/accelerator_controller.h" | 9 #include "ash/accelerators/accelerator_controller.h" |
10 #include "ash/accelerators/accelerator_controller_delegate_aura.h" | 10 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
11 #include "ash/aura/key_event_watcher_aura.h" | 11 #include "ash/aura/key_event_watcher_aura.h" |
12 #include "ash/aura/pointer_watcher_adapter.h" | 12 #include "ash/aura/pointer_watcher_adapter.h" |
13 #include "ash/host/ash_window_tree_host.h" | 13 #include "ash/display/window_tree_host_manager.h" |
| 14 #include "ash/host/ash_window_tree_host_init_params.h" |
14 #include "ash/key_event_watcher.h" | 15 #include "ash/key_event_watcher.h" |
15 #include "ash/laser/laser_pointer_controller.h" | 16 #include "ash/laser/laser_pointer_controller.h" |
16 #include "ash/magnifier/partial_magnification_controller.h" | 17 #include "ash/magnifier/partial_magnification_controller.h" |
17 #include "ash/mus/accelerators/accelerator_controller_delegate_mus.h" | 18 #include "ash/mus/accelerators/accelerator_controller_delegate_mus.h" |
18 #include "ash/mus/accelerators/accelerator_controller_registrar.h" | 19 #include "ash/mus/accelerators/accelerator_controller_registrar.h" |
| 20 #include "ash/mus/ash_window_tree_host_mus.h" |
19 #include "ash/mus/bridge/immersive_handler_factory_mus.h" | 21 #include "ash/mus/bridge/immersive_handler_factory_mus.h" |
20 #include "ash/mus/bridge/workspace_event_handler_mus.h" | 22 #include "ash/mus/bridge/workspace_event_handler_mus.h" |
21 #include "ash/mus/drag_window_resizer.h" | 23 #include "ash/mus/drag_window_resizer.h" |
22 #include "ash/mus/keyboard_ui_mus.h" | 24 #include "ash/mus/keyboard_ui_mus.h" |
23 #include "ash/mus/screen_mus.h" | 25 #include "ash/mus/screen_mus.h" |
24 #include "ash/mus/window_manager.h" | 26 #include "ash/mus/window_manager.h" |
25 #include "ash/public/cpp/config.h" | 27 #include "ash/public/cpp/config.h" |
26 #include "ash/public/cpp/shell_window_ids.h" | 28 #include "ash/public/cpp/shell_window_ids.h" |
27 #include "ash/root_window_controller.h" | 29 #include "ash/root_window_controller.h" |
28 #include "ash/root_window_settings.h" | 30 #include "ash/root_window_settings.h" |
(...skipping 14 matching lines...) Expand all Loading... |
43 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.
h" | 45 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.
h" |
44 #include "ash/wm/mru_window_tracker.h" | 46 #include "ash/wm/mru_window_tracker.h" |
45 #include "ash/wm/window_cycle_event_filter.h" | 47 #include "ash/wm/window_cycle_event_filter.h" |
46 #include "ash/wm/window_cycle_event_filter_aura.h" | 48 #include "ash/wm/window_cycle_event_filter_aura.h" |
47 #include "ash/wm/window_resizer.h" | 49 #include "ash/wm/window_resizer.h" |
48 #include "ash/wm/window_util.h" | 50 #include "ash/wm/window_util.h" |
49 #include "ash/wm/workspace/workspace_event_handler_aura.h" | 51 #include "ash/wm/workspace/workspace_event_handler_aura.h" |
50 #include "ash/wm_window.h" | 52 #include "ash/wm_window.h" |
51 #include "base/memory/ptr_util.h" | 53 #include "base/memory/ptr_util.h" |
52 #include "components/user_manager/user_info_impl.h" | 54 #include "components/user_manager/user_info_impl.h" |
| 55 #include "services/ui/public/interfaces/constants.mojom.h" |
53 #include "ui/aura/env.h" | 56 #include "ui/aura/env.h" |
54 #include "ui/aura/mus/focus_synchronizer.h" | 57 #include "ui/aura/mus/focus_synchronizer.h" |
55 #include "ui/aura/mus/window_tree_client.h" | 58 #include "ui/aura/mus/window_tree_client.h" |
56 #include "ui/aura/mus/window_tree_host_mus.h" | 59 #include "ui/aura/mus/window_tree_host_mus.h" |
| 60 #include "ui/aura/mus/window_tree_host_mus_init_params.h" |
57 #include "ui/aura/window.h" | 61 #include "ui/aura/window.h" |
| 62 #include "ui/display/manager/display_manager.h" |
58 #include "ui/display/manager/managed_display_info.h" | 63 #include "ui/display/manager/managed_display_info.h" |
59 #include "ui/display/screen.h" | 64 #include "ui/display/screen.h" |
60 #include "ui/display/types/native_display_delegate.h" | 65 #include "ui/display/types/native_display_delegate.h" |
61 #include "ui/views/mus/pointer_watcher_event_router.h" | 66 #include "ui/views/mus/pointer_watcher_event_router.h" |
62 | 67 |
| 68 #if defined(USE_OZONE) |
| 69 #include "ui/display/manager/forwarding_display_delegate.h" |
| 70 #endif |
| 71 |
63 namespace ash { | 72 namespace ash { |
64 namespace mus { | 73 namespace mus { |
65 | 74 |
66 namespace { | 75 namespace { |
67 | 76 |
68 // TODO(jamescook): After ShellDelegate is ported to ash/common use | 77 // TODO(jamescook): After ShellDelegate is ported to ash/common use |
69 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version | 78 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version |
70 // of SessionStateDelegate. | 79 // of SessionStateDelegate. |
71 class SessionStateDelegateStub : public SessionStateDelegate { | 80 class SessionStateDelegateStub : public SessionStateDelegate { |
72 public: | 81 public: |
(...skipping 30 matching lines...) Expand all Loading... |
103 | 112 |
104 ShellPortMash::ShellPortMash( | 113 ShellPortMash::ShellPortMash( |
105 WmWindow* primary_root_window, | 114 WmWindow* primary_root_window, |
106 WindowManager* window_manager, | 115 WindowManager* window_manager, |
107 views::PointerWatcherEventRouter* pointer_watcher_event_router, | 116 views::PointerWatcherEventRouter* pointer_watcher_event_router, |
108 bool create_session_state_delegate_stub) | 117 bool create_session_state_delegate_stub) |
109 : window_manager_(window_manager), | 118 : window_manager_(window_manager), |
110 primary_root_window_(primary_root_window) { | 119 primary_root_window_(primary_root_window) { |
111 if (create_session_state_delegate_stub) | 120 if (create_session_state_delegate_stub) |
112 session_state_delegate_ = base::MakeUnique<SessionStateDelegateStub>(); | 121 session_state_delegate_ = base::MakeUnique<SessionStateDelegateStub>(); |
113 DCHECK(primary_root_window_); | |
114 | 122 |
115 if (GetAshConfig() == Config::MASH) { | 123 if (GetAshConfig() == Config::MASH) { |
116 mash_state_ = base::MakeUnique<MashSpecificState>(); | 124 mash_state_ = base::MakeUnique<MashSpecificState>(); |
117 mash_state_->pointer_watcher_event_router = pointer_watcher_event_router; | 125 mash_state_->pointer_watcher_event_router = pointer_watcher_event_router; |
118 mash_state_->immersive_handler_factory = | 126 mash_state_->immersive_handler_factory = |
119 base::MakeUnique<ImmersiveHandlerFactoryMus>(); | 127 base::MakeUnique<ImmersiveHandlerFactoryMus>(); |
120 } else { | 128 } else { |
121 DCHECK_EQ(Config::MUS, GetAshConfig()); | 129 DCHECK_EQ(Config::MUS, GetAshConfig()); |
122 mus_state_ = base::MakeUnique<MusSpecificState>(); | 130 mus_state_ = base::MakeUnique<MusSpecificState>(); |
123 } | 131 } |
(...skipping 24 matching lines...) Expand all Loading... |
148 aura::WindowTreeClient* ShellPortMash::window_tree_client() { | 156 aura::WindowTreeClient* ShellPortMash::window_tree_client() { |
149 return window_manager_->window_tree_client(); | 157 return window_manager_->window_tree_client(); |
150 } | 158 } |
151 | 159 |
152 void ShellPortMash::Shutdown() { | 160 void ShellPortMash::Shutdown() { |
153 if (mus_state_) | 161 if (mus_state_) |
154 mus_state_->pointer_watcher_adapter.reset(); | 162 mus_state_->pointer_watcher_adapter.reset(); |
155 | 163 |
156 ShellPort::Shutdown(); | 164 ShellPort::Shutdown(); |
157 | 165 |
158 window_manager_->DeleteAllRootWindowControllers(); | 166 // TODO(sky): Config::MASH should use WindowTreeHostManager too. |
| 167 if (GetAshConfig() == Config::MUS) |
| 168 Shell::Get()->window_tree_host_manager()->Shutdown(); |
| 169 else |
| 170 window_manager_->DeleteAllRootWindowControllers(); |
159 } | 171 } |
160 | 172 |
161 Config ShellPortMash::GetAshConfig() const { | 173 Config ShellPortMash::GetAshConfig() const { |
162 return window_manager_->config(); | 174 return window_manager_->config(); |
163 } | 175 } |
164 | 176 |
165 WmWindow* ShellPortMash::GetPrimaryRootWindow() { | 177 WmWindow* ShellPortMash::GetPrimaryRootWindow() { |
| 178 if (GetAshConfig() == Config::MUS) { |
| 179 return WmWindow::Get( |
| 180 Shell::Get()->window_tree_host_manager()->GetPrimaryRootWindow()); |
| 181 } |
166 // NOTE: This is called before the RootWindowController has been created, so | 182 // NOTE: This is called before the RootWindowController has been created, so |
167 // it can't call through to RootWindowController to get all windows. | 183 // it can't call through to RootWindowController to get all windows. |
168 return primary_root_window_; | 184 return primary_root_window_; |
169 } | 185 } |
170 | 186 |
171 WmWindow* ShellPortMash::GetRootWindowForDisplayId(int64_t display_id) { | 187 WmWindow* ShellPortMash::GetRootWindowForDisplayId(int64_t display_id) { |
| 188 if (GetAshConfig() == Config::MUS) { |
| 189 return WmWindow::Get( |
| 190 Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId( |
| 191 display_id)); |
| 192 } |
172 RootWindowController* root_window_controller = | 193 RootWindowController* root_window_controller = |
173 GetRootWindowControllerWithDisplayId(display_id); | 194 GetRootWindowControllerWithDisplayId(display_id); |
174 return root_window_controller | 195 return root_window_controller |
175 ? WmWindow::Get(root_window_controller->GetRootWindow()) | 196 ? WmWindow::Get(root_window_controller->GetRootWindow()) |
176 : nullptr; | 197 : nullptr; |
177 } | 198 } |
178 | 199 |
179 const display::ManagedDisplayInfo& ShellPortMash::GetDisplayInfo( | 200 const display::ManagedDisplayInfo& ShellPortMash::GetDisplayInfo( |
180 int64_t display_id) const { | 201 int64_t display_id) const { |
181 // TODO(mash): implement http://crbug.com/622480. | 202 // TODO(mash): implement http://crbug.com/622480. |
(...skipping 21 matching lines...) Expand all Loading... |
203 } | 224 } |
204 | 225 |
205 bool ShellPortMash::IsInUnifiedModeIgnoreMirroring() const { | 226 bool ShellPortMash::IsInUnifiedModeIgnoreMirroring() const { |
206 // TODO(mash): implement http://crbug.com/622480. | 227 // TODO(mash): implement http://crbug.com/622480. |
207 NOTIMPLEMENTED(); | 228 NOTIMPLEMENTED(); |
208 return false; | 229 return false; |
209 } | 230 } |
210 | 231 |
211 void ShellPortMash::SetDisplayWorkAreaInsets(WmWindow* window, | 232 void ShellPortMash::SetDisplayWorkAreaInsets(WmWindow* window, |
212 const gfx::Insets& insets) { | 233 const gfx::Insets& insets) { |
| 234 if (GetAshConfig() == Config::MUS) { |
| 235 Shell::Get() |
| 236 ->window_tree_host_manager() |
| 237 ->UpdateWorkAreaOfDisplayNearestWindow(window->aura_window(), insets); |
| 238 return; |
| 239 } |
213 window_manager_->screen()->SetWorkAreaInsets(window->aura_window(), insets); | 240 window_manager_->screen()->SetWorkAreaInsets(window->aura_window(), insets); |
214 } | 241 } |
215 | 242 |
216 void ShellPortMash::LockCursor() { | 243 void ShellPortMash::LockCursor() { |
217 // TODO: http://crbug.com/637853 | 244 // TODO: http://crbug.com/637853 |
218 NOTIMPLEMENTED(); | 245 NOTIMPLEMENTED(); |
219 } | 246 } |
220 | 247 |
221 void ShellPortMash::UnlockCursor() { | 248 void ShellPortMash::UnlockCursor() { |
222 // TODO: http://crbug.com/637853 | 249 // TODO: http://crbug.com/637853 |
223 NOTIMPLEMENTED(); | 250 NOTIMPLEMENTED(); |
224 } | 251 } |
225 | 252 |
226 bool ShellPortMash::IsMouseEventsEnabled() { | 253 bool ShellPortMash::IsMouseEventsEnabled() { |
227 // TODO: http://crbug.com/637853 | 254 // TODO: http://crbug.com/637853 |
228 NOTIMPLEMENTED(); | 255 NOTIMPLEMENTED(); |
229 return true; | 256 return true; |
230 } | 257 } |
231 | 258 |
232 std::vector<WmWindow*> ShellPortMash::GetAllRootWindows() { | 259 std::vector<WmWindow*> ShellPortMash::GetAllRootWindows() { |
| 260 if (GetAshConfig() == Config::MUS) { |
| 261 aura::Window::Windows root_windows = |
| 262 Shell::Get()->window_tree_host_manager()->GetAllRootWindows(); |
| 263 std::vector<WmWindow*> wm_windows(root_windows.size()); |
| 264 for (size_t i = 0; i < root_windows.size(); ++i) |
| 265 wm_windows[i] = WmWindow::Get(root_windows[i]); |
| 266 return wm_windows; |
| 267 } |
233 std::vector<WmWindow*> root_windows; | 268 std::vector<WmWindow*> root_windows; |
234 for (RootWindowController* root_window_controller : | 269 for (RootWindowController* root_window_controller : |
235 RootWindowController::root_window_controllers()) { | 270 RootWindowController::root_window_controllers()) { |
236 root_windows.push_back(root_window_controller->GetWindow()); | 271 root_windows.push_back(root_window_controller->GetWindow()); |
237 } | 272 } |
238 return root_windows; | 273 return root_windows; |
239 } | 274 } |
240 | 275 |
241 void ShellPortMash::RecordGestureAction(GestureActionType action) { | 276 void ShellPortMash::RecordGestureAction(GestureActionType action) { |
242 if (GetAshConfig() == Config::MUS) { | 277 if (GetAshConfig() == Config::MUS) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // In Config::MUS PointerWatcherAdapter must be created when this function is | 457 // In Config::MUS PointerWatcherAdapter must be created when this function is |
423 // called (it is order dependent), that is not the case with Config::MASH. | 458 // called (it is order dependent), that is not the case with Config::MASH. |
424 if (GetAshConfig() == Config::MUS) { | 459 if (GetAshConfig() == Config::MUS) { |
425 mus_state_->pointer_watcher_adapter = | 460 mus_state_->pointer_watcher_adapter = |
426 base::MakeUnique<PointerWatcherAdapter>(); | 461 base::MakeUnique<PointerWatcherAdapter>(); |
427 } | 462 } |
428 } | 463 } |
429 | 464 |
430 std::unique_ptr<AshWindowTreeHost> ShellPortMash::CreateAshWindowTreeHost( | 465 std::unique_ptr<AshWindowTreeHost> ShellPortMash::CreateAshWindowTreeHost( |
431 const AshWindowTreeHostInitParams& init_params) { | 466 const AshWindowTreeHostInitParams& init_params) { |
432 return nullptr; | 467 // TODO(sky): make this work for mash too. |
| 468 if (GetAshConfig() != Config::MUS) |
| 469 return nullptr; |
| 470 |
| 471 std::unique_ptr<aura::DisplayInitParams> display_params = |
| 472 base::MakeUnique<aura::DisplayInitParams>(); |
| 473 display_params->viewport_metrics.bounds_in_pixels = |
| 474 init_params.initial_bounds; |
| 475 display_params->viewport_metrics.device_scale_factor = |
| 476 init_params.device_scale_factor; |
| 477 display_params->viewport_metrics.ui_scale_factor = |
| 478 init_params.ui_scale_factor; |
| 479 display::Display mirrored_display = |
| 480 Shell::Get()->display_manager()->GetMirroringDisplayById( |
| 481 init_params.display_id); |
| 482 if (mirrored_display.is_valid()) { |
| 483 display_params->display = |
| 484 base::MakeUnique<display::Display>(mirrored_display); |
| 485 } |
| 486 // TODO: wire update is_primary_display correctly. |
| 487 display_params->is_primary_display = true; |
| 488 aura::WindowTreeHostMusInitParams aura_init_params = |
| 489 window_manager_->window_manager_client()->CreateInitParamsForNewDisplay(); |
| 490 aura_init_params.display_id = init_params.display_id; |
| 491 aura_init_params.display_init_params = std::move(display_params); |
| 492 return base::MakeUnique<AshWindowTreeHostMus>(std::move(aura_init_params)); |
433 } | 493 } |
434 | 494 |
435 void ShellPortMash::OnCreatedRootWindowContainers( | 495 void ShellPortMash::OnCreatedRootWindowContainers( |
436 RootWindowController* root_window_controller) { | 496 RootWindowController* root_window_controller) { |
437 // TODO: To avoid lots of IPC AddActivationParent() should take an array. | 497 // TODO: To avoid lots of IPC AddActivationParent() should take an array. |
438 // http://crbug.com/682048. | 498 // http://crbug.com/682048. |
439 aura::Window* root_window = root_window_controller->GetRootWindow(); | 499 aura::Window* root_window = root_window_controller->GetRootWindow(); |
440 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) { | 500 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) { |
441 window_manager_->window_manager_client()->AddActivationParent( | 501 window_manager_->window_manager_client()->AddActivationParent( |
442 root_window->GetChildById(kActivatableShellWindowIds[i])); | 502 root_window->GetChildById(kActivatableShellWindowIds[i])); |
443 } | 503 } |
444 } | 504 } |
445 | 505 |
446 void ShellPortMash::CreatePrimaryHost() {} | 506 void ShellPortMash::CreatePrimaryHost() { |
| 507 if (GetAshConfig() == Config::MASH) |
| 508 return; |
| 509 |
| 510 DCHECK_EQ(Config::MUS, GetAshConfig()); |
| 511 Shell::Get()->window_tree_host_manager()->Start(); |
| 512 AshWindowTreeHostInitParams ash_init_params; |
| 513 Shell::Get()->window_tree_host_manager()->CreatePrimaryHost(ash_init_params); |
| 514 } |
447 | 515 |
448 void ShellPortMash::InitHosts(const ShellInitParams& init_params) { | 516 void ShellPortMash::InitHosts(const ShellInitParams& init_params) { |
449 window_manager_->CreatePrimaryRootWindowController( | 517 if (GetAshConfig() == Config::MUS) { |
450 base::WrapUnique(init_params.primary_window_tree_host)); | 518 Shell::Get()->window_tree_host_manager()->InitHosts(); |
| 519 } else { |
| 520 window_manager_->CreatePrimaryRootWindowController( |
| 521 base::WrapUnique(init_params.primary_window_tree_host)); |
| 522 } |
451 } | 523 } |
452 | 524 |
453 std::unique_ptr<display::NativeDisplayDelegate> | 525 std::unique_ptr<display::NativeDisplayDelegate> |
454 ShellPortMash::CreateNativeDisplayDelegate() { | 526 ShellPortMash::CreateNativeDisplayDelegate() { |
| 527 #if defined(USE_OZONE) |
| 528 display::mojom::NativeDisplayDelegatePtr native_display_delegate; |
| 529 if (window_manager_->connector()) { |
| 530 window_manager_->connector()->BindInterface(ui::mojom::kServiceName, |
| 531 &native_display_delegate); |
| 532 } |
| 533 return base::MakeUnique<display::ForwardingDisplayDelegate>( |
| 534 std::move(native_display_delegate)); |
| 535 #else |
| 536 // The bots compile this config, but it is never run. |
| 537 CHECK(false); |
455 return nullptr; | 538 return nullptr; |
| 539 #endif |
456 } | 540 } |
457 | 541 |
458 std::unique_ptr<AcceleratorController> | 542 std::unique_ptr<AcceleratorController> |
459 ShellPortMash::CreateAcceleratorController() { | 543 ShellPortMash::CreateAcceleratorController() { |
460 if (GetAshConfig() == Config::MUS) { | 544 if (GetAshConfig() == Config::MUS) { |
461 DCHECK(!mus_state_->accelerator_controller_delegate); | 545 DCHECK(!mus_state_->accelerator_controller_delegate); |
462 mus_state_->accelerator_controller_delegate = | 546 mus_state_->accelerator_controller_delegate = |
463 base::MakeUnique<AcceleratorControllerDelegateAura>(); | 547 base::MakeUnique<AcceleratorControllerDelegateAura>(); |
464 return base::MakeUnique<AcceleratorController>( | 548 return base::MakeUnique<AcceleratorController>( |
465 mus_state_->accelerator_controller_delegate.get(), nullptr); | 549 mus_state_->accelerator_controller_delegate.get(), nullptr); |
(...skipping 13 matching lines...) Expand all Loading... |
479 mash_state_->accelerator_controller_registrar = | 563 mash_state_->accelerator_controller_registrar = |
480 base ::MakeUnique<AcceleratorControllerRegistrar>( | 564 base ::MakeUnique<AcceleratorControllerRegistrar>( |
481 window_manager_, accelerator_namespace_id); | 565 window_manager_, accelerator_namespace_id); |
482 return base::MakeUnique<AcceleratorController>( | 566 return base::MakeUnique<AcceleratorController>( |
483 mash_state_->accelerator_controller_delegate.get(), | 567 mash_state_->accelerator_controller_delegate.get(), |
484 mash_state_->accelerator_controller_registrar.get()); | 568 mash_state_->accelerator_controller_registrar.get()); |
485 } | 569 } |
486 | 570 |
487 } // namespace mus | 571 } // namespace mus |
488 } // namespace ash | 572 } // namespace ash |
OLD | NEW |