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 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) { | |
|
msw
2016/09/12 23:19:48
nit: unconditionally add the display above?
sky
2016/09/13 00:10:26
Sadly it has to be like this, and I suspect even t
| |
| 188 screen_->display_list()->AddDisplay( | |
| 189 display, display::DisplayList::Type::NOT_PRIMARY); | |
| 190 } | |
| 181 return root_window_controller; | 191 return root_window_controller; |
| 182 } | 192 } |
| 183 | 193 |
| 194 void WindowManager::DestroyRootWindowController( | |
| 195 RootWindowController* root_window_controller) { | |
| 196 // TODO(sky): WindowManager shouldn't need to observe the windows. Instead | |
| 197 // WindowManager should have a specific API that is called when a display is | |
| 198 // removed. | |
| 199 ui::Window* root_window = root_window_controller->root(); | |
| 200 auto it = FindRootWindowControllerByWindow(root_window); | |
| 201 DCHECK(it != root_window_controllers_.end()); | |
| 202 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
| 203 OnWillDestroyRootWindowController((*it).get())); | |
| 204 root_window_controllers_.erase(it); | |
| 205 // Remove the observer so we don't see the OnWindowDestroying/Destroyed as we | |
| 206 // already handled it here. | |
| 207 root_window->RemoveObserver(this); | |
| 208 root_window->Destroy(); | |
| 209 } | |
| 210 | |
| 184 void WindowManager::Shutdown() { | 211 void WindowManager::Shutdown() { |
| 185 if (!window_tree_client_) | 212 if (!window_tree_client_) |
| 186 return; | 213 return; |
| 187 | 214 |
| 188 // Observers can rely on WmShell from the callback. So notify the observers | 215 // Observers can rely on WmShell from the callback. So notify the observers |
| 189 // before destroying it. | 216 // before destroying it. |
| 190 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 217 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 191 OnWindowTreeClientDestroyed()); | 218 OnWindowTreeClientDestroyed()); |
| 192 | 219 |
| 193 // Destroy the roots of the RootWindowControllers, which triggers removal | 220 // Destroy the roots of the RootWindowControllers, which triggers removal |
| 194 // in OnWindowDestroyed(). | 221 // in OnWindowDestroyed(). |
| 195 while (!root_window_controllers_.empty()) | 222 while (!root_window_controllers_.empty()) |
| 196 (*root_window_controllers_.begin())->root()->Destroy(); | 223 (*root_window_controllers_.begin())->root()->Destroy(); |
| 197 | 224 |
| 198 lookup_.reset(); | 225 lookup_.reset(); |
| 199 shell_->Shutdown(); | 226 shell_->Shutdown(); |
| 200 shell_.reset(); | 227 shell_.reset(); |
| 201 shadow_controller_.reset(); | 228 shadow_controller_.reset(); |
| 202 | 229 |
| 203 pointer_watcher_event_router_.reset(); | 230 pointer_watcher_event_router_.reset(); |
| 204 | 231 |
| 205 window_tree_client_.reset(); | 232 window_tree_client_.reset(); |
| 206 window_manager_client_ = nullptr; | 233 window_manager_client_ = nullptr; |
| 207 } | 234 } |
| 208 | 235 |
| 209 void WindowManager::OnWindowDestroying(ui::Window* window) { | 236 WindowManager::RootWindowControllers::iterator |
| 237 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { | |
| 210 for (auto it = root_window_controllers_.begin(); | 238 for (auto it = root_window_controllers_.begin(); |
| 211 it != root_window_controllers_.end(); ++it) { | 239 it != root_window_controllers_.end(); ++it) { |
| 212 if ((*it)->root() == window) { | 240 if ((*it)->root() == window) |
| 213 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 241 return it; |
| 214 OnWillDestroyRootWindowController((*it).get())); | |
| 215 return; | |
| 216 } | |
| 217 } | 242 } |
| 218 NOTREACHED(); | 243 return root_window_controllers_.end(); |
| 244 } | |
| 245 | |
| 246 void WindowManager::OnWindowDestroying(ui::Window* window) { | |
| 247 auto it = FindRootWindowControllerByWindow(window); | |
| 248 DCHECK(it != root_window_controllers_.end()); | |
| 249 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
| 250 OnWillDestroyRootWindowController((*it).get())); | |
| 219 } | 251 } |
| 220 | 252 |
| 221 void WindowManager::OnWindowDestroyed(ui::Window* window) { | 253 void WindowManager::OnWindowDestroyed(ui::Window* window) { |
| 254 auto it = FindRootWindowControllerByWindow(window); | |
| 255 DCHECK(it != root_window_controllers_.end()); | |
| 222 window->RemoveObserver(this); | 256 window->RemoveObserver(this); |
| 223 for (auto it = root_window_controllers_.begin(); | 257 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 } | 258 } |
| 232 | 259 |
| 233 void WindowManager::OnEmbed(ui::Window* root) { | 260 void WindowManager::OnEmbed(ui::Window* root) { |
| 234 // WindowManager should never see this, instead OnWmNewDisplay() is called. | 261 // WindowManager should never see this, instead OnWmNewDisplay() is called. |
| 235 NOTREACHED(); | 262 NOTREACHED(); |
| 236 } | 263 } |
| 237 | 264 |
| 238 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { | 265 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { |
| 239 // WindowManager should never see this. | 266 // WindowManager should never see this. |
| 240 NOTREACHED(); | 267 NOTREACHED(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 const ui::Event& event) { | 351 const ui::Event& event) { |
| 325 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 352 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 326 if (iter == accelerator_handlers_.end()) | 353 if (iter == accelerator_handlers_.end()) |
| 327 return ui::mojom::EventResult::HANDLED; | 354 return ui::mojom::EventResult::HANDLED; |
| 328 | 355 |
| 329 return iter->second->OnAccelerator(id, event); | 356 return iter->second->OnAccelerator(id, event); |
| 330 } | 357 } |
| 331 | 358 |
| 332 } // namespace mus | 359 } // namespace mus |
| 333 } // namespace ash | 360 } // namespace ash |
| OLD | NEW |