| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 WindowManager::~WindowManager() { | 72 WindowManager::~WindowManager() { |
| 73 Shutdown(); | 73 Shutdown(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void WindowManager::Init( | 76 void WindowManager::Init( |
| 77 std::unique_ptr<ui::WindowTreeClient> window_tree_client, | 77 std::unique_ptr<ui::WindowTreeClient> window_tree_client, |
| 78 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { | 78 const scoped_refptr<base::SequencedWorkerPool>& blocking_pool) { |
| 79 DCHECK(!window_tree_client_); | 79 DCHECK(!window_tree_client_); |
| 80 window_tree_client_ = std::move(window_tree_client); | 80 window_tree_client_ = std::move(window_tree_client); |
| 81 | 81 |
| 82 screen_ = base::MakeUnique<display::ScreenBase>(); |
| 83 |
| 82 pointer_watcher_event_router_.reset( | 84 pointer_watcher_event_router_.reset( |
| 83 new views::PointerWatcherEventRouter(window_tree_client_.get())); | 85 new views::PointerWatcherEventRouter(window_tree_client_.get())); |
| 84 | 86 |
| 85 shadow_controller_.reset(new ShadowController(window_tree_client_.get())); | 87 shadow_controller_.reset(new ShadowController(window_tree_client_.get())); |
| 86 | 88 |
| 87 // The insets are roughly what is needed by CustomFrameView. The expectation | 89 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 88 // is at some point we'll write our own NonClientFrameView and get the insets | 90 // is at some point we'll write our own NonClientFrameView and get the insets |
| 89 // from it. | 91 // from it. |
| 90 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = | 92 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 91 ui::mojom::FrameDecorationValues::New(); | 93 ui::mojom::FrameDecorationValues::New(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 observers_.AddObserver(observer); | 157 observers_.AddObserver(observer); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 160 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 159 observers_.RemoveObserver(observer); | 161 observers_.RemoveObserver(observer); |
| 160 } | 162 } |
| 161 | 163 |
| 162 RootWindowController* WindowManager::CreateRootWindowController( | 164 RootWindowController* WindowManager::CreateRootWindowController( |
| 163 ui::Window* window, | 165 ui::Window* window, |
| 164 const display::Display& display) { | 166 const display::Display& display) { |
| 165 // TODO(sky): There are timing issues with using ScreenMus. | 167 // TODO(sky): should be passed whether display is primary. |
| 166 if (!screen_) { | 168 |
| 167 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); | 169 // There needs to be at least one display before creating |
| 168 screen->Init(connector_); | 170 // RootWindowController, otherwise initializing the compositor fails. |
| 169 screen_ = std::move(screen); | 171 const bool was_displays_empty = screen_->display_list()->displays().empty(); |
| 172 if (was_displays_empty) { |
| 173 screen_->display_list()->AddDisplay(display, |
| 174 display::DisplayList::Type::PRIMARY); |
| 170 } | 175 } |
| 171 | 176 |
| 172 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 177 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 173 new RootWindowController(this, window, display)); | 178 new RootWindowController(this, window, display)); |
| 174 RootWindowController* root_window_controller = | 179 RootWindowController* root_window_controller = |
| 175 root_window_controller_ptr.get(); | 180 root_window_controller_ptr.get(); |
| 176 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 181 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 177 window->AddObserver(this); | 182 window->AddObserver(this); |
| 178 | 183 |
| 179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 184 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 180 OnRootWindowControllerAdded(root_window_controller)); | 185 OnRootWindowControllerAdded(root_window_controller)); |
| 186 |
| 187 if (!was_displays_empty) { |
| 188 // If this isn't the initial display then add the display to Screen after |
| 189 // creating the RootWindowController. We need to do this after creating the |
| 190 // RootWindowController as adding the display triggers OnDisplayAdded(), |
| 191 // which triggers some overrides asking for the RootWindowController for the |
| 192 // new display. |
| 193 screen_->display_list()->AddDisplay( |
| 194 display, display::DisplayList::Type::NOT_PRIMARY); |
| 195 } |
| 181 return root_window_controller; | 196 return root_window_controller; |
| 182 } | 197 } |
| 183 | 198 |
| 199 void WindowManager::DestroyRootWindowController( |
| 200 RootWindowController* root_window_controller) { |
| 201 // TODO(sky): WindowManager shouldn't need to observe the windows. Instead |
| 202 // WindowManager should have a specific API that is called when a display is |
| 203 // removed. |
| 204 ui::Window* root_window = root_window_controller->root(); |
| 205 auto it = FindRootWindowControllerByWindow(root_window); |
| 206 DCHECK(it != root_window_controllers_.end()); |
| 207 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 208 OnWillDestroyRootWindowController((*it).get())); |
| 209 root_window_controllers_.erase(it); |
| 210 // Remove the observer so we don't see the OnWindowDestroying/Destroyed as we |
| 211 // already handled it here. |
| 212 root_window->RemoveObserver(this); |
| 213 root_window->Destroy(); |
| 214 } |
| 215 |
| 184 void WindowManager::Shutdown() { | 216 void WindowManager::Shutdown() { |
| 185 if (!window_tree_client_) | 217 if (!window_tree_client_) |
| 186 return; | 218 return; |
| 187 | 219 |
| 188 // Observers can rely on WmShell from the callback. So notify the observers | 220 // Observers can rely on WmShell from the callback. So notify the observers |
| 189 // before destroying it. | 221 // before destroying it. |
| 190 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 222 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 191 OnWindowTreeClientDestroyed()); | 223 OnWindowTreeClientDestroyed()); |
| 192 | 224 |
| 193 // Destroy the roots of the RootWindowControllers, which triggers removal | 225 // Destroy the roots of the RootWindowControllers, which triggers removal |
| 194 // in OnWindowDestroyed(). | 226 // in OnWindowDestroyed(). |
| 195 while (!root_window_controllers_.empty()) | 227 while (!root_window_controllers_.empty()) |
| 196 (*root_window_controllers_.begin())->root()->Destroy(); | 228 (*root_window_controllers_.begin())->root()->Destroy(); |
| 197 | 229 |
| 198 lookup_.reset(); | 230 lookup_.reset(); |
| 199 shell_->Shutdown(); | 231 shell_->Shutdown(); |
| 200 shell_.reset(); | 232 shell_.reset(); |
| 201 shadow_controller_.reset(); | 233 shadow_controller_.reset(); |
| 202 | 234 |
| 203 pointer_watcher_event_router_.reset(); | 235 pointer_watcher_event_router_.reset(); |
| 204 | 236 |
| 205 window_tree_client_.reset(); | 237 window_tree_client_.reset(); |
| 206 window_manager_client_ = nullptr; | 238 window_manager_client_ = nullptr; |
| 207 } | 239 } |
| 208 | 240 |
| 209 void WindowManager::OnWindowDestroying(ui::Window* window) { | 241 WindowManager::RootWindowControllers::iterator |
| 242 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { |
| 210 for (auto it = root_window_controllers_.begin(); | 243 for (auto it = root_window_controllers_.begin(); |
| 211 it != root_window_controllers_.end(); ++it) { | 244 it != root_window_controllers_.end(); ++it) { |
| 212 if ((*it)->root() == window) { | 245 if ((*it)->root() == window) |
| 213 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 246 return it; |
| 214 OnWillDestroyRootWindowController((*it).get())); | |
| 215 return; | |
| 216 } | |
| 217 } | 247 } |
| 218 NOTREACHED(); | 248 return root_window_controllers_.end(); |
| 249 } |
| 250 |
| 251 void WindowManager::OnWindowDestroying(ui::Window* window) { |
| 252 auto it = FindRootWindowControllerByWindow(window); |
| 253 DCHECK(it != root_window_controllers_.end()); |
| 254 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 255 OnWillDestroyRootWindowController((*it).get())); |
| 219 } | 256 } |
| 220 | 257 |
| 221 void WindowManager::OnWindowDestroyed(ui::Window* window) { | 258 void WindowManager::OnWindowDestroyed(ui::Window* window) { |
| 259 auto it = FindRootWindowControllerByWindow(window); |
| 260 DCHECK(it != root_window_controllers_.end()); |
| 222 window->RemoveObserver(this); | 261 window->RemoveObserver(this); |
| 223 for (auto it = root_window_controllers_.begin(); | 262 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 } | 263 } |
| 232 | 264 |
| 233 void WindowManager::OnEmbed(ui::Window* root) { | 265 void WindowManager::OnEmbed(ui::Window* root) { |
| 234 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 266 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 235 NOTREACHED(); | 267 NOTREACHED(); |
| 236 } | 268 } |
| 237 | 269 |
| 238 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { | 270 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { |
| 239 // WindowManager should never see this. | 271 // WindowManager should never see this. |
| 240 NOTREACHED(); | 272 NOTREACHED(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 const ui::Event& event) { | 356 const ui::Event& event) { |
| 325 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 357 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 326 if (iter == accelerator_handlers_.end()) | 358 if (iter == accelerator_handlers_.end()) |
| 327 return ui::mojom::EventResult::HANDLED; | 359 return ui::mojom::EventResult::HANDLED; |
| 328 | 360 |
| 329 return iter->second->OnAccelerator(id, event); | 361 return iter->second->OnAccelerator(id, event); |
| 330 } | 362 } |
| 331 | 363 |
| 332 } // namespace mus | 364 } // namespace mus |
| 333 } // namespace ash | 365 } // namespace ash |
| OLD | NEW |