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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "ScrollbarLayerChromium.h" | 7 #include "ScrollbarLayerChromium.h" |
8 | 8 |
9 #include "CCScrollbarAnimationController.h" | 9 #include "CCScrollbarAnimationController.h" |
10 #include "CCScrollbarLayerImpl.h" | 10 #include "CCScrollbarLayerImpl.h" |
11 #include "CCSingleThreadProxy.h" | 11 #include "CCSingleThreadProxy.h" |
12 #include "TreeSynchronizer.h" | 12 #include "TreeSynchronizer.h" |
13 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | 13 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <public/WebScrollbar.h> | 15 #include <public/WebScrollbar.h> |
16 #include <public/WebScrollbarThemeGeometry.h> | 16 #include <public/WebScrollbarThemeGeometry.h> |
17 #include <public/WebScrollbarThemePainter.h> | 17 #include <public/WebScrollbarThemePainter.h> |
18 | 18 |
19 using namespace cc; | 19 using namespace cc; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class FakeWebScrollbar : public WebKit::WebScrollbar { | 23 class FakeWebScrollbar : public WebKit::WebScrollbar { |
24 public: | 24 public: |
25 static PassOwnPtr<FakeWebScrollbar> create() { return adoptPtr(new FakeWebSc
rollbar()); } | 25 static scoped_ptr<FakeWebScrollbar> create() { return make_scoped_ptr(new Fa
keWebScrollbar()); } |
26 | 26 |
27 // WebScrollbar implementation | 27 // WebScrollbar implementation |
28 virtual bool isOverlay() const OVERRIDE { return false; } | 28 virtual bool isOverlay() const OVERRIDE { return false; } |
29 virtual int value() const OVERRIDE { return 0; } | 29 virtual int value() const OVERRIDE { return 0; } |
30 virtual WebKit::WebPoint location() const OVERRIDE { return WebKit::WebPoint
(); } | 30 virtual WebKit::WebPoint location() const OVERRIDE { return WebKit::WebPoint
(); } |
31 virtual WebKit::WebSize size() const OVERRIDE { return WebKit::WebSize(); } | 31 virtual WebKit::WebSize size() const OVERRIDE { return WebKit::WebSize(); } |
32 virtual bool enabled() const OVERRIDE { return true; } | 32 virtual bool enabled() const OVERRIDE { return true; } |
33 virtual int maximum() const OVERRIDE { return 0; } | 33 virtual int maximum() const OVERRIDE { return 0; } |
34 virtual int totalSize() const OVERRIDE { return 0; } | 34 virtual int totalSize() const OVERRIDE { return 0; } |
35 virtual bool isScrollViewScrollbar() const OVERRIDE { return false; } | 35 virtual bool isScrollViewScrollbar() const OVERRIDE { return false; } |
36 virtual bool isScrollableAreaActive() const OVERRIDE { return true; } | 36 virtual bool isScrollableAreaActive() const OVERRIDE { return true; } |
37 virtual void getTickmarks(WebKit::WebVector<WebKit::WebRect>&) const OVERRID
E { } | 37 virtual void getTickmarks(WebKit::WebVector<WebKit::WebRect>&) const OVERRID
E { } |
38 virtual ScrollbarControlSize controlSize() const OVERRIDE { return WebScroll
bar::RegularScrollbar; } | 38 virtual ScrollbarControlSize controlSize() const OVERRIDE { return WebScroll
bar::RegularScrollbar; } |
39 virtual ScrollbarPart pressedPart() const OVERRIDE { return WebScrollbar::No
Part; } | 39 virtual ScrollbarPart pressedPart() const OVERRIDE { return WebScrollbar::No
Part; } |
40 virtual ScrollbarPart hoveredPart() 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; } | 41 virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const OVERRIDE { retur
n WebScrollbar::ScrollbarOverlayStyleDefault; } |
42 virtual bool isCustomScrollbar() const OVERRIDE { return false; } | 42 virtual bool isCustomScrollbar() const OVERRIDE { return false; } |
43 virtual Orientation orientation() const OVERRIDE { return WebScrollbar::Hori
zontal; } | 43 virtual Orientation orientation() const OVERRIDE { return WebScrollbar::Hori
zontal; } |
44 }; | 44 }; |
45 | 45 |
46 TEST(ScrollbarLayerChromiumTest, resolveScrollLayerPointer) | 46 TEST(ScrollbarLayerChromiumTest, resolveScrollLayerPointer) |
47 { | 47 { |
48 DebugScopedSetImplThread impl; | 48 DebugScopedSetImplThread impl; |
49 | 49 |
50 WebKit::WebScrollbarThemePainter painter; | 50 WebKit::WebScrollbarThemePainter painter; |
51 | 51 |
52 { | 52 { |
53 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 53 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
54 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 54 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
55 scoped_refptr<LayerChromium> child1 = LayerChromium::create(); | 55 scoped_refptr<LayerChromium> child1 = LayerChromium::create(); |
56 scoped_refptr<LayerChromium> child2 = ScrollbarLayerChromium::create(scr
ollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), chil
d1->id()); | 56 scoped_refptr<LayerChromium> child2 = ScrollbarLayerChromium::create(scr
ollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child1-
>id()); |
57 layerTreeRoot->addChild(child1); | 57 layerTreeRoot->addChild(child1); |
58 layerTreeRoot->addChild(child2); | 58 layerTreeRoot->addChild(child2); |
59 | 59 |
60 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); | 60 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); |
61 | 61 |
62 CCLayerImpl* ccChild1 = ccLayerTreeRoot->children()[0]; | 62 CCLayerImpl* ccChild1 = ccLayerTreeRoot->children()[0]; |
63 CCScrollbarLayerImpl* ccChild2 = static_cast<CCScrollbarLayerImpl*>(ccLa
yerTreeRoot->children()[1]); | 63 CCScrollbarLayerImpl* ccChild2 = static_cast<CCScrollbarLayerImpl*>(ccLa
yerTreeRoot->children()[1]); |
64 | 64 |
65 EXPECT_TRUE(ccChild1->scrollbarAnimationController()); | 65 EXPECT_TRUE(ccChild1->scrollbarAnimationController()); |
66 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); | 66 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); |
67 } | 67 } |
68 | 68 |
69 { // another traverse order | 69 { // another traverse order |
70 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 70 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
71 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 71 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
72 scoped_refptr<LayerChromium> child2 = LayerChromium::create(); | 72 scoped_refptr<LayerChromium> child2 = LayerChromium::create(); |
73 scoped_refptr<LayerChromium> child1 = ScrollbarLayerChromium::create(scr
ollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), chil
d2->id()); | 73 scoped_refptr<LayerChromium> child1 = ScrollbarLayerChromium::create(scr
ollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child2-
>id()); |
74 layerTreeRoot->addChild(child1); | 74 layerTreeRoot->addChild(child1); |
75 layerTreeRoot->addChild(child2); | 75 layerTreeRoot->addChild(child2); |
76 | 76 |
77 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); | 77 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeT
rees(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); |
78 | 78 |
79 CCScrollbarLayerImpl* ccChild1 = static_cast<CCScrollbarLayerImpl*>(ccLa
yerTreeRoot->children()[0]); | 79 CCScrollbarLayerImpl* ccChild1 = static_cast<CCScrollbarLayerImpl*>(ccLa
yerTreeRoot->children()[0]); |
80 CCLayerImpl* ccChild2 = ccLayerTreeRoot->children()[1]; | 80 CCLayerImpl* ccChild2 = ccLayerTreeRoot->children()[1]; |
81 | 81 |
82 EXPECT_TRUE(ccChild2->scrollbarAnimationController()); | 82 EXPECT_TRUE(ccChild2->scrollbarAnimationController()); |
83 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); | 83 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 TEST(ScrollbarLayerChromiumTest, scrollOffsetSynchronization) | 87 TEST(ScrollbarLayerChromiumTest, scrollOffsetSynchronization) |
88 { | 88 { |
89 DebugScopedSetImplThread impl; | 89 DebugScopedSetImplThread impl; |
90 | 90 |
91 WebKit::WebScrollbarThemePainter painter; | 91 WebKit::WebScrollbarThemePainter painter; |
92 | 92 |
93 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); | 93 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
94 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); | 94 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create(); |
95 scoped_refptr<LayerChromium> contentLayer = LayerChromium::create(); | 95 scoped_refptr<LayerChromium> contentLayer = LayerChromium::create(); |
96 scoped_refptr<LayerChromium> scrollbarLayer = ScrollbarLayerChromium::create
(scrollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(),
layerTreeRoot->id()); | 96 scoped_refptr<LayerChromium> scrollbarLayer = ScrollbarLayerChromium::create
(scrollbar.Pass(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), lay
erTreeRoot->id()); |
97 layerTreeRoot->addChild(contentLayer); | 97 layerTreeRoot->addChild(contentLayer); |
98 layerTreeRoot->addChild(scrollbarLayer); | 98 layerTreeRoot->addChild(scrollbarLayer); |
99 | 99 |
100 layerTreeRoot->setScrollPosition(IntPoint(10, 20)); | 100 layerTreeRoot->setScrollPosition(IntPoint(10, 20)); |
101 layerTreeRoot->setMaxScrollPosition(IntSize(30, 50)); | 101 layerTreeRoot->setMaxScrollPosition(IntSize(30, 50)); |
102 contentLayer->setBounds(IntSize(100, 200)); | 102 contentLayer->setBounds(IntSize(100, 200)); |
103 | 103 |
104 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); | 104 scoped_ptr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees
(layerTreeRoot.get(), scoped_ptr<CCLayerImpl>(), 0); |
105 | 105 |
106 CCScrollbarLayerImpl* ccScrollbarLayer = static_cast<CCScrollbarLayerImpl*>(
ccLayerTreeRoot->children()[1]); | 106 CCScrollbarLayerImpl* ccScrollbarLayer = static_cast<CCScrollbarLayerImpl*>(
ccLayerTreeRoot->children()[1]); |
(...skipping 15 matching lines...) Expand all Loading... |
122 EXPECT_EQ(300, ccScrollbarLayer->maximum()); | 122 EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
123 | 123 |
124 ccLayerTreeRoot->scrollBy(FloatSize(12, 34)); | 124 ccLayerTreeRoot->scrollBy(FloatSize(12, 34)); |
125 | 125 |
126 EXPECT_EQ(112, ccScrollbarLayer->currentPos()); | 126 EXPECT_EQ(112, ccScrollbarLayer->currentPos()); |
127 EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); | 127 EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); |
128 EXPECT_EQ(300, ccScrollbarLayer->maximum()); | 128 EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
129 } | 129 } |
130 | 130 |
131 } | 131 } |
OLD | NEW |