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_shell_mus.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "ash/accelerators/accelerator_controller.h" | |
10 #include "ash/accelerators/accelerator_controller_delegate_aura.h" | |
11 #include "ash/aura/key_event_watcher_aura.h" | |
12 #include "ash/aura/pointer_watcher_adapter.h" | |
13 #include "ash/key_event_watcher.h" | |
14 #include "ash/laser/laser_pointer_controller.h" | |
15 #include "ash/magnifier/partial_magnification_controller.h" | |
16 #include "ash/mus/accelerators/accelerator_controller_delegate_mus.h" | |
17 #include "ash/mus/accelerators/accelerator_controller_registrar.h" | |
18 #include "ash/mus/bridge/immersive_handler_factory_mus.h" | |
19 #include "ash/mus/bridge/workspace_event_handler_mus.h" | |
20 #include "ash/mus/drag_window_resizer.h" | |
21 #include "ash/mus/keyboard_ui_mus.h" | |
22 #include "ash/mus/screen_mus.h" | |
23 #include "ash/mus/window_manager.h" | |
24 #include "ash/public/cpp/config.h" | |
25 #include "ash/root_window_controller.h" | |
26 #include "ash/root_window_settings.h" | |
27 #include "ash/session/session_state_delegate.h" | |
28 #include "ash/shared/immersive_fullscreen_controller.h" | |
29 #include "ash/shell.h" | |
30 #include "ash/shell_delegate.h" | |
31 #include "ash/shell_init_params.h" | |
32 #include "ash/shell_observer.h" | |
33 #include "ash/system/tray/system_tray_delegate.h" | |
34 #include "ash/touch/touch_uma.h" | |
35 #include "ash/virtual_keyboard_controller.h" | |
36 #include "ash/wallpaper/wallpaper_delegate.h" | |
37 #include "ash/wm/drag_window_resizer.h" | |
38 #include "ash/wm/maximize_mode/maximize_mode_event_handler.h" | |
39 #include "ash/wm/maximize_mode/maximize_mode_event_handler_aura.h" | |
40 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | |
41 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.
h" | |
42 #include "ash/wm/mru_window_tracker.h" | |
43 #include "ash/wm/window_cycle_event_filter.h" | |
44 #include "ash/wm/window_cycle_event_filter_aura.h" | |
45 #include "ash/wm/window_resizer.h" | |
46 #include "ash/wm/window_util.h" | |
47 #include "ash/wm/workspace/workspace_event_handler_aura.h" | |
48 #include "ash/wm_window.h" | |
49 #include "base/memory/ptr_util.h" | |
50 #include "components/user_manager/user_info_impl.h" | |
51 #include "ui/aura/env.h" | |
52 #include "ui/aura/mus/window_tree_client.h" | |
53 #include "ui/aura/mus/window_tree_host_mus.h" | |
54 #include "ui/aura/window.h" | |
55 #include "ui/display/manager/managed_display_info.h" | |
56 #include "ui/display/screen.h" | |
57 #include "ui/views/mus/pointer_watcher_event_router.h" | |
58 | |
59 namespace ash { | |
60 namespace mus { | |
61 | |
62 namespace { | |
63 | |
64 // TODO(jamescook): After ShellDelegate is ported to ash/common use | |
65 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version | |
66 // of SessionStateDelegate. | |
67 class SessionStateDelegateStub : public SessionStateDelegate { | |
68 public: | |
69 SessionStateDelegateStub() : user_info_(new user_manager::UserInfoImpl()) {} | |
70 | |
71 ~SessionStateDelegateStub() override {} | |
72 | |
73 // SessionStateDelegate: | |
74 bool ShouldShowAvatar(WmWindow* window) const override { | |
75 NOTIMPLEMENTED(); | |
76 return !user_info_->GetImage().isNull(); | |
77 } | |
78 gfx::ImageSkia GetAvatarImageForWindow(WmWindow* window) const override { | |
79 NOTIMPLEMENTED(); | |
80 return gfx::ImageSkia(); | |
81 } | |
82 | |
83 private: | |
84 // A pseudo user info. | |
85 std::unique_ptr<user_manager::UserInfo> user_info_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub); | |
88 }; | |
89 | |
90 } // namespace | |
91 | |
92 WmShellMus::MashSpecificState::MashSpecificState() = default; | |
93 | |
94 WmShellMus::MashSpecificState::~MashSpecificState() = default; | |
95 | |
96 WmShellMus::MusSpecificState::MusSpecificState() = default; | |
97 | |
98 WmShellMus::MusSpecificState::~MusSpecificState() = default; | |
99 | |
100 WmShellMus::WmShellMus( | |
101 WmWindow* primary_root_window, | |
102 WindowManager* window_manager, | |
103 views::PointerWatcherEventRouter* pointer_watcher_event_router, | |
104 bool create_session_state_delegate_stub) | |
105 : window_manager_(window_manager), | |
106 primary_root_window_(primary_root_window) { | |
107 if (create_session_state_delegate_stub) | |
108 session_state_delegate_ = base::MakeUnique<SessionStateDelegateStub>(); | |
109 DCHECK(primary_root_window_); | |
110 | |
111 if (GetAshConfig() == Config::MASH) { | |
112 mash_state_ = base::MakeUnique<MashSpecificState>(); | |
113 mash_state_->pointer_watcher_event_router = pointer_watcher_event_router; | |
114 mash_state_->immersive_handler_factory = | |
115 base::MakeUnique<ImmersiveHandlerFactoryMus>(); | |
116 } else { | |
117 DCHECK_EQ(Config::MUS, GetAshConfig()); | |
118 mus_state_ = base::MakeUnique<MusSpecificState>(); | |
119 } | |
120 } | |
121 | |
122 WmShellMus::~WmShellMus() { | |
123 } | |
124 | |
125 // static | |
126 WmShellMus* WmShellMus::Get() { | |
127 const ash::Config config = WmShell::Get()->GetAshConfig(); | |
128 CHECK(config == Config::MUS || config == Config::MASH); | |
129 return static_cast<WmShellMus*>(WmShell::Get()); | |
130 } | |
131 | |
132 RootWindowController* WmShellMus::GetRootWindowControllerWithDisplayId( | |
133 int64_t id) { | |
134 for (RootWindowController* root_window_controller : | |
135 RootWindowController::root_window_controllers()) { | |
136 RootWindowSettings* settings = | |
137 GetRootWindowSettings(root_window_controller->GetRootWindow()); | |
138 DCHECK(settings); | |
139 if (settings->display_id == id) | |
140 return root_window_controller; | |
141 } | |
142 return nullptr; | |
143 } | |
144 | |
145 aura::WindowTreeClient* WmShellMus::window_tree_client() { | |
146 return window_manager_->window_tree_client(); | |
147 } | |
148 | |
149 void WmShellMus::Shutdown() { | |
150 if (mus_state_) | |
151 mus_state_->pointer_watcher_adapter.reset(); | |
152 | |
153 WmShell::Shutdown(); | |
154 | |
155 window_manager_->DeleteAllRootWindowControllers(); | |
156 } | |
157 | |
158 bool WmShellMus::IsRunningInMash() const { | |
159 return GetAshConfig() == Config::MASH; | |
160 } | |
161 | |
162 Config WmShellMus::GetAshConfig() const { | |
163 return window_manager_->config(); | |
164 } | |
165 | |
166 WmWindow* WmShellMus::GetPrimaryRootWindow() { | |
167 // NOTE: This is called before the RootWindowController has been created, so | |
168 // it can't call through to RootWindowController to get all windows. | |
169 return primary_root_window_; | |
170 } | |
171 | |
172 WmWindow* WmShellMus::GetRootWindowForDisplayId(int64_t display_id) { | |
173 RootWindowController* root_window_controller = | |
174 GetRootWindowControllerWithDisplayId(display_id); | |
175 return root_window_controller | |
176 ? WmWindow::Get(root_window_controller->GetRootWindow()) | |
177 : nullptr; | |
178 } | |
179 | |
180 const display::ManagedDisplayInfo& WmShellMus::GetDisplayInfo( | |
181 int64_t display_id) const { | |
182 // TODO(mash): implement http://crbug.com/622480. | |
183 NOTIMPLEMENTED(); | |
184 static display::ManagedDisplayInfo fake_info; | |
185 return fake_info; | |
186 } | |
187 | |
188 bool WmShellMus::IsActiveDisplayId(int64_t display_id) const { | |
189 // TODO(mash): implement http://crbug.com/622480. | |
190 NOTIMPLEMENTED(); | |
191 return true; | |
192 } | |
193 | |
194 display::Display WmShellMus::GetFirstDisplay() const { | |
195 // TODO(mash): implement http://crbug.com/622480. | |
196 NOTIMPLEMENTED(); | |
197 return display::Screen::GetScreen()->GetPrimaryDisplay(); | |
198 } | |
199 | |
200 bool WmShellMus::IsInUnifiedMode() const { | |
201 // TODO(mash): implement http://crbug.com/622480. | |
202 NOTIMPLEMENTED(); | |
203 return false; | |
204 } | |
205 | |
206 bool WmShellMus::IsInUnifiedModeIgnoreMirroring() const { | |
207 // TODO(mash): implement http://crbug.com/622480. | |
208 NOTIMPLEMENTED(); | |
209 return false; | |
210 } | |
211 | |
212 void WmShellMus::SetDisplayWorkAreaInsets(WmWindow* window, | |
213 const gfx::Insets& insets) { | |
214 window_manager_->screen()->SetWorkAreaInsets(window->aura_window(), insets); | |
215 } | |
216 | |
217 void WmShellMus::LockCursor() { | |
218 // TODO: http://crbug.com/637853 | |
219 NOTIMPLEMENTED(); | |
220 } | |
221 | |
222 void WmShellMus::UnlockCursor() { | |
223 // TODO: http://crbug.com/637853 | |
224 NOTIMPLEMENTED(); | |
225 } | |
226 | |
227 bool WmShellMus::IsMouseEventsEnabled() { | |
228 // TODO: http://crbug.com/637853 | |
229 NOTIMPLEMENTED(); | |
230 return true; | |
231 } | |
232 | |
233 std::vector<WmWindow*> WmShellMus::GetAllRootWindows() { | |
234 std::vector<WmWindow*> root_windows; | |
235 for (RootWindowController* root_window_controller : | |
236 RootWindowController::root_window_controllers()) { | |
237 root_windows.push_back(root_window_controller->GetWindow()); | |
238 } | |
239 return root_windows; | |
240 } | |
241 | |
242 void WmShellMus::RecordGestureAction(GestureActionType action) { | |
243 if (GetAshConfig() == Config::MUS) { | |
244 TouchUMA::GetInstance()->RecordGestureAction(action); | |
245 return; | |
246 } | |
247 // TODO: http://crbug.com/616581. | |
248 NOTIMPLEMENTED(); | |
249 } | |
250 | |
251 void WmShellMus::RecordUserMetricsAction(UserMetricsAction action) { | |
252 if (GetAshConfig() == Config::MUS) { | |
253 Shell::Get()->metrics()->RecordUserMetricsAction(action); | |
254 return; | |
255 } | |
256 // TODO: http://crbug.com/616581. | |
257 NOTIMPLEMENTED(); | |
258 } | |
259 | |
260 void WmShellMus::RecordTaskSwitchMetric(TaskSwitchSource source) { | |
261 if (GetAshConfig() == Config::MUS) { | |
262 Shell::Get()->metrics()->task_switch_metrics_recorder().OnTaskSwitch( | |
263 source); | |
264 return; | |
265 } | |
266 // TODO: http://crbug.com/616581. | |
267 NOTIMPLEMENTED(); | |
268 } | |
269 | |
270 std::unique_ptr<WindowResizer> WmShellMus::CreateDragWindowResizer( | |
271 std::unique_ptr<WindowResizer> next_window_resizer, | |
272 wm::WindowState* window_state) { | |
273 if (GetAshConfig() == Config::MUS) { | |
274 return base::WrapUnique(ash::DragWindowResizer::Create( | |
275 next_window_resizer.release(), window_state)); | |
276 } | |
277 return base::MakeUnique<ash::mus::DragWindowResizer>( | |
278 std::move(next_window_resizer), window_state); | |
279 } | |
280 | |
281 std::unique_ptr<WindowCycleEventFilter> | |
282 WmShellMus::CreateWindowCycleEventFilter() { | |
283 if (GetAshConfig() == Config::MUS) | |
284 return base::MakeUnique<WindowCycleEventFilterAura>(); | |
285 | |
286 // TODO: implement me, http://crbug.com/629191. | |
287 return nullptr; | |
288 } | |
289 | |
290 std::unique_ptr<wm::MaximizeModeEventHandler> | |
291 WmShellMus::CreateMaximizeModeEventHandler() { | |
292 if (GetAshConfig() == Config::MUS) | |
293 return base::MakeUnique<wm::MaximizeModeEventHandlerAura>(); | |
294 | |
295 // TODO: need support for window manager to get events before client: | |
296 // http://crbug.com/624157. | |
297 NOTIMPLEMENTED(); | |
298 return nullptr; | |
299 } | |
300 | |
301 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> | |
302 WmShellMus::CreateScopedDisableInternalMouseAndKeyboard() { | |
303 if (GetAshConfig() == Config::MUS) { | |
304 #if defined(USE_OZONE) | |
305 return base::MakeUnique<ScopedDisableInternalMouseAndKeyboardOzone>(); | |
306 #else | |
307 // TODO: remove this conditional. Bots build this config, but it is never | |
308 // actually used. http://crbug.com/671355. | |
309 NOTREACHED(); | |
310 return nullptr; | |
311 #endif | |
312 } | |
313 | |
314 // TODO: needs implementation for mus, http://crbug.com/624967. | |
315 NOTIMPLEMENTED(); | |
316 return nullptr; | |
317 } | |
318 | |
319 std::unique_ptr<WorkspaceEventHandler> WmShellMus::CreateWorkspaceEventHandler( | |
320 WmWindow* workspace_window) { | |
321 if (GetAshConfig() == Config::MUS) | |
322 return base::MakeUnique<WorkspaceEventHandlerAura>(workspace_window); | |
323 | |
324 return base::MakeUnique<WorkspaceEventHandlerMus>( | |
325 WmWindow::GetAuraWindow(workspace_window)); | |
326 } | |
327 | |
328 std::unique_ptr<ImmersiveFullscreenController> | |
329 WmShellMus::CreateImmersiveFullscreenController() { | |
330 return base::MakeUnique<ImmersiveFullscreenController>(); | |
331 } | |
332 | |
333 std::unique_ptr<KeyboardUI> WmShellMus::CreateKeyboardUI() { | |
334 if (GetAshConfig() == Config::MUS) | |
335 return KeyboardUI::Create(); | |
336 | |
337 return KeyboardUIMus::Create(window_manager_->connector()); | |
338 } | |
339 | |
340 std::unique_ptr<KeyEventWatcher> WmShellMus::CreateKeyEventWatcher() { | |
341 if (GetAshConfig() == Config::MUS) | |
342 return base::MakeUnique<KeyEventWatcherAura>(); | |
343 | |
344 // TODO: needs implementation for mus, http://crbug.com/649600. | |
345 NOTIMPLEMENTED(); | |
346 return std::unique_ptr<KeyEventWatcher>(); | |
347 } | |
348 | |
349 SessionStateDelegate* WmShellMus::GetSessionStateDelegate() { | |
350 return session_state_delegate_ ? session_state_delegate_.get() | |
351 : Shell::Get()->session_state_delegate(); | |
352 } | |
353 | |
354 void WmShellMus::AddDisplayObserver(WmDisplayObserver* observer) { | |
355 // TODO: need WmDisplayObserver support for mus. http://crbug.com/705831. | |
356 NOTIMPLEMENTED(); | |
357 } | |
358 | |
359 void WmShellMus::RemoveDisplayObserver(WmDisplayObserver* observer) { | |
360 // TODO: need WmDisplayObserver support for mus. http://crbug.com/705831. | |
361 NOTIMPLEMENTED(); | |
362 } | |
363 | |
364 void WmShellMus::AddPointerWatcher(views::PointerWatcher* watcher, | |
365 views::PointerWatcherEventTypes events) { | |
366 if (GetAshConfig() == Config::MUS) { | |
367 mus_state_->pointer_watcher_adapter->AddPointerWatcher(watcher, events); | |
368 return; | |
369 } | |
370 | |
371 // TODO: implement drags for mus pointer watcher, http://crbug.com/641164. | |
372 // NOTIMPLEMENTED drags for mus pointer watcher. | |
373 mash_state_->pointer_watcher_event_router->AddPointerWatcher( | |
374 watcher, events == views::PointerWatcherEventTypes::MOVES); | |
375 } | |
376 | |
377 void WmShellMus::RemovePointerWatcher(views::PointerWatcher* watcher) { | |
378 if (GetAshConfig() == Config::MUS) { | |
379 mus_state_->pointer_watcher_adapter->RemovePointerWatcher(watcher); | |
380 return; | |
381 } | |
382 | |
383 mash_state_->pointer_watcher_event_router->RemovePointerWatcher(watcher); | |
384 } | |
385 | |
386 bool WmShellMus::IsTouchDown() { | |
387 if (GetAshConfig() == Config::MUS) | |
388 return aura::Env::GetInstance()->is_touch_down(); | |
389 | |
390 // TODO: implement me, http://crbug.com/634967. | |
391 // NOTIMPLEMENTED is too spammy here. | |
392 return false; | |
393 } | |
394 | |
395 void WmShellMus::ToggleIgnoreExternalKeyboard() { | |
396 if (GetAshConfig() == Config::MUS) { | |
397 Shell::Get()->virtual_keyboard_controller()->ToggleIgnoreExternalKeyboard(); | |
398 return; | |
399 } | |
400 | |
401 NOTIMPLEMENTED(); | |
402 } | |
403 | |
404 void WmShellMus::SetLaserPointerEnabled(bool enabled) { | |
405 if (GetAshConfig() == Config::MUS) { | |
406 Shell::Get()->laser_pointer_controller()->SetEnabled(enabled); | |
407 return; | |
408 } | |
409 | |
410 NOTIMPLEMENTED(); | |
411 } | |
412 | |
413 void WmShellMus::SetPartialMagnifierEnabled(bool enabled) { | |
414 if (GetAshConfig() == Config::MUS) { | |
415 Shell::Get()->partial_magnification_controller()->SetEnabled(enabled); | |
416 return; | |
417 } | |
418 | |
419 NOTIMPLEMENTED(); | |
420 } | |
421 | |
422 void WmShellMus::CreatePointerWatcherAdapter() { | |
423 // In Config::MUS PointerWatcherAdapter must be created when this function is | |
424 // called (it is order dependent), that is not the case with Config::MASH. | |
425 if (GetAshConfig() == Config::MUS) { | |
426 mus_state_->pointer_watcher_adapter = | |
427 base::MakeUnique<PointerWatcherAdapter>(); | |
428 } | |
429 } | |
430 | |
431 void WmShellMus::CreatePrimaryHost() {} | |
432 | |
433 void WmShellMus::InitHosts(const ShellInitParams& init_params) { | |
434 window_manager_->CreatePrimaryRootWindowController( | |
435 base::WrapUnique(init_params.primary_window_tree_host)); | |
436 } | |
437 | |
438 std::unique_ptr<AcceleratorController> | |
439 WmShellMus::CreateAcceleratorController() { | |
440 if (GetAshConfig() == Config::MUS) { | |
441 DCHECK(!mus_state_->accelerator_controller_delegate); | |
442 mus_state_->accelerator_controller_delegate = | |
443 base::MakeUnique<AcceleratorControllerDelegateAura>(); | |
444 return base::MakeUnique<AcceleratorController>( | |
445 mus_state_->accelerator_controller_delegate.get(), nullptr); | |
446 } | |
447 | |
448 DCHECK(!mash_state_->accelerator_controller_delegate); | |
449 | |
450 uint16_t accelerator_namespace_id = 0u; | |
451 const bool add_result = | |
452 window_manager_->GetNextAcceleratorNamespaceId(&accelerator_namespace_id); | |
453 // WmShellMus is created early on, so that GetNextAcceleratorNamespaceId() | |
454 // should always succeed. | |
455 DCHECK(add_result); | |
456 | |
457 mash_state_->accelerator_controller_delegate = | |
458 base::MakeUnique<AcceleratorControllerDelegateMus>(window_manager_); | |
459 mash_state_->accelerator_controller_registrar = | |
460 base ::MakeUnique<AcceleratorControllerRegistrar>( | |
461 window_manager_, accelerator_namespace_id); | |
462 return base::MakeUnique<AcceleratorController>( | |
463 mash_state_->accelerator_controller_delegate.get(), | |
464 mash_state_->accelerator_controller_registrar.get()); | |
465 } | |
466 | |
467 } // namespace mus | |
468 } // namespace ash | |
OLD | NEW |