2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef ScrollAnimatorMac_h
27 #define ScrollAnimatorMac_h
29 #include "platform/Timer.h"
30 #include "platform/geometry/FloatPoint.h"
31 #include "platform/geometry/FloatSize.h"
32 #include "platform/geometry/IntRect.h"
33 #include "platform/mac/ScrollElasticityController.h"
34 #include "platform/scroll/ScrollAnimator.h"
35 #include "wtf/RetainPtr.h"
37 OBJC_CLASS WebScrollAnimationHelperDelegate;
38 OBJC_CLASS WebScrollbarPainterControllerDelegate;
39 OBJC_CLASS WebScrollbarPainterDelegate;
41 typedef id ScrollbarPainterController;
43 #if !USE(RUBBER_BANDING)
44 class ScrollElasticityControllerClient { };
51 class PLATFORM_EXPORT ScrollAnimatorMac : public ScrollAnimator, private ScrollElasticityControllerClient {
54 ScrollAnimatorMac(ScrollableArea*);
55 virtual ~ScrollAnimatorMac();
57 void immediateScrollToPointForScrollAnimation(const FloatPoint& newPosition);
58 bool haveScrolledSincePageLoad() const { return m_haveScrolledSincePageLoad; }
60 void updateScrollerStyle();
62 bool scrollbarPaintTimerIsActive() const;
63 void startScrollbarPaintTimer();
64 void stopScrollbarPaintTimer();
66 void sendContentAreaScrolledSoon(const FloatSize& scrollDelta);
68 void setVisibleScrollerThumbRect(const IntRect&);
70 static bool canUseCoordinatedScrollbar();
73 RetainPtr<id> m_scrollAnimationHelper;
74 RetainPtr<WebScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate;
76 RetainPtr<ScrollbarPainterController> m_scrollbarPainterController;
77 RetainPtr<WebScrollbarPainterControllerDelegate> m_scrollbarPainterControllerDelegate;
78 RetainPtr<WebScrollbarPainterDelegate> m_horizontalScrollbarPainterDelegate;
79 RetainPtr<WebScrollbarPainterDelegate> m_verticalScrollbarPainterDelegate;
81 void initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*);
82 Timer<ScrollAnimatorMac> m_initialScrollbarPaintTimer;
84 void sendContentAreaScrolledTimerFired(Timer<ScrollAnimatorMac>*);
85 Timer<ScrollAnimatorMac> m_sendContentAreaScrolledTimer;
86 FloatSize m_contentAreaScrolledTimerScrollDelta;
88 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float delta) OVERRIDE;
89 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&) OVERRIDE;
91 #if USE(RUBBER_BANDING)
92 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE;
95 virtual void handleWheelEventPhase(PlatformWheelEventPhase) OVERRIDE;
97 virtual void cancelAnimations() OVERRIDE;
98 virtual void setIsActive() OVERRIDE;
100 virtual void contentAreaWillPaint() const OVERRIDE;
101 virtual void mouseEnteredContentArea() const OVERRIDE;
102 virtual void mouseExitedContentArea() const OVERRIDE;
103 virtual void mouseMovedInContentArea() const OVERRIDE;
104 virtual void mouseEnteredScrollbar(Scrollbar*) const OVERRIDE;
105 virtual void mouseExitedScrollbar(Scrollbar*) const OVERRIDE;
106 virtual void willStartLiveResize() OVERRIDE;
107 virtual void contentsResized() const OVERRIDE;
108 virtual void willEndLiveResize() OVERRIDE;
109 virtual void contentAreaDidShow() const OVERRIDE;
110 virtual void contentAreaDidHide() const OVERRIDE;
111 void didBeginScrollGesture() const;
112 void didEndScrollGesture() const;
113 void mayBeginScrollGesture() const;
115 virtual void finishCurrentScrollAnimations() OVERRIDE;
117 virtual void didAddVerticalScrollbar(Scrollbar*) OVERRIDE;
118 virtual void willRemoveVerticalScrollbar(Scrollbar*) OVERRIDE;
119 virtual void didAddHorizontalScrollbar(Scrollbar*) OVERRIDE;
120 virtual void willRemoveHorizontalScrollbar(Scrollbar*) OVERRIDE;
122 virtual bool shouldScrollbarParticipateInHitTesting(Scrollbar*) OVERRIDE;
124 virtual void notifyContentAreaScrolled(const FloatSize& delta) OVERRIDE;
126 FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const;
128 void immediateScrollTo(const FloatPoint&);
130 virtual bool isRubberBandInProgress() const OVERRIDE;
132 #if USE(RUBBER_BANDING)
133 /// ScrollElasticityControllerClient member functions.
134 virtual IntSize stretchAmount() OVERRIDE;
135 virtual bool allowsHorizontalStretching() OVERRIDE;
136 virtual bool allowsVerticalStretching() OVERRIDE;
137 virtual bool pinnedInDirection(const FloatSize&) OVERRIDE;
138 virtual bool canScrollHorizontally() OVERRIDE;
139 virtual bool canScrollVertically() OVERRIDE;
140 virtual bool shouldRubberBandInDirection(ScrollDirection) OVERRIDE;
141 virtual WebCore::IntPoint absoluteScrollPosition() OVERRIDE;
142 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) OVERRIDE;
143 virtual void immediateScrollBy(const FloatSize&) OVERRIDE;
144 virtual void startSnapRubberbandTimer() OVERRIDE;
145 virtual void stopSnapRubberbandTimer() OVERRIDE;
147 bool pinnedInDirection(float deltaX, float deltaY);
148 void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*);
150 ScrollElasticityController m_scrollElasticityController;
151 Timer<ScrollAnimatorMac> m_snapRubberBandTimer;
154 bool m_haveScrolledSincePageLoad;
155 bool m_needsScrollerStyleUpdate;
156 IntRect m_visibleScrollerThumbRect;
159 } // namespace WebCore
161 #endif // ScrollAnimatorMac_h