| 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 "mojo/services/view_manager/connection_manager.h" | 5 #include "mojo/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 |
| 376 ProcessWillChangeViewHierarchy(view, new_parent, old_parent); | |
| 377 | |
| 378 animation_runner_.CancelAnimationForView(view); | 377 animation_runner_.CancelAnimationForView(view); |
| 379 } | 378 } |
| 380 | 379 |
| 381 void ConnectionManager::OnViewHierarchyChanged(const ServerView* view, | 380 void ConnectionManager::PrepareToChangeViewVisibility(ServerView* view) { |
| 382 const ServerView* new_parent, | |
| 383 const ServerView* old_parent) { | |
| 384 if (in_destructor_) | 381 if (in_destructor_) |
| 385 return; | 382 return; |
| 386 | 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 too. Reparent so that animations are still visible. |
| 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(ServerView* view) { |
| 404 if (!in_destructor_) |
| 405 ProcessViewDeleted(view->id()); |
| 406 } |
| 407 |
| 408 void ConnectionManager::OnWillChangeViewHierarchy(ServerView* view, |
| 409 ServerView* new_parent, |
| 410 ServerView* old_parent) { |
| 411 if (view->id() == ClonedViewId() || in_destructor_) |
| 412 return; |
| 413 |
| 414 ProcessWillChangeViewHierarchy(view, new_parent, old_parent); |
| 415 } |
| 416 |
| 417 void ConnectionManager::OnViewHierarchyChanged(ServerView* view, |
| 418 ServerView* new_parent, |
| 419 ServerView* old_parent) { |
| 420 if (in_destructor_) |
| 421 return; |
| 422 |
| 387 ProcessViewHierarchyChanged(view, new_parent, old_parent); | 423 ProcessViewHierarchyChanged(view, new_parent, old_parent); |
| 388 | 424 |
| 389 // TODO(beng): optimize. | 425 // TODO(beng): optimize. |
| 390 if (old_parent) { | 426 if (old_parent) { |
| 391 display_manager_->SchedulePaint(old_parent, | 427 display_manager_->SchedulePaint(old_parent, |
| 392 gfx::Rect(old_parent->bounds().size())); | 428 gfx::Rect(old_parent->bounds().size())); |
| 393 } | 429 } |
| 394 if (new_parent) { | 430 if (new_parent) { |
| 395 display_manager_->SchedulePaint(new_parent, | 431 display_manager_->SchedulePaint(new_parent, |
| 396 gfx::Rect(new_parent->bounds().size())); | 432 gfx::Rect(new_parent->bounds().size())); |
| 397 } | 433 } |
| 398 } | 434 } |
| 399 | 435 |
| 400 void ConnectionManager::OnViewBoundsChanged(const ServerView* view, | 436 void ConnectionManager::OnViewBoundsChanged(ServerView* view, |
| 401 const gfx::Rect& old_bounds, | 437 const gfx::Rect& old_bounds, |
| 402 const gfx::Rect& new_bounds) { | 438 const gfx::Rect& new_bounds) { |
| 403 if (in_destructor_) | 439 if (in_destructor_) |
| 404 return; | 440 return; |
| 405 | 441 |
| 406 ProcessViewBoundsChanged(view, old_bounds, new_bounds); | 442 ProcessViewBoundsChanged(view, old_bounds, new_bounds); |
| 407 if (!view->parent()) | 443 if (!view->parent()) |
| 408 return; | 444 return; |
| 409 | 445 |
| 410 // TODO(sky): optimize this. | 446 // TODO(sky): optimize this. |
| 411 display_manager_->SchedulePaint(view->parent(), old_bounds); | 447 display_manager_->SchedulePaint(view->parent(), old_bounds); |
| 412 display_manager_->SchedulePaint(view->parent(), new_bounds); | 448 display_manager_->SchedulePaint(view->parent(), new_bounds); |
| 413 } | 449 } |
| 414 | 450 |
| 415 void ConnectionManager::OnViewSurfaceIdChanged(const ServerView* view) { | 451 void ConnectionManager::OnViewReordered(ServerView* view, |
| 416 if (!in_destructor_) | 452 ServerView* relative, |
| 417 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | |
| 418 } | |
| 419 | |
| 420 void ConnectionManager::OnViewReordered(const ServerView* view, | |
| 421 const ServerView* relative, | |
| 422 mojo::OrderDirection direction) { | 453 mojo::OrderDirection direction) { |
| 423 if (!in_destructor_) | 454 if (!in_destructor_) |
| 424 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); | 455 display_manager_->SchedulePaint(view, gfx::Rect(view->bounds().size())); |
| 425 } | 456 } |
| 426 | 457 |
| 427 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { | 458 void ConnectionManager::OnWillChangeViewVisibility(ServerView* view) { |
| 428 if (in_destructor_) | 459 if (in_destructor_) |
| 429 return; | 460 return; |
| 430 | 461 |
| 431 // Need to repaint if the view was drawn (which means it'll in the process of | 462 // 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. | 463 // hiding) or the view is transitioning to drawn. |
| 433 if (view->IsDrawn(root_.get()) || (!view->visible() && view->parent() && | 464 if (view->IsDrawn(root_.get()) || (!view->visible() && view->parent() && |
| 434 view->parent()->IsDrawn(root_.get()))) { | 465 view->parent()->IsDrawn(root_.get()))) { |
| 435 display_manager_->SchedulePaint(view->parent(), view->bounds()); | 466 display_manager_->SchedulePaint(view->parent(), view->bounds()); |
| 436 } | 467 } |
| 437 | 468 |
| 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_) { | 469 for (auto& pair : connection_map_) { |
| 447 pair.second->service()->ProcessWillChangeViewVisibility( | 470 pair.second->service()->ProcessWillChangeViewVisibility( |
| 448 view, IsChangeSource(pair.first)); | 471 view, IsChangeSource(pair.first)); |
| 449 } | 472 } |
| 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 } | 473 } |
| 456 | 474 |
| 457 void ConnectionManager::OnViewSharedPropertyChanged( | 475 void ConnectionManager::OnViewSharedPropertyChanged( |
| 458 const ServerView* view, | 476 ServerView* view, |
| 459 const std::string& name, | 477 const std::string& name, |
| 460 const std::vector<uint8_t>* new_data) { | 478 const std::vector<uint8_t>* new_data) { |
| 461 for (auto& pair : connection_map_) { | 479 for (auto& pair : connection_map_) { |
| 462 pair.second->service()->ProcessViewPropertyChanged( | 480 pair.second->service()->ProcessViewPropertyChanged( |
| 463 view, name, new_data, IsChangeSource(pair.first)); | 481 view, name, new_data, IsChangeSource(pair.first)); |
| 464 } | 482 } |
| 465 } | 483 } |
| 466 | 484 |
| 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, | 485 void ConnectionManager::DispatchInputEventToView(mojo::Id transport_view_id, |
| 473 mojo::EventPtr event) { | 486 mojo::EventPtr event) { |
| 474 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 487 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 475 | 488 |
| 476 ViewManagerServiceImpl* connection = GetConnectionWithRoot(view_id); | 489 ViewManagerServiceImpl* connection = GetConnectionWithRoot(view_id); |
| 477 if (!connection) | 490 if (!connection) |
| 478 connection = GetConnection(view_id.connection_id); | 491 connection = GetConnection(view_id.connection_id); |
| 479 if (connection) { | 492 if (connection) { |
| 480 connection->client()->OnViewInputEvent( | 493 connection->client()->OnViewInputEvent( |
| 481 transport_view_id, event.Pass(), base::Bind(&base::DoNothing)); | 494 transport_view_id, event.Pass(), base::Bind(&base::DoNothing)); |
| 482 } | 495 } |
| 483 } | 496 } |
| 484 | 497 |
| 485 void ConnectionManager::SetViewportSize(mojo::SizePtr size) { | 498 void ConnectionManager::SetViewportSize(mojo::SizePtr size) { |
| 486 gfx::Size new_size = size.To<gfx::Size>(); | 499 gfx::Size new_size = size.To<gfx::Size>(); |
| 487 display_manager_->SetViewportSize(new_size); | 500 display_manager_->SetViewportSize(new_size); |
| 488 } | 501 } |
| 489 | 502 |
| 490 void ConnectionManager::CloneAndAnimate(mojo::Id transport_view_id) { | 503 void ConnectionManager::CloneAndAnimate(mojo::Id transport_view_id) { |
| 491 CloneAndAnimate(ViewIdFromTransportId(transport_view_id)); | 504 CloneAndAnimate(ViewIdFromTransportId(transport_view_id)); |
| 492 } | 505 } |
| 493 | 506 |
| 494 } // namespace view_manager | 507 } // namespace view_manager |
| OLD | NEW |