| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "cc/animation/animation_registrar.h" | 10 #include "cc/animation/animation_registrar.h" |
| 11 #include "cc/animation/scrollbar_animation_controller.h" | 11 #include "cc/animation/scrollbar_animation_controller.h" |
| 12 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" | 12 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
| 13 #include "cc/animation/scrollbar_animation_controller_thinning.h" | 13 #include "cc/animation/scrollbar_animation_controller_thinning.h" |
| 14 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 15 #include "cc/debug/debug_colors.h" | 15 #include "cc/debug/debug_colors.h" |
| 16 #include "cc/debug/layer_tree_debug_state.h" | 16 #include "cc/debug/layer_tree_debug_state.h" |
| 17 #include "cc/debug/micro_benchmark_impl.h" | 17 #include "cc/debug/micro_benchmark_impl.h" |
| 18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
| 19 #include "cc/input/layer_scroll_offset_delegate.h" | 19 #include "cc/input/layer_scroll_offset_delegate.h" |
| 20 #include "cc/layers/painted_scrollbar_layer_impl.h" | 20 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 21 #include "cc/layers/quad_sink.h" | 21 #include "cc/layers/quad_sink.h" |
| 22 #include "cc/output/copy_output_request.h" | 22 #include "cc/output/copy_output_request.h" |
| 23 #include "cc/quads/debug_border_draw_quad.h" | 23 #include "cc/quads/debug_border_draw_quad.h" |
| 24 #include "cc/trees/layer_tree_impl.h" | 24 #include "cc/trees/layer_tree_impl.h" |
| 25 #include "cc/trees/layer_tree_settings.h" | 25 #include "cc/trees/layer_tree_settings.h" |
| 26 #include "cc/trees/proxy.h" | 26 #include "cc/trees/proxy.h" |
| 27 #include "ui/gfx/box_f.h" | 27 #include "ui/gfx/box_f.h" |
| 28 #include "ui/gfx/geometry/vector2d_conversions.h" | |
| 29 #include "ui/gfx/point_conversions.h" | 28 #include "ui/gfx/point_conversions.h" |
| 30 #include "ui/gfx/quad_f.h" | 29 #include "ui/gfx/quad_f.h" |
| 31 #include "ui/gfx/rect_conversions.h" | 30 #include "ui/gfx/rect_conversions.h" |
| 32 | 31 |
| 33 namespace cc { | 32 namespace cc { |
| 34 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) | 33 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) |
| 35 : parent_(NULL), | 34 : parent_(NULL), |
| 36 scroll_parent_(NULL), | 35 scroll_parent_(NULL), |
| 37 clip_parent_(NULL), | 36 clip_parent_(NULL), |
| 38 mask_layer_id_(-1), | 37 mask_layer_id_(-1), |
| 39 replica_layer_id_(-1), | 38 replica_layer_id_(-1), |
| 40 layer_id_(id), | 39 layer_id_(id), |
| 41 layer_tree_impl_(tree_impl), | 40 layer_tree_impl_(tree_impl), |
| 42 anchor_point_(0.5f, 0.5f), | 41 anchor_point_(0.5f, 0.5f), |
| 43 anchor_point_z_(0.f), | 42 anchor_point_z_(0.f), |
| 44 scroll_offset_delegate_(NULL), | 43 scroll_offset_delegate_(NULL), |
| 45 scroll_clip_layer_(NULL), | 44 scrollable_(false), |
| 46 should_scroll_on_main_thread_(false), | 45 should_scroll_on_main_thread_(false), |
| 47 have_wheel_event_handlers_(false), | 46 have_wheel_event_handlers_(false), |
| 48 user_scrollable_horizontal_(true), | 47 user_scrollable_horizontal_(true), |
| 49 user_scrollable_vertical_(true), | 48 user_scrollable_vertical_(true), |
| 50 stacking_order_changed_(false), | 49 stacking_order_changed_(false), |
| 51 double_sided_(true), | 50 double_sided_(true), |
| 52 layer_property_changed_(false), | 51 layer_property_changed_(false), |
| 53 masks_to_bounds_(false), | 52 masks_to_bounds_(false), |
| 54 contents_opaque_(false), | 53 contents_opaque_(false), |
| 55 is_root_for_isolated_group_(false), | 54 is_root_for_isolated_group_(false), |
| 56 preserves_3d_(false), | 55 preserves_3d_(false), |
| 57 use_parent_backface_visibility_(false), | 56 use_parent_backface_visibility_(false), |
| 58 draw_checkerboard_for_missing_tiles_(false), | 57 draw_checkerboard_for_missing_tiles_(false), |
| 59 draws_content_(false), | 58 draws_content_(false), |
| 60 hide_layer_and_subtree_(false), | 59 hide_layer_and_subtree_(false), |
| 61 force_render_surface_(false), | 60 force_render_surface_(false), |
| 62 is_container_for_fixed_position_layers_(false), | 61 is_container_for_fixed_position_layers_(false), |
| 63 background_color_(0), | 62 background_color_(0), |
| 64 opacity_(1.0), | 63 opacity_(1.0), |
| 65 blend_mode_(SkXfermode::kSrcOver_Mode), | 64 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 66 draw_depth_(0.f), | 65 draw_depth_(0.f), |
| 67 needs_push_properties_(false), | 66 needs_push_properties_(false), |
| 68 num_dependents_need_push_properties_(0), | 67 num_dependents_need_push_properties_(0), |
| 69 current_draw_mode_(DRAW_MODE_NONE) { | 68 current_draw_mode_(DRAW_MODE_NONE), |
| 69 horizontal_scrollbar_layer_(NULL), |
| 70 vertical_scrollbar_layer_(NULL) { |
| 70 DCHECK_GT(layer_id_, 0); | 71 DCHECK_GT(layer_id_, 0); |
| 71 DCHECK(layer_tree_impl_); | 72 DCHECK(layer_tree_impl_); |
| 72 layer_tree_impl_->RegisterLayer(this); | 73 layer_tree_impl_->RegisterLayer(this); |
| 73 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); | 74 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); |
| 74 layer_animation_controller_ = | 75 layer_animation_controller_ = |
| 75 registrar->GetAnimationControllerForId(layer_id_); | 76 registrar->GetAnimationControllerForId(layer_id_); |
| 76 layer_animation_controller_->AddValueObserver(this); | 77 layer_animation_controller_->AddValueObserver(this); |
| 77 if (IsActive()) | 78 if (IsActive()) |
| 78 layer_animation_controller_->set_value_provider(this); | 79 layer_animation_controller_->set_value_provider(this); |
| 79 SetNeedsPushProperties(); | 80 SetNeedsPushProperties(); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 372 |
| 372 if (sent_scroll_delta_ == sent_scroll_delta) | 373 if (sent_scroll_delta_ == sent_scroll_delta) |
| 373 return; | 374 return; |
| 374 | 375 |
| 375 sent_scroll_delta_ = sent_scroll_delta; | 376 sent_scroll_delta_ = sent_scroll_delta; |
| 376 } | 377 } |
| 377 | 378 |
| 378 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | 379 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
| 379 DCHECK(scrollable()); | 380 DCHECK(scrollable()); |
| 380 gfx::Vector2dF min_delta = -scroll_offset_; | 381 gfx::Vector2dF min_delta = -scroll_offset_; |
| 381 gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_; | 382 gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_; |
| 382 // Clamp new_delta so that position + delta stays within scroll bounds. | 383 // Clamp new_delta so that position + delta stays within scroll bounds. |
| 383 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); | 384 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); |
| 384 new_delta.SetToMax(min_delta); | 385 new_delta.SetToMax(min_delta); |
| 385 new_delta.SetToMin(max_delta); | 386 new_delta.SetToMin(max_delta); |
| 386 gfx::Vector2dF unscrolled = | 387 gfx::Vector2dF unscrolled = |
| 387 ScrollDelta() + scroll - new_delta; | 388 ScrollDelta() + scroll - new_delta; |
| 388 SetScrollDelta(new_delta); | 389 SetScrollDelta(new_delta); |
| 389 | |
| 390 return unscrolled; | 390 return unscrolled; |
| 391 } | 391 } |
| 392 | 392 |
| 393 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { | |
| 394 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); | |
| 395 } | |
| 396 | |
| 397 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { | 393 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { |
| 398 // Pending tree never has sent scroll deltas | 394 // Pending tree never has sent scroll deltas |
| 399 DCHECK(layer_tree_impl()->IsActiveTree()); | 395 DCHECK(layer_tree_impl()->IsActiveTree()); |
| 400 | 396 |
| 401 // Apply sent scroll deltas to scroll position / scroll delta as if the | 397 // Apply sent scroll deltas to scroll position / scroll delta as if the |
| 402 // main thread had applied them and then committed those values. | 398 // main thread had applied them and then committed those values. |
| 403 // | 399 // |
| 404 // This function should not change the total scroll offset; it just shifts | 400 // This function should not change the total scroll offset; it just shifts |
| 405 // some of the scroll delta to the scroll offset. Therefore, adjust these | 401 // some of the scroll delta to the scroll offset. Therefore, adjust these |
| 406 // variables directly rather than calling the scroll offset delegate to | 402 // variables directly rather than calling the scroll offset delegate to |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { | 472 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { |
| 477 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); | 473 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); |
| 478 return InputHandler::ScrollOnMainThread; | 474 return InputHandler::ScrollOnMainThread; |
| 479 } | 475 } |
| 480 | 476 |
| 481 if (!scrollable()) { | 477 if (!scrollable()) { |
| 482 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); | 478 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); |
| 483 return InputHandler::ScrollIgnored; | 479 return InputHandler::ScrollIgnored; |
| 484 } | 480 } |
| 485 | 481 |
| 486 gfx::Vector2d max_scroll_offset = MaxScrollOffset(); | 482 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { |
| 487 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { | |
| 488 TRACE_EVENT0("cc", | 483 TRACE_EVENT0("cc", |
| 489 "LayerImpl::tryScroll: Ignored. Technically scrollable," | 484 "LayerImpl::tryScroll: Ignored. Technically scrollable," |
| 490 " but has no affordance in either direction."); | 485 " but has no affordance in either direction."); |
| 491 return InputHandler::ScrollIgnored; | 486 return InputHandler::ScrollIgnored; |
| 492 } | 487 } |
| 493 | 488 |
| 494 return InputHandler::ScrollStarted; | 489 return InputHandler::ScrollStarted; |
| 495 } | 490 } |
| 496 | 491 |
| 497 bool LayerImpl::DrawCheckerboardForMissingTiles() const { | 492 bool LayerImpl::DrawCheckerboardForMissingTiles() const { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 layer->SetPosition(position_); | 543 layer->SetPosition(position_); |
| 549 layer->SetIsContainerForFixedPositionLayers( | 544 layer->SetIsContainerForFixedPositionLayers( |
| 550 is_container_for_fixed_position_layers_); | 545 is_container_for_fixed_position_layers_); |
| 551 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); | 546 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); |
| 552 layer->SetPositionConstraint(position_constraint_); | 547 layer->SetPositionConstraint(position_constraint_); |
| 553 layer->SetPreserves3d(preserves_3d()); | 548 layer->SetPreserves3d(preserves_3d()); |
| 554 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 549 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 555 layer->SetSublayerTransform(sublayer_transform_); | 550 layer->SetSublayerTransform(sublayer_transform_); |
| 556 layer->SetTransform(transform_); | 551 layer->SetTransform(transform_); |
| 557 | 552 |
| 558 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() | 553 layer->SetScrollable(scrollable_); |
| 559 : Layer::INVALID_ID); | |
| 560 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 554 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 561 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 555 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 562 layer->SetScrollOffsetAndDelta( | 556 layer->SetScrollOffsetAndDelta( |
| 563 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); | 557 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); |
| 564 layer->SetSentScrollDelta(gfx::Vector2d()); | 558 layer->SetSentScrollDelta(gfx::Vector2d()); |
| 565 | 559 |
| 560 layer->SetMaxScrollOffset(max_scroll_offset_); |
| 561 |
| 566 LayerImpl* scroll_parent = NULL; | 562 LayerImpl* scroll_parent = NULL; |
| 567 if (scroll_parent_) | 563 if (scroll_parent_) |
| 568 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 564 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 569 | 565 |
| 570 layer->SetScrollParent(scroll_parent); | 566 layer->SetScrollParent(scroll_parent); |
| 571 if (scroll_children_) { | 567 if (scroll_children_) { |
| 572 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 568 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 573 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); | 569 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); |
| 574 it != scroll_children_->end(); ++it) | 570 it != scroll_children_->end(); ++it) |
| 575 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); | 571 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 gfx_transform.matrix().asColMajord(transform); | 625 gfx_transform.matrix().asColMajord(transform); |
| 630 list = new base::ListValue; | 626 list = new base::ListValue; |
| 631 for (int i = 0; i < 16; ++i) | 627 for (int i = 0; i < 16; ++i) |
| 632 list->AppendDouble(transform[i]); | 628 list->AppendDouble(transform[i]); |
| 633 result->Set("DrawTransform", list); | 629 result->Set("DrawTransform", list); |
| 634 | 630 |
| 635 result->SetBoolean("DrawsContent", draws_content_); | 631 result->SetBoolean("DrawsContent", draws_content_); |
| 636 result->SetDouble("Opacity", opacity()); | 632 result->SetDouble("Opacity", opacity()); |
| 637 result->SetBoolean("ContentsOpaque", contents_opaque_); | 633 result->SetBoolean("ContentsOpaque", contents_opaque_); |
| 638 | 634 |
| 639 if (scrollable()) | 635 if (scrollable_) |
| 640 result->SetBoolean("Scrollable", true); | 636 result->SetBoolean("Scrollable", scrollable_); |
| 641 | 637 |
| 642 if (have_wheel_event_handlers_) | 638 if (have_wheel_event_handlers_) |
| 643 result->SetBoolean("WheelHandler", have_wheel_event_handlers_); | 639 result->SetBoolean("WheelHandler", have_wheel_event_handlers_); |
| 644 if (!touch_event_handler_region_.IsEmpty()) { | 640 if (!touch_event_handler_region_.IsEmpty()) { |
| 645 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); | 641 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); |
| 646 result->Set("TouchRegion", region.release()); | 642 result->Set("TouchRegion", region.release()); |
| 647 } | 643 } |
| 648 | 644 |
| 649 list = new base::ListValue; | 645 list = new base::ListValue; |
| 650 for (size_t i = 0; i < children_.size(); ++i) | 646 for (size_t i = 0; i < children_.size(); ++i) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 bool LayerImpl::IsActive() const { | 748 bool LayerImpl::IsActive() const { |
| 753 return layer_tree_impl_->IsActiveTree(); | 749 return layer_tree_impl_->IsActiveTree(); |
| 754 } | 750 } |
| 755 | 751 |
| 756 void LayerImpl::SetBounds(gfx::Size bounds) { | 752 void LayerImpl::SetBounds(gfx::Size bounds) { |
| 757 if (bounds_ == bounds) | 753 if (bounds_ == bounds) |
| 758 return; | 754 return; |
| 759 | 755 |
| 760 bounds_ = bounds; | 756 bounds_ = bounds; |
| 761 | 757 |
| 762 ScrollbarParametersDidChange(); | |
| 763 if (masks_to_bounds()) | 758 if (masks_to_bounds()) |
| 764 NoteLayerPropertyChangedForSubtree(); | 759 NoteLayerPropertyChangedForSubtree(); |
| 765 else | 760 else |
| 766 NoteLayerPropertyChanged(); | 761 NoteLayerPropertyChanged(); |
| 767 } | 762 } |
| 768 | 763 |
| 769 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { | 764 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { |
| 770 int new_layer_id = mask_layer ? mask_layer->id() : -1; | 765 int new_layer_id = mask_layer ? mask_layer->id() : -1; |
| 771 | 766 |
| 772 if (mask_layer) { | 767 if (mask_layer) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 float* contents_scale_x, | 1021 float* contents_scale_x, |
| 1027 float* contents_scale_y, | 1022 float* contents_scale_y, |
| 1028 gfx::Size* content_bounds) { | 1023 gfx::Size* content_bounds) { |
| 1029 // Base LayerImpl has all of its content scales and content bounds pushed | 1024 // Base LayerImpl has all of its content scales and content bounds pushed |
| 1030 // from its Layer during commit and just reuses those values as-is. | 1025 // from its Layer during commit and just reuses those values as-is. |
| 1031 *contents_scale_x = this->contents_scale_x(); | 1026 *contents_scale_x = this->contents_scale_x(); |
| 1032 *contents_scale_y = this->contents_scale_y(); | 1027 *contents_scale_y = this->contents_scale_y(); |
| 1033 *content_bounds = this->content_bounds(); | 1028 *content_bounds = this->content_bounds(); |
| 1034 } | 1029 } |
| 1035 | 1030 |
| 1031 void LayerImpl::UpdateScrollbarPositions() { |
| 1032 gfx::Vector2dF current_offset = scroll_offset_ + ScrollDelta(); |
| 1033 |
| 1034 gfx::RectF viewport(PointAtOffsetFromOrigin(current_offset), bounds_); |
| 1035 gfx::SizeF scrollable_size(max_scroll_offset_.x() + bounds_.width(), |
| 1036 max_scroll_offset_.y() + bounds_.height()); |
| 1037 if (horizontal_scrollbar_layer_) { |
| 1038 horizontal_scrollbar_layer_->SetCurrentPos(current_offset.x()); |
| 1039 horizontal_scrollbar_layer_->SetMaximum(max_scroll_offset_.x()); |
| 1040 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio( |
| 1041 viewport.width() / scrollable_size.width()); |
| 1042 } |
| 1043 if (vertical_scrollbar_layer_) { |
| 1044 vertical_scrollbar_layer_->SetCurrentPos(current_offset.y()); |
| 1045 vertical_scrollbar_layer_->SetMaximum(max_scroll_offset_.y()); |
| 1046 vertical_scrollbar_layer_->SetVisibleToTotalLengthRatio( |
| 1047 viewport.height() / scrollable_size.height()); |
| 1048 } |
| 1049 |
| 1050 if (current_offset == last_scroll_offset_) |
| 1051 return; |
| 1052 last_scroll_offset_ = current_offset; |
| 1053 |
| 1054 if (scrollbar_animation_controller_) { |
| 1055 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate( |
| 1056 layer_tree_impl_->CurrentPhysicalTimeTicks()); |
| 1057 if (should_animate) |
| 1058 layer_tree_impl_->StartScrollbarAnimation(); |
| 1059 } |
| 1060 |
| 1061 // Get the current_offset_.y() value for a sanity-check on scrolling |
| 1062 // benchmark metrics. Specifically, we want to make sure |
| 1063 // BasicMouseWheelSmoothScrollGesture has proper scroll curves. |
| 1064 if (layer_tree_impl()->IsActiveTree()) { |
| 1065 TRACE_COUNTER_ID1("gpu", "scroll_offset_y", this->id(), current_offset.y()); |
| 1066 } |
| 1067 } |
| 1068 |
| 1036 void LayerImpl::SetScrollOffsetDelegate( | 1069 void LayerImpl::SetScrollOffsetDelegate( |
| 1037 LayerScrollOffsetDelegate* scroll_offset_delegate) { | 1070 LayerScrollOffsetDelegate* scroll_offset_delegate) { |
| 1038 // Having both a scroll parent and a scroll offset delegate is unsupported. | 1071 // Having both a scroll parent and a scroll offset delegate is unsupported. |
| 1039 DCHECK(!scroll_parent_); | 1072 DCHECK(!scroll_parent_); |
| 1040 if (!scroll_offset_delegate && scroll_offset_delegate_) { | 1073 if (!scroll_offset_delegate && scroll_offset_delegate_) { |
| 1041 scroll_delta_ = | 1074 scroll_delta_ = |
| 1042 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 1075 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; |
| 1043 } | 1076 } |
| 1044 gfx::Vector2dF total_offset = TotalScrollOffset(); | 1077 gfx::Vector2dF total_offset = TotalScrollOffset(); |
| 1045 scroll_offset_delegate_ = scroll_offset_delegate; | 1078 scroll_offset_delegate_ = scroll_offset_delegate; |
| 1046 if (scroll_offset_delegate_) | 1079 if (scroll_offset_delegate_) { |
| 1080 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); |
| 1047 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); | 1081 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); |
| 1082 } |
| 1048 } | 1083 } |
| 1049 | 1084 |
| 1050 bool LayerImpl::IsExternalFlingActive() const { | 1085 bool LayerImpl::IsExternalFlingActive() const { |
| 1051 return scroll_offset_delegate_ && | 1086 return scroll_offset_delegate_ && |
| 1052 scroll_offset_delegate_->IsExternalFlingActive(); | 1087 scroll_offset_delegate_->IsExternalFlingActive(); |
| 1053 } | 1088 } |
| 1054 | 1089 |
| 1055 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { | 1090 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { |
| 1056 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); | 1091 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); |
| 1057 } | 1092 } |
| 1058 | 1093 |
| 1059 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, | 1094 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, |
| 1060 const gfx::Vector2dF& scroll_delta) { | 1095 const gfx::Vector2dF& scroll_delta) { |
| 1061 bool changed = false; | 1096 bool changed = false; |
| 1062 | 1097 |
| 1063 last_scroll_offset_ = scroll_offset; | |
| 1064 | |
| 1065 if (scroll_offset_ != scroll_offset) { | 1098 if (scroll_offset_ != scroll_offset) { |
| 1066 changed = true; | 1099 changed = true; |
| 1067 scroll_offset_ = scroll_offset; | 1100 scroll_offset_ = scroll_offset; |
| 1068 | 1101 |
| 1069 if (scroll_offset_delegate_) | 1102 if (scroll_offset_delegate_) |
| 1070 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); | 1103 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); |
| 1071 } | 1104 } |
| 1072 | 1105 |
| 1073 if (ScrollDelta() != scroll_delta) { | 1106 if (ScrollDelta() != scroll_delta) { |
| 1074 changed = true; | 1107 changed = true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1089 if (scroll_offset_delegate_) { | 1122 if (scroll_offset_delegate_) { |
| 1090 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + | 1123 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + |
| 1091 scroll_delta); | 1124 scroll_delta); |
| 1092 } else { | 1125 } else { |
| 1093 scroll_delta_ = scroll_delta; | 1126 scroll_delta_ = scroll_delta; |
| 1094 } | 1127 } |
| 1095 } | 1128 } |
| 1096 | 1129 |
| 1097 if (changed) { | 1130 if (changed) { |
| 1098 NoteLayerPropertyChangedForSubtree(); | 1131 NoteLayerPropertyChangedForSubtree(); |
| 1099 ScrollbarParametersDidChange(); | 1132 UpdateScrollbarPositions(); |
| 1100 } | 1133 } |
| 1101 } | 1134 } |
| 1102 | 1135 |
| 1103 gfx::Vector2dF LayerImpl::ScrollDelta() const { | 1136 gfx::Vector2dF LayerImpl::ScrollDelta() const { |
| 1104 if (scroll_offset_delegate_) | 1137 if (scroll_offset_delegate_) |
| 1105 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 1138 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; |
| 1106 return scroll_delta_; | 1139 return scroll_delta_; |
| 1107 } | 1140 } |
| 1108 | 1141 |
| 1109 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { | 1142 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1125 Region LayerImpl::VisibleContentOpaqueRegion() const { | 1158 Region LayerImpl::VisibleContentOpaqueRegion() const { |
| 1126 if (contents_opaque()) | 1159 if (contents_opaque()) |
| 1127 return visible_content_rect(); | 1160 return visible_content_rect(); |
| 1128 return Region(); | 1161 return Region(); |
| 1129 } | 1162 } |
| 1130 | 1163 |
| 1131 void LayerImpl::DidBeginTracing() {} | 1164 void LayerImpl::DidBeginTracing() {} |
| 1132 | 1165 |
| 1133 void LayerImpl::ReleaseResources() {} | 1166 void LayerImpl::ReleaseResources() {} |
| 1134 | 1167 |
| 1135 gfx::Vector2d LayerImpl::MaxScrollOffset() const { | 1168 void LayerImpl::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { |
| 1136 if (!scroll_clip_layer_ || bounds().IsEmpty()) | 1169 if (max_scroll_offset_ == max_scroll_offset) |
| 1137 return gfx::Vector2d(); | 1170 return; |
| 1171 max_scroll_offset_ = max_scroll_offset; |
| 1138 | 1172 |
| 1139 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); | 1173 if (scroll_offset_delegate_) |
| 1140 DCHECK(this != page_scale_layer); | 1174 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); |
| 1141 DCHECK(scroll_clip_layer_); | |
| 1142 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || | |
| 1143 IsContainerForFixedPositionLayers()); | |
| 1144 | |
| 1145 gfx::Size scaled_scroll_bounds(bounds()); | |
| 1146 | |
| 1147 float scale_factor = 1.f; | |
| 1148 for (LayerImpl const* current_layer = this; | |
| 1149 current_layer != scroll_clip_layer_; | |
| 1150 current_layer = current_layer->parent()) { | |
| 1151 DCHECK(current_layer); | |
| 1152 float current_layer_scale = 1.f; | |
| 1153 | |
| 1154 const gfx::Transform& layer_transform = current_layer->transform(); | |
| 1155 if (current_layer == page_scale_layer) { | |
| 1156 DCHECK(layer_transform.IsIdentity()); | |
| 1157 current_layer_scale = layer_tree_impl()->total_page_scale_factor(); | |
| 1158 } else { | |
| 1159 // TODO(wjmaclean) Should we allow for translation too? | |
| 1160 DCHECK(layer_transform.IsScale2d()); | |
| 1161 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); | |
| 1162 // TODO(wjmaclean) Allow for non-isotropic scales. | |
| 1163 DCHECK(layer_scale.x() == layer_scale.y()); | |
| 1164 current_layer_scale = layer_scale.x(); | |
| 1165 } | |
| 1166 | |
| 1167 scale_factor *= current_layer_scale; | |
| 1168 } | |
| 1169 // TODO(wjmaclean) Once we move to a model where the two-viewport model is | |
| 1170 // turned on in all builds, remove the next two lines. For now however, the | |
| 1171 // page scale layer may coincide with the clip layer, and so this is | |
| 1172 // necessary. | |
| 1173 if (page_scale_layer == scroll_clip_layer_) | |
| 1174 scale_factor *= layer_tree_impl()->total_page_scale_factor(); | |
| 1175 | |
| 1176 scaled_scroll_bounds.SetSize( | |
| 1177 scale_factor * scaled_scroll_bounds.width(), | |
| 1178 scale_factor * scaled_scroll_bounds.height()); | |
| 1179 | |
| 1180 gfx::RectF clip_rect(gfx::PointF(), scroll_clip_layer_->bounds()); | |
| 1181 if (this == layer_tree_impl()->InnerViewportScrollLayer()) | |
| 1182 clip_rect = | |
| 1183 gfx::RectF(gfx::PointF(), layer_tree_impl()->ScrollableViewportSize()); | |
| 1184 gfx::Vector2dF max_offset( | |
| 1185 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), | |
| 1186 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); | |
| 1187 // We need the final scroll offset to be in CSS coords. | |
| 1188 max_offset.Scale(1 / scale_factor); | |
| 1189 max_offset.SetToMax(gfx::Vector2dF()); | |
| 1190 return gfx::ToFlooredVector2d(max_offset); | |
| 1191 } | |
| 1192 | |
| 1193 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { | |
| 1194 gfx::Vector2dF max_offset = MaxScrollOffset(); | |
| 1195 gfx::Vector2dF old_offset = TotalScrollOffset(); | |
| 1196 gfx::Vector2dF clamped_offset = old_offset; | |
| 1197 | |
| 1198 clamped_offset.SetToMin(max_offset); | |
| 1199 clamped_offset.SetToMax(gfx::Vector2d()); | |
| 1200 gfx::Vector2dF delta = clamped_offset - old_offset; | |
| 1201 if (!delta.IsZero()) | |
| 1202 ScrollBy(delta); | |
| 1203 | |
| 1204 return delta; | |
| 1205 } | |
| 1206 | |
| 1207 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, | |
| 1208 LayerImpl* scrollbar_clip_layer) const { | |
| 1209 DCHECK(scrollbar_layer); | |
| 1210 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); | |
| 1211 | |
| 1212 DCHECK(this != page_scale_layer); | |
| 1213 DCHECK(scrollbar_clip_layer); | |
| 1214 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() | |
| 1215 || IsContainerForFixedPositionLayers()); | |
| 1216 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds()); | |
| 1217 | |
| 1218 // See comment in MaxScrollOffset() regarding the use of the content layer | |
| 1219 // bounds here. | |
| 1220 gfx::RectF scroll_rect(gfx::PointF(), bounds()); | |
| 1221 | |
| 1222 if (scroll_rect.size().IsEmpty()) | |
| 1223 return; | |
| 1224 | |
| 1225 // TODO(wjmaclean) This computation is nearly identical to the one in | |
| 1226 // MaxScrollOffset. Find some way to combine these. | |
| 1227 gfx::Vector2dF current_offset; | |
| 1228 for (LayerImpl const* current_layer = this; | |
| 1229 current_layer != scrollbar_clip_layer; | |
| 1230 current_layer = current_layer->parent()) { | |
| 1231 DCHECK(current_layer); | |
| 1232 const gfx::Transform& layer_transform = current_layer->transform(); | |
| 1233 if (current_layer == page_scale_layer) { | |
| 1234 DCHECK(layer_transform.IsIdentity()); | |
| 1235 float scale_factor = layer_tree_impl()->total_page_scale_factor(); | |
| 1236 current_offset.Scale(scale_factor); | |
| 1237 scroll_rect.Scale(scale_factor); | |
| 1238 } else { | |
| 1239 DCHECK(layer_transform.IsScale2d()); | |
| 1240 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); | |
| 1241 DCHECK(layer_scale.x() == layer_scale.y()); | |
| 1242 gfx::Vector2dF new_offset = | |
| 1243 current_layer->scroll_offset() + current_layer->ScrollDelta(); | |
| 1244 new_offset.Scale(layer_scale.x(), layer_scale.y()); | |
| 1245 current_offset += new_offset; | |
| 1246 } | |
| 1247 } | |
| 1248 // TODO(wjmaclean) Once we move to a model where the two-viewport model is | |
| 1249 // turned on in all builds, remove the next two lines. For now however, the | |
| 1250 // page scale layer may coincide with the clip layer, and so this is | |
| 1251 // necessary. | |
| 1252 if (page_scale_layer == scrollbar_clip_layer) | |
| 1253 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor()); | |
| 1254 | |
| 1255 scrollbar_layer->SetVerticalAdjust(layer_tree_impl()->VerticalAdjust(this)); | |
| 1256 if (scrollbar_layer->orientation() == HORIZONTAL) { | |
| 1257 float visible_ratio = clip_rect.width() / scroll_rect.width(); | |
| 1258 scrollbar_layer->SetCurrentPos(current_offset.x()); | |
| 1259 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); | |
| 1260 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
| 1261 } else { | |
| 1262 float visible_ratio = clip_rect.height() / scroll_rect.height(); | |
| 1263 scrollbar_layer->SetCurrentPos(current_offset.y()); | |
| 1264 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height()); | |
| 1265 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
| 1266 } | |
| 1267 | 1175 |
| 1268 layer_tree_impl()->set_needs_update_draw_properties(); | 1176 layer_tree_impl()->set_needs_update_draw_properties(); |
| 1269 // TODO(wjmaclean) Should the rest of this function be deleted? | 1177 UpdateScrollbarPositions(); |
| 1270 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars should | 1178 SetNeedsPushProperties(); |
| 1271 // activate for every scroll on the main frame, not just the scrolls that move | |
| 1272 // the pinch virtual viewport (i.e. trigger from either inner or outer | |
| 1273 // viewport). | |
| 1274 if (scrollbar_animation_controller_) { | |
| 1275 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate( | |
| 1276 layer_tree_impl_->CurrentPhysicalTimeTicks()); | |
| 1277 if (should_animate) | |
| 1278 layer_tree_impl_->StartScrollbarAnimation(); | |
| 1279 } | |
| 1280 } | 1179 } |
| 1281 | 1180 |
| 1282 void LayerImpl::DidBecomeActive() { | 1181 void LayerImpl::DidBecomeActive() { |
| 1283 if (layer_tree_impl_->settings().scrollbar_animator == | 1182 if (layer_tree_impl_->settings().scrollbar_animator == |
| 1284 LayerTreeSettings::NoAnimator) { | 1183 LayerTreeSettings::NoAnimator) { |
| 1285 return; | 1184 return; |
| 1286 } | 1185 } |
| 1287 | 1186 |
| 1288 bool need_scrollbar_animation_controller = scrollable() && scrollbars_; | 1187 bool need_scrollbar_animation_controller = horizontal_scrollbar_layer_ || |
| 1188 vertical_scrollbar_layer_; |
| 1289 if (!need_scrollbar_animation_controller) { | 1189 if (!need_scrollbar_animation_controller) { |
| 1290 scrollbar_animation_controller_.reset(); | 1190 scrollbar_animation_controller_.reset(); |
| 1291 return; | 1191 return; |
| 1292 } | 1192 } |
| 1293 | 1193 |
| 1294 if (scrollbar_animation_controller_) | 1194 if (scrollbar_animation_controller_) |
| 1295 return; | 1195 return; |
| 1296 | 1196 |
| 1297 switch (layer_tree_impl_->settings().scrollbar_animator) { | 1197 switch (layer_tree_impl_->settings().scrollbar_animator) { |
| 1298 case LayerTreeSettings::LinearFade: { | 1198 case LayerTreeSettings::LinearFade: { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1312 ScrollbarAnimationControllerThinning::Create(this) | 1212 ScrollbarAnimationControllerThinning::Create(this) |
| 1313 .PassAs<ScrollbarAnimationController>(); | 1213 .PassAs<ScrollbarAnimationController>(); |
| 1314 break; | 1214 break; |
| 1315 } | 1215 } |
| 1316 case LayerTreeSettings::NoAnimator: | 1216 case LayerTreeSettings::NoAnimator: |
| 1317 NOTREACHED(); | 1217 NOTREACHED(); |
| 1318 break; | 1218 break; |
| 1319 } | 1219 } |
| 1320 } | 1220 } |
| 1321 | 1221 |
| 1322 void LayerImpl::ClearScrollbars() { | 1222 void LayerImpl::SetHorizontalScrollbarLayer( |
| 1323 if (!scrollbars_) | 1223 ScrollbarLayerImplBase* scrollbar_layer) { |
| 1324 return; | 1224 horizontal_scrollbar_layer_ = scrollbar_layer; |
| 1325 | 1225 if (horizontal_scrollbar_layer_) |
| 1326 scrollbars_.reset(NULL); | 1226 horizontal_scrollbar_layer_->set_scroll_layer_id(id()); |
| 1327 } | 1227 } |
| 1328 | 1228 |
| 1329 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) { | 1229 void LayerImpl::SetVerticalScrollbarLayer( |
| 1330 DCHECK(layer); | 1230 ScrollbarLayerImplBase* scrollbar_layer) { |
| 1331 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end()); | 1231 vertical_scrollbar_layer_ = scrollbar_layer; |
| 1332 if (!scrollbars_) | 1232 if (vertical_scrollbar_layer_) |
| 1333 scrollbars_.reset(new ScrollbarSet()); | 1233 vertical_scrollbar_layer_->set_scroll_layer_id(id()); |
| 1334 | |
| 1335 scrollbars_->insert(layer); | |
| 1336 } | |
| 1337 | |
| 1338 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) { | |
| 1339 DCHECK(scrollbars_); | |
| 1340 DCHECK(layer); | |
| 1341 DCHECK(scrollbars_->find(layer) != scrollbars_->end()); | |
| 1342 | |
| 1343 scrollbars_->erase(layer); | |
| 1344 if (scrollbars_->empty()) | |
| 1345 scrollbars_.reset(); | |
| 1346 } | |
| 1347 | |
| 1348 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const { | |
| 1349 if (!scrollbars_) | |
| 1350 return false; | |
| 1351 | |
| 1352 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
| 1353 it != scrollbars_->end(); ++it) | |
| 1354 if ((*it)->orientation() == orientation) | |
| 1355 return true; | |
| 1356 | |
| 1357 return false; | |
| 1358 } | |
| 1359 | |
| 1360 void LayerImpl::ScrollbarParametersDidChange() { | |
| 1361 if (!scrollbars_) | |
| 1362 return; | |
| 1363 | |
| 1364 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
| 1365 it != scrollbars_->end(); ++it) | |
| 1366 (*it)->ScrollbarParametersDidChange(); | |
| 1367 } | 1234 } |
| 1368 | 1235 |
| 1369 void LayerImpl::SetNeedsPushProperties() { | 1236 void LayerImpl::SetNeedsPushProperties() { |
| 1370 if (needs_push_properties_) | 1237 if (needs_push_properties_) |
| 1371 return; | 1238 return; |
| 1372 if (!parent_should_know_need_push_properties() && parent_) | 1239 if (!parent_should_know_need_push_properties() && parent_) |
| 1373 parent_->AddDependentNeedsPushProperties(); | 1240 parent_->AddDependentNeedsPushProperties(); |
| 1374 needs_push_properties_ = true; | 1241 needs_push_properties_ = true; |
| 1375 } | 1242 } |
| 1376 | 1243 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1337 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1471 AsValueInto(state.get()); | 1338 AsValueInto(state.get()); |
| 1472 return state.PassAs<base::Value>(); | 1339 return state.PassAs<base::Value>(); |
| 1473 } | 1340 } |
| 1474 | 1341 |
| 1475 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1342 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1476 benchmark->RunOnLayer(this); | 1343 benchmark->RunOnLayer(this); |
| 1477 } | 1344 } |
| 1478 | 1345 |
| 1479 } // namespace cc | 1346 } // namespace cc |
| OLD | NEW |