blob: 9839abc3b41901d1ddddd5470f53f58b7c70abd3 [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
29#include "IntRect.h"
hyatt@apple.com0819bcc2009-07-02 17:51:50 +000030#include "Scrollbar.h"
eric@webkit.orge5cf2da2008-12-05 22:10:27 +000031#include <wtf/Vector.h>
hyatt@apple.com30ed5442008-09-13 18:39:58 +000032
33namespace WebCore {
34
weinig@apple.com2a13aa82011-01-20 23:14:47 +000035class FloatPoint;
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;
39
weinig@apple.comd7d77c32011-01-21 20:15:04 +000040class ScrollableArea {
hyatt@apple.com30ed5442008-09-13 18:39:58 +000041public:
weinig@apple.comd7d77c32011-01-21 20:15:04 +000042 ScrollableArea();
43 virtual ~ScrollableArea();
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000044
weinig@apple.com2a13aa82011-01-20 23:14:47 +000045 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
46 void scrollToOffsetWithoutAnimation(const FloatPoint&);
47 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset);
48 void scrollToXOffsetWithoutAnimation(float x);
49 void scrollToYOffsetWithoutAnimation(float x);
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +000050
weinig@apple.com10187a92011-01-27 05:12:24 +000051 void handleWheelEvent(PlatformWheelEvent&);
weinig@apple.comcc0f1402011-01-28 19:05:43 +000052#if ENABLE(GESTURE_EVENTS)
53 void handleGestureEvent(const PlatformGestureEvent&);
54#endif
55
56 // Functions for controlling if you can scroll past the end of the document.
57 bool constrainsScrollingToContentEdge() const { return m_constrainsScrollingToContentEdge; }
58 void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEdge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; }
weinig@apple.com10187a92011-01-27 05:12:24 +000059
weinig@apple.com30215242011-02-03 18:13:32 +000060 bool inLiveResize() const { return m_inLiveResize; }
61 void willStartLiveResize();
62 void willEndLiveResize();
63
weinig@apple.comf17b93c2011-02-07 21:29:12 +000064 void didAddVerticalScrollbar(Scrollbar*);
65 void willRemoveVerticalScrollbar(Scrollbar*);
66 void didAddHorizontalScrollbar(Scrollbar*);
67 void willRemoveHorizontalScrollbar(Scrollbar*);
68
bdakin@apple.com32167522011-02-01 20:35:25 +000069 ScrollAnimator* scrollAnimator() const { return m_scrollAnimator.get(); }
weinig@apple.com30215242011-02-03 18:13:32 +000070
weinig@apple.com2a13aa82011-01-20 23:14:47 +000071 virtual int scrollSize(ScrollbarOrientation) const = 0;
72 virtual int scrollPosition(Scrollbar*) const = 0;
hyatt@apple.com6fa40c52008-10-03 07:06:28 +000073 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0;
hyatt@apple.com30ed5442008-09-13 18:39:58 +000074 virtual bool isActive() const = 0;
hyatt@apple.come2a30fd2008-10-13 21:23:21 +000075 virtual bool scrollbarCornerPresent() const = 0;
eric@webkit.orge5cf2da2008-12-05 22:10:27 +000076 virtual void getTickmarks(Vector<IntRect>&) const { }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +000077
weinig@apple.com2a13aa82011-01-20 23:14:47 +000078 // This function should be overriden by subclasses to perform the actual
79 // scroll of the content.
80 virtual void setScrollOffset(const IntPoint&) = 0;
81
hyatt@apple.comb327f5d2009-07-02 17:31:42 +000082 // Convert points and rects between the scrollbar and its containing view.
83 // The client needs to implement these in order to be aware of layout effects
84 // like CSS transforms.
85 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& scrollbarRect) const
86 {
87 return scrollbar->Widget::convertToContainingView(scrollbarRect);
88 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +000089 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
90 {
91 return scrollbar->Widget::convertFromContainingView(parentRect);
92 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +000093 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const
94 {
95 return scrollbar->Widget::convertToContainingView(scrollbarPoint);
96 }
hyatt@apple.comb327f5d2009-07-02 17:31:42 +000097 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
98 {
99 return scrollbar->Widget::convertFromContainingView(parentPoint);
100 }
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +0000101
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000102 virtual Scrollbar* horizontalScrollbar() const { return 0; }
103 virtual Scrollbar* verticalScrollbar() const { return 0; }
104
weinig@apple.com10187a92011-01-27 05:12:24 +0000105 virtual IntPoint scrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
106 virtual IntPoint minimumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
107 virtual IntPoint maximumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
weinig@apple.com10187a92011-01-27 05:12:24 +0000108 virtual IntRect visibleContentRect(bool = false) const { ASSERT_NOT_REACHED(); return IntRect(); }
109 virtual int visibleHeight() const { ASSERT_NOT_REACHED(); return 0; }
110 virtual int visibleWidth() const { ASSERT_NOT_REACHED(); return 0; }
weinig@apple.comcc0f1402011-01-28 19:05:43 +0000111 virtual IntSize contentsSize() const { ASSERT_NOT_REACHED(); return IntSize(); }
weinig@apple.comcc0f1402011-01-28 19:05:43 +0000112 virtual IntSize overhangAmount() const { ASSERT_NOT_REACHED(); return IntSize(); }
bdakin@apple.com32167522011-02-01 20:35:25 +0000113 virtual IntPoint currentMousePosition() const { return IntPoint(); }
weinig@apple.com30215242011-02-03 18:13:32 +0000114 virtual void didCompleteRubberBand(const IntSize&) const { ASSERT_NOT_REACHED(); }
bdakin@apple.com32167522011-02-01 20:35:25 +0000115
bdakin@apple.comb38a6352011-02-10 00:28:50 +0000116 virtual bool scrollbarWillRenderIntoCompositingLayer() const { return false; }
117
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +0000118private:
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000119 // NOTE: Only called from the ScrollAnimator.
120 friend class ScrollAnimator;
121 void setScrollOffsetFromAnimation(const IntPoint&);
122
commit-queue@webkit.org1bf3b4b2010-09-08 19:31:47 +0000123 OwnPtr<ScrollAnimator> m_scrollAnimator;
weinig@apple.comcc0f1402011-01-28 19:05:43 +0000124 bool m_constrainsScrollingToContentEdge;
bdakin@apple.com32167522011-02-01 20:35:25 +0000125
126 bool m_inLiveResize;
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000127};
128
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000129} // namespace WebCore
130
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000131#endif // ScrollableArea_h