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 "FloatPoint.h" 32 #include "FloatSize.h" 33 #include "ScrollAnimator.h" 34 #include "Timer.h" 35 #include "WebCoreSystemInterface.h" 36 #include <wtf/RetainPtr.h> 37 38 #ifdef __OBJC__ 39 @class ScrollAnimationHelperDelegate; 40 @class ScrollbarPainterDelegate; 41 @class ScrollbarPainterControllerDelegate; 42 @class ScrollbarPainterDelegate; 43 #else 44 class ScrollAnimationHelperDelegate; 45 class ScrollbarPainterDelegate; 46 class ScrollbarPainterControllerDelegate; 47 class ScrollbarPainterDelegate; 48 #endif 49 50 namespace WebCore { 51 52 class Scrollbar; 53 54 class ScrollAnimatorMac : public ScrollAnimator { 55 public: 56 ScrollAnimatorMac(ScrollableArea*); 57 virtual ~ScrollAnimatorMac(); 58 59 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier); 60 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&); 61 62 #if ENABLE(RUBBER_BANDING) 63 virtual void handleWheelEvent(PlatformWheelEvent&); 64 #if ENABLE(GESTURE_EVENTS) 65 virtual void handleGestureEvent(const PlatformGestureEvent&); 66 #endif 67 #endif 68 69 virtual void cancelAnimations(); 70 71 void immediateScrollToPoint(const FloatPoint& newPosition); 72 void immediateScrollByDeltaX(float deltaX); 73 void immediateScrollByDeltaY(float deltaY); 74 75 void setIsDrawingIntoLayer(bool b) { m_drawingIntoLayer = b; } 76 bool isDrawingIntoLayer() const { return m_drawingIntoLayer; } 77 78 bool haveScrolledSincePageLoad() const { return m_haveScrolledSincePageLoad; } 79 80 #if USE(WK_SCROLLBAR_PAINTER) 81 bool scrollbarPaintTimerIsActive() const; 82 void startScrollbarPaintTimer(); 83 void stopScrollbarPaintTimer(); 84 #endif 85 86 private: 87 RetainPtr<id> m_scrollAnimationHelper; 88 RetainPtr<ScrollAnimationHelperDelegate> m_scrollAnimationHelperDelegate; 89 90 #if USE(WK_SCROLLBAR_PAINTER) 91 RetainPtr<WKScrollbarPainterControllerRef> m_scrollbarPainterController; 92 RetainPtr<ScrollbarPainterControllerDelegate> m_scrollbarPainterControllerDelegate; 93 RetainPtr<id> m_scrollbarPainterDelegate; 94 95 void initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>*); 96 Timer<ScrollAnimatorMac> m_initialScrollbarPaintTimer; 97 #endif 98 99 virtual void notityPositionChanged(); 100 virtual void contentAreaWillPaint() const; 101 virtual void mouseEnteredContentArea() const; 102 virtual void mouseExitedContentArea() const; 103 virtual void mouseMovedInContentArea() const; 104 virtual void willStartLiveResize(); 105 virtual void contentsResized() const; 106 virtual void willEndLiveResize(); 107 virtual void contentAreaDidShow() const; 108 virtual void contentAreaDidHide() const; 109 void didBeginScrollGesture() const; 110 void didEndScrollGesture() const; 111 112 virtual void didAddVerticalScrollbar(Scrollbar*); 113 virtual void willRemoveVerticalScrollbar(Scrollbar*); 114 virtual void didAddHorizontalScrollbar(Scrollbar*); 115 virtual void willRemoveHorizontalScrollbar(Scrollbar*); 116 117 float adjustScrollXPositionIfNecessary(float) const; 118 float adjustScrollYPositionIfNecessary(float) const; 119 FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const; 120 121 #if ENABLE(RUBBER_BANDING) 122 bool allowsVerticalStretching() const; 123 bool allowsHorizontalStretching() const; 124 bool pinnedInDirection(float deltaX, float deltaY); 125 void snapRubberBand(); 126 void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*); 127 void smoothScrollWithEvent(PlatformWheelEvent&); 128 void beginScrollGesture(); 129 void endScrollGesture(); 130 131 bool m_inScrollGesture; 132 bool m_momentumScrollInProgress; 133 bool m_ignoreMomentumScrolls; 134 135 CFTimeInterval m_lastMomemtumScrollTimestamp; 136 FloatSize m_overflowScrollDelta; 137 FloatSize m_stretchScrollForce; 138 FloatSize m_momentumVelocity; 139 140 // Rubber band state. 141 CFTimeInterval m_startTime; 142 FloatSize m_startStretch; 143 FloatPoint m_origOrigin; 144 FloatSize m_origVelocity; 145 Timer<ScrollAnimatorMac> m_snapRubberBandTimer; 146 #endif 147 bool m_drawingIntoLayer; 148 bool m_haveScrolledSincePageLoad; 149 }; 150 151 } // namespace WebCore 152 153 #endif // ENABLE(SMOOTH_SCROLLING) 154 155 #endif // ScrollAnimatorMac_h 156