Chromium Code Reviews| 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/wm_shell_mus.h" | 5 #include "ash/mus/bridge/wm_shell_mus.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accelerators/accelerator_controller.h" | 9 #include "ash/common/accelerators/accelerator_controller.h" |
| 10 #include "ash/common/key_event_watcher.h" | 10 #include "ash/common/key_event_watcher.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "ash/mus/bridge/wm_window_mus.h" | 26 #include "ash/mus/bridge/wm_window_mus.h" |
| 27 #include "ash/mus/bridge/workspace_event_handler_mus.h" | 27 #include "ash/mus/bridge/workspace_event_handler_mus.h" |
| 28 #include "ash/mus/drag_window_resizer.h" | 28 #include "ash/mus/drag_window_resizer.h" |
| 29 #include "ash/mus/keyboard_ui_mus.h" | 29 #include "ash/mus/keyboard_ui_mus.h" |
| 30 #include "ash/mus/root_window_controller.h" | 30 #include "ash/mus/root_window_controller.h" |
| 31 #include "ash/mus/window_manager.h" | 31 #include "ash/mus/window_manager.h" |
| 32 #include "ash/public/cpp/shell_window_ids.h" | 32 #include "ash/public/cpp/shell_window_ids.h" |
| 33 #include "ash/shared/immersive_fullscreen_controller.h" | 33 #include "ash/shared/immersive_fullscreen_controller.h" |
| 34 #include "base/memory/ptr_util.h" | 34 #include "base/memory/ptr_util.h" |
| 35 #include "components/user_manager/user_info_impl.h" | 35 #include "components/user_manager/user_info_impl.h" |
| 36 #include "services/ui/common/util.h" | 36 #include "ui/aura/mus/window_tree_client.h" |
| 37 #include "services/ui/public/cpp/window.h" | 37 #include "ui/aura/window.h" |
| 38 #include "services/ui/public/cpp/window_tree_client.h" | |
| 39 #include "ui/display/manager/managed_display_info.h" | 38 #include "ui/display/manager/managed_display_info.h" |
| 40 #include "ui/display/screen.h" | 39 #include "ui/display/screen.h" |
| 41 #include "ui/views/mus/pointer_watcher_event_router.h" | 40 #include "ui/views/mus/pointer_watcher_event_router2.h" |
| 41 #include "ui/wm/core/capture_controller.h" | |
| 42 #include "ui/wm/core/focus_controller.h" | |
| 42 | 43 |
| 43 namespace ash { | 44 namespace ash { |
| 44 namespace mus { | 45 namespace mus { |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 // TODO(jamescook): After ShellDelegate is ported to ash/common use | 49 // TODO(jamescook): After ShellDelegate is ported to ash/common use |
| 49 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version | 50 // ShellDelegate::CreateSessionStateDelegate() to construct the mus version |
| 50 // of SessionStateDelegate. | 51 // of SessionStateDelegate. |
| 51 class SessionStateDelegateStub : public SessionStateDelegate { | 52 class SessionStateDelegateStub : public SessionStateDelegate { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 std::unique_ptr<user_manager::UserInfo> user_info_; | 105 std::unique_ptr<user_manager::UserInfo> user_info_; |
| 105 | 106 |
| 106 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub); | 107 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace | 110 } // namespace |
| 110 | 111 |
| 111 WmShellMus::WmShellMus( | 112 WmShellMus::WmShellMus( |
| 112 std::unique_ptr<ShellDelegate> shell_delegate, | 113 std::unique_ptr<ShellDelegate> shell_delegate, |
| 113 WindowManager* window_manager, | 114 WindowManager* window_manager, |
| 114 views::PointerWatcherEventRouter* pointer_watcher_event_router) | 115 views::PointerWatcherEventRouter2* pointer_watcher_event_router) |
| 115 : WmShell(std::move(shell_delegate)), | 116 : WmShell(std::move(shell_delegate)), |
| 116 window_manager_(window_manager), | 117 window_manager_(window_manager), |
| 117 pointer_watcher_event_router_(pointer_watcher_event_router), | 118 pointer_watcher_event_router_(pointer_watcher_event_router), |
| 118 session_state_delegate_(new SessionStateDelegateStub) { | 119 session_state_delegate_(new SessionStateDelegateStub) { |
| 119 window_tree_client()->AddObserver(this); | |
| 120 WmShell::Set(this); | 120 WmShell::Set(this); |
| 121 | 121 |
| 122 uint16_t accelerator_namespace_id = 0u; | 122 uint16_t accelerator_namespace_id = 0u; |
| 123 const bool add_result = | 123 const bool add_result = |
| 124 window_manager->GetNextAcceleratorNamespaceId(&accelerator_namespace_id); | 124 window_manager->GetNextAcceleratorNamespaceId(&accelerator_namespace_id); |
| 125 // WmShellMus is created early on, so that this should always succeed. | 125 // WmShellMus is created early on, so that this should always succeed. |
| 126 DCHECK(add_result); | 126 DCHECK(add_result); |
| 127 accelerator_controller_delegate_.reset( | 127 accelerator_controller_delegate_.reset( |
| 128 new AcceleratorControllerDelegateMus(window_manager_)); | 128 new AcceleratorControllerDelegateMus(window_manager_)); |
| 129 accelerator_controller_registrar_.reset(new AcceleratorControllerRegistrar( | 129 accelerator_controller_registrar_.reset(new AcceleratorControllerRegistrar( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 150 | 150 |
| 151 // Destroy maximize mode controller early on since it has some observers which | 151 // Destroy maximize mode controller early on since it has some observers which |
| 152 // need to be removed. | 152 // need to be removed. |
| 153 DeleteMaximizeModeController(); | 153 DeleteMaximizeModeController(); |
| 154 DeleteToastManager(); | 154 DeleteToastManager(); |
| 155 DeleteSystemTrayDelegate(); | 155 DeleteSystemTrayDelegate(); |
| 156 // Has to happen before ~MruWindowTracker. | 156 // Has to happen before ~MruWindowTracker. |
| 157 DeleteWindowCycleController(); | 157 DeleteWindowCycleController(); |
| 158 DeleteWindowSelectorController(); | 158 DeleteWindowSelectorController(); |
| 159 DeleteMruWindowTracker(); | 159 DeleteMruWindowTracker(); |
| 160 if (window_tree_client()) | |
| 161 window_tree_client()->RemoveObserver(this); | |
| 162 WmShell::Set(nullptr); | 160 WmShell::Set(nullptr); |
| 163 } | 161 } |
| 164 | 162 |
| 165 // static | 163 // static |
| 166 WmShellMus* WmShellMus::Get() { | 164 WmShellMus* WmShellMus::Get() { |
| 167 return static_cast<WmShellMus*>(WmShell::Get()); | 165 return static_cast<WmShellMus*>(WmShell::Get()); |
| 168 } | 166 } |
| 169 | 167 |
| 170 void WmShellMus::AddRootWindowController( | 168 void WmShellMus::AddRootWindowController( |
| 171 WmRootWindowControllerMus* controller) { | 169 WmRootWindowControllerMus* controller) { |
| 172 root_window_controllers_.push_back(controller); | 170 root_window_controllers_.push_back(controller); |
| 173 // The first root window will be the initial root for new windows. | 171 // The first root window will be the initial root for new windows. |
| 174 if (!GetRootWindowForNewWindows()) | 172 if (!GetRootWindowForNewWindows()) |
| 175 set_root_window_for_new_windows(controller->GetWindow()); | 173 set_root_window_for_new_windows(controller->GetWindow()); |
| 176 } | 174 } |
| 177 | 175 |
| 178 void WmShellMus::RemoveRootWindowController( | 176 void WmShellMus::RemoveRootWindowController( |
| 179 WmRootWindowControllerMus* controller) { | 177 WmRootWindowControllerMus* controller) { |
| 180 auto iter = std::find(root_window_controllers_.begin(), | 178 auto iter = std::find(root_window_controllers_.begin(), |
| 181 root_window_controllers_.end(), controller); | 179 root_window_controllers_.end(), controller); |
| 182 DCHECK(iter != root_window_controllers_.end()); | 180 DCHECK(iter != root_window_controllers_.end()); |
| 183 root_window_controllers_.erase(iter); | 181 root_window_controllers_.erase(iter); |
| 184 } | 182 } |
| 185 | 183 |
| 186 // static | 184 // static |
| 187 WmWindowMus* WmShellMus::GetToplevelAncestor(ui::Window* window) { | 185 WmWindowMus* WmShellMus::GetToplevelAncestor(aura::Window* window) { |
| 188 while (window) { | 186 while (window) { |
| 189 if (IsActivationParent(window->parent())) | 187 if (IsActivationParent(window->parent())) |
| 190 return WmWindowMus::Get(window); | 188 return WmWindowMus::Get(window); |
| 191 window = window->parent(); | 189 window = window->parent(); |
| 192 } | 190 } |
| 193 return nullptr; | 191 return nullptr; |
| 194 } | 192 } |
| 195 | 193 |
| 196 WmRootWindowControllerMus* WmShellMus::GetRootWindowControllerWithDisplayId( | 194 WmRootWindowControllerMus* WmShellMus::GetRootWindowControllerWithDisplayId( |
| 197 int64_t id) { | 195 int64_t id) { |
| 198 for (WmRootWindowControllerMus* root_window_controller : | 196 for (WmRootWindowControllerMus* root_window_controller : |
| 199 root_window_controllers_) { | 197 root_window_controllers_) { |
| 200 if (root_window_controller->GetDisplay().id() == id) | 198 if (root_window_controller->GetDisplay().id() == id) |
| 201 return root_window_controller; | 199 return root_window_controller; |
| 202 } | 200 } |
| 203 NOTREACHED(); | 201 NOTREACHED(); |
| 204 return nullptr; | 202 return nullptr; |
| 205 } | 203 } |
| 206 | 204 |
| 205 aura::WindowTreeClient* WmShellMus::window_tree_client() { | |
| 206 return window_manager_->window_tree_client(); | |
| 207 } | |
| 208 | |
| 207 bool WmShellMus::IsRunningInMash() const { | 209 bool WmShellMus::IsRunningInMash() const { |
| 208 return true; | 210 return true; |
| 209 } | 211 } |
| 210 | 212 |
| 211 WmWindow* WmShellMus::NewWindow(ui::wm::WindowType window_type, | 213 WmWindow* WmShellMus::NewWindow(ui::wm::WindowType window_type, |
| 212 ui::LayerType layer_type) { | 214 ui::LayerType layer_type) { |
| 213 WmWindowMus* window = WmWindowMus::Get(window_tree_client()->NewWindow()); | 215 aura::Window* window = new aura::Window(nullptr); |
| 214 window->set_wm_window_type(window_type); | 216 window->SetType(window_type); |
| 215 // TODO(sky): support layer_type. | 217 window->Init(layer_type); |
| 216 NOTIMPLEMENTED(); | 218 return WmWindowMus::Get(window); |
| 217 return window; | |
| 218 } | 219 } |
| 219 | 220 |
| 220 WmWindow* WmShellMus::GetFocusedWindow() { | 221 WmWindow* WmShellMus::GetFocusedWindow() { |
| 221 return WmWindowMus::Get(window_tree_client()->GetFocusedWindow()); | 222 // TODO: remove as both WmShells use same implementation. |
| 223 return WmWindowMus::Get(static_cast<aura::client::FocusClient*>( | |
| 224 window_manager_->focus_controller()) | |
| 225 ->GetFocusedWindow()); | |
| 222 } | 226 } |
| 223 | 227 |
| 224 WmWindow* WmShellMus::GetActiveWindow() { | 228 WmWindow* WmShellMus::GetActiveWindow() { |
| 225 return GetToplevelAncestor(window_tree_client()->GetFocusedWindow()); | 229 // TODO: remove as both WmShells use same implementation. |
| 230 return WmWindowMus::Get(static_cast<aura::client::ActivationClient*>( | |
| 231 window_manager_->focus_controller()) | |
| 232 ->GetActiveWindow()); | |
| 226 } | 233 } |
| 227 | 234 |
| 228 WmWindow* WmShellMus::GetCaptureWindow() { | 235 WmWindow* WmShellMus::GetCaptureWindow() { |
| 229 return WmWindowMus::Get(window_tree_client()->GetCaptureWindow()); | 236 // TODO: remove as both WmShells use same implementation. |
| 237 return WmWindowMus::Get(::wm::CaptureController::Get()->GetCaptureWindow()); | |
| 230 } | 238 } |
| 231 | 239 |
| 232 WmWindow* WmShellMus::GetPrimaryRootWindow() { | 240 WmWindow* WmShellMus::GetPrimaryRootWindow() { |
| 233 return root_window_controllers_[0]->GetWindow(); | 241 return root_window_controllers_[0]->GetWindow(); |
| 234 } | 242 } |
| 235 | 243 |
| 236 WmWindow* WmShellMus::GetRootWindowForDisplayId(int64_t display_id) { | 244 WmWindow* WmShellMus::GetRootWindowForDisplayId(int64_t display_id) { |
| 237 return GetRootWindowControllerWithDisplayId(display_id)->GetWindow(); | 245 return GetRootWindowControllerWithDisplayId(display_id)->GetWindow(); |
| 238 } | 246 } |
| 239 | 247 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 269 return false; | 277 return false; |
| 270 } | 278 } |
| 271 | 279 |
| 272 bool WmShellMus::IsForceMaximizeOnFirstRun() { | 280 bool WmShellMus::IsForceMaximizeOnFirstRun() { |
| 273 NOTIMPLEMENTED(); | 281 NOTIMPLEMENTED(); |
| 274 return false; | 282 return false; |
| 275 } | 283 } |
| 276 | 284 |
| 277 void WmShellMus::SetDisplayWorkAreaInsets(WmWindow* window, | 285 void WmShellMus::SetDisplayWorkAreaInsets(WmWindow* window, |
| 278 const gfx::Insets& insets) { | 286 const gfx::Insets& insets) { |
| 279 RootWindowController* root_window_controller = | 287 WmRootWindowControllerMus* root_window_controller_mus = |
| 280 GetRootWindowControllerWithDisplayId( | 288 static_cast<WmWindowMus*>(window)->GetRootWindowControllerMus(); |
| 281 WmWindowMus::GetMusWindow(window)->display_id()) | 289 if (!root_window_controller_mus) |
|
James Cook
2016/12/05 19:21:44
Q: How could this be null when root_window_control
sky
2016/12/05 21:39:19
You are right. Fixed.
| |
| 282 ->root_window_controller(); | 290 return; |
| 283 root_window_controller->SetWorkAreaInests(insets); | 291 root_window_controller_mus->root_window_controller()->SetWorkAreaInests( |
| 292 insets); | |
| 284 } | 293 } |
| 285 | 294 |
| 286 bool WmShellMus::IsPinned() { | 295 bool WmShellMus::IsPinned() { |
| 287 NOTIMPLEMENTED(); | 296 NOTIMPLEMENTED(); |
| 288 return false; | 297 return false; |
| 289 } | 298 } |
| 290 | 299 |
| 291 void WmShellMus::SetPinnedWindow(WmWindow* window) { | 300 void WmShellMus::SetPinnedWindow(WmWindow* window) { |
| 292 NOTIMPLEMENTED(); | 301 NOTIMPLEMENTED(); |
| 293 } | 302 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> | 363 std::unique_ptr<ScopedDisableInternalMouseAndKeyboard> |
| 355 WmShellMus::CreateScopedDisableInternalMouseAndKeyboard() { | 364 WmShellMus::CreateScopedDisableInternalMouseAndKeyboard() { |
| 356 // TODO: needs implementation for mus, http://crbug.com/624967. | 365 // TODO: needs implementation for mus, http://crbug.com/624967. |
| 357 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
| 358 return nullptr; | 367 return nullptr; |
| 359 } | 368 } |
| 360 | 369 |
| 361 std::unique_ptr<WorkspaceEventHandler> WmShellMus::CreateWorkspaceEventHandler( | 370 std::unique_ptr<WorkspaceEventHandler> WmShellMus::CreateWorkspaceEventHandler( |
| 362 WmWindow* workspace_window) { | 371 WmWindow* workspace_window) { |
| 363 return base::MakeUnique<WorkspaceEventHandlerMus>( | 372 return base::MakeUnique<WorkspaceEventHandlerMus>( |
| 364 WmWindowMus::GetMusWindow(workspace_window)); | 373 WmWindowMus::GetAuraWindow(workspace_window)); |
| 365 } | 374 } |
| 366 | 375 |
| 367 std::unique_ptr<ImmersiveFullscreenController> | 376 std::unique_ptr<ImmersiveFullscreenController> |
| 368 WmShellMus::CreateImmersiveFullscreenController() { | 377 WmShellMus::CreateImmersiveFullscreenController() { |
| 369 return base::MakeUnique<ImmersiveFullscreenController>(); | 378 return base::MakeUnique<ImmersiveFullscreenController>(); |
| 370 } | 379 } |
| 371 | 380 |
| 372 std::unique_ptr<KeyEventWatcher> WmShellMus::CreateKeyEventWatcher() { | 381 std::unique_ptr<KeyEventWatcher> WmShellMus::CreateKeyEventWatcher() { |
| 373 // TODO: needs implementation for mus, http://crbug.com/649600. | 382 // TODO: needs implementation for mus, http://crbug.com/649600. |
| 374 NOTIMPLEMENTED(); | 383 NOTIMPLEMENTED(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 #if defined(OS_CHROMEOS) | 439 #if defined(OS_CHROMEOS) |
| 431 void WmShellMus::ToggleIgnoreExternalKeyboard() { | 440 void WmShellMus::ToggleIgnoreExternalKeyboard() { |
| 432 NOTIMPLEMENTED(); | 441 NOTIMPLEMENTED(); |
| 433 } | 442 } |
| 434 | 443 |
| 435 void WmShellMus::SetLaserPointerEnabled(bool enabled) { | 444 void WmShellMus::SetLaserPointerEnabled(bool enabled) { |
| 436 NOTIMPLEMENTED(); | 445 NOTIMPLEMENTED(); |
| 437 } | 446 } |
| 438 #endif // defined(OS_CHROMEOS) | 447 #endif // defined(OS_CHROMEOS) |
| 439 | 448 |
| 440 ui::WindowTreeClient* WmShellMus::window_tree_client() { | |
| 441 return window_manager_->window_tree_client(); | |
| 442 } | |
| 443 | |
| 444 // static | 449 // static |
| 445 bool WmShellMus::IsActivationParent(ui::Window* window) { | 450 bool WmShellMus::IsActivationParent(aura::Window* window) { |
| 446 return window && IsActivatableShellWindowId( | 451 return window && IsActivatableShellWindowId( |
| 447 WmWindowMus::Get(window)->GetShellWindowId()); | 452 WmWindowMus::Get(window)->GetShellWindowId()); |
| 448 } | 453 } |
| 449 | 454 |
| 450 // TODO: support OnAttemptToReactivateWindow, http://crbug.com/615114. | 455 // TODO: support OnAttemptToReactivateWindow, http://crbug.com/615114. |
| 451 void WmShellMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, | 456 // TODO: Nuke and let client code use ActivationChangeObserver directly. |
| 452 ui::Window* lost_focus) { | 457 void WmShellMus::OnWindowActivated(ActivationReason reason, |
| 453 WmWindow* gained_active = GetToplevelAncestor(gained_focus); | 458 aura::Window* gained_active, |
| 454 if (gained_active) | 459 aura::Window* lost_active) { |
| 455 set_root_window_for_new_windows(gained_active->GetRootWindow()); | 460 WmWindow* gained_active_wm = WmWindowMus::Get(gained_active); |
| 456 | 461 if (gained_active_wm) |
| 457 WmWindow* lost_active = GetToplevelAncestor(lost_focus); | 462 set_root_window_for_new_windows(gained_active_wm->GetRootWindow()); |
| 458 if (gained_active == lost_active) | 463 WmWindow* lost_active_wm = WmWindowMus::Get(lost_active); |
| 459 return; | |
| 460 | |
| 461 for (auto& observer : activation_observers_) | 464 for (auto& observer : activation_observers_) |
| 462 observer.OnWindowActivated(gained_active, lost_active); | 465 observer.OnWindowActivated(gained_active_wm, lost_active_wm); |
| 463 } | |
| 464 | |
| 465 void WmShellMus::OnDidDestroyClient(ui::WindowTreeClient* client) { | |
| 466 DCHECK_EQ(window_tree_client(), client); | |
| 467 client->RemoveObserver(this); | |
| 468 } | 466 } |
| 469 | 467 |
| 470 } // namespace mus | 468 } // namespace mus |
| 471 } // namespace ash | 469 } // namespace ash |
| OLD | NEW |