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

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

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 years, 2 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
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/debug/trace_event_argument.h" 8 #include "base/debug/trace_event_argument.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const { 348 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
349 return RenderPassId(0, 0); 349 return RenderPassId(0, 0);
350 } 350 }
351 351
352 ResourceProvider::ResourceId LayerImpl::ContentsResourceId() const { 352 ResourceProvider::ResourceId LayerImpl::ContentsResourceId() const {
353 NOTREACHED(); 353 NOTREACHED();
354 return 0; 354 return 0;
355 } 355 }
356 356
357 void LayerImpl::SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta) { 357 void LayerImpl::SetSentScrollDelta(const gfx::Vector2dF& sent_scroll_delta) {
358 // Pending tree never has sent scroll deltas 358 // Pending tree never has sent scroll deltas
359 DCHECK(layer_tree_impl()->IsActiveTree()); 359 DCHECK(layer_tree_impl()->IsActiveTree());
360 360
361 if (sent_scroll_delta_ == sent_scroll_delta) 361 if (sent_scroll_delta_ == sent_scroll_delta)
362 return; 362 return;
363 363
364 sent_scroll_delta_ = sent_scroll_delta; 364 sent_scroll_delta_ = sent_scroll_delta;
365 } 365 }
366 366
367 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { 367 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
368 DCHECK(scrollable()); 368 DCHECK(scrollable());
369 gfx::Vector2dF min_delta = -scroll_offset_; 369 gfx::Vector2dF min_delta = -ScrollOffsetToVector2dF(scroll_offset_);
370 gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_; 370 gfx::Vector2dF max_delta = MaxScrollOffset().DeltaFrom(scroll_offset_);
371 // Clamp new_delta so that position + delta stays within scroll bounds. 371 // Clamp new_delta so that position + delta stays within scroll bounds.
372 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); 372 gfx::Vector2dF new_delta = (ScrollDelta() + scroll);
373 new_delta.SetToMax(min_delta); 373 new_delta.SetToMax(min_delta);
374 new_delta.SetToMin(max_delta); 374 new_delta.SetToMin(max_delta);
375 gfx::Vector2dF unscrolled = 375 gfx::Vector2dF unscrolled =
376 ScrollDelta() + scroll - new_delta; 376 ScrollDelta() + scroll - new_delta;
377 SetScrollDelta(new_delta); 377 SetScrollDelta(new_delta);
378 378
379 return unscrolled; 379 return unscrolled;
380 } 380 }
(...skipping 10 matching lines...) Expand all
391 // main thread had applied them and then committed those values. 391 // main thread had applied them and then committed those values.
392 // 392 //
393 // This function should not change the total scroll offset; it just shifts 393 // This function should not change the total scroll offset; it just shifts
394 // some of the scroll delta to the scroll offset. Therefore, adjust these 394 // some of the scroll delta to the scroll offset. Therefore, adjust these
395 // variables directly rather than calling the scroll offset delegate to 395 // variables directly rather than calling the scroll offset delegate to
396 // avoid sending it multiple spurious calls. 396 // avoid sending it multiple spurious calls.
397 // 397 //
398 // Because of the way scroll delta is calculated with a delegate, this will 398 // Because of the way scroll delta is calculated with a delegate, this will
399 // leave the total scroll offset unchanged on this layer regardless of 399 // leave the total scroll offset unchanged on this layer regardless of
400 // whether a delegate is being used. 400 // whether a delegate is being used.
401 scroll_offset_ += sent_scroll_delta_; 401 scroll_offset_ += gfx::ScrollOffset(sent_scroll_delta_);
402 scroll_delta_ -= sent_scroll_delta_; 402 scroll_delta_ -= sent_scroll_delta_;
403 sent_scroll_delta_ = gfx::Vector2d(); 403 sent_scroll_delta_ = gfx::Vector2dF();
404 } 404 }
405 405
406 void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() { 406 void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() {
407 // Only the pending tree can have missing scrolls. 407 // Only the pending tree can have missing scrolls.
408 DCHECK(layer_tree_impl()->IsPendingTree()); 408 DCHECK(layer_tree_impl()->IsPendingTree());
409 if (!scrollable()) 409 if (!scrollable())
410 return; 410 return;
411 411
412 // Pending tree should never have sent scroll deltas. 412 // Pending tree should never have sent scroll deltas.
413 DCHECK(sent_scroll_delta().IsZero()); 413 DCHECK(sent_scroll_delta().IsZero());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { 465 if (type == InputHandler::Wheel && have_wheel_event_handlers()) {
466 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); 466 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
467 return InputHandler::ScrollOnMainThread; 467 return InputHandler::ScrollOnMainThread;
468 } 468 }
469 469
470 if (!scrollable()) { 470 if (!scrollable()) {
471 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); 471 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
472 return InputHandler::ScrollIgnored; 472 return InputHandler::ScrollIgnored;
473 } 473 }
474 474
475 gfx::Vector2d max_scroll_offset = MaxScrollOffset(); 475 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
476 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { 476 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
477 TRACE_EVENT0("cc", 477 TRACE_EVENT0("cc",
478 "LayerImpl::tryScroll: Ignored. Technically scrollable," 478 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
479 " but has no affordance in either direction."); 479 " but has no affordance in either direction.");
480 return InputHandler::ScrollIgnored; 480 return InputHandler::ScrollIgnored;
481 } 481 }
482 482
483 return InputHandler::ScrollStarted; 483 return InputHandler::ScrollStarted;
484 } 484 }
485 485
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 layer->SetPositionConstraint(position_constraint_); 531 layer->SetPositionConstraint(position_constraint_);
532 layer->SetShouldFlattenTransform(should_flatten_transform_); 532 layer->SetShouldFlattenTransform(should_flatten_transform_);
533 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 533 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
534 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); 534 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
535 535
536 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() 536 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
537 : Layer::INVALID_ID); 537 : Layer::INVALID_ID);
538 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); 538 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
539 layer->set_user_scrollable_vertical(user_scrollable_vertical_); 539 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
540 layer->SetScrollOffsetAndDelta( 540 layer->SetScrollOffsetAndDelta(
541 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); 541 scroll_offset_,
542 layer->SetSentScrollDelta(gfx::Vector2d()); 542 layer->ScrollDelta() - layer->sent_scroll_delta());
543 layer->SetSentScrollDelta(gfx::Vector2dF());
543 layer->Set3dSortingContextId(sorting_context_id_); 544 layer->Set3dSortingContextId(sorting_context_id_);
544 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); 545 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
545 546
546 LayerImpl* scroll_parent = NULL; 547 LayerImpl* scroll_parent = NULL;
547 if (scroll_parent_) { 548 if (scroll_parent_) {
548 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); 549 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
549 DCHECK(scroll_parent); 550 DCHECK(scroll_parent);
550 } 551 }
551 552
552 layer->SetScrollParent(scroll_parent); 553 layer->SetScrollParent(scroll_parent);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 replica_layer_->ResetAllChangeTrackingForSubtree(); 730 replica_layer_->ResetAllChangeTrackingForSubtree();
730 } 731 }
731 732
732 for (size_t i = 0; i < children_.size(); ++i) 733 for (size_t i = 0; i < children_.size(); ++i)
733 children_[i]->ResetAllChangeTrackingForSubtree(); 734 children_[i]->ResetAllChangeTrackingForSubtree();
734 735
735 needs_push_properties_ = false; 736 needs_push_properties_ = false;
736 num_dependents_need_push_properties_ = 0; 737 num_dependents_need_push_properties_ = 0;
737 } 738 }
738 739
739 gfx::Vector2dF LayerImpl::ScrollOffsetForAnimation() const { 740 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
740 return TotalScrollOffset(); 741 return TotalScrollOffset();
741 } 742 }
742 743
743 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { 744 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
744 SetFilters(filters); 745 SetFilters(filters);
745 } 746 }
746 747
747 void LayerImpl::OnOpacityAnimated(float opacity) { 748 void LayerImpl::OnOpacityAnimated(float opacity) {
748 SetOpacity(opacity); 749 SetOpacity(opacity);
749 } 750 }
750 751
751 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { 752 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
752 SetTransform(transform); 753 SetTransform(transform);
753 } 754 }
754 755
755 void LayerImpl::OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) { 756 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
756 // Only layers in the active tree should need to do anything here, since 757 // Only layers in the active tree should need to do anything here, since
757 // layers in the pending tree will find out about these changes as a 758 // layers in the pending tree will find out about these changes as a
758 // result of the call to SetScrollDelta. 759 // result of the call to SetScrollDelta.
759 if (!IsActive()) 760 if (!IsActive())
760 return; 761 return;
761 762
762 SetScrollDelta(scroll_offset - scroll_offset_); 763 SetScrollDelta(scroll_offset.DeltaFrom(scroll_offset_));
763 764
764 layer_tree_impl_->DidAnimateScrollOffset(); 765 layer_tree_impl_->DidAnimateScrollOffset();
765 } 766 }
766 767
767 void LayerImpl::OnAnimationWaitingForDeletion() {} 768 void LayerImpl::OnAnimationWaitingForDeletion() {}
768 769
769 bool LayerImpl::IsActive() const { 770 bool LayerImpl::IsActive() const {
770 return layer_tree_impl_->IsActiveTree(); 771 return layer_tree_impl_->IsActiveTree();
771 } 772 }
772 773
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 draw_properties_.contents_scale_x = contents_scale_x; 1058 draw_properties_.contents_scale_x = contents_scale_x;
1058 draw_properties_.contents_scale_y = contents_scale_y; 1059 draw_properties_.contents_scale_y = contents_scale_y;
1059 NoteLayerPropertyChanged(); 1060 NoteLayerPropertyChanged();
1060 } 1061 }
1061 1062
1062 void LayerImpl::SetScrollOffsetDelegate( 1063 void LayerImpl::SetScrollOffsetDelegate(
1063 ScrollOffsetDelegate* scroll_offset_delegate) { 1064 ScrollOffsetDelegate* scroll_offset_delegate) {
1064 // Having both a scroll parent and a scroll offset delegate is unsupported. 1065 // Having both a scroll parent and a scroll offset delegate is unsupported.
1065 DCHECK(!scroll_parent_); 1066 DCHECK(!scroll_parent_);
1066 if (!scroll_offset_delegate && scroll_offset_delegate_) { 1067 if (!scroll_offset_delegate && scroll_offset_delegate_) {
1067 scroll_delta_ = 1068 scroll_delta_ = scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom(
1068 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 1069 scroll_offset_);
1069 } 1070 }
1070 gfx::Vector2dF total_offset = TotalScrollOffset(); 1071 gfx::ScrollOffset total_offset = TotalScrollOffset();
1071 scroll_offset_delegate_ = scroll_offset_delegate; 1072 scroll_offset_delegate_ = scroll_offset_delegate;
1072 if (scroll_offset_delegate_) 1073 if (scroll_offset_delegate_)
1073 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); 1074 scroll_offset_delegate_->SetTotalScrollOffset(total_offset);
1074 } 1075 }
1075 1076
1076 bool LayerImpl::IsExternalFlingActive() const { 1077 bool LayerImpl::IsExternalFlingActive() const {
1077 return scroll_offset_delegate_ && 1078 return scroll_offset_delegate_ &&
1078 scroll_offset_delegate_->IsExternalFlingActive(); 1079 scroll_offset_delegate_->IsExternalFlingActive();
1079 } 1080 }
1080 1081
1081 void LayerImpl::SetScrollOffset(const gfx::Vector2d& scroll_offset) { 1082 void LayerImpl::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1082 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); 1083 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta());
1083 } 1084 }
1084 1085
1085 void LayerImpl::SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, 1086 void LayerImpl::SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset,
1086 const gfx::Vector2dF& scroll_delta) { 1087 const gfx::Vector2dF& scroll_delta) {
1087 bool changed = false; 1088 bool changed = false;
1088 1089
1089 last_scroll_offset_ = scroll_offset; 1090 last_scroll_offset_ = scroll_offset;
1090 1091
1091 if (scroll_offset_ != scroll_offset) { 1092 if (scroll_offset_ != scroll_offset) {
1092 changed = true; 1093 changed = true;
1093 scroll_offset_ = scroll_offset; 1094 scroll_offset_ = scroll_offset;
1094 1095
1095 if (scroll_offset_delegate_) 1096 if (scroll_offset_delegate_)
(...skipping 10 matching lines...) Expand all
1106 // layer. Although the delta - sent scroll delta difference is 1107 // layer. Although the delta - sent scroll delta difference is
1107 // identical for both twins, the sent scroll delta for the pending 1108 // identical for both twins, the sent scroll delta for the pending
1108 // layer is zero, as anything that has been sent has been baked 1109 // layer is zero, as anything that has been sent has been baked
1109 // into the layer's position/scroll offset as a part of commit. 1110 // into the layer's position/scroll offset as a part of commit.
1110 DCHECK(pending_twin->sent_scroll_delta().IsZero()); 1111 DCHECK(pending_twin->sent_scroll_delta().IsZero());
1111 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta()); 1112 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta());
1112 } 1113 }
1113 } 1114 }
1114 1115
1115 if (scroll_offset_delegate_) { 1116 if (scroll_offset_delegate_) {
1116 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + 1117 scroll_offset_delegate_->SetTotalScrollOffset(
1117 scroll_delta); 1118 ScrollOffsetWithDelta(scroll_offset_, scroll_delta));
1118 } else { 1119 } else {
1119 scroll_delta_ = scroll_delta; 1120 scroll_delta_ = scroll_delta;
1120 } 1121 }
1121 } 1122 }
1122 1123
1123 if (changed) { 1124 if (changed) {
1124 NoteLayerPropertyChangedForSubtree(); 1125 NoteLayerPropertyChangedForSubtree();
1125 ScrollbarParametersDidChange(); 1126 ScrollbarParametersDidChange();
1126 } 1127 }
1127 } 1128 }
1128 1129
1129 gfx::Vector2dF LayerImpl::ScrollDelta() const { 1130 gfx::Vector2dF LayerImpl::ScrollDelta() const {
1130 if (scroll_offset_delegate_) 1131 if (scroll_offset_delegate_) {
1131 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; 1132 return scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom(
1133 scroll_offset_);
1134 }
1132 return scroll_delta_; 1135 return scroll_delta_;
1133 } 1136 }
1134 1137
1135 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { 1138 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) {
1136 SetScrollOffsetAndDelta(scroll_offset_, scroll_delta); 1139 SetScrollOffsetAndDelta(scroll_offset_, scroll_delta);
1137 } 1140 }
1138 1141
1139 gfx::Vector2dF LayerImpl::TotalScrollOffset() const { 1142 gfx::ScrollOffset LayerImpl::TotalScrollOffset() const {
1140 return scroll_offset_ + ScrollDelta(); 1143 return ScrollOffsetWithDelta(scroll_offset_, ScrollDelta());
1141 } 1144 }
1142 1145
1143 void LayerImpl::SetDoubleSided(bool double_sided) { 1146 void LayerImpl::SetDoubleSided(bool double_sided) {
1144 if (double_sided_ == double_sided) 1147 if (double_sided_ == double_sided)
1145 return; 1148 return;
1146 1149
1147 double_sided_ = double_sided; 1150 double_sided_ = double_sided;
1148 NoteLayerPropertyChangedForSubtree(); 1151 NoteLayerPropertyChangedForSubtree();
1149 } 1152 }
1150 1153
1151 SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const { 1154 SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const {
1152 if (contents_opaque()) 1155 if (contents_opaque())
1153 return SimpleEnclosedRegion(visible_content_rect()); 1156 return SimpleEnclosedRegion(visible_content_rect());
1154 return SimpleEnclosedRegion(); 1157 return SimpleEnclosedRegion();
1155 } 1158 }
1156 1159
1157 void LayerImpl::DidBeginTracing() {} 1160 void LayerImpl::DidBeginTracing() {}
1158 1161
1159 void LayerImpl::ReleaseResources() {} 1162 void LayerImpl::ReleaseResources() {}
1160 1163
1161 gfx::Vector2d LayerImpl::MaxScrollOffset() const { 1164 gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
1162 if (!scroll_clip_layer_ || bounds().IsEmpty()) 1165 if (!scroll_clip_layer_ || bounds().IsEmpty())
1163 return gfx::Vector2d(); 1166 return gfx::ScrollOffset();
1164 1167
1165 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); 1168 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1166 DCHECK(this != page_scale_layer); 1169 DCHECK(this != page_scale_layer);
1167 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || 1170 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1168 IsContainerForFixedPositionLayers()); 1171 IsContainerForFixedPositionLayers());
1169 1172
1170 gfx::SizeF scaled_scroll_bounds(bounds()); 1173 gfx::SizeF scaled_scroll_bounds(bounds());
1171 1174
1172 float scale_factor = 1.f; 1175 float scale_factor = 1.f;
1173 for (LayerImpl const* current_layer = this; 1176 for (LayerImpl const* current_layer = this;
(...skipping 21 matching lines...) Expand all
1195 // turned on in all builds, remove the next two lines. For now however, the 1198 // turned on in all builds, remove the next two lines. For now however, the
1196 // page scale layer may coincide with the clip layer, and so this is 1199 // page scale layer may coincide with the clip layer, and so this is
1197 // necessary. 1200 // necessary.
1198 if (page_scale_layer == scroll_clip_layer_) 1201 if (page_scale_layer == scroll_clip_layer_)
1199 scale_factor *= layer_tree_impl()->total_page_scale_factor(); 1202 scale_factor *= layer_tree_impl()->total_page_scale_factor();
1200 1203
1201 scaled_scroll_bounds.SetSize(scale_factor * scaled_scroll_bounds.width(), 1204 scaled_scroll_bounds.SetSize(scale_factor * scaled_scroll_bounds.width(),
1202 scale_factor * scaled_scroll_bounds.height()); 1205 scale_factor * scaled_scroll_bounds.height());
1203 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); 1206 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
1204 1207
1205 gfx::Vector2dF max_offset( 1208 gfx::ScrollOffset max_offset(
1206 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), 1209 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1207 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); 1210 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1208 // We need the final scroll offset to be in CSS coords. 1211 // We need the final scroll offset to be in CSS coords.
1209 max_offset.Scale(1 / scale_factor); 1212 max_offset.Scale(1 / scale_factor);
1210 max_offset.SetToMax(gfx::Vector2dF()); 1213 max_offset.SetToMax(gfx::ScrollOffset());
1211 return gfx::ToFlooredVector2d(max_offset); 1214 return max_offset;
1212 } 1215 }
1213 1216
1214 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { 1217 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1215 gfx::Vector2dF max_offset = MaxScrollOffset(); 1218 gfx::ScrollOffset max_offset = MaxScrollOffset();
1216 gfx::Vector2dF old_offset = TotalScrollOffset(); 1219 gfx::ScrollOffset old_offset = TotalScrollOffset();
1217 gfx::Vector2dF clamped_offset = old_offset; 1220 gfx::ScrollOffset clamped_offset = old_offset;
1218 1221
1219 clamped_offset.SetToMin(max_offset); 1222 clamped_offset.SetToMin(max_offset);
1220 clamped_offset.SetToMax(gfx::Vector2d()); 1223 clamped_offset.SetToMax(gfx::ScrollOffset());
1221 gfx::Vector2dF delta = clamped_offset - old_offset; 1224 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
1222 if (!delta.IsZero()) 1225 if (!delta.IsZero())
1223 ScrollBy(delta); 1226 ScrollBy(delta);
1224 1227
1225 return delta; 1228 return delta;
1226 } 1229 }
1227 1230
1228 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, 1231 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
1229 LayerImpl* scrollbar_clip_layer) const { 1232 LayerImpl* scrollbar_clip_layer) const {
1230 DCHECK(scrollbar_layer); 1233 DCHECK(scrollbar_layer);
1231 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); 1234 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1232 1235
1233 DCHECK(this != page_scale_layer); 1236 DCHECK(this != page_scale_layer);
1234 DCHECK(scrollbar_clip_layer); 1237 DCHECK(scrollbar_clip_layer);
1235 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || 1238 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1236 IsContainerForFixedPositionLayers()); 1239 IsContainerForFixedPositionLayers());
1237 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds()); 1240 gfx::RectF clip_rect(gfx::PointF(), scrollbar_clip_layer->bounds());
1238 1241
1239 // See comment in MaxScrollOffset() regarding the use of the content layer 1242 // See comment in MaxScrollOffset() regarding the use of the content layer
1240 // bounds here. 1243 // bounds here.
1241 gfx::RectF scroll_rect(gfx::PointF(), bounds()); 1244 gfx::RectF scroll_rect(gfx::PointF(), bounds());
1242 1245
1243 if (scroll_rect.size().IsEmpty()) 1246 if (scroll_rect.size().IsEmpty())
1244 return; 1247 return;
1245 1248
1246 // TODO(wjmaclean) This computation is nearly identical to the one in 1249 // TODO(wjmaclean) This computation is nearly identical to the one in
1247 // MaxScrollOffset. Find some way to combine these. 1250 // MaxScrollOffset. Find some way to combine these.
1248 gfx::Vector2dF current_offset; 1251 gfx::ScrollOffset current_offset;
1249 for (LayerImpl const* current_layer = this; 1252 for (LayerImpl const* current_layer = this;
1250 current_layer != scrollbar_clip_layer; 1253 current_layer != scrollbar_clip_layer;
1251 current_layer = current_layer->parent()) { 1254 current_layer = current_layer->parent()) {
1252 DCHECK(current_layer); 1255 DCHECK(current_layer);
1253 const gfx::Transform& layer_transform = current_layer->transform(); 1256 const gfx::Transform& layer_transform = current_layer->transform();
1254 if (current_layer == page_scale_layer) { 1257 if (current_layer == page_scale_layer) {
1255 DCHECK(layer_transform.IsIdentity()); 1258 DCHECK(layer_transform.IsIdentity());
1256 float scale_factor = layer_tree_impl()->total_page_scale_factor(); 1259 float scale_factor = layer_tree_impl()->total_page_scale_factor();
1257 current_offset.Scale(scale_factor); 1260 current_offset.Scale(scale_factor);
1258 scroll_rect.Scale(scale_factor); 1261 scroll_rect.Scale(scale_factor);
1259 } else { 1262 } else {
1260 DCHECK(layer_transform.IsScale2d()); 1263 DCHECK(layer_transform.IsScale2d());
1261 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); 1264 gfx::Vector2dF layer_scale = layer_transform.Scale2d();
1262 DCHECK(layer_scale.x() == layer_scale.y()); 1265 DCHECK(layer_scale.x() == layer_scale.y());
1263 gfx::Vector2dF new_offset = 1266 gfx::ScrollOffset new_offset = ScrollOffsetWithDelta(
1264 current_layer->scroll_offset() + current_layer->ScrollDelta(); 1267 current_layer->scroll_offset(), current_layer->ScrollDelta());
1265 new_offset.Scale(layer_scale.x(), layer_scale.y()); 1268 new_offset.Scale(layer_scale.x(), layer_scale.y());
1266 current_offset += new_offset; 1269 current_offset += new_offset;
1267 } 1270 }
1268 } 1271 }
1269 // TODO(wjmaclean) Once we move to a model where the two-viewport model is 1272 // TODO(wjmaclean) Once we move to a model where the two-viewport model is
1270 // turned on in all builds, remove the next two lines. For now however, the 1273 // turned on in all builds, remove the next two lines. For now however, the
1271 // page scale layer may coincide with the clip layer, and so this is 1274 // page scale layer may coincide with the clip layer, and so this is
1272 // necessary. 1275 // necessary.
1273 if (page_scale_layer == scrollbar_clip_layer) { 1276 if (page_scale_layer == scrollbar_clip_layer) {
1274 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor()); 1277 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor());
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 } 1552 }
1550 1553
1551 void LayerImpl::NotifyAnimationFinished( 1554 void LayerImpl::NotifyAnimationFinished(
1552 base::TimeTicks monotonic_time, 1555 base::TimeTicks monotonic_time,
1553 Animation::TargetProperty target_property) { 1556 Animation::TargetProperty target_property) {
1554 if (target_property == Animation::ScrollOffset) 1557 if (target_property == Animation::ScrollOffset)
1555 layer_tree_impl_->InputScrollAnimationFinished(); 1558 layer_tree_impl_->InputScrollAnimationFinished();
1556 } 1559 }
1557 1560
1558 } // namespace cc 1561 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698