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 "core/platform/ScrollAnimator.h" 30 #include "core/platform/Timer.h" 31 #include "core/platform/graphics/FloatPoint.h" 32 #include "core/platform/graphics/FloatSize.h" 33 #include "core/platform/graphics/IntRect.h" 34 #include "core/platform/mac/ScrollElasticityController.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 !ENABLE(RUBBER_BANDING) 44 class ScrollElasticityControllerClient { }; 45 #endif 46 47 namespace WebCore { 48 49 class Scrollbar; 50 51 class 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 multiplier); 89 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&); 90 91 #if ENABLE(RUBBER_BANDING) 92 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; 93 #endif 94 95 virtual void handleWheelEventPhase(PlatformWheelEventPhase) OVERRIDE; 96 97 virtual void cancelAnimations(); 98 virtual void setIsActive(); 99 100 virtual void notifyPositionChanged(const FloatSize& delta); 101 virtual void contentAreaWillPaint() const; 102 virtual void mouseEnteredContentArea() const; 103 virtual void mouseExitedContentArea() const; 104 virtual void mouseMovedInContentArea() const; 105 virtual void mouseEnteredScrollbar(Scrollbar*) const; 106 virtual void mouseExitedScrollbar(Scrollbar*) const; 107 virtual void willStartLiveResize(); 108 virtual void contentsResized() const; 109 virtual void willEndLiveResize(); 110 virtual void contentAreaDidShow() const; 111 virtual void contentAreaDidHide() const; 112 void didBeginScrollGesture() const; 113 void didEndScrollGesture() const; 114 void mayBeginScrollGesture() const; 115 116 virtual void finishCurrentScrollAnimations(); 117 118 virtual void didAddVerticalScrollbar(Scrollbar*); 119 virtual void willRemoveVerticalScrollbar(Scrollbar*); 120 virtual void didAddHorizontalScrollbar(Scrollbar*); 121 virtual void willRemoveHorizontalScrollbar(Scrollbar*); 122 123 virtual bool shouldScrollbarParticipateInHitTesting(Scrollbar*); 124 125 virtual void notifyContentAreaScrolled(const FloatSize& delta) OVERRIDE; 126 127 FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const; 128 129 void immediateScrollTo(const FloatPoint&); 130 131 virtual bool isRubberBandInProgress() const OVERRIDE; 132 133 #if ENABLE(RUBBER_BANDING) 134 /// ScrollElasticityControllerClient member functions. 135 virtual IntSize stretchAmount() OVERRIDE; 136 virtual bool allowsHorizontalStretching() OVERRIDE; 137 virtual bool allowsVerticalStretching() OVERRIDE; 138 virtual bool pinnedInDirection(const FloatSize&) OVERRIDE; 139 virtual bool canScrollHorizontally() OVERRIDE; 140 virtual bool canScrollVertically() OVERRIDE; 141 virtual bool shouldRubberBandInDirection(ScrollDirection) OVERRIDE; 142 virtual WebCore::IntPoint absoluteScrollPosition() OVERRIDE; 143 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) OVERRIDE; 144 virtual void immediateScrollBy(const FloatSize&) OVERRIDE; 145 virtual void startSnapRubberbandTimer() OVERRIDE; 146 virtual void stopSnapRubberbandTimer() OVERRIDE; 147 148 bool pinnedInDirection(float deltaX, float deltaY); 149 void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*); 150 151 ScrollElasticityController m_scrollElasticityController; 152 Timer<ScrollAnimatorMac> m_snapRubberBandTimer; 153 #endif 154 155 bool m_haveScrolledSincePageLoad; 156 bool m_needsScrollerStyleUpdate; 157 IntRect m_visibleScrollerThumbRect; 158 }; 159 160 } // namespace WebCore 161 162 #endif // ScrollAnimatorMac_h 163