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 <WebCore/FloatRect.h>
31 #include <WebCore/Timer.h>
32 #include <wtf/RetainPtr.h>
38 OBJC_CLASS WKSwipeTransitionController;
39 OBJC_CLASS _UIViewControllerTransitionContext;
40 OBJC_CLASS _UINavigationInteractiveTransitionBase;
44 OBJC_CLASS WKSwipeCancellationTracker;
54 class WebBackForwardListItem;
57 class ViewGestureController : private IPC::MessageReceiver {
58 WTF_MAKE_NONCOPYABLE(ViewGestureController);
60 ViewGestureController(WebPageProxy&);
61 ~ViewGestureController();
63 enum class ViewGestureType {
72 enum class SwipeTransitionStyle {
77 enum class SwipeDirection {
82 enum class PendingSwipeReason {
89 double magnification() const;
91 void handleMagnificationGesture(double scale, WebCore::FloatPoint origin);
92 void handleSmartMagnificationGesture(WebCore::FloatPoint origin);
94 bool handleScrollWheelEvent(NSEvent *);
95 void wheelEventWasNotHandledByWebCore(NSEvent *);
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;
101 void endActiveGesture();
103 bool shouldIgnorePinnedState() { return m_shouldIgnorePinnedState; }
104 void setShouldIgnorePinnedState(bool ignore) { m_shouldIgnorePinnedState = ignore; }
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);
115 // IPC::MessageReceiver.
116 virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
118 void removeSwipeSnapshot();
119 void swipeSnapshotWatchdogTimerFired(WebCore::Timer<ViewGestureController>*);
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();
127 void endMagnificationGesture();
128 WebCore::FloatPoint scaledMagnificationOrigin(WebCore::FloatPoint origin, double scale);
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);
138 CALayer *determineSnapshotLayerParent() const;
139 CALayer *determineLayerAdjacentToSnapshotForParent(SwipeDirection, CALayer *snapshotLayerParent) const;
140 void applyDebuggingPropertiesToSwipeViews();
143 WebPageProxy& m_webPageProxy;
144 ViewGestureType m_activeGestureType;
146 WebCore::Timer<ViewGestureController> m_swipeWatchdogTimer;
149 RefPtr<WebCore::IOSurface> m_currentSwipeSnapshotSurface;
153 double m_magnification;
154 WebCore::FloatPoint m_magnificationOrigin;
156 WebCore::FloatRect m_lastSmartMagnificationUnscaledTargetRect;
157 bool m_lastMagnificationGestureWasSmartMagnification;
158 WebCore::FloatPoint m_lastSmartMagnificationOrigin;
160 WebCore::FloatRect m_visibleContentRect;
161 bool m_visibleContentRectIsValid;
162 bool m_frameHandlesMagnificationGesture;
164 RetainPtr<WKSwipeCancellationTracker> m_swipeCancellationTracker;
165 RetainPtr<CALayer> m_swipeLayer;
166 RetainPtr<CALayer> m_swipeSnapshotLayer;
167 Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
169 SwipeTransitionStyle m_swipeTransitionStyle;
170 Vector<RetainPtr<NSView>> m_customSwipeViews;
171 float m_customSwipeViewsTopContentInset;
172 WebCore::FloatRect m_currentSwipeCustomViewBounds;
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;
180 bool m_shouldIgnorePinnedState;
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;
192 } // namespace WebKit
194 #endif // ViewGestureController_h