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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollableAreaTest.cpp

Issue 1550983002: Revert of Make ScrollbarThemeAura selectively invalidate scrollbar parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
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/GraphicsLayer.h" 7 #include "platform/graphics/GraphicsLayer.h"
8 #include "platform/scroll/ScrollbarTheme.h" 8 #include "platform/scroll/ScrollbarTheme.h"
9 #include "platform/scroll/ScrollbarThemeMock.h" 9 #include "platform/scroll/ScrollbarThemeMock.h"
10 #include "platform/testing/TestingPlatformSupport.h" 10 #include "platform/testing/TestingPlatformSupport.h"
11 #include "public/platform/Platform.h" 11 #include "public/platform/Platform.h"
12 #include "public/platform/WebScheduler.h" 12 #include "public/platform/WebScheduler.h"
13 #include "public/platform/WebThread.h" 13 #include "public/platform/WebThread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 namespace { 19 namespace {
20 20
21 using testing::_;
22 using testing::Return; 21 using testing::Return;
23 22
24 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea { 23 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea {
25 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
26 public: 25 public:
27 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max imumScrollPosition) 26 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max imumScrollPosition)
28 { 27 {
29 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition)) ; 28 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition)) ;
30 } 29 }
31 30
32 MOCK_CONST_METHOD0(isActive, bool()); 31 MOCK_CONST_METHOD0(isActive, bool());
33 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 32 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
34 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 33 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
35 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 34 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
36 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*());
37 MOCK_CONST_METHOD0(verticalScrollbar, Scrollbar*());
38 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 35 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
39 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); 36 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*());
40 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); 37 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect));
41 MOCK_CONST_METHOD0(contentsSize, IntSize()); 38 MOCK_CONST_METHOD0(contentsSize, IntSize());
42 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); 39 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect());
43 MOCK_CONST_METHOD0(layerForHorizontalScrollbar, GraphicsLayer*()); 40 MOCK_CONST_METHOD0(layerForHorizontalScrollbar, GraphicsLayer*());
44 MOCK_CONST_METHOD0(layerForVerticalScrollbar, GraphicsLayer*());
45 41
46 bool userInputScrollable(ScrollbarOrientation) const override { return true; } 42 bool userInputScrollable(ScrollbarOrientation) const override { return true; }
47 bool scrollbarsCanBeActive () const override { return true; } 43 bool scrollbarsCanBeActive () const override { return true; }
48 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } 44 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; }
49 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll Position = offset.shrunkTo(m_maximumScrollPosition); } 45 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll Position = offset.shrunkTo(m_maximumScrollPosition); }
50 IntPoint scrollPosition() const override { return m_scrollPosition; } 46 IntPoint scrollPosition() const override { return m_scrollPosition; }
51 IntPoint minimumScrollPosition() const override { return IntPoint(); } 47 IntPoint minimumScrollPosition() const override { return IntPoint(); }
52 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi tion; } 48 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi tion; }
53 int visibleHeight() const override { return 768; } 49 int visibleHeight() const override { return 768; }
54 int visibleWidth() const override { return 1024; } 50 int visibleWidth() const override { return 1024; }
55 bool scrollAnimatorEnabled() const override { return false; } 51 bool scrollAnimatorEnabled() const override { return false; }
56 int pageStep(ScrollbarOrientation) const override { return 0; } 52 int pageStep(ScrollbarOrientation) const override { return 0; }
57 53
58 using ScrollableArea::horizontalScrollbarNeedsPaintInvalidation;
59 using ScrollableArea::verticalScrollbarNeedsPaintInvalidation;
60 using ScrollableArea::clearNeedsPaintInvalidationForScrollControls;
61
62 DEFINE_INLINE_VIRTUAL_TRACE() 54 DEFINE_INLINE_VIRTUAL_TRACE()
63 { 55 {
64 ScrollableArea::trace(visitor); 56 ScrollableArea::trace(visitor);
65 } 57 }
66 58
67 private: 59 private:
68 explicit MockScrollableArea(const IntPoint& maximumScrollPosition) 60 explicit MockScrollableArea(const IntPoint& maximumScrollPosition)
69 : m_maximumScrollPosition(maximumScrollPosition) { } 61 : m_maximumScrollPosition(maximumScrollPosition) { }
70 62
71 IntPoint m_scrollPosition; 63 IntPoint m_scrollPosition;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 135 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100));
144 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); 136 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll);
145 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); 137 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y());
146 } 138 }
147 139
148 namespace { 140 namespace {
149 141
150 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { 142 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock {
151 public: 143 public:
152 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); 144 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool());
153 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float));
154 }; 145 };
155 146
156 } // namespace 147 } // namespace
157 148
158 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) 149 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint)
159 { 150 {
160 ScrollbarThemeWithMockInvalidation theme; 151 ScrollbarThemeWithMockInvalidation theme;
161 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 152 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100));
162 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scroll ableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 153 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scroll ableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
163 154
164 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true)); 155 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true));
165 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 156 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
166 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 157 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
167 scrollbar->setNeedsPaintInvalidation(); 158 scrollbar->setNeedsPaintInvalidation();
168 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 159 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
169 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 160 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
170 161
171 scrollbar->setTrackNeedsRepaint(false); 162 scrollbar->setTrackNeedsRepaint(false);
172 scrollbar->setThumbNeedsRepaint(false); 163 scrollbar->setThumbNeedsRepaint(false);
173 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 164 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
174 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); 165 EXPECT_FALSE(scrollbar->thumbNeedsRepaint());
175 scrollbar->setNeedsPaintInvalidation(ThumbPart); 166 scrollbar->setNeedsPaintInvalidation();
176 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 167 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
177 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 168 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
178 169
179 // When not all parts are repainted on invalidation,
180 // setNeedsPaintInvalidation sets repaint bits only on the requested parts.
181 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false)); 170 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
182 scrollbar->setTrackNeedsRepaint(false); 171 scrollbar->setTrackNeedsRepaint(false);
183 scrollbar->setThumbNeedsRepaint(false); 172 scrollbar->setThumbNeedsRepaint(false);
184 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 173 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
185 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); 174 EXPECT_FALSE(scrollbar->thumbNeedsRepaint());
186 scrollbar->setNeedsPaintInvalidation(ThumbPart); 175 scrollbar->setNeedsPaintInvalidation();
187 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 176 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
188 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 177 EXPECT_FALSE(scrollbar->thumbNeedsRepaint());
189 178
190 // Forced GC in order to finalize objects depending on the mock object. 179 // Forced GC in order to finalize objects depending on the mock object.
191 Heap::collectAllGarbage(); 180 Heap::collectAllGarbage();
192 } 181 }
193 182
194 class MockGraphicsLayerClient : public GraphicsLayerClient { 183 class MockGraphicsLayerClient : public GraphicsLayerClient {
195 public: 184 public:
196 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); } 185 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); }
197 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { } 186 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { }
198 String debugName(const GraphicsLayer*) const override { return String(); } 187 String debugName(const GraphicsLayer*) const override { return String(); }
(...skipping 15 matching lines...) Expand all
214 graphicsLayer.setSize(FloatSize(111, 222)); 203 graphicsLayer.setSize(FloatSize(111, 222));
215 204
216 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer)); 205 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer));
217 206
218 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.g et(), HorizontalScrollbar, RegularScrollbar); 207 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.g et(), HorizontalScrollbar, RegularScrollbar);
219 graphicsLayer.resetTrackedPaintInvalidations(); 208 graphicsLayer.resetTrackedPaintInvalidations();
220 scrollbar->setNeedsPaintInvalidation(); 209 scrollbar->setNeedsPaintInvalidation();
221 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 210 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations());
222 } 211 }
223 212
224 TEST_F(ScrollableAreaTest, InvalidatesNonCompositedScrollbarsWhenThumbMoves)
225 {
226 ScrollbarThemeWithMockInvalidation theme;
227 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(100, 100));
228 RefPtrWillBeRawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTest ing(scrollableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
229 RefPtrWillBeRawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTestin g(scrollableArea.get(), VerticalScrollbar, RegularScrollbar, &theme);
230 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get()));
231 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get()));
232
233 // Regardless of whether the theme invalidates any parts, non-composited
234 // scrollbars have to be repainted if the thumb moves.
235 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(nullptr));
236 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(nullptr));
237 ASSERT_FALSE(scrollableArea->hasLayerForVerticalScrollbar());
238 ASSERT_FALSE(scrollableArea->hasLayerForHorizontalScrollbar());
239 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
240 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillRepeatedly( Return(NoPart));
241
242 // A scroll in each direction should only invalidate one scrollbar.
243 scrollableArea->setScrollPosition(DoublePoint(0, 50), ProgrammaticScroll);
244 EXPECT_FALSE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
245 EXPECT_TRUE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
246 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
247 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
248 EXPECT_TRUE(scrollableArea->horizontalScrollbarNeedsPaintInvalidation());
249 EXPECT_FALSE(scrollableArea->verticalScrollbarNeedsPaintInvalidation());
250 scrollableArea->clearNeedsPaintInvalidationForScrollControls();
251
252 // Forced GC in order to finalize objects depending on the mock object.
253 Heap::collectAllGarbage();
254 }
255
256
257 TEST_F(ScrollableAreaTest, InvalidatesCompositedScrollbarsIfPartsNeedRepaint)
258 {
259 ScrollbarThemeWithMockInvalidation theme;
260 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(100, 100));
261 RefPtrWillBeRawPtr<Scrollbar> horizontalScrollbar = Scrollbar::createForTest ing(scrollableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
262 horizontalScrollbar->setTrackNeedsRepaint(false);
263 horizontalScrollbar->setThumbNeedsRepaint(false);
264 RefPtrWillBeRawPtr<Scrollbar> verticalScrollbar = Scrollbar::createForTestin g(scrollableArea.get(), VerticalScrollbar, RegularScrollbar, &theme);
265 verticalScrollbar->setTrackNeedsRepaint(false);
266 verticalScrollbar->setThumbNeedsRepaint(false);
267 EXPECT_CALL(*scrollableArea, horizontalScrollbar()).WillRepeatedly(Return(ho rizontalScrollbar.get()));
268 EXPECT_CALL(*scrollableArea, verticalScrollbar()).WillRepeatedly(Return(vert icalScrollbar.get()));
269
270 // Composited scrollbars only need repainting when parts become invalid
271 // (e.g. if the track changes appearance when the thumb reaches the end).
272 MockGraphicsLayerClient graphicsLayerClient;
273 MockGraphicsLayer layerForHorizontalScrollbar(&graphicsLayerClient);
274 layerForHorizontalScrollbar.setDrawsContent(true);
275 layerForHorizontalScrollbar.setSize(FloatSize(10, 10));
276 MockGraphicsLayer layerForVerticalScrollbar(&graphicsLayerClient);
277 layerForVerticalScrollbar.setDrawsContent(true);
278 layerForVerticalScrollbar.setSize(FloatSize(10, 10));
279 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&layerForHorizontalScrollbar));
280 EXPECT_CALL(*scrollableArea, layerForVerticalScrollbar()).WillRepeatedly(Ret urn(&layerForVerticalScrollbar));
281 ASSERT_TRUE(scrollableArea->hasLayerForHorizontalScrollbar());
282 ASSERT_TRUE(scrollableArea->hasLayerForVerticalScrollbar());
283 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
284
285 // First, we'll scroll horizontally, and the theme will require repainting
286 // the back button (i.e. the track).
287 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (BackButtonStartPart));
288 scrollableArea->setScrollPosition(DoublePoint(50, 0), ProgrammaticScroll);
289 EXPECT_TRUE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations());
290 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedPaintInvalidations());
291 EXPECT_TRUE(horizontalScrollbar->trackNeedsRepaint());
292 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
293 layerForHorizontalScrollbar.resetTrackedPaintInvalidations();
294 horizontalScrollbar->setTrackNeedsRepaint(false);
295
296 // Next, we'll scroll vertically, but invalidate the thumb.
297 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).WillOnce(Return (ThumbPart));
298 scrollableArea->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll);
299 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations());
300 EXPECT_TRUE(layerForVerticalScrollbar.hasTrackedPaintInvalidations());
301 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
302 EXPECT_TRUE(verticalScrollbar->thumbNeedsRepaint());
303 layerForVerticalScrollbar.resetTrackedPaintInvalidations();
304 verticalScrollbar->setThumbNeedsRepaint(false);
305
306 // Next we'll scroll in both, but the thumb position moving requires no
307 // invalidations.
308 EXPECT_CALL(theme, invalidateOnThumbPositionChange(_, _, _)).Times(2).WillRe peatedly(Return(NoPart));
309 scrollableArea->setScrollPosition(DoublePoint(70, 70), ProgrammaticScroll);
310 EXPECT_FALSE(layerForHorizontalScrollbar.hasTrackedPaintInvalidations());
311 EXPECT_FALSE(layerForVerticalScrollbar.hasTrackedPaintInvalidations());
312 EXPECT_FALSE(horizontalScrollbar->trackNeedsRepaint());
313 EXPECT_FALSE(horizontalScrollbar->thumbNeedsRepaint());
314 EXPECT_FALSE(verticalScrollbar->trackNeedsRepaint());
315 EXPECT_FALSE(verticalScrollbar->thumbNeedsRepaint());
316 }
317
318 } // namespace blink 213 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollableArea.cpp ('k') | third_party/WebKit/Source/platform/scroll/Scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698