hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 1 | /* |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 26 | #ifndef ScrollableArea_h |
| 27 | #define ScrollableArea_h |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 28 | |
hyatt@apple.com | 0819bcc | 2009-07-02 17:51:50 +0000 | [diff] [blame] | 29 | #include "Scrollbar.h" |
eric@webkit.org | e5cf2da | 2008-12-05 22:10:27 +0000 | [diff] [blame] | 30 | #include <wtf/Vector.h> |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 31 | |
| 32 | namespace WebCore { |
| 33 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 34 | class FloatPoint; |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 35 | class GraphicsContext; |
bdakin@apple.com | b38a635 | 2011-02-10 00:28:50 +0000 | [diff] [blame] | 36 | class PlatformGestureEvent; |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 37 | class PlatformWheelEvent; |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 38 | class ScrollAnimator; |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 39 | #if USE(ACCELERATED_COMPOSITING) |
| 40 | class GraphicsLayer; |
| 41 | #endif |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 42 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 43 | class ScrollableArea { |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 44 | public: |
wjmaclean@chromium.org | aa873b1 | 2011-10-10 00:21:51 +0000 | [diff] [blame] | 45 | enum ZoomAnimationState { ZoomAnimationContinuing, ZoomAnimationFinishing }; |
| 46 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 47 | bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1); |
| 48 | void scrollToOffsetWithoutAnimation(const FloatPoint&); |
| 49 | void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 50 | |
andersca@apple.com | 42c0c3e | 2012-02-11 02:03:27 +0000 | [diff] [blame] | 51 | // Should be called when the scroll position changes externally, for example if the scroll layer position |
| 52 | // is updated on the scrolling thread and we need to notify the main thread. |
| 53 | void notifyScrollPositionChanged(const IntPoint&); |
| 54 | |
andersca@apple.com | 46fff0d | 2012-02-11 02:33:17 +0000 | [diff] [blame^] | 55 | // Allows subclasses to handle scroll position updates themselves. If this member function |
| 56 | // returns true, the scrollable area won't actually update the scroll position and instead |
| 57 | // expect it to happen sometime in the future. |
| 58 | virtual bool requestScrollPositionUpdate(const IntPoint&) { return false; } |
| 59 | |
wjmaclean@chromium.org | 9a21566 | 2011-10-11 22:43:53 +0000 | [diff] [blame] | 60 | virtual void zoomAnimatorTransformChanged(float, float, float, ZoomAnimationState); |
wjmaclean@chromium.org | aa873b1 | 2011-10-10 00:21:51 +0000 | [diff] [blame] | 61 | |
andersca@apple.com | 741fa5d | 2011-10-04 20:44:05 +0000 | [diff] [blame] | 62 | bool handleWheelEvent(const PlatformWheelEvent&); |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 63 | #if ENABLE(GESTURE_EVENTS) |
| 64 | void handleGestureEvent(const PlatformGestureEvent&); |
| 65 | #endif |
| 66 | |
| 67 | // Functions for controlling if you can scroll past the end of the document. |
| 68 | bool constrainsScrollingToContentEdge() const { return m_constrainsScrollingToContentEdge; } |
| 69 | void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEdge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; } |
weinig@apple.com | 10187a9 | 2011-01-27 05:12:24 +0000 | [diff] [blame] | 70 | |
weinig@apple.com | 0fcf06e | 2011-04-13 00:20:11 +0000 | [diff] [blame] | 71 | void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_verticalScrollElasticity = scrollElasticity; } |
andreas.kling@nokia.com | d5015fc | 2011-10-10 14:51:44 +0000 | [diff] [blame] | 72 | ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); } |
weinig@apple.com | 0fcf06e | 2011-04-13 00:20:11 +0000 | [diff] [blame] | 73 | |
| 74 | void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_horizontalScrollElasticity = scrollElasticity; } |
andreas.kling@nokia.com | d5015fc | 2011-10-10 14:51:44 +0000 | [diff] [blame] | 75 | ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); } |
weinig@apple.com | 0fcf06e | 2011-04-13 00:20:11 +0000 | [diff] [blame] | 76 | |
weinig@apple.com | 3021524 | 2011-02-03 18:13:32 +0000 | [diff] [blame] | 77 | bool inLiveResize() const { return m_inLiveResize; } |
| 78 | void willStartLiveResize(); |
| 79 | void willEndLiveResize(); |
| 80 | |
andersca@apple.com | 72c2728 | 2011-12-20 21:21:33 +0000 | [diff] [blame] | 81 | void contentAreaWillPaint() const; |
| 82 | void mouseEnteredContentArea() const; |
| 83 | void mouseExitedContentArea() const; |
| 84 | void mouseMovedInContentArea() const; |
| 85 | void mouseEnteredScrollbar(Scrollbar*) const; |
| 86 | void mouseExitedScrollbar(Scrollbar*) const; |
| 87 | void contentAreaDidShow() const; |
| 88 | void contentAreaDidHide() const; |
| 89 | |
weinig@apple.com | f17b93c | 2011-02-07 21:29:12 +0000 | [diff] [blame] | 90 | void didAddVerticalScrollbar(Scrollbar*); |
| 91 | void willRemoveVerticalScrollbar(Scrollbar*); |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 92 | virtual void didAddHorizontalScrollbar(Scrollbar*); |
| 93 | virtual void willRemoveHorizontalScrollbar(Scrollbar*); |
weinig@apple.com | f17b93c | 2011-02-07 21:29:12 +0000 | [diff] [blame] | 94 | |
andersca@apple.com | ea30ccc | 2011-12-20 23:58:30 +0000 | [diff] [blame] | 95 | virtual void contentsResized(); |
| 96 | |
bdakin@apple.com | 1592fa2 | 2011-02-22 22:28:52 +0000 | [diff] [blame] | 97 | bool hasOverlayScrollbars() const; |
commit-queue@webkit.org | b31092d | 2011-07-21 01:32:17 +0000 | [diff] [blame] | 98 | virtual void setScrollbarOverlayStyle(ScrollbarOverlayStyle); |
andreas.kling@nokia.com | d5015fc | 2011-10-10 14:51:44 +0000 | [diff] [blame] | 99 | ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<ScrollbarOverlayStyle>(m_scrollbarOverlayStyle); } |
bdakin@apple.com | 1592fa2 | 2011-02-22 22:28:52 +0000 | [diff] [blame] | 100 | |
simon.fraser@apple.com | 296f65d | 2011-05-06 17:12:48 +0000 | [diff] [blame] | 101 | ScrollAnimator* scrollAnimator() const; |
weinig@apple.com | 8c01924 | 2011-03-10 21:43:37 +0000 | [diff] [blame] | 102 | const IntPoint& scrollOrigin() const { return m_scrollOrigin; } |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 103 | bool scrollOriginChanged() const { return m_scrollOriginChanged; } |
weinig@apple.com | 3021524 | 2011-02-03 18:13:32 +0000 | [diff] [blame] | 104 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 105 | virtual bool isActive() const = 0; |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 106 | virtual int scrollSize(ScrollbarOrientation) const = 0; |
| 107 | virtual int scrollPosition(Scrollbar*) const = 0; |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 108 | void invalidateScrollbar(Scrollbar*, const IntRect&); |
| 109 | virtual bool isScrollCornerVisible() const = 0; |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 110 | virtual IntRect scrollCornerRect() const = 0; |
simon.fraser@apple.com | c8bf639 | 2011-09-27 19:00:56 +0000 | [diff] [blame] | 111 | void invalidateScrollCorner(const IntRect&); |
eric@webkit.org | e5cf2da | 2008-12-05 22:10:27 +0000 | [diff] [blame] | 112 | virtual void getTickmarks(Vector<IntRect>&) const { } |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 113 | |
| 114 | // Convert points and rects between the scrollbar and its containing view. |
| 115 | // The client needs to implement these in order to be aware of layout effects |
| 116 | // like CSS transforms. |
| 117 | virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& scrollbarRect) const |
| 118 | { |
| 119 | return scrollbar->Widget::convertToContainingView(scrollbarRect); |
| 120 | } |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 121 | virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const |
| 122 | { |
| 123 | return scrollbar->Widget::convertFromContainingView(parentRect); |
| 124 | } |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 125 | virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const |
| 126 | { |
| 127 | return scrollbar->Widget::convertToContainingView(scrollbarPoint); |
| 128 | } |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 129 | virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const |
| 130 | { |
| 131 | return scrollbar->Widget::convertFromContainingView(parentPoint); |
| 132 | } |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 133 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 134 | virtual Scrollbar* horizontalScrollbar() const { return 0; } |
| 135 | virtual Scrollbar* verticalScrollbar() const { return 0; } |
| 136 | |
weinig@apple.com | 10187a9 | 2011-01-27 05:12:24 +0000 | [diff] [blame] | 137 | virtual IntPoint scrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); } |
| 138 | virtual IntPoint minimumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); } |
| 139 | virtual IntPoint maximumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); } |
simon.fraser@apple.com | 1003951 | 2011-05-11 20:55:03 +0000 | [diff] [blame] | 140 | virtual IntRect visibleContentRect(bool /*includeScrollbars*/ = false) const { ASSERT_NOT_REACHED(); return IntRect(); } |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 141 | virtual int visibleHeight() const { ASSERT_NOT_REACHED(); return 0; } |
| 142 | virtual int visibleWidth() const { ASSERT_NOT_REACHED(); return 0; } |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 143 | virtual IntSize contentsSize() const { ASSERT_NOT_REACHED(); return IntSize(); } |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 144 | virtual IntSize overhangAmount() const { ASSERT_NOT_REACHED(); return IntSize(); } |
bdakin@apple.com | 3216752 | 2011-02-01 20:35:25 +0000 | [diff] [blame] | 145 | virtual IntPoint currentMousePosition() const { return IntPoint(); } |
weinig@apple.com | a1255ce | 2011-06-04 19:20:00 +0000 | [diff] [blame] | 146 | |
bdakin@apple.com | e0a38ad | 2011-03-15 18:30:41 +0000 | [diff] [blame] | 147 | virtual bool shouldSuspendScrollAnimations() const { return true; } |
bdakin@apple.com | 83c96f4 | 2011-11-28 23:06:56 +0000 | [diff] [blame] | 148 | virtual void scrollbarStyleChanged(int /*newStyle*/, bool /*forceUpdate*/) { } |
bdakin@apple.com | 59845aa | 2011-04-21 22:49:53 +0000 | [diff] [blame] | 149 | virtual void setVisibleScrollerThumbRect(const IntRect&) { } |
bdakin@apple.com | 8a57afc | 2011-06-15 23:13:23 +0000 | [diff] [blame] | 150 | |
| 151 | virtual bool isOnActivePage() const { ASSERT_NOT_REACHED(); return true; } |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 152 | |
andersca@apple.com | 1bb03f3 | 2011-06-30 19:40:43 +0000 | [diff] [blame] | 153 | // Note that this only returns scrollable areas that can actually be scrolled. |
| 154 | virtual ScrollableArea* enclosingScrollableArea() const = 0; |
| 155 | |
andersca@apple.com | 6c3da66 | 2012-02-07 23:47:59 +0000 | [diff] [blame] | 156 | // Returns the bounding box of this scrollable area, in the coordinate system of the enclosing scroll view. |
andersca@apple.com | e1df2ad | 2012-02-08 00:17:42 +0000 | [diff] [blame] | 157 | virtual IntRect scrollableAreaBoundingBox() const { ASSERT_NOT_REACHED(); return IntRect(); } |
andersca@apple.com | 6c3da66 | 2012-02-07 23:47:59 +0000 | [diff] [blame] | 158 | |
jonlee@apple.com | 8d90918 | 2011-05-16 17:25:02 +0000 | [diff] [blame] | 159 | virtual bool shouldRubberBandInDirection(ScrollDirection) const { return true; } |
bdakin@apple.com | 3216752 | 2011-02-01 20:35:25 +0000 | [diff] [blame] | 160 | |
commit-queue@webkit.org | 33d35e7 | 2011-06-20 23:16:24 +0000 | [diff] [blame] | 161 | virtual bool scrollAnimatorEnabled() const { return false; } |
| 162 | |
commit-queue@webkit.org | a6e510e | 2011-09-07 20:13:34 +0000 | [diff] [blame] | 163 | // NOTE: Only called from Internals for testing. |
| 164 | void setScrollOffsetFromInternals(const IntPoint&); |
| 165 | |
weinig@apple.com | 8c01924 | 2011-03-10 21:43:37 +0000 | [diff] [blame] | 166 | protected: |
andersca@apple.com | 77cb9c2 | 2011-12-21 19:41:12 +0000 | [diff] [blame] | 167 | ScrollableArea(); |
andersca@apple.com | d604d21 | 2011-12-20 20:33:38 +0000 | [diff] [blame] | 168 | virtual ~ScrollableArea(); |
| 169 | |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 170 | void setScrollOrigin(const IntPoint&); |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 171 | void resetScrollOriginChanged() { m_scrollOriginChanged = false; } |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 172 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 173 | virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0; |
| 174 | virtual void invalidateScrollCornerRect(const IntRect&) = 0; |
| 175 | |
| 176 | #if USE(ACCELERATED_COMPOSITING) |
| 177 | virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; } |
| 178 | virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; } |
| 179 | virtual GraphicsLayer* layerForScrollCorner() const { return 0; } |
andersca@apple.com | 134cfff | 2012-01-13 00:30:55 +0000 | [diff] [blame] | 180 | #if ENABLE(RUBBER_BANDING) |
commit-queue@webkit.org | 0a4465d | 2011-09-15 04:06:49 +0000 | [diff] [blame] | 181 | virtual GraphicsLayer* layerForOverhangAreas() const { return 0; } |
| 182 | #endif |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 183 | #endif |
simon.fraser@apple.com | 856ca86 | 2011-04-24 05:53:06 +0000 | [diff] [blame] | 184 | bool hasLayerForHorizontalScrollbar() const; |
| 185 | bool hasLayerForVerticalScrollbar() const; |
| 186 | bool hasLayerForScrollCorner() const; |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 187 | |
andreas.kling@nokia.com | d5015fc | 2011-10-10 14:51:44 +0000 | [diff] [blame] | 188 | private: |
| 189 | // NOTE: Only called from the ScrollAnimator. |
| 190 | friend class ScrollAnimator; |
| 191 | void setScrollOffsetFromAnimation(const IntPoint&); |
| 192 | |
andersca@apple.com | 37eadc0 | 2012-02-10 22:01:16 +0000 | [diff] [blame] | 193 | // This function should be overriden by subclasses to perform the actual |
| 194 | // scroll of the content. |
| 195 | virtual void setScrollOffset(const IntPoint&) = 0; |
| 196 | |
andreas.kling@nokia.com | d5015fc | 2011-10-10 14:51:44 +0000 | [diff] [blame] | 197 | mutable OwnPtr<ScrollAnimator> m_scrollAnimator; |
| 198 | bool m_constrainsScrollingToContentEdge : 1; |
| 199 | |
| 200 | bool m_inLiveResize : 1; |
| 201 | |
| 202 | unsigned m_verticalScrollElasticity : 2; // ScrollElasticity |
| 203 | unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity |
| 204 | |
| 205 | unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 206 | |
| 207 | // There are 8 possible combinations of writing mode and direction. Scroll origin will be non-zero in the x or y axis |
| 208 | // if there is any reversed direction or writing-mode. The combinations are: |
| 209 | // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set |
| 210 | // horizontal-tb / ltr NO NO |
| 211 | // horizontal-tb / rtl YES NO |
| 212 | // horizontal-bt / ltr NO YES |
| 213 | // horizontal-bt / rtl YES YES |
| 214 | // vertical-lr / ltr NO NO |
| 215 | // vertical-lr / rtl NO YES |
| 216 | // vertical-rl / ltr YES NO |
| 217 | // vertical-rl / rtl YES YES |
| 218 | IntPoint m_scrollOrigin; |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 219 | |
| 220 | bool m_scrollOriginChanged; |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 223 | } // namespace WebCore |
| 224 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 225 | #endif // ScrollableArea_h |