blob: c744af6f0c1540dc86f8483f677a1ac4d84962b8 [file] [log] [blame]
hyatt@apple.com30ed5442008-09-13 18:39:58 +00001/*
weinig@apple.comd7d77c32011-01-21 20:15:04 +00002 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
hyatt@apple.com30ed5442008-09-13 18:39:58 +00003 *
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.comd7d77c32011-01-21 20:15:04 +000026#ifndef ScrollableArea_h
27#define ScrollableArea_h
hyatt@apple.com30ed5442008-09-13 18:39:58 +000028
hyatt@apple.com0819bcc2009-07-02 17:51:50 +000029#include "Scrollbar.h"
eric@webkit.orge5cf2da2008-12-05 22:10:27 +000030#include <wtf/Vector.h>
hyatt@apple.com30ed5442008-09-13 18:39:58 +000031
32namespace WebCore {
33
weinig@apple.com2a13aa82011-01-20 23:14:47 +000034class FloatPoint;
jamesr@google.come53ce642011-04-14 06:51:50 +000035class GraphicsContext;
bdakin@apple.comb38a6352011-02-10 00:28:50 +000036class PlatformGestureEvent;
weinig@apple.com2a13aa82011-01-20 23:14:47 +000037class PlatformWheelEvent;
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000038class ScrollAnimator;
jamesr@google.come53ce642011-04-14 06:51:50 +000039#if USE(ACCELERATED_COMPOSITING)
40class GraphicsLayer;
andersca@apple.com4143eb9b2012-03-21 00:04:13 +000041class TiledBacking;
jamesr@google.come53ce642011-04-14 06:51:50 +000042#endif
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000043
weinig@apple.comd7d77c32011-01-21 20:15:04 +000044class ScrollableArea {
hyatt@apple.com30ed5442008-09-13 18:39:58 +000045public:
weinig@apple.com2a13aa82011-01-20 23:14:47 +000046 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
47 void scrollToOffsetWithoutAnimation(const FloatPoint&);
48 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000049
andersca@apple.com42c0c3e2012-02-11 02:03:27 +000050 // Should be called when the scroll position changes externally, for example if the scroll layer position
51 // is updated on the scrolling thread and we need to notify the main thread.
52 void notifyScrollPositionChanged(const IntPoint&);
53
andersca@apple.com46fff0d2012-02-11 02:33:17 +000054 // Allows subclasses to handle scroll position updates themselves. If this member function
55 // returns true, the scrollable area won't actually update the scroll position and instead
56 // expect it to happen sometime in the future.
57 virtual bool requestScrollPositionUpdate(const IntPoint&) { return false; }
58
andersca@apple.com741fa5d2011-10-04 20:44:05 +000059 bool handleWheelEvent(const PlatformWheelEvent&);
weinig@apple.comcc0f1402011-01-28 19:05:43 +000060
61 // Functions for controlling if you can scroll past the end of the document.
62 bool constrainsScrollingToContentEdge() const { return m_constrainsScrollingToContentEdge; }
63 void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEdge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; }
weinig@apple.com10187a92011-01-27 05:12:24 +000064
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000065 void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_verticalScrollElasticity = scrollElasticity; }
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000066 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000067
68 void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_horizontalScrollElasticity = scrollElasticity; }
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000069 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000070
weinig@apple.com30215242011-02-03 18:13:32 +000071 bool inLiveResize() const { return m_inLiveResize; }
72 void willStartLiveResize();
73 void willEndLiveResize();
74
andersca@apple.com72c27282011-12-20 21:21:33 +000075 void contentAreaWillPaint() const;
76 void mouseEnteredContentArea() const;
77 void mouseExitedContentArea() const;
78 void mouseMovedInContentArea() const;
79 void mouseEnteredScrollbar(Scrollbar*) const;
80 void mouseExitedScrollbar(Scrollbar*) const;
81 void contentAreaDidShow() const;
82 void contentAreaDidHide() const;
83
bdakin@apple.com40772572012-09-11 00:37:06 +000084 void finishCurrentScrollAnimations() const;
85
weinig@apple.comf17b93c2011-02-07 21:29:12 +000086 void didAddVerticalScrollbar(Scrollbar*);
87 void willRemoveVerticalScrollbar(Scrollbar*);
jonlee@apple.com8d909182011-05-16 17:25:02 +000088 virtual void didAddHorizontalScrollbar(Scrollbar*);
89 virtual void willRemoveHorizontalScrollbar(Scrollbar*);
weinig@apple.comf17b93c2011-02-07 21:29:12 +000090
andersca@apple.comea30ccc2011-12-20 23:58:30 +000091 virtual void contentsResized();
92
bdakin@apple.com1592fa22011-02-22 22:28:52 +000093 bool hasOverlayScrollbars() const;
commit-queue@webkit.orgb31092d2011-07-21 01:32:17 +000094 virtual void setScrollbarOverlayStyle(ScrollbarOverlayStyle);
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000095 ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<ScrollbarOverlayStyle>(m_scrollbarOverlayStyle); }
bdakin@apple.com1592fa22011-02-22 22:28:52 +000096
bdakin@apple.com87235fc2012-03-23 20:36:31 +000097 // This getter will create a ScrollAnimator if it doesn't already exist.
simon.fraser@apple.com296f65d2011-05-06 17:12:48 +000098 ScrollAnimator* scrollAnimator() const;
bdakin@apple.com87235fc2012-03-23 20:36:31 +000099
100 // This getter will return null if the ScrollAnimator hasn't been created yet.
bdakin@apple.com3fec69c2012-03-23 21:02:51 +0000101 ScrollAnimator* existingScrollAnimator() const { return m_scrollAnimator.get(); }
bdakin@apple.com87235fc2012-03-23 20:36:31 +0000102
weinig@apple.com8c019242011-03-10 21:43:37 +0000103 const IntPoint& scrollOrigin() const { return m_scrollOrigin; }
xji@chromium.org24f57402011-11-08 22:22:24 +0000104 bool scrollOriginChanged() const { return m_scrollOriginChanged; }
weinig@apple.com30215242011-02-03 18:13:32 +0000105
jamesr@google.come53ce642011-04-14 06:51:50 +0000106 virtual bool isActive() const = 0;
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000107 virtual int scrollSize(ScrollbarOrientation) const = 0;
108 virtual int scrollPosition(Scrollbar*) const = 0;
jamesr@google.come53ce642011-04-14 06:51:50 +0000109 void invalidateScrollbar(Scrollbar*, const IntRect&);
110 virtual bool isScrollCornerVisible() const = 0;
eae@chromium.org92a579f2011-11-08 02:11:06 +0000111 virtual IntRect scrollCornerRect() const = 0;
simon.fraser@apple.comc8bf6392011-09-27 19:00:56 +0000112 void invalidateScrollCorner(const IntRect&);
eric@webkit.orge5cf2da2008-12-05 22:10:27 +0000113 virtual void getTickmarks(Vector<IntRect>&) const { }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000114
115 // Convert points and rects between the scrollbar and its containing view.
116 // The client needs to implement these in order to be aware of layout effects
117 // like CSS transforms.
118 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& scrollbarRect) const
119 {
120 return scrollbar->Widget::convertToContainingView(scrollbarRect);
121 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000122 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
123 {
124 return scrollbar->Widget::convertFromContainingView(parentRect);
125 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000126 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const
127 {
128 return scrollbar->Widget::convertToContainingView(scrollbarPoint);
129 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000130 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
131 {
132 return scrollbar->Widget::convertFromContainingView(parentPoint);
133 }
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +0000134
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000135 virtual Scrollbar* horizontalScrollbar() const { return 0; }
136 virtual Scrollbar* verticalScrollbar() const { return 0; }
137
enne@google.com18290d42012-08-23 17:41:18 +0000138 virtual IntPoint scrollPosition() const;
139 virtual IntPoint minimumScrollPosition() const;
140 virtual IntPoint maximumScrollPosition() const;
141 virtual IntRect visibleContentRect(bool /*includeScrollbars*/ = false) const;
142 virtual int visibleHeight() const = 0;
143 virtual int visibleWidth() const = 0;
144 virtual IntSize contentsSize() const = 0;
145 virtual IntSize overhangAmount() const { return IntSize(); }
bdakin@apple.com32167522011-02-01 20:35:25 +0000146 virtual IntPoint currentMousePosition() const { return IntPoint(); }
weinig@apple.coma1255ce2011-06-04 19:20:00 +0000147
bdakin@apple.come0a38ad2011-03-15 18:30:41 +0000148 virtual bool shouldSuspendScrollAnimations() const { return true; }
bdakin@apple.com83c96f42011-11-28 23:06:56 +0000149 virtual void scrollbarStyleChanged(int /*newStyle*/, bool /*forceUpdate*/) { }
bdakin@apple.com59845aa2011-04-21 22:49:53 +0000150 virtual void setVisibleScrollerThumbRect(const IntRect&) { }
bdakin@apple.com8a57afc2011-06-15 23:13:23 +0000151
bdakin@apple.com40772572012-09-11 00:37:06 +0000152 virtual bool scrollbarsCanBeActive() const = 0;
jonlee@apple.com8d909182011-05-16 17:25:02 +0000153
andersca@apple.com1bb03f32011-06-30 19:40:43 +0000154 // Note that this only returns scrollable areas that can actually be scrolled.
155 virtual ScrollableArea* enclosingScrollableArea() const = 0;
156
andersca@apple.com6c3da662012-02-07 23:47:59 +0000157 // Returns the bounding box of this scrollable area, in the coordinate system of the enclosing scroll view.
enne@google.com18290d42012-08-23 17:41:18 +0000158 virtual IntRect scrollableAreaBoundingBox() const = 0;
andersca@apple.com6c3da662012-02-07 23:47:59 +0000159
jonlee@apple.com8d909182011-05-16 17:25:02 +0000160 virtual bool shouldRubberBandInDirection(ScrollDirection) const { return true; }
bdakin@apple.com32167522011-02-01 20:35:25 +0000161
commit-queue@webkit.org33d35e72011-06-20 23:16:24 +0000162 virtual bool scrollAnimatorEnabled() const { return false; }
163
commit-queue@webkit.orga6e510e2011-09-07 20:13:34 +0000164 // NOTE: Only called from Internals for testing.
165 void setScrollOffsetFromInternals(const IntPoint&);
166
commit-queue@webkit.org660993d2012-03-08 19:37:34 +0000167 // Let subclasses provide a way of asking for and servicing scroll
168 // animations.
169 virtual bool scheduleAnimation() { return false; }
170 void serviceScrollAnimations();
171
andersca@apple.com4143eb9b2012-03-21 00:04:13 +0000172#if USE(ACCELERATED_COMPOSITING)
173 virtual TiledBacking* tiledBacking() { return 0; }
commit-queue@webkit.orgc0328312012-09-04 18:54:00 +0000174 virtual bool usesCompositedScrolling() const { return false; }
andersca@apple.com4143eb9b2012-03-21 00:04:13 +0000175#endif
176
weinig@apple.com8c019242011-03-10 21:43:37 +0000177protected:
andersca@apple.com77cb9c22011-12-21 19:41:12 +0000178 ScrollableArea();
andersca@apple.comd604d212011-12-20 20:33:38 +0000179 virtual ~ScrollableArea();
180
xji@chromium.org24f57402011-11-08 22:22:24 +0000181 void setScrollOrigin(const IntPoint&);
xji@chromium.org24f57402011-11-08 22:22:24 +0000182 void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
xji@chromium.org85d87542011-11-01 22:06:46 +0000183
jamesr@google.come53ce642011-04-14 06:51:50 +0000184 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0;
185 virtual void invalidateScrollCornerRect(const IntRect&) = 0;
186
187#if USE(ACCELERATED_COMPOSITING)
188 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; }
189 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; }
190 virtual GraphicsLayer* layerForScrollCorner() const { return 0; }
andersca@apple.com134cfff2012-01-13 00:30:55 +0000191#if ENABLE(RUBBER_BANDING)
commit-queue@webkit.org0a4465d2011-09-15 04:06:49 +0000192 virtual GraphicsLayer* layerForOverhangAreas() const { return 0; }
193#endif
jamesr@google.come53ce642011-04-14 06:51:50 +0000194#endif
simon.fraser@apple.com856ca862011-04-24 05:53:06 +0000195 bool hasLayerForHorizontalScrollbar() const;
196 bool hasLayerForVerticalScrollbar() const;
197 bool hasLayerForScrollCorner() const;
jamesr@google.come53ce642011-04-14 06:51:50 +0000198
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000199private:
andersca@apple.com6a6db042012-02-29 22:43:05 +0000200 void scrollPositionChanged(const IntPoint&);
201
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000202 // NOTE: Only called from the ScrollAnimator.
203 friend class ScrollAnimator;
204 void setScrollOffsetFromAnimation(const IntPoint&);
205
andersca@apple.com37eadc02012-02-10 22:01:16 +0000206 // This function should be overriden by subclasses to perform the actual
207 // scroll of the content.
208 virtual void setScrollOffset(const IntPoint&) = 0;
209
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000210 mutable OwnPtr<ScrollAnimator> m_scrollAnimator;
rniwa@webkit.org6f254212012-03-31 05:04:59 +0000211 unsigned m_constrainsScrollingToContentEdge : 1;
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000212
rniwa@webkit.org6f254212012-03-31 05:04:59 +0000213 unsigned m_inLiveResize : 1;
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000214
215 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
216 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
217
218 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle
xji@chromium.org85d87542011-11-01 22:06:46 +0000219
rniwa@webkit.org6f254212012-03-31 05:04:59 +0000220 unsigned m_scrollOriginChanged : 1;
221
xji@chromium.org85d87542011-11-01 22:06:46 +0000222 // There are 8 possible combinations of writing mode and direction. Scroll origin will be non-zero in the x or y axis
223 // if there is any reversed direction or writing-mode. The combinations are:
224 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set
225 // horizontal-tb / ltr NO NO
226 // horizontal-tb / rtl YES NO
227 // horizontal-bt / ltr NO YES
228 // horizontal-bt / rtl YES YES
229 // vertical-lr / ltr NO NO
230 // vertical-lr / rtl NO YES
231 // vertical-rl / ltr YES NO
232 // vertical-rl / rtl YES YES
233 IntPoint m_scrollOrigin;
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000234};
235
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000236} // namespace WebCore
237
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000238#endif // ScrollableArea_h