Add WTF::move()
[WebKit-https.git] / Source / WebKit2 / UIProcess / mac / ViewGestureController.h
1 /*
2  * Copyright (C) 2013, 2014 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 ViewGestureController_h
27 #define ViewGestureController_h
28
29 #include "MessageReceiver.h"
30 #include <WebCore/FloatRect.h>
31 #include <WebCore/Timer.h>
32 #include <wtf/RetainPtr.h>
33
34 OBJC_CLASS CALayer;
35
36 #if PLATFORM(IOS)
37 OBJC_CLASS UIView;
38 OBJC_CLASS WKSwipeTransitionController;
39 OBJC_CLASS _UIViewControllerTransitionContext;
40 OBJC_CLASS _UINavigationInteractiveTransitionBase;
41 #else
42 OBJC_CLASS NSEvent;
43 OBJC_CLASS NSView;
44 OBJC_CLASS WKSwipeCancellationTracker;
45 #endif
46
47 namespace WebCore {
48 class IOSurface;
49 }
50
51 namespace WebKit {
52
53 struct ViewSnapshot;
54 class WebBackForwardListItem;
55 class WebPageProxy;
56
57 class ViewGestureController : private IPC::MessageReceiver {
58     WTF_MAKE_NONCOPYABLE(ViewGestureController);
59 public:
60     ViewGestureController(WebPageProxy&);
61     ~ViewGestureController();
62     
63     enum class ViewGestureType {
64         None,
65 #if PLATFORM(MAC)
66         Magnification,
67         SmartMagnification,
68 #endif
69         Swipe
70     };
71     
72     enum class SwipeTransitionStyle {
73         Overlap,
74         Push
75     };
76     
77     enum class SwipeDirection {
78         Left,
79         Right
80     };
81
82     enum class PendingSwipeReason {
83         None,
84         WebCoreMayScroll,
85         InsufficientMagnitude
86     };
87     
88 #if PLATFORM(MAC)
89     double magnification() const;
90
91     void handleMagnificationGesture(double scale, WebCore::FloatPoint origin);
92     void handleSmartMagnificationGesture(WebCore::FloatPoint origin);
93
94     bool handleScrollWheelEvent(NSEvent *);
95     void wheelEventWasNotHandledByWebCore(NSEvent *);
96
97     void setCustomSwipeViews(Vector<RetainPtr<NSView>> views) { m_customSwipeViews = WTF::move(views); }
98     void setCustomSwipeViewsTopContentInset(float topContentInset) { m_customSwipeViewsTopContentInset = topContentInset; }
99     WebCore::FloatRect windowRelativeBoundsForCustomSwipeViews() const;
100
101     void endActiveGesture();
102
103     bool shouldIgnorePinnedState() { return m_shouldIgnorePinnedState; }
104     void setShouldIgnorePinnedState(bool ignore) { m_shouldIgnorePinnedState = ignore; }
105 #else
106     void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
107     bool canSwipeInDirection(SwipeDirection);
108     void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection);
109     void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled);
110     void willCommitPostSwipeTransitionLayerTree(bool);
111     void setRenderTreeSize(uint64_t);
112 #endif
113
114 private:
115     // IPC::MessageReceiver.
116     virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
117     
118     void removeSwipeSnapshot();
119     void swipeSnapshotWatchdogTimerFired(WebCore::Timer<ViewGestureController>*);
120
121 #if PLATFORM(MAC)
122     // Message handlers.
123     void didCollectGeometryForMagnificationGesture(WebCore::FloatRect visibleContentBounds, bool frameHandlesMagnificationGesture);
124     void didCollectGeometryForSmartMagnificationGesture(WebCore::FloatPoint origin, WebCore::FloatRect renderRect, WebCore::FloatRect visibleContentBounds, bool isReplacedElement, double viewportMinimumScale, double viewportMaximumScale);
125     void didHitRenderTreeSizeThreshold();
126
127     void endMagnificationGesture();
128     WebCore::FloatPoint scaledMagnificationOrigin(WebCore::FloatPoint origin, double scale);
129
130     void trackSwipeGesture(NSEvent *, SwipeDirection);
131     void beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection);
132     void handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection);
133     void endSwipeGesture(WebBackForwardListItem* targetItem, bool cancelled);
134     bool deltaIsSufficientToBeginSwipe(NSEvent *);
135     bool scrollEventCanBecomeSwipe(NSEvent *, SwipeDirection&);
136     bool shouldUseSnapshotForSize(ViewSnapshot&, WebCore::FloatSize swipeLayerSize, float topContentInset);
137
138     CALayer *determineSnapshotLayerParent() const;
139     CALayer *determineLayerAdjacentToSnapshotForParent(SwipeDirection, CALayer *snapshotLayerParent) const;
140     void applyDebuggingPropertiesToSwipeViews();
141 #endif
142     
143     WebPageProxy& m_webPageProxy;
144     ViewGestureType m_activeGestureType;
145     
146     WebCore::Timer<ViewGestureController> m_swipeWatchdogTimer;
147
148 #if USE(IOSURFACE)
149     RefPtr<WebCore::IOSurface> m_currentSwipeSnapshotSurface;
150 #endif
151
152 #if PLATFORM(MAC)
153     double m_magnification;
154     WebCore::FloatPoint m_magnificationOrigin;
155
156     WebCore::FloatRect m_lastSmartMagnificationUnscaledTargetRect;
157     bool m_lastMagnificationGestureWasSmartMagnification;
158     WebCore::FloatPoint m_lastSmartMagnificationOrigin;
159
160     WebCore::FloatRect m_visibleContentRect;
161     bool m_visibleContentRectIsValid;
162     bool m_frameHandlesMagnificationGesture;
163
164     RetainPtr<WKSwipeCancellationTracker> m_swipeCancellationTracker;
165     RetainPtr<CALayer> m_swipeLayer;
166     RetainPtr<CALayer> m_swipeSnapshotLayer;
167     Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
168
169     SwipeTransitionStyle m_swipeTransitionStyle;
170     Vector<RetainPtr<NSView>> m_customSwipeViews;
171     float m_customSwipeViewsTopContentInset;
172     WebCore::FloatRect m_currentSwipeCustomViewBounds;
173
174     // If we need to wait for content to decide if it is going to consume
175     // the scroll event that would have started a swipe, we'll fill these in.
176     PendingSwipeReason m_pendingSwipeReason;
177     SwipeDirection m_pendingSwipeDirection;
178     WebCore::FloatSize m_cumulativeDeltaForPendingSwipe;
179
180     bool m_shouldIgnorePinnedState;
181 #else    
182     UIView *m_liveSwipeView;
183     RetainPtr<UIView> m_liveSwipeViewClippingView;
184     RetainPtr<UIView> m_snapshotView;
185     RetainPtr<UIView> m_transitionContainerView;
186     RetainPtr<WKSwipeTransitionController> m_swipeInteractiveTransitionDelegate;
187     uint64_t m_snapshotRemovalTargetRenderTreeSize;
188     bool m_shouldRemoveSnapshotWhenTargetRenderTreeSizeHit;
189 #endif
190 };
191
192 } // namespace WebKit
193
194 #endif // ViewGestureController_h