| 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 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(AppListPresenterStub); | 66 DISALLOW_COPY_AND_ASSIGN(AppListPresenterStub); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 WindowManager::WindowManager(shell::Connector* connector) | 69 WindowManager::WindowManager(shell::Connector* connector) |
| 70 : connector_(connector) {} | 70 : connector_(connector) {} |
| 71 | 71 |
| 72 WindowManager::~WindowManager() { | 72 WindowManager::~WindowManager() { |
| 73 // NOTE: |window_tree_client_| may already be null. | 73 Shutdown(); |
| 74 delete window_tree_client_; | |
| 75 } | 74 } |
| 76 | 75 |
| 77 void WindowManager::Init(ui::WindowTreeClient* window_tree_client) { | 76 void WindowManager::Init( |
| 77 std::unique_ptr<ui::WindowTreeClient> window_tree_client) { |
| 78 DCHECK(!window_tree_client_); | 78 DCHECK(!window_tree_client_); |
| 79 window_tree_client_ = window_tree_client; | 79 window_tree_client_ = std::move(window_tree_client); |
| 80 | 80 |
| 81 pointer_watcher_event_router_.reset( | 81 pointer_watcher_event_router_.reset( |
| 82 new views::PointerWatcherEventRouter(window_tree_client)); | 82 new views::PointerWatcherEventRouter(window_tree_client_.get())); |
| 83 | 83 |
| 84 shadow_controller_.reset(new ShadowController(window_tree_client)); | 84 shadow_controller_.reset(new ShadowController(window_tree_client_.get())); |
| 85 | 85 |
| 86 // The insets are roughly what is needed by CustomFrameView. The expectation | 86 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 87 // is at some point we'll write our own NonClientFrameView and get the insets | 87 // is at some point we'll write our own NonClientFrameView and get the insets |
| 88 // from it. | 88 // from it. |
| 89 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = | 89 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 90 ui::mojom::FrameDecorationValues::New(); | 90 ui::mojom::FrameDecorationValues::New(); |
| 91 const gfx::Insets client_area_insets = | 91 const gfx::Insets client_area_insets = |
| 92 NonClientFrameController::GetPreferredClientAreaInsets(); | 92 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 93 frame_decoration_values->normal_client_area_insets = client_area_insets; | 93 frame_decoration_values->normal_client_area_insets = client_area_insets; |
| 94 frame_decoration_values->maximized_client_area_insets = client_area_insets; | 94 frame_decoration_values->maximized_client_area_insets = client_area_insets; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 RootWindowController* root_window_controller = | 173 RootWindowController* root_window_controller = |
| 174 root_window_controller_ptr.get(); | 174 root_window_controller_ptr.get(); |
| 175 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 175 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 176 window->AddObserver(this); | 176 window->AddObserver(this); |
| 177 | 177 |
| 178 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 178 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 179 OnRootWindowControllerAdded(root_window_controller)); | 179 OnRootWindowControllerAdded(root_window_controller)); |
| 180 return root_window_controller; | 180 return root_window_controller; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void WindowManager::Shutdown() { |
| 184 if (!window_tree_client_) |
| 185 return; |
| 186 |
| 187 // Observers can rely on WmShell from the callback. So notify the observers |
| 188 // before destroying it. |
| 189 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 190 OnWindowTreeClientDestroyed()); |
| 191 |
| 192 // Destroy the roots of the RootWindowControllers, which triggers removal |
| 193 // in OnWindowDestroyed(). |
| 194 while (!root_window_controllers_.empty()) |
| 195 (*root_window_controllers_.begin())->root()->Destroy(); |
| 196 |
| 197 lookup_.reset(); |
| 198 shell_->Shutdown(); |
| 199 shell_.reset(); |
| 200 shadow_controller_.reset(); |
| 201 |
| 202 pointer_watcher_event_router_.reset(); |
| 203 |
| 204 window_tree_client_.reset(); |
| 205 window_manager_client_ = nullptr; |
| 206 } |
| 207 |
| 183 void WindowManager::OnWindowDestroying(ui::Window* window) { | 208 void WindowManager::OnWindowDestroying(ui::Window* window) { |
| 184 for (auto it = root_window_controllers_.begin(); | 209 for (auto it = root_window_controllers_.begin(); |
| 185 it != root_window_controllers_.end(); ++it) { | 210 it != root_window_controllers_.end(); ++it) { |
| 186 if ((*it)->root() == window) { | 211 if ((*it)->root() == window) { |
| 187 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 212 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 188 OnWillDestroyRootWindowController((*it).get())); | 213 OnWillDestroyRootWindowController((*it).get())); |
| 189 return; | 214 return; |
| 190 } | 215 } |
| 191 } | 216 } |
| 192 NOTREACHED(); | 217 NOTREACHED(); |
| 193 } | 218 } |
| 194 | 219 |
| 195 void WindowManager::OnWindowDestroyed(ui::Window* window) { | 220 void WindowManager::OnWindowDestroyed(ui::Window* window) { |
| 196 window->RemoveObserver(this); | 221 window->RemoveObserver(this); |
| 197 for (auto it = root_window_controllers_.begin(); | 222 for (auto it = root_window_controllers_.begin(); |
| 198 it != root_window_controllers_.end(); ++it) { | 223 it != root_window_controllers_.end(); ++it) { |
| 199 if ((*it)->root() == window) { | 224 if ((*it)->root() == window) { |
| 200 root_window_controllers_.erase(it); | 225 root_window_controllers_.erase(it); |
| 201 return; | 226 return; |
| 202 } | 227 } |
| 203 } | 228 } |
| 204 NOTREACHED(); | 229 NOTREACHED(); |
| 205 } | 230 } |
| 206 | 231 |
| 207 void WindowManager::OnEmbed(ui::Window* root) { | 232 void WindowManager::OnEmbed(ui::Window* root) { |
| 208 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 233 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 209 NOTREACHED(); | 234 NOTREACHED(); |
| 210 } | 235 } |
| 211 | 236 |
| 212 void WindowManager::OnDidDestroyClient(ui::WindowTreeClient* client) { | 237 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { |
| 213 // Destroying the roots should result in removal from | 238 // WindowManager should never see this. |
| 214 // |root_window_controllers_|. | 239 NOTREACHED(); |
| 215 DCHECK(root_window_controllers_.empty()); | 240 } |
| 216 | 241 |
| 217 // Observers can rely on WmShell from the callback. So notify the observers | 242 void WindowManager::OnLostConnection(ui::WindowTreeClient* client) { |
| 218 // before destroying it. | 243 DCHECK_EQ(client, window_tree_client_.get()); |
| 219 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 244 Shutdown(); |
| 220 OnWindowTreeClientDestroyed()); | 245 // TODO(sky): this case should trigger shutting down WindowManagerApplication |
| 221 | 246 // too. |
| 222 lookup_.reset(); | |
| 223 shell_->Shutdown(); | |
| 224 shell_.reset(); | |
| 225 shadow_controller_.reset(); | |
| 226 | |
| 227 pointer_watcher_event_router_.reset(); | |
| 228 | |
| 229 window_tree_client_ = nullptr; | |
| 230 window_manager_client_ = nullptr; | |
| 231 } | 247 } |
| 232 | 248 |
| 233 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, | 249 void WindowManager::OnPointerEventObserved(const ui::PointerEvent& event, |
| 234 ui::Window* target) { | 250 ui::Window* target) { |
| 235 pointer_watcher_event_router_->OnPointerEventObserved(event, target); | 251 pointer_watcher_event_router_->OnPointerEventObserved(event, target); |
| 236 } | 252 } |
| 237 | 253 |
| 238 void WindowManager::SetWindowManagerClient(ui::WindowManagerClient* client) { | 254 void WindowManager::SetWindowManagerClient(ui::WindowManagerClient* client) { |
| 239 window_manager_client_ = client; | 255 window_manager_client_ = client; |
| 240 } | 256 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 const ui::Event& event) { | 324 const ui::Event& event) { |
| 309 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 325 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 310 if (iter == accelerator_handlers_.end()) | 326 if (iter == accelerator_handlers_.end()) |
| 311 return ui::mojom::EventResult::HANDLED; | 327 return ui::mojom::EventResult::HANDLED; |
| 312 | 328 |
| 313 return iter->second->OnAccelerator(id, event); | 329 return iter->second->OnAccelerator(id, event); |
| 314 } | 330 } |
| 315 | 331 |
| 316 } // namespace mus | 332 } // namespace mus |
| 317 } // namespace ash | 333 } // namespace ash |
| OLD | NEW |