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

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.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/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_perftest.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 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/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 scoped_ptr<LayerImpl> root = 231 scoped_ptr<LayerImpl> root =
232 LayerImpl::Create(layer_tree_impl, 1); 232 LayerImpl::Create(layer_tree_impl, 1);
233 root->SetBounds(content_size); 233 root->SetBounds(content_size);
234 root->SetContentBounds(content_size); 234 root->SetContentBounds(content_size);
235 root->SetPosition(gfx::PointF()); 235 root->SetPosition(gfx::PointF());
236 236
237 scoped_ptr<LayerImpl> scroll = 237 scoped_ptr<LayerImpl> scroll =
238 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); 238 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId);
239 LayerImpl* scroll_layer = scroll.get(); 239 LayerImpl* scroll_layer = scroll.get();
240 scroll->SetIsContainerForFixedPositionLayers(true); 240 scroll->SetIsContainerForFixedPositionLayers(true);
241 scroll->SetScrollOffset(gfx::Vector2d()); 241 scroll->SetScrollOffset(gfx::ScrollOffset());
242 242
243 scoped_ptr<LayerImpl> clip = 243 scoped_ptr<LayerImpl> clip =
244 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); 244 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId);
245 clip->SetBounds( 245 clip->SetBounds(
246 gfx::Size(content_size.width() / 2, content_size.height() / 2)); 246 gfx::Size(content_size.width() / 2, content_size.height() / 2));
247 247
248 scoped_ptr<LayerImpl> page_scale = 248 scoped_ptr<LayerImpl> page_scale =
249 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); 249 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId);
250 250
251 scroll->SetScrollClipLayer(clip->id()); 251 scroll->SetScrollClipLayer(clip->id());
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 scroll_info = host_impl_->ProcessScrollDeltas(); 452 scroll_info = host_impl_->ProcessScrollDeltas();
453 ASSERT_EQ(scroll_info->scrolls.size(), 0u); 453 ASSERT_EQ(scroll_info->scrolls.size(), 0u);
454 ExpectClearedScrollDeltasRecursive(root); 454 ExpectClearedScrollDeltasRecursive(root);
455 455
456 scroll_info = host_impl_->ProcessScrollDeltas(); 456 scroll_info = host_impl_->ProcessScrollDeltas();
457 ASSERT_EQ(scroll_info->scrolls.size(), 0u); 457 ASSERT_EQ(scroll_info->scrolls.size(), 0u);
458 ExpectClearedScrollDeltasRecursive(root); 458 ExpectClearedScrollDeltasRecursive(root);
459 } 459 }
460 460
461 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { 461 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) {
462 gfx::Vector2d scroll_offset(20, 30); 462 gfx::ScrollOffset scroll_offset(20, 30);
463 gfx::Vector2d scroll_delta(11, -15); 463 gfx::Vector2d scroll_delta(11, -15);
464 { 464 {
465 scoped_ptr<LayerImpl> root_clip = 465 scoped_ptr<LayerImpl> root_clip =
466 LayerImpl::Create(host_impl_->active_tree(), 2); 466 LayerImpl::Create(host_impl_->active_tree(), 2);
467 scoped_ptr<LayerImpl> root = 467 scoped_ptr<LayerImpl> root =
468 LayerImpl::Create(host_impl_->active_tree(), 1); 468 LayerImpl::Create(host_impl_->active_tree(), 1);
469 root_clip->SetBounds(gfx::Size(10, 10)); 469 root_clip->SetBounds(gfx::Size(10, 10));
470 LayerImpl* root_layer = root.get(); 470 LayerImpl* root_layer = root.get();
471 root_clip->AddChild(root.Pass()); 471 root_clip->AddChild(root.Pass());
472 root_layer->SetBounds(gfx::Size(110, 110)); 472 root_layer->SetBounds(gfx::Size(110, 110));
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { 828 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) {
829 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); 829 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200));
830 host_impl_->SetViewportSize(gfx::Size(100, 100)); 830 host_impl_->SetViewportSize(gfx::Size(100, 100));
831 831
832 gfx::Size overflow_size(400, 400); 832 gfx::Size overflow_size(400, 400);
833 ASSERT_EQ(1u, scroll_layer->children().size()); 833 ASSERT_EQ(1u, scroll_layer->children().size());
834 LayerImpl* overflow = scroll_layer->children()[0]; 834 LayerImpl* overflow = scroll_layer->children()[0];
835 overflow->SetBounds(overflow_size); 835 overflow->SetBounds(overflow_size);
836 overflow->SetContentBounds(overflow_size); 836 overflow->SetContentBounds(overflow_size);
837 overflow->SetScrollClipLayer(scroll_layer->parent()->id()); 837 overflow->SetScrollClipLayer(scroll_layer->parent()->id());
838 overflow->SetScrollOffset(gfx::Vector2d()); 838 overflow->SetScrollOffset(gfx::ScrollOffset());
839 overflow->SetPosition(gfx::PointF()); 839 overflow->SetPosition(gfx::PointF());
840 840
841 DrawFrame(); 841 DrawFrame();
842 gfx::Point scroll_position(10, 10); 842 gfx::Point scroll_position(10, 10);
843 843
844 EXPECT_EQ(InputHandler::ScrollStarted, 844 EXPECT_EQ(InputHandler::ScrollStarted,
845 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); 845 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel));
846 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); 846 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset());
847 EXPECT_VECTOR_EQ(gfx::Vector2dF(), overflow->TotalScrollOffset()); 847 EXPECT_VECTOR_EQ(gfx::Vector2dF(), overflow->TotalScrollOffset());
848 848
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 host_impl_->ScrollEnd(); 928 host_impl_->ScrollEnd();
929 EXPECT_FALSE(did_request_animate_); 929 EXPECT_FALSE(did_request_animate_);
930 EXPECT_TRUE(did_request_redraw_); 930 EXPECT_TRUE(did_request_redraw_);
931 EXPECT_TRUE(did_request_commit_); 931 EXPECT_TRUE(did_request_commit_);
932 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 932 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
933 933
934 scoped_ptr<ScrollAndScaleSet> scroll_info = 934 scoped_ptr<ScrollAndScaleSet> scroll_info =
935 host_impl_->ProcessScrollDeltas(); 935 host_impl_->ProcessScrollDeltas();
936 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 936 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
937 937
938 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), 938 EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(),
939 scroll_layer->MaxScrollOffset().ToString()); 939 scroll_layer->MaxScrollOffset().ToString());
940 } 940 }
941 941
942 // Scrolling after a pinch gesture should always be in local space. The 942 // Scrolling after a pinch gesture should always be in local space. The
943 // scroll deltas do not have the page scale factor applied. 943 // scroll deltas do not have the page scale factor applied.
944 { 944 {
945 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 945 host_impl_->active_tree()->SetPageScaleFactorAndLimits(
946 page_scale_factor, min_page_scale, max_page_scale); 946 page_scale_factor, min_page_scale, max_page_scale);
947 host_impl_->active_tree()->SetPageScaleDelta(1.f); 947 host_impl_->active_tree()->SetPageScaleDelta(1.f);
948 scroll_layer->SetScrollDelta(gfx::Vector2d()); 948 scroll_layer->SetScrollDelta(gfx::Vector2d());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 host_impl_->ProcessScrollDeltas(); 1038 host_impl_->ProcessScrollDeltas();
1039 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); 1039 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale);
1040 } 1040 }
1041 1041
1042 // Zoom-out clamping 1042 // Zoom-out clamping
1043 { 1043 {
1044 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1044 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1045 min_page_scale, 1045 min_page_scale,
1046 max_page_scale); 1046 max_page_scale);
1047 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1047 scroll_layer->SetScrollDelta(gfx::Vector2d());
1048 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1048 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1049 1049
1050 float page_scale_delta = 0.1f; 1050 float page_scale_delta = 0.1f;
1051 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 1051 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
1052 host_impl_->PinchGestureBegin(); 1052 host_impl_->PinchGestureBegin();
1053 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); 1053 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point());
1054 host_impl_->PinchGestureEnd(); 1054 host_impl_->PinchGestureEnd();
1055 host_impl_->ScrollEnd(); 1055 host_impl_->ScrollEnd();
1056 1056
1057 scoped_ptr<ScrollAndScaleSet> scroll_info = 1057 scoped_ptr<ScrollAndScaleSet> scroll_info =
1058 host_impl_->ProcessScrollDeltas(); 1058 host_impl_->ProcessScrollDeltas();
1059 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); 1059 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale);
1060 1060
1061 EXPECT_TRUE(scroll_info->scrolls.empty()); 1061 EXPECT_TRUE(scroll_info->scrolls.empty());
1062 } 1062 }
1063 1063
1064 // Two-finger panning should not happen based on pinch events only 1064 // Two-finger panning should not happen based on pinch events only
1065 { 1065 {
1066 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1066 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1067 min_page_scale, 1067 min_page_scale,
1068 max_page_scale); 1068 max_page_scale);
1069 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1069 scroll_layer->SetScrollDelta(gfx::Vector2d());
1070 scroll_layer->SetScrollOffset(gfx::Vector2d(20, 20)); 1070 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1071 1071
1072 float page_scale_delta = 1.f; 1072 float page_scale_delta = 1.f;
1073 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1073 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1074 host_impl_->PinchGestureBegin(); 1074 host_impl_->PinchGestureBegin();
1075 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1075 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1076 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1076 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1077 host_impl_->PinchGestureEnd(); 1077 host_impl_->PinchGestureEnd();
1078 host_impl_->ScrollEnd(); 1078 host_impl_->ScrollEnd();
1079 1079
1080 scoped_ptr<ScrollAndScaleSet> scroll_info = 1080 scoped_ptr<ScrollAndScaleSet> scroll_info =
1081 host_impl_->ProcessScrollDeltas(); 1081 host_impl_->ProcessScrollDeltas();
1082 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1082 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1083 EXPECT_TRUE(scroll_info->scrolls.empty()); 1083 EXPECT_TRUE(scroll_info->scrolls.empty());
1084 } 1084 }
1085 1085
1086 // Two-finger panning should work with interleaved scroll events 1086 // Two-finger panning should work with interleaved scroll events
1087 { 1087 {
1088 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1088 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1089 min_page_scale, 1089 min_page_scale,
1090 max_page_scale); 1090 max_page_scale);
1091 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1091 scroll_layer->SetScrollDelta(gfx::Vector2d());
1092 scroll_layer->SetScrollOffset(gfx::Vector2d(20, 20)); 1092 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1093 1093
1094 float page_scale_delta = 1.f; 1094 float page_scale_delta = 1.f;
1095 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1095 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1096 host_impl_->PinchGestureBegin(); 1096 host_impl_->PinchGestureBegin();
1097 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1097 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1098 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10)); 1098 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10));
1099 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1099 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1100 host_impl_->PinchGestureEnd(); 1100 host_impl_->PinchGestureEnd();
1101 host_impl_->ScrollEnd(); 1101 host_impl_->ScrollEnd();
1102 1102
1103 scoped_ptr<ScrollAndScaleSet> scroll_info = 1103 scoped_ptr<ScrollAndScaleSet> scroll_info =
1104 host_impl_->ProcessScrollDeltas(); 1104 host_impl_->ProcessScrollDeltas();
1105 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1105 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1106 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); 1106 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10));
1107 } 1107 }
1108 1108
1109 // Two-finger panning should work when starting fully zoomed out. 1109 // Two-finger panning should work when starting fully zoomed out.
1110 { 1110 {
1111 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, 1111 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f,
1112 0.5f, 1112 0.5f,
1113 4.f); 1113 4.f);
1114 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1114 scroll_layer->SetScrollDelta(gfx::Vector2d());
1115 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); 1115 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
1116 1116
1117 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); 1117 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture);
1118 host_impl_->PinchGestureBegin(); 1118 host_impl_->PinchGestureBegin();
1119 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); 1119 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0));
1120 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); 1120 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0));
1121 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); 1121 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10));
1122 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); 1122 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10));
1123 host_impl_->PinchGestureEnd(); 1123 host_impl_->PinchGestureEnd();
1124 host_impl_->ScrollEnd(); 1124 host_impl_->ScrollEnd();
1125 1125
(...skipping 18 matching lines...) Expand all
1144 base::TimeDelta::FromSeconds(1); 1144 base::TimeDelta::FromSeconds(1);
1145 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 1145 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
1146 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1146 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1147 base::TimeTicks end_time = start_time + duration; 1147 base::TimeTicks end_time = start_time + duration;
1148 1148
1149 // Non-anchor zoom-in 1149 // Non-anchor zoom-in
1150 { 1150 {
1151 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1151 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1152 min_page_scale, 1152 min_page_scale,
1153 max_page_scale); 1153 max_page_scale);
1154 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1154 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1155 1155
1156 did_request_redraw_ = false; 1156 did_request_redraw_ = false;
1157 did_request_animate_ = false; 1157 did_request_animate_ = false;
1158 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); 1158 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration);
1159 EXPECT_FALSE(did_request_redraw_); 1159 EXPECT_FALSE(did_request_redraw_);
1160 EXPECT_TRUE(did_request_animate_); 1160 EXPECT_TRUE(did_request_animate_);
1161 1161
1162 did_request_redraw_ = false; 1162 did_request_redraw_ = false;
1163 did_request_animate_ = false; 1163 did_request_animate_ = false;
1164 host_impl_->Animate(start_time); 1164 host_impl_->Animate(start_time);
(...skipping 17 matching lines...) Expand all
1182 host_impl_->ProcessScrollDeltas(); 1182 host_impl_->ProcessScrollDeltas();
1183 EXPECT_EQ(scroll_info->page_scale_delta, 2); 1183 EXPECT_EQ(scroll_info->page_scale_delta, 2);
1184 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1184 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1185 } 1185 }
1186 1186
1187 // Anchor zoom-out 1187 // Anchor zoom-out
1188 { 1188 {
1189 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1189 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1190 min_page_scale, 1190 min_page_scale,
1191 max_page_scale); 1191 max_page_scale);
1192 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1192 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1193 1193
1194 did_request_redraw_ = false; 1194 did_request_redraw_ = false;
1195 did_request_animate_ = false; 1195 did_request_animate_ = false;
1196 host_impl_->StartPageScaleAnimation( 1196 host_impl_->StartPageScaleAnimation(
1197 gfx::Vector2d(25, 25), true, min_page_scale, duration); 1197 gfx::Vector2d(25, 25), true, min_page_scale, duration);
1198 EXPECT_FALSE(did_request_redraw_); 1198 EXPECT_FALSE(did_request_redraw_);
1199 EXPECT_TRUE(did_request_animate_); 1199 EXPECT_TRUE(did_request_animate_);
1200 1200
1201 did_request_redraw_ = false; 1201 did_request_redraw_ = false;
1202 did_request_animate_ = false; 1202 did_request_animate_ = false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 base::TimeDelta::FromSeconds(1); 1234 base::TimeDelta::FromSeconds(1);
1235 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 1235 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
1236 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1236 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1237 base::TimeTicks end_time = start_time + duration; 1237 base::TimeTicks end_time = start_time + duration;
1238 1238
1239 // Anchor zoom with unchanged page scale should not change scroll or scale. 1239 // Anchor zoom with unchanged page scale should not change scroll or scale.
1240 { 1240 {
1241 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1241 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f,
1242 min_page_scale, 1242 min_page_scale,
1243 max_page_scale); 1243 max_page_scale);
1244 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); 1244 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1245 1245
1246 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration); 1246 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), true, 1.f, duration);
1247 host_impl_->Animate(start_time); 1247 host_impl_->Animate(start_time);
1248 host_impl_->Animate(halfway_through_animation); 1248 host_impl_->Animate(halfway_through_animation);
1249 EXPECT_TRUE(did_request_redraw_); 1249 EXPECT_TRUE(did_request_redraw_);
1250 host_impl_->Animate(end_time); 1250 host_impl_->Animate(end_time);
1251 EXPECT_TRUE(did_request_commit_); 1251 EXPECT_TRUE(did_request_commit_);
1252 1252
1253 scoped_ptr<ScrollAndScaleSet> scroll_info = 1253 scoped_ptr<ScrollAndScaleSet> scroll_info =
1254 host_impl_->ProcessScrollDeltas(); 1254 host_impl_->ProcessScrollDeltas();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 host_impl_->InitializeRenderer(CreateOutputSurface()); \ 1298 host_impl_->InitializeRenderer(CreateOutputSurface()); \
1299 host_impl_->SetViewportSize(viewport_size); \ 1299 host_impl_->SetViewportSize(viewport_size); \
1300 \ 1300 \
1301 scoped_ptr<LayerImpl> root = \ 1301 scoped_ptr<LayerImpl> root = \
1302 LayerImpl::Create(host_impl_->active_tree(), 1); \ 1302 LayerImpl::Create(host_impl_->active_tree(), 1); \
1303 root->SetBounds(viewport_size); \ 1303 root->SetBounds(viewport_size); \
1304 \ 1304 \
1305 scoped_ptr<LayerImpl> scroll = \ 1305 scoped_ptr<LayerImpl> scroll = \
1306 LayerImpl::Create(host_impl_->active_tree(), 2); \ 1306 LayerImpl::Create(host_impl_->active_tree(), 2); \
1307 scroll->SetScrollClipLayer(root->id()); \ 1307 scroll->SetScrollClipLayer(root->id()); \
1308 scroll->SetScrollOffset(gfx::Vector2d()); \ 1308 scroll->SetScrollOffset(gfx::ScrollOffset()); \
1309 root->SetBounds(viewport_size); \ 1309 root->SetBounds(viewport_size); \
1310 scroll->SetBounds(content_size); \ 1310 scroll->SetBounds(content_size); \
1311 scroll->SetContentBounds(content_size); \ 1311 scroll->SetContentBounds(content_size); \
1312 scroll->SetIsContainerForFixedPositionLayers(true); \ 1312 scroll->SetIsContainerForFixedPositionLayers(true); \
1313 \ 1313 \
1314 scoped_ptr<LayerImpl> contents = \ 1314 scoped_ptr<LayerImpl> contents = \
1315 LayerImpl::Create(host_impl_->active_tree(), 3); \ 1315 LayerImpl::Create(host_impl_->active_tree(), 3); \
1316 contents->SetDrawsContent(true); \ 1316 contents->SetDrawsContent(true); \
1317 contents->SetBounds(content_size); \ 1317 contents->SetBounds(content_size); \
1318 contents->SetContentBounds(content_size); \ 1318 contents->SetContentBounds(content_size); \
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 1369
1370 // After the fade begins, we should start getting redraws instead of a 1370 // After the fade begins, we should start getting redraws instead of a
1371 // scheduled animation. 1371 // scheduled animation.
1372 fake_now += base::TimeDelta::FromMilliseconds(25); 1372 fake_now += base::TimeDelta::FromMilliseconds(25);
1373 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1373 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1374 EXPECT_TRUE(did_request_animate_); 1374 EXPECT_TRUE(did_request_animate_);
1375 did_request_animate_ = false; 1375 did_request_animate_ = false;
1376 1376
1377 // Setting the scroll offset outside a scroll should also cause the scrollbar 1377 // Setting the scroll offset outside a scroll should also cause the scrollbar
1378 // to appear and to schedule a fade. 1378 // to appear and to schedule a fade.
1379 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); 1379 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(
1380 gfx::ScrollOffset(5, 5));
1380 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1381 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1381 requested_scrollbar_animation_delay_); 1382 requested_scrollbar_animation_delay_);
1382 EXPECT_FALSE(did_request_redraw_); 1383 EXPECT_FALSE(did_request_redraw_);
1383 EXPECT_FALSE(did_request_animate_); 1384 EXPECT_FALSE(did_request_animate_);
1384 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1385 requested_scrollbar_animation_delay_ = base::TimeDelta();
1385 1386
1386 // Unnecessarily Fade animation of solid color scrollbar is not triggered. 1387 // Unnecessarily Fade animation of solid color scrollbar is not triggered.
1387 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1388 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1388 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1389 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1389 host_impl_->ScrollEnd(); 1390 host_impl_->ScrollEnd();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 host_impl_->SetDeviceScaleFactor(device_scale_factor); 1465 host_impl_->SetDeviceScaleFactor(device_scale_factor);
1465 host_impl_->SetViewportSize(device_viewport_size); 1466 host_impl_->SetViewportSize(device_viewport_size);
1466 1467
1467 scoped_ptr<LayerImpl> root = 1468 scoped_ptr<LayerImpl> root =
1468 LayerImpl::Create(host_impl_->active_tree(), 1); 1469 LayerImpl::Create(host_impl_->active_tree(), 1);
1469 root->SetBounds(viewport_size); 1470 root->SetBounds(viewport_size);
1470 1471
1471 scoped_ptr<LayerImpl> scroll = 1472 scoped_ptr<LayerImpl> scroll =
1472 LayerImpl::Create(host_impl_->active_tree(), 2); 1473 LayerImpl::Create(host_impl_->active_tree(), 2);
1473 scroll->SetScrollClipLayer(root->id()); 1474 scroll->SetScrollClipLayer(root->id());
1474 scroll->SetScrollOffset(gfx::Vector2d()); 1475 scroll->SetScrollOffset(gfx::ScrollOffset());
1475 scroll->SetBounds(content_size); 1476 scroll->SetBounds(content_size);
1476 scroll->SetContentBounds(content_size); 1477 scroll->SetContentBounds(content_size);
1477 scroll->SetIsContainerForFixedPositionLayers(true); 1478 scroll->SetIsContainerForFixedPositionLayers(true);
1478 1479
1479 scoped_ptr<LayerImpl> contents = 1480 scoped_ptr<LayerImpl> contents =
1480 LayerImpl::Create(host_impl_->active_tree(), 3); 1481 LayerImpl::Create(host_impl_->active_tree(), 3);
1481 contents->SetDrawsContent(true); 1482 contents->SetDrawsContent(true);
1482 contents->SetBounds(content_size); 1483 contents->SetBounds(content_size);
1483 contents->SetContentBounds(content_size); 1484 contents->SetContentBounds(content_size);
1484 1485
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 host_impl_->top_controls_manager()->ScrollEnd(); 2404 host_impl_->top_controls_manager()->ScrollEnd();
2404 EXPECT_EQ(-2 * scroll_increment_y, 2405 EXPECT_EQ(-2 * scroll_increment_y,
2405 host_impl_->top_controls_manager()->ContentTopOffset()); 2406 host_impl_->top_controls_manager()->ContentTopOffset());
2406 // Now that top controls have moved, expect the clip to resize. 2407 // Now that top controls have moved, expect the clip to resize.
2407 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); 2408 EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
2408 2409
2409 host_impl_->ScrollEnd(); 2410 host_impl_->ScrollEnd();
2410 2411
2411 // Verify the layer is once-again non-scrollable. 2412 // Verify the layer is once-again non-scrollable.
2412 EXPECT_EQ( 2413 EXPECT_EQ(
2413 gfx::Vector2d(), 2414 gfx::ScrollOffset(),
2414 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); 2415 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset());
2415 2416
2416 EXPECT_EQ(InputHandler::ScrollStarted, 2417 EXPECT_EQ(InputHandler::ScrollStarted,
2417 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2418 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2418 } 2419 }
2419 2420
2420 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { 2421 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) {
2421 // Test the configuration where a non-composited root layer is embedded in a 2422 // Test the configuration where a non-composited root layer is embedded in a
2422 // scrollable outer layer. 2423 // scrollable outer layer.
2423 gfx::Size surface_size(10, 10); 2424 gfx::Size surface_size(10, 10);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 host_impl_->active_tree()->DidBecomeActive(); 2567 host_impl_->active_tree()->DidBecomeActive();
2567 host_impl_->SetViewportSize(viewport_size); 2568 host_impl_->SetViewportSize(viewport_size);
2568 DrawFrame(); 2569 DrawFrame();
2569 2570
2570 LayerImpl* root_scroll = 2571 LayerImpl* root_scroll =
2571 host_impl_->active_tree()->InnerViewportScrollLayer(); 2572 host_impl_->active_tree()->InnerViewportScrollLayer();
2572 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); 2573 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds());
2573 2574
2574 gfx::Vector2d scroll_delta(0, 10); 2575 gfx::Vector2d scroll_delta(0, 10);
2575 gfx::Vector2d expected_scroll_delta = scroll_delta; 2576 gfx::Vector2d expected_scroll_delta = scroll_delta;
2576 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); 2577 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset();
2577 EXPECT_EQ(InputHandler::ScrollStarted, 2578 EXPECT_EQ(InputHandler::ScrollStarted,
2578 host_impl_->ScrollBegin(gfx::Point(5, 5), 2579 host_impl_->ScrollBegin(gfx::Point(5, 5),
2579 InputHandler::Wheel)); 2580 InputHandler::Wheel));
2580 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2581 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2581 host_impl_->ScrollEnd(); 2582 host_impl_->ScrollEnd();
2582 2583
2583 // Set new page scale from main thread. 2584 // Set new page scale from main thread.
2584 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 2585 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale,
2585 page_scale, 2586 page_scale,
2586 page_scale); 2587 page_scale);
(...skipping 30 matching lines...) Expand all
2617 host_impl_->SetViewportSize(viewport_size); 2618 host_impl_->SetViewportSize(viewport_size);
2618 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); 2619 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale);
2619 DrawFrame(); 2620 DrawFrame();
2620 2621
2621 LayerImpl* root_scroll = 2622 LayerImpl* root_scroll =
2622 host_impl_->active_tree()->InnerViewportScrollLayer(); 2623 host_impl_->active_tree()->InnerViewportScrollLayer();
2623 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); 2624 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds());
2624 2625
2625 gfx::Vector2d scroll_delta(0, 10); 2626 gfx::Vector2d scroll_delta(0, 10);
2626 gfx::Vector2d expected_scroll_delta = scroll_delta; 2627 gfx::Vector2d expected_scroll_delta = scroll_delta;
2627 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); 2628 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset();
2628 EXPECT_EQ(InputHandler::ScrollStarted, 2629 EXPECT_EQ(InputHandler::ScrollStarted,
2629 host_impl_->ScrollBegin(gfx::Point(5, 5), 2630 host_impl_->ScrollBegin(gfx::Point(5, 5),
2630 InputHandler::Wheel)); 2631 InputHandler::Wheel));
2631 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2632 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2632 host_impl_->ScrollEnd(); 2633 host_impl_->ScrollEnd();
2633 2634
2634 // Set new page scale on impl thread by pinching. 2635 // Set new page scale on impl thread by pinching.
2635 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 2636 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
2636 host_impl_->PinchGestureBegin(); 2637 host_impl_->PinchGestureBegin();
2637 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); 2638 host_impl_->PinchGestureUpdate(page_scale, gfx::Point());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 LayerImpl* child = child_scrolling.get(); 2728 LayerImpl* child = child_scrolling.get();
2728 root_scrolling_ptr->AddChild(child_scrolling.Pass()); 2729 root_scrolling_ptr->AddChild(child_scrolling.Pass());
2729 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2730 host_impl_->active_tree()->SetRootLayer(root.Pass());
2730 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); 2731 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID);
2731 host_impl_->active_tree()->DidBecomeActive(); 2732 host_impl_->active_tree()->DidBecomeActive();
2732 host_impl_->SetViewportSize(surface_size); 2733 host_impl_->SetViewportSize(surface_size);
2733 DrawFrame(); 2734 DrawFrame();
2734 2735
2735 gfx::Vector2d scroll_delta(0, 10); 2736 gfx::Vector2d scroll_delta(0, 10);
2736 gfx::Vector2d expected_scroll_delta(scroll_delta); 2737 gfx::Vector2d expected_scroll_delta(scroll_delta);
2737 gfx::Vector2d expected_max_scroll(child->MaxScrollOffset()); 2738 gfx::ScrollOffset expected_max_scroll(child->MaxScrollOffset());
2738 EXPECT_EQ(InputHandler::ScrollStarted, 2739 EXPECT_EQ(InputHandler::ScrollStarted,
2739 host_impl_->ScrollBegin(gfx::Point(5, 5), 2740 host_impl_->ScrollBegin(gfx::Point(5, 5),
2740 InputHandler::Wheel)); 2741 InputHandler::Wheel));
2741 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2742 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2742 host_impl_->ScrollEnd(); 2743 host_impl_->ScrollEnd();
2743 2744
2744 float page_scale = 2.f; 2745 float page_scale = 2.f;
2745 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 2746 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale,
2746 1.f, 2747 1.f,
2747 page_scale); 2748 page_scale);
(...skipping 27 matching lines...) Expand all
2775 scoped_ptr<LayerImpl> child = 2776 scoped_ptr<LayerImpl> child =
2776 CreateScrollableLayer(2, content_size, root.get()); 2777 CreateScrollableLayer(2, content_size, root.get());
2777 LayerImpl* grand_child_layer = grand_child.get(); 2778 LayerImpl* grand_child_layer = grand_child.get();
2778 child->AddChild(grand_child.Pass()); 2779 child->AddChild(grand_child.Pass());
2779 2780
2780 LayerImpl* child_layer = child.get(); 2781 LayerImpl* child_layer = child.get();
2781 root->AddChild(child.Pass()); 2782 root->AddChild(child.Pass());
2782 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2783 host_impl_->active_tree()->SetRootLayer(root.Pass());
2783 host_impl_->active_tree()->DidBecomeActive(); 2784 host_impl_->active_tree()->DidBecomeActive();
2784 host_impl_->SetViewportSize(surface_size); 2785 host_impl_->SetViewportSize(surface_size);
2785 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 5)); 2786 grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 5));
2786 child_layer->SetScrollOffset(gfx::Vector2d(3, 0)); 2787 child_layer->SetScrollOffset(gfx::ScrollOffset(3, 0));
2787 2788
2788 DrawFrame(); 2789 DrawFrame();
2789 { 2790 {
2790 gfx::Vector2d scroll_delta(-8, -7); 2791 gfx::Vector2d scroll_delta(-8, -7);
2791 EXPECT_EQ(InputHandler::ScrollStarted, 2792 EXPECT_EQ(InputHandler::ScrollStarted,
2792 host_impl_->ScrollBegin(gfx::Point(), 2793 host_impl_->ScrollBegin(gfx::Point(),
2793 InputHandler::Wheel)); 2794 InputHandler::Wheel));
2794 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2795 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2795 host_impl_->ScrollEnd(); 2796 host_impl_->ScrollEnd();
2796 2797
(...skipping 30 matching lines...) Expand all
2827 2828
2828 LayerImpl* child_layer = child.get(); 2829 LayerImpl* child_layer = child.get();
2829 root_scrolling->AddChild(child.Pass()); 2830 root_scrolling->AddChild(child.Pass());
2830 root->AddChild(root_scrolling.Pass()); 2831 root->AddChild(root_scrolling.Pass());
2831 EXPECT_EQ(viewport_size, root->bounds()); 2832 EXPECT_EQ(viewport_size, root->bounds());
2832 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2833 host_impl_->active_tree()->SetRootLayer(root.Pass());
2833 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); 2834 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID);
2834 host_impl_->active_tree()->DidBecomeActive(); 2835 host_impl_->active_tree()->DidBecomeActive();
2835 host_impl_->SetViewportSize(viewport_size); 2836 host_impl_->SetViewportSize(viewport_size);
2836 2837
2837 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); 2838 grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 2));
2838 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); 2839 child_layer->SetScrollOffset(gfx::ScrollOffset(0, 3));
2839 2840
2840 DrawFrame(); 2841 DrawFrame();
2841 { 2842 {
2842 gfx::Vector2d scroll_delta(0, -10); 2843 gfx::Vector2d scroll_delta(0, -10);
2843 EXPECT_EQ(InputHandler::ScrollStarted, 2844 EXPECT_EQ(InputHandler::ScrollStarted,
2844 host_impl_->ScrollBegin(gfx::Point(), 2845 host_impl_->ScrollBegin(gfx::Point(),
2845 InputHandler::NonBubblingGesture)); 2846 InputHandler::NonBubblingGesture));
2846 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2847 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2847 host_impl_->ScrollEnd(); 2848 host_impl_->ScrollEnd();
2848 2849
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 int height = 20; 3167 int height = 20;
3167 int scale = 3; 3168 int scale = 3;
3168 SetupScrollAndContentsLayers(gfx::Size(width, height)); 3169 SetupScrollAndContentsLayers(gfx::Size(width, height));
3169 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( 3170 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds(
3170 gfx::Size(width * scale - 1, height * scale)); 3171 gfx::Size(width * scale - 1, height * scale));
3171 host_impl_->SetDeviceScaleFactor(scale); 3172 host_impl_->SetDeviceScaleFactor(scale);
3172 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 3173 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
3173 3174
3174 LayerImpl* inner_viewport_scroll_layer = 3175 LayerImpl* inner_viewport_scroll_layer =
3175 host_impl_->active_tree()->InnerViewportScrollLayer(); 3176 host_impl_->active_tree()->InnerViewportScrollLayer();
3176 EXPECT_EQ(gfx::Vector2d(0, 0), 3177 EXPECT_EQ(gfx::ScrollOffset(0, 0),
3177 inner_viewport_scroll_layer->MaxScrollOffset()); 3178 inner_viewport_scroll_layer->MaxScrollOffset());
3178 } 3179 }
3179 3180
3180 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { 3181 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate {
3181 public: 3182 public:
3182 TestScrollOffsetDelegate() 3183 TestScrollOffsetDelegate()
3183 : page_scale_factor_(0.f), 3184 : page_scale_factor_(0.f),
3184 min_page_scale_factor_(-1.f), 3185 min_page_scale_factor_(-1.f),
3185 max_page_scale_factor_(-1.f) {} 3186 max_page_scale_factor_(-1.f) {}
3186 3187
3187 virtual ~TestScrollOffsetDelegate() {} 3188 virtual ~TestScrollOffsetDelegate() {}
3188 3189
3189 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { 3190 virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE {
3190 return getter_return_value_; 3191 return getter_return_value_;
3191 } 3192 }
3192 3193
3193 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } 3194 virtual bool IsExternalFlingActive() const OVERRIDE { return false; }
3194 3195
3195 virtual void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset, 3196 virtual void UpdateRootLayerState(
3196 const gfx::Vector2dF& max_scroll_offset, 3197 const gfx::ScrollOffset& total_scroll_offset,
3197 const gfx::SizeF& scrollable_size, 3198 const gfx::ScrollOffset& max_scroll_offset,
3198 float page_scale_factor, 3199 const gfx::SizeF& scrollable_size,
3199 float min_page_scale_factor, 3200 float page_scale_factor,
3200 float max_page_scale_factor) OVERRIDE { 3201 float min_page_scale_factor,
3202 float max_page_scale_factor) OVERRIDE {
3201 DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); 3203 DCHECK(total_scroll_offset.x() <= max_scroll_offset.x());
3202 DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); 3204 DCHECK(total_scroll_offset.y() <= max_scroll_offset.y());
3203 last_set_scroll_offset_ = total_scroll_offset; 3205 last_set_scroll_offset_ = total_scroll_offset;
3204 max_scroll_offset_ = max_scroll_offset; 3206 max_scroll_offset_ = max_scroll_offset;
3205 scrollable_size_ = scrollable_size; 3207 scrollable_size_ = scrollable_size;
3206 page_scale_factor_ = page_scale_factor; 3208 page_scale_factor_ = page_scale_factor;
3207 min_page_scale_factor_ = min_page_scale_factor; 3209 min_page_scale_factor_ = min_page_scale_factor;
3208 max_page_scale_factor_ = max_page_scale_factor; 3210 max_page_scale_factor_ = max_page_scale_factor;
3209 } 3211 }
3210 3212
3211 gfx::Vector2dF last_set_scroll_offset() { 3213 gfx::ScrollOffset last_set_scroll_offset() {
3212 return last_set_scroll_offset_; 3214 return last_set_scroll_offset_;
3213 } 3215 }
3214 3216
3215 void set_getter_return_value(const gfx::Vector2dF& value) { 3217 void set_getter_return_value(const gfx::ScrollOffset& value) {
3216 getter_return_value_ = value; 3218 getter_return_value_ = value;
3217 } 3219 }
3218 3220
3219 gfx::Vector2dF max_scroll_offset() const { 3221 gfx::ScrollOffset max_scroll_offset() const {
3220 return max_scroll_offset_; 3222 return max_scroll_offset_;
3221 } 3223 }
3222 3224
3223 gfx::SizeF scrollable_size() const { 3225 gfx::SizeF scrollable_size() const {
3224 return scrollable_size_; 3226 return scrollable_size_;
3225 } 3227 }
3226 3228
3227 float page_scale_factor() const { 3229 float page_scale_factor() const {
3228 return page_scale_factor_; 3230 return page_scale_factor_;
3229 } 3231 }
3230 3232
3231 float min_page_scale_factor() const { 3233 float min_page_scale_factor() const {
3232 return min_page_scale_factor_; 3234 return min_page_scale_factor_;
3233 } 3235 }
3234 3236
3235 float max_page_scale_factor() const { 3237 float max_page_scale_factor() const {
3236 return max_page_scale_factor_; 3238 return max_page_scale_factor_;
3237 } 3239 }
3238 3240
3239 private: 3241 private:
3240 gfx::Vector2dF last_set_scroll_offset_; 3242 gfx::ScrollOffset last_set_scroll_offset_;
3241 gfx::Vector2dF getter_return_value_; 3243 gfx::ScrollOffset getter_return_value_;
3242 gfx::Vector2dF max_scroll_offset_; 3244 gfx::ScrollOffset max_scroll_offset_;
3243 gfx::SizeF scrollable_size_; 3245 gfx::SizeF scrollable_size_;
3244 float page_scale_factor_; 3246 float page_scale_factor_;
3245 float min_page_scale_factor_; 3247 float min_page_scale_factor_;
3246 float max_page_scale_factor_; 3248 float max_page_scale_factor_;
3247 }; 3249 };
3248 3250
3249 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { 3251 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) {
3250 TestScrollOffsetDelegate scroll_delegate; 3252 TestScrollOffsetDelegate scroll_delegate;
3251 host_impl_->SetViewportSize(gfx::Size(10, 20)); 3253 host_impl_->SetViewportSize(gfx::Size(10, 20));
3252 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); 3254 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100));
3253 LayerImpl* clip_layer = scroll_layer->parent()->parent(); 3255 LayerImpl* clip_layer = scroll_layer->parent()->parent();
3254 clip_layer->SetBounds(gfx::Size(10, 20)); 3256 clip_layer->SetBounds(gfx::Size(10, 20));
3255 3257
3256 // Setting the delegate results in the current scroll offset being set. 3258 // Setting the delegate results in the current scroll offset being set.
3257 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); 3259 gfx::Vector2dF initial_scroll_delta(10.f, 10.f);
3258 scroll_layer->SetScrollOffset(gfx::Vector2d()); 3260 scroll_layer->SetScrollOffset(gfx::ScrollOffset());
3259 scroll_layer->SetScrollDelta(initial_scroll_delta); 3261 scroll_layer->SetScrollDelta(initial_scroll_delta);
3260 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); 3262 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate);
3261 EXPECT_EQ(initial_scroll_delta.ToString(), 3263 EXPECT_EQ(initial_scroll_delta.ToString(),
3262 scroll_delegate.last_set_scroll_offset().ToString()); 3264 scroll_delegate.last_set_scroll_offset().ToString());
3263 3265
3264 // Setting the delegate results in the scrollable_size, max_scroll_offset, 3266 // Setting the delegate results in the scrollable_size, max_scroll_offset,
3265 // page_scale_factor and {min|max}_page_scale_factor being set. 3267 // page_scale_factor and {min|max}_page_scale_factor being set.
3266 EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size()); 3268 EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size());
3267 EXPECT_EQ(gfx::Vector2dF(90, 80), scroll_delegate.max_scroll_offset()); 3269 EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_delegate.max_scroll_offset());
3268 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); 3270 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor());
3269 EXPECT_EQ(0.f, scroll_delegate.min_page_scale_factor()); 3271 EXPECT_EQ(0.f, scroll_delegate.min_page_scale_factor());
3270 EXPECT_EQ(0.f, scroll_delegate.max_page_scale_factor()); 3272 EXPECT_EQ(0.f, scroll_delegate.max_page_scale_factor());
3271 3273
3272 // Updating page scale immediately updates the delegate. 3274 // Updating page scale immediately updates the delegate.
3273 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 0.5f, 4.f); 3275 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 0.5f, 4.f);
3274 EXPECT_EQ(2.f, scroll_delegate.page_scale_factor()); 3276 EXPECT_EQ(2.f, scroll_delegate.page_scale_factor());
3275 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); 3277 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor());
3276 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); 3278 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor());
3277 host_impl_->active_tree()->SetPageScaleDelta(1.5f); 3279 host_impl_->active_tree()->SetPageScaleDelta(1.5f);
(...skipping 11 matching lines...) Expand all
3289 // delegate). 3291 // delegate).
3290 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 3292 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
3291 host_impl_->PinchGestureBegin(); 3293 host_impl_->PinchGestureBegin();
3292 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); 3294 host_impl_->PinchGestureUpdate(2.f, gfx::Point());
3293 host_impl_->PinchGestureUpdate(.5f, gfx::Point()); 3295 host_impl_->PinchGestureUpdate(.5f, gfx::Point());
3294 host_impl_->PinchGestureEnd(); 3296 host_impl_->PinchGestureEnd();
3295 host_impl_->ScrollEnd(); 3297 host_impl_->ScrollEnd();
3296 3298
3297 // Scrolling should be relative to the offset as returned by the delegate. 3299 // Scrolling should be relative to the offset as returned by the delegate.
3298 gfx::Vector2dF scroll_delta(0.f, 10.f); 3300 gfx::Vector2dF scroll_delta(0.f, 10.f);
3299 gfx::Vector2dF current_offset(7.f, 8.f); 3301 gfx::ScrollOffset current_offset(7.f, 8.f);
3300 3302
3301 scroll_delegate.set_getter_return_value(current_offset); 3303 scroll_delegate.set_getter_return_value(current_offset);
3302 EXPECT_EQ(InputHandler::ScrollStarted, 3304 EXPECT_EQ(InputHandler::ScrollStarted,
3303 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 3305 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
3304 3306
3305 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3307 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3306 EXPECT_EQ(current_offset + scroll_delta, 3308 EXPECT_EQ(ScrollOffsetWithDelta(current_offset, scroll_delta),
3307 scroll_delegate.last_set_scroll_offset()); 3309 scroll_delegate.last_set_scroll_offset());
3308 3310
3309 current_offset = gfx::Vector2dF(42.f, 41.f); 3311 current_offset = gfx::ScrollOffset(42.f, 41.f);
3310 scroll_delegate.set_getter_return_value(current_offset); 3312 scroll_delegate.set_getter_return_value(current_offset);
3311 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3313 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3312 EXPECT_EQ(current_offset + scroll_delta, 3314 EXPECT_EQ(current_offset + gfx::ScrollOffset(scroll_delta),
3313 scroll_delegate.last_set_scroll_offset()); 3315 scroll_delegate.last_set_scroll_offset());
3314 host_impl_->ScrollEnd(); 3316 host_impl_->ScrollEnd();
3315 scroll_delegate.set_getter_return_value(gfx::Vector2dF()); 3317 scroll_delegate.set_getter_return_value(gfx::ScrollOffset());
3316 3318
3317 // Forces a full tree synchronization and ensures that the scroll delegate 3319 // Forces a full tree synchronization and ensures that the scroll delegate
3318 // sees the correct size of the new tree. 3320 // sees the correct size of the new tree.
3319 gfx::Size new_size(42, 24); 3321 gfx::Size new_size(42, 24);
3320 host_impl_->CreatePendingTree(); 3322 host_impl_->CreatePendingTree();
3321 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); 3323 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size);
3322 host_impl_->ActivateSyncTree(); 3324 host_impl_->ActivateSyncTree();
3323 EXPECT_EQ(new_size, scroll_delegate.scrollable_size()); 3325 EXPECT_EQ(new_size, scroll_delegate.scrollable_size());
3324 3326
3325 // Un-setting the delegate should propagate the delegate's current offset to 3327 // Un-setting the delegate should propagate the delegate's current offset to
3326 // the root scrollable layer. 3328 // the root scrollable layer.
3327 current_offset = gfx::Vector2dF(13.f, 12.f); 3329 current_offset = gfx::ScrollOffset(13.f, 12.f);
3328 scroll_delegate.set_getter_return_value(current_offset); 3330 scroll_delegate.set_getter_return_value(current_offset);
3329 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); 3331 host_impl_->SetRootLayerScrollOffsetDelegate(NULL);
3330 3332
3331 EXPECT_EQ(current_offset.ToString(), 3333 EXPECT_EQ(current_offset.ToString(),
3332 scroll_layer->TotalScrollOffset().ToString()); 3334 scroll_layer->TotalScrollOffset().ToString());
3333 } 3335 }
3334 3336
3335 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { 3337 void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) {
3336 const gfx::Transform target_space_transform = 3338 const gfx::Transform target_space_transform =
3337 layer->draw_properties().target_space_transform; 3339 layer->draw_properties().target_space_transform;
(...skipping 12 matching lines...) Expand all
3350 LayerImpl* clip_layer = scroll_layer->parent()->parent(); 3352 LayerImpl* clip_layer = scroll_layer->parent()->parent();
3351 clip_layer->SetBounds(gfx::Size(10, 20)); 3353 clip_layer->SetBounds(gfx::Size(10, 20));
3352 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); 3354 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate);
3353 3355
3354 // Draw first frame to clear any pending draws and check scroll. 3356 // Draw first frame to clear any pending draws and check scroll.
3355 DrawFrame(); 3357 DrawFrame();
3356 CheckLayerScrollDelta(scroll_layer, gfx::Vector2dF(0.f, 0.f)); 3358 CheckLayerScrollDelta(scroll_layer, gfx::Vector2dF(0.f, 0.f));
3357 EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); 3359 EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties());
3358 3360
3359 // Set external scroll delta on delegate and notify LayerTreeHost. 3361 // Set external scroll delta on delegate and notify LayerTreeHost.
3360 gfx::Vector2dF scroll_delta(10.f, 10.f); 3362 gfx::ScrollOffset scroll_offset(10.f, 10.f);
3361 scroll_delegate.set_getter_return_value(scroll_delta); 3363 scroll_delegate.set_getter_return_value(scroll_offset);
3362 host_impl_->OnRootLayerDelegatedScrollOffsetChanged(); 3364 host_impl_->OnRootLayerDelegatedScrollOffsetChanged();
3363 3365
3364 // Check scroll delta reflected in layer. 3366 // Check scroll delta reflected in layer.
3365 DrawFrame(); 3367 DrawFrame();
3366 CheckLayerScrollDelta(scroll_layer, scroll_delta); 3368 CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset));
3367 3369
3368 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); 3370 host_impl_->SetRootLayerScrollOffsetDelegate(NULL);
3369 } 3371 }
3370 3372
3371 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { 3373 TEST_F(LayerTreeHostImplTest, OverscrollRoot) {
3372 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 3374 SetupScrollAndContentsLayers(gfx::Size(100, 100));
3373 host_impl_->SetViewportSize(gfx::Size(50, 50)); 3375 host_impl_->SetViewportSize(gfx::Size(50, 50));
3374 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 3376 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
3375 DrawFrame(); 3377 DrawFrame();
3376 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); 3378 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 CreateScrollableLayer(3, surface_size, root_clip.get()); 3429 CreateScrollableLayer(3, surface_size, root_clip.get());
3428 3430
3429 scoped_ptr<LayerImpl> child = 3431 scoped_ptr<LayerImpl> child =
3430 CreateScrollableLayer(2, surface_size, root_clip.get()); 3432 CreateScrollableLayer(2, surface_size, root_clip.get());
3431 LayerImpl* grand_child_layer = grand_child.get(); 3433 LayerImpl* grand_child_layer = grand_child.get();
3432 child->AddChild(grand_child.Pass()); 3434 child->AddChild(grand_child.Pass());
3433 3435
3434 LayerImpl* child_layer = child.get(); 3436 LayerImpl* child_layer = child.get();
3435 root->AddChild(child.Pass()); 3437 root->AddChild(child.Pass());
3436 root_clip->AddChild(root.Pass()); 3438 root_clip->AddChild(root.Pass());
3437 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); 3439 child_layer->SetScrollOffset(gfx::ScrollOffset(0, 3));
3438 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); 3440 grand_child_layer->SetScrollOffset(gfx::ScrollOffset(0, 2));
3439 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 3441 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
3440 host_impl_->active_tree()->DidBecomeActive(); 3442 host_impl_->active_tree()->DidBecomeActive();
3441 host_impl_->SetViewportSize(surface_size); 3443 host_impl_->SetViewportSize(surface_size);
3442 DrawFrame(); 3444 DrawFrame();
3443 { 3445 {
3444 gfx::Vector2d scroll_delta(0, -10); 3446 gfx::Vector2d scroll_delta(0, -10);
3445 EXPECT_EQ(InputHandler::ScrollStarted, 3447 EXPECT_EQ(InputHandler::ScrollStarted,
3446 host_impl_->ScrollBegin(gfx::Point(), 3448 host_impl_->ScrollBegin(gfx::Point(),
3447 InputHandler::NonBubblingGesture)); 3449 InputHandler::NonBubblingGesture));
3448 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3450 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
(...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after
5633 5635
5634 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = 5636 scoped_ptr<FakePictureLayerImpl> scoped_content_layer =
5635 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); 5637 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile);
5636 LayerImpl* content_layer = scoped_content_layer.get(); 5638 LayerImpl* content_layer = scoped_content_layer.get();
5637 scrolling_layer->AddChild(scoped_content_layer.Pass()); 5639 scrolling_layer->AddChild(scoped_content_layer.Pass());
5638 content_layer->SetBounds(content_layer_bounds); 5640 content_layer->SetBounds(content_layer_bounds);
5639 content_layer->SetDrawsContent(true); 5641 content_layer->SetDrawsContent(true);
5640 5642
5641 root->SetBounds(root_size); 5643 root->SetBounds(root_size);
5642 5644
5643 gfx::Vector2d scroll_offset(100000, 0); 5645 gfx::ScrollOffset scroll_offset(100000, 0);
5644 scrolling_layer->SetScrollClipLayer(root->id()); 5646 scrolling_layer->SetScrollClipLayer(root->id());
5645 scrolling_layer->SetScrollOffset(scroll_offset); 5647 scrolling_layer->SetScrollOffset(scroll_offset);
5646 5648
5647 host_impl_->ActivateSyncTree(); 5649 host_impl_->ActivateSyncTree();
5648 5650
5649 host_impl_->active_tree()->UpdateDrawProperties(); 5651 host_impl_->active_tree()->UpdateDrawProperties();
5650 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); 5652 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size());
5651 5653
5652 LayerTreeHostImpl::FrameData frame; 5654 LayerTreeHostImpl::FrameData frame;
5653 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); 5655 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
6160 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { 6162 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) {
6161 // Scroll a child layer beyond its maximum scroll range and make sure the 6163 // Scroll a child layer beyond its maximum scroll range and make sure the
6162 // the scroll doesn't bubble up to the parent layer. 6164 // the scroll doesn't bubble up to the parent layer.
6163 gfx::Size surface_size(10, 10); 6165 gfx::Size surface_size(10, 10);
6164 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); 6166 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1);
6165 scoped_ptr<LayerImpl> root_scrolling = 6167 scoped_ptr<LayerImpl> root_scrolling =
6166 CreateScrollableLayer(2, surface_size, root.get()); 6168 CreateScrollableLayer(2, surface_size, root.get());
6167 6169
6168 scoped_ptr<LayerImpl> grand_child = 6170 scoped_ptr<LayerImpl> grand_child =
6169 CreateScrollableLayer(4, surface_size, root.get()); 6171 CreateScrollableLayer(4, surface_size, root.get());
6170 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); 6172 grand_child->SetScrollOffset(gfx::ScrollOffset(0, 2));
6171 6173
6172 scoped_ptr<LayerImpl> child = 6174 scoped_ptr<LayerImpl> child =
6173 CreateScrollableLayer(3, surface_size, root.get()); 6175 CreateScrollableLayer(3, surface_size, root.get());
6174 child->SetScrollOffset(gfx::Vector2d(0, 4)); 6176 child->SetScrollOffset(gfx::ScrollOffset(0, 4));
6175 child->AddChild(grand_child.Pass()); 6177 child->AddChild(grand_child.Pass());
6176 6178
6177 root_scrolling->AddChild(child.Pass()); 6179 root_scrolling->AddChild(child.Pass());
6178 root->AddChild(root_scrolling.Pass()); 6180 root->AddChild(root_scrolling.Pass());
6179 host_impl_->active_tree()->SetRootLayer(root.Pass()); 6181 host_impl_->active_tree()->SetRootLayer(root.Pass());
6180 host_impl_->active_tree()->DidBecomeActive(); 6182 host_impl_->active_tree()->DidBecomeActive();
6181 host_impl_->SetViewportSize(surface_size); 6183 host_impl_->SetViewportSize(surface_size);
6182 DrawFrame(); 6184 DrawFrame();
6183 { 6185 {
6184 scoped_ptr<ScrollAndScaleSet> scroll_info; 6186 scoped_ptr<ScrollAndScaleSet> scroll_info;
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
6652 } 6654 }
6653 6655
6654 protected: 6656 protected:
6655 static const int top_controls_height_; 6657 static const int top_controls_height_;
6656 }; 6658 };
6657 6659
6658 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; 6660 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50;
6659 6661
6660 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 6662 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
6661 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 6663 SetupScrollAndContentsLayers(gfx::Size(100, 100))
6662 ->SetScrollOffset(gfx::Vector2d(0, 10)); 6664 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
6663 host_impl_->Animate(base::TimeTicks()); 6665 host_impl_->Animate(base::TimeTicks());
6664 EXPECT_FALSE(did_request_redraw_); 6666 EXPECT_FALSE(did_request_redraw_);
6665 } 6667 }
6666 6668
6667 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { 6669 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) {
6668 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 6670 SetupScrollAndContentsLayers(gfx::Size(100, 100))
6669 ->SetScrollOffset(gfx::Vector2d(0, 10)); 6671 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
6670 host_impl_->DidChangeTopControlsPosition(); 6672 host_impl_->DidChangeTopControlsPosition();
6671 EXPECT_TRUE(did_request_animate_); 6673 EXPECT_TRUE(did_request_animate_);
6672 EXPECT_TRUE(did_request_redraw_); 6674 EXPECT_TRUE(did_request_redraw_);
6673 } 6675 }
6674 6676
6675 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { 6677 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) {
6676 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); 6678 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200));
6677 host_impl_->SetViewportSize(gfx::Size(100, 100)); 6679 host_impl_->SetViewportSize(gfx::Size(100, 100));
6678 host_impl_->top_controls_manager()->UpdateTopControlsState( 6680 host_impl_->top_controls_manager()->UpdateTopControlsState(
6679 BOTH, SHOWN, false); 6681 BOTH, SHOWN, false);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6791 } 6793 }
6792 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); 6794 EXPECT_FALSE(host_impl_->top_controls_manager()->animation());
6793 } 6795 }
6794 6796
6795 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { 6797 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) {
6796 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); 6798 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200));
6797 host_impl_->SetViewportSize(gfx::Size(100, 100)); 6799 host_impl_->SetViewportSize(gfx::Size(100, 100));
6798 host_impl_->top_controls_manager()->UpdateTopControlsState( 6800 host_impl_->top_controls_manager()->UpdateTopControlsState(
6799 BOTH, SHOWN, false); 6801 BOTH, SHOWN, false);
6800 float initial_scroll_offset = 50; 6802 float initial_scroll_offset = 50;
6801 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); 6803 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, initial_scroll_offset));
6802 DrawFrame(); 6804 DrawFrame();
6803 6805
6804 EXPECT_EQ(InputHandler::ScrollStarted, 6806 EXPECT_EQ(InputHandler::ScrollStarted,
6805 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 6807 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
6806 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); 6808 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset());
6807 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), 6809 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(),
6808 scroll_layer->TotalScrollOffset().ToString()); 6810 scroll_layer->TotalScrollOffset().ToString());
6809 6811
6810 // Scroll the top controls partially. 6812 // Scroll the top controls partially.
6811 const float residue = 15; 6813 const float residue = 15;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6858 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); 6860 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree();
6859 const int kOuterViewportClipLayerId = 6; 6861 const int kOuterViewportClipLayerId = 6;
6860 const int kOuterViewportScrollLayerId = 7; 6862 const int kOuterViewportScrollLayerId = 7;
6861 const int kInnerViewportScrollLayerId = 2; 6863 const int kInnerViewportScrollLayerId = 2;
6862 const int kInnerViewportClipLayerId = 4; 6864 const int kInnerViewportClipLayerId = 4;
6863 const int kPageScaleLayerId = 5; 6865 const int kPageScaleLayerId = 5;
6864 6866
6865 scoped_ptr<LayerImpl> inner_scroll = 6867 scoped_ptr<LayerImpl> inner_scroll =
6866 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); 6868 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId);
6867 inner_scroll->SetIsContainerForFixedPositionLayers(true); 6869 inner_scroll->SetIsContainerForFixedPositionLayers(true);
6868 inner_scroll->SetScrollOffset(gfx::Vector2d()); 6870 inner_scroll->SetScrollOffset(gfx::ScrollOffset());
6869 6871
6870 scoped_ptr<LayerImpl> inner_clip = 6872 scoped_ptr<LayerImpl> inner_clip =
6871 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); 6873 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId);
6872 inner_clip->SetBounds(inner_viewport); 6874 inner_clip->SetBounds(inner_viewport);
6873 6875
6874 scoped_ptr<LayerImpl> page_scale = 6876 scoped_ptr<LayerImpl> page_scale =
6875 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); 6877 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId);
6876 6878
6877 inner_scroll->SetScrollClipLayer(inner_clip->id()); 6879 inner_scroll->SetScrollClipLayer(inner_clip->id());
6878 inner_scroll->SetBounds(outer_viewport); 6880 inner_scroll->SetBounds(outer_viewport);
6879 inner_scroll->SetContentBounds(outer_viewport); 6881 inner_scroll->SetContentBounds(outer_viewport);
6880 inner_scroll->SetPosition(gfx::PointF()); 6882 inner_scroll->SetPosition(gfx::PointF());
6881 6883
6882 scoped_ptr<LayerImpl> outer_clip = 6884 scoped_ptr<LayerImpl> outer_clip =
6883 LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); 6885 LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId);
6884 outer_clip->SetBounds(outer_viewport); 6886 outer_clip->SetBounds(outer_viewport);
6885 outer_clip->SetIsContainerForFixedPositionLayers(true); 6887 outer_clip->SetIsContainerForFixedPositionLayers(true);
6886 6888
6887 scoped_ptr<LayerImpl> outer_scroll = 6889 scoped_ptr<LayerImpl> outer_scroll =
6888 LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); 6890 LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId);
6889 outer_scroll->SetScrollClipLayer(outer_clip->id()); 6891 outer_scroll->SetScrollClipLayer(outer_clip->id());
6890 outer_scroll->SetScrollOffset(gfx::Vector2d()); 6892 outer_scroll->SetScrollOffset(gfx::ScrollOffset());
6891 outer_scroll->SetBounds(content_size); 6893 outer_scroll->SetBounds(content_size);
6892 outer_scroll->SetContentBounds(content_size); 6894 outer_scroll->SetContentBounds(content_size);
6893 outer_scroll->SetPosition(gfx::PointF()); 6895 outer_scroll->SetPosition(gfx::PointF());
6894 6896
6895 scoped_ptr<LayerImpl> contents = 6897 scoped_ptr<LayerImpl> contents =
6896 LayerImpl::Create(layer_tree_impl, 8); 6898 LayerImpl::Create(layer_tree_impl, 8);
6897 contents->SetDrawsContent(true); 6899 contents->SetDrawsContent(true);
6898 contents->SetBounds(content_size); 6900 contents->SetBounds(content_size);
6899 contents->SetContentBounds(content_size); 6901 contents->SetContentBounds(content_size);
6900 contents->SetPosition(gfx::PointF()); 6902 contents->SetPosition(gfx::PointF());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
7021 base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); 7023 base::TimeTicks() + base::TimeDelta::FromMilliseconds(100);
7022 7024
7023 EXPECT_EQ(InputHandler::ScrollStarted, 7025 EXPECT_EQ(InputHandler::ScrollStarted,
7024 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50))); 7026 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)));
7025 7027
7026 LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); 7028 LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer();
7027 7029
7028 host_impl_->Animate(start_time); 7030 host_impl_->Animate(start_time);
7029 host_impl_->UpdateAnimationState(true); 7031 host_impl_->UpdateAnimationState(true);
7030 7032
7031 EXPECT_EQ(gfx::Vector2dF(), scrolling_layer->TotalScrollOffset()); 7033 EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->TotalScrollOffset());
7032 7034
7033 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(50)); 7035 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(50));
7034 host_impl_->UpdateAnimationState(true); 7036 host_impl_->UpdateAnimationState(true);
7035 7037
7036 float y = scrolling_layer->TotalScrollOffset().y(); 7038 float y = scrolling_layer->TotalScrollOffset().y();
7037 EXPECT_TRUE(y > 1 && y < 49); 7039 EXPECT_TRUE(y > 1 && y < 49);
7038 7040
7039 // Update target. 7041 // Update target.
7040 EXPECT_EQ(InputHandler::ScrollStarted, 7042 EXPECT_EQ(InputHandler::ScrollStarted,
7041 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50))); 7043 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)));
7042 7044
7043 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(200)); 7045 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(200));
7044 host_impl_->UpdateAnimationState(true); 7046 host_impl_->UpdateAnimationState(true);
7045 7047
7046 y = scrolling_layer->TotalScrollOffset().y(); 7048 y = scrolling_layer->TotalScrollOffset().y();
7047 EXPECT_TRUE(y > 50 && y < 100); 7049 EXPECT_TRUE(y > 50 && y < 100);
7048 EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); 7050 EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer());
7049 7051
7050 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(250)); 7052 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(250));
7051 host_impl_->UpdateAnimationState(true); 7053 host_impl_->UpdateAnimationState(true);
7052 7054
7053 EXPECT_EQ(gfx::Vector2dF(0, 100), scrolling_layer->TotalScrollOffset()); 7055 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100),
7056 scrolling_layer->TotalScrollOffset());
7054 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); 7057 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer());
7055 } 7058 }
7056 7059
7057 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { 7060 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) {
7058 host_impl_->CreatePendingTree(); 7061 host_impl_->CreatePendingTree();
7059 host_impl_->ActivateSyncTree(); 7062 host_impl_->ActivateSyncTree();
7060 host_impl_->CreatePendingTree(); 7063 host_impl_->CreatePendingTree();
7061 7064
7062 LayerTreeImpl* active_tree = host_impl_->active_tree(); 7065 LayerTreeImpl* active_tree = host_impl_->active_tree();
7063 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 7066 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
7167 // surface. 7170 // surface.
7168 EXPECT_EQ(0, num_lost_surfaces_); 7171 EXPECT_EQ(0, num_lost_surfaces_);
7169 host_impl_->DidLoseOutputSurface(); 7172 host_impl_->DidLoseOutputSurface();
7170 EXPECT_EQ(1, num_lost_surfaces_); 7173 EXPECT_EQ(1, num_lost_surfaces_);
7171 host_impl_->DidLoseOutputSurface(); 7174 host_impl_->DidLoseOutputSurface();
7172 EXPECT_LE(1, num_lost_surfaces_); 7175 EXPECT_LE(1, num_lost_surfaces_);
7173 } 7176 }
7174 7177
7175 } // namespace 7178 } // namespace
7176 } // namespace cc 7179 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698