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

Side by Side Diff: components/mus/ws/connection_manager.cc

Issue 1755223002: Adds WindowManagerManager to mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge and WindowManagerState Created 4 years, 9 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 | « components/mus/ws/connection_manager.h ('k') | components/mus/ws/connection_manager_delegate.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/mus/ws/connection_manager.h" 5 #include "components/mus/ws/connection_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "components/mus/ws/client_connection.h" 9 #include "components/mus/ws/client_connection.h"
10 #include "components/mus/ws/connection_manager_delegate.h" 10 #include "components/mus/ws/connection_manager_delegate.h"
11 #include "components/mus/ws/operation.h" 11 #include "components/mus/ws/operation.h"
12 #include "components/mus/ws/server_window.h" 12 #include "components/mus/ws/server_window.h"
13 #include "components/mus/ws/window_coordinate_conversions.h" 13 #include "components/mus/ws/window_coordinate_conversions.h"
14 #include "components/mus/ws/window_manager_factory_service.h" 14 #include "components/mus/ws/window_manager_factory_service.h"
15 #include "components/mus/ws/window_manager_state.h"
15 #include "components/mus/ws/window_tree_host_connection.h" 16 #include "components/mus/ws/window_tree_host_connection.h"
16 #include "components/mus/ws/window_tree_impl.h" 17 #include "components/mus/ws/window_tree_impl.h"
17 #include "mojo/converters/geometry/geometry_type_converters.h" 18 #include "mojo/converters/geometry/geometry_type_converters.h"
18 #include "mojo/converters/input_events/input_events_type_converters.h" 19 #include "mojo/converters/input_events/input_events_type_converters.h"
19 #include "mojo/converters/surfaces/surfaces_type_converters.h" 20 #include "mojo/converters/surfaces/surfaces_type_converters.h"
20 #include "mojo/shell/public/cpp/connection.h" 21 #include "mojo/shell/public/cpp/connection.h"
21 #include "ui/gfx/geometry/size_conversions.h" 22 #include "ui/gfx/geometry/size_conversions.h"
22 23
23 namespace mus { 24 namespace mus {
24 namespace ws { 25 namespace ws {
25 26
26 ConnectionManager::ConnectionManager( 27 ConnectionManager::ConnectionManager(
27 ConnectionManagerDelegate* delegate, 28 ConnectionManagerDelegate* delegate,
28 const scoped_refptr<mus::SurfacesState>& surfaces_state) 29 const scoped_refptr<mus::SurfacesState>& surfaces_state)
29 : delegate_(delegate), 30 : delegate_(delegate),
30 surfaces_state_(surfaces_state), 31 surfaces_state_(surfaces_state),
31 next_connection_id_(1), 32 next_connection_id_(1),
32 next_host_id_(0), 33 next_host_id_(0),
33 current_operation_(nullptr), 34 current_operation_(nullptr),
34 in_destructor_(false), 35 in_destructor_(false),
35 next_wm_change_id_(0), 36 next_wm_change_id_(0),
36 got_valid_frame_decorations_(false) {} 37 got_valid_frame_decorations_(false),
38 window_manager_factory_registry_(this) {}
37 39
38 ConnectionManager::~ConnectionManager() { 40 ConnectionManager::~ConnectionManager() {
39 in_destructor_ = true; 41 in_destructor_ = true;
40 42
43 while (!pending_hosts_.empty())
44 DestroyHost(*pending_hosts_.begin());
45 DCHECK(pending_hosts_.empty());
46
41 // DestroyHost() removes from |hosts_| and deletes the WindowTreeHostImpl. 47 // DestroyHost() removes from |hosts_| and deletes the WindowTreeHostImpl.
42 while (!hosts_.empty()) 48 while (!hosts_.empty())
43 DestroyHost(*hosts_.begin()); 49 DestroyHost(*hosts_.begin());
44 DCHECK(hosts_.empty()); 50 DCHECK(hosts_.empty());
45 51
46 STLDeleteValues(&connection_map_); 52 STLDeleteValues(&connection_map_);
47 // All the connections should have been destroyed. 53 // All the connections should have been destroyed.
48 DCHECK(connection_map_.empty()); 54 DCHECK(connection_map_.empty());
49 } 55 }
50 56
51 void ConnectionManager::AddHost(WindowTreeHostImpl* host) { 57 void ConnectionManager::AddHost(WindowTreeHostImpl* host) {
52 DCHECK_EQ(0u, pending_hosts_.count(host)); 58 DCHECK_EQ(0u, pending_hosts_.count(host));
53 pending_hosts_.insert(host); 59 pending_hosts_.insert(host);
54 } 60 }
55 61
56 void ConnectionManager::DestroyHost(WindowTreeHostImpl* host) { 62 void ConnectionManager::DestroyHost(WindowTreeHostImpl* host) {
57 DCHECK(hosts_.count(host)); 63 for (auto& pair : connection_map_)
58 hosts_.erase(host); 64 pair.second->service()->OnWillDestroyWindowTreeHost(host);
65
66 if (pending_hosts_.count(host)) {
67 pending_hosts_.erase(host);
68 } else {
69 DCHECK(hosts_.count(host));
70 hosts_.erase(host);
71 }
59 delete host; 72 delete host;
73
74 // If we have no more roots left, let the app know so it can terminate.
75 if (!hosts_.size() && !pending_hosts_.size())
76 delegate_->OnNoMoreRootConnections();
60 } 77 }
61 78
62 ServerWindow* ConnectionManager::CreateServerWindow( 79 ServerWindow* ConnectionManager::CreateServerWindow(
63 const WindowId& id, 80 const WindowId& id,
64 const std::map<std::string, std::vector<uint8_t>>& properties) { 81 const std::map<std::string, std::vector<uint8_t>>& properties) {
65 ServerWindow* window = new ServerWindow(this, id, properties); 82 ServerWindow* window = new ServerWindow(this, id, properties);
66 window->AddObserver(this); 83 window->AddObserver(this);
67 return window; 84 return window;
68 } 85 }
69 86
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 131 }
115 for (uint32_t id : to_remove) 132 for (uint32_t id : to_remove)
116 in_flight_wm_change_map_.erase(id); 133 in_flight_wm_change_map_.erase(id);
117 } 134 }
118 135
119 ClientConnection* ConnectionManager::GetClientConnection( 136 ClientConnection* ConnectionManager::GetClientConnection(
120 WindowTreeImpl* window_tree) { 137 WindowTreeImpl* window_tree) {
121 return connection_map_[window_tree->id()]; 138 return connection_map_[window_tree->id()];
122 } 139 }
123 140
124 void ConnectionManager::OnHostConnectionClosed(WindowTreeHostImpl* host) {
125 if (pending_hosts_.count(host)) {
126 pending_hosts_.erase(host);
127 delete host;
128 return;
129 }
130 auto it = hosts_.find(host);
131 DCHECK(it != hosts_.end());
132
133 // Get the ClientConnection by WindowTreeImpl ID.
134 ConnectionMap::iterator service_connection_it =
135 connection_map_.find(host->GetWindowTree()->id());
136 DCHECK(service_connection_it != connection_map_.end());
137
138 scoped_ptr<WindowTreeHostImpl> host_owner(*it);
139 hosts_.erase(it);
140
141 // Tear down the associated WindowTree connection.
142 // TODO(fsamuel): I don't think this is quite right, we should tear down all
143 // connections within the root's viewport. We should probably employ an
144 // observer pattern to do this. Each WindowTreeImpl should track its
145 // parent's lifetime.
146 OnConnectionError(service_connection_it->second);
147
148 for (auto& pair : connection_map_)
149 pair.second->service()->OnWillDestroyWindowTreeHost(host);
150
151 // If we have no more roots left, let the app know so it can terminate.
152 if (!hosts_.size() && !pending_hosts_.size())
153 delegate_->OnNoMoreRootConnections();
154 }
155
156 WindowTreeImpl* ConnectionManager::EmbedAtWindow( 141 WindowTreeImpl* ConnectionManager::EmbedAtWindow(
157 ServerWindow* root, 142 ServerWindow* root,
158 uint32_t policy_bitmask, 143 uint32_t policy_bitmask,
159 mojom::WindowTreeClientPtr client) { 144 mojom::WindowTreeClientPtr client) {
160 mojom::WindowTreePtr tree_ptr; 145 mojom::WindowTreePtr tree_ptr;
161 ClientConnection* client_connection = 146 ClientConnection* client_connection =
162 delegate_->CreateClientConnectionForEmbedAtWindow( 147 delegate_->CreateClientConnectionForEmbedAtWindow(
163 this, GetProxy(&tree_ptr), root, policy_bitmask, std::move(client)); 148 this, GetProxy(&tree_ptr), root, policy_bitmask, std::move(client));
164 AddConnection(make_scoped_ptr(client_connection), std::move(tree_ptr)); 149 AddConnection(make_scoped_ptr(client_connection), std::move(tree_ptr));
165 OnConnectionMessagedClient(client_connection->service()->id()); 150 OnConnectionMessagedClient(client_connection->service()->id());
166 return client_connection->service(); 151 return client_connection->service();
167 } 152 }
168 153
169 void ConnectionManager::AddConnection( 154 void ConnectionManager::AddConnection(
170 scoped_ptr<ClientConnection> owned_connection, 155 scoped_ptr<ClientConnection> owned_connection,
171 mojom::WindowTreePtr tree_ptr) { 156 mojom::WindowTreePtr tree_ptr) {
172 ClientConnection* connection = owned_connection.release(); 157 ClientConnection* connection = owned_connection.release();
173 CHECK_EQ(0u, connection_map_.count(connection->service()->id())); 158 CHECK_EQ(0u, connection_map_.count(connection->service()->id()));
174 connection_map_[connection->service()->id()] = connection; 159 connection_map_[connection->service()->id()] = connection;
175 connection->service()->Init(connection->client(), std::move(tree_ptr)); 160 connection->service()->Init(connection->client(), std::move(tree_ptr));
176 } 161 }
177 162
178 WindowTreeImpl* ConnectionManager::GetConnection( 163 WindowTreeImpl* ConnectionManager::GetConnection(
179 ConnectionSpecificId connection_id) { 164 ConnectionSpecificId connection_id) {
180 ConnectionMap::iterator i = connection_map_.find(connection_id); 165 ConnectionMap::iterator i = connection_map_.find(connection_id);
181 return i == connection_map_.end() ? nullptr : i->second->service(); 166 return i == connection_map_.end() ? nullptr : i->second->service();
182 } 167 }
183 168
184 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) { 169 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) {
185 for (WindowTreeHostImpl* host : hosts_) { 170 // kInvalidConnectionId is used for WindowTreeHost and WindowManager root
186 if (host->root_window()->id() == id) 171 // nodes.
187 return host->root_window(); 172 if (id.connection_id == kInvalidConnectionId) {
173 for (WindowTreeHostImpl* host : hosts_) {
174 ServerWindow* window = host->GetRootWithId(id);
175 if (window)
176 return window;
177 }
188 } 178 }
189 WindowTreeImpl* service = GetConnection(id.connection_id); 179 WindowTreeImpl* service = GetConnection(id.connection_id);
190 return service ? service->GetWindow(id) : nullptr; 180 return service ? service->GetWindow(id) : nullptr;
191 } 181 }
192 182
193 bool ConnectionManager::IsWindowAttachedToRoot(
194 const ServerWindow* window) const {
195 for (WindowTreeHostImpl* host : hosts_) {
196 if (host->IsWindowAttachedToRoot(window))
197 return true;
198 }
199 return false;
200 }
201
202 void ConnectionManager::SchedulePaint(const ServerWindow* window, 183 void ConnectionManager::SchedulePaint(const ServerWindow* window,
203 const gfx::Rect& bounds) { 184 const gfx::Rect& bounds) {
204 for (WindowTreeHostImpl* host : hosts_) { 185 for (WindowTreeHostImpl* host : hosts_) {
205 if (host->SchedulePaintIfInViewport(window, bounds)) 186 if (host->SchedulePaintIfInViewport(window, bounds))
206 return; 187 return;
207 } 188 }
208 } 189 }
209 190
210 void ConnectionManager::OnWindowTreeHostDisplayAvailable( 191 void ConnectionManager::OnWindowTreeHostDisplayAvailable(
211 WindowTreeHostImpl* host) { 192 WindowTreeHostImpl* host) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const ServerWindow* window) const { 227 const ServerWindow* window) const {
247 if (!window) 228 if (!window)
248 return nullptr; 229 return nullptr;
249 for (auto& pair : connection_map_) { 230 for (auto& pair : connection_map_) {
250 if (pair.second->service()->HasRoot(window)) 231 if (pair.second->service()->HasRoot(window))
251 return pair.second->service(); 232 return pair.second->service();
252 } 233 }
253 return nullptr; 234 return nullptr;
254 } 235 }
255 236
237 WindowManagerAndHostConst ConnectionManager::GetWindowManagerAndHost(
238 const ServerWindow* window) const {
239 const ServerWindow* last = window;
240 while (window && window->parent()) {
241 last = window;
242 window = window->parent();
243 }
244 for (WindowTreeHostImpl* host : hosts_) {
245 if (window == host->root_window()) {
246 WindowManagerAndHostConst result;
247 result.window_tree_host = host;
248 result.window_manager_state = host->GetWindowManagerStateWithRoot(last);
249 return result;
250 }
251 }
252 return WindowManagerAndHostConst();
253 }
254
255 WindowManagerAndHost ConnectionManager::GetWindowManagerAndHost(
256 const ServerWindow* window) {
257 WindowManagerAndHostConst result_const =
258 const_cast<const ConnectionManager*>(this)->GetWindowManagerAndHost(
259 window);
260 WindowManagerAndHost result;
261 result.window_tree_host =
262 const_cast<WindowTreeHostImpl*>(result_const.window_tree_host);
263 result.window_manager_state =
264 const_cast<WindowManagerState*>(result_const.window_manager_state);
265 return result;
266 }
267
256 WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow( 268 WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow(
257 const ServerWindow* window) { 269 const ServerWindow* window) {
258 return const_cast<WindowTreeHostImpl*>( 270 return const_cast<WindowTreeHostImpl*>(
259 static_cast<const ConnectionManager*>(this) 271 static_cast<const ConnectionManager*>(this)
260 ->GetWindowTreeHostByWindow(window)); 272 ->GetWindowTreeHostByWindow(window));
261 } 273 }
262 274
263 const WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow( 275 const WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow(
264 const ServerWindow* window) const { 276 const ServerWindow* window) const {
265 while (window && window->parent()) 277 while (window && window->parent())
266 window = window->parent(); 278 window = window->parent();
267 for (WindowTreeHostImpl* host : hosts_) { 279 for (WindowTreeHostImpl* host : hosts_) {
268 if (window == host->root_window()) 280 if (window == host->root_window())
269 return host; 281 return host;
270 } 282 }
271 return nullptr; 283 return nullptr;
272 } 284 }
273 285
274 WindowTreeHostImpl* ConnectionManager::GetActiveWindowTreeHost() { 286 WindowTreeHostImpl* ConnectionManager::GetActiveWindowTreeHost() {
275 // TODO(sky): this isn't active, but first. Make it active. 287 // TODO(sky): this isn't active, but first. Make it active.
276 return hosts_.size() ? *hosts_.begin() : nullptr; 288 return hosts_.size() ? *hosts_.begin() : nullptr;
277 } 289 }
278 290
279 void ConnectionManager::AddDisplayManagerBinding( 291 void ConnectionManager::AddDisplayManagerBinding(
280 mojo::InterfaceRequest<mojom::DisplayManager> request) { 292 mojo::InterfaceRequest<mojom::DisplayManager> request) {
281 display_manager_bindings_.AddBinding(this, std::move(request)); 293 display_manager_bindings_.AddBinding(this, std::move(request));
282 } 294 }
283 295
284 void ConnectionManager::CreateWindowManagerFactoryService( 296 void ConnectionManager::CreateWindowManagerFactoryService(
297 uint32_t user_id,
285 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) { 298 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) {
286 if (window_manager_factory_service_) 299 window_manager_factory_registry_.Register(user_id, std::move(request));
300 }
301
302 void ConnectionManager::OnWindowManagerFactorySet() {
303 if (!hosts_.empty() || !pending_hosts_.empty())
287 return; 304 return;
288 305
289 window_manager_factory_service_.reset( 306 // We've been supplied a WindowManagerFactory and no windowtreehosts have been
290 new WindowManagerFactoryService(std::move(request))); 307 // created yet. Treat this as a signal to create a WindowTreeHost.
308 // TODO(sky): we need a better way to determine this, most likely a switch.
309 delegate_->CreateDefaultWindowTreeHosts();
291 } 310 }
292 311
293 uint32_t ConnectionManager::GenerateWindowManagerChangeId( 312 uint32_t ConnectionManager::GenerateWindowManagerChangeId(
294 WindowTreeImpl* source, 313 WindowTreeImpl* source,
295 uint32_t client_change_id) { 314 uint32_t client_change_id) {
296 const uint32_t wm_change_id = next_wm_change_id_++; 315 const uint32_t wm_change_id = next_wm_change_id_++;
297 in_flight_wm_change_map_[wm_change_id] = {source->id(), client_change_id}; 316 in_flight_wm_change_map_[wm_change_id] = {source->id(), client_change_id};
298 return wm_change_id; 317 return wm_change_id;
299 } 318 }
300 319
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 !window || window->id().connection_id != wm_connection->id() || 351 !window || window->id().connection_id != wm_connection->id() ||
333 !window->children().empty() || GetConnectionWithRoot(window)) { 352 !window->children().empty() || GetConnectionWithRoot(window)) {
334 WindowManagerSentBogusMessage(); 353 WindowManagerSentBogusMessage();
335 return; 354 return;
336 } 355 }
337 356
338 connection->OnWindowManagerCreatedTopLevelWindow( 357 connection->OnWindowManagerCreatedTopLevelWindow(
339 window_manager_change_id, change.client_change_id, window); 358 window_manager_change_id, change.client_change_id, window);
340 } 359 }
341 360
361 mojom::DisplayPtr ConnectionManager::DisplayForHost(WindowTreeHostImpl* host) {
362 size_t i = 0;
363 int next_x = 0;
364 for (WindowTreeHostImpl* host2 : hosts_) {
365 const ServerWindow* root = host->root_window();
366 if (host == host2) {
367 mojom::DisplayPtr display = mojom::Display::New();
368 display = mojom::Display::New();
369 display->id = host->id();
370 display->bounds = mojo::Rect::New();
371 display->bounds->x = next_x;
372 display->bounds->y = 0;
373 display->bounds->width = root->bounds().size().width();
374 display->bounds->height = root->bounds().size().height();
375 // TODO(sky): window manager needs an API to set the work area.
376 display->work_area = display->bounds.Clone();
377 display->device_pixel_ratio =
378 host->GetViewportMetrics().device_pixel_ratio;
379 display->rotation = host->GetRotation();
380 // TODO(sky): make this real.
381 display->is_primary = i == 0;
382 // TODO(sky): make this real.
383 display->touch_support = mojom::TouchSupport::UNKNOWN;
384 display->frame_decoration_values =
385 host->frame_decoration_values().Clone();
386 return display;
387 }
388 next_x += root->bounds().size().width();
389 ++i;
390 }
391 NOTREACHED();
392 return mojom::Display::New();
393 }
394
342 void ConnectionManager::ProcessWindowBoundsChanged( 395 void ConnectionManager::ProcessWindowBoundsChanged(
343 const ServerWindow* window, 396 const ServerWindow* window,
344 const gfx::Rect& old_bounds, 397 const gfx::Rect& old_bounds,
345 const gfx::Rect& new_bounds) { 398 const gfx::Rect& new_bounds) {
346 for (auto& pair : connection_map_) { 399 for (auto& pair : connection_map_) {
347 pair.second->service()->ProcessWindowBoundsChanged( 400 pair.second->service()->ProcessWindowBoundsChanged(
348 window, old_bounds, new_bounds, IsOperationSource(pair.first)); 401 window, old_bounds, new_bounds, IsOperationSource(pair.first));
349 } 402 }
350 } 403 }
351 404
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 mojom::DisplayManagerObserver* observer, 557 mojom::DisplayManagerObserver* observer,
505 WindowTreeHostImpl* host) { 558 WindowTreeHostImpl* host) {
506 mojo::Array<mojom::DisplayPtr> displays(1); 559 mojo::Array<mojom::DisplayPtr> displays(1);
507 displays[0] = DisplayForHost(host); 560 displays[0] = DisplayForHost(host);
508 display_manager_observers_.ForAllPtrs( 561 display_manager_observers_.ForAllPtrs(
509 [&displays](mojom::DisplayManagerObserver* observer) { 562 [&displays](mojom::DisplayManagerObserver* observer) {
510 observer->OnDisplaysChanged(displays.Clone()); 563 observer->OnDisplaysChanged(displays.Clone());
511 }); 564 });
512 } 565 }
513 566
514 mojom::DisplayPtr ConnectionManager::DisplayForHost(WindowTreeHostImpl* host) {
515 size_t i = 0;
516 int next_x = 0;
517 for (WindowTreeHostImpl* host2 : hosts_) {
518 const ServerWindow* root = host->root_window();
519 if (host == host2) {
520 mojom::DisplayPtr display = mojom::Display::New();
521 display = mojom::Display::New();
522 display->id = host->id();
523 display->bounds = mojo::Rect::New();
524 display->bounds->x = next_x;
525 display->bounds->y = 0;
526 display->bounds->width = root->bounds().size().width();
527 display->bounds->height = root->bounds().size().height();
528 // TODO(sky): window manager needs an API to set the work area.
529 display->work_area = display->bounds.Clone();
530 display->device_pixel_ratio =
531 host->GetViewportMetrics().device_pixel_ratio;
532 display->rotation = host->GetRotation();
533 // TODO(sky): make this real.
534 display->is_primary = i == 0;
535 // TODO(sky): make this real.
536 display->touch_support = mojom::TouchSupport::UNKNOWN;
537 display->frame_decoration_values =
538 host->frame_decoration_values().Clone();
539 return display;
540 }
541 next_x += root->bounds().size().width();
542 ++i;
543 }
544 NOTREACHED();
545 return mojom::Display::New();
546 }
547
548 mus::SurfacesState* ConnectionManager::GetSurfacesState() { 567 mus::SurfacesState* ConnectionManager::GetSurfacesState() {
549 return surfaces_state_.get(); 568 return surfaces_state_.get();
550 } 569 }
551 570
552 void ConnectionManager::OnScheduleWindowPaint(const ServerWindow* window) { 571 void ConnectionManager::OnScheduleWindowPaint(const ServerWindow* window) {
553 if (!in_destructor_) 572 if (!in_destructor_)
554 SchedulePaint(window, gfx::Rect(window->bounds().size())); 573 SchedulePaint(window, gfx::Rect(window->bounds().size()));
555 } 574 }
556 575
557 const ServerWindow* ConnectionManager::GetRootWindow( 576 const ServerWindow* ConnectionManager::GetRootWindow(
558 const ServerWindow* window) const { 577 const ServerWindow* window) const {
559 const WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window); 578 const WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window);
560 return host ? host->root_window() : nullptr; 579 return host ? host->root_window() : nullptr;
561 } 580 }
562 581
563 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) { 582 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) {
564 for (WindowTreeHostImpl* host : hosts_) { 583 for (WindowTreeHostImpl* host : hosts_) {
565 if (host->root_window()->Contains(window)) { 584 if (host->root_window()->Contains(window)) {
566 host->ScheduleSurfaceDestruction(window); 585 host->ScheduleSurfaceDestruction(window);
567 break; 586 break;
568 } 587 }
569 } 588 }
570 } 589 }
571 590
572 ServerWindow* ConnectionManager::FindWindowForSurface( 591 ServerWindow* ConnectionManager::FindWindowForSurface(
573 const ServerWindow* ancestor, 592 const ServerWindow* ancestor,
574 mojom::SurfaceType surface_type, 593 mojom::SurfaceType surface_type,
575 const ClientWindowId& client_window_id) { 594 const ClientWindowId& client_window_id) {
576 WindowTreeImpl* window_tree; 595 WindowTreeImpl* window_tree;
577 if (ancestor->id().connection_id == kInvalidConnectionId) 596 if (ancestor->id().connection_id == kInvalidConnectionId) {
578 window_tree = GetWindowTreeHostByWindow(ancestor)->GetWindowTree(); 597 WindowManagerAndHost wm_and_host = GetWindowManagerAndHost(ancestor);
579 else 598 window_tree = wm_and_host.window_manager_state
599 ? wm_and_host.window_manager_state->tree()
600 : nullptr;
601 } else {
580 window_tree = GetConnection(ancestor->id().connection_id); 602 window_tree = GetConnection(ancestor->id().connection_id);
603 }
581 if (!window_tree) 604 if (!window_tree)
582 return nullptr; 605 return nullptr;
583 if (surface_type == mojom::SurfaceType::DEFAULT) { 606 if (surface_type == mojom::SurfaceType::DEFAULT) {
584 // At embed points the default surface comes from the embedded app. 607 // At embed points the default surface comes from the embedded app.
585 WindowTreeImpl* connection_with_root = GetConnectionWithRoot(ancestor); 608 WindowTreeImpl* connection_with_root = GetConnectionWithRoot(ancestor);
586 if (connection_with_root) 609 if (connection_with_root)
587 window_tree = connection_with_root; 610 window_tree = connection_with_root;
588 } 611 }
589 return window_tree->GetWindowByClientId(client_window_id); 612 return window_tree->GetWindowByClientId(client_window_id);
590 } 613 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 // If we're deleting a window, then this is a superfluous message. 737 // If we're deleting a window, then this is a superfluous message.
715 if (current_operation_type() == OperationType::DELETE_WINDOW) 738 if (current_operation_type() == OperationType::DELETE_WINDOW)
716 return; 739 return;
717 for (auto& pair : connection_map_) { 740 for (auto& pair : connection_map_) {
718 pair.second->service()->ProcessTransientWindowRemoved( 741 pair.second->service()->ProcessTransientWindowRemoved(
719 window, transient_child, IsOperationSource(pair.first)); 742 window, transient_child, IsOperationSource(pair.first));
720 } 743 }
721 } 744 }
722 745
723 void ConnectionManager::AddObserver(mojom::DisplayManagerObserverPtr observer) { 746 void ConnectionManager::AddObserver(mojom::DisplayManagerObserverPtr observer) {
747 // TODO(sky): this needs to be per user.
748
724 // Many clients key off the frame decorations to size widgets. Wait for frame 749 // Many clients key off the frame decorations to size widgets. Wait for frame
725 // decorations before notifying so that we don't have to worry about clients 750 // decorations before notifying so that we don't have to worry about clients
726 // resizing appropriately. 751 // resizing appropriately.
727 if (!got_valid_frame_decorations_) { 752 if (!got_valid_frame_decorations_) {
728 display_manager_observers_.AddInterfacePtr(std::move(observer)); 753 display_manager_observers_.AddInterfacePtr(std::move(observer));
729 return; 754 return;
730 } 755 }
731 CallOnDisplays(observer.get()); 756 CallOnDisplays(observer.get());
732 display_manager_observers_.AddInterfacePtr(std::move(observer)); 757 display_manager_observers_.AddInterfacePtr(std::move(observer));
733 } 758 }
734 759
735 } // namespace ws 760 } // namespace ws
736 } // namespace mus 761 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/connection_manager.h ('k') | components/mus/ws/connection_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698