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

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: Address review comments. Created 6 years, 12 months 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 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
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 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 compositing_reasons_(kCompositingReasonUnknown), 66 compositing_reasons_(kCompositingReasonUnknown),
67 current_draw_mode_(DRAW_MODE_NONE), 67 current_draw_mode_(DRAW_MODE_NONE) {
68 horizontal_scrollbar_layer_(NULL),
69 vertical_scrollbar_layer_(NULL) {
70 DCHECK_GT(layer_id_, 0); 68 DCHECK_GT(layer_id_, 0);
71 DCHECK(layer_tree_impl_); 69 DCHECK(layer_tree_impl_);
72 layer_tree_impl_->RegisterLayer(this); 70 layer_tree_impl_->RegisterLayer(this);
73 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); 71 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar();
74 layer_animation_controller_ = 72 layer_animation_controller_ =
75 registrar->GetAnimationControllerForId(layer_id_); 73 registrar->GetAnimationControllerForId(layer_id_);
76 layer_animation_controller_->AddValueObserver(this); 74 layer_animation_controller_->AddValueObserver(this);
77 if (IsActive()) 75 if (IsActive())
78 layer_animation_controller_->set_value_provider(this); 76 layer_animation_controller_->set_value_provider(this);
79 } 77 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 351
354 if (sent_scroll_delta_ == sent_scroll_delta) 352 if (sent_scroll_delta_ == sent_scroll_delta)
355 return; 353 return;
356 354
357 sent_scroll_delta_ = sent_scroll_delta; 355 sent_scroll_delta_ = sent_scroll_delta;
358 } 356 }
359 357
360 gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) { 358 gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) {
361 DCHECK(scrollable()); 359 DCHECK(scrollable());
362 gfx::Vector2dF min_delta = -scroll_offset_; 360 gfx::Vector2dF min_delta = -scroll_offset_;
363 gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_; 361 gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_;
364 // Clamp new_delta so that position + delta stays within scroll bounds. 362 // Clamp new_delta so that position + delta stays within scroll bounds.
365 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); 363 gfx::Vector2dF new_delta = (ScrollDelta() + scroll);
366 new_delta.SetToMax(min_delta); 364 new_delta.SetToMax(min_delta);
367 new_delta.SetToMin(max_delta); 365 new_delta.SetToMin(max_delta);
368 gfx::Vector2dF unscrolled = 366 gfx::Vector2dF unscrolled =
369 ScrollDelta() + scroll - new_delta; 367 ScrollDelta() + scroll - new_delta;
370 SetScrollDelta(new_delta); 368 SetScrollDelta(new_delta);
369
371 return unscrolled; 370 return unscrolled;
372 } 371 }
373 372
373 void LayerImpl::SetScrollClipLayer(int clip_layer_id) {
374 clip_layer_ = layer_tree_impl()->LayerById(clip_layer_id);
375 }
376
374 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { 377 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
375 // Pending tree never has sent scroll deltas 378 // Pending tree never has sent scroll deltas
376 DCHECK(layer_tree_impl()->IsActiveTree()); 379 DCHECK(layer_tree_impl()->IsActiveTree());
377 380
378 // Apply sent scroll deltas to scroll position / scroll delta as if the 381 // Apply sent scroll deltas to scroll position / scroll delta as if the
379 // main thread had applied them and then committed those values. 382 // main thread had applied them and then committed those values.
380 // 383 //
381 // This function should not change the total scroll offset; it just shifts 384 // This function should not change the total scroll offset; it just shifts
382 // some of the scroll delta to the scroll offset. Therefore, adjust these 385 // some of the scroll delta to the scroll offset. Therefore, adjust these
383 // variables directly rather than calling the scroll offset delegate to 386 // variables directly rather than calling the scroll offset delegate to
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { 456 if (type == InputHandler::Wheel && have_wheel_event_handlers()) {
454 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); 457 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
455 return InputHandler::ScrollOnMainThread; 458 return InputHandler::ScrollOnMainThread;
456 } 459 }
457 460
458 if (!scrollable()) { 461 if (!scrollable()) {
459 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); 462 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
460 return InputHandler::ScrollIgnored; 463 return InputHandler::ScrollIgnored;
461 } 464 }
462 465
463 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { 466 gfx::Vector2d max_scroll_offset = MaxScrollOffset();
467 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
464 TRACE_EVENT0("cc", 468 TRACE_EVENT0("cc",
465 "LayerImpl::tryScroll: Ignored. Technically scrollable," 469 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
466 " but has no affordance in either direction."); 470 " but has no affordance in either direction.");
467 return InputHandler::ScrollIgnored; 471 return InputHandler::ScrollIgnored;
468 } 472 }
469 473
470 return InputHandler::ScrollStarted; 474 return InputHandler::ScrollStarted;
471 } 475 }
472 476
473 bool LayerImpl::DrawCheckerboardForMissingTiles() const { 477 bool LayerImpl::DrawCheckerboardForMissingTiles() const {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 layer->SetPosition(position_); 530 layer->SetPosition(position_);
527 layer->SetIsContainerForFixedPositionLayers( 531 layer->SetIsContainerForFixedPositionLayers(
528 is_container_for_fixed_position_layers_); 532 is_container_for_fixed_position_layers_);
529 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_); 533 layer->SetFixedContainerSizeDelta(fixed_container_size_delta_);
530 layer->SetPositionConstraint(position_constraint_); 534 layer->SetPositionConstraint(position_constraint_);
531 layer->SetPreserves3d(preserves_3d()); 535 layer->SetPreserves3d(preserves_3d());
532 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 536 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
533 layer->SetSublayerTransform(sublayer_transform_); 537 layer->SetSublayerTransform(sublayer_transform_);
534 layer->SetTransform(transform_); 538 layer->SetTransform(transform_);
535 539
536 layer->SetScrollable(scrollable_); 540 layer->SetScrollClipLayer(clip_layer_ ? clip_layer_->id()
541 : Layer::INVALID_ID);
537 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); 542 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
538 layer->set_user_scrollable_vertical(user_scrollable_vertical_); 543 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
539 layer->SetScrollOffsetAndDelta( 544 layer->SetScrollOffsetAndDelta(
540 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); 545 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta());
541 layer->SetSentScrollDelta(gfx::Vector2d()); 546 layer->SetSentScrollDelta(gfx::Vector2d());
542 547
543 layer->SetMaxScrollOffset(max_scroll_offset_);
544
545 LayerImpl* scroll_parent = NULL; 548 LayerImpl* scroll_parent = NULL;
546 if (scroll_parent_) 549 if (scroll_parent_)
547 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); 550 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
548 551
549 layer->SetScrollParent(scroll_parent); 552 layer->SetScrollParent(scroll_parent);
550 if (scroll_children_) { 553 if (scroll_children_) {
551 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; 554 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
552 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); 555 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
553 it != scroll_children_->end(); ++it) 556 it != scroll_children_->end(); ++it)
554 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); 557 scroll_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 gfx_transform.matrix().asColMajord(transform); 610 gfx_transform.matrix().asColMajord(transform);
608 list = new base::ListValue; 611 list = new base::ListValue;
609 for (int i = 0; i < 16; ++i) 612 for (int i = 0; i < 16; ++i)
610 list->AppendDouble(transform[i]); 613 list->AppendDouble(transform[i]);
611 result->Set("DrawTransform", list); 614 result->Set("DrawTransform", list);
612 615
613 result->SetBoolean("DrawsContent", draws_content_); 616 result->SetBoolean("DrawsContent", draws_content_);
614 result->SetDouble("Opacity", opacity()); 617 result->SetDouble("Opacity", opacity());
615 result->SetBoolean("ContentsOpaque", contents_opaque_); 618 result->SetBoolean("ContentsOpaque", contents_opaque_);
616 619
617 if (scrollable_) 620 if (scrollable())
618 result->SetBoolean("Scrollable", scrollable_); 621 result->SetBoolean("Scrollable", true);
619 622
620 if (have_wheel_event_handlers_) 623 if (have_wheel_event_handlers_)
621 result->SetBoolean("WheelHandler", have_wheel_event_handlers_); 624 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
622 if (!touch_event_handler_region_.IsEmpty()) { 625 if (!touch_event_handler_region_.IsEmpty()) {
623 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); 626 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
624 result->Set("TouchRegion", region.release()); 627 result->Set("TouchRegion", region.release());
625 } 628 }
626 629
627 list = new base::ListValue; 630 list = new base::ListValue;
628 for (size_t i = 0; i < children_.size(); ++i) 631 for (size_t i = 0; i < children_.size(); ++i)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 bool LayerImpl::IsActive() const { 719 bool LayerImpl::IsActive() const {
717 return layer_tree_impl_->IsActiveTree(); 720 return layer_tree_impl_->IsActiveTree();
718 } 721 }
719 722
720 void LayerImpl::SetBounds(gfx::Size bounds) { 723 void LayerImpl::SetBounds(gfx::Size bounds) {
721 if (bounds_ == bounds) 724 if (bounds_ == bounds)
722 return; 725 return;
723 726
724 bounds_ = bounds; 727 bounds_ = bounds;
725 728
729 ScrollbarParametersDidChange();
726 if (masks_to_bounds()) 730 if (masks_to_bounds())
727 NoteLayerPropertyChangedForSubtree(); 731 NoteLayerPropertyChangedForSubtree();
728 else 732 else
729 NoteLayerPropertyChanged(); 733 NoteLayerPropertyChanged();
730 } 734 }
731 735
732 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { 736 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
733 int new_layer_id = mask_layer ? mask_layer->id() : -1; 737 int new_layer_id = mask_layer ? mask_layer->id() : -1;
734 738
735 if (mask_layer) { 739 if (mask_layer) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 float* contents_scale_x, 987 float* contents_scale_x,
984 float* contents_scale_y, 988 float* contents_scale_y,
985 gfx::Size* content_bounds) { 989 gfx::Size* content_bounds) {
986 // Base LayerImpl has all of its content scales and content bounds pushed 990 // Base LayerImpl has all of its content scales and content bounds pushed
987 // from its Layer during commit and just reuses those values as-is. 991 // from its Layer during commit and just reuses those values as-is.
988 *contents_scale_x = this->contents_scale_x(); 992 *contents_scale_x = this->contents_scale_x();
989 *contents_scale_y = this->contents_scale_y(); 993 *contents_scale_y = this->contents_scale_y();
990 *content_bounds = this->content_bounds(); 994 *content_bounds = this->content_bounds();
991 } 995 }
992 996
993 void LayerImpl::UpdateScrollbarPositions() {
994 gfx::Vector2dF current_offset = scroll_offset_ + ScrollDelta();
995
996 gfx::RectF viewport(PointAtOffsetFromOrigin(current_offset), bounds_);
997 gfx::SizeF scrollable_size(max_scroll_offset_.x() + bounds_.width(),
998 max_scroll_offset_.y() + bounds_.height());
999 if (horizontal_scrollbar_layer_) {
1000 horizontal_scrollbar_layer_->SetCurrentPos(current_offset.x());
1001 horizontal_scrollbar_layer_->SetMaximum(max_scroll_offset_.x());
1002 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(
1003 viewport.width() / scrollable_size.width());
1004 }
1005 if (vertical_scrollbar_layer_) {
1006 vertical_scrollbar_layer_->SetCurrentPos(current_offset.y());
1007 vertical_scrollbar_layer_->SetMaximum(max_scroll_offset_.y());
1008 vertical_scrollbar_layer_->SetVisibleToTotalLengthRatio(
1009 viewport.height() / scrollable_size.height());
1010 }
1011
1012 if (current_offset == last_scroll_offset_)
1013 return;
1014 last_scroll_offset_ = current_offset;
1015
1016 if (scrollbar_animation_controller_) {
1017 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate(
1018 layer_tree_impl_->CurrentPhysicalTimeTicks());
1019 if (should_animate)
1020 layer_tree_impl_->StartScrollbarAnimation();
1021 }
1022
1023 // Get the current_offset_.y() value for a sanity-check on scrolling
1024 // benchmark metrics. Specifically, we want to make sure
1025 // BasicMouseWheelSmoothScrollGesture has proper scroll curves.
1026 if (layer_tree_impl()->IsActiveTree()) {
1027 TRACE_COUNTER_ID1("gpu", "scroll_offset_y", this->id(), current_offset.y());
1028 }
1029 }
1030
1031 void LayerImpl::SetScrollOffsetDelegate( 997 void LayerImpl::SetScrollOffsetDelegate(
1032 LayerScrollOffsetDelegate* scroll_offset_delegate) { 998 LayerScrollOffsetDelegate* scroll_offset_delegate) {
1033 // Having both a scroll parent and a scroll offset delegate is unsupported. 999 // Having both a scroll parent and a scroll offset delegate is unsupported.
1034 DCHECK(!scroll_parent_); 1000 DCHECK(!scroll_parent_);
1035 if (!scroll_offset_delegate && scroll_offset_delegate_) { 1001 if (!scroll_offset_delegate && scroll_offset_delegate_) {
1036 scroll_delta_ = 1002 scroll_delta_ =
1037 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 1003 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_;
1038 } 1004 }
1039 gfx::Vector2dF total_offset = TotalScrollOffset(); 1005 gfx::Vector2dF total_offset = TotalScrollOffset();
1040 scroll_offset_delegate_ = scroll_offset_delegate; 1006 scroll_offset_delegate_ = scroll_offset_delegate;
1041 if (scroll_offset_delegate_) { 1007 if (scroll_offset_delegate_)
1042 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_);
1043 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); 1008 scroll_offset_delegate_->SetTotalScrollOffset(total_offset);
1044 }
1045 } 1009 }
1046 1010
1047 bool LayerImpl::IsExternalFlingActive() const { 1011 bool LayerImpl::IsExternalFlingActive() const {
1048 return scroll_offset_delegate_ && 1012 return scroll_offset_delegate_ &&
1049 scroll_offset_delegate_->IsExternalFlingActive(); 1013 scroll_offset_delegate_->IsExternalFlingActive();
1050 } 1014 }
1051 1015
1052 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) { 1016 void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) {
1053 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); 1017 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta());
1054 } 1018 }
1055 1019
1056 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset, 1020 void LayerImpl::SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset,
1057 gfx::Vector2dF scroll_delta) { 1021 gfx::Vector2dF scroll_delta) {
1058 bool changed = false; 1022 bool changed = false;
1059 1023
1024 last_scroll_offset_ = scroll_offset;
1025
1060 if (scroll_offset_ != scroll_offset) { 1026 if (scroll_offset_ != scroll_offset) {
1061 changed = true; 1027 changed = true;
1062 scroll_offset_ = scroll_offset; 1028 scroll_offset_ = scroll_offset;
1063 1029
1064 if (scroll_offset_delegate_) 1030 if (scroll_offset_delegate_)
1065 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); 1031 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset());
1066 } 1032 }
1067 1033
1068 if (ScrollDelta() != scroll_delta) { 1034 if (ScrollDelta() != scroll_delta) {
1069 changed = true; 1035 changed = true;
(...skipping 14 matching lines...) Expand all
1084 if (scroll_offset_delegate_) { 1050 if (scroll_offset_delegate_) {
1085 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + 1051 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ +
1086 scroll_delta); 1052 scroll_delta);
1087 } else { 1053 } else {
1088 scroll_delta_ = scroll_delta; 1054 scroll_delta_ = scroll_delta;
1089 } 1055 }
1090 } 1056 }
1091 1057
1092 if (changed) { 1058 if (changed) {
1093 NoteLayerPropertyChangedForSubtree(); 1059 NoteLayerPropertyChangedForSubtree();
1094 UpdateScrollbarPositions(); 1060 ScrollbarParametersDidChange();
1095 } 1061 }
1096 } 1062 }
1097 1063
1098 gfx::Vector2dF LayerImpl::ScrollDelta() const { 1064 gfx::Vector2dF LayerImpl::ScrollDelta() const {
1099 if (scroll_offset_delegate_) 1065 if (scroll_offset_delegate_)
1100 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 1066 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_;
1101 return scroll_delta_; 1067 return scroll_delta_;
1102 } 1068 }
1103 1069
1104 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { 1070 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) {
(...skipping 15 matching lines...) Expand all
1120 Region LayerImpl::VisibleContentOpaqueRegion() const { 1086 Region LayerImpl::VisibleContentOpaqueRegion() const {
1121 if (contents_opaque()) 1087 if (contents_opaque())
1122 return visible_content_rect(); 1088 return visible_content_rect();
1123 return Region(); 1089 return Region();
1124 } 1090 }
1125 1091
1126 void LayerImpl::DidBeginTracing() {} 1092 void LayerImpl::DidBeginTracing() {}
1127 1093
1128 void LayerImpl::DidLoseOutputSurface() {} 1094 void LayerImpl::DidLoseOutputSurface() {}
1129 1095
1130 void LayerImpl::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { 1096 gfx::Vector2d LayerImpl::MaxScrollOffset() const {
1131 if (max_scroll_offset_ == max_scroll_offset) 1097 if (!clip_layer_)
1132 return; 1098 return gfx::Vector2d();
1133 max_scroll_offset_ = max_scroll_offset;
1134 1099
1135 if (scroll_offset_delegate_) 1100 gfx::Size scaled_scroll_bounds(bounds());
1136 scroll_offset_delegate_->SetMaxScrollOffset(max_scroll_offset_); 1101 LayerImpl const* current_layer = this->parent();
1102 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1103 DCHECK(this != page_scale_layer);
1104 DCHECK(clip_layer_);
1105 float scale_factor = 1.f;
1106 while (current_layer && current_layer != clip_layer_) {
1107 float current_layer_scale = 1.f;
1137 1108
1138 layer_tree_impl()->set_needs_update_draw_properties(); 1109 const gfx::Transform& layer_transform = current_layer->transform();
1139 UpdateScrollbarPositions(); 1110 if (current_layer == page_scale_layer) {
1111 DCHECK(layer_transform.IsIdentity());
1112 current_layer_scale = layer_tree_impl()->total_page_scale_factor();
1113 } else {
1114 // TODO(wjmaclean) Should we allow for translation too?
1115 DCHECK(layer_transform.IsScale());
1116 gfx::Vector2dF layer_scale = layer_transform.Scale();
1117 // TODO(wjmaclean) Allow for non-isotropic scales.
1118 DCHECK(layer_scale.x() == layer_scale.y());
1119 current_layer_scale = layer_scale.x();
1120 }
1121
1122 scale_factor *= current_layer_scale;
1123 current_layer = current_layer->parent();
1124 }
1125 DCHECK(current_layer == clip_layer_);
1126
1127 scaled_scroll_bounds.SetSize(
1128 scale_factor * scaled_scroll_bounds.width(),
1129 scale_factor * scaled_scroll_bounds.height());
1130
1131 gfx::Vector2dF max_offset(
1132 scaled_scroll_bounds.width() - clip_layer_->bounds().width(),
1133 scaled_scroll_bounds.height() - clip_layer_->bounds().height());
1134 // We need the final scroll offset to be in CSS coords.
1135 max_offset.Scale(1 / scale_factor);
1136 return gfx::Vector2d(max_offset.x(), max_offset.y());
1137 }
1138
1139 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1140 gfx::Vector2dF max_offset = MaxScrollOffset();
1141 gfx::Vector2dF old_offset = TotalScrollOffset();
1142 gfx::Vector2dF clamped_offset = old_offset;
1143
1144 clamped_offset.SetToMin(max_offset);
1145 clamped_offset.SetToMax(gfx::Vector2d());
1146 gfx::Vector2dF delta = clamped_offset - old_offset;
1147 if (!delta.IsZero())
1148 ScrollBy(delta);
1149
1150 return delta;
1151 }
1152
1153 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
1154 LayerImpl* scrollbar_clip_layer) const {
1155 DCHECK(scrollbar_layer);
1156 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1157
1158 DCHECK(this != page_scale_layer);
1159 DCHECK(scrollbar_clip_layer);
1160 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds());
1161 if (scrollbar_clip_layer == layer_tree_impl()->InnerViewportScrollLayer())
1162 clip_rect =
1163 gfx::RectF(gfx::PointF(), layer_tree_impl()->ScrollableViewportSize());
1164 gfx::RectF scroll_rect(gfx::PointF(), bounds());
1165
1166 gfx::Vector2dF current_offset = scroll_offset() + ScrollDelta();
1167
1168 // TODO(wjmaclean) This computation is nearly identical to the one in
1169 // MaxScrollOffset. Find some way to combine these.
1170 LayerImpl const* current_layer = this->parent();
1171 float scale_factor = 1.f;
1172 while (current_layer && current_layer != scrollbar_clip_layer) {
1173 const gfx::Transform& layer_transform = current_layer->transform();
1174 if (current_layer == page_scale_layer) {
1175 DCHECK(layer_transform.IsIdentity());
1176 scale_factor = layer_tree_impl()->total_page_scale_factor();
1177 current_offset.Scale(scale_factor);
1178 scroll_rect.Scale(scale_factor);
1179 } else {
1180 DCHECK(layer_transform.IsScale());
1181 gfx::Vector2dF layer_scale = layer_transform.Scale();
1182 DCHECK(layer_scale.x() == layer_scale.y());
1183 gfx::Vector2dF new_offset =
1184 current_layer->scroll_offset() + current_layer->ScrollDelta();
1185 new_offset.Scale(layer_scale.x(), layer_scale.y());
1186 current_offset += new_offset;
1187 }
1188 current_layer = current_layer->parent();
1189 }
1190 DCHECK(current_layer == scrollbar_clip_layer);
1191
1192 scrollbar_layer->SetVerticalAdjust(layer_tree_impl()->VerticalAdjust(this));
1193 if (scrollbar_layer->orientation() == HORIZONTAL) {
1194 float visible_ratio = clip_rect.width() / scroll_rect.width();
1195 scrollbar_layer->SetCurrentPos(current_offset.x());
1196 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1197 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1198 } else {
1199 float visible_ratio = clip_rect.height() / scroll_rect.height();
1200 scrollbar_layer->SetCurrentPos(current_offset.y());
1201 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1202 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1203 }
1204
1205 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars should
1206 // activate for every scroll on the main frame, not just the scrolls that move
1207 // the pinch virtual viewport (i.e. trigger from either inner or outer
1208 // viewport).
1209 if (scrollbar_animation_controller_) {
1210 bool should_animate = scrollbar_animation_controller_->DidScrollUpdate(
1211 layer_tree_impl_->CurrentPhysicalTimeTicks());
1212 if (should_animate)
1213 layer_tree_impl_->StartScrollbarAnimation();
1214 }
1140 } 1215 }
1141 1216
1142 void LayerImpl::DidBecomeActive() { 1217 void LayerImpl::DidBecomeActive() {
1143 if (layer_tree_impl_->settings().scrollbar_animator == 1218 if (layer_tree_impl_->settings().scrollbar_animator ==
1144 LayerTreeSettings::NoAnimator) { 1219 LayerTreeSettings::NoAnimator) {
1145 return; 1220 return;
1146 } 1221 }
1147 1222
1148 bool need_scrollbar_animation_controller = horizontal_scrollbar_layer_ || 1223 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
1149 vertical_scrollbar_layer_;
1150 if (!need_scrollbar_animation_controller) { 1224 if (!need_scrollbar_animation_controller) {
1151 scrollbar_animation_controller_.reset(); 1225 scrollbar_animation_controller_.reset();
1152 return; 1226 return;
1153 } 1227 }
1154 1228
1155 if (scrollbar_animation_controller_) 1229 if (scrollbar_animation_controller_)
1156 return; 1230 return;
1157 1231
1158 switch (layer_tree_impl_->settings().scrollbar_animator) { 1232 switch (layer_tree_impl_->settings().scrollbar_animator) {
1159 case LayerTreeSettings::LinearFade: { 1233 case LayerTreeSettings::LinearFade: {
(...skipping 12 matching lines...) Expand all
1172 scrollbar_animation_controller_ = 1246 scrollbar_animation_controller_ =
1173 ScrollbarAnimationControllerThinning::Create(this) 1247 ScrollbarAnimationControllerThinning::Create(this)
1174 .PassAs<ScrollbarAnimationController>(); 1248 .PassAs<ScrollbarAnimationController>();
1175 break; 1249 break;
1176 } 1250 }
1177 case LayerTreeSettings::NoAnimator: 1251 case LayerTreeSettings::NoAnimator:
1178 NOTREACHED(); 1252 NOTREACHED();
1179 break; 1253 break;
1180 } 1254 }
1181 } 1255 }
1182 void LayerImpl::SetHorizontalScrollbarLayer( 1256
1183 ScrollbarLayerImplBase* scrollbar_layer) { 1257 void LayerImpl::ClearScrollbars() {
1184 horizontal_scrollbar_layer_ = scrollbar_layer; 1258 if (!scrollbars_)
1185 if (horizontal_scrollbar_layer_) 1259 return;
1186 horizontal_scrollbar_layer_->set_scroll_layer_id(id()); 1260
1261 scrollbars_.reset(NULL);
1187 } 1262 }
1188 1263
1189 void LayerImpl::SetVerticalScrollbarLayer( 1264 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1190 ScrollbarLayerImplBase* scrollbar_layer) { 1265 DCHECK(layer);
1191 vertical_scrollbar_layer_ = scrollbar_layer; 1266 if (!scrollbars_)
1192 if (vertical_scrollbar_layer_) 1267 scrollbars_.reset(new ScrollbarSet());
1193 vertical_scrollbar_layer_->set_scroll_layer_id(id()); 1268
1269 scrollbars_->insert(layer);
1270 }
1271
1272 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1273 DCHECK(scrollbars_);
1274 DCHECK(layer);
1275
1276 scrollbars_->erase(layer);
1277 if (scrollbars_->empty())
1278 scrollbars_.reset();
1279 }
1280
1281 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1282 if (!scrollbars_)
1283 return false;
1284
1285 for (ScrollbarSet::iterator it = scrollbars_->begin();
1286 it != scrollbars_->end(); ++it)
1287 if ((*it)->orientation() == orientation)
1288 return true;
1289
1290 return false;
1291 }
1292
1293 void LayerImpl::ScrollbarParametersDidChange() {
1294 if (!scrollbars_)
1295 return;
1296
1297 for (ScrollbarSet::iterator it = scrollbars_->begin();
1298 it != scrollbars_->end(); ++it)
1299 (*it)->ScrollbarParametersDidChange();
1194 } 1300 }
1195 1301
1196 static scoped_ptr<base::Value> 1302 static scoped_ptr<base::Value>
1197 CompositingReasonsAsValue(CompositingReasons reasons) { 1303 CompositingReasonsAsValue(CompositingReasons reasons) {
1198 scoped_ptr<base::ListValue> reason_list(new base::ListValue()); 1304 scoped_ptr<base::ListValue> reason_list(new base::ListValue());
1199 1305
1200 if (reasons == kCompositingReasonUnknown) { 1306 if (reasons == kCompositingReasonUnknown) {
1201 reason_list->AppendString("No reasons given"); 1307 reason_list->AppendString("No reasons given");
1202 return reason_list.PassAs<base::Value>(); 1308 return reason_list.PassAs<base::Value>();
1203 } 1309 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); 1503 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
1398 AsValueInto(state.get()); 1504 AsValueInto(state.get());
1399 return state.PassAs<base::Value>(); 1505 return state.PassAs<base::Value>();
1400 } 1506 }
1401 1507
1402 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { 1508 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1403 benchmark->RunOnLayer(this); 1509 benchmark->RunOnLayer(this);
1404 } 1510 }
1405 1511
1406 } // namespace cc 1512 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698