OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scroll/ScrollableArea.h" | 5 #include "platform/scroll/ScrollableArea.h" |
6 | 6 |
7 #include "platform/graphics/Color.h" | 7 #include "platform/graphics/Color.h" |
8 #include "platform/graphics/GraphicsLayer.h" | 8 #include "platform/graphics/GraphicsLayer.h" |
9 #include "platform/scroll/ScrollbarTestSuite.h" | 9 #include "platform/scroll/ScrollbarTestSuite.h" |
10 #include "platform/scroll/ScrollbarTheme.h" | 10 #include "platform/scroll/ScrollbarTheme.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, | 29 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, |
30 ScrollbarPart(const ScrollbarThemeClient&, float, float)); | 30 ScrollbarPart(const ScrollbarThemeClient&, float, float)); |
31 }; | 31 }; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class ScrollableAreaTest : public ScrollbarTestSuite {}; | 35 class ScrollableAreaTest : public ScrollbarTestSuite {}; |
36 | 36 |
37 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) { | 37 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) { |
38 MockScrollableArea* scrollableArea = | 38 MockScrollableArea* scrollableArea = |
39 MockScrollableArea::create(IntPoint(0, 100)); | 39 MockScrollableArea::create(ScrollOffset(0, 100)); |
40 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); | 40 scrollableArea->setScrollOffset(ScrollOffset(0, 10000), CompositorScroll); |
41 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); | 41 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentOffset().height()); |
42 } | 42 } |
43 | 43 |
44 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) { | 44 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) { |
45 ScrollbarThemeWithMockInvalidation theme; | 45 ScrollbarThemeWithMockInvalidation theme; |
46 MockScrollableArea* scrollableArea = | 46 MockScrollableArea* scrollableArea = |
47 MockScrollableArea::create(IntPoint(0, 100)); | 47 MockScrollableArea::create(ScrollOffset(0, 100)); |
48 Scrollbar* scrollbar = Scrollbar::createForTesting( | 48 Scrollbar* scrollbar = Scrollbar::createForTesting( |
49 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 49 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
50 | 50 |
51 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) | 51 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) |
52 .WillRepeatedly(Return(true)); | 52 .WillRepeatedly(Return(true)); |
53 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); | 53 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); |
54 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 54 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
55 scrollbar->setNeedsPaintInvalidation(NoPart); | 55 scrollbar->setNeedsPaintInvalidation(NoPart); |
56 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); | 56 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); |
57 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 57 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
(...skipping 18 matching lines...) Expand all Loading... |
76 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); | 76 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); |
77 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 77 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
78 | 78 |
79 // Forced GC in order to finalize objects depending on the mock object. | 79 // Forced GC in order to finalize objects depending on the mock object. |
80 ThreadState::current()->collectAllGarbage(); | 80 ThreadState::current()->collectAllGarbage(); |
81 } | 81 } |
82 | 82 |
83 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) { | 83 TEST_F(ScrollableAreaTest, ScrollbarGraphicsLayerInvalidation) { |
84 ScrollbarTheme::setMockScrollbarsEnabled(true); | 84 ScrollbarTheme::setMockScrollbarsEnabled(true); |
85 MockScrollableArea* scrollableArea = | 85 MockScrollableArea* scrollableArea = |
86 MockScrollableArea::create(IntPoint(0, 100)); | 86 MockScrollableArea::create(ScrollOffset(0, 100)); |
87 FakeGraphicsLayerClient graphicsLayerClient; | 87 FakeGraphicsLayerClient graphicsLayerClient; |
88 graphicsLayerClient.setIsTrackingRasterInvalidations(true); | 88 graphicsLayerClient.setIsTrackingRasterInvalidations(true); |
89 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); | 89 FakeGraphicsLayer graphicsLayer(&graphicsLayerClient); |
90 graphicsLayer.setDrawsContent(true); | 90 graphicsLayer.setDrawsContent(true); |
91 graphicsLayer.setSize(FloatSize(111, 222)); | 91 graphicsLayer.setSize(FloatSize(111, 222)); |
92 | 92 |
93 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) | 93 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) |
94 .WillRepeatedly(Return(&graphicsLayer)); | 94 .WillRepeatedly(Return(&graphicsLayer)); |
95 | 95 |
96 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar, | 96 Scrollbar* scrollbar = Scrollbar::create(scrollableArea, HorizontalScrollbar, |
97 RegularScrollbar, nullptr); | 97 RegularScrollbar, nullptr); |
98 graphicsLayer.resetTrackedRasterInvalidations(); | 98 graphicsLayer.resetTrackedRasterInvalidations(); |
99 scrollbar->setNeedsPaintInvalidation(NoPart); | 99 scrollbar->setNeedsPaintInvalidation(NoPart); |
100 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations()); | 100 EXPECT_TRUE(graphicsLayer.hasTrackedRasterInvalidations()); |
101 | 101 |
102 // Forced GC in order to finalize objects depending on the mock object. | 102 // Forced GC in order to finalize objects depending on the mock object. |
103 ThreadState::current()->collectAllGarbage(); | 103 ThreadState::current()->collectAllGarbage(); |
104 } | 104 } |
105 | 105 |
106 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) { | 106 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves) { |
107 ScrollbarThemeWithMockInvalidation theme; | 107 ScrollbarThemeWithMockInvalidation theme; |
108 MockScrollableArea* scrollableArea = | 108 MockScrollableArea* scrollableArea = |
109 MockScrollableArea::create(IntPoint(100, 100)); | 109 MockScrollableArea::create(ScrollOffset(100, 100)); |
110 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( | 110 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( |
111 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 111 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
112 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( | 112 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( |
113 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); | 113 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); |
114 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) | 114 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) |
115 .WillRepeatedly(Return(horizontalScrollbar)); | 115 .WillRepeatedly(Return(horizontalScrollbar)); |
116 EXPECT_CALL(*scrollableArea, verticalScrollbar()) | 116 EXPECT_CALL(*scrollableArea, verticalScrollbar()) |
117 .WillRepeatedly(Return(verticalScrollbar)); | 117 .WillRepeatedly(Return(verticalScrollbar)); |
118 | 118 |
119 // Regardless of whether the theme invalidates any parts, non-composited | 119 // Regardless of whether the theme invalidates any parts, non-composited |
120 // scrollbars have to be repainted if the thumb moves. | 120 // scrollbars have to be repainted if the thumb moves. |
121 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) | 121 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()) |
122 .WillRepeatedly(Return(nullptr)); | 122 .WillRepeatedly(Return(nullptr)); |
123 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()) | 123 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()) |
124 .WillRepeatedly(Return(nullptr)); | 124 .WillRepeatedly(Return(nullptr)); |
125 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar()); | 125 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar()); |
126 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar()); | 126 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar()); |
127 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) | 127 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) |
128 .WillRepeatedly(Return(false)); | 128 .WillRepeatedly(Return(false)); |
129 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) | 129 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) |
130 .WillRepeatedly(Return(NoPart)); | 130 .WillRepeatedly(Return(NoPart)); |
131 | 131 |
132 // A scroll in each direction should only invalidate one scrollbar. | 132 // A scroll in each direction should only invalidate one scrollbar. |
133 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll); | 133 scrollableArea->setScrollOffset(ScrollOffset(0, 50), ProgrammaticScroll); |
134 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); | 134 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); |
135 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); | 135 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); |
136 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); | 136 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); |
137 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); | 137 scrollableArea->setScrollOffset(ScrollOffset(50, 50), ProgrammaticScroll); |
138 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); | 138 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation()); |
139 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); | 139 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation()); |
140 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); | 140 scrollableArea->clearNeedsPaintInvalidationForScrollControls(); |
141 | 141 |
142 // Forced GC in order to finalize objects depending on the mock object. | 142 // Forced GC in order to finalize objects depending on the mock object. |
143 ThreadState::current()->collectAllGarbage(); | 143 ThreadState::current()->collectAllGarbage(); |
144 } | 144 } |
145 | 145 |
146 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) { | 146 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint) { |
147 ScrollbarThemeWithMockInvalidation theme; | 147 ScrollbarThemeWithMockInvalidation theme; |
148 MockScrollableArea* scrollableArea = | 148 MockScrollableArea* scrollableArea = |
149 MockScrollableArea::create(IntPoint(100, 100)); | 149 MockScrollableArea::create(ScrollOffset(100, 100)); |
150 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( | 150 Scrollbar* horizontalScrollbar = Scrollbar::createForTesting( |
151 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); | 151 scrollableArea, HorizontalScrollbar, RegularScrollbar, &theme); |
152 horizontalScrollbar->clearTrackNeedsRepaint(); | 152 horizontalScrollbar->clearTrackNeedsRepaint(); |
153 horizontalScrollbar->clearThumbNeedsRepaint(); | 153 horizontalScrollbar->clearThumbNeedsRepaint(); |
154 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( | 154 Scrollbar* verticalScrollbar = Scrollbar::createForTesting( |
155 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); | 155 scrollableArea, VerticalScrollbar, RegularScrollbar, &theme); |
156 verticalScrollbar->clearTrackNeedsRepaint(); | 156 verticalScrollbar->clearTrackNeedsRepaint(); |
157 verticalScrollbar->clearThumbNeedsRepaint(); | 157 verticalScrollbar->clearThumbNeedsRepaint(); |
158 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) | 158 EXPECT_CALL(*scrollableArea, horizontalScrollbar()) |
159 .WillRepeatedly(Return(horizontalScrollbar)); | 159 .WillRepeatedly(Return(horizontalScrollbar)); |
(...skipping 16 matching lines...) Expand all Loading... |
176 .WillRepeatedly(Return(&layerForVerticalScrollbar)); | 176 .WillRepeatedly(Return(&layerForVerticalScrollbar)); |
177 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar()); | 177 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar()); |
178 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar()); | 178 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar()); |
179 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) | 179 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()) |
180 .WillRepeatedly(Return(false)); | 180 .WillRepeatedly(Return(false)); |
181 | 181 |
182 // First, we'll scroll horizontally, and the theme will require repainting | 182 // First, we'll scroll horizontally, and the theme will require repainting |
183 // the back button (i.e. the track). | 183 // the back button (i.e. the track). |
184 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) | 184 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) |
185 .WillOnce(Return(BackButtonStartPart)); | 185 .WillOnce(Return(BackButtonStartPart)); |
186 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll); | 186 scrollableArea->setScrollOffset(ScrollOffset(50, 0), ProgrammaticScroll); |
187 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); | 187 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); |
188 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); | 188 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); |
189 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint()); | 189 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint()); |
190 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); | 190 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); |
191 layerForHorizontalScrollbar.resetTrackedRasterInvalidations(); | 191 layerForHorizontalScrollbar.resetTrackedRasterInvalidations(); |
192 horizontalScrollbar->clearTrackNeedsRepaint(); | 192 horizontalScrollbar->clearTrackNeedsRepaint(); |
193 | 193 |
194 // Next, we'll scroll vertically, but invalidate the thumb. | 194 // Next, we'll scroll vertically, but invalidate the thumb. |
195 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) | 195 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) |
196 .WillOnce(Return(ThumbPart)); | 196 .WillOnce(Return(ThumbPart)); |
197 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); | 197 scrollableArea->setScrollOffset(ScrollOffset(50, 50), ProgrammaticScroll); |
198 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); | 198 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); |
199 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); | 199 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); |
200 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); | 200 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); |
201 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint()); | 201 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint()); |
202 layerForVerticalScrollbar.resetTrackedRasterInvalidations(); | 202 layerForVerticalScrollbar.resetTrackedRasterInvalidations(); |
203 verticalScrollbar->clearThumbNeedsRepaint(); | 203 verticalScrollbar->clearThumbNeedsRepaint(); |
204 | 204 |
205 // Next we'll scroll in both, but the thumb position moving requires no | 205 // Next we'll scroll in both, but the thumb position moving requires no |
206 // invalidations. Nonetheless the GraphicsLayer should be invalidated, | 206 // invalidations. Nonetheless the GraphicsLayer should be invalidated, |
207 // because we still need to update the underlying layer (though no | 207 // because we still need to update the underlying layer (though no |
208 // rasterization will be required). | 208 // rasterization will be required). |
209 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) | 209 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)) |
210 .Times(2) | 210 .Times(2) |
211 .WillRepeatedly(Return(NoPart)); | 211 .WillRepeatedly(Return(NoPart)); |
212 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll); | 212 scrollableArea->setScrollOffset(ScrollOffset(70, 70), ProgrammaticScroll); |
213 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); | 213 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedRasterInvalidations()); |
214 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); | 214 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedRasterInvalidations()); |
215 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); | 215 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint()); |
216 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); | 216 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint()); |
217 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); | 217 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint()); |
218 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); | 218 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint()); |
219 | 219 |
220 // Forced GC in order to finalize objects depending on the mock object. | 220 // Forced GC in order to finalize objects depending on the mock object. |
221 ThreadState::current()->collectAllGarbage(); | 221 ThreadState::current()->collectAllGarbage(); |
222 } | 222 } |
223 | 223 |
224 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) { | 224 TEST_F(ScrollableAreaTest, RecalculatesScrollbarOverlayIfBackgroundChanges) { |
225 MockScrollableArea* scrollableArea = | 225 MockScrollableArea* scrollableArea = |
226 MockScrollableArea::create(IntPoint(0, 100)); | 226 MockScrollableArea::create(ScrollOffset(0, 100)); |
227 | 227 |
228 EXPECT_EQ(ScrollbarOverlayStyleDefault, | 228 EXPECT_EQ(ScrollbarOverlayStyleDefault, |
229 scrollableArea->getScrollbarOverlayStyle()); | 229 scrollableArea->getScrollbarOverlayStyle()); |
230 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); | 230 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); |
231 EXPECT_EQ(ScrollbarOverlayStyleLight, | 231 EXPECT_EQ(ScrollbarOverlayStyleLight, |
232 scrollableArea->getScrollbarOverlayStyle()); | 232 scrollableArea->getScrollbarOverlayStyle()); |
233 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); | 233 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); |
234 EXPECT_EQ(ScrollbarOverlayStyleDefault, | 234 EXPECT_EQ(ScrollbarOverlayStyleDefault, |
235 scrollableArea->getScrollbarOverlayStyle()); | 235 scrollableArea->getScrollbarOverlayStyle()); |
236 } | 236 } |
237 | 237 |
238 } // namespace blink | 238 } // namespace blink |
OLD | NEW |