2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef ScrollAnimator_h
33 #define ScrollAnimator_h
35 #include "FloatSize.h"
36 #include "LayoutUnit.h"
37 #include "PlatformWheelEvent.h"
38 #include "ScrollTypes.h"
39 #include <wtf/FastMalloc.h>
40 #include <wtf/Forward.h>
42 #if (ENABLE(RUBBER_BANDING) || ENABLE(CSS_SCROLL_SNAP)) && PLATFORM(MAC)
43 #include "ScrollController.h"
49 class PlatformTouchEvent;
53 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
54 class ScrollAnimator : private ScrollControllerClient {
56 class ScrollAnimator {
58 WTF_MAKE_FAST_ALLOCATED;
60 static std::unique_ptr<ScrollAnimator> create(ScrollableArea&);
62 explicit ScrollAnimator(ScrollableArea&);
63 virtual ~ScrollAnimator();
65 // Computes a scroll destination for the given parameters. Returns false if
66 // already at the destination. Otherwise, starts scrolling towards the
67 // destination and returns true. Scrolling may be immediate or animated.
68 // The base class implementation always scrolls immediately, never animates.
69 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier);
71 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&);
73 ScrollableArea& scrollableArea() const { return m_scrollableArea; }
75 virtual bool handleWheelEvent(const PlatformWheelEvent&);
77 #if ENABLE(TOUCH_EVENTS)
78 virtual bool handleTouchEvent(const PlatformTouchEvent&);
82 virtual void handleWheelEventPhase(PlatformWheelEventPhase) { }
85 void setCurrentPosition(const FloatPoint&);
86 FloatPoint currentPosition() const;
88 virtual void cancelAnimations() { }
89 virtual void serviceScrollAnimations() { }
91 virtual void contentAreaWillPaint() const { }
92 virtual void mouseEnteredContentArea() const { }
93 virtual void mouseExitedContentArea() const { }
94 virtual void mouseMovedInContentArea() const { }
95 virtual void mouseEnteredScrollbar(Scrollbar*) const { }
96 virtual void mouseExitedScrollbar(Scrollbar*) const { }
97 virtual void willStartLiveResize() { }
98 virtual void contentsResized() const { }
99 virtual void willEndLiveResize() { }
100 virtual void contentAreaDidShow() const { }
101 virtual void contentAreaDidHide() const { }
103 virtual void lockOverlayScrollbarStateToHidden(bool) { }
104 virtual bool scrollbarsCanBeActive() const { return true; }
106 virtual void didAddVerticalScrollbar(Scrollbar*) { }
107 virtual void willRemoveVerticalScrollbar(Scrollbar*) { }
108 virtual void didAddHorizontalScrollbar(Scrollbar*) { }
109 virtual void willRemoveHorizontalScrollbar(Scrollbar*) { }
111 virtual void verticalScrollbarLayerDidChange() { }
112 virtual void horizontalScrollbarLayerDidChange() { }
114 virtual bool shouldScrollbarParticipateInHitTesting(Scrollbar*) { return true; }
116 virtual void notifyContentAreaScrolled(const FloatSize& delta) { UNUSED_PARAM(delta); }
118 virtual bool isRubberBandInProgress() const { return false; }
120 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
121 bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
122 void updateScrollAnimatorsAndTimers();
123 LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const override;
124 void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
128 virtual void notifyPositionChanged(const FloatSize& delta);
130 ScrollableArea& m_scrollableArea;
131 #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
132 ScrollController m_scrollController;
134 float m_currentPosX; // We avoid using a FloatPoint in order to reduce
135 float m_currentPosY; // subclass code complexity.
138 } // namespace WebCore
140 #endif // ScrollAnimator_h