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

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

Powered by Google App Engine
This is Rietveld 408576698