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

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

Issue 1558493002: Reland: Make ScrollbarThemeAura selectively invalidate scrollbar parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ScrollableAreaTest.InvalidatesCompositedScrollbarsIfPartsNeedRepaint for Oilpan 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::_;
21 using testing::Return; 22 using testing::Return;
22 23
23 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea { 24 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro llableArea>, public ScrollableArea {
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); 25 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea);
25 public: 26 public:
26 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max imumScrollPosition) 27 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max imumScrollPosition)
27 { 28 {
28 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition)) ; 29 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition)) ;
29 } 30 }
30 31
31 MOCK_CONST_METHOD0(isActive, bool()); 32 MOCK_CONST_METHOD0(isActive, bool());
32 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); 33 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation));
33 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); 34 MOCK_CONST_METHOD0(isScrollCornerVisible, bool());
34 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); 35 MOCK_CONST_METHOD0(scrollCornerRect, IntRect());
36 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*());
37 MOCK_CONST_METHOD0(verticalScrollbar, Scrollbar*());
35 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); 38 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void());
36 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); 39 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*());
37 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); 40 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect));
38 MOCK_CONST_METHOD0(contentsSize, IntSize()); 41 MOCK_CONST_METHOD0(contentsSize, IntSize());
39 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); 42 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect());
40 MOCK_CONST_METHOD0(layerForHorizontalScrollbar, GraphicsLayer*()); 43 MOCK_CONST_METHOD0(layerForHorizontalScrollbar, GraphicsLayer*());
44 MOCK_CONST_METHOD0(layerForVerticalScrollbar, GraphicsLayer*());
41 45
42 bool userInputScrollable(ScrollbarOrientation) const override { return true; } 46 bool userInputScrollable(ScrollbarOrientation) const override { return true; }
43 bool scrollbarsCanBeActive () const override { return true; } 47 bool scrollbarsCanBeActive () const override { return true; }
44 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } 48 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; }
45 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll Position = offset.shrunkTo(m_maximumScrollPosition); } 49 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll Position = offset.shrunkTo(m_maximumScrollPosition); }
46 IntPoint scrollPosition() const override { return m_scrollPosition; } 50 IntPoint scrollPosition() const override { return m_scrollPosition; }
47 IntPoint minimumScrollPosition() const override { return IntPoint(); } 51 IntPoint minimumScrollPosition() const override { return IntPoint(); }
48 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi tion; } 52 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi tion; }
49 int visibleHeight() const override { return 768; } 53 int visibleHeight() const override { return 768; }
50 int visibleWidth() const override { return 1024; } 54 int visibleWidth() const override { return 1024; }
51 bool scrollAnimatorEnabled() const override { return false; } 55 bool scrollAnimatorEnabled() const override { return false; }
52 int pageStep(ScrollbarOrientation) const override { return 0; } 56 int pageStep(ScrollbarOrientation) const override { return 0; }
53 57
58 using ScrollableArea::horizontalScrollbarNeedsPaintInvalidation;
59 using ScrollableArea::verticalScrollbarNeedsPaintInvalidation;
60 using ScrollableArea::clearNeedsPaintInvalidationForScrollControls;
61
54 DEFINE_INLINE_VIRTUAL_TRACE() 62 DEFINE_INLINE_VIRTUAL_TRACE()
55 { 63 {
56 ScrollableArea::trace(visitor); 64 ScrollableArea::trace(visitor);
57 } 65 }
58 66
59 private: 67 private:
60 explicit MockScrollableArea(const IntPoint& maximumScrollPosition) 68 explicit MockScrollableArea(const IntPoint& maximumScrollPosition)
61 : m_maximumScrollPosition(maximumScrollPosition) { } 69 : m_maximumScrollPosition(maximumScrollPosition) { }
62 70
63 IntPoint m_scrollPosition; 71 IntPoint m_scrollPosition;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 143 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100));
136 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); 144 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll);
137 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); 145 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y());
138 } 146 }
139 147
140 namespace { 148 namespace {
141 149
142 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { 150 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock {
143 public: 151 public:
144 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); 152 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool());
153 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro llbarThemeClient&, float, float));
145 }; 154 };
146 155
147 } // namespace 156 } // namespace
148 157
149 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) 158 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint)
150 { 159 {
151 ScrollbarThemeWithMockInvalidation theme; 160 ScrollbarThemeWithMockInvalidation theme;
152 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100)); 161 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea:: create(IntPoint(0, 100));
153 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scroll ableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme); 162 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::createForTesting(scroll ableArea.get(), HorizontalScrollbar, RegularScrollbar, &theme);
154 163
155 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true)); 164 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(true));
156 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 165 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
157 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 166 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
158 scrollbar->setNeedsPaintInvalidation(); 167 scrollbar->setNeedsPaintInvalidation();
159 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 168 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
160 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 169 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
161 170
162 scrollbar->setTrackNeedsRepaint(false); 171 scrollbar->setTrackNeedsRepaint(false);
163 scrollbar->setThumbNeedsRepaint(false); 172 scrollbar->setThumbNeedsRepaint(false);
164 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 173 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
165 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); 174 EXPECT_FALSE(scrollbar->thumbNeedsRepaint());
166 scrollbar->setNeedsPaintInvalidation(); 175 scrollbar->setNeedsPaintInvalidation(ThumbPart);
167 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); 176 EXPECT_TRUE(scrollbar->trackNeedsRepaint());
168 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); 177 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
169 178
179 // When not all parts are repainted on invalidation,
180 // setNeedsPaintInvalidation sets repaint bits only on the requested parts.
170 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false)); 181 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret urn(false));
171 scrollbar->setTrackNeedsRepaint(false); 182 scrollbar->setTrackNeedsRepaint(false);
172 scrollbar->setThumbNeedsRepaint(false); 183 scrollbar->setThumbNeedsRepaint(false);
173 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 184 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
174 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); 185 EXPECT_FALSE(scrollbar->thumbNeedsRepaint());
175 scrollbar->setNeedsPaintInvalidation(); 186 scrollbar->setNeedsPaintInvalidation(ThumbPart);
176 EXPECT_FALSE(scrollbar->trackNeedsRepaint()); 187 EXPECT_FALSE(scrollbar->trackNeedsRepaint());
177 EXPECT_FALSE(scrollbar->thumbNeedsRepaint()); 188 EXPECT_TRUE(scrollbar->thumbNeedsRepaint());
178 189
179 // Forced GC in order to finalize objects depending on the mock object. 190 // Forced GC in order to finalize objects depending on the mock object.
180 Heap::collectAllGarbage(); 191 Heap::collectAllGarbage();
181 } 192 }
182 193
183 class MockGraphicsLayerClient : public GraphicsLayerClient { 194 class MockGraphicsLayerClient : public GraphicsLayerClient {
184 public: 195 public:
185 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); } 196 IntRect computeInterestRect(const GraphicsLayer*, const IntRect&) const { re turn IntRect(); }
186 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { } 197 void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPain tingPhase, const IntRect&) const override { }
187 String debugName(const GraphicsLayer*) const override { return String(); } 198 String debugName(const GraphicsLayer*) const override { return String(); }
(...skipping 15 matching lines...) Expand all
203 graphicsLayer.setSize(FloatSize(111, 222)); 214 graphicsLayer.setSize(FloatSize(111, 222));
204 215
205 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer)); 216 EXPECT_CALL(*scrollableArea, layerForHorizontalScrollbar()).WillRepeatedly(R eturn(&graphicsLayer));
206 217
207 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.g et(), HorizontalScrollbar, RegularScrollbar); 218 RefPtrWillBeRawPtr<Scrollbar> scrollbar = Scrollbar::create(scrollableArea.g et(), HorizontalScrollbar, RegularScrollbar);
208 graphicsLayer.resetTrackedPaintInvalidations(); 219 graphicsLayer.resetTrackedPaintInvalidations();
209 scrollbar->setNeedsPaintInvalidation(); 220 scrollbar->setNeedsPaintInvalidation();
210 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations()); 221 EXPECT_TRUE(graphicsLayer.hasTrackedPaintInvalidations());
211 } 222 }
212 223
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 // Forced GC in order to finalize objects depending on the mock object.
318 Heap::collectAllGarbage();
319 }
320
213 } // namespace blink 321 } // 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