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 #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" 36 37 OBJC_CLASS WebScrollAnimationHelperDelegate; 38 OBJC_CLASS WebScrollbarPainterControllerDelegate; 39 OBJC_CLASS WebScrollbarPainterDelegate; 40 41 typedef id ScrollbarPainterController; 42 43 #if !USE(RUBBER_BANDING) 44 class ScrollElasticityControllerClient { }; 45 #endif 46 47 namespace WebCore { 48 49 class Scrollbar; 50 51 class PLATFORM_EXPORT ScrollAnimatorMac : public ScrollAnimator, private ScrollElasticityControllerClient { 52 53 public: 54 ScrollAnimatorMac(ScrollableArea*); 55 virtual ~ScrollAnimatorMac(); 56 57 void immediateScrollToPointForScrollAnimation(const FloatPoint& newPosition); 58 bool haveScrolledSincePageLoad() const { return m_haveScrolledSincePageLoad; } 59 60 void updateScrollerStyle(); 61 62 bool scrollbarPaintTimerIsActive() const; 63 void startScrollbarPaintTimer(); 64 void stopScrollbarPaintTimer(); 65 66 void sendContentAreaScrolledSoon(const FloatSize& scrollDelta); 67 68 void setVisibleScrollerThumbRect(const IntRect&); 69 70 static bool canUseCoordinatedScrollbar(); 71 72 private: 73 RetainPtr<id> m_scrollAnimationHelper; 74 RetainPtr<WebScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate; 75 76 RetainPtr<ScrollbarPainterController> m_scrollbarPainterController; 77 RetainPtr<WebScrollbarPainterControllerDelegate> m_scrollbarPainterControllerDelegate; 78 RetainPtr<WebScrollbarPainterDelegate> m_horizontalScrollbarPainterDelegate; 79 RetainPtr<WebScrollbarPainterDelegate> m_verticalScrollbarPainterDelegate; 80 81 void initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*); 82 Timer<ScrollAnimatorMac> m_initialScrollbarPaintTimer; 83 84 void sendContentAreaScrolledTimerFired(Timer<ScrollAnimatorMac>*); 85 Timer<ScrollAnimatorMac> m_sendContentAreaScrolledTimer; 86 FloatSize m_contentAreaScrolledTimerScrollDelta; 87 88 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float delta) OVERRIDE; 89 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&) OVERRIDE; 90 91 #if USE(RUBBER_BANDING) 92 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; 93 #endif 94 95 virtual void handleWheelEventPhase(PlatformWheelEventPhase) OVERRIDE; 96 97 virtual void cancelAnimations() OVERRIDE; 98 virtual void setIsActive() OVERRIDE; 99 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; 114 115 virtual void finishCurrentScrollAnimations() OVERRIDE; 116 117 virtual void didAddVerticalScrollbar(Scrollbar*) OVERRIDE; 118 virtual void willRemoveVerticalScrollbar(Scrollbar*) OVERRIDE; 119 virtual void didAddHorizontalScrollbar(Scrollbar*) OVERRIDE; 120 virtual void willRemoveHorizontalScrollbar(Scrollbar*) OVERRIDE; 121 122 virtual bool shouldScrollbarParticipateInHitTesting(Scrollbar*) OVERRIDE; 123 124 virtual void notifyContentAreaScrolled(const FloatSize& delta) OVERRIDE; 125 126 FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const; 127 128 void immediateScrollTo(const FloatPoint&); 129 130 virtual bool isRubberBandInProgress() const OVERRIDE; 131 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 WebCore::IntPoint absoluteScrollPosition() OVERRIDE; 141 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) OVERRIDE; 142 virtual void immediateScrollBy(const FloatSize&) OVERRIDE; 143 virtual void startSnapRubberbandTimer() OVERRIDE; 144 virtual void stopSnapRubberbandTimer() OVERRIDE; 145 virtual void adjustScrollPositionToBoundsIfNecessary() OVERRIDE; 146 147 bool pinnedInDirection(float deltaX, float deltaY); 148 void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*); 149 150 ScrollElasticityController m_scrollElasticityController; 151 Timer<ScrollAnimatorMac> m_snapRubberBandTimer; 152 #endif 153 154 bool m_haveScrolledSincePageLoad; 155 bool m_needsScrollerStyleUpdate; 156 IntRect m_visibleScrollerThumbRect; 157 }; 158 159 } // namespace WebCore 160 161 #endif // ScrollAnimatorMac_h 162