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

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

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl_perftest.cc ('k') | cc/test/animation_test_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/containers/hash_tables.h" 5 #include "base/containers/hash_tables.h"
6 #include "cc/animation/scrollbar_animation_controller.h" 6 #include "cc/animation/scrollbar_animation_controller.h"
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/layers/painted_scrollbar_layer.h" 8 #include "cc/layers/painted_scrollbar_layer.h"
9 #include "cc/layers/painted_scrollbar_layer_impl.h" 9 #include "cc/layers/painted_scrollbar_layer_impl.h"
10 #include "cc/layers/scrollbar_layer_interface.h" 10 #include "cc/layers/scrollbar_layer_interface.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
133 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 133 scoped_refptr<Layer> layer_tree_root = Layer::Create();
134 scoped_refptr<Layer> scroll_layer = Layer::Create(); 134 scoped_refptr<Layer> scroll_layer = Layer::Create();
135 scoped_refptr<Layer> content_layer = Layer::Create(); 135 scoped_refptr<Layer> content_layer = Layer::Create();
136 scoped_refptr<Layer> scrollbar_layer = 136 scoped_refptr<Layer> scrollbar_layer =
137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
138 138
139 // Choose bounds to give max_scroll_offset = (30, 50). 139 // Choose bounds to give max_scroll_offset = (30, 50).
140 layer_tree_root->SetBounds(gfx::Size(70, 150)); 140 layer_tree_root->SetBounds(gfx::Size(70, 150));
141 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 141 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
142 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); 142 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
143 scroll_layer->SetBounds(gfx::Size(100, 200)); 143 scroll_layer->SetBounds(gfx::Size(100, 200));
144 content_layer->SetBounds(gfx::Size(100, 200)); 144 content_layer->SetBounds(gfx::Size(100, 200));
145 145
146 host->SetRootLayer(layer_tree_root); 146 host->SetRootLayer(layer_tree_root);
147 layer_tree_root->AddChild(scroll_layer); 147 layer_tree_root->AddChild(scroll_layer);
148 scroll_layer->AddChild(content_layer); 148 scroll_layer->AddChild(content_layer);
149 layer_tree_root->AddChild(scrollbar_layer); 149 layer_tree_root->AddChild(scrollbar_layer);
150 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 150 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
151 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 151 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
152 152
153 layer_tree_root->SavePaintProperties(); 153 layer_tree_root->SavePaintProperties();
154 content_layer->SavePaintProperties(); 154 content_layer->SavePaintProperties();
155 155
156 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 156 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
157 157
158 ScrollbarLayerImplBase* cc_scrollbar_layer = 158 ScrollbarLayerImplBase* cc_scrollbar_layer =
159 static_cast<PaintedScrollbarLayerImpl*>( 159 static_cast<PaintedScrollbarLayerImpl*>(
160 layer_impl_tree_root->children()[1]); 160 layer_impl_tree_root->children()[1]);
161 161
162 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 162 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
163 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); 163 EXPECT_EQ(30, cc_scrollbar_layer->maximum());
164 164
165 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 165 layer_tree_root->SetBounds(gfx::Size(700, 1500));
166 layer_tree_root->SavePaintProperties(); 166 layer_tree_root->SavePaintProperties();
167 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 167 scroll_layer->SetBounds(gfx::Size(1000, 2000));
168 scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200)); 168 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
169 scroll_layer->SavePaintProperties(); 169 scroll_layer->SavePaintProperties();
170 content_layer->SetBounds(gfx::Size(1000, 2000)); 170 content_layer->SetBounds(gfx::Size(1000, 2000));
171 content_layer->SavePaintProperties(); 171 content_layer->SavePaintProperties();
172 172
173 ScrollbarAnimationController* scrollbar_controller = 173 ScrollbarAnimationController* scrollbar_controller =
174 layer_impl_tree_root->scrollbar_animation_controller(); 174 layer_impl_tree_root->scrollbar_animation_controller();
175 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 175 layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
176 EXPECT_EQ(scrollbar_controller, 176 EXPECT_EQ(scrollbar_controller,
177 layer_impl_tree_root->scrollbar_animation_controller()); 177 layer_impl_tree_root->scrollbar_animation_controller());
178 178
(...skipping 30 matching lines...) Expand all
209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
210 root_clip_layer->SetBounds(gfx::Size(20, 50)); 210 root_clip_layer->SetBounds(gfx::Size(20, 50));
211 root_layer->SetBounds(gfx::Size(100, 50)); 211 root_layer->SetBounds(gfx::Size(100, 50));
212 content_layer->SetBounds(gfx::Size(100, 50)); 212 content_layer->SetBounds(gfx::Size(100, 50));
213 213
214 host->SetRootLayer(root_clip_layer); 214 host->SetRootLayer(root_clip_layer);
215 root_clip_layer->AddChild(root_layer); 215 root_clip_layer->AddChild(root_layer);
216 root_layer->AddChild(content_layer); 216 root_layer->AddChild(content_layer);
217 root_layer->AddChild(scrollbar_layer); 217 root_layer->AddChild(scrollbar_layer);
218 218
219 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); 219 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
220 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 220 scrollbar_layer->SetBounds(gfx::Size(70, 10));
221 scrollbar_layer->SetScrollLayer(root_layer->id()); 221 scrollbar_layer->SetScrollLayer(root_layer->id());
222 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 222 scrollbar_layer->SetClipLayer(root_clip_layer->id());
223 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 223 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
224 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 224 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
225 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 225 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
226 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 226 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
227 227
228 scrollbar_layer->UpdateThumbAndTrackGeometry(); 228 scrollbar_layer->UpdateThumbAndTrackGeometry();
229 LayerImpl* root_clip_layer_impl = NULL; 229 LayerImpl* root_clip_layer_impl = NULL;
(...skipping 24 matching lines...) Expand all
254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
255 root_clip_layer->SetBounds(gfx::Size(20, 50)); 255 root_clip_layer->SetBounds(gfx::Size(20, 50));
256 root_layer->SetBounds(gfx::Size(100, 50)); 256 root_layer->SetBounds(gfx::Size(100, 50));
257 content_layer->SetBounds(gfx::Size(100, 50)); 257 content_layer->SetBounds(gfx::Size(100, 50));
258 258
259 host->SetRootLayer(root_clip_layer); 259 host->SetRootLayer(root_clip_layer);
260 root_clip_layer->AddChild(root_layer); 260 root_clip_layer->AddChild(root_layer);
261 root_layer->AddChild(content_layer); 261 root_layer->AddChild(content_layer);
262 root_layer->AddChild(scrollbar_layer); 262 root_layer->AddChild(scrollbar_layer);
263 263
264 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); 264 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
265 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 265 scrollbar_layer->SetBounds(gfx::Size(70, 10));
266 scrollbar_layer->SetScrollLayer(root_layer->id()); 266 scrollbar_layer->SetScrollLayer(root_layer->id());
267 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 267 scrollbar_layer->SetClipLayer(root_clip_layer->id());
268 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 268 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
269 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 269 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
270 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 270 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
271 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 271 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
272 scrollbar_layer->UpdateThumbAndTrackGeometry(); 272 scrollbar_layer->UpdateThumbAndTrackGeometry();
273 LayerImpl* root_clip_layer_impl = NULL; 273 LayerImpl* root_clip_layer_impl = NULL;
274 LayerImpl* root_layer_impl = NULL; 274 LayerImpl* root_layer_impl = NULL;
275 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; 275 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL;
276 276
277 // Thumb is at the edge of the scrollbar (should be inset to 277 // Thumb is at the edge of the scrollbar (should be inset to
278 // the start of the track within the scrollbar layer's 278 // the start of the track within the scrollbar layer's
279 // position). 279 // position).
280 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 280 UPDATE_AND_EXTRACT_LAYER_POINTERS();
281 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 281 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
282 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 282 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
283 283
284 // Under-scroll (thumb position should clamp and be unchanged). 284 // Under-scroll (thumb position should clamp and be unchanged).
285 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); 285 root_layer->SetScrollOffset(gfx::ScrollOffset(-5, 0));
286 286
287 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 287 UPDATE_AND_EXTRACT_LAYER_POINTERS();
288 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 288 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
289 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 289 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
290 290
291 // Over-scroll (thumb position should clamp on the far side). 291 // Over-scroll (thumb position should clamp on the far side).
292 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); 292 root_layer->SetScrollOffset(gfx::ScrollOffset(85, 0));
293 293
294 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 294 UPDATE_AND_EXTRACT_LAYER_POINTERS();
295 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), 295 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(),
296 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 296 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
297 297
298 // Change thumb thickness and length. 298 // Change thumb thickness and length.
299 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); 299 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4);
300 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); 300 scrollbar_layer->fake_scrollbar()->set_thumb_length(6);
301 301
302 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 302 UPDATE_AND_EXTRACT_LAYER_POINTERS();
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), 721 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(),
722 layer_tree_root->id()); 722 layer_tree_root->id());
723 } 723 }
724 layer_tree_root->AddChild(content_layer); 724 layer_tree_root->AddChild(content_layer);
725 layer_tree_root->AddChild(scrollbar_layer); 725 layer_tree_root->AddChild(scrollbar_layer);
726 726
727 layer_tree_host_->SetRootLayer(layer_tree_root); 727 layer_tree_host_->SetRootLayer(layer_tree_root);
728 728
729 scrollbar_layer->SetIsDrawable(true); 729 scrollbar_layer->SetIsDrawable(true);
730 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 730 scrollbar_layer->SetBounds(gfx::Size(100, 100));
731 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 731 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20));
732 layer_tree_root->SetBounds(gfx::Size(100, 200)); 732 layer_tree_root->SetBounds(gfx::Size(100, 200));
733 content_layer->SetBounds(gfx::Size(100, 200)); 733 content_layer->SetBounds(gfx::Size(100, 200));
734 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); 734 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
735 scrollbar_layer->draw_properties().visible_content_rect = 735 scrollbar_layer->draw_properties().visible_content_rect =
736 gfx::Rect(0, 0, 100, 200); 736 gfx::Rect(0, 0, 100, 200);
737 scrollbar_layer->CreateRenderSurface(); 737 scrollbar_layer->CreateRenderSurface();
738 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); 738 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
739 739
740 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 740 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
741 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 741 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1103 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1104 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1104 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1105 1105
1106 // Horizontal Scrollbars. 1106 // Horizontal Scrollbars.
1107 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1107 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1108 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1108 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1109 } 1109 }
1110 1110
1111 } // namespace 1111 } // namespace
1112 } // namespace cc 1112 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl_perftest.cc ('k') | cc/test/animation_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698