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