tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / mac / ScrollAnimatorMac.h
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
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. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef ScrollAnimatorMac_h
27 #define ScrollAnimatorMac_h
28
29 #if ENABLE(SMOOTH_SCROLLING)
30
31 #include "IntRect.h"
32 #include "FloatPoint.h"
33 #include "FloatSize.h"
34 #include "ScrollAnimator.h"
35 #include "ScrollElasticityController.h"
36 #include "Timer.h"
37 #include <wtf/RetainPtr.h>
38
39 #ifdef __OBJC__
40 @class WebScrollAnimationHelperDelegate;
41 @class WebScrollbarPainterControllerDelegate;
42 @class WebScrollbarPainterDelegate;
43 #else
44 class WebScrollAnimationHelperDelegate;
45 class WebScrollbarPainterControllerDelegate;
46 class WebScrollbarPainterDelegate;
47 #endif
48
49 #if USE(SCROLLBAR_PAINTER)
50 typedef id ScrollbarPainterController;
51 #endif
52
53 #if !ENABLE(RUBBER_BANDING)
54 class ScrollElasticityControllerClient { };
55 #endif
56
57 namespace WebCore {
58
59 class Scrollbar;
60
61 class ScrollAnimatorMac : public ScrollAnimator, private ScrollElasticityControllerClient {
62
63 public:
64     ScrollAnimatorMac(ScrollableArea*);
65     virtual ~ScrollAnimatorMac();
66
67     virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier);
68     virtual void scrollToOffsetWithoutAnimation(const FloatPoint&);
69
70 #if ENABLE(RUBBER_BANDING)
71     virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE;
72 #if ENABLE(GESTURE_EVENTS)
73     virtual void handleGestureEvent(const PlatformGestureEvent&);
74 #endif
75 #endif
76
77     virtual void cancelAnimations();
78
79     void immediateScrollToPoint(const FloatPoint& newPosition);
80     void immediateScrollByDeltaX(float deltaX);
81     void immediateScrollByDeltaY(float deltaY);
82
83     void immediateScrollToPointForScrollAnimation(const FloatPoint& newPosition);
84
85     void setIsDrawingIntoLayer(bool b) { m_drawingIntoLayer = b; }
86     bool isDrawingIntoLayer() const { return m_drawingIntoLayer; }
87
88     bool haveScrolledSincePageLoad() const { return m_haveScrolledSincePageLoad; }
89
90     virtual void setIsActive();
91
92 #if USE(SCROLLBAR_PAINTER)
93     void updateScrollerStyle();
94
95     bool scrollbarPaintTimerIsActive() const;
96     void startScrollbarPaintTimer();
97     void stopScrollbarPaintTimer();
98 #endif
99
100     void setVisibleScrollerThumbRect(const IntRect&);
101
102 private:
103     RetainPtr<id> m_scrollAnimationHelper;
104     RetainPtr<WebScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate;
105
106 #if USE(SCROLLBAR_PAINTER)
107     RetainPtr<ScrollbarPainterController> m_scrollbarPainterController;
108     RetainPtr<WebScrollbarPainterControllerDelegate> m_scrollbarPainterControllerDelegate;
109     RetainPtr<WebScrollbarPainterDelegate> m_scrollbarPainterDelegate;
110
111     void initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*);
112     Timer<ScrollAnimatorMac> m_initialScrollbarPaintTimer;
113 #endif
114     
115     virtual void notifyPositionChanged();
116     virtual void contentAreaWillPaint() const;
117     virtual void mouseEnteredContentArea() const;
118     virtual void mouseExitedContentArea() const;
119     virtual void mouseMovedInContentArea() const;
120     virtual void mouseEnteredScrollbar(Scrollbar*) const;
121     virtual void mouseExitedScrollbar(Scrollbar*) const;
122     virtual void willStartLiveResize();
123     virtual void contentsResized() const;
124     virtual void willEndLiveResize();
125     virtual void contentAreaDidShow() const;
126     virtual void contentAreaDidHide() const;
127     void didBeginScrollGesture() const;
128     void didEndScrollGesture() const;
129
130     virtual void didAddVerticalScrollbar(Scrollbar*);
131     virtual void willRemoveVerticalScrollbar(Scrollbar*);
132     virtual void didAddHorizontalScrollbar(Scrollbar*);
133     virtual void willRemoveHorizontalScrollbar(Scrollbar*);
134
135     void setNeedsScrollerStyleUpdate(bool needsUpdate) { m_needsScrollerStyleUpdate = needsUpdate; }
136     bool needsScrollerStyleUpdate() const { return m_needsScrollerStyleUpdate; }
137
138     float adjustScrollXPositionIfNecessary(float) const;
139     float adjustScrollYPositionIfNecessary(float) const;
140     FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const;
141
142 #if ENABLE(RUBBER_BANDING)
143     /// ScrollElasticityControllerClient member functions.
144     virtual bool isHorizontalScrollerPinnedToMinimumPosition() OVERRIDE;
145     virtual bool isHorizontalScrollerPinnedToMaximumPosition() OVERRIDE;
146     virtual IntSize stretchAmount() OVERRIDE;
147     virtual void startSnapRubberbandTimer() OVERRIDE;
148     virtual void stopSnapRubberbandTimer() OVERRIDE;
149
150     bool allowsVerticalStretching() const;
151     bool allowsHorizontalStretching() const;
152     bool pinnedInDirection(float deltaX, float deltaY);
153     void snapRubberBand();
154     void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*);
155     void smoothScrollWithEvent(const PlatformWheelEvent&);
156     void beginScrollGesture();
157     void endScrollGesture();
158
159     ScrollElasticityController m_scrollElasticityController;
160     Timer<ScrollAnimatorMac> m_snapRubberBandTimer;
161 #endif
162
163     bool m_drawingIntoLayer;
164     bool m_haveScrolledSincePageLoad;
165     bool m_needsScrollerStyleUpdate;
166     IntRect m_visibleScrollerThumbRect;
167 };
168
169 } // namespace WebCore
170
171 #endif // ENABLE(SMOOTH_SCROLLING)
172
173 #endif // ScrollAnimatorMac_h