Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: cc/layers/layer_impl.cc

Issue 23983047: Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Draft for review. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
365 return unscrolled; 364 return unscrolled;
366 } 365 }
367 366
367 void LayerImpl::SetScrollable(int clip_layer_id) {
enne (OOO) 2013/11/14 22:59:01 As I said on the other patch, I think this is a so
wjmaclean 2013/12/24 21:03:49 Let's try "SetScrollClipLayer", sound ok? Fixed i
368 clip_layer_ = layer_tree_impl()->LayerById(clip_layer_id);
369 }
370
368 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { 371 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
369 // Pending tree never has sent scroll deltas 372 // Pending tree never has sent scroll deltas
370 DCHECK(layer_tree_impl()->IsActiveTree()); 373 DCHECK(layer_tree_impl()->IsActiveTree());
371 374
372 // Apply sent scroll deltas to scroll position / scroll delta as if the 375 // Apply sent scroll deltas to scroll position / scroll delta as if the
373 // main thread had applied them and then committed those values. 376 // main thread had applied them and then committed those values.
374 // 377 //
375 // This function should not change the total scroll offset; it just shifts 378 // 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 379 // some of the scroll delta to the scroll offset. Therefore, adjust these
377 // variables directly rather than calling the scroll offset delegate to 380 // variables directly rather than calling the scroll offset delegate to
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { 450 if (type == InputHandler::Wheel && have_wheel_event_handlers()) {
448 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); 451 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
449 return InputHandler::ScrollOnMainThread; 452 return InputHandler::ScrollOnMainThread;
450 } 453 }
451 454
452 if (!scrollable()) { 455 if (!scrollable()) {
453 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); 456 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
454 return InputHandler::ScrollIgnored; 457 return InputHandler::ScrollIgnored;
455 } 458 }
456 459
457 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { 460 gfx::Vector2d max_scroll_offset = MaxScrollOffset();
461 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
458 TRACE_EVENT0("cc", 462 TRACE_EVENT0("cc",
459 "LayerImpl::tryScroll: Ignored. Technically scrollable," 463 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
460 " but has no affordance in either direction."); 464 " but has no affordance in either direction.");
461 return InputHandler::ScrollIgnored; 465 return InputHandler::ScrollIgnored;
462 } 466 }
463 467
464 if (!user_scrollable_horizontal_ && !user_scrollable_vertical_) { 468 if (!user_scrollable_horizontal_ && !user_scrollable_vertical_) {
465 TRACE_EVENT0("cc", 469 TRACE_EVENT0("cc",
466 "LayerImpl::TryScroll: Ignored. User gesture is not allowed" 470 "LayerImpl::TryScroll: Ignored. User gesture is not allowed"
467 " to scroll this layer."); 471 " to scroll this layer.");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 layer->SetPosition(position_); 529 layer->SetPosition(position_);
526 layer->SetIsContainerForFixedPositionLayers( 530 layer->SetIsContainerForFixedPositionLayers(
527 is_container_for_fixed_position_layers_); 531 is_container_for_fixed_position_layers_);
528 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); 532 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_);
529 layer->SetPositionConstraint(position_constraint_); 533 layer->SetPositionConstraint(position_constraint_);
530 layer->SetPreserves3d(preserves_3d()); 534 layer->SetPreserves3d(preserves_3d());
531 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 535 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
532 layer->SetSublayerTransform(sublayer_transform_); 536 layer->SetSublayerTransform(sublayer_transform_);
533 layer->SetTransform(transform_); 537 layer->SetTransform(transform_);
534 538
535 layer->SetScrollable(scrollable_); 539 layer->SetScrollable(clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID);
536 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); 540 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
537 layer->set_user_scrollable_vertical(user_scrollable_vertical_); 541 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
538 layer->SetScrollOffsetAndDelta( 542 layer->SetScrollOffsetAndDelta(
539 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); 543 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta());
540 layer->SetSentScrollDelta(gfx::Vector2d()); 544 layer->SetSentScrollDelta(gfx::Vector2d());
541 545
542 layer->SetMaxScrollOffset(max_scroll_offset_);
543
544 LayerImpl* scroll_parent = NULL; 546 LayerImpl* scroll_parent = NULL;
545 if (scroll_parent_) 547 if (scroll_parent_)
546 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); 548 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
547 549
548 layer->SetScrollParent(scroll_parent); 550 layer->SetScrollParent(scroll_parent);
549 if (scroll_children_) { 551 if (scroll_children_) {
550 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; 552 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
551 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); 553 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
552 it != scroll_children_->end(); ++it) 554 it != scroll_children_->end(); ++it)
553 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); 555 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 gfx_transform.matrix().asColMajord(transform); 606 gfx_transform.matrix().asColMajord(transform);
605 list = new base::ListValue; 607 list = new base::ListValue;
606 for (int i = 0; i < 16; ++i) 608 for (int i = 0; i < 16; ++i)
607 list->AppendDouble(transform[i]); 609 list->AppendDouble(transform[i]);
608 result->Set("DrawTransform", list); 610 result->Set("DrawTransform", list);
609 611
610 result->SetBoolean("DrawsContent", draws_content_); 612 result->SetBoolean("DrawsContent", draws_content_);
611 result->SetDouble("Opacity", opacity()); 613 result->SetDouble("Opacity", opacity());
612 result->SetBoolean("ContentsOpaque", contents_opaque_); 614 result->SetBoolean("ContentsOpaque", contents_opaque_);
613 615
614 if (scrollable_) 616 if (scrollable())
615 result->SetBoolean("Scrollable", scrollable_); 617 result->SetBoolean("Scrollable", true);
616 618
617 if (have_wheel_event_handlers_) 619 if (have_wheel_event_handlers_)
618 result->SetBoolean("WheelHandler", have_wheel_event_handlers_); 620 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
619 if (!touch_event_handler_region_.IsEmpty()) { 621 if (!touch_event_handler_region_.IsEmpty()) {
620 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); 622 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
621 result->Set("TouchRegion", region.release()); 623 result->Set("TouchRegion", region.release());
622 } 624 }
623 625
624 list = new base::ListValue; 626 list = new base::ListValue;
625 for (size_t i = 0; i < children_.size(); ++i) 627 for (size_t i = 0; i < children_.size(); ++i)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 bool LayerImpl::IsActive() const { 697 bool LayerImpl::IsActive() const {
696 return layer_tree_impl_->IsActiveTree(); 698 return layer_tree_impl_->IsActiveTree();
697 } 699 }
698 700
699 void LayerImpl::SetBounds(gfx::Size bounds) { 701 void LayerImpl::SetBounds(gfx::Size bounds) {
700 if (bounds_ == bounds) 702 if (bounds_ == bounds)
701 return; 703 return;
702 704
703 bounds_ = bounds; 705 bounds_ = bounds;
704 706
707 NotifyScrollbars();
705 if (masks_to_bounds()) 708 if (masks_to_bounds())
706 NoteLayerPropertyChangedForSubtree(); 709 NoteLayerPropertyChangedForSubtree();
707 else 710 else
708 NoteLayerPropertyChanged(); 711 NoteLayerPropertyChanged();
709 } 712 }
710 713
711 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { 714 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
712 int new_layer_id = mask_layer ? mask_layer->id() : -1; 715 int new_layer_id = mask_layer ? mask_layer->id() : -1;
713 716
714 if (mask_layer) { 717 if (mask_layer) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 float* contents_scale_x, 950 float* contents_scale_x,
948 float* contents_scale_y, 951 float* contents_scale_y,
949 gfx::Size* content_bounds) { 952 gfx::Size* content_bounds) {
950 // Base LayerImpl has all of its content scales and content bounds pushed 953 // Base LayerImpl has all of its content scales and content bounds pushed
951 // from its Layer during commit and just reuses those values as-is. 954 // from its Layer during commit and just reuses those values as-is.
952 *contents_scale_x = this->contents_scale_x(); 955 *contents_scale_x = this->contents_scale_x();
953 *contents_scale_y = this->contents_scale_y(); 956 *contents_scale_y = this->contents_scale_y();
954 *content_bounds = this->content_bounds(); 957 *content_bounds = this->content_bounds();
955 } 958 }
956 959
957 void LayerImpl::UpdateScrollbarPositions() {
958 gfx::Vector2dF current_offset = scroll_offset_ + ScrollDelta();
959
960 gfx::RectF viewport(PointAtOffsetFromOrigin(current_offset), bounds_);
961 gfx::SizeF scrollable_size(max_scroll_offset_.x() + bounds_.width(),
962 max_scroll_offset_.y() + bounds_.height());
963 if (horizontal_scrollbar_layer_) {
964 horizontal_scrollbar_layer_->SetCurrentPos(current_offset.x());
965 horizontal_scrollbar_layer_->SetMaximum(max_scroll_offset_.x());
966 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(
967 viewport.width() / scrollable_size.width());
968 }
969 if (vertical_scrollbar_layer_) {
970 vertical_scrollbar_layer_->SetCurrentPos(current_offset.y());
971 vertical_scrollbar_layer_->SetMaximum(max_scroll_offset_.y());
972 vertical_scrollbar_layer_->SetVisibleToTotalLengthRatio(
973 viewport.height() / scrollable_size.height());
974 }
975
976 if (current_offset == last_scroll_offset_)
977 return;
978 last_scroll_offset_ = current_offset;
979
980 if (scrollbar_animation_controller_) {
981 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate(
982 layer_tree_impl_->CurrentPhysicalTimeTicks());
983 if (should_animate)
984 layer_tree_impl_->StartScrollbarAnimation();
985 }
986
987 // Get the current_offset_.y() value for a sanity-check on scrolling
988 // benchmark metrics. Specifically, we want to make sure
989 // BasicMouseWheelSmoothScrollGesture has proper scroll curves.
990 if (layer_tree_impl()->IsActiveTree()) {
991 TRACE_COUNTER_ID1("gpu", "scroll_offset_y", this->id(), current_offset.y());
992 }
993 }
994
995 void LayerImpl::SetScrollOffsetDelegate( 960 void LayerImpl::SetScrollOffsetDelegate(
996 LayerScrollOffsetDelegate* scroll_offset_delegate) { 961 LayerScrollOffsetDelegate* scroll_offset_delegate) {
997 // Having both a scroll parent and a scroll offset delegate is unsupported. 962 // Having both a scroll parent and a scroll offset delegate is unsupported.
998 DCHECK(!scroll_parent_); 963 DCHECK(!scroll_parent_);
999 if (!scroll_offset_delegate && scroll_offset_delegate_) { 964 if (!scroll_offset_delegate && scroll_offset_delegate_) {
1000 scroll_delta_ = 965 scroll_delta_ =
1001 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 966 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_;
1002 } 967 }
1003 gfx::Vector2dF total_offset = TotalScrollOffset(); 968 gfx::Vector2dF total_offset = TotalScrollOffset();
1004 scroll_offset_delegate_ = scroll_offset_delegate; 969 scroll_offset_delegate_ = scroll_offset_delegate;
1005 if (scroll_offset_delegate_) { 970 if (scroll_offset_delegate_)
1006 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_);
1007 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); 971 scroll_offset_delegate_->SetTotalScrollOffset(total_offset);
1008 }
1009 } 972 }
1010 973
1011 bool LayerImpl::IsExternalFlingActive() const { 974 bool LayerImpl::IsExternalFlingActive() const {
1012 return scroll_offset_delegate_ && 975 return scroll_offset_delegate_ &&
1013 scroll_offset_delegate_->IsExternalFlingActive(); 976 scroll_offset_delegate_->IsExternalFlingActive();
1014 } 977 }
1015 978
1016 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { 979 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) {
1017 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); 980 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta());
1018 } 981 }
1019 982
1020 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, 983 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset,
1021 gfx::Vector2dF scroll_delta) { 984 gfx::Vector2dF scroll_delta) {
1022 bool changed = false; 985 bool changed = false;
1023 986
987 last_scroll_offset_ = scroll_offset;
enne (OOO) 2013/11/14 22:59:01 What is last_scroll_offset_ used for?
wjmaclean 2013/12/24 21:03:49 Ooops, remnant of diagnostic code :-) Removed.
988
1024 if (scroll_offset_ != scroll_offset) { 989 if (scroll_offset_ != scroll_offset) {
1025 changed = true; 990 changed = true;
1026 scroll_offset_ = scroll_offset; 991 scroll_offset_ = scroll_offset;
1027 992
1028 if (scroll_offset_delegate_) 993 if (scroll_offset_delegate_)
1029 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); 994 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset());
1030 } 995 }
1031 996
1032 if (ScrollDelta() != scroll_delta) { 997 if (ScrollDelta() != scroll_delta) {
1033 changed = true; 998 changed = true;
(...skipping 14 matching lines...) Expand all
1048 if (scroll_offset_delegate_) { 1013 if (scroll_offset_delegate_) {
1049 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + 1014 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ +
1050 scroll_delta); 1015 scroll_delta);
1051 } else { 1016 } else {
1052 scroll_delta_ = scroll_delta; 1017 scroll_delta_ = scroll_delta;
1053 } 1018 }
1054 } 1019 }
1055 1020
1056 if (changed) { 1021 if (changed) {
1057 NoteLayerPropertyChangedForSubtree(); 1022 NoteLayerPropertyChangedForSubtree();
1058 UpdateScrollbarPositions(); 1023 NotifyScrollbars();
1059 } 1024 }
1060 } 1025 }
1061 1026
1062 gfx::Vector2dF LayerImpl::ScrollDelta() const { 1027 gfx::Vector2dF LayerImpl::ScrollDelta() const {
1063 if (scroll_offset_delegate_) 1028 if (scroll_offset_delegate_)
1064 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 1029 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_;
1065 return scroll_delta_; 1030 return scroll_delta_;
1066 } 1031 }
1067 1032
1068 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { 1033 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) {
(...skipping 15 matching lines...) Expand all
1084 Region LayerImpl::VisibleContentOpaqueRegion() const { 1049 Region LayerImpl::VisibleContentOpaqueRegion() const {
1085 if (contents_opaque()) 1050 if (contents_opaque())
1086 return visible_content_rect(); 1051 return visible_content_rect();
1087 return Region(); 1052 return Region();
1088 } 1053 }
1089 1054
1090 void LayerImpl::DidBeginTracing() {} 1055 void LayerImpl::DidBeginTracing() {}
1091 1056
1092 void LayerImpl::DidLoseOutputSurface() {} 1057 void LayerImpl::DidLoseOutputSurface() {}
1093 1058
1094 void LayerImpl::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { 1059 gfx::Vector2d LayerImpl::MaxScrollOffset() const {
1095 if (max_scroll_offset_ == max_scroll_offset) 1060 if (!clip_layer_)
1096 return; 1061 return gfx::Vector2d();
1097 max_scroll_offset_ = max_scroll_offset;
1098 1062
1099 if (scroll_offset_delegate_) 1063 gfx::Size scaled_scroll_bounds(bounds());
1100 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); 1064 LayerImpl const* current_layer = this;
1065 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1066 float scale_factor = 1.f;
1067 do {
enne (OOO) 2013/11/14 22:59:01 This loop assumes there are no other scale transfo
wjmaclean 2013/12/24 21:03:49 I've made this more general, allow scale (but not
1068 if (current_layer == page_scale_layer) {
1069 scale_factor = layer_tree_impl()->total_page_scale_factor();
1070 scaled_scroll_bounds.SetSize(
1071 scale_factor * scaled_scroll_bounds.width(),
1072 scale_factor * scaled_scroll_bounds.height());
1073 }
1074 current_layer = current_layer->parent();
1075 } while (current_layer && current_layer != clip_layer_);
1076 DCHECK(current_layer == clip_layer_);
1101 1077
1102 layer_tree_impl()->set_needs_update_draw_properties(); 1078 gfx::Vector2dF max_offset(
1103 UpdateScrollbarPositions(); 1079 scaled_scroll_bounds.width() - clip_layer_->bounds().width(),
aelias_OOO_until_Jul13 2013/11/14 01:25:35 Using clip_layer_->bounds() is incorrect on Androi
1080 scaled_scroll_bounds.height() - clip_layer_->bounds().height());
1081 // We need the final scroll offset to be in CSS coords.
1082 max_offset.Scale(1 / scale_factor);
1083 return gfx::Vector2d(max_offset.x(), max_offset.y());
1084 }
1085
1086 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1087 gfx::Vector2dF max_offset = MaxScrollOffset();
1088 gfx::Vector2dF old_offset = TotalScrollOffset();
1089 gfx::Vector2dF clamped_offset = old_offset;
1090
1091 clamped_offset.SetToMin(max_offset);
1092 clamped_offset.SetToMax(gfx::Vector2d());
1093 gfx::Vector2dF delta = clamped_offset - old_offset;
1094 if (!delta.IsZero())
1095 ScrollBy(delta);
1096
1097 return delta;
1098 }
1099
1100 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
1101 LayerImpl* scrollbar_clip_layer) const {
1102 DCHECK(scrollbar_layer);
1103 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1104
1105 DCHECK(scrollbar_clip_layer);
1106 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds());
1107 gfx::RectF scroll_rect(gfx::PointF(), bounds());
1108
1109 gfx::Vector2dF current_offset;
1110
1111 // TODO(wjmaclean): How do I account for vertical adjust, or do I need to?
aelias_OOO_until_Jul13 2013/11/14 01:25:35 "Vertical adjust" is used to keep the horizontal s
wjmaclean 2013/12/24 21:03:49 Done.
1112 // Also, I can probably improve some of the variable names.
1113 LayerImpl const* current_layer = this;
1114 float scale_factor = 1.f;
1115 do {
1116 if (current_layer == page_scale_layer) {
1117 scale_factor = layer_tree_impl()->total_page_scale_factor();
1118 current_offset.Scale(scale_factor);
1119 scroll_rect.Scale(scale_factor);
1120 current_offset.Scale(scale_factor);
1121 } else {
1122 gfx::Vector2dF new_offset =
1123 current_layer->scroll_offset() + current_layer->ScrollDelta();
1124 current_offset += new_offset;
1125 }
1126 current_layer = current_layer->parent();
1127 } while (current_layer && current_layer != scrollbar_clip_layer);
1128 DCHECK(current_layer == scrollbar_clip_layer);
1129 current_offset.Scale(1 / scale_factor);
1130
1131 if (scrollbar_layer->orientation() == HORIZONTAL) {
1132 float visible_ratio = clip_rect.width() / scroll_rect.width();
1133 scrollbar_layer->SetCurrentPos(current_offset.x());
1134 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1135 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1136 } else {
1137 float visible_ratio = clip_rect.height() / scroll_rect.height();
1138 scrollbar_layer->SetCurrentPos(current_offset.y());
1139 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1140 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1141 }
1142
1143 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars should
1144 // activate for every scroll on the main frame, not just the scrolls that move
1145 // the pinch virtual viewport.
1146 if (scrollbar_animation_controller_) {
1147 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate(
1148 layer_tree_impl_->CurrentPhysicalTimeTicks());
1149 if (should_animate)
1150 layer_tree_impl_->StartScrollbarAnimation();
1151 }
1104 } 1152 }
1105 1153
1106 void LayerImpl::DidBecomeActive() { 1154 void LayerImpl::DidBecomeActive() {
1107 if (layer_tree_impl_->settings().scrollbar_animator == 1155 if (layer_tree_impl_->settings().scrollbar_animator ==
1108 LayerTreeSettings::NoAnimator) { 1156 LayerTreeSettings::NoAnimator) {
1109 return; 1157 return;
1110 } 1158 }
1111 1159
1112 bool need_scrollbar_animation_controller = horizontal_scrollbar_layer_ || 1160 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
1113 vertical_scrollbar_layer_;
1114 if (!need_scrollbar_animation_controller) { 1161 if (!need_scrollbar_animation_controller) {
1115 scrollbar_animation_controller_.reset(); 1162 scrollbar_animation_controller_.reset();
1116 return; 1163 return;
1117 } 1164 }
1118 1165
1119 if (scrollbar_animation_controller_) 1166 if (scrollbar_animation_controller_)
1120 return; 1167 return;
1121 1168
1122 switch (layer_tree_impl_->settings().scrollbar_animator) { 1169 switch (layer_tree_impl_->settings().scrollbar_animator) {
1123 case LayerTreeSettings::LinearFade: { 1170 case LayerTreeSettings::LinearFade: {
(...skipping 12 matching lines...) Expand all
1136 scrollbar_animation_controller_ = 1183 scrollbar_animation_controller_ =
1137 ScrollbarAnimationControllerThinning::Create(this) 1184 ScrollbarAnimationControllerThinning::Create(this)
1138 .PassAs<ScrollbarAnimationController>(); 1185 .PassAs<ScrollbarAnimationController>();
1139 break; 1186 break;
1140 } 1187 }
1141 case LayerTreeSettings::NoAnimator: 1188 case LayerTreeSettings::NoAnimator:
1142 NOTREACHED(); 1189 NOTREACHED();
1143 break; 1190 break;
1144 } 1191 }
1145 } 1192 }
1146 void LayerImpl::SetHorizontalScrollbarLayer( 1193
1147 ScrollbarLayerImplBase* scrollbar_layer) { 1194 void LayerImpl::ClearScrollbars() {
1148 horizontal_scrollbar_layer_ = scrollbar_layer; 1195 if (!scrollbars_)
1149 if (horizontal_scrollbar_layer_) 1196 return;
1150 horizontal_scrollbar_layer_->set_scroll_layer_id(id()); 1197
1198 scrollbars_.reset(NULL);
1151 } 1199 }
1152 1200
1153 void LayerImpl::SetVerticalScrollbarLayer( 1201 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1154 ScrollbarLayerImplBase* scrollbar_layer) { 1202 DCHECK(layer);
1155 vertical_scrollbar_layer_ = scrollbar_layer; 1203 if (!scrollbars_)
1156 if (vertical_scrollbar_layer_) 1204 scrollbars_.reset(new ScrollbarSet());
1157 vertical_scrollbar_layer_->set_scroll_layer_id(id()); 1205
1206 scrollbars_->insert(layer);
1207 }
1208
1209 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1210 DCHECK(scrollbars_);
1211 DCHECK(layer);
1212
1213 scrollbars_->erase(layer);
1214 if (scrollbars_->empty())
1215 scrollbars_.reset();
1216 }
1217
1218 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1219 if (!scrollbars_)
1220 return false;
1221
1222 for (ScrollbarSet::iterator it = scrollbars_->begin();
1223 it != scrollbars_->end(); ++it)
1224 if ((*it)->orientation() == orientation)
1225 return true;
1226
1227 return false;
1228 }
1229
1230 void LayerImpl::NotifyScrollbars() {
1231 if (!scrollbars_)
1232 return;
1233
1234 for (ScrollbarSet::iterator it = scrollbars_->begin();
1235 it != scrollbars_->end(); ++it)
1236 (*it)->ScrollbarParametersDidChange();
1158 } 1237 }
1159 1238
1160 static scoped_ptr<base::Value> 1239 static scoped_ptr<base::Value>
1161 CompositingReasonsAsValue(CompositingReasons reasons) { 1240 CompositingReasonsAsValue(CompositingReasons reasons) {
1162 scoped_ptr<base::ListValue> reason_list(new base::ListValue()); 1241 scoped_ptr<base::ListValue> reason_list(new base::ListValue());
1163 1242
1164 if (reasons == kCompositingReasonUnknown) { 1243 if (reasons == kCompositingReasonUnknown) {
1165 reason_list->AppendString("No reasons given"); 1244 reason_list->AppendString("No reasons given");
1166 return reason_list.PassAs<base::Value>(); 1245 return reason_list.PassAs<base::Value>();
1167 } 1246 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 1412
1334 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } 1413 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1335 1414
1336 scoped_ptr<base::Value> LayerImpl::AsValue() const { 1415 scoped_ptr<base::Value> LayerImpl::AsValue() const {
1337 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 1416 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
1338 AsValueInto(state.get()); 1417 AsValueInto(state.get());
1339 return state.PassAs<base::Value>(); 1418 return state.PassAs<base::Value>();
1340 } 1419 }
1341 1420
1342 } // namespace cc 1421 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698