blob: 94da5da1b7f30af6c91e496b09a6816e42949010 [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;
41#endif
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000042
weinig@apple.comd7d77c32011-01-21 20:15:04 +000043class ScrollableArea {
hyatt@apple.com30ed5442008-09-13 18:39:58 +000044public:
wjmaclean@chromium.orgaa873b12011-10-10 00:21:51 +000045 enum ZoomAnimationState { ZoomAnimationContinuing, ZoomAnimationFinishing };
46
weinig@apple.com2a13aa82011-01-20 23:14:47 +000047 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
48 void scrollToOffsetWithoutAnimation(const FloatPoint&);
49 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000050
andersca@apple.com42c0c3e2012-02-11 02:03:27 +000051 // 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.com46fff0d2012-02-11 02:33:17 +000055 // 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.org9a215662011-10-11 22:43:53 +000060 virtual void zoomAnimatorTransformChanged(float, float, float, ZoomAnimationState);
wjmaclean@chromium.orgaa873b12011-10-10 00:21:51 +000061
andersca@apple.com741fa5d2011-10-04 20:44:05 +000062 bool handleWheelEvent(const PlatformWheelEvent&);
weinig@apple.comcc0f1402011-01-28 19:05:43 +000063#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.com10187a92011-01-27 05:12:24 +000070
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000071 void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_verticalScrollElasticity = scrollElasticity; }
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000072 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000073
74 void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_horizontalScrollElasticity = scrollElasticity; }
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000075 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
weinig@apple.com0fcf06e2011-04-13 00:20:11 +000076
weinig@apple.com30215242011-02-03 18:13:32 +000077 bool inLiveResize() const { return m_inLiveResize; }
78 void willStartLiveResize();
79 void willEndLiveResize();
80
andersca@apple.com72c27282011-12-20 21:21:33 +000081 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.comf17b93c2011-02-07 21:29:12 +000090 void didAddVerticalScrollbar(Scrollbar*);
91 void willRemoveVerticalScrollbar(Scrollbar*);
jonlee@apple.com8d909182011-05-16 17:25:02 +000092 virtual void didAddHorizontalScrollbar(Scrollbar*);
93 virtual void willRemoveHorizontalScrollbar(Scrollbar*);
weinig@apple.comf17b93c2011-02-07 21:29:12 +000094
andersca@apple.comea30ccc2011-12-20 23:58:30 +000095 virtual void contentsResized();
96
bdakin@apple.com1592fa22011-02-22 22:28:52 +000097 bool hasOverlayScrollbars() const;
commit-queue@webkit.orgb31092d2011-07-21 01:32:17 +000098 virtual void setScrollbarOverlayStyle(ScrollbarOverlayStyle);
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +000099 ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<ScrollbarOverlayStyle>(m_scrollbarOverlayStyle); }
bdakin@apple.com1592fa22011-02-22 22:28:52 +0000100
simon.fraser@apple.com296f65d2011-05-06 17:12:48 +0000101 ScrollAnimator* scrollAnimator() const;
weinig@apple.com8c019242011-03-10 21:43:37 +0000102 const IntPoint& scrollOrigin() const { return m_scrollOrigin; }
xji@chromium.org24f57402011-11-08 22:22:24 +0000103 bool scrollOriginChanged() const { return m_scrollOriginChanged; }
weinig@apple.com30215242011-02-03 18:13:32 +0000104
jamesr@google.come53ce642011-04-14 06:51:50 +0000105 virtual bool isActive() const = 0;
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000106 virtual int scrollSize(ScrollbarOrientation) const = 0;
107 virtual int scrollPosition(Scrollbar*) const = 0;
jamesr@google.come53ce642011-04-14 06:51:50 +0000108 void invalidateScrollbar(Scrollbar*, const IntRect&);
109 virtual bool isScrollCornerVisible() const = 0;
eae@chromium.org92a579f2011-11-08 02:11:06 +0000110 virtual IntRect scrollCornerRect() const = 0;
simon.fraser@apple.comc8bf6392011-09-27 19:00:56 +0000111 void invalidateScrollCorner(const IntRect&);
eric@webkit.orge5cf2da2008-12-05 22:10:27 +0000112 virtual void getTickmarks(Vector<IntRect>&) const { }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000113
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.comb327f5d2009-07-02 17:31:42 +0000121 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
122 {
123 return scrollbar->Widget::convertFromContainingView(parentRect);
124 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000125 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const
126 {
127 return scrollbar->Widget::convertToContainingView(scrollbarPoint);
128 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000129 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
130 {
131 return scrollbar->Widget::convertFromContainingView(parentPoint);
132 }
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +0000133
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000134 virtual Scrollbar* horizontalScrollbar() const { return 0; }
135 virtual Scrollbar* verticalScrollbar() const { return 0; }
136
weinig@apple.com10187a92011-01-27 05:12:24 +0000137 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.com10039512011-05-11 20:55:03 +0000140 virtual IntRect visibleContentRect(bool /*includeScrollbars*/ = false) const { ASSERT_NOT_REACHED(); return IntRect(); }
eae@chromium.org92a579f2011-11-08 02:11:06 +0000141 virtual int visibleHeight() const { ASSERT_NOT_REACHED(); return 0; }
142 virtual int visibleWidth() const { ASSERT_NOT_REACHED(); return 0; }
weinig@apple.comcc0f1402011-01-28 19:05:43 +0000143 virtual IntSize contentsSize() const { ASSERT_NOT_REACHED(); return IntSize(); }
weinig@apple.comcc0f1402011-01-28 19:05:43 +0000144 virtual IntSize overhangAmount() const { ASSERT_NOT_REACHED(); return IntSize(); }
bdakin@apple.com32167522011-02-01 20:35:25 +0000145 virtual IntPoint currentMousePosition() const { return IntPoint(); }
weinig@apple.coma1255ce2011-06-04 19:20:00 +0000146
bdakin@apple.come0a38ad2011-03-15 18:30:41 +0000147 virtual bool shouldSuspendScrollAnimations() const { return true; }
bdakin@apple.com83c96f42011-11-28 23:06:56 +0000148 virtual void scrollbarStyleChanged(int /*newStyle*/, bool /*forceUpdate*/) { }
bdakin@apple.com59845aa2011-04-21 22:49:53 +0000149 virtual void setVisibleScrollerThumbRect(const IntRect&) { }
bdakin@apple.com8a57afc2011-06-15 23:13:23 +0000150
151 virtual bool isOnActivePage() const { ASSERT_NOT_REACHED(); return true; }
jonlee@apple.com8d909182011-05-16 17:25:02 +0000152
andersca@apple.com1bb03f32011-06-30 19:40:43 +0000153 // Note that this only returns scrollable areas that can actually be scrolled.
154 virtual ScrollableArea* enclosingScrollableArea() const = 0;
155
andersca@apple.com6c3da662012-02-07 23:47:59 +0000156 // Returns the bounding box of this scrollable area, in the coordinate system of the enclosing scroll view.
andersca@apple.come1df2ad2012-02-08 00:17:42 +0000157 virtual IntRect scrollableAreaBoundingBox() const { ASSERT_NOT_REACHED(); return IntRect(); }
andersca@apple.com6c3da662012-02-07 23:47:59 +0000158
jonlee@apple.com8d909182011-05-16 17:25:02 +0000159 virtual bool shouldRubberBandInDirection(ScrollDirection) const { return true; }
bdakin@apple.com32167522011-02-01 20:35:25 +0000160
commit-queue@webkit.org33d35e72011-06-20 23:16:24 +0000161 virtual bool scrollAnimatorEnabled() const { return false; }
162
commit-queue@webkit.orga6e510e2011-09-07 20:13:34 +0000163 // NOTE: Only called from Internals for testing.
164 void setScrollOffsetFromInternals(const IntPoint&);
165
weinig@apple.com8c019242011-03-10 21:43:37 +0000166protected:
andersca@apple.com77cb9c22011-12-21 19:41:12 +0000167 ScrollableArea();
andersca@apple.comd604d212011-12-20 20:33:38 +0000168 virtual ~ScrollableArea();
169
xji@chromium.org24f57402011-11-08 22:22:24 +0000170 void setScrollOrigin(const IntPoint&);
xji@chromium.org24f57402011-11-08 22:22:24 +0000171 void resetScrollOriginChanged() { m_scrollOriginChanged = false; }
xji@chromium.org85d87542011-11-01 22:06:46 +0000172
jamesr@google.come53ce642011-04-14 06:51:50 +0000173 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.com134cfff2012-01-13 00:30:55 +0000180#if ENABLE(RUBBER_BANDING)
commit-queue@webkit.org0a4465d2011-09-15 04:06:49 +0000181 virtual GraphicsLayer* layerForOverhangAreas() const { return 0; }
182#endif
jamesr@google.come53ce642011-04-14 06:51:50 +0000183#endif
simon.fraser@apple.com856ca862011-04-24 05:53:06 +0000184 bool hasLayerForHorizontalScrollbar() const;
185 bool hasLayerForVerticalScrollbar() const;
186 bool hasLayerForScrollCorner() const;
jamesr@google.come53ce642011-04-14 06:51:50 +0000187
andreas.kling@nokia.comd5015fc2011-10-10 14:51:44 +0000188private:
189 // NOTE: Only called from the ScrollAnimator.
190 friend class ScrollAnimator;
191 void setScrollOffsetFromAnimation(const IntPoint&);
192
andersca@apple.com37eadc02012-02-10 22:01:16 +0000193 // 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.comd5015fc2011-10-10 14:51:44 +0000197 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.org85d87542011-11-01 22:06:46 +0000206
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.org24f57402011-11-08 22:22:24 +0000219
220 bool m_scrollOriginChanged;
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000221};
222
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000223} // namespace WebCore
224
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000225#endif // ScrollableArea_h