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

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

Issue 18139004: cc: Create a LayerScrollClient interface and an adapter class in compositor_bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 "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/layers/layer_scroll_client.h"
11 #include "cc/test/fake_content_layer_client.h" 12 #include "cc/test/fake_content_layer_client.h"
12 #include "cc/test/fake_layer_tree_host_client.h" 13 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/geometry_test_utils.h" 14 #include "cc/test/geometry_test_utils.h"
14 #include "cc/test/layer_tree_test.h" 15 #include "cc/test/layer_tree_test.h"
15 #include "cc/trees/layer_tree_impl.h" 16 #include "cc/trees/layer_tree_impl.h"
16 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h"
17 #include "ui/gfx/point_conversions.h" 17 #include "ui/gfx/point_conversions.h"
18 #include "ui/gfx/size_conversions.h" 18 #include "ui/gfx/size_conversions.h"
19 #include "ui/gfx/vector2d_conversions.h" 19 #include "ui/gfx/vector2d_conversions.h"
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 class LayerTreeHostScrollTest : public LayerTreeTest {}; 24 class LayerTreeHostScrollTest : public LayerTreeTest {};
25 25
26 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { 26 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 215 }
216 216
217 virtual void AfterTest() OVERRIDE {} 217 virtual void AfterTest() OVERRIDE {}
218 218
219 private: 219 private:
220 gfx::Vector2dF scroll_amount_; 220 gfx::Vector2dF scroll_amount_;
221 }; 221 };
222 222
223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); 223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll);
224 224
225 class LayerTreeHostScrollTestCaseWithChild 225 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest,
226 : public LayerTreeHostScrollTest, 226 public LayerScrollClient {
227 public WebKit::WebLayerScrollClient {
228 public: 227 public:
229 LayerTreeHostScrollTestCaseWithChild() 228 LayerTreeHostScrollTestCaseWithChild()
230 : initial_offset_(10, 20), 229 : initial_offset_(10, 20),
231 javascript_scroll_(40, 5), 230 javascript_scroll_(40, 5),
232 scroll_amount_(2, -1), 231 scroll_amount_(2, -1),
233 num_scrolls_(0) {} 232 num_scrolls_(0) {}
234 233
235 virtual void SetupTree() OVERRIDE { 234 virtual void SetupTree() OVERRIDE {
236 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); 235 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
237 236
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 virtual void DidScroll() OVERRIDE {
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
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 : public LayerScrollClient {
804 public: 803 public:
805 virtual void didScroll() OVERRIDE { 804 virtual void DidScroll() OVERRIDE {
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_layer_scroll_client(client);
822 client->owner_ = this; 821 client->owner_ = this;
823 client->layer_ = scroll_layer.get(); 822 client->layer_ = scroll_layer.get();
824 parent->AddChild(scroll_layer); 823 parent->AddChild(scroll_layer);
825 return scroll_layer.get(); 824 return scroll_layer.get();
826 } 825 }
827 826
828 FakeWebLayerScrollClient root_scroll_layer_client_; 827 FakeLayerScrollClient root_scroll_layer_client_;
829 FakeWebLayerScrollClient sibling_scroll_layer_client_; 828 FakeLayerScrollClient sibling_scroll_layer_client_;
830 FakeWebLayerScrollClient child_scroll_layer_client_; 829 FakeLayerScrollClient child_scroll_layer_client_;
831 830
832 FakeContentLayerClient fake_content_layer_client_; 831 FakeContentLayerClient fake_content_layer_client_;
833 832
834 bool scroll_destroy_whole_tree_; 833 bool scroll_destroy_whole_tree_;
835 }; 834 };
836 835
837 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { 836 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) {
838 RunTest(true, false, false); 837 RunTest(true, false, false);
839 } 838 }
840 839
841 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 840 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
842 scroll_destroy_whole_tree_ = true; 841 scroll_destroy_whole_tree_ = true;
843 RunTest(true, false, false); 842 RunTest(true, false, false);
844 } 843 }
845 844
846 } // namespace 845 } // namespace
847 } // namespace cc 846 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698