Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: ash/mus/window_manager.cc

Issue 2350953009: Centralizes more shared code between ash and mash (Closed)
Patch Set: moar Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/mus/accelerators/accelerator_handler.h" 12 #include "ash/mus/accelerators/accelerator_handler.h"
13 #include "ash/mus/accelerators/accelerator_ids.h" 13 #include "ash/mus/accelerators/accelerator_ids.h"
14 #include "ash/mus/app_list_presenter_mus.h" 14 #include "ash/mus/app_list_presenter_mus.h"
15 #include "ash/mus/bridge/wm_lookup_mus.h" 15 #include "ash/mus/bridge/wm_lookup_mus.h"
16 #include "ash/mus/bridge/wm_root_window_controller_mus.h"
16 #include "ash/mus/bridge/wm_shell_mus.h" 17 #include "ash/mus/bridge/wm_shell_mus.h"
17 #include "ash/mus/bridge/wm_window_mus.h" 18 #include "ash/mus/bridge/wm_window_mus.h"
18 #include "ash/mus/move_event_handler.h" 19 #include "ash/mus/move_event_handler.h"
19 #include "ash/mus/non_client_frame_controller.h" 20 #include "ash/mus/non_client_frame_controller.h"
20 #include "ash/mus/property_util.h" 21 #include "ash/mus/property_util.h"
21 #include "ash/mus/root_window_controller.h" 22 #include "ash/mus/root_window_controller.h"
22 #include "ash/mus/shadow_controller.h" 23 #include "ash/mus/shadow_controller.h"
23 #include "ash/mus/shell_delegate_mus.h" 24 #include "ash/mus/shell_delegate_mus.h"
24 #include "ash/mus/window_manager_observer.h" 25 #include "ash/mus/window_manager_observer.h"
25 #include "ash/public/interfaces/container.mojom.h" 26 #include "ash/public/interfaces/container.mojom.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (was_displays_empty) { 145 if (was_displays_empty) {
145 screen_->display_list()->AddDisplay(display, 146 screen_->display_list()->AddDisplay(display,
146 display::DisplayList::Type::PRIMARY); 147 display::DisplayList::Type::PRIMARY);
147 } 148 }
148 149
149 std::unique_ptr<RootWindowController> root_window_controller_ptr( 150 std::unique_ptr<RootWindowController> root_window_controller_ptr(
150 new RootWindowController(this, window, display)); 151 new RootWindowController(this, window, display));
151 RootWindowController* root_window_controller = 152 RootWindowController* root_window_controller =
152 root_window_controller_ptr.get(); 153 root_window_controller_ptr.get();
153 root_window_controllers_.insert(std::move(root_window_controller_ptr)); 154 root_window_controllers_.insert(std::move(root_window_controller_ptr));
154 window->AddObserver(this);
155 155
156 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 156 FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
157 OnRootWindowControllerAdded(root_window_controller)); 157 OnRootWindowControllerAdded(root_window_controller));
158 158
159 if (!was_displays_empty) { 159 if (!was_displays_empty) {
160 // If this isn't the initial display then add the display to Screen after 160 // If this isn't the initial display then add the display to Screen after
161 // creating the RootWindowController. We need to do this after creating the 161 // creating the RootWindowController. We need to do this after creating the
162 // RootWindowController as adding the display triggers OnDisplayAdded(), 162 // RootWindowController as adding the display triggers OnDisplayAdded(),
163 // which triggers some overrides asking for the RootWindowController for the 163 // which triggers some overrides asking for the RootWindowController for the
164 // new display. 164 // new display.
165 screen_->display_list()->AddDisplay( 165 screen_->display_list()->AddDisplay(
166 display, display::DisplayList::Type::NOT_PRIMARY); 166 display, display::DisplayList::Type::NOT_PRIMARY);
167 } 167 }
168 return root_window_controller; 168 return root_window_controller;
169 } 169 }
170 170
171 void WindowManager::DestroyRootWindowController( 171 void WindowManager::DestroyRootWindowController(
172 RootWindowController* root_window_controller) { 172 RootWindowController* root_window_controller) {
173 // TODO(sky): WindowManager shouldn't need to observe the windows. Instead 173 if (root_window_controllers_.size() > 1) {
174 // WindowManager should have a specific API that is called when a display is 174 root_window_controller->wm_root_window_controller()->MoveWindowsTo(
175 // removed. 175 WmWindowMus::Get(GetPrimaryRootWindowController()->root()));
James Cook 2016/09/21 22:03:19 DCHECK that the root_window_controller being destr
sky 2016/09/21 22:47:49 Done.
176 }
177
176 ui::Window* root_window = root_window_controller->root(); 178 ui::Window* root_window = root_window_controller->root();
177 auto it = FindRootWindowControllerByWindow(root_window); 179 auto it = FindRootWindowControllerByWindow(root_window);
178 DCHECK(it != root_window_controllers_.end()); 180 DCHECK(it != root_window_controllers_.end());
179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 181
180 OnWillDestroyRootWindowController((*it).get())); 182 (*it)->Shutdown();
183
184 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon())
185 // this may need to change to mirror that.
181 root_window_controllers_.erase(it); 186 root_window_controllers_.erase(it);
182 // Remove the observer so we don't see the OnWindowDestroying/Destroyed as we
183 // already handled it here.
184 root_window->RemoveObserver(this);
185 root_window->Destroy();
186 } 187 }
187 188
188 void WindowManager::Shutdown() { 189 void WindowManager::Shutdown() {
189 if (!window_tree_client_) 190 if (!window_tree_client_)
190 return; 191 return;
191 192
192 // Observers can rely on WmShell from the callback. So notify the observers 193 // Observers can rely on WmShell from the callback. So notify the observers
193 // before destroying it. 194 // before destroying it.
194 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 195 FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
195 OnWindowTreeClientDestroyed()); 196 OnWindowTreeClientDestroyed());
196 197
197 // Destroy the roots of the RootWindowControllers, which triggers removal 198 // Destroy the roots of the RootWindowControllers, which triggers removal
198 // in OnWindowDestroyed(). 199 // in OnWindowDestroyed().
199 while (!root_window_controllers_.empty()) 200 while (!root_window_controllers_.empty())
200 (*root_window_controllers_.begin())->root()->Destroy(); 201 DestroyRootWindowController(root_window_controllers_.begin()->get());
201 202
202 lookup_.reset(); 203 lookup_.reset();
203 shell_->Shutdown(); 204 shell_->Shutdown();
204 shell_.reset(); 205 shell_.reset();
205 shadow_controller_.reset(); 206 shadow_controller_.reset();
206 207
207 pointer_watcher_event_router_.reset(); 208 pointer_watcher_event_router_.reset();
208 209
209 window_tree_client_.reset(); 210 window_tree_client_.reset();
210 window_manager_client_ = nullptr; 211 window_manager_client_ = nullptr;
211 } 212 }
212 213
213 WindowManager::RootWindowControllers::iterator 214 WindowManager::RootWindowControllers::iterator
214 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { 215 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) {
215 for (auto it = root_window_controllers_.begin(); 216 for (auto it = root_window_controllers_.begin();
216 it != root_window_controllers_.end(); ++it) { 217 it != root_window_controllers_.end(); ++it) {
217 if ((*it)->root() == window) 218 if ((*it)->root() == window)
218 return it; 219 return it;
219 } 220 }
220 return root_window_controllers_.end(); 221 return root_window_controllers_.end();
221 } 222 }
222 223
223 void WindowManager::OnWindowDestroying(ui::Window* window) { 224 RootWindowController* WindowManager::GetPrimaryRootWindowController() {
224 auto it = FindRootWindowControllerByWindow(window); 225 return static_cast<WmRootWindowControllerMus*>(
225 DCHECK(it != root_window_controllers_.end()); 226 WmShell::Get()->GetPrimaryRootWindowController())
226 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 227 ->root_window_controller();
227 OnWillDestroyRootWindowController((*it).get()));
228 }
229
230 void WindowManager::OnWindowDestroyed(ui::Window* window) {
231 auto it = FindRootWindowControllerByWindow(window);
232 DCHECK(it != root_window_controllers_.end());
233 window->RemoveObserver(this);
234 root_window_controllers_.erase(it);
235 } 228 }
236 229
237 void WindowManager::OnEmbed(ui::Window* root) { 230 void WindowManager::OnEmbed(ui::Window* root) {
238 // WindowManager should never see this, instead OnWmNewDisplay() is called. 231 // WindowManager should never see this, instead OnWmNewDisplay() is called.
239 NOTREACHED(); 232 NOTREACHED();
240 } 233 }
241 234
242 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { 235 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) {
243 // WindowManager should never see this. 236 // WindowManager should never see this.
244 NOTREACHED(); 237 NOTREACHED();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 for (auto* window : client_windows) 284 for (auto* window : client_windows)
292 SetWindowIsJanky(window, janky); 285 SetWindowIsJanky(window, janky);
293 } 286 }
294 287
295 void WindowManager::OnWmNewDisplay(ui::Window* window, 288 void WindowManager::OnWmNewDisplay(ui::Window* window,
296 const display::Display& display) { 289 const display::Display& display) {
297 CreateRootWindowController(window, display); 290 CreateRootWindowController(window, display);
298 } 291 }
299 292
300 void WindowManager::OnWmDisplayRemoved(ui::Window* window) { 293 void WindowManager::OnWmDisplayRemoved(ui::Window* window) {
301 // TODO(sky): wire up this up correctly. 294 auto iter = FindRootWindowControllerByWindow(window);
302 NOTIMPLEMENTED(); 295 DCHECK(iter != root_window_controllers_.end());
296 DestroyRootWindowController(iter->get());
303 } 297 }
304 298
305 void WindowManager::OnWmPerformMoveLoop( 299 void WindowManager::OnWmPerformMoveLoop(
306 ui::Window* window, 300 ui::Window* window,
307 ui::mojom::MoveLoopSource source, 301 ui::mojom::MoveLoopSource source,
308 const gfx::Point& cursor_location, 302 const gfx::Point& cursor_location,
309 const base::Callback<void(bool)>& on_done) { 303 const base::Callback<void(bool)>& on_done) {
310 WmWindowMus* child_window = WmWindowMus::Get(window); 304 WmWindowMus* child_window = WmWindowMus::Get(window);
311 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); 305 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window);
312 if (!handler) { 306 if (!handler) {
(...skipping 20 matching lines...) Expand all
333 const ui::Event& event) { 327 const ui::Event& event) {
334 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); 328 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id));
335 if (iter == accelerator_handlers_.end()) 329 if (iter == accelerator_handlers_.end())
336 return ui::mojom::EventResult::HANDLED; 330 return ui::mojom::EventResult::HANDLED;
337 331
338 return iter->second->OnAccelerator(id, event); 332 return iter->second->OnAccelerator(id, event);
339 } 333 }
340 334
341 } // namespace mus 335 } // namespace mus
342 } // namespace ash 336 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698