OLD | NEW |
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/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
6 | 6 |
7 #include "cc/output/filter_operation.h" | 7 #include "cc/output/filter_operation.h" |
8 #include "cc/output/filter_operations.h" | 8 #include "cc/output/filter_operations.h" |
9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { | 87 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { |
88 // | 88 // |
89 // This test checks that layerPropertyChanged() has the correct behavior. | 89 // This test checks that layerPropertyChanged() has the correct behavior. |
90 // | 90 // |
91 | 91 |
92 // The constructor on this will fake that we are on the correct thread. | 92 // The constructor on this will fake that we are on the correct thread. |
93 // Create a simple LayerImpl tree: | 93 // Create a simple LayerImpl tree: |
94 FakeImplProxy proxy; | 94 FakeImplProxy proxy; |
95 FakeLayerTreeHostImpl host_impl(&proxy); | 95 FakeLayerTreeHostImpl host_impl(&proxy); |
96 EXPECT_TRUE(host_impl.InitializeRenderer(CreateFakeOutputSurface())); | 96 EXPECT_TRUE(host_impl.InitializeRenderer(CreateFakeOutputSurface())); |
97 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | 97 scoped_ptr<LayerImpl> root_clip = |
98 | 98 LayerImpl::Create(host_impl.active_tree(), 1); |
| 99 scoped_ptr<LayerImpl> root_ptr = |
| 100 LayerImpl::Create(host_impl.active_tree(), 2); |
| 101 LayerImpl* root = root_ptr.get(); |
| 102 root_clip->AddChild(root_ptr.Pass()); |
99 scoped_ptr<LayerImpl> scroll_parent = | 103 scoped_ptr<LayerImpl> scroll_parent = |
100 LayerImpl::Create(host_impl.active_tree(), 2); | 104 LayerImpl::Create(host_impl.active_tree(), 3); |
101 LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 3).get(); | 105 LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get(); |
102 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>(); | 106 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>(); |
103 scroll_children->insert(scroll_child); | 107 scroll_children->insert(scroll_child); |
104 scroll_children->insert(root.get()); | 108 scroll_children->insert(root); |
105 | 109 |
106 scoped_ptr<LayerImpl> clip_parent = | 110 scoped_ptr<LayerImpl> clip_parent = |
107 LayerImpl::Create(host_impl.active_tree(), 4); | 111 LayerImpl::Create(host_impl.active_tree(), 5); |
108 LayerImpl* clip_child = LayerImpl::Create(host_impl.active_tree(), 5).get(); | 112 LayerImpl* clip_child = LayerImpl::Create(host_impl.active_tree(), 6).get(); |
109 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>(); | 113 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>(); |
110 clip_children->insert(clip_child); | 114 clip_children->insert(clip_child); |
111 clip_children->insert(root.get()); | 115 clip_children->insert(root); |
112 | 116 |
113 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 6)); | 117 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 7)); |
114 LayerImpl* child = root->children()[0]; | 118 LayerImpl* child = root->children()[0]; |
115 child->AddChild(LayerImpl::Create(host_impl.active_tree(), 7)); | 119 child->AddChild(LayerImpl::Create(host_impl.active_tree(), 8)); |
116 LayerImpl* grand_child = child->children()[0]; | 120 LayerImpl* grand_child = child->children()[0]; |
117 | 121 |
118 root->SetScrollable(true); | 122 root->SetScrollClipLayer(root_clip->id()); |
119 | 123 |
120 // Adding children is an internal operation and should not mark layers as | 124 // Adding children is an internal operation and should not mark layers as |
121 // changed. | 125 // changed. |
122 EXPECT_FALSE(root->LayerPropertyChanged()); | 126 EXPECT_FALSE(root->LayerPropertyChanged()); |
123 EXPECT_FALSE(child->LayerPropertyChanged()); | 127 EXPECT_FALSE(child->LayerPropertyChanged()); |
124 EXPECT_FALSE(grand_child->LayerPropertyChanged()); | 128 EXPECT_FALSE(grand_child->LayerPropertyChanged()); |
125 | 129 |
126 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); | 130 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); |
127 float arbitrary_number = 0.352f; | 131 float arbitrary_number = 0.352f; |
128 gfx::Size arbitrary_size = gfx::Size(111, 222); | 132 gfx::Size arbitrary_size = gfx::Size(111, 222); |
129 gfx::Point arbitrary_point = gfx::Point(333, 444); | 133 gfx::Point arbitrary_point = gfx::Point(333, 444); |
130 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222); | 134 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222); |
131 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size); | 135 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size); |
132 gfx::RectF arbitrary_rect_f = | 136 gfx::RectF arbitrary_rect_f = |
133 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f)); | 137 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f)); |
134 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30); | 138 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30); |
135 gfx::Transform arbitrary_transform; | 139 gfx::Transform arbitrary_transform; |
136 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); | 140 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); |
137 FilterOperations arbitrary_filters; | 141 FilterOperations arbitrary_filters; |
138 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); | 142 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
139 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; | 143 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; |
140 | 144 |
141 // These properties are internal, and should not be considered "change" when | 145 // These properties are internal, and should not be considered "change" when |
142 // they are used. | 146 // they are used. |
143 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( | 147 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( |
144 root->SetUpdateRect(arbitrary_rect_f)); | 148 root->SetUpdateRect(arbitrary_rect_f)); |
145 EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE( | 149 EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(root->SetBounds(arbitrary_size)); |
146 root->SetMaxScrollOffset(arbitrary_vector2d)); | |
147 | 150 |
148 // Changing these properties affects the entire subtree of layers. | 151 // Changing these properties affects the entire subtree of layers. |
149 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPoint(arbitrary_point_f)); | 152 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPoint(arbitrary_point_f)); |
150 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPointZ(arbitrary_number)); | 153 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetAnchorPointZ(arbitrary_number)); |
151 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(arbitrary_filters)); | 154 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(arbitrary_filters)); |
152 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(FilterOperations())); | 155 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetFilters(FilterOperations())); |
153 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( | 156 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( |
154 root->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 8))); | 157 root->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 9))); |
155 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true)); | 158 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true)); |
156 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true)); | 159 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true)); |
157 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( | 160 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( |
158 root->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 9))); | 161 root->SetReplicaLayer(LayerImpl::Create(host_impl.active_tree(), 10))); |
159 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitrary_point_f)); | 162 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPosition(arbitrary_point_f)); |
160 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPreserves3d(true)); | 163 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetPreserves3d(true)); |
161 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( | 164 EXECUTE_AND_VERIFY_SUBTREE_CHANGED( |
162 root->SetDoubleSided(false)); // constructor initializes it to "true". | 165 root->SetDoubleSided(false)); // constructor initializes it to "true". |
163 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d)); | 166 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->ScrollBy(arbitrary_vector2d)); |
164 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d())); | 167 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollDelta(gfx::Vector2d())); |
165 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollOffset(arbitrary_vector2d)); | 168 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetScrollOffset(arbitrary_vector2d)); |
166 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); | 169 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); |
167 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number)); | 170 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetOpacity(arbitrary_number)); |
168 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); | 171 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 FakeImplProxy proxy; | 260 FakeImplProxy proxy; |
258 FakeLayerTreeHostImpl host_impl(&proxy); | 261 FakeLayerTreeHostImpl host_impl(&proxy); |
259 EXPECT_TRUE(host_impl.InitializeRenderer(CreateFakeOutputSurface())); | 262 EXPECT_TRUE(host_impl.InitializeRenderer(CreateFakeOutputSurface())); |
260 host_impl.active_tree()->SetRootLayer( | 263 host_impl.active_tree()->SetRootLayer( |
261 LayerImpl::Create(host_impl.active_tree(), 1)); | 264 LayerImpl::Create(host_impl.active_tree(), 1)); |
262 LayerImpl* root = host_impl.active_tree()->root_layer(); | 265 LayerImpl* root = host_impl.active_tree()->root_layer(); |
263 scoped_ptr<LayerImpl> layer_ptr = | 266 scoped_ptr<LayerImpl> layer_ptr = |
264 LayerImpl::Create(host_impl.active_tree(), 2); | 267 LayerImpl::Create(host_impl.active_tree(), 2); |
265 LayerImpl* layer = layer_ptr.get(); | 268 LayerImpl* layer = layer_ptr.get(); |
266 root->AddChild(layer_ptr.Pass()); | 269 root->AddChild(layer_ptr.Pass()); |
267 layer->SetScrollable(true); | 270 layer->SetScrollClipLayer(root->id()); |
268 DCHECK(host_impl.CanDraw()); | 271 DCHECK(host_impl.CanDraw()); |
269 | 272 |
270 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); | 273 gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); |
271 float arbitrary_number = 0.352f; | 274 float arbitrary_number = 0.352f; |
272 gfx::Size arbitrary_size = gfx::Size(111, 222); | 275 gfx::Size arbitrary_size = gfx::Size(111, 222); |
273 gfx::Point arbitrary_point = gfx::Point(333, 444); | 276 gfx::Point arbitrary_point = gfx::Point(333, 444); |
274 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222); | 277 gfx::Vector2d arbitrary_vector2d = gfx::Vector2d(111, 222); |
275 gfx::Vector2d large_vector2d = gfx::Vector2d(1000, 1000); | 278 gfx::Size large_size = gfx::Size(1000, 1000); |
276 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size); | 279 gfx::Rect arbitrary_rect = gfx::Rect(arbitrary_point, arbitrary_size); |
277 gfx::RectF arbitrary_rect_f = | 280 gfx::RectF arbitrary_rect_f = |
278 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f)); | 281 gfx::RectF(arbitrary_point_f, gfx::SizeF(1.234f, 5.678f)); |
279 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30); | 282 SkColor arbitrary_color = SkColorSetRGB(10, 20, 30); |
280 gfx::Transform arbitrary_transform; | 283 gfx::Transform arbitrary_transform; |
281 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); | 284 arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); |
282 FilterOperations arbitrary_filters; | 285 FilterOperations arbitrary_filters; |
283 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); | 286 arbitrary_filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); |
284 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; | 287 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; |
285 | 288 |
286 // Related filter functions. | 289 // Related filter functions. |
287 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); | 290 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); |
288 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); | 291 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); |
289 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(FilterOperations())); | 292 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(FilterOperations())); |
290 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); | 293 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetFilters(arbitrary_filters)); |
291 | 294 |
292 // Related scrolling functions. | 295 // Related scrolling functions. |
293 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( | 296 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size)); |
294 layer->SetMaxScrollOffset(large_vector2d)); | 297 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size)); |
295 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | |
296 layer->SetMaxScrollOffset(large_vector2d)); | |
297 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d)); | 298 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d)); |
298 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d())); | 299 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d())); |
299 layer->SetScrollDelta(gfx::Vector2d(0, 0)); | 300 layer->SetScrollDelta(gfx::Vector2d(0, 0)); |
300 host_impl.ForcePrepareToDraw(); | 301 host_impl.ForcePrepareToDraw(); |
301 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( | 302 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( |
302 layer->SetScrollDelta(arbitrary_vector2d)); | 303 layer->SetScrollDelta(arbitrary_vector2d)); |
303 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 304 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
304 layer->SetScrollDelta(arbitrary_vector2d)); | 305 layer->SetScrollDelta(arbitrary_vector2d)); |
305 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( | 306 VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( |
306 layer->SetScrollOffset(arbitrary_vector2d)); | 307 layer->SetScrollOffset(arbitrary_vector2d)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 397 } |
397 } | 398 } |
398 } | 399 } |
399 } | 400 } |
400 | 401 |
401 class LayerImplScrollTest : public testing::Test { | 402 class LayerImplScrollTest : public testing::Test { |
402 public: | 403 public: |
403 LayerImplScrollTest() : host_impl_(&proxy_), root_id_(7) { | 404 LayerImplScrollTest() : host_impl_(&proxy_), root_id_(7) { |
404 host_impl_.active_tree() | 405 host_impl_.active_tree() |
405 ->SetRootLayer(LayerImpl::Create(host_impl_.active_tree(), root_id_)); | 406 ->SetRootLayer(LayerImpl::Create(host_impl_.active_tree(), root_id_)); |
406 host_impl_.active_tree()->root_layer()->SetScrollable(true); | 407 host_impl_.active_tree()->root_layer()->AddChild( |
| 408 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); |
| 409 layer()->SetScrollClipLayer(root_id_); |
| 410 // Set the max scroll offset by noting that the root layer has bounds (1,1), |
| 411 // thus whatever bounds are set for the layer will be the max scroll |
| 412 // offset plus 1 in each direction. |
| 413 host_impl_.active_tree()->root_layer()->SetBounds(gfx::Size(1, 1)); |
| 414 gfx::Vector2d max_scroll_offset(51, 81); |
| 415 layer()->SetBounds(gfx::Size(max_scroll_offset.x(), max_scroll_offset.y())); |
407 } | 416 } |
408 | 417 |
409 LayerImpl* layer() { return host_impl_.active_tree()->root_layer(); } | 418 LayerImpl* layer() { |
| 419 return host_impl_.active_tree()->root_layer()->children()[0]; |
| 420 } |
410 | 421 |
411 private: | 422 private: |
412 FakeImplProxy proxy_; | 423 FakeImplProxy proxy_; |
413 FakeLayerTreeHostImpl host_impl_; | 424 FakeLayerTreeHostImpl host_impl_; |
414 int root_id_; | 425 int root_id_; |
415 }; | 426 }; |
416 | 427 |
417 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { | 428 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { |
418 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll | 429 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll |
419 // offset is bounded by the range [0, max scroll offset]. | 430 // offset is bounded by the range [0, max scroll offset]. |
420 gfx::Vector2d max_scroll_offset(50, 80); | |
421 layer()->SetMaxScrollOffset(max_scroll_offset); | |
422 | 431 |
423 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->TotalScrollOffset()); | 432 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->TotalScrollOffset()); |
424 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); | 433 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); |
425 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); | 434 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); |
426 | 435 |
427 layer()->ScrollBy(gfx::Vector2dF(-100, 100)); | 436 layer()->ScrollBy(gfx::Vector2dF(-100, 100)); |
428 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); | 437 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); |
429 | 438 |
430 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset()); | 439 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset()); |
431 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); | 440 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); |
432 | 441 |
433 layer()->ScrollBy(gfx::Vector2dF(100, -100)); | 442 layer()->ScrollBy(gfx::Vector2dF(100, -100)); |
434 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset()); | 443 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 0), layer()->TotalScrollOffset()); |
435 | 444 |
436 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset()); | 445 EXPECT_VECTOR_EQ(layer()->ScrollDelta(), layer()->TotalScrollOffset()); |
437 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); | 446 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->scroll_offset()); |
438 } | 447 } |
439 | 448 |
440 TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) { | 449 TEST_F(LayerImplScrollTest, ScrollByWithNonZeroOffset) { |
441 gfx::Vector2d max_scroll_offset(50, 80); | |
442 gfx::Vector2d scroll_offset(10, 5); | 450 gfx::Vector2d scroll_offset(10, 5); |
443 layer()->SetMaxScrollOffset(max_scroll_offset); | |
444 layer()->SetScrollOffset(scroll_offset); | 451 layer()->SetScrollOffset(scroll_offset); |
445 | 452 |
446 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); | 453 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); |
447 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 454 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
448 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); | 455 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); |
449 | 456 |
450 layer()->ScrollBy(gfx::Vector2dF(-100, 100)); | 457 layer()->ScrollBy(gfx::Vector2dF(-100, 100)); |
451 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); | 458 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 80), layer()->TotalScrollOffset()); |
452 | 459 |
453 EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, | 460 EXPECT_VECTOR_EQ(layer()->ScrollDelta() + scroll_offset, |
(...skipping 23 matching lines...) Expand all Loading... |
477 } | 484 } |
478 | 485 |
479 virtual void SetTotalPageScaleFactor(float page_scale_factor) OVERRIDE {} | 486 virtual void SetTotalPageScaleFactor(float page_scale_factor) OVERRIDE {} |
480 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE {} | 487 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE {} |
481 | 488 |
482 private: | 489 private: |
483 gfx::Vector2dF fixed_offset_; | 490 gfx::Vector2dF fixed_offset_; |
484 }; | 491 }; |
485 | 492 |
486 TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) { | 493 TEST_F(LayerImplScrollTest, ScrollByWithIgnoringDelegate) { |
487 gfx::Vector2d max_scroll_offset(50, 80); | |
488 gfx::Vector2d scroll_offset(10, 5); | 494 gfx::Vector2d scroll_offset(10, 5); |
489 layer()->SetMaxScrollOffset(max_scroll_offset); | |
490 layer()->SetScrollOffset(scroll_offset); | 495 layer()->SetScrollOffset(scroll_offset); |
491 | 496 |
492 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); | 497 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); |
493 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 498 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
494 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); | 499 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); |
495 | 500 |
496 ScrollDelegateIgnore delegate; | 501 ScrollDelegateIgnore delegate; |
497 gfx::Vector2dF fixed_offset(32, 12); | 502 gfx::Vector2dF fixed_offset(32, 12); |
498 delegate.set_fixed_offset(fixed_offset); | 503 delegate.set_fixed_offset(fixed_offset); |
499 layer()->SetScrollOffsetDelegate(&delegate); | 504 layer()->SetScrollOffsetDelegate(&delegate); |
(...skipping 30 matching lines...) Expand all Loading... |
530 } | 535 } |
531 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } | 536 virtual bool IsExternalFlingActive() const OVERRIDE { return false; } |
532 virtual void SetTotalPageScaleFactor(float page_scale_factor) OVERRIDE {} | 537 virtual void SetTotalPageScaleFactor(float page_scale_factor) OVERRIDE {} |
533 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE {} | 538 virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE {} |
534 | 539 |
535 private: | 540 private: |
536 gfx::Vector2dF current_offset_; | 541 gfx::Vector2dF current_offset_; |
537 }; | 542 }; |
538 | 543 |
539 TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) { | 544 TEST_F(LayerImplScrollTest, ScrollByWithAcceptingDelegate) { |
540 gfx::Vector2d max_scroll_offset(50, 80); | |
541 gfx::Vector2d scroll_offset(10, 5); | 545 gfx::Vector2d scroll_offset(10, 5); |
542 layer()->SetMaxScrollOffset(max_scroll_offset); | |
543 layer()->SetScrollOffset(scroll_offset); | 546 layer()->SetScrollOffset(scroll_offset); |
544 | 547 |
545 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); | 548 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); |
546 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 549 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
547 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); | 550 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->ScrollDelta()); |
548 | 551 |
549 ScrollDelegateAccept delegate; | 552 ScrollDelegateAccept delegate; |
550 layer()->SetScrollOffsetDelegate(&delegate); | 553 layer()->SetScrollOffsetDelegate(&delegate); |
551 | 554 |
552 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); | 555 EXPECT_VECTOR_EQ(scroll_offset, layer()->TotalScrollOffset()); |
(...skipping 11 matching lines...) Expand all Loading... |
564 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 567 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
565 | 568 |
566 gfx::Vector2dF scroll_delta(1, 1); | 569 gfx::Vector2dF scroll_delta(1, 1); |
567 layer()->ScrollBy(scroll_delta); | 570 layer()->ScrollBy(scroll_delta); |
568 | 571 |
569 EXPECT_VECTOR_EQ(gfx::Vector2dF(1, 80), layer()->TotalScrollOffset()); | 572 EXPECT_VECTOR_EQ(gfx::Vector2dF(1, 80), layer()->TotalScrollOffset()); |
570 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 573 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
571 } | 574 } |
572 | 575 |
573 TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) { | 576 TEST_F(LayerImplScrollTest, ApplySentScrollsNoDelegate) { |
574 gfx::Vector2d max_scroll_offset(50, 80); | |
575 gfx::Vector2d scroll_offset(10, 5); | 577 gfx::Vector2d scroll_offset(10, 5); |
576 gfx::Vector2dF scroll_delta(20.5f, 8.5f); | 578 gfx::Vector2dF scroll_delta(20.5f, 8.5f); |
577 gfx::Vector2d sent_scroll_delta(12, -3); | 579 gfx::Vector2d sent_scroll_delta(12, -3); |
578 | 580 |
579 layer()->SetMaxScrollOffset(max_scroll_offset); | |
580 layer()->SetScrollOffset(scroll_offset); | 581 layer()->SetScrollOffset(scroll_offset); |
581 layer()->ScrollBy(scroll_delta); | 582 layer()->ScrollBy(scroll_delta); |
582 layer()->SetSentScrollDelta(sent_scroll_delta); | 583 layer()->SetSentScrollDelta(sent_scroll_delta); |
583 | 584 |
584 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); | 585 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); |
585 EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta()); | 586 EXPECT_VECTOR_EQ(scroll_delta, layer()->ScrollDelta()); |
586 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 587 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
587 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); | 588 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); |
588 | 589 |
589 layer()->ApplySentScrollDeltasFromAbortedCommit(); | 590 layer()->ApplySentScrollDeltasFromAbortedCommit(); |
590 | 591 |
591 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); | 592 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); |
592 EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta()); | 593 EXPECT_VECTOR_EQ(scroll_delta - sent_scroll_delta, layer()->ScrollDelta()); |
593 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); | 594 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); |
594 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); | 595 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); |
595 } | 596 } |
596 | 597 |
597 TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) { | 598 TEST_F(LayerImplScrollTest, ApplySentScrollsWithIgnoringDelegate) { |
598 gfx::Vector2d max_scroll_offset(50, 80); | |
599 gfx::Vector2d scroll_offset(10, 5); | 599 gfx::Vector2d scroll_offset(10, 5); |
600 gfx::Vector2d sent_scroll_delta(12, -3); | 600 gfx::Vector2d sent_scroll_delta(12, -3); |
601 gfx::Vector2dF fixed_offset(32, 12); | 601 gfx::Vector2dF fixed_offset(32, 12); |
602 | 602 |
603 layer()->SetMaxScrollOffset(max_scroll_offset); | |
604 layer()->SetScrollOffset(scroll_offset); | 603 layer()->SetScrollOffset(scroll_offset); |
605 ScrollDelegateIgnore delegate; | 604 ScrollDelegateIgnore delegate; |
606 delegate.set_fixed_offset(fixed_offset); | 605 delegate.set_fixed_offset(fixed_offset); |
607 layer()->SetScrollOffsetDelegate(&delegate); | 606 layer()->SetScrollOffsetDelegate(&delegate); |
608 layer()->SetSentScrollDelta(sent_scroll_delta); | 607 layer()->SetSentScrollDelta(sent_scroll_delta); |
609 | 608 |
610 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); | 609 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); |
611 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 610 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
612 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); | 611 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); |
613 | 612 |
614 layer()->ApplySentScrollDeltasFromAbortedCommit(); | 613 layer()->ApplySentScrollDeltasFromAbortedCommit(); |
615 | 614 |
616 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); | 615 EXPECT_VECTOR_EQ(fixed_offset, layer()->TotalScrollOffset()); |
617 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); | 616 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); |
618 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); | 617 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); |
619 } | 618 } |
620 | 619 |
621 TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) { | 620 TEST_F(LayerImplScrollTest, ApplySentScrollsWithAcceptingDelegate) { |
622 gfx::Vector2d max_scroll_offset(50, 80); | |
623 gfx::Vector2d scroll_offset(10, 5); | 621 gfx::Vector2d scroll_offset(10, 5); |
624 gfx::Vector2d sent_scroll_delta(12, -3); | 622 gfx::Vector2d sent_scroll_delta(12, -3); |
625 gfx::Vector2dF scroll_delta(20.5f, 8.5f); | 623 gfx::Vector2dF scroll_delta(20.5f, 8.5f); |
626 | 624 |
627 layer()->SetMaxScrollOffset(max_scroll_offset); | |
628 layer()->SetScrollOffset(scroll_offset); | 625 layer()->SetScrollOffset(scroll_offset); |
629 ScrollDelegateAccept delegate; | 626 ScrollDelegateAccept delegate; |
630 layer()->SetScrollOffsetDelegate(&delegate); | 627 layer()->SetScrollOffsetDelegate(&delegate); |
631 layer()->ScrollBy(scroll_delta); | 628 layer()->ScrollBy(scroll_delta); |
632 layer()->SetSentScrollDelta(sent_scroll_delta); | 629 layer()->SetSentScrollDelta(sent_scroll_delta); |
633 | 630 |
634 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); | 631 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); |
635 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); | 632 EXPECT_VECTOR_EQ(scroll_offset, layer()->scroll_offset()); |
636 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); | 633 EXPECT_VECTOR_EQ(sent_scroll_delta, layer()->sent_scroll_delta()); |
637 | 634 |
638 layer()->ApplySentScrollDeltasFromAbortedCommit(); | 635 layer()->ApplySentScrollDeltasFromAbortedCommit(); |
639 | 636 |
640 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); | 637 EXPECT_VECTOR_EQ(scroll_offset + scroll_delta, layer()->TotalScrollOffset()); |
641 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); | 638 EXPECT_VECTOR_EQ(scroll_offset + sent_scroll_delta, layer()->scroll_offset()); |
642 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); | 639 EXPECT_VECTOR_EQ(gfx::Vector2d(), layer()->sent_scroll_delta()); |
643 } | 640 } |
644 | 641 |
645 // The user-scrollability breaks for zoomed-in pages. So disable this. | 642 // The user-scrollability breaks for zoomed-in pages. So disable this. |
646 // http://crbug.com/322223 | 643 // http://crbug.com/322223 |
647 TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { | 644 TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { |
648 gfx::Vector2d max_scroll_offset(50, 80); | |
649 gfx::Vector2d scroll_offset(10, 5); | 645 gfx::Vector2d scroll_offset(10, 5); |
650 gfx::Vector2dF scroll_delta(20.5f, 8.5f); | 646 gfx::Vector2dF scroll_delta(20.5f, 8.5f); |
651 | 647 |
652 layer()->set_user_scrollable_vertical(false); | 648 layer()->set_user_scrollable_vertical(false); |
653 layer()->SetMaxScrollOffset(max_scroll_offset); | |
654 layer()->SetScrollOffset(scroll_offset); | 649 layer()->SetScrollOffset(scroll_offset); |
655 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta); | 650 gfx::Vector2dF unscrolled = layer()->ScrollBy(scroll_delta); |
656 | 651 |
657 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled); | 652 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 8.5f), unscrolled); |
658 EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset()); | 653 EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset()); |
659 } | 654 } |
660 | 655 |
661 } // namespace | 656 } // namespace |
662 } // namespace cc | 657 } // namespace cc |
OLD | NEW |