OLD | NEW |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 static int pixelsPerLineStep(HostWindow*); | 65 static int pixelsPerLineStep(HostWindow*); |
66 static float minFractionToStepWhenPaging(); | 66 static float minFractionToStepWhenPaging(); |
67 static int maxOverlapBetweenPages(); | 67 static int maxOverlapBetweenPages(); |
68 | 68 |
69 // Convert a non-finite scroll value (Infinity, -Infinity, NaN) to 0 as | 69 // Convert a non-finite scroll value (Infinity, -Infinity, NaN) to 0 as |
70 // per http://dev.w3.org/csswg/cssom-view/#normalize-non_finite-values. | 70 // per http://dev.w3.org/csswg/cssom-view/#normalize-non_finite-values. |
71 static double normalizeNonFiniteScroll(double value) { | 71 static double normalizeNonFiniteScroll(double value) { |
72 return std::isfinite(value) ? value : 0.0; | 72 return std::isfinite(value) ? value : 0.0; |
73 } | 73 } |
74 | 74 |
75 // The window that hosts the ScrollableArea. The ScrollableArea will communica
te scrolls and repaints to the | 75 // The window that hosts the ScrollableArea. The ScrollableArea will |
76 // host window in the window's coordinate space. | 76 // communicate scrolls and repaints to the host window in the window's |
| 77 // coordinate space. |
77 virtual HostWindow* getHostWindow() const { return 0; } | 78 virtual HostWindow* getHostWindow() const { return 0; } |
78 | 79 |
79 virtual ScrollResult userScroll(ScrollGranularity, const FloatSize&); | 80 virtual ScrollResult userScroll(ScrollGranularity, const FloatSize&); |
80 | 81 |
81 virtual void setScrollPosition(const DoublePoint&, | 82 virtual void setScrollPosition(const DoublePoint&, |
82 ScrollType, | 83 ScrollType, |
83 ScrollBehavior = ScrollBehaviorInstant); | 84 ScrollBehavior = ScrollBehaviorInstant); |
84 virtual void scrollBy(const DoubleSize&, | 85 virtual void scrollBy(const DoubleSize&, |
85 ScrollType, | 86 ScrollType, |
86 ScrollBehavior = ScrollBehaviorInstant); | 87 ScrollBehavior = ScrollBehaviorInstant); |
87 void setScrollPositionSingleAxis(ScrollbarOrientation, | 88 void setScrollPositionSingleAxis(ScrollbarOrientation, |
88 double, | 89 double, |
89 ScrollType, | 90 ScrollType, |
90 ScrollBehavior = ScrollBehaviorInstant); | 91 ScrollBehavior = ScrollBehaviorInstant); |
91 | 92 |
92 // Scrolls the area so that the given rect, given in the document's content co
ordinates, such that it's | 93 // Scrolls the area so that the given rect, given in the document's content |
93 // visible in the area. Returns the new location of the input rect relative on
ce again to the document. | 94 // coordinates, such that it's visible in the area. Returns the new location |
94 // Note, in the case of a Document container, such as FrameView, the output wi
ll always be the input rect | 95 // of the input rect relative once again to the document. |
95 // since scrolling it can't change the location of content relative to the doc
ument, unlike an overflowing | 96 // Note, in the case of a Document container, such as FrameView, the output |
96 // element. | 97 // will always be the input rect since scrolling it can't change the location |
| 98 // of content relative to the document, unlike an overflowing element. |
97 virtual LayoutRect scrollIntoView(const LayoutRect& rectInContent, | 99 virtual LayoutRect scrollIntoView(const LayoutRect& rectInContent, |
98 const ScrollAlignment& alignX, | 100 const ScrollAlignment& alignX, |
99 const ScrollAlignment& alignY, | 101 const ScrollAlignment& alignY, |
100 ScrollType = ProgrammaticScroll); | 102 ScrollType = ProgrammaticScroll); |
101 | 103 |
102 // Returns a rect, in the space of the area's backing graphics layer, that con
tains the visual | 104 // Returns a rect, in the space of the area's backing graphics layer, that |
103 // region of all scrollbar parts. | 105 // contains the visual region of all scrollbar parts. |
104 virtual LayoutRect visualRectForScrollbarParts() const = 0; | 106 virtual LayoutRect visualRectForScrollbarParts() const = 0; |
105 | 107 |
106 static bool scrollBehaviorFromString(const String&, ScrollBehavior&); | 108 static bool scrollBehaviorFromString(const String&, ScrollBehavior&); |
107 | 109 |
108 void contentAreaWillPaint() const; | 110 void contentAreaWillPaint() const; |
109 void mouseEnteredContentArea() const; | 111 void mouseEnteredContentArea() const; |
110 void mouseExitedContentArea() const; | 112 void mouseExitedContentArea() const; |
111 void mouseMovedInContentArea() const; | 113 void mouseMovedInContentArea() const; |
112 void mouseEnteredScrollbar(Scrollbar&) const; | 114 void mouseEnteredScrollbar(Scrollbar&) const; |
113 void mouseExitedScrollbar(Scrollbar&) const; | 115 void mouseExitedScrollbar(Scrollbar&) const; |
(...skipping 10 matching lines...) Expand all Loading... |
124 bool hasOverlayScrollbars() const; | 126 bool hasOverlayScrollbars() const; |
125 void setScrollbarOverlayStyle(ScrollbarOverlayStyle); | 127 void setScrollbarOverlayStyle(ScrollbarOverlayStyle); |
126 void recalculateScrollbarOverlayStyle(Color); | 128 void recalculateScrollbarOverlayStyle(Color); |
127 ScrollbarOverlayStyle getScrollbarOverlayStyle() const { | 129 ScrollbarOverlayStyle getScrollbarOverlayStyle() const { |
128 return static_cast<ScrollbarOverlayStyle>(m_scrollbarOverlayStyle); | 130 return static_cast<ScrollbarOverlayStyle>(m_scrollbarOverlayStyle); |
129 } | 131 } |
130 | 132 |
131 // This getter will create a ScrollAnimatorBase if it doesn't already exist. | 133 // This getter will create a ScrollAnimatorBase if it doesn't already exist. |
132 ScrollAnimatorBase& scrollAnimator() const; | 134 ScrollAnimatorBase& scrollAnimator() const; |
133 | 135 |
134 // This getter will return null if the ScrollAnimatorBase hasn't been created
yet. | 136 // This getter will return null if the ScrollAnimatorBase hasn't been created |
| 137 // yet. |
135 ScrollAnimatorBase* existingScrollAnimator() const { | 138 ScrollAnimatorBase* existingScrollAnimator() const { |
136 return m_scrollAnimator; | 139 return m_scrollAnimator; |
137 } | 140 } |
138 | 141 |
139 ProgrammaticScrollAnimator& programmaticScrollAnimator() const; | 142 ProgrammaticScrollAnimator& programmaticScrollAnimator() const; |
140 ProgrammaticScrollAnimator* existingProgrammaticScrollAnimator() const { | 143 ProgrammaticScrollAnimator* existingProgrammaticScrollAnimator() const { |
141 return m_programmaticScrollAnimator; | 144 return m_programmaticScrollAnimator; |
142 } | 145 } |
143 | 146 |
144 virtual CompositorAnimationTimeline* compositorAnimationTimeline() const { | 147 virtual CompositorAnimationTimeline* compositorAnimationTimeline() const { |
145 return nullptr; | 148 return nullptr; |
146 } | 149 } |
147 | 150 |
148 // See Source/core/layout/README.md for an explanation of scroll origin. | 151 // See Source/core/layout/README.md for an explanation of scroll origin. |
149 const IntPoint& scrollOrigin() const { return m_scrollOrigin; } | 152 const IntPoint& scrollOrigin() const { return m_scrollOrigin; } |
150 bool scrollOriginChanged() const { return m_scrollOriginChanged; } | 153 bool scrollOriginChanged() const { return m_scrollOriginChanged; } |
151 | 154 |
152 // This is used to determine whether the incoming fractional scroll offset sho
uld | 155 // This is used to determine whether the incoming fractional scroll offset |
153 // be truncated to integer. Current rule is that if preferCompositingToLCDText
Enabled() | 156 // should be truncated to integer. Current rule is that if |
154 // is disabled (which is true on low-dpi device by default) we should do the t
runcation. | 157 // preferCompositingToLCDTextEnabled() is disabled (which is true on low-dpi |
155 // The justification is that non-composited elements using fractional scroll o
ffsets | 158 // device by default) we should do the truncation. The justification is that |
156 // is causing too much nasty bugs but does not add too benefit on low-dpi devi
ces. | 159 // non-composited elements using fractional scroll offsets is causing too much |
| 160 // nasty bugs but does not add too benefit on low-dpi devices. |
157 virtual bool shouldUseIntegerScrollOffset() const { | 161 virtual bool shouldUseIntegerScrollOffset() const { |
158 return !RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); | 162 return !RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); |
159 } | 163 } |
160 | 164 |
161 virtual bool isActive() const = 0; | 165 virtual bool isActive() const = 0; |
162 virtual int scrollSize(ScrollbarOrientation) const = 0; | 166 virtual int scrollSize(ScrollbarOrientation) const = 0; |
163 void setScrollbarNeedsPaintInvalidation(ScrollbarOrientation); | 167 void setScrollbarNeedsPaintInvalidation(ScrollbarOrientation); |
164 virtual bool isScrollCornerVisible() const = 0; | 168 virtual bool isScrollCornerVisible() const = 0; |
165 virtual IntRect scrollCornerRect() const = 0; | 169 virtual IntRect scrollCornerRect() const = 0; |
166 void setScrollCornerNeedsPaintInvalidation(); | 170 void setScrollCornerNeedsPaintInvalidation(); |
(...skipping 21 matching lines...) Expand all Loading... |
188 const Scrollbar& scrollbar, | 192 const Scrollbar& scrollbar, |
189 const IntPoint& parentPoint) const { | 193 const IntPoint& parentPoint) const { |
190 return scrollbar.Widget::convertFromContainingWidget(parentPoint); | 194 return scrollbar.Widget::convertFromContainingWidget(parentPoint); |
191 } | 195 } |
192 | 196 |
193 virtual Scrollbar* horizontalScrollbar() const { return nullptr; } | 197 virtual Scrollbar* horizontalScrollbar() const { return nullptr; } |
194 virtual Scrollbar* verticalScrollbar() const { return nullptr; } | 198 virtual Scrollbar* verticalScrollbar() const { return nullptr; } |
195 | 199 |
196 // scrollPosition is relative to the scrollOrigin. i.e. If the page is RTL | 200 // scrollPosition is relative to the scrollOrigin. i.e. If the page is RTL |
197 // then scrollPosition will be negative. By default, scrollPositionDouble() | 201 // then scrollPosition will be negative. By default, scrollPositionDouble() |
198 // just call into scrollPosition(). Subclass can override scrollPositionDouble
() | 202 // just call into scrollPosition(). Subclass can override |
199 // to return floating point precision scrolloffset. | 203 // scrollPositionDouble() to return floating point precision scrolloffset. |
200 // FIXME: Remove scrollPosition(). crbug.com/414283. | 204 // FIXME: Remove scrollPosition(). crbug.com/414283. |
201 virtual IntPoint scrollPosition() const = 0; | 205 virtual IntPoint scrollPosition() const = 0; |
202 virtual DoublePoint scrollPositionDouble() const { | 206 virtual DoublePoint scrollPositionDouble() const { |
203 return DoublePoint(scrollPosition()); | 207 return DoublePoint(scrollPosition()); |
204 } | 208 } |
205 virtual IntPoint minimumScrollPosition() const = 0; | 209 virtual IntPoint minimumScrollPosition() const = 0; |
206 virtual DoublePoint minimumScrollPositionDouble() const { | 210 virtual DoublePoint minimumScrollPositionDouble() const { |
207 return DoublePoint(minimumScrollPosition()); | 211 return DoublePoint(minimumScrollPosition()); |
208 } | 212 } |
209 virtual IntPoint maximumScrollPosition() const = 0; | 213 virtual IntPoint maximumScrollPosition() const = 0; |
210 virtual DoublePoint maximumScrollPositionDouble() const { | 214 virtual DoublePoint maximumScrollPositionDouble() const { |
211 return DoublePoint(maximumScrollPosition()); | 215 return DoublePoint(maximumScrollPosition()); |
212 } | 216 } |
213 | 217 |
214 virtual DoubleRect visibleContentRectDouble( | 218 virtual DoubleRect visibleContentRectDouble( |
215 IncludeScrollbarsInRect = ExcludeScrollbars) const; | 219 IncludeScrollbarsInRect = ExcludeScrollbars) const; |
216 virtual IntRect visibleContentRect( | 220 virtual IntRect visibleContentRect( |
217 IncludeScrollbarsInRect = ExcludeScrollbars) const; | 221 IncludeScrollbarsInRect = ExcludeScrollbars) const; |
218 virtual int visibleHeight() const { return visibleContentRect().height(); } | 222 virtual int visibleHeight() const { return visibleContentRect().height(); } |
219 virtual int visibleWidth() const { return visibleContentRect().width(); } | 223 virtual int visibleWidth() const { return visibleContentRect().width(); } |
220 virtual IntSize contentsSize() const = 0; | 224 virtual IntSize contentsSize() const = 0; |
221 virtual IntPoint lastKnownMousePosition() const { return IntPoint(); } | 225 virtual IntPoint lastKnownMousePosition() const { return IntPoint(); } |
222 | 226 |
223 virtual bool shouldSuspendScrollAnimations() const { return true; } | 227 virtual bool shouldSuspendScrollAnimations() const { return true; } |
224 virtual void scrollbarStyleChanged() {} | 228 virtual void scrollbarStyleChanged() {} |
225 virtual void scrollbarVisibilityChanged() {} | 229 virtual void scrollbarVisibilityChanged() {} |
226 virtual bool scrollbarsCanBeActive() const = 0; | 230 virtual bool scrollbarsCanBeActive() const = 0; |
227 | 231 |
228 // Returns the bounding box of this scrollable area, in the coordinate system
of the enclosing scroll view. | 232 // Returns the bounding box of this scrollable area, in the coordinate system |
| 233 // of the enclosing scroll view. |
229 virtual IntRect scrollableAreaBoundingBox() const = 0; | 234 virtual IntRect scrollableAreaBoundingBox() const = 0; |
230 | 235 |
231 virtual bool scrollAnimatorEnabled() const { return false; } | 236 virtual bool scrollAnimatorEnabled() const { return false; } |
232 | 237 |
233 // NOTE: Only called from Internals for testing. | 238 // NOTE: Only called from Internals for testing. |
234 void setScrollOffsetFromInternals(const IntPoint&); | 239 void setScrollOffsetFromInternals(const IntPoint&); |
235 | 240 |
236 IntPoint clampScrollPosition(const IntPoint&) const; | 241 IntPoint clampScrollPosition(const IntPoint&) const; |
237 DoublePoint clampScrollPosition(const DoublePoint&) const; | 242 DoublePoint clampScrollPosition(const DoublePoint&) const; |
238 | 243 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 bool hasLayerForVerticalScrollbar() const; | 285 bool hasLayerForVerticalScrollbar() const; |
281 bool hasLayerForScrollCorner() const; | 286 bool hasLayerForScrollCorner() const; |
282 | 287 |
283 void layerForScrollingDidChange(CompositorAnimationTimeline*); | 288 void layerForScrollingDidChange(CompositorAnimationTimeline*); |
284 | 289 |
285 void cancelScrollAnimation(); | 290 void cancelScrollAnimation(); |
286 virtual void cancelProgrammaticScrollAnimation(); | 291 virtual void cancelProgrammaticScrollAnimation(); |
287 | 292 |
288 virtual ~ScrollableArea(); | 293 virtual ~ScrollableArea(); |
289 | 294 |
290 // Called when any of horizontal scrollbar, vertical scrollbar and scroll corn
er is setNeedsPaintInvalidation. | 295 // Called when any of horizontal scrollbar, vertical scrollbar and scroll |
| 296 // corner is setNeedsPaintInvalidation. |
291 virtual void scrollControlWasSetNeedsPaintInvalidation() = 0; | 297 virtual void scrollControlWasSetNeedsPaintInvalidation() = 0; |
292 | 298 |
293 // Returns the default scroll style this area should scroll with when not | 299 // Returns the default scroll style this area should scroll with when not |
294 // explicitly specified. E.g. The scrolling behavior of an element can be | 300 // explicitly specified. E.g. The scrolling behavior of an element can be |
295 // specified in CSS. | 301 // specified in CSS. |
296 virtual ScrollBehavior scrollBehaviorStyle() const { | 302 virtual ScrollBehavior scrollBehaviorStyle() const { |
297 return ScrollBehaviorInstant; | 303 return ScrollBehaviorInstant; |
298 } | 304 } |
299 | 305 |
300 // TODO(bokan): This is only used in FrameView to check scrollability but is | 306 // TODO(bokan): This is only used in FrameView to check scrollability but is |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 void clearNeedsPaintInvalidationForScrollControls() { | 371 void clearNeedsPaintInvalidationForScrollControls() { |
366 m_horizontalScrollbarNeedsPaintInvalidation = false; | 372 m_horizontalScrollbarNeedsPaintInvalidation = false; |
367 m_verticalScrollbarNeedsPaintInvalidation = false; | 373 m_verticalScrollbarNeedsPaintInvalidation = false; |
368 m_scrollCornerNeedsPaintInvalidation = false; | 374 m_scrollCornerNeedsPaintInvalidation = false; |
369 } | 375 } |
370 | 376 |
371 private: | 377 private: |
372 void programmaticScrollHelper(const DoublePoint&, ScrollBehavior); | 378 void programmaticScrollHelper(const DoublePoint&, ScrollBehavior); |
373 void userScrollHelper(const DoublePoint&, ScrollBehavior); | 379 void userScrollHelper(const DoublePoint&, ScrollBehavior); |
374 | 380 |
375 // This function should be overriden by subclasses to perform the actual scrol
l of the content. | 381 // This function should be overriden by subclasses to perform the actual |
| 382 // scroll of the content. |
376 virtual void setScrollOffset(const DoublePoint& offset, ScrollType) = 0; | 383 virtual void setScrollOffset(const DoublePoint& offset, ScrollType) = 0; |
377 | 384 |
378 virtual int lineStep(ScrollbarOrientation) const; | 385 virtual int lineStep(ScrollbarOrientation) const; |
379 virtual int pageStep(ScrollbarOrientation) const; | 386 virtual int pageStep(ScrollbarOrientation) const; |
380 virtual int documentStep(ScrollbarOrientation) const; | 387 virtual int documentStep(ScrollbarOrientation) const; |
381 virtual float pixelStep(ScrollbarOrientation) const; | 388 virtual float pixelStep(ScrollbarOrientation) const; |
382 | 389 |
383 mutable Member<ScrollAnimatorBase> m_scrollAnimator; | 390 mutable Member<ScrollAnimatorBase> m_scrollAnimator; |
384 mutable Member<ProgrammaticScrollAnimator> m_programmaticScrollAnimator; | 391 mutable Member<ProgrammaticScrollAnimator> m_programmaticScrollAnimator; |
385 | 392 |
386 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle | 393 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle |
387 | 394 |
388 unsigned m_scrollOriginChanged : 1; | 395 unsigned m_scrollOriginChanged : 1; |
389 | 396 |
390 unsigned m_horizontalScrollbarNeedsPaintInvalidation : 1; | 397 unsigned m_horizontalScrollbarNeedsPaintInvalidation : 1; |
391 unsigned m_verticalScrollbarNeedsPaintInvalidation : 1; | 398 unsigned m_verticalScrollbarNeedsPaintInvalidation : 1; |
392 unsigned m_scrollCornerNeedsPaintInvalidation : 1; | 399 unsigned m_scrollCornerNeedsPaintInvalidation : 1; |
393 | 400 |
394 // There are 6 possible combinations of writing mode and direction. Scroll ori
gin will be non-zero in the x or y axis | 401 // There are 6 possible combinations of writing mode and direction. Scroll |
395 // if there is any reversed direction or writing-mode. The combinations are: | 402 // origin will be non-zero in the x or y axis if there is any reversed |
| 403 // direction or writing-mode. The combinations are: |
396 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set | 404 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set |
397 // horizontal-tb / ltr NO NO | 405 // horizontal-tb / ltr NO NO |
398 // horizontal-tb / rtl YES NO | 406 // horizontal-tb / rtl YES NO |
399 // vertical-lr / ltr NO NO | 407 // vertical-lr / ltr NO NO |
400 // vertical-lr / rtl NO YES | 408 // vertical-lr / rtl NO YES |
401 // vertical-rl / ltr YES NO | 409 // vertical-rl / ltr YES NO |
402 // vertical-rl / rtl YES YES | 410 // vertical-rl / rtl YES YES |
403 IntPoint m_scrollOrigin; | 411 IntPoint m_scrollOrigin; |
404 }; | 412 }; |
405 | 413 |
406 } // namespace blink | 414 } // namespace blink |
407 | 415 |
408 #endif // ScrollableArea_h | 416 #endif // ScrollableArea_h |
OLD | NEW |