| 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/common/wm/container_finder.h" |
| 12 #include "ash/common/wm/window_state.h" |
| 13 #include "ash/display/screen_position_controller.h" |
| 11 #include "ash/mus/accelerators/accelerator_handler.h" | 14 #include "ash/mus/accelerators/accelerator_handler.h" |
| 12 #include "ash/mus/accelerators/accelerator_ids.h" | 15 #include "ash/mus/accelerators/accelerator_ids.h" |
| 13 #include "ash/mus/app_list_presenter_mus.h" | 16 #include "ash/mus/app_list_presenter_mus.h" |
| 14 #include "ash/mus/bridge/wm_lookup_mus.h" | 17 #include "ash/mus/bridge/wm_lookup_mus.h" |
| 15 #include "ash/mus/bridge/wm_root_window_controller_mus.h" | 18 #include "ash/mus/bridge/wm_root_window_controller_mus.h" |
| 16 #include "ash/mus/bridge/wm_shell_mus.h" | 19 #include "ash/mus/bridge/wm_shell_mus.h" |
| 17 #include "ash/mus/bridge/wm_window_mus.h" | 20 #include "ash/mus/bridge/wm_window_mus.h" |
| 18 #include "ash/mus/move_event_handler.h" | 21 #include "ash/mus/move_event_handler.h" |
| 19 #include "ash/mus/non_client_frame_controller.h" | 22 #include "ash/mus/non_client_frame_controller.h" |
| 20 #include "ash/mus/property_util.h" | 23 #include "ash/mus/property_util.h" |
| 21 #include "ash/mus/root_window_controller.h" | 24 #include "ash/mus/root_window_controller.h" |
| 25 #include "ash/mus/screen_mus.h" |
| 22 #include "ash/mus/shadow_controller.h" | 26 #include "ash/mus/shadow_controller.h" |
| 23 #include "ash/mus/shell_delegate_mus.h" | 27 #include "ash/mus/shell_delegate_mus.h" |
| 24 #include "ash/mus/window_manager_observer.h" | 28 #include "ash/mus/window_manager_observer.h" |
| 29 #include "ash/mus/window_properties.h" |
| 25 #include "ash/public/cpp/shell_window_ids.h" | 30 #include "ash/public/cpp/shell_window_ids.h" |
| 31 #include "ash/wm/ash_focus_rules.h" |
| 32 #include "ash/wm/event_client_impl.h" |
| 33 #include "ash/wm/window_properties.h" |
| 26 #include "base/memory/ptr_util.h" | 34 #include "base/memory/ptr_util.h" |
| 27 #include "services/service_manager/public/cpp/connector.h" | 35 #include "services/service_manager/public/cpp/connector.h" |
| 28 #include "services/ui/common/accelerator_util.h" | 36 #include "services/ui/common/accelerator_util.h" |
| 29 #include "services/ui/common/types.h" | 37 #include "services/ui/common/types.h" |
| 30 #include "services/ui/public/cpp/property_type_converters.h" | 38 #include "services/ui/public/cpp/property_type_converters.h" |
| 31 #include "services/ui/public/cpp/window.h" | |
| 32 #include "services/ui/public/cpp/window_property.h" | |
| 33 #include "services/ui/public/cpp/window_tree_client.h" | |
| 34 #include "services/ui/public/interfaces/constants.mojom.h" | 39 #include "services/ui/public/interfaces/constants.mojom.h" |
| 35 #include "services/ui/public/interfaces/mus_constants.mojom.h" | |
| 36 #include "services/ui/public/interfaces/window_manager.mojom.h" | 40 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 41 #include "ui/aura/client/window_parenting_client.h" |
| 42 #include "ui/aura/env.h" |
| 43 #include "ui/aura/mus/property_converter.h" |
| 44 #include "ui/aura/mus/window_tree_client.h" |
| 45 #include "ui/aura/mus/window_tree_host_mus.h" |
| 46 #include "ui/aura/window.h" |
| 47 #include "ui/aura/window_property.h" |
| 37 #include "ui/base/hit_test.h" | 48 #include "ui/base/hit_test.h" |
| 38 #include "ui/display/display_observer.h" | 49 #include "ui/display/display_observer.h" |
| 39 #include "ui/events/mojo/event.mojom.h" | 50 #include "ui/events/mojo/event.mojom.h" |
| 40 #include "ui/views/mus/pointer_watcher_event_router.h" | 51 #include "ui/views/mus/pointer_watcher_event_router2.h" |
| 41 #include "ui/views/mus/screen_mus.h" | 52 #include "ui/views/mus/screen_mus.h" |
| 53 #include "ui/wm/core/capture_controller.h" |
| 54 #include "ui/wm/core/focus_controller.h" |
| 55 #include "ui/wm/core/wm_state.h" |
| 42 | 56 |
| 43 namespace ash { | 57 namespace ash { |
| 44 namespace mus { | 58 namespace mus { |
| 59 namespace { |
| 45 | 60 |
| 61 // TODO: this is temporary until WindowManager create the real Shell (which is |
| 62 // the event target). http://crbug.com/670744. |
| 63 class EventClientImplMus : public EventClientImpl { |
| 64 public: |
| 65 EventClientImplMus() = default; |
| 66 ~EventClientImplMus() override = default; |
| 67 |
| 68 // EventClientImpl: |
| 69 ui::EventTarget* GetToplevelEventTarget() override { return nullptr; } |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(EventClientImplMus); |
| 73 }; |
| 74 |
| 75 } // namespace |
| 76 |
| 77 // TODO: need to register OSExchangeDataProviderMus. http://crbug.com/665077. |
| 46 WindowManager::WindowManager(service_manager::Connector* connector) | 78 WindowManager::WindowManager(service_manager::Connector* connector) |
| 47 : connector_(connector) {} | 79 : connector_(connector), |
| 80 focus_controller_(base::MakeUnique<::wm::FocusController>( |
| 81 new ::ash::wm::AshFocusRules())), |
| 82 wm_state_(base::MakeUnique<::wm::WMState>()), |
| 83 property_converter_(base::MakeUnique<aura::PropertyConverter>()), |
| 84 event_client_(base::MakeUnique<EventClientImplMus>()), |
| 85 screen_position_controller_( |
| 86 base::MakeUnique<ScreenPositionController>()) { |
| 87 property_converter_->RegisterProperty( |
| 88 kShelfItemTypeKey, ui::mojom::WindowManager::kShelfItemType_Property); |
| 89 } |
| 48 | 90 |
| 49 WindowManager::~WindowManager() { | 91 WindowManager::~WindowManager() { |
| 50 Shutdown(); | 92 Shutdown(); |
| 93 aura::Env::GetInstance()->RemoveObserver(this); |
| 51 } | 94 } |
| 52 | 95 |
| 53 void WindowManager::Init( | 96 void WindowManager::Init( |
| 54 std::unique_ptr<ui::WindowTreeClient> window_tree_client, | 97 std::unique_ptr<aura::WindowTreeClient> window_tree_client, |
| 55 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { | 98 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { |
| 99 DCHECK(window_manager_client_); |
| 56 DCHECK(!window_tree_client_); | 100 DCHECK(!window_tree_client_); |
| 57 window_tree_client_ = std::move(window_tree_client); | 101 window_tree_client_ = std::move(window_tree_client); |
| 58 | 102 |
| 103 aura::Env::GetInstance()->AddObserver(this); |
| 104 |
| 59 // |connector_| will be null in some tests. | 105 // |connector_| will be null in some tests. |
| 60 if (connector_) { | 106 if (connector_) { |
| 61 connector_->ConnectToInterface(ui::mojom::kServiceName, | 107 connector_->ConnectToInterface(ui::mojom::kServiceName, |
| 62 &display_controller_); | 108 &display_controller_); |
| 63 } | 109 } |
| 64 | 110 |
| 65 screen_ = base::MakeUnique<display::ScreenBase>(); | 111 screen_ = base::MakeUnique<ScreenMus>(); |
| 66 display::Screen::SetScreenInstance(screen_.get()); | 112 display::Screen::SetScreenInstance(screen_.get()); |
| 67 | 113 |
| 68 pointer_watcher_event_router_.reset( | 114 pointer_watcher_event_router_ = |
| 69 new views::PointerWatcherEventRouter(window_tree_client_.get())); | 115 base::MakeUnique<views::PointerWatcherEventRouter2>( |
| 116 window_tree_client_.get()); |
| 70 | 117 |
| 71 shadow_controller_.reset(new ShadowController(window_tree_client_.get())); | 118 shadow_controller_ = base::MakeUnique<ShadowController>(); |
| 72 | 119 |
| 73 // The insets are roughly what is needed by CustomFrameView. The expectation | |
| 74 // is at some point we'll write our own NonClientFrameView and get the insets | |
| 75 // from it. | |
| 76 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = | 120 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 77 ui::mojom::FrameDecorationValues::New(); | 121 ui::mojom::FrameDecorationValues::New(); |
| 78 const gfx::Insets client_area_insets = | 122 const gfx::Insets client_area_insets = |
| 79 NonClientFrameController::GetPreferredClientAreaInsets(); | 123 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 80 frame_decoration_values->normal_client_area_insets = client_area_insets; | 124 frame_decoration_values->normal_client_area_insets = client_area_insets; |
| 81 frame_decoration_values->maximized_client_area_insets = client_area_insets; | 125 frame_decoration_values->maximized_client_area_insets = client_area_insets; |
| 82 frame_decoration_values->max_title_bar_button_width = | 126 frame_decoration_values->max_title_bar_button_width = |
| 83 NonClientFrameController::GetMaxTitleBarButtonWidth(); | 127 NonClientFrameController::GetMaxTitleBarButtonWidth(); |
| 84 window_manager_client_->SetFrameDecorationValues( | 128 window_manager_client_->SetFrameDecorationValues( |
| 85 std::move(frame_decoration_values)); | 129 std::move(frame_decoration_values)); |
| 86 | 130 |
| 87 shell_.reset(new WmShellMus(base::MakeUnique<ShellDelegateMus>(connector_), | 131 shell_.reset(new WmShellMus(base::MakeUnique<ShellDelegateMus>(connector_), |
| 88 this, pointer_watcher_event_router_.get())); | 132 this, pointer_watcher_event_router_.get())); |
| 89 shell_->Initialize(blocking_pool); | 133 shell_->Initialize(blocking_pool); |
| 90 lookup_.reset(new WmLookupMus); | 134 lookup_.reset(new WmLookupMus); |
| 91 | 135 |
| 92 // TODO: this should be called when logged in. See http://crbug.com/654606. | 136 // TODO: this should be called when logged in. See http://crbug.com/654606. |
| 93 shell_->CreateShelf(); | 137 shell_->CreateShelf(); |
| 94 } | 138 } |
| 95 | 139 |
| 96 void WindowManager::SetScreenLocked(bool is_locked) { | 140 void WindowManager::SetScreenLocked(bool is_locked) { |
| 97 // TODO: screen locked state needs to be persisted for newly added displays. | 141 // TODO: screen locked state needs to be persisted for newly added displays. |
| 98 for (auto& root_window_controller : root_window_controllers_) { | 142 for (auto& root_window_controller : root_window_controllers_) { |
| 99 WmWindowMus* non_lock_screen_containers_container = | 143 WmWindowMus* non_lock_screen_containers_container = |
| 100 root_window_controller->GetWindowByShellWindowId( | 144 root_window_controller->GetWindowByShellWindowId( |
| 101 kShellWindowId_NonLockScreenContainersContainer); | 145 kShellWindowId_NonLockScreenContainersContainer); |
| 102 non_lock_screen_containers_container->mus_window()->SetVisible(!is_locked); | 146 if (is_locked) |
| 147 non_lock_screen_containers_container->aura_window()->Hide(); |
| 148 else |
| 149 non_lock_screen_containers_container->aura_window()->Show(); |
| 103 } | 150 } |
| 104 } | 151 } |
| 105 | 152 |
| 106 ui::Window* WindowManager::NewTopLevelWindow( | 153 aura::Window* WindowManager::NewTopLevelWindow( |
| 154 ui::mojom::WindowType window_type, |
| 107 std::map<std::string, std::vector<uint8_t>>* properties) { | 155 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 108 RootWindowController* root_window_controller = | 156 RootWindowController* root_window_controller = |
| 109 GetRootWindowControllerForNewTopLevelWindow(properties); | 157 GetRootWindowControllerForNewTopLevelWindow(properties); |
| 110 return root_window_controller->NewTopLevelWindow(properties); | 158 aura::Window* window = |
| 159 root_window_controller->NewTopLevelWindow(window_type, properties); |
| 160 if (properties->count( |
| 161 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) { |
| 162 wm::WindowState* window_state = |
| 163 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); |
| 164 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>( |
| 165 (*properties) |
| 166 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property])); |
| 167 // No need to persist this value. |
| 168 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); |
| 169 } |
| 170 return window; |
| 111 } | 171 } |
| 112 | 172 |
| 113 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { | 173 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { |
| 114 std::set<RootWindowController*> result; | 174 std::set<RootWindowController*> result; |
| 115 for (auto& root_window_controller : root_window_controllers_) | 175 for (auto& root_window_controller : root_window_controllers_) |
| 116 result.insert(root_window_controller.get()); | 176 result.insert(root_window_controller.get()); |
| 117 return result; | 177 return result; |
| 118 } | 178 } |
| 119 | 179 |
| 120 bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) { | 180 bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 | 203 |
| 144 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 204 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 145 observers_.RemoveObserver(observer); | 205 observers_.RemoveObserver(observer); |
| 146 } | 206 } |
| 147 | 207 |
| 148 display::mojom::DisplayController* WindowManager::GetDisplayController() { | 208 display::mojom::DisplayController* WindowManager::GetDisplayController() { |
| 149 return display_controller_ ? display_controller_.get() : nullptr; | 209 return display_controller_ ? display_controller_.get() : nullptr; |
| 150 } | 210 } |
| 151 | 211 |
| 152 RootWindowController* WindowManager::CreateRootWindowController( | 212 RootWindowController* WindowManager::CreateRootWindowController( |
| 153 ui::Window* window, | 213 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 154 const display::Display& display) { | 214 const display::Display& display) { |
| 155 // CreateRootWindowController() means a new display is being added, so the | 215 window_tree_host->InitCompositor(); |
| 156 // DisplayList needs to be updated. Calling AddDisplay() results in | 216 // TODO(sky): this is temporary, should use RootWindowController directly. |
| 157 // notifying DisplayObservers. Ash code assumes when this happens there is | 217 aura::client::SetCaptureClient(window_tree_host->window(), |
| 158 // a valid RootWindowController for the new display. Suspend notifying | 218 wm_state_->capture_controller()); |
| 159 // observers, add the Display, create the RootWindowController, and then | 219 aura::client::SetFocusClient(window_tree_host->window(), |
| 160 // notify DisplayObservers. Classic ash does this by making sure | 220 focus_controller_.get()); |
| 161 // WindowTreeHostManager is added as a DisplayObserver early on. | 221 aura::client::SetActivationClient(window_tree_host->window(), |
| 162 std::unique_ptr<display::DisplayListObserverLock> display_lock = | 222 focus_controller_.get()); |
| 163 screen_->display_list().SuspendObserverUpdates(); | 223 aura::client::SetEventClient(window_tree_host->window(), event_client_.get()); |
| 164 const bool is_first_display = screen_->display_list().displays().empty(); | 224 aura::client::SetScreenPositionClient(window_tree_host->window(), |
| 165 // TODO(sky): should be passed whether display is primary. | 225 screen_position_controller_.get()); |
| 166 screen_->display_list().AddDisplay( | |
| 167 display, is_first_display ? display::DisplayList::Type::PRIMARY | |
| 168 : display::DisplayList::Type::NOT_PRIMARY); | |
| 169 | 226 |
| 170 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 227 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 171 new RootWindowController(this, window, display)); | 228 new RootWindowController(this, std::move(window_tree_host), display)); |
| 172 RootWindowController* root_window_controller = | 229 RootWindowController* root_window_controller = |
| 173 root_window_controller_ptr.get(); | 230 root_window_controller_ptr.get(); |
| 174 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 231 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 175 | 232 |
| 176 // TODO: this should be called when logged in. See http://crbug.com/654606. | 233 // TODO: this should be called when logged in. See http://crbug.com/654606. |
| 177 root_window_controller->wm_root_window_controller()->CreateShelf(); | 234 root_window_controller->wm_root_window_controller()->CreateShelf(); |
| 178 | 235 |
| 179 for (auto& observer : observers_) | 236 for (auto& observer : observers_) |
| 180 observer.OnRootWindowControllerAdded(root_window_controller); | 237 observer.OnRootWindowControllerAdded(root_window_controller); |
| 181 | 238 |
| 182 for (auto& observer : *screen_->display_list().observers()) | 239 for (auto& observer : *screen_->display_list().observers()) |
| 183 observer.OnDisplayAdded(root_window_controller->display()); | 240 observer.OnDisplayAdded(root_window_controller->display()); |
| 184 | 241 |
| 185 return root_window_controller; | 242 return root_window_controller; |
| 186 } | 243 } |
| 187 | 244 |
| 188 void WindowManager::DestroyRootWindowController( | 245 void WindowManager::DestroyRootWindowController( |
| 189 RootWindowController* root_window_controller) { | 246 RootWindowController* root_window_controller) { |
| 190 if (root_window_controllers_.size() > 1) { | 247 if (root_window_controllers_.size() > 1) { |
| 191 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); | 248 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); |
| 192 root_window_controller->wm_root_window_controller()->MoveWindowsTo( | 249 root_window_controller->wm_root_window_controller()->MoveWindowsTo( |
| 193 WmWindowMus::Get(GetPrimaryRootWindowController()->root())); | 250 WmWindowMus::Get(GetPrimaryRootWindowController()->root())); |
| 194 } | 251 } |
| 195 | 252 |
| 196 ui::Window* root_window = root_window_controller->root(); | 253 root_window_controller->Shutdown(); |
| 197 auto it = FindRootWindowControllerByWindow(root_window); | |
| 198 DCHECK(it != root_window_controllers_.end()); | |
| 199 | |
| 200 (*it)->Shutdown(); | |
| 201 | 254 |
| 202 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) | 255 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) |
| 203 // this may need to change to mirror that. | 256 // this may need to change to mirror that. |
| 204 root_window_controllers_.erase(it); | 257 for (auto iter = root_window_controllers_.begin(); |
| 258 iter != root_window_controllers_.end(); ++iter) { |
| 259 if (iter->get() == root_window_controller) { |
| 260 root_window_controllers_.erase(iter); |
| 261 break; |
| 262 } |
| 263 } |
| 205 } | 264 } |
| 206 | 265 |
| 207 void WindowManager::Shutdown() { | 266 void WindowManager::Shutdown() { |
| 208 if (!window_tree_client_) | 267 if (!window_tree_client_) |
| 209 return; | 268 return; |
| 210 | 269 |
| 270 // Remove the focus from any window. This will prevent overhead and side |
| 271 // effects (e.g. crashes) from changing focus during shutdown. |
| 272 // See bug crbug.com/134502. |
| 273 static_cast<aura::client::FocusClient*>(focus_controller_.get()) |
| 274 ->FocusWindow(nullptr); |
| 275 |
| 211 // Observers can rely on WmShell from the callback. So notify the observers | 276 // Observers can rely on WmShell from the callback. So notify the observers |
| 212 // before destroying it. | 277 // before destroying it. |
| 213 for (auto& observer : observers_) | 278 for (auto& observer : observers_) |
| 214 observer.OnWindowTreeClientDestroyed(); | 279 observer.OnWindowTreeClientDestroyed(); |
| 215 | 280 |
| 216 // Primary RootWindowController must be destroyed last. | 281 // Primary RootWindowController must be destroyed last. |
| 217 RootWindowController* primary_root_window_controller = | 282 RootWindowController* primary_root_window_controller = |
| 218 GetPrimaryRootWindowController(); | 283 GetPrimaryRootWindowController(); |
| 219 std::set<RootWindowController*> secondary_root_window_controllers; | 284 std::set<RootWindowController*> secondary_root_window_controllers; |
| 220 for (auto& root_window_controller_ptr : root_window_controllers_) { | 285 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 238 | 303 |
| 239 pointer_watcher_event_router_.reset(); | 304 pointer_watcher_event_router_.reset(); |
| 240 | 305 |
| 241 window_tree_client_.reset(); | 306 window_tree_client_.reset(); |
| 242 window_manager_client_ = nullptr; | 307 window_manager_client_ = nullptr; |
| 243 | 308 |
| 244 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); | 309 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); |
| 245 display::Screen::SetScreenInstance(nullptr); | 310 display::Screen::SetScreenInstance(nullptr); |
| 246 } | 311 } |
| 247 | 312 |
| 248 WindowManager::RootWindowControllers::iterator | |
| 249 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { | |
| 250 for (auto it = root_window_controllers_.begin(); | |
| 251 it != root_window_controllers_.end(); ++it) { | |
| 252 if ((*it)->root() == window) | |
| 253 return it; | |
| 254 } | |
| 255 return root_window_controllers_.end(); | |
| 256 } | |
| 257 | |
| 258 RootWindowController* WindowManager::GetPrimaryRootWindowController() { | 313 RootWindowController* WindowManager::GetPrimaryRootWindowController() { |
| 259 return static_cast<WmRootWindowControllerMus*>( | 314 return static_cast<WmRootWindowControllerMus*>( |
| 260 WmShell::Get()->GetPrimaryRootWindowController()) | 315 WmShell::Get()->GetPrimaryRootWindowController()) |
| 261 ->root_window_controller(); | 316 ->root_window_controller(); |
| 262 } | 317 } |
| 263 | 318 |
| 264 RootWindowController* | 319 RootWindowController* |
| 265 WindowManager::GetRootWindowControllerForNewTopLevelWindow( | 320 WindowManager::GetRootWindowControllerForNewTopLevelWindow( |
| 266 std::map<std::string, std::vector<uint8_t>>* properties) { | 321 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 267 // If a specific display was requested, use it. | 322 // If a specific display was requested, use it. |
| 268 const int64_t display_id = GetInitialDisplayId(*properties); | 323 const int64_t display_id = GetInitialDisplayId(*properties); |
| 269 for (auto& root_window_controller_ptr : root_window_controllers_) { | 324 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 270 if (root_window_controller_ptr->display().id() == display_id) | 325 if (root_window_controller_ptr->display().id() == display_id) |
| 271 return root_window_controller_ptr.get(); | 326 return root_window_controller_ptr.get(); |
| 272 } | 327 } |
| 273 | 328 |
| 274 return static_cast<WmRootWindowControllerMus*>( | 329 return static_cast<WmRootWindowControllerMus*>( |
| 275 WmShellMus::Get() | 330 WmShellMus::Get() |
| 276 ->GetRootWindowForNewWindows() | 331 ->GetRootWindowForNewWindows() |
| 277 ->GetRootWindowController()) | 332 ->GetRootWindowController()) |
| 278 ->root_window_controller(); | 333 ->root_window_controller(); |
| 279 } | 334 } |
| 280 | 335 |
| 281 void WindowManager::OnEmbed(ui::Window* root) { | 336 void WindowManager::OnEmbed( |
| 337 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 282 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 338 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 283 NOTREACHED(); | 339 NOTREACHED(); |
| 284 } | 340 } |
| 285 | 341 |
| 286 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { | 342 void WindowManager::OnEmbedRootDestroyed(aura::Window* root) { |
| 287 // WindowManager should never see this. | 343 // WindowManager should never see this. |
| 288 NOTREACHED(); | 344 NOTREACHED(); |
| 289 } | 345 } |
| 290 | 346 |
| 291 void WindowManager::OnLostConnection(ui::WindowTreeClient* client) { | 347 void WindowManager::OnLostConnection(aura::WindowTreeClient* client) { |
| 292 DCHECK_EQ(client, window_tree_client_.get()); | 348 DCHECK_EQ(client, window_tree_client_.get()); |
| 293 Shutdown(); | 349 Shutdown(); |
| 294 // TODO(sky): this case should trigger shutting down WindowManagerApplication | 350 // TODO(sky): this case should trigger shutting down WindowManagerApplication |
| 295 // too. | 351 // too. |
| 296 } | 352 } |
| 297 | 353 |
| 298 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, | 354 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, |
| 299 ui::Window* target) { | 355 aura::Window* target) { |
| 300 pointer_watcher_event_router_->OnPointerEventObserved(event, target); | 356 pointer_watcher_event_router_->OnPointerEventObserved(event, target); |
| 301 } | 357 } |
| 302 | 358 |
| 303 void WindowManager::SetWindowManagerClient(ui::WindowManagerClient* client) { | 359 aura::client::CaptureClient* WindowManager::GetCaptureClient() { |
| 360 return wm_state_->capture_controller(); |
| 361 } |
| 362 |
| 363 aura::PropertyConverter* WindowManager::GetPropertyConverter() { |
| 364 return property_converter_.get(); |
| 365 } |
| 366 |
| 367 void WindowManager::SetWindowManagerClient(aura::WindowManagerClient* client) { |
| 304 window_manager_client_ = client; | 368 window_manager_client_ = client; |
| 305 } | 369 } |
| 306 | 370 |
| 307 bool WindowManager::OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) { | 371 bool WindowManager::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { |
| 308 // TODO(sky): this indirectly sets bounds, which is against what | 372 // TODO(sky): this indirectly sets bounds, which is against what |
| 309 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. | 373 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. |
| 310 WmWindowMus::Get(window)->SetBounds(*bounds); | 374 WmWindowMus::Get(window)->SetBounds(*bounds); |
| 311 *bounds = window->bounds(); | 375 *bounds = window->bounds(); |
| 312 return true; | 376 return true; |
| 313 } | 377 } |
| 314 | 378 |
| 315 bool WindowManager::OnWmSetProperty( | 379 bool WindowManager::OnWmSetProperty( |
| 316 ui::Window* window, | 380 aura::Window* window, |
| 317 const std::string& name, | 381 const std::string& name, |
| 318 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 382 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
| 319 // TODO(sky): constrain this to set of keys we know about, and allowed values. | 383 // TODO(sky): constrain this to set of keys we know about, and allowed values. |
| 384 if (name == ui::mojom::WindowManager::kWindowIgnoredByShelf_Property) { |
| 385 wm::WindowState* window_state = |
| 386 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); |
| 387 window_state->set_ignored_by_shelf( |
| 388 new_data ? mojo::ConvertTo<bool>(**new_data) : false); |
| 389 return false; // Won't attempt to map through property converter. |
| 390 } |
| 320 return name == ui::mojom::WindowManager::kAppIcon_Property || | 391 return name == ui::mojom::WindowManager::kAppIcon_Property || |
| 321 name == ui::mojom::WindowManager::kShowState_Property || | 392 name == ui::mojom::WindowManager::kShowState_Property || |
| 322 name == ui::mojom::WindowManager::kPreferredSize_Property || | 393 name == ui::mojom::WindowManager::kPreferredSize_Property || |
| 323 name == ui::mojom::WindowManager::kResizeBehavior_Property || | 394 name == ui::mojom::WindowManager::kResizeBehavior_Property || |
| 324 name == ui::mojom::WindowManager::kShelfItemType_Property || | 395 name == ui::mojom::WindowManager::kShelfItemType_Property || |
| 325 name == ui::mojom::WindowManager::kWindowIcon_Property || | 396 name == ui::mojom::WindowManager::kWindowIcon_Property || |
| 326 name == ui::mojom::WindowManager::kWindowTitle_Property; | 397 name == ui::mojom::WindowManager::kWindowTitle_Property; |
| 327 } | 398 } |
| 328 | 399 |
| 329 ui::Window* WindowManager::OnWmCreateTopLevelWindow( | 400 aura::Window* WindowManager::OnWmCreateTopLevelWindow( |
| 401 ui::mojom::WindowType window_type, |
| 330 std::map<std::string, std::vector<uint8_t>>* properties) { | 402 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 331 return NewTopLevelWindow(properties); | 403 return NewTopLevelWindow(window_type, properties); |
| 332 } | 404 } |
| 333 | 405 |
| 334 void WindowManager::OnWmClientJankinessChanged( | 406 void WindowManager::OnWmClientJankinessChanged( |
| 335 const std::set<ui::Window*>& client_windows, | 407 const std::set<aura::Window*>& client_windows, |
| 336 bool janky) { | 408 bool janky) { |
| 337 for (auto* window : client_windows) | 409 for (auto* window : client_windows) |
| 338 SetWindowIsJanky(window, janky); | 410 window->SetProperty(kWindowIsJanky, janky); |
| 339 } | 411 } |
| 340 | 412 |
| 341 void WindowManager::OnWmNewDisplay(ui::Window* window, | 413 void WindowManager::OnWmWillCreateDisplay(const display::Display& display) { |
| 342 const display::Display& display) { | 414 // A call to this function means a new display is being added, so the |
| 343 CreateRootWindowController(window, display); | 415 // DisplayList needs to be updated. Calling AddDisplay() results in |
| 416 // notifying DisplayObservers. Ash code assumes when this happens there is |
| 417 // a valid RootWindowController for the new display. Suspend notifying |
| 418 // observers, add the Display. The RootWindowController is created in |
| 419 // OnWmNewDisplay(), which is called immediately after this function. |
| 420 std::unique_ptr<display::DisplayListObserverLock> display_lock = |
| 421 screen_->display_list().SuspendObserverUpdates(); |
| 422 const bool is_first_display = screen_->display_list().displays().empty(); |
| 423 // TODO(sky): should be passed whether display is primary. |
| 424 screen_->display_list().AddDisplay( |
| 425 display, is_first_display ? display::DisplayList::Type::PRIMARY |
| 426 : display::DisplayList::Type::NOT_PRIMARY); |
| 344 } | 427 } |
| 345 | 428 |
| 346 void WindowManager::OnWmDisplayRemoved(ui::Window* window) { | 429 void WindowManager::OnWmNewDisplay( |
| 347 auto iter = FindRootWindowControllerByWindow(window); | 430 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 348 DCHECK(iter != root_window_controllers_.end()); | 431 const display::Display& display) { |
| 349 DestroyRootWindowController(iter->get()); | 432 CreateRootWindowController(std::move(window_tree_host), display); |
| 433 } |
| 434 |
| 435 void WindowManager::OnWmDisplayRemoved( |
| 436 aura::WindowTreeHostMus* window_tree_host) { |
| 437 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 438 if (root_window_controller_ptr->window_tree_host() == window_tree_host) { |
| 439 DestroyRootWindowController(root_window_controller_ptr.get()); |
| 440 break; |
| 441 } |
| 442 } |
| 350 } | 443 } |
| 351 | 444 |
| 352 void WindowManager::OnWmDisplayModified(const display::Display& display) { | 445 void WindowManager::OnWmDisplayModified(const display::Display& display) { |
| 353 for (auto& controller : root_window_controllers_) { | 446 for (auto& controller : root_window_controllers_) { |
| 354 if (controller->display().id() == display.id()) { | 447 if (controller->display().id() == display.id()) { |
| 355 controller->SetDisplay(display); | 448 controller->SetDisplay(display); |
| 356 // The root window will be resized by the window server. | 449 // The root window will be resized by the window server. |
| 357 return; | 450 return; |
| 358 } | 451 } |
| 359 } | 452 } |
| 360 | 453 |
| 361 NOTREACHED(); | 454 NOTREACHED(); |
| 362 } | 455 } |
| 363 | 456 |
| 364 void WindowManager::OnWmPerformMoveLoop( | 457 void WindowManager::OnWmPerformMoveLoop( |
| 365 ui::Window* window, | 458 aura::Window* window, |
| 366 ui::mojom::MoveLoopSource source, | 459 ui::mojom::MoveLoopSource source, |
| 367 const gfx::Point& cursor_location, | 460 const gfx::Point& cursor_location, |
| 368 const base::Callback<void(bool)>& on_done) { | 461 const base::Callback<void(bool)>& on_done) { |
| 369 WmWindowMus* child_window = WmWindowMus::Get(window); | 462 WmWindowMus* child_window = WmWindowMus::Get(window); |
| 370 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); | 463 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); |
| 371 if (!handler) { | 464 if (!handler) { |
| 372 on_done.Run(false); | 465 on_done.Run(false); |
| 373 return; | 466 return; |
| 374 } | 467 } |
| 375 | 468 |
| 376 DCHECK(!handler->IsDragInProgress()); | 469 DCHECK(!handler->IsDragInProgress()); |
| 377 aura::client::WindowMoveSource aura_source = | 470 aura::client::WindowMoveSource aura_source = |
| 378 source == ui::mojom::MoveLoopSource::MOUSE | 471 source == ui::mojom::MoveLoopSource::MOUSE |
| 379 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE | 472 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| 380 : aura::client::WINDOW_MOVE_SOURCE_TOUCH; | 473 : aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
| 381 handler->AttemptToStartDrag(cursor_location, HTCAPTION, aura_source, on_done); | 474 handler->AttemptToStartDrag(cursor_location, HTCAPTION, aura_source, on_done); |
| 382 } | 475 } |
| 383 | 476 |
| 384 void WindowManager::OnWmCancelMoveLoop(ui::Window* window) { | 477 void WindowManager::OnWmCancelMoveLoop(aura::Window* window) { |
| 385 WmWindowMus* child_window = WmWindowMus::Get(window); | 478 WmWindowMus* child_window = WmWindowMus::Get(window); |
| 386 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); | 479 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); |
| 387 if (handler) | 480 if (handler) |
| 388 handler->RevertDrag(); | 481 handler->RevertDrag(); |
| 389 } | 482 } |
| 390 | 483 |
| 391 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, | 484 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, |
| 392 const ui::Event& event) { | 485 const ui::Event& event) { |
| 393 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 486 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 394 if (iter == accelerator_handlers_.end()) | 487 if (iter == accelerator_handlers_.end()) |
| 395 return ui::mojom::EventResult::HANDLED; | 488 return ui::mojom::EventResult::HANDLED; |
| 396 | 489 |
| 397 return iter->second->OnAccelerator(id, event); | 490 return iter->second->OnAccelerator(id, event); |
| 398 } | 491 } |
| 399 | 492 |
| 493 void WindowManager::OnWmSetClientArea( |
| 494 aura::Window* window, |
| 495 const gfx::Insets& insets, |
| 496 const std::vector<gfx::Rect>& additional_client_areas) { |
| 497 NonClientFrameController* non_client_frame_controller = |
| 498 NonClientFrameController::Get(window); |
| 499 if (!non_client_frame_controller) |
| 500 return; |
| 501 non_client_frame_controller->SetClientArea(insets, additional_client_areas); |
| 502 } |
| 503 |
| 504 void WindowManager::OnWindowInitialized(aura::Window* window) { |
| 505 // This ensures WmWindowAura won't be called before WmWindowMus. This is |
| 506 // important as if WmWindowAura::Get() is called first, then WmWindowAura |
| 507 // would be created, not WmWindowMus. |
| 508 WmWindowMus::Get(window); |
| 509 } |
| 510 |
| 400 } // namespace mus | 511 } // namespace mus |
| 401 } // namespace ash | 512 } // namespace ash |
| OLD | NEW |