Chromium Code Reviews| 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. | |
|
James Cook
2016/12/05 19:21:45
Thanks for filing bugs for these TODO items.
| |
| 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) { |
| 56 DCHECK(!window_tree_client_); | 99 DCHECK(!window_tree_client_); |
|
James Cook
2016/12/05 19:21:45
nit: Can you also DCHECK(window_manager_client_)?
sky
2016/12/05 21:39:20
Done.
| |
| 57 window_tree_client_ = std::move(window_tree_client); | 100 window_tree_client_ = std::move(window_tree_client); |
| 58 | 101 |
| 102 aura::Env::GetInstance()->AddObserver(this); | |
| 103 | |
| 59 // |connector_| will be null in some tests. | 104 // |connector_| will be null in some tests. |
| 60 if (connector_) { | 105 if (connector_) { |
| 61 connector_->ConnectToInterface(ui::mojom::kServiceName, | 106 connector_->ConnectToInterface(ui::mojom::kServiceName, |
| 62 &display_controller_); | 107 &display_controller_); |
| 63 } | 108 } |
| 64 | 109 |
| 65 screen_ = base::MakeUnique<display::ScreenBase>(); | 110 screen_ = base::MakeUnique<ScreenMus>(); |
| 66 display::Screen::SetScreenInstance(screen_.get()); | 111 display::Screen::SetScreenInstance(screen_.get()); |
| 67 | 112 |
| 68 pointer_watcher_event_router_.reset( | 113 pointer_watcher_event_router_ = |
| 69 new views::PointerWatcherEventRouter(window_tree_client_.get())); | 114 base::MakeUnique<views::PointerWatcherEventRouter2>( |
| 115 window_tree_client_.get()); | |
| 70 | 116 |
| 71 shadow_controller_.reset(new ShadowController(window_tree_client_.get())); | 117 shadow_controller_ = base::MakeUnique<ShadowController>(); |
| 72 | 118 |
| 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 = | 119 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 77 ui::mojom::FrameDecorationValues::New(); | 120 ui::mojom::FrameDecorationValues::New(); |
| 78 const gfx::Insets client_area_insets = | 121 const gfx::Insets client_area_insets = |
| 79 NonClientFrameController::GetPreferredClientAreaInsets(); | 122 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 80 frame_decoration_values->normal_client_area_insets = client_area_insets; | 123 frame_decoration_values->normal_client_area_insets = client_area_insets; |
| 81 frame_decoration_values->maximized_client_area_insets = client_area_insets; | 124 frame_decoration_values->maximized_client_area_insets = client_area_insets; |
| 82 frame_decoration_values->max_title_bar_button_width = | 125 frame_decoration_values->max_title_bar_button_width = |
| 83 NonClientFrameController::GetMaxTitleBarButtonWidth(); | 126 NonClientFrameController::GetMaxTitleBarButtonWidth(); |
| 84 window_manager_client_->SetFrameDecorationValues( | 127 window_manager_client_->SetFrameDecorationValues( |
| 85 std::move(frame_decoration_values)); | 128 std::move(frame_decoration_values)); |
| 86 | 129 |
| 87 shell_.reset(new WmShellMus(base::MakeUnique<ShellDelegateMus>(connector_), | 130 shell_.reset(new WmShellMus(base::MakeUnique<ShellDelegateMus>(connector_), |
| 88 this, pointer_watcher_event_router_.get())); | 131 this, pointer_watcher_event_router_.get())); |
| 89 shell_->Initialize(blocking_pool); | 132 shell_->Initialize(blocking_pool); |
| 90 lookup_.reset(new WmLookupMus); | 133 lookup_.reset(new WmLookupMus); |
| 91 | 134 |
| 92 // TODO: this should be called when logged in. See http://crbug.com/654606. | 135 // TODO: this should be called when logged in. See http://crbug.com/654606. |
| 93 shell_->CreateShelf(); | 136 shell_->CreateShelf(); |
| 94 } | 137 } |
| 95 | 138 |
| 96 void WindowManager::SetScreenLocked(bool is_locked) { | 139 void WindowManager::SetScreenLocked(bool is_locked) { |
| 97 // TODO: screen locked state needs to be persisted for newly added displays. | 140 // TODO: screen locked state needs to be persisted for newly added displays. |
| 98 for (auto& root_window_controller : root_window_controllers_) { | 141 for (auto& root_window_controller : root_window_controllers_) { |
| 99 WmWindowMus* non_lock_screen_containers_container = | 142 WmWindowMus* non_lock_screen_containers_container = |
| 100 root_window_controller->GetWindowByShellWindowId( | 143 root_window_controller->GetWindowByShellWindowId( |
| 101 kShellWindowId_NonLockScreenContainersContainer); | 144 kShellWindowId_NonLockScreenContainersContainer); |
| 102 non_lock_screen_containers_container->mus_window()->SetVisible(!is_locked); | 145 if (is_locked) |
| 146 non_lock_screen_containers_container->aura_window()->Hide(); | |
| 147 else | |
| 148 non_lock_screen_containers_container->aura_window()->Show(); | |
| 103 } | 149 } |
| 104 } | 150 } |
| 105 | 151 |
| 106 ui::Window* WindowManager::NewTopLevelWindow( | 152 aura::Window* WindowManager::NewTopLevelWindow( |
| 153 ui::mojom::WindowType window_type, | |
| 107 std::map<std::string, std::vector<uint8_t>>* properties) { | 154 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 108 RootWindowController* root_window_controller = | 155 RootWindowController* root_window_controller = |
| 109 GetRootWindowControllerForNewTopLevelWindow(properties); | 156 GetRootWindowControllerForNewTopLevelWindow(properties); |
| 110 return root_window_controller->NewTopLevelWindow(properties); | 157 aura::Window* window = |
| 158 root_window_controller->NewTopLevelWindow(window_type, properties); | |
| 159 if (properties->count( | |
| 160 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) { | |
| 161 wm::WindowState* window_state = | |
| 162 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); | |
| 163 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>( | |
| 164 (*properties) | |
| 165 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property])); | |
| 166 // No need to persist this value. | |
| 167 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); | |
|
James Cook
2016/12/05 19:21:45
I think there should be a central place where we d
sky
2016/12/05 21:39:20
Definitely. In fact Mike asked for the same thing.
James Cook
2016/12/05 22:56:34
Updating window_manager.mojom separately SGTM
| |
| 168 } | |
| 169 return window; | |
| 111 } | 170 } |
| 112 | 171 |
| 113 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { | 172 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { |
| 114 std::set<RootWindowController*> result; | 173 std::set<RootWindowController*> result; |
| 115 for (auto& root_window_controller : root_window_controllers_) | 174 for (auto& root_window_controller : root_window_controllers_) |
| 116 result.insert(root_window_controller.get()); | 175 result.insert(root_window_controller.get()); |
| 117 return result; | 176 return result; |
| 118 } | 177 } |
| 119 | 178 |
| 120 bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) { | 179 bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 143 | 202 |
| 144 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 203 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 145 observers_.RemoveObserver(observer); | 204 observers_.RemoveObserver(observer); |
| 146 } | 205 } |
| 147 | 206 |
| 148 display::mojom::DisplayController* WindowManager::GetDisplayController() { | 207 display::mojom::DisplayController* WindowManager::GetDisplayController() { |
| 149 return display_controller_ ? display_controller_.get() : nullptr; | 208 return display_controller_ ? display_controller_.get() : nullptr; |
| 150 } | 209 } |
| 151 | 210 |
| 152 RootWindowController* WindowManager::CreateRootWindowController( | 211 RootWindowController* WindowManager::CreateRootWindowController( |
| 153 ui::Window* window, | 212 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| 154 const display::Display& display) { | 213 const display::Display& display) { |
| 155 // CreateRootWindowController() means a new display is being added, so the | 214 window_tree_host->InitCompositor(); |
| 156 // DisplayList needs to be updated. Calling AddDisplay() results in | 215 // TODO(sky): this is temporary, should use RootWindowController directly. |
| 157 // notifying DisplayObservers. Ash code assumes when this happens there is | 216 aura::client::SetCaptureClient(window_tree_host->window(), |
| 158 // a valid RootWindowController for the new display. Suspend notifying | 217 wm_state_->capture_controller()); |
| 159 // observers, add the Display, create the RootWindowController, and then | 218 aura::client::SetFocusClient(window_tree_host->window(), |
| 160 // notify DisplayObservers. Classic ash does this by making sure | 219 focus_controller_.get()); |
| 161 // WindowTreeHostManager is added as a DisplayObserver early on. | 220 aura::client::SetActivationClient(window_tree_host->window(), |
| 162 std::unique_ptr<display::DisplayListObserverLock> display_lock = | 221 focus_controller_.get()); |
| 163 screen_->display_list().SuspendObserverUpdates(); | 222 aura::client::SetEventClient(window_tree_host->window(), event_client_.get()); |
| 164 const bool is_first_display = screen_->display_list().displays().empty(); | 223 aura::client::SetScreenPositionClient(window_tree_host->window(), |
| 165 // TODO(sky): should be passed whether display is primary. | 224 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 | 225 |
| 170 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 226 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 171 new RootWindowController(this, window, display)); | 227 new RootWindowController(this, std::move(window_tree_host), display)); |
| 172 RootWindowController* root_window_controller = | 228 RootWindowController* root_window_controller = |
| 173 root_window_controller_ptr.get(); | 229 root_window_controller_ptr.get(); |
| 174 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 230 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 175 | 231 |
| 176 // TODO: this should be called when logged in. See http://crbug.com/654606. | 232 // TODO: this should be called when logged in. See http://crbug.com/654606. |
| 177 root_window_controller->wm_root_window_controller()->CreateShelf(); | 233 root_window_controller->wm_root_window_controller()->CreateShelf(); |
| 178 | 234 |
| 179 for (auto& observer : observers_) | 235 for (auto& observer : observers_) |
| 180 observer.OnRootWindowControllerAdded(root_window_controller); | 236 observer.OnRootWindowControllerAdded(root_window_controller); |
| 181 | 237 |
| 182 for (auto& observer : *screen_->display_list().observers()) | 238 for (auto& observer : *screen_->display_list().observers()) |
| 183 observer.OnDisplayAdded(root_window_controller->display()); | 239 observer.OnDisplayAdded(root_window_controller->display()); |
| 184 | 240 |
| 185 return root_window_controller; | 241 return root_window_controller; |
| 186 } | 242 } |
| 187 | 243 |
| 188 void WindowManager::DestroyRootWindowController( | 244 void WindowManager::DestroyRootWindowController( |
| 189 RootWindowController* root_window_controller) { | 245 RootWindowController* root_window_controller) { |
| 190 if (root_window_controllers_.size() > 1) { | 246 if (root_window_controllers_.size() > 1) { |
| 191 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); | 247 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController()); |
| 192 root_window_controller->wm_root_window_controller()->MoveWindowsTo( | 248 root_window_controller->wm_root_window_controller()->MoveWindowsTo( |
| 193 WmWindowMus::Get(GetPrimaryRootWindowController()->root())); | 249 WmWindowMus::Get(GetPrimaryRootWindowController()->root())); |
| 194 } | 250 } |
| 195 | 251 |
| 196 ui::Window* root_window = root_window_controller->root(); | 252 root_window_controller->Shutdown(); |
| 197 auto it = FindRootWindowControllerByWindow(root_window); | |
| 198 DCHECK(it != root_window_controllers_.end()); | |
| 199 | |
| 200 (*it)->Shutdown(); | |
| 201 | 253 |
| 202 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) | 254 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon()) |
| 203 // this may need to change to mirror that. | 255 // this may need to change to mirror that. |
| 204 root_window_controllers_.erase(it); | 256 for (auto iter = root_window_controllers_.begin(); |
| 257 iter != root_window_controllers_.end(); ++iter) { | |
| 258 if (iter->get() == root_window_controller) { | |
| 259 root_window_controllers_.erase(iter); | |
| 260 break; | |
| 261 } | |
| 262 } | |
| 205 } | 263 } |
| 206 | 264 |
| 207 void WindowManager::Shutdown() { | 265 void WindowManager::Shutdown() { |
| 208 if (!window_tree_client_) | 266 if (!window_tree_client_) |
| 209 return; | 267 return; |
| 210 | 268 |
| 269 // Remove the focus from any window. This will prevent overhead and side | |
| 270 // effects (e.g. crashes) from changing focus during shutdown. | |
| 271 // See bug crbug.com/134502. | |
| 272 static_cast<aura::client::FocusClient*>(focus_controller_.get()) | |
| 273 ->FocusWindow(nullptr); | |
| 274 | |
| 211 // Observers can rely on WmShell from the callback. So notify the observers | 275 // Observers can rely on WmShell from the callback. So notify the observers |
| 212 // before destroying it. | 276 // before destroying it. |
| 213 for (auto& observer : observers_) | 277 for (auto& observer : observers_) |
| 214 observer.OnWindowTreeClientDestroyed(); | 278 observer.OnWindowTreeClientDestroyed(); |
| 215 | 279 |
| 216 // Primary RootWindowController must be destroyed last. | 280 // Primary RootWindowController must be destroyed last. |
| 217 RootWindowController* primary_root_window_controller = | 281 RootWindowController* primary_root_window_controller = |
| 218 GetPrimaryRootWindowController(); | 282 GetPrimaryRootWindowController(); |
| 219 std::set<RootWindowController*> secondary_root_window_controllers; | 283 std::set<RootWindowController*> secondary_root_window_controllers; |
| 220 for (auto& root_window_controller_ptr : root_window_controllers_) { | 284 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 238 | 302 |
| 239 pointer_watcher_event_router_.reset(); | 303 pointer_watcher_event_router_.reset(); |
| 240 | 304 |
| 241 window_tree_client_.reset(); | 305 window_tree_client_.reset(); |
| 242 window_manager_client_ = nullptr; | 306 window_manager_client_ = nullptr; |
| 243 | 307 |
| 244 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); | 308 DCHECK_EQ(screen_.get(), display::Screen::GetScreen()); |
| 245 display::Screen::SetScreenInstance(nullptr); | 309 display::Screen::SetScreenInstance(nullptr); |
| 246 } | 310 } |
| 247 | 311 |
| 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() { | 312 RootWindowController* WindowManager::GetPrimaryRootWindowController() { |
| 259 return static_cast<WmRootWindowControllerMus*>( | 313 return static_cast<WmRootWindowControllerMus*>( |
| 260 WmShell::Get()->GetPrimaryRootWindowController()) | 314 WmShell::Get()->GetPrimaryRootWindowController()) |
| 261 ->root_window_controller(); | 315 ->root_window_controller(); |
| 262 } | 316 } |
| 263 | 317 |
| 264 RootWindowController* | 318 RootWindowController* |
| 265 WindowManager::GetRootWindowControllerForNewTopLevelWindow( | 319 WindowManager::GetRootWindowControllerForNewTopLevelWindow( |
| 266 std::map<std::string, std::vector<uint8_t>>* properties) { | 320 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 267 // If a specific display was requested, use it. | 321 // If a specific display was requested, use it. |
| 268 const int64_t display_id = GetInitialDisplayId(*properties); | 322 const int64_t display_id = GetInitialDisplayId(*properties); |
| 269 for (auto& root_window_controller_ptr : root_window_controllers_) { | 323 for (auto& root_window_controller_ptr : root_window_controllers_) { |
| 270 if (root_window_controller_ptr->display().id() == display_id) | 324 if (root_window_controller_ptr->display().id() == display_id) |
| 271 return root_window_controller_ptr.get(); | 325 return root_window_controller_ptr.get(); |
| 272 } | 326 } |
| 273 | 327 |
| 274 return static_cast<WmRootWindowControllerMus*>( | 328 return static_cast<WmRootWindowControllerMus*>( |
| 275 WmShellMus::Get() | 329 WmShellMus::Get() |
| 276 ->GetRootWindowForNewWindows() | 330 ->GetRootWindowForNewWindows() |
| 277 ->GetRootWindowController()) | 331 ->GetRootWindowController()) |
| 278 ->root_window_controller(); | 332 ->root_window_controller(); |
| 279 } | 333 } |
| 280 | 334 |
| 281 void WindowManager::OnEmbed(ui::Window* root) { | 335 void WindowManager::OnEmbed( |
| 336 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | |
| 282 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 337 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 283 NOTREACHED(); | 338 NOTREACHED(); |
| 284 } | 339 } |
| 285 | 340 |
| 286 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { | 341 void WindowManager::OnEmbedRootDestroyed(aura::Window* root) { |
| 287 // WindowManager should never see this. | 342 // WindowManager should never see this. |
| 288 NOTREACHED(); | 343 NOTREACHED(); |
| 289 } | 344 } |
| 290 | 345 |
| 291 void WindowManager::OnLostConnection(ui::WindowTreeClient* client) { | 346 void WindowManager::OnLostConnection(aura::WindowTreeClient* client) { |
| 292 DCHECK_EQ(client, window_tree_client_.get()); | 347 DCHECK_EQ(client, window_tree_client_.get()); |
| 293 Shutdown(); | 348 Shutdown(); |
| 294 // TODO(sky): this case should trigger shutting down WindowManagerApplication | 349 // TODO(sky): this case should trigger shutting down WindowManagerApplication |
| 295 // too. | 350 // too. |
| 296 } | 351 } |
| 297 | 352 |
| 298 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, | 353 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, |
| 299 ui::Window* target) { | 354 aura::Window* target) { |
| 300 pointer_watcher_event_router_->OnPointerEventObserved(event, target); | 355 pointer_watcher_event_router_->OnPointerEventObserved(event, target); |
| 301 } | 356 } |
| 302 | 357 |
| 303 void WindowManager::SetWindowManagerClient(ui::WindowManagerClient* client) { | 358 aura::client::CaptureClient* WindowManager::GetCaptureClient() { |
| 359 return wm_state_->capture_controller(); | |
| 360 } | |
| 361 | |
| 362 aura::PropertyConverter* WindowManager::GetPropertyConverter() { | |
| 363 return property_converter_.get(); | |
| 364 } | |
| 365 | |
| 366 void WindowManager::SetWindowManagerClient(aura::WindowManagerClient* client) { | |
| 304 window_manager_client_ = client; | 367 window_manager_client_ = client; |
| 305 } | 368 } |
| 306 | 369 |
| 307 bool WindowManager::OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) { | 370 bool WindowManager::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { |
| 308 // TODO(sky): this indirectly sets bounds, which is against what | 371 // TODO(sky): this indirectly sets bounds, which is against what |
| 309 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. | 372 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. |
| 310 WmWindowMus::Get(window)->SetBounds(*bounds); | 373 WmWindowMus::Get(window)->SetBounds(*bounds); |
| 311 *bounds = window->bounds(); | 374 *bounds = window->bounds(); |
| 312 return true; | 375 return true; |
| 313 } | 376 } |
| 314 | 377 |
| 315 bool WindowManager::OnWmSetProperty( | 378 bool WindowManager::OnWmSetProperty( |
| 316 ui::Window* window, | 379 aura::Window* window, |
| 317 const std::string& name, | 380 const std::string& name, |
| 318 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 381 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
| 319 // 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) { | |
| 384 wm::WindowState* window_state = | |
| 385 static_cast<WmWindow*>(WmWindowMus::Get(window))->GetWindowState(); | |
| 386 window_state->set_ignored_by_shelf( | |
| 387 new_data ? mojo::ConvertTo<bool>(**new_data) : false); | |
| 388 return false; // Won't attempt to map through property converter. | |
| 389 } | |
| 320 return name == ui::mojom::WindowManager::kAppIcon_Property || | 390 return name == ui::mojom::WindowManager::kAppIcon_Property || |
| 321 name == ui::mojom::WindowManager::kShowState_Property || | 391 name == ui::mojom::WindowManager::kShowState_Property || |
| 322 name == ui::mojom::WindowManager::kPreferredSize_Property || | 392 name == ui::mojom::WindowManager::kPreferredSize_Property || |
| 323 name == ui::mojom::WindowManager::kResizeBehavior_Property || | 393 name == ui::mojom::WindowManager::kResizeBehavior_Property || |
| 324 name == ui::mojom::WindowManager::kShelfItemType_Property || | 394 name == ui::mojom::WindowManager::kShelfItemType_Property || |
| 325 name == ui::mojom::WindowManager::kWindowIcon_Property || | 395 name == ui::mojom::WindowManager::kWindowIcon_Property || |
| 326 name == ui::mojom::WindowManager::kWindowTitle_Property; | 396 name == ui::mojom::WindowManager::kWindowTitle_Property; |
| 327 } | 397 } |
| 328 | 398 |
| 329 ui::Window* WindowManager::OnWmCreateTopLevelWindow( | 399 aura::Window* WindowManager::OnWmCreateTopLevelWindow( |
| 400 ui::mojom::WindowType window_type, | |
| 330 std::map<std::string, std::vector<uint8_t>>* properties) { | 401 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 331 return NewTopLevelWindow(properties); | 402 return NewTopLevelWindow(window_type, properties); |
| 332 } | 403 } |
| 333 | 404 |
| 334 void WindowManager::OnWmClientJankinessChanged( | 405 void WindowManager::OnWmClientJankinessChanged( |
| 335 const std::set<ui::Window*>& client_windows, | 406 const std::set<aura::Window*>& client_windows, |
| 336 bool janky) { | 407 bool janky) { |
| 337 for (auto* window : client_windows) | 408 for (auto* window : client_windows) |
| 338 SetWindowIsJanky(window, janky); | 409 window->SetProperty(kWindowIsJanky, janky); |
| 339 } | 410 } |
| 340 | 411 |
| 341 void WindowManager::OnWmNewDisplay(ui::Window* window, | 412 void WindowManager::OnWmWillCreateDisplay(const display::Display& display) { |
| 342 const display::Display& display) { | 413 // CreateRootWindowController() means a new display is being added, so the |
|
James Cook
2016/12/05 19:21:45
nit: CreateRootWindowController -> "A call to this
sky
2016/12/05 21:39:20
Done.
| |
| 343 CreateRootWindowController(window, display); | 414 // DisplayList needs to be updated. Calling AddDisplay() results in |
| 415 // notifying DisplayObservers. Ash code assumes when this happens there is | |
| 416 // a valid RootWindowController for the new display. Suspend notifying | |
| 417 // observers, add the Display, create the RootWindowController, and then | |
| 418 // notify DisplayObservers. Classic ash does this by making sure | |
| 419 // WindowTreeHostManager is added as a DisplayObserver early on. | |
| 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. | |
|
James Cook
2016/12/05 19:21:45
because WmWindowMus::Get() has side effects that h
sky
2016/12/05 21:39:20
Done.
| |
| 506 WmWindowMus::Get(window); | |
| 507 } | |
| 508 | |
| 400 } // namespace mus | 509 } // namespace mus |
| 401 } // namespace ash | 510 } // namespace ash |
| OLD | NEW |