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

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 783543003: Update from https://crrev.com/306901 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 scrollbar_fade_start_ = start_fade; 148 scrollbar_fade_start_ = start_fade;
149 requested_scrollbar_animation_delay_ = delay; 149 requested_scrollbar_animation_delay_ = delay;
150 } 150 }
151 void DidActivateSyncTree() override {} 151 void DidActivateSyncTree() override {}
152 void DidManageTiles() override {} 152 void DidManageTiles() override {}
153 153
154 void set_reduce_memory_result(bool reduce_memory_result) { 154 void set_reduce_memory_result(bool reduce_memory_result) {
155 reduce_memory_result_ = reduce_memory_result; 155 reduce_memory_result_ = reduce_memory_result;
156 } 156 }
157 157
158 bool CreateHostImpl(const LayerTreeSettings& settings, 158 virtual bool CreateHostImpl(const LayerTreeSettings& settings,
159 scoped_ptr<OutputSurface> output_surface) { 159 scoped_ptr<OutputSurface> output_surface) {
160 host_impl_ = LayerTreeHostImpl::Create(settings, 160 host_impl_ = LayerTreeHostImpl::Create(settings,
161 this, 161 this,
162 &proxy_, 162 &proxy_,
163 &stats_instrumentation_, 163 &stats_instrumentation_,
164 shared_bitmap_manager_.get(), 164 shared_bitmap_manager_.get(),
165 gpu_memory_buffer_manager_.get(), 165 gpu_memory_buffer_manager_.get(),
166 0); 166 0);
167 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); 167 bool init = host_impl_->InitializeRenderer(output_surface.Pass());
168 host_impl_->SetViewportSize(gfx::Size(10, 10)); 168 host_impl_->SetViewportSize(gfx::Size(10, 10));
169 return init; 169 return init;
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 912
913 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); 913 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer());
914 LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); 914 LayerImpl* container_layer = scroll_layer->scroll_clip_layer();
915 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 915 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
916 916
917 float min_page_scale = 1.f, max_page_scale = 4.f; 917 float min_page_scale = 1.f, max_page_scale = 4.f;
918 float page_scale_factor = 1.f; 918 float page_scale_factor = 1.f;
919 919
920 // The impl-based pinch zoom should adjust the max scroll position. 920 // The impl-based pinch zoom should adjust the max scroll position.
921 { 921 {
922 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 922 host_impl_->active_tree()->PushPageScaleFromMainThread(
923 page_scale_factor, min_page_scale, max_page_scale); 923 page_scale_factor, min_page_scale, max_page_scale);
924 host_impl_->active_tree()->SetPageScaleDelta(1.f); 924 host_impl_->SetPageScaleOnActiveTree(page_scale_factor);
925 scroll_layer->SetScrollDelta(gfx::Vector2d()); 925 scroll_layer->SetScrollDelta(gfx::Vector2d());
926 926
927 float page_scale_delta = 2.f; 927 float page_scale_delta = 2.f;
928 928
929 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 929 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
930 host_impl_->PinchGestureBegin(); 930 host_impl_->PinchGestureBegin();
931 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 931 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
932 host_impl_->PinchGestureEnd(); 932 host_impl_->PinchGestureEnd();
933 host_impl_->ScrollEnd(); 933 host_impl_->ScrollEnd();
934 EXPECT_FALSE(did_request_animate_); 934 EXPECT_FALSE(did_request_animate_);
935 EXPECT_TRUE(did_request_redraw_); 935 EXPECT_TRUE(did_request_redraw_);
936 EXPECT_TRUE(did_request_commit_); 936 EXPECT_TRUE(did_request_commit_);
937 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 937 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
938 938
939 scoped_ptr<ScrollAndScaleSet> scroll_info = 939 scoped_ptr<ScrollAndScaleSet> scroll_info =
940 host_impl_->ProcessScrollDeltas(); 940 host_impl_->ProcessScrollDeltas();
941 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 941 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
942 942
943 EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), 943 EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(),
944 scroll_layer->MaxScrollOffset().ToString()); 944 scroll_layer->MaxScrollOffset().ToString());
945 } 945 }
946 946
947 // Scrolling after a pinch gesture should always be in local space. The 947 // Scrolling after a pinch gesture should always be in local space. The
948 // scroll deltas have the page scale factor applied. 948 // scroll deltas have the page scale factor applied.
949 { 949 {
950 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 950 host_impl_->active_tree()->PushPageScaleFromMainThread(
951 page_scale_factor, min_page_scale, max_page_scale); 951 page_scale_factor, min_page_scale, max_page_scale);
952 host_impl_->active_tree()->SetPageScaleDelta(1.f); 952 host_impl_->SetPageScaleOnActiveTree(page_scale_factor);
953 scroll_layer->SetScrollDelta(gfx::Vector2d()); 953 scroll_layer->SetScrollDelta(gfx::Vector2d());
954 954
955 float page_scale_delta = 2.f; 955 float page_scale_delta = 2.f;
956 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 956 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
957 host_impl_->PinchGestureBegin(); 957 host_impl_->PinchGestureBegin();
958 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); 958 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point());
959 host_impl_->PinchGestureEnd(); 959 host_impl_->PinchGestureEnd();
960 host_impl_->ScrollEnd(); 960 host_impl_->ScrollEnd();
961 961
962 gfx::Vector2d scroll_delta(0, 10); 962 gfx::Vector2d scroll_delta(0, 10);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 DrawFrame(); 997 DrawFrame();
998 998
999 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); 999 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer();
1000 DCHECK(scroll_layer); 1000 DCHECK(scroll_layer);
1001 1001
1002 float min_page_scale = 1.f; 1002 float min_page_scale = 1.f;
1003 float max_page_scale = 4.f; 1003 float max_page_scale = 4.f;
1004 1004
1005 // Basic pinch zoom in gesture 1005 // Basic pinch zoom in gesture
1006 { 1006 {
1007 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1007 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1008 min_page_scale,
1009 max_page_scale); 1008 max_page_scale);
1010 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1009 scroll_layer->SetScrollDelta(gfx::Vector2d());
1011 1010
1012 float page_scale_delta = 2.f; 1011 float page_scale_delta = 2.f;
1013 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 1012 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
1014 host_impl_->PinchGestureBegin(); 1013 host_impl_->PinchGestureBegin();
1015 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 1014 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
1016 host_impl_->PinchGestureEnd(); 1015 host_impl_->PinchGestureEnd();
1017 host_impl_->ScrollEnd(); 1016 host_impl_->ScrollEnd();
1018 EXPECT_FALSE(did_request_animate_); 1017 EXPECT_FALSE(did_request_animate_);
1019 EXPECT_TRUE(did_request_redraw_); 1018 EXPECT_TRUE(did_request_redraw_);
1020 EXPECT_TRUE(did_request_commit_); 1019 EXPECT_TRUE(did_request_commit_);
1021 1020
1022 scoped_ptr<ScrollAndScaleSet> scroll_info = 1021 scoped_ptr<ScrollAndScaleSet> scroll_info =
1023 host_impl_->ProcessScrollDeltas(); 1022 host_impl_->ProcessScrollDeltas();
1024 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1023 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1025 } 1024 }
1026 1025
1027 // Zoom-in clamping 1026 // Zoom-in clamping
1028 { 1027 {
1029 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1028 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1030 min_page_scale,
1031 max_page_scale); 1029 max_page_scale);
1032 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1030 scroll_layer->SetScrollDelta(gfx::Vector2d());
1033 float page_scale_delta = 10.f; 1031 float page_scale_delta = 10.f;
1034 1032
1035 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 1033 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
1036 host_impl_->PinchGestureBegin(); 1034 host_impl_->PinchGestureBegin();
1037 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 1035 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
1038 host_impl_->PinchGestureEnd(); 1036 host_impl_->PinchGestureEnd();
1039 host_impl_->ScrollEnd(); 1037 host_impl_->ScrollEnd();
1040 1038
1041 scoped_ptr<ScrollAndScaleSet> scroll_info = 1039 scoped_ptr<ScrollAndScaleSet> scroll_info =
1042 host_impl_->ProcessScrollDeltas(); 1040 host_impl_->ProcessScrollDeltas();
1043 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); 1041 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale);
1044 } 1042 }
1045 1043
1046 // Zoom-out clamping 1044 // Zoom-out clamping
1047 { 1045 {
1048 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1046 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1049 min_page_scale,
1050 max_page_scale); 1047 max_page_scale);
1051 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1048 scroll_layer->SetScrollDelta(gfx::Vector2d());
1052 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); 1049 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1053 1050
1054 float page_scale_delta = 0.1f; 1051 float page_scale_delta = 0.1f;
1055 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 1052 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
1056 host_impl_->PinchGestureBegin(); 1053 host_impl_->PinchGestureBegin();
1057 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); 1054 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point());
1058 host_impl_->PinchGestureEnd(); 1055 host_impl_->PinchGestureEnd();
1059 host_impl_->ScrollEnd(); 1056 host_impl_->ScrollEnd();
1060 1057
1061 scoped_ptr<ScrollAndScaleSet> scroll_info = 1058 scoped_ptr<ScrollAndScaleSet> scroll_info =
1062 host_impl_->ProcessScrollDeltas(); 1059 host_impl_->ProcessScrollDeltas();
1063 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); 1060 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale);
1064 1061
1065 EXPECT_TRUE(scroll_info->scrolls.empty()); 1062 EXPECT_TRUE(scroll_info->scrolls.empty());
1066 } 1063 }
1067 1064
1068 // Two-finger panning should not happen based on pinch events only 1065 // Two-finger panning should not happen based on pinch events only
1069 { 1066 {
1070 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1067 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1071 min_page_scale,
1072 max_page_scale); 1068 max_page_scale);
1073 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1069 scroll_layer->SetScrollDelta(gfx::Vector2d());
1074 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); 1070 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1075 1071
1076 float page_scale_delta = 1.f; 1072 float page_scale_delta = 1.f;
1077 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1073 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1078 host_impl_->PinchGestureBegin(); 1074 host_impl_->PinchGestureBegin();
1079 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1075 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1080 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1076 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1081 host_impl_->PinchGestureEnd(); 1077 host_impl_->PinchGestureEnd();
1082 host_impl_->ScrollEnd(); 1078 host_impl_->ScrollEnd();
1083 1079
1084 scoped_ptr<ScrollAndScaleSet> scroll_info = 1080 scoped_ptr<ScrollAndScaleSet> scroll_info =
1085 host_impl_->ProcessScrollDeltas(); 1081 host_impl_->ProcessScrollDeltas();
1086 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1082 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1087 EXPECT_TRUE(scroll_info->scrolls.empty()); 1083 EXPECT_TRUE(scroll_info->scrolls.empty());
1088 } 1084 }
1089 1085
1090 // Two-finger panning should work with interleaved scroll events 1086 // Two-finger panning should work with interleaved scroll events
1091 { 1087 {
1092 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1088 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1093 min_page_scale,
1094 max_page_scale); 1089 max_page_scale);
1095 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1090 scroll_layer->SetScrollDelta(gfx::Vector2d());
1096 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20)); 1091 scroll_layer->SetScrollOffset(gfx::ScrollOffset(20, 20));
1097 1092
1098 float page_scale_delta = 1.f; 1093 float page_scale_delta = 1.f;
1099 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture); 1094 host_impl_->ScrollBegin(gfx::Point(10, 10), InputHandler::Gesture);
1100 host_impl_->PinchGestureBegin(); 1095 host_impl_->PinchGestureBegin();
1101 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); 1096 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10));
1102 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10)); 1097 host_impl_->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10));
1103 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); 1098 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20));
1104 host_impl_->PinchGestureEnd(); 1099 host_impl_->PinchGestureEnd();
1105 host_impl_->ScrollEnd(); 1100 host_impl_->ScrollEnd();
1106 1101
1107 scoped_ptr<ScrollAndScaleSet> scroll_info = 1102 scoped_ptr<ScrollAndScaleSet> scroll_info =
1108 host_impl_->ProcessScrollDeltas(); 1103 host_impl_->ProcessScrollDeltas();
1109 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 1104 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
1110 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); 1105 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10));
1111 } 1106 }
1112 1107
1113 // Two-finger panning should work when starting fully zoomed out. 1108 // Two-finger panning should work when starting fully zoomed out.
1114 { 1109 {
1115 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, 1110 host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f);
1116 0.5f,
1117 4.f);
1118 scroll_layer->SetScrollDelta(gfx::Vector2d()); 1111 scroll_layer->SetScrollDelta(gfx::Vector2d());
1119 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 1112 scroll_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
1120 1113
1121 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); 1114 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture);
1122 host_impl_->PinchGestureBegin(); 1115 host_impl_->PinchGestureBegin();
1123 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); 1116 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0));
1124 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); 1117 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0));
1125 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); 1118 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10));
1126 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); 1119 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10));
1127 host_impl_->PinchGestureEnd(); 1120 host_impl_->PinchGestureEnd();
(...skipping 17 matching lines...) Expand all
1145 float min_page_scale = 0.5f; 1138 float min_page_scale = 0.5f;
1146 float max_page_scale = 4.f; 1139 float max_page_scale = 4.f;
1147 base::TimeTicks start_time = base::TimeTicks() + 1140 base::TimeTicks start_time = base::TimeTicks() +
1148 base::TimeDelta::FromSeconds(1); 1141 base::TimeDelta::FromSeconds(1);
1149 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 1142 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
1150 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1143 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1151 base::TimeTicks end_time = start_time + duration; 1144 base::TimeTicks end_time = start_time + duration;
1152 1145
1153 // Non-anchor zoom-in 1146 // Non-anchor zoom-in
1154 { 1147 {
1155 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1148 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1156 min_page_scale,
1157 max_page_scale); 1149 max_page_scale);
1158 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); 1150 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1159 1151
1160 did_request_redraw_ = false; 1152 did_request_redraw_ = false;
1161 did_request_animate_ = false; 1153 did_request_animate_ = false;
1162 host_impl_->active_tree()->SetPendingPageScaleAnimation( 1154 host_impl_->active_tree()->SetPendingPageScaleAnimation(
1163 scoped_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( 1155 scoped_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation(
1164 gfx::Vector2d(), 1156 gfx::Vector2d(),
1165 false, 1157 false,
1166 2.f, 1158 2.f,
(...skipping 22 matching lines...) Expand all
1189 EXPECT_FALSE(did_request_animate_); 1181 EXPECT_FALSE(did_request_animate_);
1190 1182
1191 scoped_ptr<ScrollAndScaleSet> scroll_info = 1183 scoped_ptr<ScrollAndScaleSet> scroll_info =
1192 host_impl_->ProcessScrollDeltas(); 1184 host_impl_->ProcessScrollDeltas();
1193 EXPECT_EQ(scroll_info->page_scale_delta, 2); 1185 EXPECT_EQ(scroll_info->page_scale_delta, 2);
1194 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); 1186 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50));
1195 } 1187 }
1196 1188
1197 // Anchor zoom-out 1189 // Anchor zoom-out
1198 { 1190 {
1199 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1191 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1200 min_page_scale,
1201 max_page_scale); 1192 max_page_scale);
1202 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); 1193 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1203 1194
1204 did_request_redraw_ = false; 1195 did_request_redraw_ = false;
1205 did_request_animate_ = false; 1196 did_request_animate_ = false;
1206 host_impl_->active_tree()->SetPendingPageScaleAnimation( 1197 host_impl_->active_tree()->SetPendingPageScaleAnimation(
1207 scoped_ptr<PendingPageScaleAnimation> (new PendingPageScaleAnimation( 1198 scoped_ptr<PendingPageScaleAnimation> (new PendingPageScaleAnimation(
1208 gfx::Vector2d(25, 25), 1199 gfx::Vector2d(25, 25),
1209 true, 1200 true,
1210 min_page_scale, 1201 min_page_scale,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 float min_page_scale = 0.5f; 1237 float min_page_scale = 0.5f;
1247 float max_page_scale = 4.f; 1238 float max_page_scale = 4.f;
1248 base::TimeTicks start_time = base::TimeTicks() + 1239 base::TimeTicks start_time = base::TimeTicks() +
1249 base::TimeDelta::FromSeconds(1); 1240 base::TimeDelta::FromSeconds(1);
1250 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 1241 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
1251 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1242 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1252 base::TimeTicks end_time = start_time + duration; 1243 base::TimeTicks end_time = start_time + duration;
1253 1244
1254 // Anchor zoom with unchanged page scale should not change scroll or scale. 1245 // Anchor zoom with unchanged page scale should not change scroll or scale.
1255 { 1246 {
1256 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1247 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1257 min_page_scale,
1258 max_page_scale); 1248 max_page_scale);
1259 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50)); 1249 scroll_layer->SetScrollOffset(gfx::ScrollOffset(50, 50));
1260 1250
1261 host_impl_->active_tree()->SetPendingPageScaleAnimation( 1251 host_impl_->active_tree()->SetPendingPageScaleAnimation(
1262 scoped_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( 1252 scoped_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation(
1263 gfx::Vector2d(), 1253 gfx::Vector2d(),
1264 true, 1254 true,
1265 1.f, 1255 1.f,
1266 duration))); 1256 duration)));
1267 host_impl_->ActivateSyncTree(); 1257 host_impl_->ActivateSyncTree();
(...skipping 16 matching lines...) Expand all
1284 host_impl_->pending_tree(), 1274 host_impl_->pending_tree(),
1285 gfx::Size(100, 100)); 1275 gfx::Size(100, 100));
1286 host_impl_->ActivateSyncTree(); 1276 host_impl_->ActivateSyncTree();
1287 DrawFrame(); 1277 DrawFrame();
1288 1278
1289 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); 1279 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer();
1290 DCHECK(scroll_layer); 1280 DCHECK(scroll_layer);
1291 1281
1292 float min_page_scale = 0.5f; 1282 float min_page_scale = 0.5f;
1293 float max_page_scale = 4.f; 1283 float max_page_scale = 4.f;
1294 host_impl_->sync_tree()->SetPageScaleFactorAndLimits(1.f, 1284 host_impl_->sync_tree()->PushPageScaleFromMainThread(1.f, min_page_scale,
1295 min_page_scale,
1296 max_page_scale); 1285 max_page_scale);
1297 host_impl_->ActivateSyncTree(); 1286 host_impl_->ActivateSyncTree();
1298 1287
1299 base::TimeTicks start_time = base::TimeTicks() + 1288 base::TimeTicks start_time = base::TimeTicks() +
1300 base::TimeDelta::FromSeconds(1); 1289 base::TimeDelta::FromSeconds(1);
1301 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 1290 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
1302 base::TimeTicks third_through_animation = start_time + duration / 3; 1291 base::TimeTicks third_through_animation = start_time + duration / 3;
1303 base::TimeTicks halfway_through_animation = start_time + duration / 2; 1292 base::TimeTicks halfway_through_animation = start_time + duration / 2;
1304 base::TimeTicks end_time = start_time + duration; 1293 base::TimeTicks end_time = start_time + duration;
1305 float target_scale = 2.f; 1294 float target_scale = 2.f;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 LayerTreeSettings settings; 1504 LayerTreeSettings settings;
1516 settings.scrollbar_animator = LayerTreeSettings::LinearFade; 1505 settings.scrollbar_animator = LayerTreeSettings::LinearFade;
1517 settings.scrollbar_fade_delay_ms = 20; 1506 settings.scrollbar_fade_delay_ms = 20;
1518 settings.scrollbar_fade_duration_ms = 20; 1507 settings.scrollbar_fade_duration_ms = 20;
1519 settings.use_pinch_zoom_scrollbars = true; 1508 settings.use_pinch_zoom_scrollbars = true;
1520 1509
1521 SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST(); 1510 SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST();
1522 1511
1523 base::TimeTicks fake_now = gfx::FrameTime::Now(); 1512 base::TimeTicks fake_now = gfx::FrameTime::Now();
1524 1513
1525 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); 1514 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f);
1526 1515
1527 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1516 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1528 EXPECT_FALSE(did_request_animate_); 1517 EXPECT_FALSE(did_request_animate_);
1529 1518
1530 // If no scroll happened during a scroll gesture, it should have no effect. 1519 // If no scroll happened during a scroll gesture, it should have no effect.
1531 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1520 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1532 host_impl_->ScrollEnd(); 1521 host_impl_->ScrollEnd();
1533 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1522 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1534 EXPECT_FALSE(did_request_animate_); 1523 EXPECT_FALSE(did_request_animate_);
1535 EXPECT_TRUE(scrollbar_fade_start_.Equals(base::Closure())); 1524 EXPECT_TRUE(scrollbar_fade_start_.Equals(base::Closure()));
1536 1525
1537 // After a scroll, no fade animation should be scheduled. 1526 // After a scroll, no fade animation should be scheduled.
1538 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1527 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1539 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1528 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1540 host_impl_->ScrollEnd(); 1529 host_impl_->ScrollEnd();
1541 did_request_redraw_ = false; 1530 did_request_redraw_ = false;
1542 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1531 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1543 EXPECT_FALSE(did_request_animate_); 1532 EXPECT_FALSE(did_request_animate_);
1544 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1533 requested_scrollbar_animation_delay_ = base::TimeDelta();
1545 1534
1546 // We should not see any draw requests. 1535 // We should not see any draw requests.
1547 fake_now += base::TimeDelta::FromMilliseconds(25); 1536 fake_now += base::TimeDelta::FromMilliseconds(25);
1548 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); 1537 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_);
1549 EXPECT_FALSE(did_request_animate_); 1538 EXPECT_FALSE(did_request_animate_);
1550 1539
1551 // Make page scale > min so that subsequent scrolls will trigger fades. 1540 // Make page scale > min so that subsequent scrolls will trigger fades.
1552 host_impl_->active_tree()->SetPageScaleDelta(1.1f); 1541 host_impl_->SetPageScaleOnActiveTree(1.1f);
1553 1542
1554 // After a scroll, a fade animation should be scheduled about 20ms from now. 1543 // After a scroll, a fade animation should be scheduled about 20ms from now.
1555 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel); 1544 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel);
1556 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); 1545 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0));
1557 host_impl_->ScrollEnd(); 1546 host_impl_->ScrollEnd();
1558 did_request_redraw_ = false; 1547 did_request_redraw_ = false;
1559 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), 1548 EXPECT_LT(base::TimeDelta::FromMilliseconds(19),
1560 requested_scrollbar_animation_delay_); 1549 requested_scrollbar_animation_delay_);
1561 EXPECT_FALSE(did_request_animate_); 1550 EXPECT_FALSE(did_request_animate_);
1562 requested_scrollbar_animation_delay_ = base::TimeDelta(); 1551 requested_scrollbar_animation_delay_ = base::TimeDelta();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 SetupMouseMoveAtWithDeviceScale(1.f); 1646 SetupMouseMoveAtWithDeviceScale(1.f);
1658 } 1647 }
1659 1648
1660 TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf2) { 1649 TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf2) {
1661 SetupMouseMoveAtWithDeviceScale(2.f); 1650 SetupMouseMoveAtWithDeviceScale(2.f);
1662 } 1651 }
1663 1652
1664 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { 1653 TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
1665 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 1654 SetupScrollAndContentsLayers(gfx::Size(100, 100));
1666 host_impl_->SetViewportSize(gfx::Size(50, 50)); 1655 host_impl_->SetViewportSize(gfx::Size(50, 50));
1667 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 1656 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
1668 DrawFrame(); 1657 DrawFrame();
1669 { 1658 {
1670 CompositorFrameMetadata metadata = 1659 CompositorFrameMetadata metadata =
1671 host_impl_->MakeCompositorFrameMetadata(); 1660 host_impl_->MakeCompositorFrameMetadata();
1672 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); 1661 EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset);
1673 EXPECT_EQ(1.f, metadata.page_scale_factor); 1662 EXPECT_EQ(1.f, metadata.page_scale_factor);
1674 EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.scrollable_viewport_size); 1663 EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.scrollable_viewport_size);
1675 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); 1664 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
1676 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 1665 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
1677 EXPECT_EQ(4.f, metadata.max_page_scale_factor); 1666 EXPECT_EQ(4.f, metadata.max_page_scale_factor);
(...skipping 27 matching lines...) Expand all
1705 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); 1694 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
1706 EXPECT_EQ(2.f, metadata.page_scale_factor); 1695 EXPECT_EQ(2.f, metadata.page_scale_factor);
1707 EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.scrollable_viewport_size); 1696 EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.scrollable_viewport_size);
1708 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); 1697 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
1709 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 1698 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
1710 EXPECT_EQ(4.f, metadata.max_page_scale_factor); 1699 EXPECT_EQ(4.f, metadata.max_page_scale_factor);
1711 } 1700 }
1712 1701
1713 // Likewise if set from the main thread. 1702 // Likewise if set from the main thread.
1714 host_impl_->ProcessScrollDeltas(); 1703 host_impl_->ProcessScrollDeltas();
1715 host_impl_->active_tree()->SetPageScaleFactorAndLimits(4.f, 0.5f, 4.f); 1704 host_impl_->active_tree()->PushPageScaleFromMainThread(4.f, 0.5f, 4.f);
1716 host_impl_->active_tree()->SetPageScaleDelta(1.f); 1705 host_impl_->SetPageScaleOnActiveTree(4.f);
1717 { 1706 {
1718 CompositorFrameMetadata metadata = 1707 CompositorFrameMetadata metadata =
1719 host_impl_->MakeCompositorFrameMetadata(); 1708 host_impl_->MakeCompositorFrameMetadata();
1720 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); 1709 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
1721 EXPECT_EQ(4.f, metadata.page_scale_factor); 1710 EXPECT_EQ(4.f, metadata.page_scale_factor);
1722 EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.scrollable_viewport_size); 1711 EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.scrollable_viewport_size);
1723 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); 1712 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
1724 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 1713 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
1725 EXPECT_EQ(4.f, metadata.max_page_scale_factor); 1714 EXPECT_EQ(4.f, metadata.max_page_scale_factor);
1726 } 1715 }
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 EXPECT_FALSE(did_request_commit_); 2247 EXPECT_FALSE(did_request_commit_);
2259 } 2248 }
2260 2249
2261 // TODO(bokan): Convert these tests to create inner and outer viewports. 2250 // TODO(bokan): Convert these tests to create inner and outer viewports.
2262 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { 2251 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
2263 public: 2252 public:
2264 LayerTreeHostImplTopControlsTest() 2253 LayerTreeHostImplTopControlsTest()
2265 // Make the clip size the same as the layer (content) size so the layer is 2254 // Make the clip size the same as the layer (content) size so the layer is
2266 // non-scrollable. 2255 // non-scrollable.
2267 : layer_size_(10, 10), 2256 : layer_size_(10, 10),
2268 clip_size_(layer_size_) { 2257 clip_size_(layer_size_),
2258 top_controls_height_(50) {
2269 settings_.calculate_top_controls_position = true; 2259 settings_.calculate_top_controls_position = true;
2270 settings_.top_controls_height = 50;
2271 settings_.use_pinch_virtual_viewport = true; 2260 settings_.use_pinch_virtual_viewport = true;
2272 2261
2273 viewport_size_ = 2262 viewport_size_ = gfx::Size(clip_size_.width(),
2274 gfx::Size(clip_size_.width(), 2263 clip_size_.height() + top_controls_height_);
2275 clip_size_.height() + settings_.top_controls_height); 2264 }
2265
2266 bool CreateHostImpl(const LayerTreeSettings& settings,
2267 scoped_ptr<OutputSurface> output_surface) override {
2268 bool init =
2269 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass());
2270 if (init && settings.calculate_top_controls_position) {
2271 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
2272 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_);
2273 host_impl_->top_controls_manager()->SetTopControlsHeight(
2274 top_controls_height_);
2275 host_impl_->DidChangeTopControlsPosition();
2276 }
2277 return init;
2276 } 2278 }
2277 2279
2278 void SetupTopControlsAndScrollLayer() { 2280 void SetupTopControlsAndScrollLayer() {
2279 scoped_ptr<LayerImpl> root = 2281 scoped_ptr<LayerImpl> root =
2280 LayerImpl::Create(host_impl_->active_tree(), 1); 2282 LayerImpl::Create(host_impl_->active_tree(), 1);
2281 scoped_ptr<LayerImpl> root_clip = 2283 scoped_ptr<LayerImpl> root_clip =
2282 LayerImpl::Create(host_impl_->active_tree(), 2); 2284 LayerImpl::Create(host_impl_->active_tree(), 2);
2283 root_clip->SetBounds(clip_size_); 2285 root_clip->SetBounds(clip_size_);
2284 root->SetScrollClipLayer(root_clip->id()); 2286 root->SetScrollClipLayer(root_clip->id());
2285 root->SetBounds(layer_size_); 2287 root->SetBounds(layer_size_);
2286 root->SetContentBounds(layer_size_); 2288 root->SetContentBounds(layer_size_);
2287 root->SetPosition(gfx::PointF()); 2289 root->SetPosition(gfx::PointF());
2288 root->SetDrawsContent(false); 2290 root->SetDrawsContent(false);
2289 root->SetIsContainerForFixedPositionLayers(true); 2291 root->SetIsContainerForFixedPositionLayers(true);
2290 int inner_viewport_scroll_layer_id = root->id(); 2292 int inner_viewport_scroll_layer_id = root->id();
2291 int page_scale_layer_id = root_clip->id(); 2293 int page_scale_layer_id = root_clip->id();
2292 root_clip->AddChild(root.Pass()); 2294 root_clip->AddChild(root.Pass());
2293 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 2295 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
2294 host_impl_->active_tree()->SetViewportLayersFromIds( 2296 host_impl_->active_tree()->SetViewportLayersFromIds(
2295 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id, 2297 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id,
2296 Layer::INVALID_ID); 2298 Layer::INVALID_ID);
2297 // Set a viewport size that is large enough to contain both the top controls 2299 // Set a viewport size that is large enough to contain both the top controls
2298 // and some content. 2300 // and some content.
2299 host_impl_->SetViewportSize(viewport_size_); 2301 host_impl_->SetViewportSize(viewport_size_);
2300 host_impl_->SetTopControlsLayoutHeight( 2302 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2301 settings_.top_controls_height); 2303
2304 host_impl_->DidChangeTopControlsPosition();
2302 2305
2303 host_impl_->CreatePendingTree(); 2306 host_impl_->CreatePendingTree();
2304 root = 2307 root =
2305 LayerImpl::Create(host_impl_->sync_tree(), 1); 2308 LayerImpl::Create(host_impl_->sync_tree(), 1);
2306 root_clip = 2309 root_clip =
2307 LayerImpl::Create(host_impl_->sync_tree(), 2); 2310 LayerImpl::Create(host_impl_->sync_tree(), 2);
2308 root_clip->SetBounds(clip_size_); 2311 root_clip->SetBounds(clip_size_);
2309 root->SetScrollClipLayer(root_clip->id()); 2312 root->SetScrollClipLayer(root_clip->id());
2310 root->SetBounds(layer_size_); 2313 root->SetBounds(layer_size_);
2311 root->SetContentBounds(layer_size_); 2314 root->SetContentBounds(layer_size_);
2312 root->SetPosition(gfx::PointF()); 2315 root->SetPosition(gfx::PointF());
2313 root->SetDrawsContent(false); 2316 root->SetDrawsContent(false);
2314 root->SetIsContainerForFixedPositionLayers(true); 2317 root->SetIsContainerForFixedPositionLayers(true);
2315 inner_viewport_scroll_layer_id = root->id(); 2318 inner_viewport_scroll_layer_id = root->id();
2316 page_scale_layer_id = root_clip->id(); 2319 page_scale_layer_id = root_clip->id();
2317 root_clip->AddChild(root.Pass()); 2320 root_clip->AddChild(root.Pass());
2318 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass()); 2321 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass());
2319 host_impl_->sync_tree()->SetViewportLayersFromIds( 2322 host_impl_->sync_tree()->SetViewportLayersFromIds(
2320 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id, 2323 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id,
2321 Layer::INVALID_ID); 2324 Layer::INVALID_ID);
2322 // Set a viewport size that is large enough to contain both the top controls 2325 // Set a viewport size that is large enough to contain both the top controls
2323 // and some content. 2326 // and some content.
2324 host_impl_->SetViewportSize(viewport_size_); 2327 host_impl_->SetViewportSize(viewport_size_);
2325 host_impl_->sync_tree()->set_top_controls_layout_height( 2328 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2326 settings_.top_controls_height); 2329 host_impl_->DidChangeTopControlsPosition();
2327 } 2330 }
2328 2331
2329 void SetupTopControlsAndScrollLayerWithVirtualViewport( 2332 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2330 const gfx::Size& inner_viewport_size, 2333 const gfx::Size& inner_viewport_size,
2331 const gfx::Size& outer_viewport_size, 2334 const gfx::Size& outer_viewport_size,
2332 const gfx::Size& scroll_layer_size) { 2335 const gfx::Size& scroll_layer_size) {
2333 CreateHostImpl(settings_, CreateOutputSurface()); 2336 CreateHostImpl(settings_, CreateOutputSurface());
2334 host_impl_->SetTopControlsLayoutHeight( 2337 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2335 settings_.top_controls_height); 2338 host_impl_->DidChangeTopControlsPosition();
2336 2339
2337 scoped_ptr<LayerImpl> root = 2340 scoped_ptr<LayerImpl> root =
2338 LayerImpl::Create(host_impl_->active_tree(), 1); 2341 LayerImpl::Create(host_impl_->active_tree(), 1);
2339 scoped_ptr<LayerImpl> root_clip = 2342 scoped_ptr<LayerImpl> root_clip =
2340 LayerImpl::Create(host_impl_->active_tree(), 2); 2343 LayerImpl::Create(host_impl_->active_tree(), 2);
2341 scoped_ptr<LayerImpl> page_scale = 2344 scoped_ptr<LayerImpl> page_scale =
2342 LayerImpl::Create(host_impl_->active_tree(), 3); 2345 LayerImpl::Create(host_impl_->active_tree(), 3);
2343 2346
2344 scoped_ptr<LayerImpl> outer_scroll = 2347 scoped_ptr<LayerImpl> outer_scroll =
2345 LayerImpl::Create(host_impl_->active_tree(), 4); 2348 LayerImpl::Create(host_impl_->active_tree(), 4);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 2381
2379 host_impl_->SetViewportSize(inner_viewport_size); 2382 host_impl_->SetViewportSize(inner_viewport_size);
2380 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2383 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2381 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); 2384 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds());
2382 } 2385 }
2383 2386
2384 protected: 2387 protected:
2385 gfx::Size layer_size_; 2388 gfx::Size layer_size_;
2386 gfx::Size clip_size_; 2389 gfx::Size clip_size_;
2387 gfx::Size viewport_size_; 2390 gfx::Size viewport_size_;
2391 float top_controls_height_;
2388 2392
2389 LayerTreeSettings settings_; 2393 LayerTreeSettings settings_;
2390 }; // class LayerTreeHostImplTopControlsTest 2394 }; // class LayerTreeHostImplTopControlsTest
2391 2395
2392 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { 2396 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
2393 SetupTopControlsAndScrollLayerWithVirtualViewport( 2397 SetupTopControlsAndScrollLayerWithVirtualViewport(
2394 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); 2398 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10));
2395 DrawFrame(); 2399 DrawFrame();
2396 2400
2397 EXPECT_EQ(InputHandler::ScrollStarted, 2401 EXPECT_EQ(InputHandler::ScrollStarted,
(...skipping 28 matching lines...) Expand all
2426 host_impl_->active_tree()->InnerViewportScrollLayer(); 2430 host_impl_->active_tree()->InnerViewportScrollLayer();
2427 LayerImpl *inner_container = 2431 LayerImpl *inner_container =
2428 host_impl_->active_tree()->InnerViewportContainerLayer(); 2432 host_impl_->active_tree()->InnerViewportContainerLayer();
2429 LayerImpl *outer_scroll = 2433 LayerImpl *outer_scroll =
2430 host_impl_->active_tree()->OuterViewportScrollLayer(); 2434 host_impl_->active_tree()->OuterViewportScrollLayer();
2431 LayerImpl *outer_container = 2435 LayerImpl *outer_container =
2432 host_impl_->active_tree()->OuterViewportContainerLayer(); 2436 host_impl_->active_tree()->OuterViewportContainerLayer();
2433 2437
2434 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. 2438 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer.
2435 outer_scroll->SetDrawsContent(true); 2439 outer_scroll->SetDrawsContent(true);
2436 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 1.f, 2.f); 2440 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f);
2437 2441
2438 EXPECT_EQ(InputHandler::ScrollStarted, 2442 EXPECT_EQ(InputHandler::ScrollStarted,
2439 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2443 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2440 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f)); 2444 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f));
2441 2445
2442 // The entire scroll delta should have been used to hide the top controls. 2446 // The entire scroll delta should have been used to hide the top controls.
2443 // The viewport layers should be resized back to their full sizes. 2447 // The viewport layers should be resized back to their full sizes.
2444 EXPECT_EQ(0.f, 2448 EXPECT_EQ(0.f,
2445 host_impl_->active_tree()->total_top_controls_content_offset()); 2449 host_impl_->active_tree()->total_top_controls_content_offset());
2446 EXPECT_EQ(0.f, inner_scroll->TotalScrollOffset().y()); 2450 EXPECT_EQ(0.f, inner_scroll->TotalScrollOffset().y());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 } 2493 }
2490 2494
2491 // Test that the fixed position container delta is appropriately adjusted 2495 // Test that the fixed position container delta is appropriately adjusted
2492 // by the top controls showing/hiding and page scale doesn't affect it. 2496 // by the top controls showing/hiding and page scale doesn't affect it.
2493 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { 2497 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) {
2494 SetupTopControlsAndScrollLayerWithVirtualViewport( 2498 SetupTopControlsAndScrollLayerWithVirtualViewport(
2495 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); 2499 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100));
2496 DrawFrame(); 2500 DrawFrame();
2497 2501
2498 float page_scale = 1.5f; 2502 float page_scale = 1.5f;
2499 float top_controls_height = settings_.top_controls_height;
2500 LayerImpl* outer_viewport_scroll_layer = 2503 LayerImpl* outer_viewport_scroll_layer =
2501 host_impl_->active_tree()->OuterViewportScrollLayer(); 2504 host_impl_->active_tree()->OuterViewportScrollLayer();
2502 2505
2503 // Zoom in, since the fixed container is the outer viewport, the delta should 2506 // Zoom in, since the fixed container is the outer viewport, the delta should
2504 // not be scaled. 2507 // not be scaled.
2505 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); 2508 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f);
2506 2509
2507 EXPECT_EQ(InputHandler::ScrollStarted, 2510 EXPECT_EQ(InputHandler::ScrollStarted,
2508 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2511 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2509 2512
2510 // Scroll down, the top controls hiding should expand the viewport size so 2513 // Scroll down, the top controls hiding should expand the viewport size so
2511 // the delta should be equal to the scroll distance. 2514 // the delta should be equal to the scroll distance.
2512 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); 2515 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
2513 host_impl_->top_controls_manager()->ScrollBegin(); 2516 host_impl_->top_controls_manager()->ScrollBegin();
2514 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2517 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2515 EXPECT_EQ(top_controls_height - top_controls_scroll_delta.y(), 2518 EXPECT_EQ(top_controls_height_ - top_controls_scroll_delta.y(),
2516 host_impl_->top_controls_manager()->ContentTopOffset()); 2519 host_impl_->top_controls_manager()->ContentTopOffset());
2517 EXPECT_VECTOR_EQ(top_controls_scroll_delta, 2520 EXPECT_VECTOR_EQ(top_controls_scroll_delta,
2518 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2521 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2519 host_impl_->ScrollEnd(); 2522 host_impl_->ScrollEnd();
2520 2523
2521 // Scroll past the maximum extent. The delta shouldn't be greater than the 2524 // Scroll past the maximum extent. The delta shouldn't be greater than the
2522 // top controls height. 2525 // top controls height.
2523 host_impl_->top_controls_manager()->ScrollBegin(); 2526 host_impl_->top_controls_manager()->ScrollBegin();
2524 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2527 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2525 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2528 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2526 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2529 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2527 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2530 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2528 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height), 2531 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height_),
2529 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2532 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2530 host_impl_->ScrollEnd(); 2533 host_impl_->ScrollEnd();
2531 2534
2532 // Scroll in the direction to make the top controls show. 2535 // Scroll in the direction to make the top controls show.
2533 host_impl_->top_controls_manager()->ScrollBegin(); 2536 host_impl_->top_controls_manager()->ScrollBegin();
2534 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); 2537 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta);
2535 EXPECT_EQ(top_controls_scroll_delta.y(), 2538 EXPECT_EQ(top_controls_scroll_delta.y(),
2536 host_impl_->top_controls_manager()->ContentTopOffset()); 2539 host_impl_->top_controls_manager()->ContentTopOffset());
2537 EXPECT_VECTOR_EQ( 2540 EXPECT_VECTOR_EQ(
2538 gfx::Vector2dF(0, top_controls_height - top_controls_scroll_delta.y()), 2541 gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()),
2539 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2542 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2540 host_impl_->top_controls_manager()->ScrollEnd(); 2543 host_impl_->top_controls_manager()->ScrollEnd();
2541 } 2544 }
2542 2545
2543 // Ensure setting the top controls position explicitly using the setters on the 2546 // Ensure setting the top controls position explicitly using the setters on the
2544 // TreeImpl correctly affects the top controls manager and viewport bounds. 2547 // TreeImpl correctly affects the top controls manager and viewport bounds.
2545 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2548 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2546 CreateHostImpl(settings_, CreateOutputSurface()); 2549 CreateHostImpl(settings_, CreateOutputSurface());
2547 SetupTopControlsAndScrollLayer(); 2550 SetupTopControlsAndScrollLayer();
2548 DrawFrame(); 2551 DrawFrame();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 2602
2600 // Test that changing the top controls layout height is correctly applied to 2603 // Test that changing the top controls layout height is correctly applied to
2601 // the inner viewport container bounds. That is, the top controls layout 2604 // the inner viewport container bounds. That is, the top controls layout
2602 // height is the amount that the inner viewport container was shrunk outside 2605 // height is the amount that the inner viewport container was shrunk outside
2603 // the compositor to accommodate the top controls. 2606 // the compositor to accommodate the top controls.
2604 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { 2607 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
2605 CreateHostImpl(settings_, CreateOutputSurface()); 2608 CreateHostImpl(settings_, CreateOutputSurface());
2606 SetupTopControlsAndScrollLayer(); 2609 SetupTopControlsAndScrollLayer();
2607 DrawFrame(); 2610 DrawFrame();
2608 2611
2609 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2612 host_impl_->sync_tree()->set_top_controls_content_offset(50.f);
2610 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); 2613 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2611 2614
2612 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2615 host_impl_->active_tree()->set_top_controls_content_offset(50.f);
2613 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2616 host_impl_->active_tree()->set_top_controls_delta(-50.f);
2614 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f);
2615 2617
2616 host_impl_->DidChangeTopControlsPosition(); 2618 host_impl_->DidChangeTopControlsPosition();
2617 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2619 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2618 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2620 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2619 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2621 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2620 2622
2621 host_impl_->sync_tree()->root_layer()->SetBounds( 2623 host_impl_->sync_tree()->root_layer()->SetBounds(
2622 gfx::Size(root_clip_ptr->bounds().width(), 2624 gfx::Size(root_clip_ptr->bounds().width(),
2623 root_clip_ptr->bounds().height() - 15.f)); 2625 root_clip_ptr->bounds().height() - 50.f));
2624 2626
2625 host_impl_->ActivateSyncTree(); 2627 host_impl_->ActivateSyncTree();
2626 2628
2627 root_clip_ptr = host_impl_->active_tree()->root_layer(); 2629 root_clip_ptr = host_impl_->active_tree()->root_layer();
2628 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2630 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2629 2631
2630 // The total bounds should remain unchanged since the bounds delta should 2632 // The total bounds should remain unchanged since the bounds delta should
2631 // account for the difference between the layout height and the current 2633 // account for the difference between the layout height and the current
2632 // top controls offset. 2634 // top controls offset.
2633 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2635 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2634 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 15.f), root_clip_ptr->bounds_delta()); 2636 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), root_clip_ptr->bounds_delta());
2635 2637
2636 host_impl_->active_tree()->set_top_controls_delta(0.f); 2638 host_impl_->active_tree()->set_top_controls_delta(0.f);
2637 host_impl_->DidChangeTopControlsPosition(); 2639 host_impl_->DidChangeTopControlsPosition();
2638 2640
2639 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2641 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset());
2640 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); 2642 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta());
2641 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f), 2643 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f),
2642 root_clip_ptr->bounds()); 2644 root_clip_ptr->bounds());
2643 } 2645 }
2644 2646
2645 // Test that showing/hiding the top controls when the viewport is fully scrolled 2647 // Test that showing/hiding the top controls when the viewport is fully scrolled
2646 // doesn't incorrectly change the viewport offset due to clamping from changing 2648 // doesn't incorrectly change the viewport offset due to clamping from changing
2647 // viewport bounds. 2649 // viewport bounds.
2648 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { 2650 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) {
2649 SetupTopControlsAndScrollLayerWithVirtualViewport( 2651 SetupTopControlsAndScrollLayerWithVirtualViewport(
2650 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2652 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2651 DrawFrame(); 2653 DrawFrame();
2652 2654
2653 EXPECT_EQ(settings_.top_controls_height, 2655 EXPECT_EQ(top_controls_height_,
2654 host_impl_->active_tree()->total_top_controls_content_offset()); 2656 host_impl_->active_tree()->total_top_controls_content_offset());
2655 2657
2656 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); 2658 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
2657 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); 2659 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
2658 2660
2659 // Scroll the viewports to max scroll offset. 2661 // Scroll the viewports to max scroll offset.
2660 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); 2662 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2661 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); 2663 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2662 2664
2663 gfx::ScrollOffset viewport_offset = 2665 gfx::ScrollOffset viewport_offset =
2664 host_impl_->active_tree()->TotalScrollOffset(); 2666 host_impl_->active_tree()->TotalScrollOffset();
2665 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); 2667 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset);
2666 2668
2667 // Hide the top controls by 25px. 2669 // Hide the top controls by 25px.
2668 gfx::Vector2dF scroll_delta(0.f, 25.f); 2670 gfx::Vector2dF scroll_delta(0.f, 25.f);
2669 EXPECT_EQ(InputHandler::ScrollStarted, 2671 EXPECT_EQ(InputHandler::ScrollStarted,
2670 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2672 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2671 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2673 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2672 2674
2673 // scrolling down at the max extents no longer hides the top controls 2675 // scrolling down at the max extents no longer hides the top controls
2674 EXPECT_EQ(0.f, 2676 EXPECT_EQ(0.f,
2675 settings_.top_controls_height - 2677 top_controls_height_ -
2676 host_impl_->active_tree()->total_top_controls_content_offset()); 2678 host_impl_->active_tree()->total_top_controls_content_offset());
2677 2679
2678 // forcefully hide the top controls by 25px 2680 // forcefully hide the top controls by 25px
2679 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); 2681 host_impl_->top_controls_manager()->ScrollBy(scroll_delta);
2680 host_impl_->ScrollEnd(); 2682 host_impl_->ScrollEnd();
2681 2683
2682 EXPECT_EQ(scroll_delta.y(), 2684 EXPECT_EQ(scroll_delta.y(),
2683 settings_.top_controls_height - 2685 top_controls_height_ -
2684 host_impl_->active_tree()->total_top_controls_content_offset()); 2686 host_impl_->active_tree()->total_top_controls_content_offset());
2685 2687
2686 inner_scroll->ClampScrollToMaxScrollOffset(); 2688 inner_scroll->ClampScrollToMaxScrollOffset();
2687 outer_scroll->ClampScrollToMaxScrollOffset(); 2689 outer_scroll->ClampScrollToMaxScrollOffset();
2688 2690
2689 // We should still be fully scrolled. 2691 // We should still be fully scrolled.
2690 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), 2692 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2691 host_impl_->active_tree()->TotalScrollOffset()); 2693 host_impl_->active_tree()->TotalScrollOffset());
2692 2694
2693 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); 2695 viewport_offset = host_impl_->active_tree()->TotalScrollOffset();
(...skipping 16 matching lines...) Expand all
2710 host_impl_->active_tree()->TotalScrollOffset()); 2712 host_impl_->active_tree()->TotalScrollOffset());
2711 } 2713 }
2712 2714
2713 // Test that the top controls coming in and out maintains the same aspect ratio 2715 // Test that the top controls coming in and out maintains the same aspect ratio
2714 // between the inner and outer viewports. 2716 // between the inner and outer viewports.
2715 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { 2717 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) {
2716 SetupTopControlsAndScrollLayerWithVirtualViewport( 2718 SetupTopControlsAndScrollLayerWithVirtualViewport(
2717 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2719 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2718 DrawFrame(); 2720 DrawFrame();
2719 2721
2720 EXPECT_EQ(settings_.top_controls_height, 2722 EXPECT_EQ(top_controls_height_,
2721 host_impl_->active_tree()->total_top_controls_content_offset()); 2723 host_impl_->active_tree()->total_top_controls_content_offset());
2722 2724
2723 gfx::Vector2dF scroll_delta(0.f, 25.f); 2725 gfx::Vector2dF scroll_delta(0.f, 25.f);
2724 EXPECT_EQ(InputHandler::ScrollStarted, 2726 EXPECT_EQ(InputHandler::ScrollStarted,
2725 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2727 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2726 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2728 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2727 host_impl_->ScrollEnd(); 2729 host_impl_->ScrollEnd();
2728 2730
2729 EXPECT_EQ(scroll_delta.y(), 2731 EXPECT_EQ(scroll_delta.y(),
2730 settings_.top_controls_height - 2732 top_controls_height_ -
2731 host_impl_->active_tree()->total_top_controls_content_offset()); 2733 host_impl_->active_tree()->total_top_controls_content_offset());
2732 2734
2733 // Top controls were hidden by 25px so the inner viewport should have expanded 2735 // Top controls were hidden by 25px so the inner viewport should have expanded
2734 // by that much. 2736 // by that much.
2735 LayerImpl* outer_container = 2737 LayerImpl* outer_container =
2736 host_impl_->active_tree()->OuterViewportContainerLayer(); 2738 host_impl_->active_tree()->OuterViewportContainerLayer();
2737 LayerImpl* inner_container = 2739 LayerImpl* inner_container =
2738 host_impl_->active_tree()->InnerViewportContainerLayer(); 2740 host_impl_->active_tree()->InnerViewportContainerLayer();
2739 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); 2741 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling());
2740 2742
2741 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. 2743 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
2742 float aspect_ratio = inner_container->BoundsForScrolling().width() / 2744 float aspect_ratio = inner_container->BoundsForScrolling().width() /
2743 inner_container->BoundsForScrolling().height(); 2745 inner_container->BoundsForScrolling().height();
2744 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); 2746 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio));
2745 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); 2747 EXPECT_EQ(expected, outer_container->BoundsForScrolling());
2746 EXPECT_EQ(expected, 2748 EXPECT_EQ(expected,
2747 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); 2749 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling());
2748 } 2750 }
2749 2751
2750 // Test that scrolling the outer viewport affects the top controls. 2752 // Test that scrolling the outer viewport affects the top controls.
2751 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { 2753 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
2752 SetupTopControlsAndScrollLayerWithVirtualViewport( 2754 SetupTopControlsAndScrollLayerWithVirtualViewport(
2753 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2755 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2754 DrawFrame(); 2756 DrawFrame();
2755 2757
2756 EXPECT_EQ(settings_.top_controls_height, 2758 EXPECT_EQ(top_controls_height_,
2757 host_impl_->active_tree()->total_top_controls_content_offset()); 2759 host_impl_->active_tree()->total_top_controls_content_offset());
2758 2760
2759 // Send a gesture scroll that will scroll the outer viewport, make sure the 2761 // Send a gesture scroll that will scroll the outer viewport, make sure the
2760 // top controls get scrolled. 2762 // top controls get scrolled.
2761 gfx::Vector2dF scroll_delta(0.f, 15.f); 2763 gfx::Vector2dF scroll_delta(0.f, 15.f);
2762 EXPECT_EQ(InputHandler::ScrollStarted, 2764 EXPECT_EQ(InputHandler::ScrollStarted,
2763 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2765 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2764 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2766 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2765 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2767 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2766 host_impl_->CurrentlyScrollingLayer()); 2768 host_impl_->CurrentlyScrollingLayer());
2767 host_impl_->ScrollEnd(); 2769 host_impl_->ScrollEnd();
2768 2770
2769 EXPECT_EQ(scroll_delta.y(), 2771 EXPECT_EQ(scroll_delta.y(),
2770 settings_.top_controls_height - 2772 top_controls_height_ -
2771 host_impl_->active_tree()->total_top_controls_content_offset()); 2773 host_impl_->active_tree()->total_top_controls_content_offset());
2772 2774
2773 scroll_delta = gfx::Vector2dF(0.f, 50.f); 2775 scroll_delta = gfx::Vector2dF(0.f, 50.f);
2774 EXPECT_EQ(InputHandler::ScrollStarted, 2776 EXPECT_EQ(InputHandler::ScrollStarted,
2775 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2777 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2776 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2778 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2777 2779
2778 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset()); 2780 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset());
2779 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2781 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2780 host_impl_->CurrentlyScrollingLayer()); 2782 host_impl_->CurrentlyScrollingLayer());
2781 2783
2782 host_impl_->ScrollEnd(); 2784 host_impl_->ScrollEnd();
2783 2785
2784 // Position the viewports such that the inner viewport will be scrolled. 2786 // Position the viewports such that the inner viewport will be scrolled.
2785 gfx::Vector2dF inner_viewport_offset(0.f, 25.f); 2787 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
2786 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF()); 2788 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF());
2787 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset); 2789 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset);
2788 2790
2789 scroll_delta = gfx::Vector2dF(0.f, -65.f); 2791 scroll_delta = gfx::Vector2dF(0.f, -65.f);
2790 EXPECT_EQ(InputHandler::ScrollStarted, 2792 EXPECT_EQ(InputHandler::ScrollStarted,
2791 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2793 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2792 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2794 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2793 2795
2794 EXPECT_EQ(settings_.top_controls_height, 2796 EXPECT_EQ(top_controls_height_,
2795 host_impl_->active_tree()->total_top_controls_content_offset()); 2797 host_impl_->active_tree()->total_top_controls_content_offset());
2796 EXPECT_EQ(inner_viewport_offset.y() + 2798 EXPECT_EQ(
2797 (scroll_delta.y() + settings_.top_controls_height), 2799 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_),
2798 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); 2800 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y());
2799 2801
2800 host_impl_->ScrollEnd(); 2802 host_impl_->ScrollEnd();
2801 } 2803 }
2802 2804
2803 TEST_F(LayerTreeHostImplTopControlsTest, 2805 TEST_F(LayerTreeHostImplTopControlsTest,
2804 ScrollNonScrollableRootWithTopControls) { 2806 ScrollNonScrollableRootWithTopControls) {
2805 CreateHostImpl(settings_, CreateOutputSurface()); 2807 CreateHostImpl(settings_, CreateOutputSurface());
2806 SetupTopControlsAndScrollLayer(); 2808 SetupTopControlsAndScrollLayer();
2807 DrawFrame(); 2809 DrawFrame();
2808 2810
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3010 gfx::Vector2d scroll_delta(0, 10); 3012 gfx::Vector2d scroll_delta(0, 10);
3011 gfx::Vector2d expected_scroll_delta = scroll_delta; 3013 gfx::Vector2d expected_scroll_delta = scroll_delta;
3012 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); 3014 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset();
3013 EXPECT_EQ(InputHandler::ScrollStarted, 3015 EXPECT_EQ(InputHandler::ScrollStarted,
3014 host_impl_->ScrollBegin(gfx::Point(5, 5), 3016 host_impl_->ScrollBegin(gfx::Point(5, 5),
3015 InputHandler::Wheel)); 3017 InputHandler::Wheel));
3016 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3018 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3017 host_impl_->ScrollEnd(); 3019 host_impl_->ScrollEnd();
3018 3020
3019 // Set new page scale from main thread. 3021 // Set new page scale from main thread.
3020 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 3022 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, page_scale,
3021 page_scale,
3022 page_scale); 3023 page_scale);
3023 3024
3024 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); 3025 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
3025 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); 3026 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta);
3026 3027
3027 // The scroll range should also have been updated. 3028 // The scroll range should also have been updated.
3028 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); 3029 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset());
3029 3030
3030 // The page scale delta remains constant because the impl thread did not 3031 // The page scale delta remains constant because the impl thread did not
3031 // scale. 3032 // scale.
(...skipping 13 matching lines...) Expand all
3045 root_scrolling->SetIsContainerForFixedPositionLayers(true); 3046 root_scrolling->SetIsContainerForFixedPositionLayers(true);
3046 root_clip->AddChild(root_scrolling.Pass()); 3047 root_clip->AddChild(root_scrolling.Pass());
3047 root->AddChild(root_clip.Pass()); 3048 root->AddChild(root_clip.Pass());
3048 host_impl_->active_tree()->SetRootLayer(root.Pass()); 3049 host_impl_->active_tree()->SetRootLayer(root.Pass());
3049 // The behaviour in this test assumes the page scale is applied at a layer 3050 // The behaviour in this test assumes the page scale is applied at a layer
3050 // above the clip layer. 3051 // above the clip layer.
3051 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, 3052 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3,
3052 Layer::INVALID_ID); 3053 Layer::INVALID_ID);
3053 host_impl_->active_tree()->DidBecomeActive(); 3054 host_impl_->active_tree()->DidBecomeActive();
3054 host_impl_->SetViewportSize(viewport_size); 3055 host_impl_->SetViewportSize(viewport_size);
3055 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); 3056 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, page_scale);
3056 DrawFrame(); 3057 DrawFrame();
3057 3058
3058 LayerImpl* root_scroll = 3059 LayerImpl* root_scroll =
3059 host_impl_->active_tree()->InnerViewportScrollLayer(); 3060 host_impl_->active_tree()->InnerViewportScrollLayer();
3060 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); 3061 EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds());
3061 3062
3062 gfx::Vector2d scroll_delta(0, 10); 3063 gfx::Vector2d scroll_delta(0, 10);
3063 gfx::Vector2d expected_scroll_delta = scroll_delta; 3064 gfx::Vector2d expected_scroll_delta = scroll_delta;
3064 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); 3065 gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset();
3065 EXPECT_EQ(InputHandler::ScrollStarted, 3066 EXPECT_EQ(InputHandler::ScrollStarted,
(...skipping 11 matching lines...) Expand all
3077 DrawOneFrame(); 3078 DrawOneFrame();
3078 3079
3079 // The scroll delta is not scaled because the main thread did not scale. 3080 // The scroll delta is not scaled because the main thread did not scale.
3080 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); 3081 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
3081 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); 3082 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta);
3082 3083
3083 // The scroll range should also have been updated. 3084 // The scroll range should also have been updated.
3084 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); 3085 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset());
3085 3086
3086 // The page scale delta should match the new scale on the impl side. 3087 // The page scale delta should match the new scale on the impl side.
3087 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); 3088 EXPECT_EQ(page_scale, host_impl_->active_tree()->current_page_scale_factor());
3088 } 3089 }
3089 3090
3090 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { 3091 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) {
3091 gfx::Size surface_size(10, 10); 3092 gfx::Size surface_size(10, 10);
3092 float default_page_scale = 1.f; 3093 float default_page_scale = 1.f;
3093 gfx::Transform default_page_scale_matrix; 3094 gfx::Transform default_page_scale_matrix;
3094 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); 3095 default_page_scale_matrix.Scale(default_page_scale, default_page_scale);
3095 3096
3096 float new_page_scale = 2.f; 3097 float new_page_scale = 2.f;
3097 gfx::Transform new_page_scale_matrix; 3098 gfx::Transform new_page_scale_matrix;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 gfx::Vector2d scroll_delta(0, 10); 3174 gfx::Vector2d scroll_delta(0, 10);
3174 gfx::Vector2d expected_scroll_delta(scroll_delta); 3175 gfx::Vector2d expected_scroll_delta(scroll_delta);
3175 gfx::ScrollOffset expected_max_scroll(child->MaxScrollOffset()); 3176 gfx::ScrollOffset expected_max_scroll(child->MaxScrollOffset());
3176 EXPECT_EQ(InputHandler::ScrollStarted, 3177 EXPECT_EQ(InputHandler::ScrollStarted,
3177 host_impl_->ScrollBegin(gfx::Point(5, 5), 3178 host_impl_->ScrollBegin(gfx::Point(5, 5),
3178 InputHandler::Wheel)); 3179 InputHandler::Wheel));
3179 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3180 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3180 host_impl_->ScrollEnd(); 3181 host_impl_->ScrollEnd();
3181 3182
3182 float page_scale = 2.f; 3183 float page_scale = 2.f;
3183 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 3184 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f,
3184 1.f,
3185 page_scale); 3185 page_scale);
3186 3186
3187 DrawOneFrame(); 3187 DrawOneFrame();
3188 3188
3189 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); 3189 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas();
3190 ExpectContains( 3190 ExpectContains(
3191 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); 3191 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta);
3192 3192
3193 // The scroll range should not have changed. 3193 // The scroll range should not have changed.
3194 EXPECT_EQ(child->MaxScrollOffset(), expected_max_scroll); 3194 EXPECT_EQ(child->MaxScrollOffset(), expected_max_scroll);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3329 scroll_info = host_impl_->ProcessScrollDeltas(); 3329 scroll_info = host_impl_->ProcessScrollDeltas();
3330 3330
3331 // The grand child should have scrolled. 3331 // The grand child should have scrolled.
3332 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 5)); 3332 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 5));
3333 3333
3334 // The child should not have scrolled. 3334 // The child should not have scrolled.
3335 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(0, -3)); 3335 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(0, -3));
3336 3336
3337 3337
3338 // Scrolling should be adjusted from viewport space. 3338 // Scrolling should be adjusted from viewport space.
3339 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 2.f, 2.f); 3339 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 2.f, 2.f);
3340 host_impl_->active_tree()->SetPageScaleDelta(1.f); 3340 host_impl_->SetPageScaleOnActiveTree(2.f);
3341 3341
3342 scroll_delta = gfx::Vector2d(0, -2); 3342 scroll_delta = gfx::Vector2d(0, -2);
3343 EXPECT_EQ(InputHandler::ScrollStarted, 3343 EXPECT_EQ(InputHandler::ScrollStarted,
3344 host_impl_->ScrollBegin(gfx::Point(1, 1), 3344 host_impl_->ScrollBegin(gfx::Point(1, 1),
3345 InputHandler::NonBubblingGesture)); 3345 InputHandler::NonBubblingGesture));
3346 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); 3346 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer());
3347 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3347 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3348 host_impl_->ScrollEnd(); 3348 host_impl_->ScrollEnd();
3349 3349
3350 scroll_info = host_impl_->ProcessScrollDeltas(); 3350 scroll_info = host_impl_->ProcessScrollDeltas();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3604 } 3604 }
3605 3605
3606 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { 3606 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) {
3607 int width = 332; 3607 int width = 332;
3608 int height = 20; 3608 int height = 20;
3609 int scale = 3; 3609 int scale = 3;
3610 SetupScrollAndContentsLayers(gfx::Size(width, height)); 3610 SetupScrollAndContentsLayers(gfx::Size(width, height));
3611 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( 3611 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds(
3612 gfx::Size(width * scale - 1, height * scale)); 3612 gfx::Size(width * scale - 1, height * scale));
3613 host_impl_->SetDeviceScaleFactor(scale); 3613 host_impl_->SetDeviceScaleFactor(scale);
3614 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 3614 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
3615 3615
3616 LayerImpl* inner_viewport_scroll_layer = 3616 LayerImpl* inner_viewport_scroll_layer =
3617 host_impl_->active_tree()->InnerViewportScrollLayer(); 3617 host_impl_->active_tree()->InnerViewportScrollLayer();
3618 EXPECT_EQ(gfx::ScrollOffset(0, 0), 3618 EXPECT_EQ(gfx::ScrollOffset(0, 0),
3619 inner_viewport_scroll_layer->MaxScrollOffset()); 3619 inner_viewport_scroll_layer->MaxScrollOffset());
3620 } 3620 }
3621 3621
3622 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { 3622 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate {
3623 public: 3623 public:
3624 TestScrollOffsetDelegate() 3624 TestScrollOffsetDelegate()
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 3705
3706 // Setting the delegate results in the scrollable_size, max_scroll_offset, 3706 // Setting the delegate results in the scrollable_size, max_scroll_offset,
3707 // page_scale_factor and {min|max}_page_scale_factor being set. 3707 // page_scale_factor and {min|max}_page_scale_factor being set.
3708 EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size()); 3708 EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size());
3709 EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_delegate.max_scroll_offset()); 3709 EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_delegate.max_scroll_offset());
3710 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); 3710 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor());
3711 EXPECT_EQ(0.f, scroll_delegate.min_page_scale_factor()); 3711 EXPECT_EQ(0.f, scroll_delegate.min_page_scale_factor());
3712 EXPECT_EQ(0.f, scroll_delegate.max_page_scale_factor()); 3712 EXPECT_EQ(0.f, scroll_delegate.max_page_scale_factor());
3713 3713
3714 // Updating page scale immediately updates the delegate. 3714 // Updating page scale immediately updates the delegate.
3715 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 0.5f, 4.f); 3715 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 0.5f, 4.f);
3716 EXPECT_EQ(2.f, scroll_delegate.page_scale_factor()); 3716 EXPECT_EQ(2.f, scroll_delegate.page_scale_factor());
3717 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); 3717 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor());
3718 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); 3718 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor());
3719 host_impl_->active_tree()->SetPageScaleDelta(1.5f); 3719 host_impl_->SetPageScaleOnActiveTree(2.f * 1.5f);
3720 EXPECT_EQ(3.f, scroll_delegate.page_scale_factor()); 3720 EXPECT_EQ(3.f, scroll_delegate.page_scale_factor());
3721 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); 3721 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor());
3722 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); 3722 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor());
3723 host_impl_->active_tree()->SetPageScaleDelta(1.f); 3723 host_impl_->SetPageScaleOnActiveTree(2.f);
3724 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 3724 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
3725 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor()); 3725 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor());
3726 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor()); 3726 EXPECT_EQ(0.5f, scroll_delegate.min_page_scale_factor());
3727 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor()); 3727 EXPECT_EQ(4.f, scroll_delegate.max_page_scale_factor());
3728 3728
3729 // The pinch gesture doesn't put the delegate into a state where the scroll 3729 // The pinch gesture doesn't put the delegate into a state where the scroll
3730 // offset is outside of the scroll range. (this is verified by DCHECKs in the 3730 // offset is outside of the scroll range. (this is verified by DCHECKs in the
3731 // delegate). 3731 // delegate).
3732 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 3732 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
3733 host_impl_->PinchGestureBegin(); 3733 host_impl_->PinchGestureBegin();
3734 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); 3734 host_impl_->PinchGestureUpdate(2.f, gfx::Point());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3811 EXPECT_FALSE(frame.has_no_damage); 3811 EXPECT_FALSE(frame.has_no_damage);
3812 CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); 3812 CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset));
3813 3813
3814 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); 3814 host_impl_->SetRootLayerScrollOffsetDelegate(NULL);
3815 } 3815 }
3816 3816
3817 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { 3817 TEST_F(LayerTreeHostImplTest, OverscrollRoot) {
3818 InputHandlerScrollResult scroll_result; 3818 InputHandlerScrollResult scroll_result;
3819 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 3819 SetupScrollAndContentsLayers(gfx::Size(100, 100));
3820 host_impl_->SetViewportSize(gfx::Size(50, 50)); 3820 host_impl_->SetViewportSize(gfx::Size(50, 50));
3821 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 3821 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
3822 DrawFrame(); 3822 DrawFrame();
3823 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); 3823 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll());
3824 3824
3825 // In-bounds scrolling does not affect overscroll. 3825 // In-bounds scrolling does not affect overscroll.
3826 EXPECT_EQ(InputHandler::ScrollStarted, 3826 EXPECT_EQ(InputHandler::ScrollStarted,
3827 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); 3827 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
3828 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 3828 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
3829 EXPECT_TRUE(scroll_result.did_scroll); 3829 EXPECT_TRUE(scroll_result.did_scroll);
3830 EXPECT_FALSE(scroll_result.did_overscroll_root); 3830 EXPECT_FALSE(scroll_result.did_overscroll_root);
3831 EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); 3831 EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
4030 } 4030 }
4031 4031
4032 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { 4032 TEST_F(LayerTreeHostImplTest, OverscrollAlways) {
4033 LayerTreeSettings settings; 4033 LayerTreeSettings settings;
4034 CreateHostImpl(settings, CreateOutputSurface()); 4034 CreateHostImpl(settings, CreateOutputSurface());
4035 4035
4036 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); 4036 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50));
4037 LayerImpl* clip_layer = scroll_layer->parent()->parent(); 4037 LayerImpl* clip_layer = scroll_layer->parent()->parent();
4038 clip_layer->SetBounds(gfx::Size(50, 50)); 4038 clip_layer->SetBounds(gfx::Size(50, 50));
4039 host_impl_->SetViewportSize(gfx::Size(50, 50)); 4039 host_impl_->SetViewportSize(gfx::Size(50, 50));
4040 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 4040 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
4041 DrawFrame(); 4041 DrawFrame();
4042 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); 4042 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll());
4043 4043
4044 // Even though the layer can't scroll the overscroll still happens. 4044 // Even though the layer can't scroll the overscroll still happens.
4045 EXPECT_EQ(InputHandler::ScrollStarted, 4045 EXPECT_EQ(InputHandler::ScrollStarted,
4046 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); 4046 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
4047 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 4047 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
4048 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); 4048 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll());
4049 } 4049 }
4050 4050
4051 TEST_F(LayerTreeHostImplTest, NoOverscrollOnFractionalDeviceScale) { 4051 TEST_F(LayerTreeHostImplTest, NoOverscrollOnFractionalDeviceScale) {
4052 gfx::Size surface_size(980, 1439); 4052 gfx::Size surface_size(980, 1439);
4053 gfx::Size content_size(980, 1438); 4053 gfx::Size content_size(980, 1438);
4054 float device_scale_factor = 1.5f; 4054 float device_scale_factor = 1.5f;
4055 scoped_ptr<LayerImpl> root_clip = 4055 scoped_ptr<LayerImpl> root_clip =
4056 LayerImpl::Create(host_impl_->active_tree(), 3); 4056 LayerImpl::Create(host_impl_->active_tree(), 3);
4057 scoped_ptr<LayerImpl> root = 4057 scoped_ptr<LayerImpl> root =
4058 CreateScrollableLayer(1, content_size, root_clip.get()); 4058 CreateScrollableLayer(1, content_size, root_clip.get());
4059 root->SetIsContainerForFixedPositionLayers(true); 4059 root->SetIsContainerForFixedPositionLayers(true);
4060 scoped_ptr<LayerImpl> child = 4060 scoped_ptr<LayerImpl> child =
4061 CreateScrollableLayer(2, content_size, root_clip.get()); 4061 CreateScrollableLayer(2, content_size, root_clip.get());
4062 root->scroll_clip_layer()->SetBounds(gfx::Size(320, 469)); 4062 root->scroll_clip_layer()->SetBounds(gfx::Size(320, 469));
4063 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 4063 host_impl_->active_tree()->PushPageScaleFromMainThread(0.326531f, 0.326531f,
4064 0.326531f, 0.326531f, 5.f); 4064 5.f);
4065 host_impl_->active_tree()->SetPageScaleDelta(1.f); 4065 host_impl_->SetPageScaleOnActiveTree(0.326531f);
4066 child->SetScrollClipLayer(Layer::INVALID_ID); 4066 child->SetScrollClipLayer(Layer::INVALID_ID);
4067 root->AddChild(child.Pass()); 4067 root->AddChild(child.Pass());
4068 root_clip->AddChild(root.Pass()); 4068 root_clip->AddChild(root.Pass());
4069 4069
4070 host_impl_->SetViewportSize(surface_size); 4070 host_impl_->SetViewportSize(surface_size);
4071 host_impl_->SetDeviceScaleFactor(device_scale_factor); 4071 host_impl_->SetDeviceScaleFactor(device_scale_factor);
4072 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 4072 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
4073 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 3, 1, 4073 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 3, 1,
4074 Layer::INVALID_ID); 4074 Layer::INVALID_ID);
4075 host_impl_->active_tree()->DidBecomeActive(); 4075 host_impl_->active_tree()->DidBecomeActive();
(...skipping 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after
6135 // Due to precision issues (especially on Android), sometimes far 6135 // Due to precision issues (especially on Android), sometimes far
6136 // away quads can end up thinking they need AA. 6136 // away quads can end up thinking they need AA.
6137 float device_scale_factor = 4.f / 3.f; 6137 float device_scale_factor = 4.f / 3.f;
6138 host_impl_->SetDeviceScaleFactor(device_scale_factor); 6138 host_impl_->SetDeviceScaleFactor(device_scale_factor);
6139 gfx::Size root_size(2000, 1000); 6139 gfx::Size root_size(2000, 1000);
6140 gfx::Size device_viewport_size = 6140 gfx::Size device_viewport_size =
6141 gfx::ToCeiledSize(gfx::ScaleSize(root_size, device_scale_factor)); 6141 gfx::ToCeiledSize(gfx::ScaleSize(root_size, device_scale_factor));
6142 host_impl_->SetViewportSize(device_viewport_size); 6142 host_impl_->SetViewportSize(device_viewport_size);
6143 6143
6144 host_impl_->CreatePendingTree(); 6144 host_impl_->CreatePendingTree();
6145 host_impl_->pending_tree() 6145 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f,
6146 ->SetPageScaleFactorAndLimits(1.f, 1.f / 16.f, 16.f); 6146 16.f);
6147 6147
6148 scoped_ptr<LayerImpl> scoped_root = 6148 scoped_ptr<LayerImpl> scoped_root =
6149 LayerImpl::Create(host_impl_->pending_tree(), 1); 6149 LayerImpl::Create(host_impl_->pending_tree(), 1);
6150 LayerImpl* root = scoped_root.get(); 6150 LayerImpl* root = scoped_root.get();
6151 6151
6152 host_impl_->pending_tree()->SetRootLayer(scoped_root.Pass()); 6152 host_impl_->pending_tree()->SetRootLayer(scoped_root.Pass());
6153 6153
6154 scoped_ptr<LayerImpl> scoped_scrolling_layer = 6154 scoped_ptr<LayerImpl> scoped_scrolling_layer =
6155 LayerImpl::Create(host_impl_->pending_tree(), 2); 6155 LayerImpl::Create(host_impl_->pending_tree(), 2);
6156 LayerImpl* scrolling_layer = scoped_scrolling_layer.get(); 6156 LayerImpl* scrolling_layer = scoped_scrolling_layer.get();
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
7159 EXPECT_EQ(2, set_needs_redraw_count); 7159 EXPECT_EQ(2, set_needs_redraw_count);
7160 EXPECT_EQ(1, forward_to_main_count); 7160 EXPECT_EQ(1, forward_to_main_count);
7161 } 7161 }
7162 } 7162 }
7163 7163
7164 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { 7164 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest {
7165 public: 7165 public:
7166 void SetUp() override { 7166 void SetUp() override {
7167 LayerTreeSettings settings = DefaultSettings(); 7167 LayerTreeSettings settings = DefaultSettings();
7168 settings.calculate_top_controls_position = true; 7168 settings.calculate_top_controls_position = true;
7169 settings.top_controls_height = top_controls_height_;
7170 CreateHostImpl(settings, CreateOutputSurface()); 7169 CreateHostImpl(settings, CreateOutputSurface());
7170 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
7171 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_);
7172 host_impl_->top_controls_manager()->SetTopControlsHeight(
7173 top_controls_height_);
7171 } 7174 }
7172 7175
7173 protected: 7176 protected:
7174 static const int top_controls_height_; 7177 static const int top_controls_height_;
7175 }; 7178 };
7176 7179
7177 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; 7180 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50;
7178 7181
7179 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 7182 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
7180 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7183 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7181 ->SetScrollOffset(gfx::ScrollOffset(0, 10)); 7184 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
7182 host_impl_->Animate(base::TimeTicks()); 7185 host_impl_->Animate(base::TimeTicks());
7183 EXPECT_FALSE(did_request_redraw_); 7186 EXPECT_FALSE(did_request_redraw_);
7184 } 7187 }
7185 7188
7189 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) {
7190 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7191 EXPECT_FALSE(did_request_redraw_);
7192 host_impl_->CreatePendingTree();
7193 host_impl_->sync_tree()->set_top_controls_height(100);
7194 host_impl_->ActivateSyncTree();
7195 EXPECT_EQ(100, host_impl_->top_controls_manager()->top_controls_height());
7196 }
7197
7198 TEST_F(LayerTreeHostImplWithTopControlsTest,
7199 TopControlsStayFullyVisibleOnHeightChange) {
7200 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7201 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset());
7202
7203 host_impl_->CreatePendingTree();
7204 host_impl_->sync_tree()->set_top_controls_height(0);
7205 host_impl_->ActivateSyncTree();
7206 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset());
7207
7208 host_impl_->CreatePendingTree();
7209 host_impl_->sync_tree()->set_top_controls_height(50);
7210 host_impl_->ActivateSyncTree();
7211 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset());
7212 }
7213
7186 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { 7214 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) {
7187 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7215 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7188 ->SetScrollOffset(gfx::ScrollOffset(0, 10)); 7216 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
7189 host_impl_->DidChangeTopControlsPosition(); 7217 host_impl_->DidChangeTopControlsPosition();
7190 EXPECT_TRUE(did_request_animate_); 7218 EXPECT_TRUE(did_request_animate_);
7191 EXPECT_TRUE(did_request_redraw_); 7219 EXPECT_TRUE(did_request_redraw_);
7192 } 7220 }
7193 7221
7194 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { 7222 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) {
7195 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); 7223 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200));
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
7805 host_impl_->SetViewportSize(gfx::Size(50, 50)); 7833 host_impl_->SetViewportSize(gfx::Size(50, 50));
7806 DrawFrame(); 7834 DrawFrame();
7807 7835
7808 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); 7836 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer());
7809 7837
7810 float min_page_scale = 1.f, max_page_scale = 4.f; 7838 float min_page_scale = 1.f, max_page_scale = 4.f;
7811 float page_scale_factor = 1.f; 7839 float page_scale_factor = 1.f;
7812 7840
7813 // The scroll deltas should have the page scale factor applied. 7841 // The scroll deltas should have the page scale factor applied.
7814 { 7842 {
7815 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 7843 host_impl_->active_tree()->PushPageScaleFromMainThread(
7816 page_scale_factor, min_page_scale, max_page_scale); 7844 page_scale_factor, min_page_scale, max_page_scale);
7817 host_impl_->active_tree()->SetPageScaleDelta(1.f); 7845 host_impl_->SetPageScaleOnActiveTree(page_scale_factor);
7818 scroll_layer->SetScrollDelta(gfx::Vector2d()); 7846 scroll_layer->SetScrollDelta(gfx::Vector2d());
7819 7847
7820 float page_scale_delta = 2.f; 7848 float page_scale_delta = 2.f;
7821 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); 7849 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture);
7822 host_impl_->PinchGestureBegin(); 7850 host_impl_->PinchGestureBegin();
7823 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); 7851 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point());
7824 host_impl_->PinchGestureEnd(); 7852 host_impl_->PinchGestureEnd();
7825 host_impl_->ScrollEnd(); 7853 host_impl_->ScrollEnd();
7826 7854
7827 gfx::Vector2dF scroll_delta(0, 5); 7855 gfx::Vector2dF scroll_delta(0, 5);
(...skipping 22 matching lines...) Expand all
7850 // surface. 7878 // surface.
7851 EXPECT_EQ(0, num_lost_surfaces_); 7879 EXPECT_EQ(0, num_lost_surfaces_);
7852 host_impl_->DidLoseOutputSurface(); 7880 host_impl_->DidLoseOutputSurface();
7853 EXPECT_EQ(1, num_lost_surfaces_); 7881 EXPECT_EQ(1, num_lost_surfaces_);
7854 host_impl_->DidLoseOutputSurface(); 7882 host_impl_->DidLoseOutputSurface();
7855 EXPECT_LE(1, num_lost_surfaces_); 7883 EXPECT_LE(1, num_lost_surfaces_);
7856 } 7884 }
7857 7885
7858 } // namespace 7886 } // namespace
7859 } // namespace cc 7887 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698