Chromium Code Reviews| 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" |
| 11 #include "cc/test/fake_content_layer_client.h" | 11 #include "cc/test/fake_content_layer_client.h" |
| 12 #include "cc/test/fake_layer_tree_host_client.h" | 12 #include "cc/test/fake_layer_tree_host_client.h" |
| 13 #include "cc/test/geometry_test_utils.h" | 13 #include "cc/test/geometry_test_utils.h" |
| 14 #include "cc/test/layer_tree_test.h" | 14 #include "cc/test/layer_tree_test.h" |
| 15 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
| 16 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" | |
| 17 #include "ui/gfx/point_conversions.h" | 16 #include "ui/gfx/point_conversions.h" |
| 18 #include "ui/gfx/size_conversions.h" | 17 #include "ui/gfx/size_conversions.h" |
| 19 #include "ui/gfx/vector2d_conversions.h" | 18 #include "ui/gfx/vector2d_conversions.h" |
| 20 | 19 |
| 21 namespace cc { | 20 namespace cc { |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 class LayerTreeHostScrollTest : public LayerTreeTest {}; | 23 class LayerTreeHostScrollTest : public LayerTreeTest {}; |
| 25 | 24 |
| 26 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { | 25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 214 } |
| 216 | 215 |
| 217 virtual void AfterTest() OVERRIDE {} | 216 virtual void AfterTest() OVERRIDE {} |
| 218 | 217 |
| 219 private: | 218 private: |
| 220 gfx::Vector2dF scroll_amount_; | 219 gfx::Vector2dF scroll_amount_; |
| 221 }; | 220 }; |
| 222 | 221 |
| 223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); | 222 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); |
| 224 | 223 |
| 225 class LayerTreeHostScrollTestCaseWithChild | 224 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { |
| 226 : public LayerTreeHostScrollTest, | |
| 227 public WebKit::WebLayerScrollClient { | |
| 228 public: | 225 public: |
| 229 LayerTreeHostScrollTestCaseWithChild() | 226 LayerTreeHostScrollTestCaseWithChild() |
| 230 : initial_offset_(10, 20), | 227 : initial_offset_(10, 20), |
| 231 javascript_scroll_(40, 5), | 228 javascript_scroll_(40, 5), |
| 232 scroll_amount_(2, -1), | 229 scroll_amount_(2, -1), |
| 233 num_scrolls_(0) {} | 230 num_scrolls_(0) {} |
| 234 | 231 |
| 235 virtual void SetupTree() OVERRIDE { | 232 virtual void SetupTree() OVERRIDE { |
| 236 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); | 233 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 237 | 234 |
| 238 scoped_refptr<Layer> root_layer = Layer::Create(); | 235 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 239 root_layer->SetBounds(gfx::Size(10, 10)); | 236 root_layer->SetBounds(gfx::Size(10, 10)); |
| 240 | 237 |
| 241 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 238 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
| 242 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); | 239 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); |
| 243 | 240 |
| 244 root_scroll_layer_->SetPosition(gfx::Point(0, 0)); | 241 root_scroll_layer_->SetPosition(gfx::Point(0, 0)); |
| 245 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); | 242 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); |
| 246 | 243 |
| 247 root_scroll_layer_->SetIsDrawable(true); | 244 root_scroll_layer_->SetIsDrawable(true); |
| 248 root_scroll_layer_->SetScrollable(true); | 245 root_scroll_layer_->SetScrollable(true); |
| 249 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 246 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 250 root_layer->AddChild(root_scroll_layer_); | 247 root_layer->AddChild(root_scroll_layer_); |
| 251 | 248 |
| 252 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 249 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
| 253 child_layer_->set_layer_scroll_client(this); | 250 child_layer_->set_did_scroll_callback( |
| 251 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, | |
| 252 base::Unretained(this))); | |
| 254 child_layer_->SetBounds(gfx::Size(110, 110)); | 253 child_layer_->SetBounds(gfx::Size(110, 110)); |
| 255 | 254 |
| 256 // Scrolls on the child layer will happen at 5, 5. If they are treated | 255 // Scrolls on the child layer will happen at 5, 5. If they are treated |
| 257 // like device pixels, and device scale factor is 2, then they will | 256 // like device pixels, and device scale factor is 2, then they will |
| 258 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. | 257 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. |
| 259 child_layer_->SetPosition(gfx::Point(5, 5)); | 258 child_layer_->SetPosition(gfx::Point(5, 5)); |
| 260 child_layer_->SetAnchorPoint(gfx::PointF()); | 259 child_layer_->SetAnchorPoint(gfx::PointF()); |
| 261 | 260 |
| 262 child_layer_->SetIsDrawable(true); | 261 child_layer_->SetIsDrawable(true); |
| 263 child_layer_->SetScrollable(true); | 262 child_layer_->SetScrollable(true); |
| 264 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 263 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 265 root_scroll_layer_->AddChild(child_layer_); | 264 root_scroll_layer_->AddChild(child_layer_); |
| 266 | 265 |
| 267 if (scroll_child_layer_) { | 266 if (scroll_child_layer_) { |
| 268 expected_scroll_layer_ = child_layer_; | 267 expected_scroll_layer_ = child_layer_; |
| 269 expected_no_scroll_layer_ = root_scroll_layer_; | 268 expected_no_scroll_layer_ = root_scroll_layer_; |
| 270 } else { | 269 } else { |
| 271 expected_scroll_layer_ = root_scroll_layer_; | 270 expected_scroll_layer_ = root_scroll_layer_; |
| 272 expected_no_scroll_layer_ = child_layer_; | 271 expected_no_scroll_layer_ = child_layer_; |
| 273 } | 272 } |
| 274 | 273 |
| 275 expected_scroll_layer_->SetScrollOffset(initial_offset_); | 274 expected_scroll_layer_->SetScrollOffset(initial_offset_); |
| 276 | 275 |
| 277 layer_tree_host()->SetRootLayer(root_layer); | 276 layer_tree_host()->SetRootLayer(root_layer); |
| 278 LayerTreeHostScrollTest::SetupTree(); | 277 LayerTreeHostScrollTest::SetupTree(); |
| 279 } | 278 } |
| 280 | 279 |
| 281 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 280 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 282 | 281 |
| 283 virtual void didScroll() OVERRIDE { | 282 void DidScroll() { |
| 284 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); | 283 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); |
| 285 } | 284 } |
| 286 | 285 |
| 287 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 286 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 288 OVERRIDE { | 287 OVERRIDE { |
| 289 gfx::Vector2d offset = root_scroll_layer_->scroll_offset(); | 288 gfx::Vector2d offset = root_scroll_layer_->scroll_offset(); |
| 290 root_scroll_layer_->SetScrollOffset(offset + scroll_delta); | 289 root_scroll_layer_->SetScrollOffset(offset + scroll_delta); |
| 291 num_scrolls_++; | 290 num_scrolls_++; |
| 292 } | 291 } |
| 293 | 292 |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 virtual void DidScroll(Layer* layer) { | 792 virtual void DidScroll(Layer* layer) { |
| 794 if (scroll_destroy_whole_tree_) { | 793 if (scroll_destroy_whole_tree_) { |
| 795 layer_tree_host()->SetRootLayer(NULL); | 794 layer_tree_host()->SetRootLayer(NULL); |
| 796 EndTest(); | 795 EndTest(); |
| 797 return; | 796 return; |
| 798 } | 797 } |
| 799 layer->RemoveFromParent(); | 798 layer->RemoveFromParent(); |
| 800 } | 799 } |
| 801 | 800 |
| 802 protected: | 801 protected: |
| 803 class FakeWebLayerScrollClient : public WebKit::WebLayerScrollClient { | 802 class FakeLayerScrollClient { |
|
danakj
2013/06/28 16:06:54
Can this class just go away here, and we set the c
tfarina
2013/06/28 16:13:33
I'll try this when I get back to home later tonigh
danakj
2013/06/28 16:46:43
Oh, that's true. LGTM
| |
| 804 public: | 803 public: |
| 805 virtual void didScroll() OVERRIDE { | 804 void DidScroll() { |
| 806 owner_->DidScroll(layer_); | 805 owner_->DidScroll(layer_); |
| 807 } | 806 } |
| 808 LayerTreeHostScrollTestLayerStructureChange* owner_; | 807 LayerTreeHostScrollTestLayerStructureChange* owner_; |
| 809 Layer* layer_; | 808 Layer* layer_; |
| 810 }; | 809 }; |
| 811 | 810 |
| 812 Layer* CreateScrollLayer(Layer* parent, FakeWebLayerScrollClient* client) { | 811 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { |
| 813 scoped_refptr<Layer> scroll_layer = | 812 scoped_refptr<Layer> scroll_layer = |
| 814 ContentLayer::Create(&fake_content_layer_client_); | 813 ContentLayer::Create(&fake_content_layer_client_); |
| 815 scroll_layer->SetBounds(gfx::Size(110, 110)); | 814 scroll_layer->SetBounds(gfx::Size(110, 110)); |
| 816 scroll_layer->SetPosition(gfx::Point(0, 0)); | 815 scroll_layer->SetPosition(gfx::Point(0, 0)); |
| 817 scroll_layer->SetAnchorPoint(gfx::PointF()); | 816 scroll_layer->SetAnchorPoint(gfx::PointF()); |
| 818 scroll_layer->SetIsDrawable(true); | 817 scroll_layer->SetIsDrawable(true); |
| 819 scroll_layer->SetScrollable(true); | 818 scroll_layer->SetScrollable(true); |
| 820 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 819 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 821 scroll_layer->set_layer_scroll_client(client); | 820 scroll_layer->set_did_scroll_callback(base::Bind( |
| 821 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); | |
| 822 client->owner_ = this; | 822 client->owner_ = this; |
| 823 client->layer_ = scroll_layer.get(); | 823 client->layer_ = scroll_layer.get(); |
| 824 parent->AddChild(scroll_layer); | 824 parent->AddChild(scroll_layer); |
| 825 return scroll_layer.get(); | 825 return scroll_layer.get(); |
| 826 } | 826 } |
| 827 | 827 |
| 828 FakeWebLayerScrollClient root_scroll_layer_client_; | 828 FakeLayerScrollClient root_scroll_layer_client_; |
| 829 FakeWebLayerScrollClient sibling_scroll_layer_client_; | 829 FakeLayerScrollClient sibling_scroll_layer_client_; |
| 830 FakeWebLayerScrollClient child_scroll_layer_client_; | 830 FakeLayerScrollClient child_scroll_layer_client_; |
| 831 | 831 |
| 832 FakeContentLayerClient fake_content_layer_client_; | 832 FakeContentLayerClient fake_content_layer_client_; |
| 833 | 833 |
| 834 bool scroll_destroy_whole_tree_; | 834 bool scroll_destroy_whole_tree_; |
| 835 }; | 835 }; |
| 836 | 836 |
| 837 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { | 837 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { |
| 838 RunTest(true, false, false); | 838 RunTest(true, false, false); |
| 839 } | 839 } |
| 840 | 840 |
| 841 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 841 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 842 scroll_destroy_whole_tree_ = true; | 842 scroll_destroy_whole_tree_ = true; |
| 843 RunTest(true, false, false); | 843 RunTest(true, false, false); |
| 844 } | 844 } |
| 845 | 845 |
| 846 } // namespace | 846 } // namespace |
| 847 } // namespace cc | 847 } // namespace cc |
| OLD | NEW |