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

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

Issue 134443003: Implement CSSOM Smooth Scroll API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years, 10 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 | Annotate | Revision Log
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 21 matching lines...) Expand all
32 #include "wtf/Noncopyable.h" 32 #include "wtf/Noncopyable.h"
33 #include "wtf/Vector.h" 33 #include "wtf/Vector.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 class FloatPoint; 37 class FloatPoint;
38 class GraphicsContext; 38 class GraphicsContext;
39 class GraphicsLayer; 39 class GraphicsLayer;
40 class PlatformGestureEvent; 40 class PlatformGestureEvent;
41 class PlatformWheelEvent; 41 class PlatformWheelEvent;
42 class ProgrammaticScrollAnimator;
42 class ScrollAnimator; 43 class ScrollAnimator;
43 44
44 enum ScrollBehavior { 45 enum ScrollBehavior {
45 ScrollBehaviorAuto, 46 ScrollBehaviorAuto,
46 ScrollBehaviorInstant, 47 ScrollBehaviorInstant,
47 ScrollBehaviorSmooth, 48 ScrollBehaviorSmooth,
48 }; 49 };
49 50
50 class PLATFORM_EXPORT ScrollableArea { 51 class PLATFORM_EXPORT ScrollableArea {
51 WTF_MAKE_NONCOPYABLE(ScrollableArea); 52 WTF_MAKE_NONCOPYABLE(ScrollableArea);
52 public: 53 public:
53 static int pixelsPerLineStep(); 54 static int pixelsPerLineStep();
54 static float minFractionToStepWhenPaging(); 55 static float minFractionToStepWhenPaging();
55 static int maxOverlapBetweenPages(); 56 static int maxOverlapBetweenPages();
56 57
57 bool scroll(ScrollDirection, ScrollGranularity, float delta = 1); 58 bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
58 void scrollToOffsetWithoutAnimation(const FloatPoint&); 59 void scrollToOffsetWithoutAnimation(const FloatPoint&);
59 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); 60 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
60 61
62 void programmaticallyScrollSmoothlyToOffset(const FloatPoint&);
63
61 // Should be called when the scroll position changes externally, for example if the scroll layer position 64 // Should be called when the scroll position changes externally, for example if the scroll layer position
62 // is updated on the scrolling thread and we need to notify the main thread. 65 // is updated on the scrolling thread and we need to notify the main thread.
63 void notifyScrollPositionChanged(const IntPoint&); 66 void notifyScrollPositionChanged(const IntPoint&);
64 67
65 static bool scrollBehaviorFromString(const String&, ScrollBehavior&); 68 static bool scrollBehaviorFromString(const String&, ScrollBehavior&);
66 69
67 bool handleWheelEvent(const PlatformWheelEvent&); 70 bool handleWheelEvent(const PlatformWheelEvent&);
68 71
69 // Functions for controlling if you can scroll past the end of the document. 72 // Functions for controlling if you can scroll past the end of the document.
70 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling ToContentEdge; } 73 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling ToContentEdge; }
(...skipping 28 matching lines...) Expand all
99 bool hasOverlayScrollbars() const; 102 bool hasOverlayScrollbars() const;
100 void setScrollbarOverlayStyle(ScrollbarOverlayStyle); 103 void setScrollbarOverlayStyle(ScrollbarOverlayStyle);
101 ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<Scr ollbarOverlayStyle>(m_scrollbarOverlayStyle); } 104 ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<Scr ollbarOverlayStyle>(m_scrollbarOverlayStyle); }
102 105
103 // This getter will create a ScrollAnimator if it doesn't already exist. 106 // This getter will create a ScrollAnimator if it doesn't already exist.
104 ScrollAnimator* scrollAnimator() const; 107 ScrollAnimator* scrollAnimator() const;
105 108
106 // This getter will return null if the ScrollAnimator hasn't been created ye t. 109 // This getter will return null if the ScrollAnimator hasn't been created ye t.
107 ScrollAnimator* existingScrollAnimator() const { return m_scrollAnimator.get (); } 110 ScrollAnimator* existingScrollAnimator() const { return m_scrollAnimator.get (); }
108 111
112 ProgrammaticScrollAnimator* programmaticScrollAnimator() const;
113 ProgrammaticScrollAnimator* existingProgrammaticScrollAnimator() const
114 {
115 return m_programmaticScrollAnimator.get();
116 }
117
109 const IntPoint& scrollOrigin() const { return m_scrollOrigin; } 118 const IntPoint& scrollOrigin() const { return m_scrollOrigin; }
110 bool scrollOriginChanged() const { return m_scrollOriginChanged; } 119 bool scrollOriginChanged() const { return m_scrollOriginChanged; }
111 120
112 virtual bool isActive() const = 0; 121 virtual bool isActive() const = 0;
113 virtual int scrollSize(ScrollbarOrientation) const = 0; 122 virtual int scrollSize(ScrollbarOrientation) const = 0;
114 virtual void invalidateScrollbar(Scrollbar*, const IntRect&); 123 virtual void invalidateScrollbar(Scrollbar*, const IntRect&);
115 virtual bool isScrollCornerVisible() const = 0; 124 virtual bool isScrollCornerVisible() const = 0;
116 virtual IntRect scrollCornerRect() const = 0; 125 virtual IntRect scrollCornerRect() const = 0;
117 virtual void invalidateScrollCorner(const IntRect&); 126 virtual void invalidateScrollCorner(const IntRect&);
118 virtual void getTickmarks(Vector<IntRect>&) const { } 127 virtual void getTickmarks(Vector<IntRect>&) const { }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 179
171 virtual bool scrollAnimatorEnabled() const { return false; } 180 virtual bool scrollAnimatorEnabled() const { return false; }
172 181
173 // NOTE: Only called from Internals for testing. 182 // NOTE: Only called from Internals for testing.
174 void setScrollOffsetFromInternals(const IntPoint&); 183 void setScrollOffsetFromInternals(const IntPoint&);
175 184
176 IntPoint clampScrollPosition(const IntPoint&) const; 185 IntPoint clampScrollPosition(const IntPoint&) const;
177 186
178 // Let subclasses provide a way of asking for and servicing scroll 187 // Let subclasses provide a way of asking for and servicing scroll
179 // animations. 188 // animations.
189 virtual bool registerForAnimation() { return false; }
190 virtual void deregisterForAnimation() { }
180 virtual bool scheduleAnimation() { return false; } 191 virtual bool scheduleAnimation() { return false; }
181 void serviceScrollAnimations(); 192 virtual void serviceScrollAnimations(double monotonicTime);
193
182 194
183 virtual bool usesCompositedScrolling() const { return false; } 195 virtual bool usesCompositedScrolling() const { return false; }
184 virtual void updateNeedsCompositedScrolling() { } 196 virtual void updateNeedsCompositedScrolling() { }
185 virtual void updateHasVisibleNonLayerContent() { } 197 virtual void updateHasVisibleNonLayerContent() { }
186 198
187 virtual bool userInputScrollable(ScrollbarOrientation) const = 0; 199 virtual bool userInputScrollable(ScrollbarOrientation) const = 0;
188 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0; 200 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0;
189 201
202 // Notifications for compositor-driven animations.
203 void notifyAnimationStarted(double monotonicTime);
204 void notifyAnimationFinished(double monotonicTime);
205
206 void layerForScrollingDidChange();
207 void requiresMainThreadScrollingDidChange();
208 bool canUseCompositedScrollAnimations() const;
209
190 // Convenience functions 210 // Convenience functions
191 int scrollPosition(ScrollbarOrientation orientation) { return orientation == HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); } 211 int scrollPosition(ScrollbarOrientation orientation) { return orientation == HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); }
192 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio n().y(); } 212 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio n().y(); }
193 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio n().y(); } 213 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio n().y(); }
194 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi on(orientation)); } 214 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi on(orientation)); }
195 215
196 bool hasVerticalBarDamage() const { return m_hasVerticalBarDamage; } 216 bool hasVerticalBarDamage() const { return m_hasVerticalBarDamage; }
197 bool hasHorizontalBarDamage() const { return m_hasHorizontalBarDamage; } 217 bool hasHorizontalBarDamage() const { return m_hasHorizontalBarDamage; }
198 218
199 const IntRect& verticalBarDamage() const 219 const IntRect& verticalBarDamage() const
(...skipping 18 matching lines...) Expand all
218 ScrollableArea(); 238 ScrollableArea();
219 virtual ~ScrollableArea(); 239 virtual ~ScrollableArea();
220 240
221 void setScrollOrigin(const IntPoint&); 241 void setScrollOrigin(const IntPoint&);
222 void resetScrollOriginChanged() { m_scrollOriginChanged = false; } 242 void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
223 243
224 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0; 244 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0;
225 virtual void invalidateScrollCornerRect(const IntRect&) = 0; 245 virtual void invalidateScrollCornerRect(const IntRect&) = 0;
226 246
227 friend class ScrollingCoordinator; 247 friend class ScrollingCoordinator;
248 friend class ProgrammaticScrollAnimator;
228 virtual GraphicsLayer* layerForScrolling() const { return 0; } 249 virtual GraphicsLayer* layerForScrolling() const { return 0; }
229 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; } 250 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; }
230 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; } 251 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; }
231 virtual GraphicsLayer* layerForScrollCorner() const { return 0; } 252 virtual GraphicsLayer* layerForScrollCorner() const { return 0; }
232 bool hasLayerForHorizontalScrollbar() const; 253 bool hasLayerForHorizontalScrollbar() const;
233 bool hasLayerForVerticalScrollbar() const; 254 bool hasLayerForVerticalScrollbar() const;
234 bool hasLayerForScrollCorner() const; 255 bool hasLayerForScrollCorner() const;
235 256
257 void cancelProgrammaticScrollAnimation();
258 virtual bool compositedScrollAnimationsEnabled() const { return false; }
259
236 // For repaint after layout, stores the damage to be repainted for the 260 // For repaint after layout, stores the damage to be repainted for the
237 // scrollbars. 261 // scrollbars.
238 unsigned m_hasHorizontalBarDamage : 1; 262 unsigned m_hasHorizontalBarDamage : 1;
239 unsigned m_hasVerticalBarDamage : 1; 263 unsigned m_hasVerticalBarDamage : 1;
240 IntRect m_horizontalBarDamage; 264 IntRect m_horizontalBarDamage;
241 IntRect m_verticalBarDamage; 265 IntRect m_verticalBarDamage;
242 266
243 private: 267 private:
244 void scrollPositionChanged(const IntPoint&); 268 void scrollPositionChanged(const IntPoint&);
245 269
246 // NOTE: Only called from the ScrollAnimator. 270 // NOTE: Only called from the ScrollAnimator.
247 friend class ScrollAnimator; 271 friend class ScrollAnimator;
248 void setScrollOffsetFromAnimation(const IntPoint&); 272 void setScrollOffsetFromAnimation(const IntPoint&);
249 273
274 // Only called from ProgrammaticScrollAnimator.
275 void setScrollOffsetFromProgrammaticAnimation(const IntPoint&);
276
250 // This function should be overriden by subclasses to perform the actual 277 // This function should be overriden by subclasses to perform the actual
251 // scroll of the content. 278 // scroll of the content.
252 virtual void setScrollOffset(const IntPoint&) = 0; 279 virtual void setScrollOffset(const IntPoint&) = 0;
253 280
254 virtual int lineStep(ScrollbarOrientation) const; 281 virtual int lineStep(ScrollbarOrientation) const;
255 virtual int pageStep(ScrollbarOrientation) const = 0; 282 virtual int pageStep(ScrollbarOrientation) const = 0;
256 virtual int documentStep(ScrollbarOrientation) const; 283 virtual int documentStep(ScrollbarOrientation) const;
257 virtual float pixelStep(ScrollbarOrientation) const; 284 virtual float pixelStep(ScrollbarOrientation) const;
258 285
259 mutable OwnPtr<ScrollAnimator> m_scrollAnimator; 286 mutable OwnPtr<ScrollAnimator> m_scrollAnimator;
287 mutable OwnPtr<ProgrammaticScrollAnimator> m_programmaticScrollAnimator;
260 unsigned m_constrainsScrollingToContentEdge : 1; 288 unsigned m_constrainsScrollingToContentEdge : 1;
261 289
262 unsigned m_inLiveResize : 1; 290 unsigned m_inLiveResize : 1;
263 291
264 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity 292 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
265 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity 293 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
266 294
267 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle 295 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle
268 296
269 unsigned m_scrollOriginChanged : 1; 297 unsigned m_scrollOriginChanged : 1;
270 298
271 // There are 8 possible combinations of writing mode and direction. Scroll o rigin will be non-zero in the x or y axis 299 // There are 8 possible combinations of writing mode and direction. Scroll o rigin will be non-zero in the x or y axis
272 // if there is any reversed direction or writing-mode. The combinations are: 300 // if there is any reversed direction or writing-mode. The combinations are:
273 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set 301 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set
274 // horizontal-tb / ltr NO NO 302 // horizontal-tb / ltr NO NO
275 // horizontal-tb / rtl YES NO 303 // horizontal-tb / rtl YES NO
276 // horizontal-bt / ltr NO YES 304 // horizontal-bt / ltr NO YES
277 // horizontal-bt / rtl YES YES 305 // horizontal-bt / rtl YES YES
278 // vertical-lr / ltr NO NO 306 // vertical-lr / ltr NO NO
279 // vertical-lr / rtl NO YES 307 // vertical-lr / rtl NO YES
280 // vertical-rl / ltr YES NO 308 // vertical-rl / ltr YES NO
281 // vertical-rl / rtl YES YES 309 // vertical-rl / rtl YES YES
282 IntPoint m_scrollOrigin; 310 IntPoint m_scrollOrigin;
283 }; 311 };
284 312
285 } // namespace WebCore 313 } // namespace WebCore
286 314
287 #endif // ScrollableArea_h 315 #endif // ScrollableArea_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698