Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "services/view_manager/connection_manager.h" | 5 #include "services/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 "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 connection_manager_->FinishChange(); | 109 connection_manager_->FinishChange(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate, | 112 ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate, |
| 113 scoped_ptr<DisplayManager> display_manager, | 113 scoped_ptr<DisplayManager> display_manager, |
| 114 mojo::WindowManagerInternal* wm_internal) | 114 mojo::WindowManagerInternal* wm_internal) |
| 115 : delegate_(delegate), | 115 : delegate_(delegate), |
| 116 window_manager_client_connection_(nullptr), | 116 window_manager_client_connection_(nullptr), |
| 117 next_connection_id_(1), | 117 next_connection_id_(1), |
| 118 display_manager_(display_manager.Pass()), | 118 display_manager_(display_manager.Pass()), |
| 119 root_(new ServerView(this, RootViewId())), | 119 root_(CreateServerView(RootViewId())), |
| 120 wm_internal_(wm_internal), | 120 wm_internal_(wm_internal), |
| 121 current_change_(nullptr), | 121 current_change_(nullptr), |
| 122 in_destructor_(false), | 122 in_destructor_(false), |
| 123 animation_runner_(base::TimeTicks::Now()) { | 123 animation_runner_(base::TimeTicks::Now()) { |
| 124 root_->SetBounds(gfx::Rect(800, 600)); | 124 root_->SetBounds(gfx::Rect(800, 600)); |
| 125 root_->SetVisible(true); | 125 root_->SetVisible(true); |
| 126 display_manager_->Init(this); | 126 display_manager_->Init(this); |
| 127 } | 127 } |
| 128 | 128 |
| 129 ConnectionManager::~ConnectionManager() { | 129 ConnectionManager::~ConnectionManager() { |
| 130 in_destructor_ = true; | 130 in_destructor_ = true; |
| 131 | 131 |
| 132 STLDeleteValues(&connection_map_); | 132 STLDeleteValues(&connection_map_); |
| 133 // All the connections should have been destroyed. | 133 // All the connections should have been destroyed. |
| 134 DCHECK(connection_map_.empty()); | 134 DCHECK(connection_map_.empty()); |
| 135 root_.reset(); | 135 root_.reset(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 ServerView* ConnectionManager::CreateServerView(const ViewId& id) { | |
| 139 ServerView* view = new ServerView(this, id); | |
| 140 view->AddObserver(this); | |
| 141 return view; | |
| 142 } | |
| 143 | |
| 138 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() { | 144 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() { |
| 139 const ConnectionSpecificId id = next_connection_id_++; | 145 const ConnectionSpecificId id = next_connection_id_++; |
| 140 DCHECK_LT(id, next_connection_id_); | 146 DCHECK_LT(id, next_connection_id_); |
| 141 return id; | 147 return id; |
| 142 } | 148 } |
| 143 | 149 |
| 144 void ConnectionManager::OnConnectionError(ClientConnection* connection) { | 150 void ConnectionManager::OnConnectionError(ClientConnection* connection) { |
| 145 if (connection == window_manager_client_connection_) { | 151 if (connection == window_manager_client_connection_) { |
| 146 window_manager_client_connection_ = nullptr; | 152 window_manager_client_connection_ = nullptr; |
| 147 delegate_->OnLostConnectionToWindowManager(); | 153 delegate_->OnLostConnectionToWindowManager(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 void ConnectionManager::DoAnimation() { | 339 void ConnectionManager::DoAnimation() { |
| 334 if (!DecrementAnimatingViewsOpacity(root())) | 340 if (!DecrementAnimatingViewsOpacity(root())) |
| 335 animation_timer_.Stop(); | 341 animation_timer_.Stop(); |
| 336 } | 342 } |
| 337 | 343 |
| 338 void ConnectionManager::AddConnection(ClientConnection* connection) { | 344 void ConnectionManager::AddConnection(ClientConnection* connection) { |
| 339 DCHECK_EQ(0u, connection_map_.count(connection->service()->id())); | 345 DCHECK_EQ(0u, connection_map_.count(connection->service()->id())); |
| 340 connection_map_[connection->service()->id()] = connection; | 346 connection_map_[connection->service()->id()] = connection; |
| 341 } | 347 } |
| 342 | 348 |
| 343 void ConnectionManager::OnWillDestroyView(ServerView* view) { | 349 void ConnectionManager::PrepareToDestroyView(ServerView* view) { |
| 344 if (!in_destructor_ && root_->Contains(view) && view != root_.get() && | 350 if (!in_destructor_ && root_->Contains(view) && view != root_.get() && |
| 345 view->id() != ClonedViewId()) { | 351 view->id() != ClonedViewId()) { |
| 346 // We're about to destroy a view. Any cloned views need to be reparented | 352 // We're about to destroy a view. Any cloned views need to be reparented |
| 347 // else the animation would no longer be visible. By moving to a visible | 353 // else the animation would no longer be visible. By moving to a visible |
| 348 // view, view->parent(), we ensure the animation is still visible. | 354 // view, view->parent(), we ensure the animation is still visible. |
| 349 ServerView* parent_above = view; | 355 ServerView* parent_above = view; |
| 350 ReparentClonedViews(view->parent(), &parent_above, view); | 356 ReparentClonedViews(view->parent(), &parent_above, view); |
| 351 } | 357 } |
| 352 | 358 |
| 353 animation_runner_.CancelAnimationForView(view); | 359 animation_runner_.CancelAnimationForView(view); |
| 354 } | 360 } |
| 355 | 361 |
| 356 void ConnectionManager::OnViewDestroyed(const ServerView* view) { | 362 void ConnectionManager::PrepareToChangeViewHierarchy(ServerView* view, |
| 357 if (!in_destructor_) | 363 ServerView* new_parent, |
| 358 ProcessViewDeleted(view->id()); | 364 ServerView* old_parent) { |
| 359 } | |
| 360 | |
| 361 void ConnectionManager::OnWillChangeViewHierarchy(ServerView* view, | |
| 362 ServerView* new_parent, | |
| 363 ServerView* old_parent) { | |
| 364 if (view->id() == ClonedViewId() || in_destructor_) | 365 if (view->id() == ClonedViewId() || in_destructor_) |
| 365 return; | 366 return; |
| 366 | 367 |
| 367 if (root_->Contains(view) && view != root_.get()) { | 368 if (root_->Contains(view) && view != root_.get()) { |
| 368 // We're about to reparent a view. Any cloned views need to be reparented | 369 // We're about to reparent a view. Any cloned views need to be reparented |
| 369 // else the animation may be effected in unusual ways. For example, the view | 370 // else the animation may be effected in unusual ways. For example, the view |
| 370 // could move to a new location such that the animation is entirely clipped. | 371 // could move to a new location such that the animation is entirely clipped. |
| 371 // By moving to view->parent() we ensure the animation is still visible. | 372 // By moving to view->parent() we ensure the animation is still visible. |
| 372 ServerView* parent_above = view; | 373 ServerView* parent_above = view; |
| 373 ReparentClonedViews(view->parent(), &parent_above, view); | 374 ReparentClonedViews(view->parent(), &parent_above, view); |
| 374 } | 375 } |
| 375 | 376 |
| 377 animation_runner_.CancelAnimationForView(view); | |
| 378 } | |
| 379 | |
| 380 void ConnectionManager::PrepareToChangeViewVisibility(ServerView* view) { | |
| 381 if (in_destructor_) | |
| 382 return; | |
| 383 | |
| 384 if (view != root_.get() && view->id() != ClonedViewId() && | |
| 385 root_->Contains(view) && view->IsDrawn(root_.get())) { | |
| 386 // We're about to hide |view|, this would implicitly make any cloned views | |
| 387 // hide to. Reparent so that animations are still visible. | |
|
Ben Goodger (Google)
2015/04/13 23:09:00
hide too
| |
| 388 ServerView* parent_above = view; | |
| 389 ReparentClonedViews(view->parent(), &parent_above, view); | |
| 390 } | |
| 391 | |
| 392 const bool is_parent_drawn = | |
| 393 view->parent() && view->parent()->IsDrawn(root_.get()); | |
| 394 if (!is_parent_drawn || !view->visible()) | |
| 395 animation_runner_.CancelAnimationForView(view); | |
| 396 } | |
| 397 | |
| 398 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { | |
| 399 if (!in_destructor_) | |
| 400 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | |
| 401 } | |
| 402 | |
| 403 void ConnectionManager::OnViewDestroyed(const ServerView* view) { | |
| 404 if (!in_destructor_) | |
| 405 ProcessViewDeleted(view->id()); | |
| 406 } | |
| 407 | |
| 408 void ConnectionManager::OnWillChangeViewHierarchy( | |
| 409 const ServerView* view, | |
| 410 const ServerView* new_parent, | |
| 411 const ServerView* old_parent) { | |
| 412 if (view->id() == ClonedViewId() || in_destructor_) | |
| 413 return; | |
| 414 | |
| 376 ProcessWillChangeViewHierarchy(view, new_parent, old_parent); | 415 ProcessWillChangeViewHierarchy(view, new_parent, old_parent); |
| 377 | |
| 378 animation_runner_.CancelAnimationForView(view); | |
| 379 } | 416 } |
| 380 | 417 |
| 381 void ConnectionManager::OnViewHierarchyChanged(const ServerView* view, | 418 void ConnectionManager::OnViewHierarchyChanged(const ServerView* view, |
| 382 const ServerView* new_parent, | 419 const ServerView* new_parent, |
| 383 const ServerView* old_parent) { | 420 const ServerView* old_parent) { |
| 384 if (in_destructor_) | 421 if (in_destructor_) |
| 385 return; | 422 return; |
| 386 | 423 |
| 387 ProcessViewHierarchyChanged(view, new_parent, old_parent); | 424 ProcessViewHierarchyChanged(view, new_parent, old_parent); |
| 388 | 425 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 405 | 442 |
| 406 ProcessViewBoundsChanged(view, old_bounds, new_bounds); | 443 ProcessViewBoundsChanged(view, old_bounds, new_bounds); |
| 407 if (!view->parent()) | 444 if (!view->parent()) |
| 408 return; | 445 return; |
| 409 | 446 |
| 410 // TODO(sky): optimize this. | 447 // TODO(sky): optimize this. |
| 411 display_manager_->SchedulePaint(view->parent(), old_bounds); | 448 display_manager_->SchedulePaint(view->parent(), old_bounds); |
| 412 display_manager_->SchedulePaint(view->parent(), new_bounds); | 449 display_manager_->SchedulePaint(view->parent(), new_bounds); |
| 413 } | 450 } |
| 414 | 451 |
| 415 void ConnectionManager::OnViewSurfaceIdChanged(const ServerView* view) { | |
| 416 if (!in_destructor_) | |
| 417 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | |
| 418 } | |
| 419 | |
| 420 void ConnectionManager::OnViewReordered(const ServerView* view, | 452 void ConnectionManager::OnViewReordered(const ServerView* view, |
| 421 const ServerView* relative, | 453 const ServerView* relative, |
| 422 mojo::OrderDirection direction) { | 454 mojo::OrderDirection direction) { |
| 423 if (!in_destructor_) | 455 if (!in_destructor_) |
| 424 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | 456 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 425 } | 457 } |
| 426 | 458 |
| 427 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { | 459 void ConnectionManager::OnWillChangeViewVisibility(const ServerView* view) { |
| 428 if (in_destructor_) | 460 if (in_destructor_) |
| 429 return; | 461 return; |
| 430 | 462 |
| 431 // Need to repaint if the view was drawn (which means it'll in the process of | 463 // Need to repaint if the view was drawn (which means it's in the process of |
| 432 // hiding) or the view is transitioning to drawn. | 464 // hiding) or the view is transitioning to drawn. |
| 433 if (view->IsDrawn(root_.get()) || (!view->visible() && view->parent() && | 465 if (view->IsDrawn(root_.get()) || (!view->visible() && view->parent() && |
| 434 view->parent()->IsDrawn(root_.get()))) { | 466 view->parent()->IsDrawn(root_.get()))) { |
| 435 display_manager_->SchedulePaint(view->parent(), view->bounds()); | 467 display_manager_->SchedulePaint(view->parent(), view->bounds()); |
| 436 } | 468 } |
| 437 | 469 |
| 438 if (view != root_.get() && view->id() != ClonedViewId() && | |
| 439 root_->Contains(view) && view->IsDrawn(root_.get())) { | |
| 440 // We're about to hide |view|, this would implicitly make any cloned views | |
| 441 // hide to. Reparent so that animations are still visible. | |
| 442 ServerView* parent_above = view; | |
| 443 ReparentClonedViews(view->parent(), &parent_above, view); | |
| 444 } | |
| 445 | |
| 446 for (auto& pair : connection_map_) { | 470 for (auto& pair : connection_map_) { |
| 447 pair.second->service()->ProcessWillChangeViewVisibility( | 471 pair.second->service()->ProcessWillChangeViewVisibility( |
| 448 view, IsChangeSource(pair.first)); | 472 view, IsChangeSource(pair.first)); |
| 449 } | 473 } |
| 450 | |
| 451 const bool is_parent_drawn = | |
| 452 view->parent() && view->parent()->IsDrawn(root_.get()); | |
| 453 if (!is_parent_drawn || !view->visible()) | |
| 454 animation_runner_.CancelAnimationForView(view); | |
| 455 } | 474 } |
| 456 | 475 |
| 457 void ConnectionManager::OnViewSharedPropertyChanged( | 476 void ConnectionManager::OnViewSharedPropertyChanged( |
| 458 const ServerView* view, | 477 const ServerView* view, |
| 459 const std::string& name, | 478 const std::string& name, |
| 460 const std::vector<uint8_t>* new_data) { | 479 const std::vector<uint8_t>* new_data) { |
| 461 for (auto& pair : connection_map_) { | 480 for (auto& pair : connection_map_) { |
| 462 pair.second->service()->ProcessViewPropertyChanged( | 481 pair.second->service()->ProcessViewPropertyChanged( |
| 463 view, name, new_data, IsChangeSource(pair.first)); | 482 view, name, new_data, IsChangeSource(pair.first)); |
| 464 } | 483 } |
| 465 } | 484 } |
| 466 | 485 |
| 467 void ConnectionManager::OnScheduleViewPaint(const ServerView* view) { | |
| 468 if (!in_destructor_) | |
| 469 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | |
| 470 } | |
| 471 | |
| 472 void ConnectionManager::DispatchInputEventToView(mojo::Id transport_view_id, | 486 void ConnectionManager::DispatchInputEventToView(mojo::Id transport_view_id, |
| 473 mojo::EventPtr event) { | 487 mojo::EventPtr event) { |
| 474 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 488 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 475 | 489 |
| 476 ViewManagerServiceImpl* connection = GetConnectionWithRoot(view_id); | 490 ViewManagerServiceImpl* connection = GetConnectionWithRoot(view_id); |
| 477 if (!connection) | 491 if (!connection) |
| 478 connection = GetConnection(view_id.connection_id); | 492 connection = GetConnection(view_id.connection_id); |
| 479 if (connection) { | 493 if (connection) { |
| 480 connection->client()->OnViewInputEvent( | 494 connection->client()->OnViewInputEvent( |
| 481 transport_view_id, event.Pass(), base::Bind(&base::DoNothing)); | 495 transport_view_id, event.Pass(), base::Bind(&base::DoNothing)); |
| 482 } | 496 } |
| 483 } | 497 } |
| 484 | 498 |
| 485 void ConnectionManager::SetViewportSize(mojo::SizePtr size) { | 499 void ConnectionManager::SetViewportSize(mojo::SizePtr size) { |
| 486 gfx::Size new_size = size.To<gfx::Size>(); | 500 gfx::Size new_size = size.To<gfx::Size>(); |
| 487 display_manager_->SetViewportSize(new_size); | 501 display_manager_->SetViewportSize(new_size); |
| 488 } | 502 } |
| 489 | 503 |
| 490 void ConnectionManager::CloneAndAnimate(mojo::Id transport_view_id) { | 504 void ConnectionManager::CloneAndAnimate(mojo::Id transport_view_id) { |
| 491 CloneAndAnimate(ViewIdFromTransportId(transport_view_id)); | 505 CloneAndAnimate(ViewIdFromTransportId(transport_view_id)); |
| 492 } | 506 } |
| 493 | 507 |
| 494 } // namespace view_manager | 508 } // namespace view_manager |
| OLD | NEW |