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/scrollbar_layer.h" | 5 #include "cc/scrollbar_layer.h" |
6 | 6 |
7 #include "cc/scrollbar_animation_controller.h" | 7 #include "cc/scrollbar_animation_controller.h" |
8 #include "cc/scrollbar_layer_impl.h" | 8 #include "cc/scrollbar_layer_impl.h" |
9 #include "cc/single_thread_proxy.h" | 9 #include "cc/single_thread_proxy.h" |
10 #include "cc/test/fake_impl_proxy.h" | 10 #include "cc/test/fake_impl_proxy.h" |
11 #include "cc/test/fake_layer_tree_host_impl.h" | 11 #include "cc/test/fake_layer_tree_host_impl.h" |
| 12 #include "cc/test/fake_scrollbar_theme_painter.h" |
| 13 #include "cc/test/fake_web_scrollbar.h" |
12 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | 14 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
13 #include "cc/test/layer_tree_test_common.h" | 15 #include "cc/test/layer_tree_test_common.h" |
14 #include "cc/tree_synchronizer.h" | 16 #include "cc/tree_synchronizer.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 #include <public/WebScrollbar.h> | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGe
ometry.h" |
17 #include <public/WebScrollbarThemeGeometry.h> | |
18 #include <public/WebScrollbarThemePainter.h> | |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 class FakeWebScrollbar : public WebKit::WebScrollbar { | |
24 public: | |
25 static scoped_ptr<FakeWebScrollbar> create() { return make_scoped_ptr(new Fa
keWebScrollbar()); } | |
26 | |
27 // WebScrollbar implementation | |
28 virtual bool isOverlay() const OVERRIDE { return false; } | |
29 virtual int value() const OVERRIDE { return 0; } | |
30 virtual WebKit::WebPoint location() const OVERRIDE { return WebKit::WebPoint
(); } | |
31 virtual WebKit::WebSize size() const OVERRIDE { return WebKit::WebSize(); } | |
32 virtual bool enabled() const OVERRIDE { return true; } | |
33 virtual int maximum() const OVERRIDE { return 0; } | |
34 virtual int totalSize() const OVERRIDE { return 0; } | |
35 virtual bool isScrollViewScrollbar() const OVERRIDE { return false; } | |
36 virtual bool isScrollableAreaActive() const OVERRIDE { return true; } | |
37 virtual void getTickmarks(WebKit::WebVector<WebKit::WebRect>&) const OVERRID
E { } | |
38 virtual ScrollbarControlSize controlSize() const OVERRIDE { return WebScroll
bar::RegularScrollbar; } | |
39 virtual ScrollbarPart pressedPart() const OVERRIDE { return WebScrollbar::No
Part; } | |
40 virtual ScrollbarPart hoveredPart() const OVERRIDE { return WebScrollbar::No
Part; } | |
41 virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const OVERRIDE { retur
n WebScrollbar::ScrollbarOverlayStyleDefault; } | |
42 virtual bool isCustomScrollbar() const OVERRIDE { return false; } | |
43 virtual Orientation orientation() const OVERRIDE { return WebScrollbar::Hori
zontal; } | |
44 }; | |
45 | |
46 TEST(ScrollbarLayerTest, resolveScrollLayerPointer) | 23 TEST(ScrollbarLayerTest, resolveScrollLayerPointer) |
47 { | 24 { |
48 FakeImplProxy proxy; | 25 FakeImplProxy proxy; |
49 FakeLayerTreeHostImpl hostImpl(&proxy); | 26 FakeLayerTreeHostImpl hostImpl(&proxy); |
50 WebKit::WebScrollbarThemePainter painter; | |
51 | 27 |
52 { | 28 { |
53 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 29 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
54 scoped_refptr<Layer> layerTreeRoot = Layer::create(); | 30 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
55 scoped_refptr<Layer> child1 = Layer::create(); | 31 scoped_refptr<Layer> child1 = Layer::create(); |
56 scoped_refptr<Layer> child2 = ScrollbarLayer::create(scrollbar.Pass(), p
ainter, FakeWebScrollbarThemeGeometry::create(), child1->id()); | 32 scoped_refptr<Layer> child2 = ScrollbarLayer::create(scrollbar.Pass(), F
akeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWeb
ScrollbarThemeGeometry::create(), child1->id()); |
57 layerTreeRoot->addChild(child1); | 33 layerTreeRoot->addChild(child1); |
58 layerTreeRoot->addChild(child2); | 34 layerTreeRoot->addChild(child2); |
59 | 35 |
60 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); | 36 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
61 | 37 |
62 LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; | 38 LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; |
63 ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImp
lTreeRoot->children()[1]); | 39 ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImp
lTreeRoot->children()[1]); |
64 | 40 |
65 EXPECT_TRUE(ccChild1->scrollbarAnimationController()); | 41 EXPECT_TRUE(ccChild1->scrollbarAnimationController()); |
66 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); | 42 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); |
67 } | 43 } |
68 | 44 |
69 { // another traverse order | 45 { // another traverse order |
70 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 46 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
71 scoped_refptr<Layer> layerTreeRoot = Layer::create(); | 47 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
72 scoped_refptr<Layer> child2 = Layer::create(); | 48 scoped_refptr<Layer> child2 = Layer::create(); |
73 scoped_refptr<Layer> child1 = ScrollbarLayer::create(scrollbar.Pass(), p
ainter, FakeWebScrollbarThemeGeometry::create(), child2->id()); | 49 scoped_refptr<Layer> child1 = ScrollbarLayer::create(scrollbar.Pass(), F
akeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWeb
ScrollbarThemeGeometry::create(), child2->id()); |
74 layerTreeRoot->addChild(child1); | 50 layerTreeRoot->addChild(child1); |
75 layerTreeRoot->addChild(child2); | 51 layerTreeRoot->addChild(child2); |
76 | 52 |
77 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); | 53 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
78 | 54 |
79 ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImp
lTreeRoot->children()[0]); | 55 ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImp
lTreeRoot->children()[0]); |
80 LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; | 56 LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; |
81 | 57 |
82 EXPECT_TRUE(ccChild2->scrollbarAnimationController()); | 58 EXPECT_TRUE(ccChild2->scrollbarAnimationController()); |
83 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); | 59 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); |
84 } | 60 } |
85 } | 61 } |
86 | 62 |
87 TEST(ScrollbarLayerTest, scrollOffsetSynchronization) | 63 TEST(ScrollbarLayerTest, scrollOffsetSynchronization) |
88 { | 64 { |
89 FakeImplProxy proxy; | 65 FakeImplProxy proxy; |
90 FakeLayerTreeHostImpl hostImpl(&proxy); | 66 FakeLayerTreeHostImpl hostImpl(&proxy); |
91 WebKit::WebScrollbarThemePainter painter; | |
92 | 67 |
93 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 68 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
94 scoped_refptr<Layer> layerTreeRoot = Layer::create(); | 69 scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
95 scoped_refptr<Layer> contentLayer = Layer::create(); | 70 scoped_refptr<Layer> contentLayer = Layer::create(); |
96 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(
), painter, FakeWebScrollbarThemeGeometry::create(), layerTreeRoot->id()); | 71 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(
), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), Fak
eWebScrollbarThemeGeometry::create(), layerTreeRoot->id()); |
97 layerTreeRoot->addChild(contentLayer); | 72 layerTreeRoot->addChild(contentLayer); |
98 layerTreeRoot->addChild(scrollbarLayer); | 73 layerTreeRoot->addChild(scrollbarLayer); |
99 | 74 |
100 layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); | 75 layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); |
101 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); | 76 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); |
102 contentLayer->setBounds(gfx::Size(100, 200)); | 77 contentLayer->setBounds(gfx::Size(100, 200)); |
103 | 78 |
104 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); | 79 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
105 | 80 |
106 ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(laye
rImplTreeRoot->children()[1]); | 81 ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(laye
rImplTreeRoot->children()[1]); |
(...skipping 27 matching lines...) Expand all Loading... |
134 | 109 |
135 void setScrollbarBounds(gfx::Size bounds) { | 110 void setScrollbarBounds(gfx::Size bounds) { |
136 m_bounds = bounds; | 111 m_bounds = bounds; |
137 } | 112 } |
138 | 113 |
139 virtual void beginTest() OVERRIDE | 114 virtual void beginTest() OVERRIDE |
140 { | 115 { |
141 m_layerTreeHost->initializeRendererIfNeeded(); | 116 m_layerTreeHost->initializeRendererIfNeeded(); |
142 | 117 |
143 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 118 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
144 m_scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), m_painter, F
akeWebScrollbarThemeGeometry::create(), 1); | 119 m_scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollba
rThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarTh
emeGeometry::create(), 1); |
145 m_scrollbarLayer->setLayerTreeHost(m_layerTreeHost.get()); | 120 m_scrollbarLayer->setLayerTreeHost(m_layerTreeHost.get()); |
146 m_scrollbarLayer->setBounds(m_bounds); | 121 m_scrollbarLayer->setBounds(m_bounds); |
147 m_layerTreeHost->rootLayer()->addChild(m_scrollbarLayer); | 122 m_layerTreeHost->rootLayer()->addChild(m_scrollbarLayer); |
148 | 123 |
149 m_scrollLayer = Layer::create(); | 124 m_scrollLayer = Layer::create(); |
150 m_scrollbarLayer->setScrollLayerId(m_scrollLayer->id()); | 125 m_scrollbarLayer->setScrollLayerId(m_scrollLayer->id()); |
151 m_layerTreeHost->rootLayer()->addChild(m_scrollLayer); | 126 m_layerTreeHost->rootLayer()->addChild(m_scrollLayer); |
152 | 127 |
153 postSetNeedsCommitToMainThread(); | 128 postSetNeedsCommitToMainThread(); |
154 } | 129 } |
(...skipping 11 matching lines...) Expand all Loading... |
166 endTest(); | 141 endTest(); |
167 } | 142 } |
168 | 143 |
169 virtual void afterTest() OVERRIDE | 144 virtual void afterTest() OVERRIDE |
170 { | 145 { |
171 } | 146 } |
172 | 147 |
173 private: | 148 private: |
174 scoped_refptr<ScrollbarLayer> m_scrollbarLayer; | 149 scoped_refptr<ScrollbarLayer> m_scrollbarLayer; |
175 scoped_refptr<Layer> m_scrollLayer; | 150 scoped_refptr<Layer> m_scrollLayer; |
176 WebKit::WebScrollbarThemePainter m_painter; | |
177 gfx::Size m_bounds; | 151 gfx::Size m_bounds; |
178 }; | 152 }; |
179 | 153 |
180 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { | 154 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { |
181 FakeWebGraphicsContext3D context; | 155 FakeWebGraphicsContext3D context; |
182 int max_size = 0; | 156 int max_size = 0; |
183 context.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); | 157 context.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
184 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); | 158 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
185 runTest(true); | 159 runTest(true); |
186 } | 160 } |
187 | 161 |
188 } // namespace | 162 } // namespace |
189 } // namespace cc | 163 } // namespace cc |
OLD | NEW |