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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollableArea.h

Issue 1406133005: Calculate paint invalidation rect for scrollbars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // This is used to determine whether the incoming fractional scroll offset s hould 141 // This is used to determine whether the incoming fractional scroll offset s hould
142 // be truncated to integer. Current rule is that if preferCompositingToLCDTe xtEnabled() 142 // be truncated to integer. Current rule is that if preferCompositingToLCDTe xtEnabled()
143 // is disabled (which is true on low-dpi device by default) we should do the truncation. 143 // is disabled (which is true on low-dpi device by default) we should do the truncation.
144 // The justification is that non-composited elements using fractional scroll offsets 144 // The justification is that non-composited elements using fractional scroll offsets
145 // is causing too much nasty bugs but does not add too benefit on low-dpi de vices. 145 // is causing too much nasty bugs but does not add too benefit on low-dpi de vices.
146 virtual bool shouldUseIntegerScrollOffset() const { return !RuntimeEnabledFe atures::fractionalScrollOffsetsEnabled(); } 146 virtual bool shouldUseIntegerScrollOffset() const { return !RuntimeEnabledFe atures::fractionalScrollOffsetsEnabled(); }
147 147
148 virtual bool isActive() const = 0; 148 virtual bool isActive() const = 0;
149 virtual int scrollSize(ScrollbarOrientation) const = 0; 149 virtual int scrollSize(ScrollbarOrientation) const = 0;
150 virtual void invalidateScrollbar(Scrollbar*, const IntRect&); 150 void setScrollbarNeedsPaintInvalidation(Scrollbar*);
151 virtual bool isScrollCornerVisible() const = 0; 151 virtual bool isScrollCornerVisible() const = 0;
152 virtual IntRect scrollCornerRect() const = 0; 152 virtual IntRect scrollCornerRect() const = 0;
153 virtual void invalidateScrollCorner(const IntRect&); 153 void setScrollCornerNeedsPaintInvalidation();
154 virtual void getTickmarks(Vector<IntRect>&) const { } 154 virtual void getTickmarks(Vector<IntRect>&) const { }
155 155
156 // Convert points and rects between the scrollbar and its containing view. 156 // Convert points and rects between the scrollbar and its containing view.
157 // The client needs to implement these in order to be aware of layout effect s 157 // The client needs to implement these in order to be aware of layout effect s
158 // like CSS transforms. 158 // like CSS transforms.
159 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scroll bar, const IntRect& scrollbarRect) const 159 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scroll bar, const IntRect& scrollbarRect) const
160 { 160 {
161 return scrollbar->Widget::convertToContainingView(scrollbarRect); 161 return scrollbar->Widget::convertToContainingView(scrollbarRect);
162 } 162 }
163 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scroll bar, const IntRect& parentRect) const 163 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scroll bar, const IntRect& parentRect) const
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 virtual bool userInputScrollable(ScrollbarOrientation) const = 0; 229 virtual bool userInputScrollable(ScrollbarOrientation) const = 0;
230 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0; 230 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0;
231 231
232 // Convenience functions 232 // Convenience functions
233 int scrollPosition(ScrollbarOrientation orientation) { return orientation == HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); } 233 int scrollPosition(ScrollbarOrientation orientation) { return orientation == HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); }
234 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio n().y(); } 234 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio n().y(); }
235 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio n().y(); } 235 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio n().y(); }
236 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi on(orientation)); } 236 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi on(orientation)); }
237 237
238 bool hasVerticalBarDamage() const { return !m_verticalBarDamage.isEmpty(); }
239 bool hasHorizontalBarDamage() const { return !m_horizontalBarDamage.isEmpty( ); }
240 const IntRect& verticalBarDamage() const { return m_verticalBarDamage; }
241 const IntRect& horizontalBarDamage() const { return m_horizontalBarDamage; }
242
243 void addScrollbarDamage(Scrollbar* scrollbar, const IntRect& rect)
244 {
245 if (scrollbar == horizontalScrollbar())
246 m_horizontalBarDamage.unite(rect);
247 else
248 m_verticalBarDamage.unite(rect);
249 }
250
251 void resetScrollbarDamage()
252 {
253 m_verticalBarDamage = IntRect();
254 m_horizontalBarDamage = IntRect();
255 }
256
257 virtual GraphicsLayer* layerForContainer() const; 238 virtual GraphicsLayer* layerForContainer() const;
258 virtual GraphicsLayer* layerForScrolling() const { return 0; } 239 virtual GraphicsLayer* layerForScrolling() const { return 0; }
259 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; } 240 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; }
260 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; } 241 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; }
261 virtual GraphicsLayer* layerForScrollCorner() const { return 0; } 242 virtual GraphicsLayer* layerForScrollCorner() const { return 0; }
262 bool hasLayerForHorizontalScrollbar() const; 243 bool hasLayerForHorizontalScrollbar() const;
263 bool hasLayerForVerticalScrollbar() const; 244 bool hasLayerForVerticalScrollbar() const;
264 bool hasLayerForScrollCorner() const; 245 bool hasLayerForScrollCorner() const;
265 246
266 void layerForScrollingDidChange(WebCompositorAnimationTimeline*); 247 void layerForScrollingDidChange(WebCompositorAnimationTimeline*);
267 248
268 void cancelScrollAnimation(); 249 void cancelScrollAnimation();
269 void cancelProgrammaticScrollAnimation(); 250 void cancelProgrammaticScrollAnimation();
270 251
271 virtual ~ScrollableArea(); 252 virtual ~ScrollableArea();
272 253
273 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0; 254 // Called when any of horizontal scrollbar, vertical scrollbar and scroll co rner is setNeedsPaintInvalidation.
274 virtual void invalidateScrollCornerRect(const IntRect&) = 0; 255 virtual void scrollControlWasSetNeedsPaintInvalidation() = 0;
275 256
276 // Returns the default scroll style this area should scroll with when not 257 // Returns the default scroll style this area should scroll with when not
277 // explicitly specified. E.g. The scrolling behavior of an element can be 258 // explicitly specified. E.g. The scrolling behavior of an element can be
278 // specified in CSS. 259 // specified in CSS.
279 virtual ScrollBehavior scrollBehaviorStyle() const { return ScrollBehaviorIn stant; } 260 virtual ScrollBehavior scrollBehaviorStyle() const { return ScrollBehaviorIn stant; }
280 261
281 // TODO(bokan): This is only used in FrameView to check scrollability but is 262 // TODO(bokan): This is only used in FrameView to check scrollability but is
282 // needed here to allow RootFrameViewport to preserve wheelHandler 263 // needed here to allow RootFrameViewport to preserve wheelHandler
283 // semantics. Not sure why it's FrameView specific, it could probably be 264 // semantics. Not sure why it's FrameView specific, it could probably be
284 // generalized to other types of ScrollableAreas. 265 // generalized to other types of ScrollableAreas.
(...skipping 20 matching lines...) Expand all
305 void setScrollOrigin(const IntPoint&); 286 void setScrollOrigin(const IntPoint&);
306 void resetScrollOriginChanged() { m_scrollOriginChanged = false; } 287 void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
307 288
308 // Needed to let the animators call scrollPositionChanged. 289 // Needed to let the animators call scrollPositionChanged.
309 friend class ScrollAnimatorBase; 290 friend class ScrollAnimatorBase;
310 friend class ProgrammaticScrollAnimator; 291 friend class ProgrammaticScrollAnimator;
311 void scrollPositionChanged(const DoublePoint&, ScrollType); 292 void scrollPositionChanged(const DoublePoint&, ScrollType);
312 293
313 void clearScrollAnimators(); 294 void clearScrollAnimators();
314 295
296 bool horizontalScrollbarNeedsPaintInvalidation() const { return m_horizontal ScrollbarNeedsPaintInvalidation; }
297 bool verticalScrollbarNeedsPaintInvalidation() const { return m_verticalScro llbarNeedsPaintInvalidation; }
298 bool scrollCornerNeedsPaintInvalidation() const { return m_scrollCornerNeeds PaintInvalidation; }
299 void clearNeedsPaintInvalidationForScrollControls()
300 {
301 m_horizontalScrollbarNeedsPaintInvalidation = false;
302 m_verticalScrollbarNeedsPaintInvalidation = false;
303 m_scrollCornerNeedsPaintInvalidation = false;
304 }
305
315 private: 306 private:
316 void programmaticScrollHelper(const DoublePoint&, ScrollBehavior); 307 void programmaticScrollHelper(const DoublePoint&, ScrollBehavior);
317 void userScrollHelper(const DoublePoint&, ScrollBehavior); 308 void userScrollHelper(const DoublePoint&, ScrollBehavior);
318 309
319 // This function should be overriden by subclasses to perform the actual 310 // This function should be overriden by subclasses to perform the actual
320 // scroll of the content. By default the DoublePoint version will just 311 // scroll of the content. By default the DoublePoint version will just
321 // call into the IntPoint version. If fractional scroll is needed, one 312 // call into the IntPoint version. If fractional scroll is needed, one
322 // can override the DoublePoint version to take advantage of the double 313 // can override the DoublePoint version to take advantage of the double
323 // precision scroll offset. 314 // precision scroll offset.
324 // FIXME: Remove the IntPoint version. And change the function to 315 // FIXME: Remove the IntPoint version. And change the function to
325 // take DoubleSize. crbug.com/414283. 316 // take DoubleSize. crbug.com/414283.
326 virtual void setScrollOffset(const IntPoint&, ScrollType) = 0; 317 virtual void setScrollOffset(const IntPoint&, ScrollType) = 0;
327 virtual void setScrollOffset(const DoublePoint& offset, ScrollType scrollTyp e) 318 virtual void setScrollOffset(const DoublePoint& offset, ScrollType scrollTyp e)
328 { 319 {
329 setScrollOffset(flooredIntPoint(offset), scrollType); 320 setScrollOffset(flooredIntPoint(offset), scrollType);
330 } 321 }
331 322
332 virtual int lineStep(ScrollbarOrientation) const; 323 virtual int lineStep(ScrollbarOrientation) const;
333 virtual int pageStep(ScrollbarOrientation) const; 324 virtual int pageStep(ScrollbarOrientation) const;
334 virtual int documentStep(ScrollbarOrientation) const; 325 virtual int documentStep(ScrollbarOrientation) const;
335 virtual float pixelStep(ScrollbarOrientation) const; 326 virtual float pixelStep(ScrollbarOrientation) const;
336 327
337 // Stores the paint invalidations for the scrollbars during layout.
338 IntRect m_horizontalBarDamage;
339 IntRect m_verticalBarDamage;
340
341 struct ScrollableAreaAnimators { 328 struct ScrollableAreaAnimators {
342 OwnPtr<ScrollAnimatorBase> scrollAnimator; 329 OwnPtr<ScrollAnimatorBase> scrollAnimator;
343 OwnPtr<ProgrammaticScrollAnimator> programmaticScrollAnimator; 330 OwnPtr<ProgrammaticScrollAnimator> programmaticScrollAnimator;
344 }; 331 };
345 332
346 mutable OwnPtr<ScrollableAreaAnimators> m_animators; 333 mutable OwnPtr<ScrollableAreaAnimators> m_animators;
347 334
348 unsigned m_inLiveResize : 1; 335 unsigned m_inLiveResize : 1;
349 336
350 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle 337 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle
351 338
352 unsigned m_scrollOriginChanged : 1; 339 unsigned m_scrollOriginChanged : 1;
353 340
341 unsigned m_horizontalScrollbarNeedsPaintInvalidation : 1;
342 unsigned m_verticalScrollbarNeedsPaintInvalidation : 1;
343 unsigned m_scrollCornerNeedsPaintInvalidation : 1;
344
354 // There are 8 possible combinations of writing mode and direction. Scroll o rigin will be non-zero in the x or y axis 345 // There are 8 possible combinations of writing mode and direction. Scroll o rigin will be non-zero in the x or y axis
355 // if there is any reversed direction or writing-mode. The combinations are: 346 // if there is any reversed direction or writing-mode. The combinations are:
356 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set 347 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set
357 // horizontal-tb / ltr NO NO 348 // horizontal-tb / ltr NO NO
358 // horizontal-tb / rtl YES NO 349 // horizontal-tb / rtl YES NO
359 // horizontal-bt / ltr NO YES 350 // horizontal-bt / ltr NO YES
360 // horizontal-bt / rtl YES YES 351 // horizontal-bt / rtl YES YES
361 // vertical-lr / ltr NO NO 352 // vertical-lr / ltr NO NO
362 // vertical-lr / rtl NO YES 353 // vertical-lr / rtl NO YES
363 // vertical-rl / ltr YES NO 354 // vertical-rl / ltr YES NO
364 // vertical-rl / rtl YES YES 355 // vertical-rl / rtl YES YES
365 IntPoint m_scrollOrigin; 356 IntPoint m_scrollOrigin;
366 }; 357 };
367 358
368 } // namespace blink 359 } // namespace blink
369 360
370 #endif // ScrollableArea_h 361 #endif // ScrollableArea_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698