2 * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef ViewGestureController_h
27 #define ViewGestureController_h
29 #include "MessageReceiver.h"
30 #include "WeakObjCPtr.h"
31 #include <WebCore/FloatRect.h>
32 #include <wtf/RetainPtr.h>
33 #include <wtf/RunLoop.h>
39 OBJC_CLASS WKSwipeTransitionController;
41 OBJC_CLASS _UIViewControllerTransitionContext;
42 OBJC_CLASS _UINavigationInteractiveTransitionBase;
46 OBJC_CLASS WKSwipeCancellationTracker;
56 class WebBackForwardListItem;
59 class ViewGestureController : private IPC::MessageReceiver {
60 WTF_MAKE_NONCOPYABLE(ViewGestureController);
62 ViewGestureController(WebPageProxy&);
63 ~ViewGestureController();
65 enum class ViewGestureType {
74 enum class SwipeTransitionStyle {
79 enum class SwipeDirection {
84 enum class PendingSwipeReason {
91 double magnification() const;
93 void handleMagnificationGesture(double scale, WebCore::FloatPoint origin);
94 void handleSmartMagnificationGesture(WebCore::FloatPoint origin);
96 bool handleScrollWheelEvent(NSEvent *);
97 void wheelEventWasNotHandledByWebCore(NSEvent *);
99 void setCustomSwipeViews(Vector<RetainPtr<NSView>> views) { m_customSwipeViews = WTF::move(views); }
100 void setCustomSwipeViewsTopContentInset(float topContentInset) { m_customSwipeViewsTopContentInset = topContentInset; }
101 WebCore::FloatRect windowRelativeBoundsForCustomSwipeViews() const;
103 void endActiveGesture();
105 bool shouldIgnorePinnedState() { return m_shouldIgnorePinnedState; }
106 void setShouldIgnorePinnedState(bool ignore) { m_shouldIgnorePinnedState = ignore; }
108 void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
109 void setAlternateBackForwardListSourceView(WKWebView *);
110 bool canSwipeInDirection(SwipeDirection);
111 void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection);
112 void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled);
113 void willCommitPostSwipeTransitionLayerTree(bool);
114 void setRenderTreeSize(uint64_t);
118 // IPC::MessageReceiver.
119 virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
121 void removeSwipeSnapshot();
122 void swipeSnapshotWatchdogTimerFired();
126 void didCollectGeometryForMagnificationGesture(WebCore::FloatRect visibleContentBounds, bool frameHandlesMagnificationGesture);
127 void didCollectGeometryForSmartMagnificationGesture(WebCore::FloatPoint origin, WebCore::FloatRect renderRect, WebCore::FloatRect visibleContentBounds, bool isReplacedElement, double viewportMinimumScale, double viewportMaximumScale);
128 void didHitRenderTreeSizeThreshold();
130 void endMagnificationGesture();
131 WebCore::FloatPoint scaledMagnificationOrigin(WebCore::FloatPoint origin, double scale);
133 void trackSwipeGesture(NSEvent *, SwipeDirection);
134 void beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection);
135 void handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection);
136 void endSwipeGesture(WebBackForwardListItem* targetItem, bool cancelled);
137 bool deltaIsSufficientToBeginSwipe(NSEvent *);
138 bool scrollEventCanBecomeSwipe(NSEvent *, SwipeDirection&);
139 bool shouldUseSnapshotForSize(ViewSnapshot&, WebCore::FloatSize swipeLayerSize, float topContentInset);
141 CALayer *determineSnapshotLayerParent() const;
142 CALayer *determineLayerAdjacentToSnapshotForParent(SwipeDirection, CALayer *snapshotLayerParent) const;
143 void applyDebuggingPropertiesToSwipeViews();
146 WebPageProxy& m_webPageProxy;
147 ViewGestureType m_activeGestureType;
149 RunLoop::Timer<ViewGestureController> m_swipeWatchdogTimer;
152 RefPtr<WebCore::IOSurface> m_currentSwipeSnapshotSurface;
156 double m_magnification;
157 WebCore::FloatPoint m_magnificationOrigin;
159 WebCore::FloatRect m_lastSmartMagnificationUnscaledTargetRect;
160 bool m_lastMagnificationGestureWasSmartMagnification;
161 WebCore::FloatPoint m_lastSmartMagnificationOrigin;
163 WebCore::FloatRect m_visibleContentRect;
164 bool m_visibleContentRectIsValid;
165 bool m_frameHandlesMagnificationGesture;
167 RetainPtr<WKSwipeCancellationTracker> m_swipeCancellationTracker;
168 RetainPtr<CALayer> m_swipeLayer;
169 RetainPtr<CALayer> m_swipeSnapshotLayer;
170 Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
172 SwipeTransitionStyle m_swipeTransitionStyle;
173 Vector<RetainPtr<NSView>> m_customSwipeViews;
174 float m_customSwipeViewsTopContentInset;
175 WebCore::FloatRect m_currentSwipeCustomViewBounds;
177 // If we need to wait for content to decide if it is going to consume
178 // the scroll event that would have started a swipe, we'll fill these in.
179 PendingSwipeReason m_pendingSwipeReason;
180 SwipeDirection m_pendingSwipeDirection;
181 WebCore::FloatSize m_cumulativeDeltaForPendingSwipe;
183 bool m_shouldIgnorePinnedState;
185 UIView *m_liveSwipeView;
186 RetainPtr<UIView> m_liveSwipeViewClippingView;
187 RetainPtr<UIView> m_snapshotView;
188 RetainPtr<UIView> m_transitionContainerView;
189 RetainPtr<WKSwipeTransitionController> m_swipeInteractiveTransitionDelegate;
190 uint64_t m_snapshotRemovalTargetRenderTreeSize;
191 bool m_shouldRemoveSnapshotWhenTargetRenderTreeSizeHit;
192 WeakObjCPtr<WKWebView> m_alternateBackForwardListSourceView;
193 RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;
197 } // namespace WebKit
199 #endif // ViewGestureController_h