Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "cc/animation/animation_registrar.h" | 9 #include "cc/animation/animation_registrar.h" |
| 10 #include "cc/animation/scrollbar_animation_controller.h" | 10 #include "cc/animation/scrollbar_animation_controller.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 : parent_(NULL), | 32 : parent_(NULL), |
| 33 scroll_parent_(NULL), | 33 scroll_parent_(NULL), |
| 34 clip_parent_(NULL), | 34 clip_parent_(NULL), |
| 35 mask_layer_id_(-1), | 35 mask_layer_id_(-1), |
| 36 replica_layer_id_(-1), | 36 replica_layer_id_(-1), |
| 37 layer_id_(id), | 37 layer_id_(id), |
| 38 layer_tree_impl_(tree_impl), | 38 layer_tree_impl_(tree_impl), |
| 39 anchor_point_(0.5f, 0.5f), | 39 anchor_point_(0.5f, 0.5f), |
| 40 anchor_point_z_(0.f), | 40 anchor_point_z_(0.f), |
| 41 scroll_offset_delegate_(NULL), | 41 scroll_offset_delegate_(NULL), |
| 42 scrollable_(false), | 42 clip_layer_(NULL), |
| 43 should_scroll_on_main_thread_(false), | 43 should_scroll_on_main_thread_(false), |
| 44 have_wheel_event_handlers_(false), | 44 have_wheel_event_handlers_(false), |
| 45 user_scrollable_horizontal_(true), | 45 user_scrollable_horizontal_(true), |
| 46 user_scrollable_vertical_(true), | 46 user_scrollable_vertical_(true), |
| 47 background_color_(0), | 47 background_color_(0), |
| 48 stacking_order_changed_(false), | 48 stacking_order_changed_(false), |
| 49 double_sided_(true), | 49 double_sided_(true), |
| 50 layer_property_changed_(false), | 50 layer_property_changed_(false), |
| 51 masks_to_bounds_(false), | 51 masks_to_bounds_(false), |
| 52 contents_opaque_(false), | 52 contents_opaque_(false), |
| 53 opacity_(1.0), | 53 opacity_(1.0), |
| 54 preserves_3d_(false), | 54 preserves_3d_(false), |
| 55 use_parent_backface_visibility_(false), | 55 use_parent_backface_visibility_(false), |
| 56 draw_checkerboard_for_missing_tiles_(false), | 56 draw_checkerboard_for_missing_tiles_(false), |
| 57 draws_content_(false), | 57 draws_content_(false), |
| 58 hide_layer_and_subtree_(false), | 58 hide_layer_and_subtree_(false), |
| 59 force_render_surface_(false), | 59 force_render_surface_(false), |
| 60 is_container_for_fixed_position_layers_(false), | 60 is_container_for_fixed_position_layers_(false), |
| 61 draw_depth_(0.f), | 61 draw_depth_(0.f), |
| 62 compositing_reasons_(kCompositingReasonUnknown), | 62 compositing_reasons_(kCompositingReasonUnknown), |
| 63 current_draw_mode_(DRAW_MODE_NONE), | 63 current_draw_mode_(DRAW_MODE_NONE) { |
| 64 horizontal_scrollbar_layer_(NULL), | |
| 65 vertical_scrollbar_layer_(NULL) { | |
| 66 DCHECK_GT(layer_id_, 0); | 64 DCHECK_GT(layer_id_, 0); |
| 67 DCHECK(layer_tree_impl_); | 65 DCHECK(layer_tree_impl_); |
| 68 layer_tree_impl_->RegisterLayer(this); | 66 layer_tree_impl_->RegisterLayer(this); |
| 69 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); | 67 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); |
| 70 layer_animation_controller_ = | 68 layer_animation_controller_ = |
| 71 registrar->GetAnimationControllerForId(layer_id_); | 69 registrar->GetAnimationControllerForId(layer_id_); |
| 72 layer_animation_controller_->AddValueObserver(this); | 70 layer_animation_controller_->AddValueObserver(this); |
| 73 } | 71 } |
| 74 | 72 |
| 75 LayerImpl::~LayerImpl() { | 73 LayerImpl::~LayerImpl() { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 if (!user_scrollable_horizontal_) { | 345 if (!user_scrollable_horizontal_) { |
| 348 scroll_hidden.set_x(scroll.x()); | 346 scroll_hidden.set_x(scroll.x()); |
| 349 scroll.set_x(0.f); | 347 scroll.set_x(0.f); |
| 350 } | 348 } |
| 351 if (!user_scrollable_vertical_) { | 349 if (!user_scrollable_vertical_) { |
| 352 scroll_hidden.set_y(scroll.y()); | 350 scroll_hidden.set_y(scroll.y()); |
| 353 scroll.set_y(0.f); | 351 scroll.set_y(0.f); |
| 354 } | 352 } |
| 355 | 353 |
| 356 gfx::Vector2dF min_delta = -scroll_offset_; | 354 gfx::Vector2dF min_delta = -scroll_offset_; |
| 357 gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_; | 355 gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_; |
| 358 // Clamp new_delta so that position + delta stays within scroll bounds. | 356 // Clamp new_delta so that position + delta stays within scroll bounds. |
| 359 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); | 357 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); |
| 360 new_delta.SetToMax(min_delta); | 358 new_delta.SetToMax(min_delta); |
| 361 new_delta.SetToMin(max_delta); | 359 new_delta.SetToMin(max_delta); |
| 362 gfx::Vector2dF unscrolled = | 360 gfx::Vector2dF unscrolled = |
| 363 ScrollDelta() + scroll + scroll_hidden - new_delta; | 361 ScrollDelta() + scroll + scroll_hidden - new_delta; |
| 364 SetScrollDelta(new_delta); | 362 SetScrollDelta(new_delta); |
| 363 /* | |
| 364 if (this == layer_tree_impl()->OuterViewportScrollLayer() || | |
| 365 this == layer_tree_impl()->InnerViewportScrollLayer()) { | |
| 366 gfx::Vector2dF max = MaxScrollOffset(); | |
| 367 fprintf(stderr, "wjm: LayerImpl::ScrollBy(%p, %f, %f), unscrolled = (%f,%f)" | |
| 368 ", offset = (%d,%d), max = (%f,%f), delta = (%f,%f)\n", | |
| 369 this, scroll.x(), scroll.y(), unscrolled.x(), unscrolled.y(), | |
| 370 scroll_offset_.x(), scroll_offset_.y(), max.x(), max.y(), | |
| 371 new_delta.x(), new_delta.y()); | |
| 372 } | |
| 373 */ | |
| 365 return unscrolled; | 374 return unscrolled; |
| 366 } | 375 } |
| 367 | 376 |
| 377 void LayerImpl::SetScrollable(int clip_layer_id) { | |
|
enne (OOO)
2013/10/31 18:45:58
SetScrollable => SetClipLayerId, or possibly just
wjmaclean
2013/11/13 21:01:29
Sure, we could re-name it to SetClipLayerId(). Not
| |
| 378 clip_layer_ = layer_tree_impl()->LayerById(clip_layer_id); | |
| 379 } | |
| 380 | |
| 368 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { | 381 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { |
| 369 // Pending tree never has sent scroll deltas | 382 // Pending tree never has sent scroll deltas |
| 370 DCHECK(layer_tree_impl()->IsActiveTree()); | 383 DCHECK(layer_tree_impl()->IsActiveTree()); |
| 371 | 384 |
| 372 // Apply sent scroll deltas to scroll position / scroll delta as if the | 385 // Apply sent scroll deltas to scroll position / scroll delta as if the |
| 373 // main thread had applied them and then committed those values. | 386 // main thread had applied them and then committed those values. |
| 374 // | 387 // |
| 375 // This function should not change the total scroll offset; it just shifts | 388 // This function should not change the total scroll offset; it just shifts |
| 376 // some of the scroll delta to the scroll offset. Therefore, adjust these | 389 // some of the scroll delta to the scroll offset. Therefore, adjust these |
| 377 // variables directly rather than calling the scroll offset delegate to | 390 // variables directly rather than calling the scroll offset delegate to |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { | 460 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { |
| 448 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); | 461 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); |
| 449 return InputHandler::ScrollOnMainThread; | 462 return InputHandler::ScrollOnMainThread; |
| 450 } | 463 } |
| 451 | 464 |
| 452 if (!scrollable()) { | 465 if (!scrollable()) { |
| 453 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); | 466 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); |
| 454 return InputHandler::ScrollIgnored; | 467 return InputHandler::ScrollIgnored; |
| 455 } | 468 } |
| 456 | 469 |
| 457 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { | 470 gfx::Vector2d max_scroll_offset = MaxScrollOffset(); |
| 471 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { | |
| 458 TRACE_EVENT0("cc", | 472 TRACE_EVENT0("cc", |
| 459 "LayerImpl::tryScroll: Ignored. Technically scrollable," | 473 "LayerImpl::tryScroll: Ignored. Technically scrollable," |
| 460 " but has no affordance in either direction."); | 474 " but has no affordance in either direction."); |
| 461 return InputHandler::ScrollIgnored; | 475 return InputHandler::ScrollIgnored; |
| 462 } | 476 } |
| 463 | 477 |
| 464 if (!user_scrollable_horizontal_ && !user_scrollable_vertical_) { | 478 if (!user_scrollable_horizontal_ && !user_scrollable_vertical_) { |
| 465 TRACE_EVENT0("cc", | 479 TRACE_EVENT0("cc", |
| 466 "LayerImpl::TryScroll: Ignored. User gesture is not allowed" | 480 "LayerImpl::TryScroll: Ignored. User gesture is not allowed" |
| 467 " to scroll this layer."); | 481 " to scroll this layer."); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 layer->SetPosition(position_); | 539 layer->SetPosition(position_); |
| 526 layer->SetIsContainerForFixedPositionLayers( | 540 layer->SetIsContainerForFixedPositionLayers( |
| 527 is_container_for_fixed_position_layers_); | 541 is_container_for_fixed_position_layers_); |
| 528 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); | 542 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); |
| 529 layer->SetPositionConstraint(position_constraint_); | 543 layer->SetPositionConstraint(position_constraint_); |
| 530 layer->SetPreserves3d(preserves_3d()); | 544 layer->SetPreserves3d(preserves_3d()); |
| 531 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 545 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 532 layer->SetSublayerTransform(sublayer_transform_); | 546 layer->SetSublayerTransform(sublayer_transform_); |
| 533 layer->SetTransform(transform_); | 547 layer->SetTransform(transform_); |
| 534 | 548 |
| 535 layer->SetScrollable(scrollable_); | 549 layer->SetScrollable(clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID); |
| 536 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 550 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 537 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 551 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 538 layer->SetScrollOffsetAndDelta( | 552 layer->SetScrollOffsetAndDelta( |
| 539 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); | 553 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); |
| 540 layer->SetSentScrollDelta(gfx::Vector2d()); | 554 layer->SetSentScrollDelta(gfx::Vector2d()); |
| 541 | 555 |
| 542 layer->SetMaxScrollOffset(max_scroll_offset_); | |
| 543 | |
| 544 LayerImpl* scroll_parent = NULL; | 556 LayerImpl* scroll_parent = NULL; |
| 545 if (scroll_parent_) | 557 if (scroll_parent_) |
| 546 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 558 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 547 | 559 |
| 548 layer->SetScrollParent(scroll_parent); | 560 layer->SetScrollParent(scroll_parent); |
| 549 if (scroll_children_) { | 561 if (scroll_children_) { |
| 550 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 562 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 551 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); | 563 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); |
| 552 it != scroll_children_->end(); ++it) | 564 it != scroll_children_->end(); ++it) |
| 553 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); | 565 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 gfx_transform.matrix().asColMajord(transform); | 616 gfx_transform.matrix().asColMajord(transform); |
| 605 list = new base::ListValue; | 617 list = new base::ListValue; |
| 606 for (int i = 0; i < 16; ++i) | 618 for (int i = 0; i < 16; ++i) |
| 607 list->AppendDouble(transform[i]); | 619 list->AppendDouble(transform[i]); |
| 608 result->Set("DrawTransform", list); | 620 result->Set("DrawTransform", list); |
| 609 | 621 |
| 610 result->SetBoolean("DrawsContent", draws_content_); | 622 result->SetBoolean("DrawsContent", draws_content_); |
| 611 result->SetDouble("Opacity", opacity()); | 623 result->SetDouble("Opacity", opacity()); |
| 612 result->SetBoolean("ContentsOpaque", contents_opaque_); | 624 result->SetBoolean("ContentsOpaque", contents_opaque_); |
| 613 | 625 |
| 614 if (scrollable_) | 626 if (scrollable()) |
| 615 result->SetBoolean("Scrollable", scrollable_); | 627 result->SetBoolean("Scrollable", true); |
| 616 | 628 |
| 617 list = new base::ListValue; | 629 list = new base::ListValue; |
| 618 for (size_t i = 0; i < children_.size(); ++i) | 630 for (size_t i = 0; i < children_.size(); ++i) |
| 619 list->Append(children_[i]->LayerTreeAsJson()); | 631 list->Append(children_[i]->LayerTreeAsJson()); |
| 620 result->Set("Children", list); | 632 result->Set("Children", list); |
| 621 | 633 |
| 622 return result; | 634 return result; |
| 623 } | 635 } |
| 624 | 636 |
| 625 void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) { | 637 void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 bool LayerImpl::IsActive() const { | 700 bool LayerImpl::IsActive() const { |
| 689 return layer_tree_impl_->IsActiveTree(); | 701 return layer_tree_impl_->IsActiveTree(); |
| 690 } | 702 } |
| 691 | 703 |
| 692 void LayerImpl::SetBounds(gfx::Size bounds) { | 704 void LayerImpl::SetBounds(gfx::Size bounds) { |
| 693 if (bounds_ == bounds) | 705 if (bounds_ == bounds) |
| 694 return; | 706 return; |
| 695 | 707 |
| 696 bounds_ = bounds; | 708 bounds_ = bounds; |
| 697 | 709 |
| 710 NotifyScrollbars(); | |
| 698 if (masks_to_bounds()) | 711 if (masks_to_bounds()) |
| 699 NoteLayerPropertyChangedForSubtree(); | 712 NoteLayerPropertyChangedForSubtree(); |
| 700 else | 713 else |
| 701 NoteLayerPropertyChanged(); | 714 NoteLayerPropertyChanged(); |
| 702 } | 715 } |
| 703 | 716 |
| 704 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { | 717 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { |
| 705 int new_layer_id = mask_layer ? mask_layer->id() : -1; | 718 int new_layer_id = mask_layer ? mask_layer->id() : -1; |
| 706 | 719 |
| 707 if (mask_layer) { | 720 if (mask_layer) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 float* contents_scale_x, | 953 float* contents_scale_x, |
| 941 float* contents_scale_y, | 954 float* contents_scale_y, |
| 942 gfx::Size* content_bounds) { | 955 gfx::Size* content_bounds) { |
| 943 // Base LayerImpl has all of its content scales and content bounds pushed | 956 // Base LayerImpl has all of its content scales and content bounds pushed |
| 944 // from its Layer during commit and just reuses those values as-is. | 957 // from its Layer during commit and just reuses those values as-is. |
| 945 *contents_scale_x = this->contents_scale_x(); | 958 *contents_scale_x = this->contents_scale_x(); |
| 946 *contents_scale_y = this->contents_scale_y(); | 959 *contents_scale_y = this->contents_scale_y(); |
| 947 *content_bounds = this->content_bounds(); | 960 *content_bounds = this->content_bounds(); |
| 948 } | 961 } |
| 949 | 962 |
| 950 void LayerImpl::UpdateScrollbarPositions() { | |
| 951 gfx::Vector2dF current_offset = scroll_offset_ + ScrollDelta(); | |
| 952 | |
| 953 gfx::RectF viewport(PointAtOffsetFromOrigin(current_offset), bounds_); | |
| 954 gfx::SizeF scrollable_size(max_scroll_offset_.x() + bounds_.width(), | |
| 955 max_scroll_offset_.y() + bounds_.height()); | |
| 956 if (horizontal_scrollbar_layer_) { | |
| 957 horizontal_scrollbar_layer_->SetCurrentPos(current_offset.x()); | |
| 958 horizontal_scrollbar_layer_->SetMaximum(max_scroll_offset_.x()); | |
| 959 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio( | |
| 960 viewport.width() / scrollable_size.width()); | |
| 961 } | |
| 962 if (vertical_scrollbar_layer_) { | |
| 963 vertical_scrollbar_layer_->SetCurrentPos(current_offset.y()); | |
| 964 vertical_scrollbar_layer_->SetMaximum(max_scroll_offset_.y()); | |
| 965 vertical_scrollbar_layer_->SetVisibleToTotalLengthRatio( | |
| 966 viewport.height() / scrollable_size.height()); | |
| 967 } | |
| 968 | |
| 969 if (current_offset == last_scroll_offset_) | |
| 970 return; | |
| 971 last_scroll_offset_ = current_offset; | |
| 972 | |
| 973 if (scrollbar_animation_controller_) { | |
| 974 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate( | |
| 975 layer_tree_impl_->CurrentPhysicalTimeTicks()); | |
| 976 if (should_animate) | |
| 977 layer_tree_impl_->StartScrollbarAnimation(); | |
| 978 } | |
| 979 | |
| 980 // Get the current_offset_.y() value for a sanity-check on scrolling | |
| 981 // benchmark metrics. Specifically, we want to make sure | |
| 982 // BasicMouseWheelSmoothScrollGesture has proper scroll curves. | |
| 983 if (layer_tree_impl()->IsActiveTree()) { | |
| 984 TRACE_COUNTER_ID1("gpu", "scroll_offset_y", this->id(), current_offset.y()); | |
| 985 } | |
| 986 } | |
| 987 | |
| 988 void LayerImpl::SetScrollOffsetDelegate( | 963 void LayerImpl::SetScrollOffsetDelegate( |
| 989 LayerScrollOffsetDelegate* scroll_offset_delegate) { | 964 LayerScrollOffsetDelegate* scroll_offset_delegate) { |
| 990 // Having both a scroll parent and a scroll offset delegate is unsupported. | 965 // Having both a scroll parent and a scroll offset delegate is unsupported. |
| 991 DCHECK(!scroll_parent_); | 966 DCHECK(!scroll_parent_); |
| 992 if (!scroll_offset_delegate && scroll_offset_delegate_) { | 967 if (!scroll_offset_delegate && scroll_offset_delegate_) { |
| 993 scroll_delta_ = | 968 scroll_delta_ = |
| 994 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 969 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; |
| 995 } | 970 } |
| 996 gfx::Vector2dF total_offset = TotalScrollOffset(); | |
| 997 scroll_offset_delegate_ = scroll_offset_delegate; | 971 scroll_offset_delegate_ = scroll_offset_delegate; |
| 998 if (scroll_offset_delegate_) { | |
| 999 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); | |
| 1000 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); | |
| 1001 } | |
| 1002 } | 972 } |
| 1003 | 973 |
| 1004 bool LayerImpl::IsExternalFlingActive() const { | 974 bool LayerImpl::IsExternalFlingActive() const { |
| 1005 return scroll_offset_delegate_ && | 975 return scroll_offset_delegate_ && |
| 1006 scroll_offset_delegate_->IsExternalFlingActive(); | 976 scroll_offset_delegate_->IsExternalFlingActive(); |
| 1007 } | 977 } |
| 1008 | 978 |
| 1009 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { | 979 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { |
| 1010 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); | 980 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); |
| 1011 } | 981 } |
| 1012 | 982 |
| 1013 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, | 983 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, |
| 1014 gfx::Vector2dF scroll_delta) { | 984 gfx::Vector2dF scroll_delta) { |
| 1015 bool changed = false; | 985 bool changed = false; |
| 1016 | 986 |
| 987 last_scroll_offset_ = scroll_offset; | |
| 988 | |
| 1017 if (scroll_offset_ != scroll_offset) { | 989 if (scroll_offset_ != scroll_offset) { |
| 1018 changed = true; | 990 changed = true; |
| 1019 scroll_offset_ = scroll_offset; | 991 scroll_offset_ = scroll_offset; |
| 992 gfx::Vector2dF max = MaxScrollOffset(); | |
| 993 if (scroll_offset_.x() > max.x() || scroll_offset_.y() > max.y()) | |
| 994 fprintf(stderr, "wjm: LI::SetScrollOffsetAndDelta() scroll_offset too larg e!\n"); | |
| 1020 | 995 |
| 1021 if (scroll_offset_delegate_) | 996 if (scroll_offset_delegate_) |
| 1022 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); | 997 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); |
| 1023 } | 998 } |
| 1024 | 999 |
| 1025 if (ScrollDelta() != scroll_delta) { | 1000 if (ScrollDelta() != scroll_delta) { |
| 1026 changed = true; | 1001 changed = true; |
| 1027 if (layer_tree_impl()->IsActiveTree()) { | 1002 if (layer_tree_impl()->IsActiveTree()) { |
| 1028 LayerImpl* pending_twin = | 1003 LayerImpl* pending_twin = |
| 1029 layer_tree_impl()->FindPendingTreeLayerById(id()); | 1004 layer_tree_impl()->FindPendingTreeLayerById(id()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1041 if (scroll_offset_delegate_) { | 1016 if (scroll_offset_delegate_) { |
| 1042 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + | 1017 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + |
| 1043 scroll_delta); | 1018 scroll_delta); |
| 1044 } else { | 1019 } else { |
| 1045 scroll_delta_ = scroll_delta; | 1020 scroll_delta_ = scroll_delta; |
| 1046 } | 1021 } |
| 1047 } | 1022 } |
| 1048 | 1023 |
| 1049 if (changed) { | 1024 if (changed) { |
| 1050 NoteLayerPropertyChangedForSubtree(); | 1025 NoteLayerPropertyChangedForSubtree(); |
| 1051 UpdateScrollbarPositions(); | 1026 NotifyScrollbars(); |
| 1052 } | 1027 } |
| 1053 } | 1028 } |
| 1054 | 1029 |
| 1055 gfx::Vector2dF LayerImpl::ScrollDelta() const { | 1030 gfx::Vector2dF LayerImpl::ScrollDelta() const { |
| 1056 if (scroll_offset_delegate_) | 1031 if (scroll_offset_delegate_) |
| 1057 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 1032 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; |
| 1058 return scroll_delta_; | 1033 return scroll_delta_; |
| 1059 } | 1034 } |
| 1060 | 1035 |
| 1061 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { | 1036 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1077 Region LayerImpl::VisibleContentOpaqueRegion() const { | 1052 Region LayerImpl::VisibleContentOpaqueRegion() const { |
| 1078 if (contents_opaque()) | 1053 if (contents_opaque()) |
| 1079 return visible_content_rect(); | 1054 return visible_content_rect(); |
| 1080 return Region(); | 1055 return Region(); |
| 1081 } | 1056 } |
| 1082 | 1057 |
| 1083 void LayerImpl::DidBeginTracing() {} | 1058 void LayerImpl::DidBeginTracing() {} |
| 1084 | 1059 |
| 1085 void LayerImpl::DidLoseOutputSurface() {} | 1060 void LayerImpl::DidLoseOutputSurface() {} |
| 1086 | 1061 |
| 1087 void LayerImpl::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 1062 gfx::Vector2d LayerImpl::MaxScrollOffset() const { |
| 1088 if (max_scroll_offset_ == max_scroll_offset) | 1063 if (!clip_layer_) |
| 1089 return; | 1064 return gfx::Vector2d(); |
| 1090 max_scroll_offset_ = max_scroll_offset; | |
| 1091 | 1065 |
| 1092 if (scroll_offset_delegate_) | 1066 gfx::Size scaled_scroll_bounds(bounds()); |
| 1093 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); | 1067 LayerImpl const* current_layer = this; |
| 1068 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); | |
| 1069 float scale_factor = 1.f; | |
| 1070 do { | |
| 1071 if (current_layer == page_scale_layer) { | |
| 1072 scale_factor = layer_tree_impl()->total_page_scale_factor(); | |
| 1073 scaled_scroll_bounds.SetSize( | |
| 1074 scale_factor * scaled_scroll_bounds.width(), | |
| 1075 scale_factor * scaled_scroll_bounds.height()); | |
| 1076 } | |
| 1077 current_layer = current_layer->parent(); | |
| 1078 } while (current_layer && current_layer != clip_layer_); | |
| 1079 DCHECK(current_layer == clip_layer_); | |
| 1094 | 1080 |
| 1095 layer_tree_impl()->set_needs_update_draw_properties(); | 1081 gfx::Vector2dF max_offset( |
| 1096 UpdateScrollbarPositions(); | 1082 scaled_scroll_bounds.width() - clip_layer_->bounds().width(), |
| 1083 scaled_scroll_bounds.height() - clip_layer_->bounds().height()); | |
| 1084 // We need the final scroll offset to be in CSS coords. | |
| 1085 max_offset.Scale(1 / scale_factor); | |
| 1086 return gfx::Vector2d(max_offset.x(), max_offset.y()); | |
| 1087 } | |
| 1088 | |
| 1089 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { | |
| 1090 gfx::Vector2dF max_offset = MaxScrollOffset(); | |
| 1091 gfx::Vector2dF old_offset = TotalScrollOffset(); | |
| 1092 gfx::Vector2dF clamped_offset = old_offset; | |
| 1093 | |
| 1094 clamped_offset.SetToMin(max_offset); | |
| 1095 clamped_offset.SetToMax(gfx::Vector2d()); | |
| 1096 gfx::Vector2dF delta = clamped_offset - old_offset; | |
| 1097 if (!delta.IsZero()) | |
| 1098 ScrollBy(delta); | |
| 1099 | |
| 1100 return delta; | |
| 1101 } | |
| 1102 | |
| 1103 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, | |
| 1104 LayerImpl* scrollbar_clip_layer) const { | |
| 1105 DCHECK(scrollbar_layer); | |
| 1106 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); | |
| 1107 | |
| 1108 DCHECK(scrollbar_clip_layer); | |
| 1109 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds()); | |
| 1110 gfx::RectF scroll_rect(gfx::PointF(), bounds()); | |
| 1111 | |
| 1112 gfx::Vector2dF current_offset; | |
| 1113 | |
| 1114 // TODO(wjmaclean): How do I account for vertical adjust, or do I need to? | |
| 1115 // Also, I can probably improve some of the variable names. | |
| 1116 LayerImpl const* current_layer = this; | |
| 1117 float scale_factor = 1.f; | |
| 1118 do { | |
| 1119 if (current_layer == page_scale_layer) { | |
| 1120 scale_factor = layer_tree_impl()->total_page_scale_factor(); | |
| 1121 current_offset.Scale(scale_factor); | |
| 1122 scroll_rect.Scale(scale_factor); | |
| 1123 current_offset.Scale(scale_factor); | |
| 1124 } else { | |
| 1125 gfx::Vector2dF new_offset = | |
| 1126 current_layer->scroll_offset() + current_layer->ScrollDelta(); | |
| 1127 current_offset += new_offset; | |
| 1128 } | |
| 1129 current_layer = current_layer->parent(); | |
| 1130 } while (current_layer && current_layer != scrollbar_clip_layer); | |
| 1131 DCHECK(current_layer == scrollbar_clip_layer); | |
| 1132 current_offset.Scale(1 / scale_factor); | |
| 1133 // TODO(wjmaclean) need to think about the effect the size of the non-overlay | |
| 1134 // scrollbars have on the scroll size ... the final max value of current_pos | |
| 1135 // should not exceed maximum(), but it seems to by roughly | |
| 1136 // non_overlay_scroll_bar_width / scale_factor. | |
| 1137 | |
| 1138 if (scrollbar_layer->orientation() == HORIZONTAL) { | |
| 1139 float visible_ratio = clip_rect.width() / scroll_rect.width(); | |
| 1140 scrollbar_layer->SetCurrentPos(visible_ratio * current_offset.x()); | |
| 1141 scrollbar_layer->SetMaximum(visible_ratio * | |
| 1142 (scroll_rect.width() - clip_rect.width())); | |
| 1143 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
| 1144 } else { | |
| 1145 float visible_ratio = clip_rect.height() / scroll_rect.height(); | |
| 1146 scrollbar_layer->SetCurrentPos(visible_ratio * current_offset.y()); | |
| 1147 scrollbar_layer->SetMaximum(visible_ratio * | |
| 1148 (scroll_rect.height() - clip_rect.height())); | |
| 1149 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
| 1150 } | |
| 1151 | |
| 1152 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars should | |
| 1153 // activate for every scroll on the main frame, not just the scrolls that move | |
| 1154 // the pinch virtual viewport. | |
| 1155 if (scrollbar_animation_controller_) { | |
| 1156 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate( | |
| 1157 layer_tree_impl_->CurrentPhysicalTimeTicks()); | |
| 1158 if (should_animate) | |
| 1159 layer_tree_impl_->StartScrollbarAnimation(); | |
| 1160 } | |
| 1097 } | 1161 } |
| 1098 | 1162 |
| 1099 void LayerImpl::DidBecomeActive() { | 1163 void LayerImpl::DidBecomeActive() { |
| 1100 if (layer_tree_impl_->settings().scrollbar_animator == | 1164 if (layer_tree_impl_->settings().scrollbar_animator == |
| 1101 LayerTreeSettings::NoAnimator) { | 1165 LayerTreeSettings::NoAnimator) { |
| 1102 return; | 1166 return; |
| 1103 } | 1167 } |
| 1104 | 1168 |
| 1105 bool need_scrollbar_animation_controller = horizontal_scrollbar_layer_ || | 1169 bool need_scrollbar_animation_controller = scrollable() && scrollbars_; |
| 1106 vertical_scrollbar_layer_; | |
| 1107 if (!need_scrollbar_animation_controller) { | 1170 if (!need_scrollbar_animation_controller) { |
| 1108 scrollbar_animation_controller_.reset(); | 1171 scrollbar_animation_controller_.reset(); |
| 1109 return; | 1172 return; |
| 1110 } | 1173 } |
| 1111 | 1174 |
| 1112 if (scrollbar_animation_controller_) | 1175 if (scrollbar_animation_controller_) |
| 1113 return; | 1176 return; |
| 1114 | 1177 |
| 1115 switch (layer_tree_impl_->settings().scrollbar_animator) { | 1178 switch (layer_tree_impl_->settings().scrollbar_animator) { |
| 1116 case LayerTreeSettings::LinearFade: { | 1179 case LayerTreeSettings::LinearFade: { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1129 scrollbar_animation_controller_ = | 1192 scrollbar_animation_controller_ = |
| 1130 ScrollbarAnimationControllerThinning::Create(this) | 1193 ScrollbarAnimationControllerThinning::Create(this) |
| 1131 .PassAs<ScrollbarAnimationController>(); | 1194 .PassAs<ScrollbarAnimationController>(); |
| 1132 break; | 1195 break; |
| 1133 } | 1196 } |
| 1134 case LayerTreeSettings::NoAnimator: | 1197 case LayerTreeSettings::NoAnimator: |
| 1135 NOTREACHED(); | 1198 NOTREACHED(); |
| 1136 break; | 1199 break; |
| 1137 } | 1200 } |
| 1138 } | 1201 } |
| 1139 void LayerImpl::SetHorizontalScrollbarLayer( | 1202 |
| 1140 ScrollbarLayerImplBase* scrollbar_layer) { | 1203 void LayerImpl::ClearScrollbars() { |
| 1141 horizontal_scrollbar_layer_ = scrollbar_layer; | 1204 if (!scrollbars_) |
| 1142 if (horizontal_scrollbar_layer_) | 1205 return; |
| 1143 horizontal_scrollbar_layer_->set_scroll_layer_id(id()); | 1206 |
| 1207 scrollbars_.reset(NULL); | |
| 1144 } | 1208 } |
| 1145 | 1209 |
| 1146 void LayerImpl::SetVerticalScrollbarLayer( | 1210 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) { |
| 1147 ScrollbarLayerImplBase* scrollbar_layer) { | 1211 DCHECK(layer); |
| 1148 vertical_scrollbar_layer_ = scrollbar_layer; | 1212 if (!scrollbars_) |
| 1149 if (vertical_scrollbar_layer_) | 1213 scrollbars_.reset(new ScrollbarSet()); |
| 1150 vertical_scrollbar_layer_->set_scroll_layer_id(id()); | 1214 |
| 1215 scrollbars_->insert(layer); | |
| 1216 } | |
| 1217 | |
| 1218 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) { | |
| 1219 DCHECK(scrollbars_); | |
| 1220 DCHECK(layer); | |
| 1221 | |
| 1222 scrollbars_->erase(layer); | |
| 1223 if (scrollbars_->empty()) | |
| 1224 scrollbars_.reset(); | |
| 1225 } | |
| 1226 | |
| 1227 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const { | |
| 1228 if (!scrollbars_) | |
| 1229 return false; | |
| 1230 | |
| 1231 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
| 1232 it != scrollbars_->end(); ++it) | |
| 1233 if ((*it)->orientation() == orientation) | |
| 1234 return true; | |
| 1235 | |
| 1236 return false; | |
| 1237 } | |
| 1238 | |
| 1239 void LayerImpl::NotifyScrollbars() { | |
| 1240 if (!scrollbars_) | |
| 1241 return; | |
| 1242 | |
| 1243 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
| 1244 it != scrollbars_->end(); ++it) | |
| 1245 (*it)->ScrollbarParametersDidChange(); | |
| 1151 } | 1246 } |
| 1152 | 1247 |
| 1153 static scoped_ptr<base::Value> | 1248 static scoped_ptr<base::Value> |
| 1154 CompositingReasonsAsValue(CompositingReasons reasons) { | 1249 CompositingReasonsAsValue(CompositingReasons reasons) { |
| 1155 scoped_ptr<base::ListValue> reason_list(new base::ListValue()); | 1250 scoped_ptr<base::ListValue> reason_list(new base::ListValue()); |
| 1156 | 1251 |
| 1157 if (reasons == kCompositingReasonUnknown) { | 1252 if (reasons == kCompositingReasonUnknown) { |
| 1158 reason_list->AppendString("No reasons given"); | 1253 reason_list->AppendString("No reasons given"); |
| 1159 return reason_list.PassAs<base::Value>(); | 1254 return reason_list.PassAs<base::Value>(); |
| 1160 } | 1255 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1326 | 1421 |
| 1327 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } | 1422 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
| 1328 | 1423 |
| 1329 scoped_ptr<base::Value> LayerImpl::AsValue() const { | 1424 scoped_ptr<base::Value> LayerImpl::AsValue() const { |
| 1330 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1425 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1331 AsValueInto(state.get()); | 1426 AsValueInto(state.get()); |
| 1332 return state.PassAs<base::Value>(); | 1427 return state.PassAs<base::Value>(); |
| 1333 } | 1428 } |
| 1334 | 1429 |
| 1335 } // namespace cc | 1430 } // namespace cc |
| OLD | NEW |