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

Side by Side Diff: components/view_manager/connection_manager.cc

Issue 1314953002: Rename ViewManagerService,ViewManagerClient -> ViewTree,ViewTreeClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 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 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/view_manager/connection_manager.h" 5 #include "components/view_manager/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/view_manager/client_connection.h" 9 #include "components/view_manager/client_connection.h"
10 #include "components/view_manager/connection_manager_delegate.h" 10 #include "components/view_manager/connection_manager_delegate.h"
11 #include "components/view_manager/focus_controller.h" 11 #include "components/view_manager/focus_controller.h"
12 #include "components/view_manager/server_view.h" 12 #include "components/view_manager/server_view.h"
13 #include "components/view_manager/view_coordinate_conversions.h" 13 #include "components/view_manager/view_coordinate_conversions.h"
14 #include "components/view_manager/view_manager_root_connection.h" 14 #include "components/view_manager/view_manager_root_connection.h"
15 #include "components/view_manager/view_manager_service_impl.h" 15 #include "components/view_manager/view_tree_impl.h"
16 #include "mojo/application/public/cpp/application_connection.h" 16 #include "mojo/application/public/cpp/application_connection.h"
17 #include "mojo/converters/geometry/geometry_type_converters.h" 17 #include "mojo/converters/geometry/geometry_type_converters.h"
18 #include "mojo/converters/input_events/input_events_type_converters.h" 18 #include "mojo/converters/input_events/input_events_type_converters.h"
19 19
20 using mojo::ConnectionSpecificId; 20 using mojo::ConnectionSpecificId;
21 21
22 namespace view_manager { 22 namespace view_manager {
23 namespace { 23 namespace {
24 24
25 // Creates a copy of |view|. The copied view has |delegate| as its delegate. 25 // Creates a copy of |view|. The copied view has |delegate| as its delegate.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for (ServerView* child : view->GetChildren()) { 90 for (ServerView* child : view->GetChildren()) {
91 if (DecrementAnimatingViewsOpacity(child)) 91 if (DecrementAnimatingViewsOpacity(child))
92 ret_value = true; 92 ret_value = true;
93 } 93 }
94 return ret_value; 94 return ret_value;
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 ConnectionManager::ScopedChange::ScopedChange( 99 ConnectionManager::ScopedChange::ScopedChange(
100 ViewManagerServiceImpl* connection, 100 ViewTreeImpl* connection,
101 ConnectionManager* connection_manager, 101 ConnectionManager* connection_manager,
102 bool is_delete_view) 102 bool is_delete_view)
103 : connection_manager_(connection_manager), 103 : connection_manager_(connection_manager),
104 connection_id_(connection->id()), 104 connection_id_(connection->id()),
105 is_delete_view_(is_delete_view) { 105 is_delete_view_(is_delete_view) {
106 connection_manager_->PrepareForChange(this); 106 connection_manager_->PrepareForChange(this);
107 } 107 }
108 108
109 ConnectionManager::ScopedChange::~ScopedChange() { 109 ConnectionManager::ScopedChange::~ScopedChange() {
110 connection_manager_->FinishChange(); 110 connection_manager_->FinishChange();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const uint16_t id = next_root_id_++; 164 const uint16_t id = next_root_id_++;
165 DCHECK_LT(id, next_root_id_); 165 DCHECK_LT(id, next_root_id_);
166 return id; 166 return id;
167 } 167 }
168 168
169 void ConnectionManager::OnConnectionError(ClientConnection* connection) { 169 void ConnectionManager::OnConnectionError(ClientConnection* connection) {
170 // This will be null if the root has been destroyed. 170 // This will be null if the root has been destroyed.
171 const ViewId* view_id = connection->service()->root(); 171 const ViewId* view_id = connection->service()->root();
172 ServerView* view = 172 ServerView* view =
173 view_id ? GetView(*connection->service()->root()) : nullptr; 173 view_id ? GetView(*connection->service()->root()) : nullptr;
174 // If the ViewManagerService root is a viewport root, then we'll wait until 174 // If the ViewTree root is a viewport root, then we'll wait until
175 // the root connection goes away to cleanup. 175 // the root connection goes away to cleanup.
176 if (view && (GetRootView(view) == view)) 176 if (view && (GetRootView(view) == view))
177 return; 177 return;
178 178
179 scoped_ptr<ClientConnection> connection_owner(connection); 179 scoped_ptr<ClientConnection> connection_owner(connection);
180 180
181 connection_map_.erase(connection->service()->id()); 181 connection_map_.erase(connection->service()->id());
182 182
183 // TODO(sky): I may want to advance focus differently if focus is in 183 // TODO(sky): I may want to advance focus differently if focus is in
184 // |connection|. 184 // |connection|.
185 185
186 // Notify remaining connections so that they can cleanup. 186 // Notify remaining connections so that they can cleanup.
187 for (auto& pair : connection_map_) { 187 for (auto& pair : connection_map_) {
188 pair.second->service()->OnWillDestroyViewManagerServiceImpl( 188 pair.second->service()->OnWillDestroyViewTreeImpl(
189 connection->service()); 189 connection->service());
190 } 190 }
191 } 191 }
192 192
193 void ConnectionManager::OnRootConnectionClosed( 193 void ConnectionManager::OnRootConnectionClosed(
194 ViewManagerRootConnection* connection) { 194 ViewManagerRootConnection* connection) {
195 auto it = root_connection_map_.find(connection->view_manager_root()); 195 auto it = root_connection_map_.find(connection->view_manager_root());
196 DCHECK(it != root_connection_map_.end()); 196 DCHECK(it != root_connection_map_.end());
197 197
198 // Clear focus if the focused view is in this viewport. 198 // Clear focus if the focused view is in this viewport.
199 if (GetRootView(GetFocusedView()) == it->first->root_view()) 199 if (GetRootView(GetFocusedView()) == it->first->root_view())
200 SetFocusedView(nullptr); 200 SetFocusedView(nullptr);
201 201
202 // Get the ClientConnection by ViewManagerServiceImpl ID. 202 // Get the ClientConnection by ViewTreeImpl ID.
203 ConnectionMap::iterator service_connection_it = 203 ConnectionMap::iterator service_connection_it =
204 connection_map_.find(it->first->GetViewManagerService()->id()); 204 connection_map_.find(it->first->GetViewTree()->id());
205 DCHECK(service_connection_it != connection_map_.end()); 205 DCHECK(service_connection_it != connection_map_.end());
206 206
207 // Tear down the associated ViewManagerService connection. 207 // Tear down the associated ViewTree connection.
208 // TODO(fsamuel): I don't think this is quite right, we should tear down all 208 // TODO(fsamuel): I don't think this is quite right, we should tear down all
209 // connections within the root's viewport. We should probably employ an 209 // connections within the root's viewport. We should probably employ an
210 // observer pattern to do this. Each ViewManagerServiceImpl should track its 210 // observer pattern to do this. Each ViewTreeImpl should track its
211 // parent's lifetime. 211 // parent's lifetime.
212 root_connection_map_.erase(it); 212 root_connection_map_.erase(it);
213 OnConnectionError(service_connection_it->second); 213 OnConnectionError(service_connection_it->second);
214 214
215 // If we have no more roots left, let the app know so it can terminate. 215 // If we have no more roots left, let the app know so it can terminate.
216 if (!root_connection_map_.size()) 216 if (!root_connection_map_.size())
217 delegate_->OnNoMoreRootConnections(); 217 delegate_->OnNoMoreRootConnections();
218 } 218 }
219 219
220 void ConnectionManager::EmbedAtView(mojo::ConnectionSpecificId creator_id, 220 void ConnectionManager::EmbedAtView(mojo::ConnectionSpecificId creator_id,
221 const ViewId& view_id, 221 const ViewId& view_id,
222 mojo::URLRequestPtr request) { 222 mojo::URLRequestPtr request) {
223 mojo::ViewManagerServicePtr service_ptr; 223 mojo::ViewTreePtr service_ptr;
224 ClientConnection* client_connection = 224 ClientConnection* client_connection =
225 delegate_->CreateClientConnectionForEmbedAtView( 225 delegate_->CreateClientConnectionForEmbedAtView(
226 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id); 226 this, GetProxy(&service_ptr), creator_id, request.Pass(), view_id);
227 AddConnection(client_connection); 227 AddConnection(client_connection);
228 client_connection->service()->Init(client_connection->client(), 228 client_connection->service()->Init(client_connection->client(),
229 service_ptr.Pass()); 229 service_ptr.Pass());
230 OnConnectionMessagedClient(client_connection->service()->id()); 230 OnConnectionMessagedClient(client_connection->service()->id());
231 } 231 }
232 232
233 ViewManagerServiceImpl* ConnectionManager::EmbedAtView( 233 ViewTreeImpl* ConnectionManager::EmbedAtView(
234 mojo::ConnectionSpecificId creator_id, 234 mojo::ConnectionSpecificId creator_id,
235 const ViewId& view_id, 235 const ViewId& view_id,
236 mojo::ViewManagerClientPtr client) { 236 mojo::ViewTreeClientPtr client) {
237 mojo::ViewManagerServicePtr service_ptr; 237 mojo::ViewTreePtr service_ptr;
238 ClientConnection* client_connection = 238 ClientConnection* client_connection =
239 delegate_->CreateClientConnectionForEmbedAtView( 239 delegate_->CreateClientConnectionForEmbedAtView(
240 this, GetProxy(&service_ptr), creator_id, view_id, client.Pass()); 240 this, GetProxy(&service_ptr), creator_id, view_id, client.Pass());
241 AddConnection(client_connection); 241 AddConnection(client_connection);
242 client_connection->service()->Init(client_connection->client(), 242 client_connection->service()->Init(client_connection->client(),
243 service_ptr.Pass()); 243 service_ptr.Pass());
244 OnConnectionMessagedClient(client_connection->service()->id()); 244 OnConnectionMessagedClient(client_connection->service()->id());
245 245
246 return client_connection->service(); 246 return client_connection->service();
247 } 247 }
248 248
249 void ConnectionManager::OnAccelerator(ServerView* root, mojo::EventPtr event) { 249 void ConnectionManager::OnAccelerator(ServerView* root, mojo::EventPtr event) {
250 for (auto& pair : root_connection_map_) { 250 for (auto& pair : root_connection_map_) {
251 if (root == pair.first->root_view()) { 251 if (root == pair.first->root_view()) {
252 pair.first->client()->OnAccelerator(event.Pass()); 252 pair.first->client()->OnAccelerator(event.Pass());
253 return; 253 return;
254 } 254 }
255 } 255 }
256 } 256 }
257 257
258 ViewManagerServiceImpl* ConnectionManager::GetConnection( 258 ViewTreeImpl* ConnectionManager::GetConnection(
259 ConnectionSpecificId connection_id) { 259 ConnectionSpecificId connection_id) {
260 ConnectionMap::iterator i = connection_map_.find(connection_id); 260 ConnectionMap::iterator i = connection_map_.find(connection_id);
261 return i == connection_map_.end() ? nullptr : i->second->service(); 261 return i == connection_map_.end() ? nullptr : i->second->service();
262 } 262 }
263 263
264 ServerView* ConnectionManager::GetView(const ViewId& id) { 264 ServerView* ConnectionManager::GetView(const ViewId& id) {
265 for (auto& pair : root_connection_map_) { 265 for (auto& pair : root_connection_map_) {
266 if (pair.first->root_view()->id() == id) 266 if (pair.first->root_view()->id() == id)
267 return pair.first->root_view(); 267 return pair.first->root_view();
268 } 268 }
269 ViewManagerServiceImpl* service = GetConnection(id.connection_id); 269 ViewTreeImpl* service = GetConnection(id.connection_id);
270 return service ? service->GetView(id) : nullptr; 270 return service ? service->GetView(id) : nullptr;
271 } 271 }
272 272
273 void ConnectionManager::SetFocusedView(ServerView* view) { 273 void ConnectionManager::SetFocusedView(ServerView* view) {
274 if (!focus_controller_) 274 if (!focus_controller_)
275 return; 275 return;
276 ServerView* old_focused = GetFocusedView(); 276 ServerView* old_focused = GetFocusedView();
277 if (old_focused == view) 277 if (old_focused == view)
278 return; 278 return;
279 focus_controller_->SetFocusedView(view); 279 focus_controller_->SetFocusedView(view);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return view_manager_root->GetViewportMetrics().Clone(); 319 return view_manager_root->GetViewportMetrics().Clone();
320 320
321 if (!root_connection_map_.empty()) 321 if (!root_connection_map_.empty())
322 return root_connection_map_.begin()->first->GetViewportMetrics().Clone(); 322 return root_connection_map_.begin()->first->GetViewportMetrics().Clone();
323 323
324 mojo::ViewportMetricsPtr metrics = mojo::ViewportMetrics::New(); 324 mojo::ViewportMetricsPtr metrics = mojo::ViewportMetrics::New();
325 metrics->size_in_pixels = mojo::Size::New(); 325 metrics->size_in_pixels = mojo::Size::New();
326 return metrics.Pass(); 326 return metrics.Pass();
327 } 327 }
328 328
329 const ViewManagerServiceImpl* ConnectionManager::GetConnectionWithRoot( 329 const ViewTreeImpl* ConnectionManager::GetConnectionWithRoot(
330 const ViewId& id) const { 330 const ViewId& id) const {
331 for (auto& pair : connection_map_) { 331 for (auto& pair : connection_map_) {
332 if (pair.second->service()->IsRoot(id)) 332 if (pair.second->service()->IsRoot(id))
333 return pair.second->service(); 333 return pair.second->service();
334 } 334 }
335 return nullptr; 335 return nullptr;
336 } 336 }
337 337
338 ViewManagerServiceImpl* ConnectionManager::GetEmbedRoot( 338 ViewTreeImpl* ConnectionManager::GetEmbedRoot(ViewTreeImpl* service) {
339 ViewManagerServiceImpl* service) {
340 while (service) { 339 while (service) {
341 const ViewId* root_id = service->root(); 340 const ViewId* root_id = service->root();
342 if (!root_id || root_id->connection_id == service->id()) 341 if (!root_id || root_id->connection_id == service->id())
343 return nullptr; 342 return nullptr;
344 343
345 ViewManagerServiceImpl* parent_service = 344 ViewTreeImpl* parent_service = GetConnection(root_id->connection_id);
346 GetConnection(root_id->connection_id);
347 service = parent_service; 345 service = parent_service;
348 if (service && service->is_embed_root()) 346 if (service && service->is_embed_root())
349 return service; 347 return service;
350 } 348 }
351 return nullptr; 349 return nullptr;
352 } 350 }
353 351
354 bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) { 352 bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) {
355 ServerView* view = GetView(view_id); 353 ServerView* view = GetView(view_id);
356 if (!view || !view->IsDrawn() || (view->GetRoot() == view)) 354 if (!view || !view->IsDrawn() || (view->GetRoot() == view))
357 return false; 355 return false;
358 if (!animation_timer_.IsRunning()) { 356 if (!animation_timer_.IsRunning()) {
359 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(100), 357 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(100),
360 this, &ConnectionManager::DoAnimation); 358 this, &ConnectionManager::DoAnimation);
361 } 359 }
362 ServerView* clone = CloneView(view, this); 360 ServerView* clone = CloneView(view, this);
363 CloneViewTree(view, clone, this); 361 CloneViewTree(view, clone, this);
364 view->parent()->Add(clone); 362 view->parent()->Add(clone);
365 view->parent()->Reorder(clone, view, mojo::ORDER_DIRECTION_ABOVE); 363 view->parent()->Reorder(clone, view, mojo::ORDER_DIRECTION_ABOVE);
366 return true; 364 return true;
367 } 365 }
368 366
369 void ConnectionManager::DispatchInputEventToView(const ServerView* view, 367 void ConnectionManager::DispatchInputEventToView(const ServerView* view,
370 mojo::EventPtr event) { 368 mojo::EventPtr event) {
371 // If the view is an embed root, forward to the embedded view, not the owner. 369 // If the view is an embed root, forward to the embedded view, not the owner.
372 ViewManagerServiceImpl* connection = GetConnectionWithRoot(view->id()); 370 ViewTreeImpl* connection = GetConnectionWithRoot(view->id());
373 if (!connection) 371 if (!connection)
374 connection = GetConnection(view->id().connection_id); 372 connection = GetConnection(view->id().connection_id);
375 CHECK(connection); 373 CHECK(connection);
376 connection->client()->OnViewInputEvent(ViewIdToTransportId(view->id()), 374 connection->client()->OnViewInputEvent(ViewIdToTransportId(view->id()),
377 event.Pass(), 375 event.Pass(),
378 base::Bind(&base::DoNothing)); 376 base::Bind(&base::DoNothing));
379 } 377 }
380 378
381 void ConnectionManager::OnEvent(ViewManagerRootImpl* root, 379 void ConnectionManager::OnEvent(ViewManagerRootImpl* root,
382 mojo::EventPtr event) { 380 mojo::EventPtr event) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 648
651 void ConnectionManager::OnFocusChanged(ServerView* old_focused_view, 649 void ConnectionManager::OnFocusChanged(ServerView* old_focused_view,
652 ServerView* new_focused_view) { 650 ServerView* new_focused_view) {
653 // There are up to four connections that need to be notified: 651 // There are up to four connections that need to be notified:
654 // . the connection containing |old_focused_view|. 652 // . the connection containing |old_focused_view|.
655 // . the connection with |old_focused_view| as its root. 653 // . the connection with |old_focused_view| as its root.
656 // . the connection containing |new_focused_view|. 654 // . the connection containing |new_focused_view|.
657 // . the connection with |new_focused_view| as its root. 655 // . the connection with |new_focused_view| as its root.
658 // Some of these connections may be the same. The following takes care to 656 // Some of these connections may be the same. The following takes care to
659 // notify each only once. 657 // notify each only once.
660 ViewManagerServiceImpl* owning_connection_old = nullptr; 658 ViewTreeImpl* owning_connection_old = nullptr;
661 ViewManagerServiceImpl* embedded_connection_old = nullptr; 659 ViewTreeImpl* embedded_connection_old = nullptr;
662 660
663 if (old_focused_view) { 661 if (old_focused_view) {
664 owning_connection_old = GetConnection(old_focused_view->id().connection_id); 662 owning_connection_old = GetConnection(old_focused_view->id().connection_id);
665 if (owning_connection_old) { 663 if (owning_connection_old) {
666 owning_connection_old->ProcessFocusChanged(old_focused_view, 664 owning_connection_old->ProcessFocusChanged(old_focused_view,
667 new_focused_view); 665 new_focused_view);
668 } 666 }
669 embedded_connection_old = GetConnectionWithRoot(old_focused_view->id()); 667 embedded_connection_old = GetConnectionWithRoot(old_focused_view->id());
670 if (embedded_connection_old) { 668 if (embedded_connection_old) {
671 DCHECK_NE(owning_connection_old, embedded_connection_old); 669 DCHECK_NE(owning_connection_old, embedded_connection_old);
672 embedded_connection_old->ProcessFocusChanged(old_focused_view, 670 embedded_connection_old->ProcessFocusChanged(old_focused_view,
673 new_focused_view); 671 new_focused_view);
674 } 672 }
675 } 673 }
676 ViewManagerServiceImpl* owning_connection_new = nullptr; 674 ViewTreeImpl* owning_connection_new = nullptr;
677 ViewManagerServiceImpl* embedded_connection_new = nullptr; 675 ViewTreeImpl* embedded_connection_new = nullptr;
678 if (new_focused_view) { 676 if (new_focused_view) {
679 owning_connection_new = GetConnection(new_focused_view->id().connection_id); 677 owning_connection_new = GetConnection(new_focused_view->id().connection_id);
680 if (owning_connection_new && 678 if (owning_connection_new &&
681 owning_connection_new != owning_connection_old && 679 owning_connection_new != owning_connection_old &&
682 owning_connection_new != embedded_connection_old) { 680 owning_connection_new != embedded_connection_old) {
683 owning_connection_new->ProcessFocusChanged(old_focused_view, 681 owning_connection_new->ProcessFocusChanged(old_focused_view,
684 new_focused_view); 682 new_focused_view);
685 } 683 }
686 embedded_connection_new = GetConnectionWithRoot(new_focused_view->id()); 684 embedded_connection_new = GetConnectionWithRoot(new_focused_view->id());
687 if (embedded_connection_new && 685 if (embedded_connection_new &&
688 embedded_connection_new != owning_connection_old && 686 embedded_connection_new != owning_connection_old &&
689 embedded_connection_new != embedded_connection_old) { 687 embedded_connection_new != embedded_connection_old) {
690 DCHECK_NE(owning_connection_new, embedded_connection_new); 688 DCHECK_NE(owning_connection_new, embedded_connection_new);
691 embedded_connection_new->ProcessFocusChanged(old_focused_view, 689 embedded_connection_new->ProcessFocusChanged(old_focused_view,
692 new_focused_view); 690 new_focused_view);
693 } 691 }
694 } 692 }
695 693
696 for (auto& pair : root_connection_map_) { 694 for (auto& pair : root_connection_map_) {
697 ViewManagerServiceImpl* service = pair.first->GetViewManagerService(); 695 ViewTreeImpl* service = pair.first->GetViewTree();
698 if (service != owning_connection_old && 696 if (service != owning_connection_old &&
699 service != embedded_connection_old && 697 service != embedded_connection_old &&
700 service != owning_connection_new && 698 service != owning_connection_new &&
701 service != embedded_connection_new) { 699 service != embedded_connection_new) {
702 service->ProcessFocusChanged(old_focused_view, new_focused_view); 700 service->ProcessFocusChanged(old_focused_view, new_focused_view);
703 } 701 }
704 } 702 }
705 703
706 ViewManagerRootImpl* old_view_manager_root = 704 ViewManagerRootImpl* old_view_manager_root =
707 old_focused_view ? GetViewManagerRootByView(old_focused_view) : nullptr; 705 old_focused_view ? GetViewManagerRootByView(old_focused_view) : nullptr;
708 706
709 ViewManagerRootImpl* new_view_manager_root = 707 ViewManagerRootImpl* new_view_manager_root =
710 new_focused_view ? GetViewManagerRootByView(new_focused_view) : nullptr; 708 new_focused_view ? GetViewManagerRootByView(new_focused_view) : nullptr;
711 709
712 if (new_view_manager_root) { 710 if (new_view_manager_root) {
713 new_view_manager_root->UpdateTextInputState( 711 new_view_manager_root->UpdateTextInputState(
714 new_focused_view->text_input_state()); 712 new_focused_view->text_input_state());
715 } else if (old_view_manager_root) { 713 } else if (old_view_manager_root) {
716 old_view_manager_root->UpdateTextInputState(ui::TextInputState()); 714 old_view_manager_root->UpdateTextInputState(ui::TextInputState());
717 } 715 }
718 } 716 }
719 717
720 } // namespace view_manager 718 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/connection_manager.h ('k') | components/view_manager/connection_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698