| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/window_manager.h" | 5 #include "ash/mus/window_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/aura/wm_window_aura.h" |
| 11 #include "ash/common/wm/container_finder.h" | 12 #include "ash/common/wm/container_finder.h" |
| 12 #include "ash/common/wm/window_state.h" | 13 #include "ash/common/wm/window_state.h" |
| 13 #include "ash/display/screen_position_controller.h" | 14 #include "ash/display/screen_position_controller.h" |
| 14 #include "ash/mus/accelerators/accelerator_handler.h" | 15 #include "ash/mus/accelerators/accelerator_handler.h" |
| 15 #include "ash/mus/accelerators/accelerator_ids.h" | 16 #include "ash/mus/accelerators/accelerator_ids.h" |
| 16 #include "ash/mus/bridge/wm_lookup_mus.h" | 17 #include "ash/mus/bridge/wm_lookup_mus.h" |
| 17 #include "ash/mus/bridge/wm_shell_mus.h" | 18 #include "ash/mus/bridge/wm_shell_mus.h" |
| 18 #include "ash/mus/bridge/wm_window_mus.h" | |
| 19 #include "ash/mus/move_event_handler.h" | 19 #include "ash/mus/move_event_handler.h" |
| 20 #include "ash/mus/non_client_frame_controller.h" | 20 #include "ash/mus/non_client_frame_controller.h" |
| 21 #include "ash/mus/property_util.h" | 21 #include "ash/mus/property_util.h" |
| 22 #include "ash/mus/root_window_controller.h" | 22 #include "ash/mus/root_window_controller.h" |
| 23 #include "ash/mus/screen_mus.h" | 23 #include "ash/mus/screen_mus.h" |
| 24 #include "ash/mus/shadow_controller.h" | 24 #include "ash/mus/shadow_controller.h" |
| 25 #include "ash/mus/shell_delegate_mus.h" | 25 #include "ash/mus/shell_delegate_mus.h" |
| 26 #include "ash/mus/window_manager_observer.h" | 26 #include "ash/mus/window_manager_observer.h" |
| 27 #include "ash/mus/window_properties.h" | 27 #include "ash/mus/window_properties.h" |
| 28 #include "ash/public/cpp/shell_window_ids.h" | 28 #include "ash/public/cpp/shell_window_ids.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 kPanelAttachedKey, ui::mojom::WindowManager::kPanelAttached_Property); | 88 kPanelAttachedKey, ui::mojom::WindowManager::kPanelAttached_Property); |
| 89 property_converter_->RegisterProperty( | 89 property_converter_->RegisterProperty( |
| 90 kRenderTitleAreaProperty, | 90 kRenderTitleAreaProperty, |
| 91 ui::mojom::WindowManager::kRenderParentTitleArea_Property); | 91 ui::mojom::WindowManager::kRenderParentTitleArea_Property); |
| 92 property_converter_->RegisterProperty( | 92 property_converter_->RegisterProperty( |
| 93 kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property); | 93 kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property); |
| 94 } | 94 } |
| 95 | 95 |
| 96 WindowManager::~WindowManager() { | 96 WindowManager::~WindowManager() { |
| 97 Shutdown(); | 97 Shutdown(); |
| 98 aura::Env::GetInstance()->RemoveObserver(this); | |
| 99 ash::Shell::set_window_tree_client(nullptr); | 98 ash::Shell::set_window_tree_client(nullptr); |
| 99 ash::Shell::set_window_manager_client(nullptr); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void WindowManager::Init( | 102 void WindowManager::Init( |
| 103 std::unique_ptr<aura::WindowTreeClient> window_tree_client, | 103 std::unique_ptr<aura::WindowTreeClient> window_tree_client, |
| 104 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { | 104 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { |
| 105 DCHECK(window_manager_client_); | 105 DCHECK(window_manager_client_); |
| 106 DCHECK(!window_tree_client_); | 106 DCHECK(!window_tree_client_); |
| 107 window_tree_client_ = std::move(window_tree_client); | 107 window_tree_client_ = std::move(window_tree_client); |
| 108 | 108 |
| 109 DCHECK_EQ(nullptr, ash::Shell::window_tree_client()); | 109 DCHECK_EQ(nullptr, ash::Shell::window_tree_client()); |
| 110 ash::Shell::set_window_tree_client(window_tree_client_.get()); | 110 ash::Shell::set_window_tree_client(window_tree_client_.get()); |
| 111 | 111 |
| 112 aura::Env::GetInstance()->AddObserver(this); | |
| 113 | |
| 114 // |connector_| will be null in some tests. | 112 // |connector_| will be null in some tests. |
| 115 if (connector_) | 113 if (connector_) |
| 116 connector_->BindInterface(ui::mojom::kServiceName, &display_controller_); | 114 connector_->BindInterface(ui::mojom::kServiceName, &display_controller_); |
| 117 | 115 |
| 118 screen_ = base::MakeUnique<ScreenMus>(); | 116 screen_ = base::MakeUnique<ScreenMus>(); |
| 119 display::Screen::SetScreenInstance(screen_.get()); | 117 display::Screen::SetScreenInstance(screen_.get()); |
| 120 | 118 |
| 121 pointer_watcher_event_router_ = | 119 pointer_watcher_event_router_ = |
| 122 base::MakeUnique<views::PointerWatcherEventRouter>( | 120 base::MakeUnique<views::PointerWatcherEventRouter>( |
| 123 window_tree_client_.get()); | 121 window_tree_client_.get()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 151 aura::Window* WindowManager::NewTopLevelWindow( | 149 aura::Window* WindowManager::NewTopLevelWindow( |
| 152 ui::mojom::WindowType window_type, | 150 ui::mojom::WindowType window_type, |
| 153 std::map<std::string, std::vector<uint8_t>>* properties) { | 151 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 154 RootWindowController* root_window_controller = | 152 RootWindowController* root_window_controller = |
| 155 GetRootWindowControllerForNewTopLevelWindow(properties); | 153 GetRootWindowControllerForNewTopLevelWindow(properties); |
| 156 aura::Window* window = | 154 aura::Window* window = |
| 157 root_window_controller->NewTopLevelWindow(window_type, properties); | 155 root_window_controller->NewTopLevelWindow(window_type, properties); |
| 158 if (properties->count( | 156 if (properties->count( |
| 159 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) { | 157 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) { |
| 160 wm::WindowState* window_state = | 158 wm::WindowState* window_state = |
| 161 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); | 159 static_cast<WmWindow*>(WmWindowAura::Get(window))->GetWindowState(); |
| 162 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>( | 160 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>( |
| 163 (*properties) | 161 (*properties) |
| 164 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property])); | 162 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property])); |
| 165 // No need to persist this value. | 163 // No need to persist this value. |
| 166 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); | 164 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); |
| 167 } | 165 } |
| 168 return window; | 166 return window; |
| 169 } | 167 } |
| 170 | 168 |
| 171 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { | 169 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 302 |
| 305 window_tree_client_.reset(); | 303 window_tree_client_.reset(); |
| 306 window_manager_client_ = nullptr; | 304 window_manager_client_ = nullptr; |
| 307 | 305 |
| 308 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); | 306 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); |
| 309 display::Screen::SetScreenInstance(nullptr); | 307 display::Screen::SetScreenInstance(nullptr); |
| 310 } | 308 } |
| 311 | 309 |
| 312 RootWindowController* WindowManager::GetPrimaryRootWindowController() { | 310 RootWindowController* WindowManager::GetPrimaryRootWindowController() { |
| 313 return RootWindowController::ForWindow( | 311 return RootWindowController::ForWindow( |
| 314 static_cast<WmWindowMus*>( | 312 static_cast<WmWindowAura*>( |
| 315 WmShell::Get()->GetPrimaryRootWindowController()->GetWindow()) | 313 WmShell::Get()->GetPrimaryRootWindowController()->GetWindow()) |
| 316 ->aura_window()); | 314 ->aura_window()); |
| 317 } | 315 } |
| 318 | 316 |
| 319 RootWindowController* | 317 RootWindowController* |
| 320 WindowManager::GetRootWindowControllerForNewTopLevelWindow( | 318 WindowManager::GetRootWindowControllerForNewTopLevelWindow( |
| 321 std::map<std::string, std::vector<uint8_t>>* properties) { | 319 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 322 // If a specific display was requested, use it. | 320 // If a specific display was requested, use it. |
| 323 const int64_t display_id = GetInitialDisplayId(*properties); | 321 const int64_t display_id = GetInitialDisplayId(*properties); |
| 324 for (auto& root_window_controller_ptr : root_window_controllers_) { | 322 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 325 if (root_window_controller_ptr->display().id() == display_id) | 323 if (root_window_controller_ptr->display().id() == display_id) |
| 326 return root_window_controller_ptr.get(); | 324 return root_window_controller_ptr.get(); |
| 327 } | 325 } |
| 328 | 326 |
| 329 return RootWindowController::ForWindow( | 327 return RootWindowController::ForWindow( |
| 330 static_cast<WmWindowMus*>(WmShellMus::Get()->GetRootWindowForNewWindows()) | 328 static_cast<WmWindowAura*>( |
| 329 WmShellMus::Get()->GetRootWindowForNewWindows()) |
| 331 ->aura_window()); | 330 ->aura_window()); |
| 332 } | 331 } |
| 333 | 332 |
| 334 void WindowManager::OnEmbed( | 333 void WindowManager::OnEmbed( |
| 335 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 334 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 336 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 335 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 337 NOTREACHED(); | 336 NOTREACHED(); |
| 338 } | 337 } |
| 339 | 338 |
| 340 void WindowManager::OnEmbedRootDestroyed( | 339 void WindowManager::OnEmbedRootDestroyed( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 358 aura::client::CaptureClient* WindowManager::GetCaptureClient() { | 357 aura::client::CaptureClient* WindowManager::GetCaptureClient() { |
| 359 return wm_state_->capture_controller(); | 358 return wm_state_->capture_controller(); |
| 360 } | 359 } |
| 361 | 360 |
| 362 aura::PropertyConverter* WindowManager::GetPropertyConverter() { | 361 aura::PropertyConverter* WindowManager::GetPropertyConverter() { |
| 363 return property_converter_.get(); | 362 return property_converter_.get(); |
| 364 } | 363 } |
| 365 | 364 |
| 366 void WindowManager::SetWindowManagerClient(aura::WindowManagerClient* client) { | 365 void WindowManager::SetWindowManagerClient(aura::WindowManagerClient* client) { |
| 367 window_manager_client_ = client; | 366 window_manager_client_ = client; |
| 367 ash::Shell::set_window_manager_client(client); |
| 368 } | 368 } |
| 369 | 369 |
| 370 bool WindowManager::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { | 370 bool WindowManager::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { |
| 371 // TODO(sky): this indirectly sets bounds, which is against what | 371 // TODO(sky): this indirectly sets bounds, which is against what |
| 372 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. | 372 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. |
| 373 WmWindowMus::Get(window)->SetBounds(*bounds); | 373 WmWindowAura::Get(window)->SetBounds(*bounds); |
| 374 *bounds = window->bounds(); | 374 *bounds = window->bounds(); |
| 375 return true; | 375 return true; |
| 376 } | 376 } |
| 377 | 377 |
| 378 bool WindowManager::OnWmSetProperty( | 378 bool WindowManager::OnWmSetProperty( |
| 379 aura::Window* window, | 379 aura::Window* window, |
| 380 const std::string& name, | 380 const std::string& name, |
| 381 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 381 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
| 382 // TODO(sky): constrain this to set of keys we know about, and allowed values. | 382 // TODO(sky): constrain this to set of keys we know about, and allowed values. |
| 383 if (name == ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) { | 383 if (name == ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) { |
| 384 wm::WindowState* window_state = | 384 wm::WindowState* window_state = WmWindowAura::Get(window)->GetWindowState(); |
| 385 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); | |
| 386 window_state->set_ignored_by_shelf( | 385 window_state->set_ignored_by_shelf( |
| 387 new_data ? mojo::ConvertTo<bool>(**new_data) : false); | 386 new_data ? mojo::ConvertTo<bool>(**new_data) : false); |
| 388 return false; // Won't attempt to map through property converter. | 387 return false; // Won't attempt to map through property converter. |
| 389 } | 388 } |
| 390 return name == ui::mojom::WindowManager::kAppIcon_Property || | 389 return name == ui::mojom::WindowManager::kAppIcon_Property || |
| 391 name == ui::mojom::WindowManager::kShowState_Property || | 390 name == ui::mojom::WindowManager::kShowState_Property || |
| 392 name == ui::mojom::WindowManager::kPreferredSize_Property || | 391 name == ui::mojom::WindowManager::kPreferredSize_Property || |
| 393 name == ui::mojom::WindowManager::kResizeBehavior_Property || | 392 name == ui::mojom::WindowManager::kResizeBehavior_Property || |
| 394 name == ui::mojom::WindowManager::kShelfItemType_Property || | 393 name == ui::mojom::WindowManager::kShelfItemType_Property || |
| 395 name == ui::mojom::WindowManager::kWindowIcon_Property || | 394 name == ui::mojom::WindowManager::kWindowIcon_Property || |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 460 } |
| 462 | 461 |
| 463 NOTREACHED(); | 462 NOTREACHED(); |
| 464 } | 463 } |
| 465 | 464 |
| 466 void WindowManager::OnWmPerformMoveLoop( | 465 void WindowManager::OnWmPerformMoveLoop( |
| 467 aura::Window* window, | 466 aura::Window* window, |
| 468 ui::mojom::MoveLoopSource source, | 467 ui::mojom::MoveLoopSource source, |
| 469 const gfx::Point& cursor_location, | 468 const gfx::Point& cursor_location, |
| 470 const base::Callback<void(bool)>& on_done) { | 469 const base::Callback<void(bool)>& on_done) { |
| 471 WmWindowMus* child_window = WmWindowMus::Get(window); | 470 WmWindowAura* child_window = WmWindowAura::Get(window); |
| 472 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); | 471 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); |
| 473 if (!handler) { | 472 if (!handler) { |
| 474 on_done.Run(false); | 473 on_done.Run(false); |
| 475 return; | 474 return; |
| 476 } | 475 } |
| 477 | 476 |
| 478 DCHECK(!handler->IsDragInProgress()); | 477 DCHECK(!handler->IsDragInProgress()); |
| 479 aura::client::WindowMoveSource aura_source = | 478 aura::client::WindowMoveSource aura_source = |
| 480 source == ui::mojom::MoveLoopSource::MOUSE | 479 source == ui::mojom::MoveLoopSource::MOUSE |
| 481 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE | 480 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 482 : aura::client::WINDOW_MOVE_SOURCE_TOUCH; | 481 : aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
| 483 handler->AttemptToStartDrag(cursor_location, HTCAPTION, aura_source, on_done); | 482 handler->AttemptToStartDrag(cursor_location, HTCAPTION, aura_source, on_done); |
| 484 } | 483 } |
| 485 | 484 |
| 486 void WindowManager::OnWmCancelMoveLoop(aura::Window* window) { | 485 void WindowManager::OnWmCancelMoveLoop(aura::Window* window) { |
| 487 WmWindowMus* child_window = WmWindowMus::Get(window); | 486 WmWindowAura* child_window = WmWindowAura::Get(window); |
| 488 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); | 487 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); |
| 489 if (handler) | 488 if (handler) |
| 490 handler->RevertDrag(); | 489 handler->RevertDrag(); |
| 491 } | 490 } |
| 492 | 491 |
| 493 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, | 492 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, |
| 494 const ui::Event& event) { | 493 const ui::Event& event) { |
| 495 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 494 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 496 if (iter == accelerator_handlers_.end()) | 495 if (iter == accelerator_handlers_.end()) |
| 497 return ui::mojom::EventResult::HANDLED; | 496 return ui::mojom::EventResult::HANDLED; |
| 498 | 497 |
| 499 return iter->second->OnAccelerator(id, event); | 498 return iter->second->OnAccelerator(id, event); |
| 500 } | 499 } |
| 501 | 500 |
| 502 void WindowManager::OnWmSetClientArea( | 501 void WindowManager::OnWmSetClientArea( |
| 503 aura::Window* window, | 502 aura::Window* window, |
| 504 const gfx::Insets& insets, | 503 const gfx::Insets& insets, |
| 505 const std::vector<gfx::Rect>& additional_client_areas) { | 504 const std::vector<gfx::Rect>& additional_client_areas) { |
| 506 NonClientFrameController* non_client_frame_controller = | 505 NonClientFrameController* non_client_frame_controller = |
| 507 NonClientFrameController::Get(window); | 506 NonClientFrameController::Get(window); |
| 508 if (!non_client_frame_controller) | 507 if (!non_client_frame_controller) |
| 509 return; | 508 return; |
| 510 non_client_frame_controller->SetClientArea(insets, additional_client_areas); | 509 non_client_frame_controller->SetClientArea(insets, additional_client_areas); |
| 511 } | 510 } |
| 512 | 511 |
| 513 void WindowManager::OnWindowInitialized(aura::Window* window) { | |
| 514 // This ensures WmWindowAura won't be called before WmWindowMus. This is | |
| 515 // important as if WmWindowAura::Get() is called first, then WmWindowAura | |
| 516 // would be created, not WmWindowMus. | |
| 517 WmWindowMus::Get(window); | |
| 518 } | |
| 519 | |
| 520 } // namespace mus | 512 } // namespace mus |
| 521 } // namespace ash | 513 } // namespace ash |
| OLD | NEW |