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

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

Issue 2350953009: Centralizes more shared code between ash and mash (Closed)
Patch Set: feedback 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
« no previous file with comments | « ash/mus/window_manager.h ('k') | ash/mus/window_manager_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 DCHECK_NE(root_window_controller, GetPrimaryRootWindowController());
175 // removed. 175 root_window_controller->wm_root_window_controller()->MoveWindowsTo(
176 WmWindowMus::Get(GetPrimaryRootWindowController()->root()));
177 }
178
176 ui::Window* root_window = root_window_controller->root(); 179 ui::Window* root_window = root_window_controller->root();
177 auto it = FindRootWindowControllerByWindow(root_window); 180 auto it = FindRootWindowControllerByWindow(root_window);
178 DCHECK(it != root_window_controllers_.end()); 181 DCHECK(it != root_window_controllers_.end());
179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 182
180 OnWillDestroyRootWindowController((*it).get())); 183 (*it)->Shutdown();
184
185 // NOTE: classic ash deleted RootWindowController after a delay (DeleteSoon())
186 // this may need to change to mirror that.
181 root_window_controllers_.erase(it); 187 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 } 188 }
187 189
188 void WindowManager::Shutdown() { 190 void WindowManager::Shutdown() {
189 if (!window_tree_client_) 191 if (!window_tree_client_)
190 return; 192 return;
191 193
192 // Observers can rely on WmShell from the callback. So notify the observers 194 // Observers can rely on WmShell from the callback. So notify the observers
193 // before destroying it. 195 // before destroying it.
194 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 196 FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
195 OnWindowTreeClientDestroyed()); 197 OnWindowTreeClientDestroyed());
196 198
197 // Destroy the roots of the RootWindowControllers, which triggers removal 199 // Destroy the roots of the RootWindowControllers, which triggers removal
198 // in OnWindowDestroyed(). 200 // in OnWindowDestroyed().
199 while (!root_window_controllers_.empty()) 201 while (!root_window_controllers_.empty())
200 (*root_window_controllers_.begin())->root()->Destroy(); 202 DestroyRootWindowController(root_window_controllers_.begin()->get());
201 203
202 lookup_.reset(); 204 lookup_.reset();
203 shell_->Shutdown(); 205 shell_->Shutdown();
204 shell_.reset(); 206 shell_.reset();
205 shadow_controller_.reset(); 207 shadow_controller_.reset();
206 208
207 pointer_watcher_event_router_.reset(); 209 pointer_watcher_event_router_.reset();
208 210
209 window_tree_client_.reset(); 211 window_tree_client_.reset();
210 window_manager_client_ = nullptr; 212 window_manager_client_ = nullptr;
211 } 213 }
212 214
213 WindowManager::RootWindowControllers::iterator 215 WindowManager::RootWindowControllers::iterator
214 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { 216 WindowManager::FindRootWindowControllerByWindow(ui::Window* window) {
215 for (auto it = root_window_controllers_.begin(); 217 for (auto it = root_window_controllers_.begin();
216 it != root_window_controllers_.end(); ++it) { 218 it != root_window_controllers_.end(); ++it) {
217 if ((*it)->root() == window) 219 if ((*it)->root() == window)
218 return it; 220 return it;
219 } 221 }
220 return root_window_controllers_.end(); 222 return root_window_controllers_.end();
221 } 223 }
222 224
223 void WindowManager::OnWindowDestroying(ui::Window* window) { 225 RootWindowController* WindowManager::GetPrimaryRootWindowController() {
224 auto it = FindRootWindowControllerByWindow(window); 226 return static_cast<WmRootWindowControllerMus*>(
225 DCHECK(it != root_window_controllers_.end()); 227 WmShell::Get()->GetPrimaryRootWindowController())
226 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, 228 ->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 } 229 }
236 230
237 void WindowManager::OnEmbed(ui::Window* root) { 231 void WindowManager::OnEmbed(ui::Window* root) {
238 // WindowManager should never see this, instead OnWmNewDisplay() is called. 232 // WindowManager should never see this, instead OnWmNewDisplay() is called.
239 NOTREACHED(); 233 NOTREACHED();
240 } 234 }
241 235
242 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) { 236 void WindowManager::OnEmbedRootDestroyed(ui::Window* root) {
243 // WindowManager should never see this. 237 // WindowManager should never see this.
244 NOTREACHED(); 238 NOTREACHED();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 for (auto* window : client_windows) 285 for (auto* window : client_windows)
292 SetWindowIsJanky(window, janky); 286 SetWindowIsJanky(window, janky);
293 } 287 }
294 288
295 void WindowManager::OnWmNewDisplay(ui::Window* window, 289 void WindowManager::OnWmNewDisplay(ui::Window* window,
296 const display::Display& display) { 290 const display::Display& display) {
297 CreateRootWindowController(window, display); 291 CreateRootWindowController(window, display);
298 } 292 }
299 293
300 void WindowManager::OnWmDisplayRemoved(ui::Window* window) { 294 void WindowManager::OnWmDisplayRemoved(ui::Window* window) {
301 // TODO(sky): wire up this up correctly. 295 auto iter = FindRootWindowControllerByWindow(window);
302 NOTIMPLEMENTED(); 296 DCHECK(iter != root_window_controllers_.end());
297 DestroyRootWindowController(iter->get());
303 } 298 }
304 299
305 void WindowManager::OnWmPerformMoveLoop( 300 void WindowManager::OnWmPerformMoveLoop(
306 ui::Window* window, 301 ui::Window* window,
307 ui::mojom::MoveLoopSource source, 302 ui::mojom::MoveLoopSource source,
308 const gfx::Point& cursor_location, 303 const gfx::Point& cursor_location,
309 const base::Callback<void(bool)>& on_done) { 304 const base::Callback<void(bool)>& on_done) {
310 WmWindowMus* child_window = WmWindowMus::Get(window); 305 WmWindowMus* child_window = WmWindowMus::Get(window);
311 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); 306 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window);
312 if (!handler) { 307 if (!handler) {
(...skipping 20 matching lines...) Expand all
333 const ui::Event& event) { 328 const ui::Event& event) {
334 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); 329 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id));
335 if (iter == accelerator_handlers_.end()) 330 if (iter == accelerator_handlers_.end())
336 return ui::mojom::EventResult::HANDLED; 331 return ui::mojom::EventResult::HANDLED;
337 332
338 return iter->second->OnAccelerator(id, event); 333 return iter->second->OnAccelerator(id, event);
339 } 334 }
340 335
341 } // namespace mus 336 } // namespace mus
342 } // namespace ash 337 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/window_manager.h ('k') | ash/mus/window_manager_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698