OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 class LayerTreeHostScrollTestScrollMultipleRedraw | 91 class LayerTreeHostScrollTestScrollMultipleRedraw |
92 : public LayerTreeHostScrollTest { | 92 : public LayerTreeHostScrollTest { |
93 public: | 93 public: |
94 LayerTreeHostScrollTestScrollMultipleRedraw() | 94 LayerTreeHostScrollTestScrollMultipleRedraw() |
95 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} | 95 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} |
96 | 96 |
97 virtual void BeginTest() OVERRIDE { | 97 virtual void BeginTest() OVERRIDE { |
98 layer_tree_host()->root_layer()->SetScrollable(true); | 98 layer_tree_host()->root_layer()->SetScrollable(true); |
99 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | 99 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); |
| 100 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); |
100 PostSetNeedsCommitToMainThread(); | 101 PostSetNeedsCommitToMainThread(); |
101 } | 102 } |
102 | 103 |
103 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 104 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
104 Layer* root = layer_tree_host()->root_layer(); | 105 Layer* root = layer_tree_host()->root_layer(); |
105 switch (layer_tree_host()->commit_number()) { | 106 switch (layer_tree_host()->commit_number()) { |
106 case 0: | 107 case 0: |
107 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 108 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
108 break; | 109 break; |
109 case 1: | 110 case 1: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 232 |
232 virtual void SetupTree() OVERRIDE { | 233 virtual void SetupTree() OVERRIDE { |
233 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); | 234 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
234 | 235 |
235 scoped_refptr<Layer> root_layer = Layer::Create(); | 236 scoped_refptr<Layer> root_layer = Layer::Create(); |
236 root_layer->SetBounds(gfx::Size(10, 10)); | 237 root_layer->SetBounds(gfx::Size(10, 10)); |
237 | 238 |
238 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 239 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
239 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); | 240 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); |
240 | 241 |
241 root_scroll_layer_->SetPosition(gfx::Point(0, 0)); | 242 root_scroll_layer_->SetPosition(gfx::Point()); |
242 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); | 243 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); |
243 | 244 |
244 root_scroll_layer_->SetIsDrawable(true); | 245 root_scroll_layer_->SetIsDrawable(true); |
245 root_scroll_layer_->SetScrollable(true); | 246 root_scroll_layer_->SetScrollable(true); |
246 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 247 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
247 root_layer->AddChild(root_scroll_layer_); | 248 root_layer->AddChild(root_scroll_layer_); |
248 | 249 |
249 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 250 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
250 child_layer_->set_did_scroll_callback( | 251 child_layer_->set_did_scroll_callback( |
251 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, | 252 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, |
252 base::Unretained(this))); | 253 base::Unretained(this))); |
253 child_layer_->SetBounds(gfx::Size(110, 110)); | 254 child_layer_->SetBounds(gfx::Size(110, 110)); |
254 | 255 |
255 // Scrolls on the child layer will happen at 5, 5. If they are treated | 256 if (scroll_child_layer_) { |
256 // like device pixels, and device scale factor is 2, then they will | 257 // Scrolls on the child layer will happen at 5, 5. If they are treated |
257 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. | 258 // like device pixels, and device scale factor is 2, then they will |
258 child_layer_->SetPosition(gfx::Point(5, 5)); | 259 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. |
| 260 child_layer_->SetPosition(gfx::Point(5, 5)); |
| 261 } else { |
| 262 // Adjust the child layer horizontally so that scrolls will never hit it. |
| 263 child_layer_->SetPosition(gfx::Point(60, 5)); |
| 264 } |
259 child_layer_->SetAnchorPoint(gfx::PointF()); | 265 child_layer_->SetAnchorPoint(gfx::PointF()); |
260 | 266 |
261 child_layer_->SetIsDrawable(true); | 267 child_layer_->SetIsDrawable(true); |
262 child_layer_->SetScrollable(true); | 268 child_layer_->SetScrollable(true); |
263 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 269 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
264 root_scroll_layer_->AddChild(child_layer_); | 270 root_scroll_layer_->AddChild(child_layer_); |
265 | 271 |
266 if (scroll_child_layer_) { | 272 if (scroll_child_layer_) { |
267 expected_scroll_layer_ = child_layer_; | 273 expected_scroll_layer_ = child_layer_; |
268 expected_no_scroll_layer_ = root_scroll_layer_; | 274 expected_no_scroll_layer_ = root_scroll_layer_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 root_scroll_layer_->content_bounds()); | 345 root_scroll_layer_->content_bounds()); |
340 | 346 |
341 expected_content_bounds = gfx::ToCeiledSize( | 347 expected_content_bounds = gfx::ToCeiledSize( |
342 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_)); | 348 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_)); |
343 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds()); | 349 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds()); |
344 | 350 |
345 switch (impl->active_tree()->source_frame_number()) { | 351 switch (impl->active_tree()->source_frame_number()) { |
346 case 0: { | 352 case 0: { |
347 // Gesture scroll on impl thread. | 353 // Gesture scroll on impl thread. |
348 InputHandler::ScrollStatus status = impl->ScrollBegin( | 354 InputHandler::ScrollStatus status = impl->ScrollBegin( |
349 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() + | 355 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() - |
350 gfx::Vector2dF(0.5f, 0.5f)), | 356 gfx::Vector2dF(0.5f, 0.5f)), |
351 InputHandler::Gesture); | 357 InputHandler::Gesture); |
352 EXPECT_EQ(InputHandler::ScrollStarted, status); | 358 EXPECT_EQ(InputHandler::ScrollStarted, status); |
353 impl->ScrollBy(gfx::Point(), scroll_amount_); | 359 impl->ScrollBy(gfx::Point(), scroll_amount_); |
354 impl->ScrollEnd(); | 360 impl->ScrollEnd(); |
355 | 361 |
356 // Check the scroll is applied as a delta. | 362 // Check the scroll is applied as a delta. |
357 EXPECT_VECTOR_EQ(initial_offset_, | 363 EXPECT_VECTOR_EQ(initial_offset_, |
358 expected_scroll_layer_impl->scroll_offset()); | 364 expected_scroll_layer_impl->scroll_offset()); |
359 EXPECT_VECTOR_EQ(scroll_amount_, | 365 EXPECT_VECTOR_EQ(scroll_amount_, |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 RunTest(true, false, false); | 849 RunTest(true, false, false); |
844 } | 850 } |
845 | 851 |
846 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 852 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
847 scroll_destroy_whole_tree_ = true; | 853 scroll_destroy_whole_tree_ = true; |
848 RunTest(true, false, false); | 854 RunTest(true, false, false); |
849 } | 855 } |
850 | 856 |
851 } // namespace | 857 } // namespace |
852 } // namespace cc | 858 } // namespace cc |
OLD | NEW |