OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 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 ScrollElasticityController_h | |
27 #define ScrollElasticityController_h | |
28 | |
29 #if USE(RUBBER_BANDING) | |
30 | |
31 #include "platform/geometry/FloatPoint.h" | |
32 #include "platform/geometry/FloatSize.h" | |
33 #include "platform/scroll/ScrollTypes.h" | |
34 #include "wtf/Noncopyable.h" | |
35 | |
36 namespace WebCore { | |
37 | |
38 class PlatformWheelEvent; | |
39 | |
40 class ScrollElasticityControllerClient { | |
41 protected: | |
42 virtual ~ScrollElasticityControllerClient() { } | |
43 | |
44 public: | |
45 virtual bool allowsHorizontalStretching() = 0; | |
46 virtual bool allowsVerticalStretching() = 0; | |
47 virtual IntSize stretchAmount() = 0; | |
48 virtual bool pinnedInDirection(const FloatSize&) = 0; | |
49 virtual bool canScrollHorizontally() = 0; | |
50 virtual bool canScrollVertically() = 0; | |
51 virtual bool shouldRubberBandInDirection(ScrollDirection) = 0; | |
52 | |
53 // Return the absolute scroll position, not relative to the scroll origin. | |
54 virtual WebCore::IntPoint absoluteScrollPosition() = 0; | |
55 | |
56 virtual void immediateScrollBy(const FloatSize&) = 0; | |
57 virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&
) = 0; | |
58 virtual void startSnapRubberbandTimer() = 0; | |
59 virtual void stopSnapRubberbandTimer() = 0; | |
60 }; | |
61 | |
62 class ScrollElasticityController { | |
63 WTF_MAKE_NONCOPYABLE(ScrollElasticityController); | |
64 | |
65 public: | |
66 explicit ScrollElasticityController(ScrollElasticityControllerClient*); | |
67 | |
68 bool handleWheelEvent(const PlatformWheelEvent&); | |
69 void snapRubberBandTimerFired(); | |
70 | |
71 bool isRubberBandInProgress() const; | |
72 | |
73 private: | |
74 void stopSnapRubberbandTimer(); | |
75 void snapRubberBand(); | |
76 | |
77 bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&); | |
78 | |
79 ScrollElasticityControllerClient* m_client; | |
80 | |
81 bool m_inScrollGesture; | |
82 bool m_momentumScrollInProgress; | |
83 bool m_ignoreMomentumScrolls; | |
84 | |
85 CFTimeInterval m_lastMomentumScrollTimestamp; | |
86 FloatSize m_overflowScrollDelta; | |
87 FloatSize m_stretchScrollForce; | |
88 FloatSize m_momentumVelocity; | |
89 | |
90 // Rubber band state. | |
91 CFTimeInterval m_startTime; | |
92 FloatSize m_startStretch; | |
93 FloatPoint m_origOrigin; | |
94 FloatSize m_origVelocity; | |
95 | |
96 bool m_snapRubberbandTimerIsActive; | |
97 }; | |
98 | |
99 } // namespace WebCore | |
100 | |
101 #endif // USE(RUBBER_BANDING) | |
102 | |
103 #endif // ScrollElasticityController_h | |
OLD | NEW |