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