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 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 RootWindowController* root_window_controller = | 174 RootWindowController* root_window_controller = |
| 175 root_window_controller_ptr.get(); | 175 root_window_controller_ptr.get(); |
| 176 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 176 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 177 window->AddObserver(this); | 177 window->AddObserver(this); |
| 178 | 178 |
| 179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 180 OnRootWindowControllerAdded(root_window_controller)); | 180 OnRootWindowControllerAdded(root_window_controller)); |
| 181 return root_window_controller; | 181 return root_window_controller; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void WindowManager::RemoveDisplay(ui::Window* window) { | |
|
msw
2016/09/12 22:01:51
q: just window->Destroy and let OnWindowDestroy[in
sky
2016/09/12 23:11:27
Indeed. I want to move away from the observer and
| |
| 185 // TODO(sky): WindowManager shouldn't need to observer the windows. Instead | |
|
msw
2016/09/12 22:01:51
nit: "observer"
sky
2016/09/12 23:11:27
Done.
| |
| 186 // WindowManager should have a specific API that is called when a display is | |
| 187 // removed. | |
| 188 auto it = FindRootWindowControllerByWindow(window); | |
| 189 DCHECK(it != root_window_controllers_.end()); | |
| 190 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
| 191 OnWillDestroyRootWindowController((*it).get())); | |
| 192 root_window_controllers_.erase(it); | |
| 193 // Remove the observer so we don't see the OnWindowDestroying/Destroyed as we | |
| 194 // already handled it here. | |
| 195 window->RemoveObserver(this); | |
| 196 window->Destroy(); | |
| 197 } | |
| 198 | |
| 184 void WindowManager::Shutdown() { | 199 void WindowManager::Shutdown() { |
| 185 if (!window_tree_client_) | 200 if (!window_tree_client_) |
| 186 return; | 201 return; |
| 187 | 202 |
| 188 // Observers can rely on WmShell from the callback. So notify the observers | 203 // Observers can rely on WmShell from the callback. So notify the observers |
| 189 // before destroying it. | 204 // before destroying it. |
| 190 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 205 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 191 OnWindowTreeClientDestroyed()); | 206 OnWindowTreeClientDestroyed()); |
| 192 | 207 |
| 193 // Destroy the roots of the RootWindowControllers, which triggers removal | 208 // Destroy the roots of the RootWindowControllers, which triggers removal |
| 194 // in OnWindowDestroyed(). | 209 // in OnWindowDestroyed(). |
| 195 while (!root_window_controllers_.empty()) | 210 while (!root_window_controllers_.empty()) |
| 196 (*root_window_controllers_.begin())->root()->Destroy(); | 211 (*root_window_controllers_.begin())->root()->Destroy(); |
| 197 | 212 |
| 198 lookup_.reset(); | 213 lookup_.reset(); |
| 199 shell_->Shutdown(); | 214 shell_->Shutdown(); |
| 200 shell_.reset(); | 215 shell_.reset(); |
| 201 shadow_controller_.reset(); | 216 shadow_controller_.reset(); |
| 202 | 217 |
| 203 pointer_watcher_event_router_.reset(); | 218 pointer_watcher_event_router_.reset(); |
| 204 | 219 |
| 205 window_tree_client_.reset(); | 220 window_tree_client_.reset(); |
| 206 window_manager_client_ = nullptr; | 221 window_manager_client_ = nullptr; |
| 207 } | 222 } |
| 208 | 223 |
| 209 void WindowManager::OnWindowDestroying(ui::Window* window) { | 224 WindowManager::RootWindowControllers::iterator |
| 225 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { | |
| 210 for (auto it = root_window_controllers_.begin(); | 226 for (auto it = root_window_controllers_.begin(); |
|
msw
2016/09/12 22:01:51
optional nit: for (auto it : root_window_controlle
sky
2016/09/12 23:11:27
That'll give me a std::unique_ptr<RootWindowContro
| |
| 211 it != root_window_controllers_.end(); ++it) { | 227 it != root_window_controllers_.end(); ++it) { |
| 212 if ((*it)->root() == window) { | 228 if ((*it)->root() == window) |
| 213 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 229 return it; |
| 214 OnWillDestroyRootWindowController((*it).get())); | |
| 215 return; | |
| 216 } | |
| 217 } | 230 } |
| 218 NOTREACHED(); | 231 return root_window_controllers_.end(); |
| 232 } | |
| 233 | |
| 234 void WindowManager::OnWindowDestroying(ui::Window* window) { | |
| 235 auto it = FindRootWindowControllerByWindow(window); | |
| 236 DCHECK(it != root_window_controllers_.end()); | |
| 237 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
| 238 OnWillDestroyRootWindowController((*it).get())); | |
| 219 } | 239 } |
| 220 | 240 |
| 221 void WindowManager::OnWindowDestroyed(ui::Window* window) { | 241 void WindowManager::OnWindowDestroyed(ui::Window* window) { |
| 242 auto it = FindRootWindowControllerByWindow(window); | |
| 243 DCHECK(it != root_window_controllers_.end()); | |
| 222 window->RemoveObserver(this); | 244 window->RemoveObserver(this); |
| 223 for (auto it = root_window_controllers_.begin(); | 245 root_window_controllers_.erase(it); |
| 224 it != root_window_controllers_.end(); ++it) { | |
| 225 if ((*it)->root() == window) { | |
| 226 root_window_controllers_.erase(it); | |
| 227 return; | |
| 228 } | |
| 229 } | |
| 230 NOTREACHED(); | |
| 231 } | 246 } |
| 232 | 247 |
| 233 void WindowManager::OnEmbed(ui::Window* root) { | 248 void WindowManager::OnEmbed(ui::Window* root) { |
| 234 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 249 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 235 NOTREACHED(); | 250 NOTREACHED(); |
| 236 } | 251 } |
| 237 | 252 |
| 238 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { | 253 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { |
| 239 // WindowManager should never see this. | 254 // WindowManager should never see this. |
| 240 NOTREACHED(); | 255 NOTREACHED(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 const ui::Event& event) { | 339 const ui::Event& event) { |
| 325 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 340 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 326 if (iter == accelerator_handlers_.end()) | 341 if (iter == accelerator_handlers_.end()) |
| 327 return ui::mojom::EventResult::HANDLED; | 342 return ui::mojom::EventResult::HANDLED; |
| 328 | 343 |
| 329 return iter->second->OnAccelerator(id, event); | 344 return iter->second->OnAccelerator(id, event); |
| 330 } | 345 } |
| 331 | 346 |
| 332 } // namespace mus | 347 } // namespace mus |
| 333 } // namespace ash | 348 } // namespace ash |
| OLD | NEW |