Changeset 206950 in webkit
- Timestamp:
- Oct 8, 2016 1:31:00 AM (8 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r206937 r206950 1 2016-10-08 Tim Horton <timothy_horton@apple.com> 2 3 Share more code between iOS and macOS ViewGestureController 4 https://bugs.webkit.org/show_bug.cgi?id=163158 5 6 Reviewed by Simon Fraser. 7 8 Share canSwipeInDirection() and the (unused on Mac) alternate back-forward list mechanism. 9 Make ViewGestureController operate in terms of WebPageProxy, not WKWebView, 10 because it shouldn't know anything about WKWebView. 11 Refactor scrollEventCanBecomeSwipe a bit to be less repetitive. 12 13 * UIProcess/API/Cocoa/WKWebView.mm: 14 (-[WKWebView setAllowsBackForwardNavigationGestures:]): 15 * UIProcess/Cocoa/ViewGestureController.cpp: 16 (WebKit::ViewGestureController::ViewGestureController): 17 (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): 18 (WebKit::ViewGestureController::canSwipeInDirection): 19 (WebKit::ViewGestureController::gestureControllerForPage): Deleted. 20 * UIProcess/Cocoa/ViewGestureController.h: 21 * UIProcess/WebPageProxy.cpp: 22 (WebKit::WebPageProxy::WebPageProxy): 23 * UIProcess/WebPageProxy.h: 24 (WebKit::WebPageProxy::createWeakPtr): 25 * UIProcess/ios/ViewGestureControllerIOS.mm: 26 (WebKit::ViewGestureController::beginSwipeGesture): 27 (WebKit::ViewGestureController::setAlternateBackForwardListSourceView): Deleted. 28 (WebKit::ViewGestureController::canSwipeInDirection): Deleted. 29 * UIProcess/mac/ViewGestureControllerMac.mm: 30 (WebKit::ViewGestureController::PendingSwipeTracker::PendingSwipeTracker): 31 (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe): 32 (WebKit::ViewGestureController::PendingSwipeTracker::tryToStartSwipe): 33 1 34 2016-10-07 Anders Carlsson <andersca@apple.com> 2 35 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
r206829 r206950 2199 2199 _gestureController = std::make_unique<WebKit::ViewGestureController>(*_page); 2200 2200 _gestureController->installSwipeHandler(self, [self scrollView]); 2201 _gestureController->setAlternateBackForwardListSource View([_configuration _alternateWebViewForNavigationGestures]);2201 _gestureController->setAlternateBackForwardListSourcePage([_configuration _alternateWebViewForNavigationGestures]->_page.get()); 2202 2202 } 2203 2203 } else -
trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.cpp
r206936 r206950 30 30 #import "RemoteLayerTreeDrawingAreaProxy.h" 31 31 #import "ViewGestureControllerMessages.h" 32 #import "WebBackForwardList.h" 32 33 #import "WebPageProxy.h" 33 34 #import "WebProcessProxy.h" … … 60 61 , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::checkForActiveLoads) 61 62 #if PLATFORM(MAC) 62 , m_pendingSwipeTracker(webPageProxy, std::bind(&ViewGestureController::trackSwipeGesture, this, std::placeholders::_1, std::placeholders::_2))63 , m_pendingSwipeTracker(webPageProxy, *this) 63 64 #endif 64 65 { … … 84 85 return gestureControllerIter->value; 85 86 } 87 88 void ViewGestureController::setAlternateBackForwardListSourcePage(WebPageProxy* page) 89 { 90 if (page) 91 m_alternateBackForwardListSourcePage = page->createWeakPtr(); 92 else 93 m_alternateBackForwardListSourcePage.clear(); 94 } 95 96 bool ViewGestureController::canSwipeInDirection(SwipeDirection direction) const 97 { 98 RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get(); 99 auto& backForwardList = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage->backForwardList() : m_webPageProxy.backForwardList(); 100 if (direction == SwipeDirection::Back) 101 return !!backForwardList.backItem(); 102 return !!backForwardList.forwardItem(); 103 } 104 86 105 87 106 void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame() -
trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.h
r206936 r206950 29 29 #include "MessageReceiver.h" 30 30 #include "SameDocumentNavigationType.h" 31 #include "WeakObjCPtr.h"32 31 #include <WebCore/Color.h> 33 32 #include <WebCore/FloatRect.h> … … 36 35 #include <wtf/RetainPtr.h> 37 36 #include <wtf/RunLoop.h> 38 39 // FIXME: Move this file out of the mac/ subdirectory. 37 #include <wtf/WeakPtr.h> 40 38 41 39 OBJC_CLASS CALayer; … … 44 42 OBJC_CLASS UIView; 45 43 OBJC_CLASS WKSwipeTransitionController; 46 OBJC_CLASS WKWebView;47 44 OBJC_CLASS _UINavigationInteractiveTransitionBase; 48 45 OBJC_CLASS _UIViewControllerOneToOneTransitionContext; … … 110 107 #else 111 108 void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView); 112 void setAlternateBackForwardListSourceView(WKWebView *);113 bool canSwipeInDirection(SwipeDirection);114 109 void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection); 115 110 void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled); … … 117 112 void setRenderTreeSize(uint64_t); 118 113 #endif 114 115 void setAlternateBackForwardListSourcePage(WebPageProxy*); 116 117 bool canSwipeInDirection(SwipeDirection) const; 119 118 120 119 WebCore::Color backgroundColorForCurrentSnapshot() const { return m_backgroundColorForCurrentSnapshot; } … … 203 202 class PendingSwipeTracker { 204 203 public: 205 PendingSwipeTracker(WebPageProxy&, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback);204 PendingSwipeTracker(WebPageProxy&, ViewGestureController&); 206 205 bool handleEvent(NSEvent *); 207 206 void eventWasNotHandledByWebCore(NSEvent *); … … 228 227 bool m_shouldIgnorePinnedState { false }; 229 228 230 std::function<void(NSEvent *, SwipeDirection)> m_trackSwipeCallback;229 ViewGestureController& m_viewGestureController; 231 230 WebPageProxy& m_webPageProxy; 232 231 }; … … 239 238 240 239 WebCore::Color m_backgroundColorForCurrentSnapshot; 240 241 WeakPtr<WebPageProxy> m_alternateBackForwardListSourcePage; 242 RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe; 241 243 242 244 #if PLATFORM(MAC) … … 278 280 RetainPtr<_UIViewControllerOneToOneTransitionContext> m_swipeTransitionContext; 279 281 uint64_t m_snapshotRemovalTargetRenderTreeSize { 0 }; 280 WeakObjCPtr<WKWebView> m_alternateBackForwardListSourceView;281 RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;282 282 uint64_t m_gesturePendingSnapshotRemoval { 0 }; 283 283 #endif -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r206929 r206950 451 451 , m_potentiallyChangedViewStateFlags(ViewState::NoFlags) 452 452 , m_viewStateChangeWantsSynchronousReply(false) 453 , m_weakPtrFactory(this) 453 454 { 454 455 m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore); -
trunk/Source/WebKit2/UIProcess/WebPageProxy.h
r206937 r206950 1130 1130 void gamepadActivity(const Vector<GamepadData>&); 1131 1131 #endif 1132 1133 WeakPtr<WebPageProxy> createWeakPtr() const { return m_weakPtrFactory.createWeakPtr(); } 1132 1134 1133 1135 private: … … 1890 1892 bool m_syncNavigationActionHasDownloadAttribute { false }; 1891 1893 #endif 1894 1895 WeakPtrFactory<WebPageProxy> m_weakPtrFactory; 1892 1896 }; 1893 1897 -
trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm
r206833 r206950 35 35 #import "WKBackForwardListItemInternal.h" 36 36 #import "WKWebViewInternal.h" 37 #import "WeakObjCPtr.h" 37 38 #import "WebBackForwardList.h" 38 39 #import "WebPageGroup.h" … … 141 142 } 142 143 143 void ViewGestureController::setAlternateBackForwardListSourceView(WKWebView *view)144 {145 m_alternateBackForwardListSourceView = view;146 }147 148 144 void ViewGestureController::installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView) 149 145 { … … 160 156 m_webPageProxy.recordAutomaticNavigationSnapshot(); 161 157 162 m_webPageProxyForBackForwardListForCurrentSwipe = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page : &m_webPageProxy; 158 RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get(); 159 m_webPageProxyForBackForwardListForCurrentSwipe = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage.get() : &m_webPageProxy; 160 163 161 m_webPageProxyForBackForwardListForCurrentSwipe->navigationGestureDidBegin(); 164 162 if (&m_webPageProxy != m_webPageProxyForBackForwardListForCurrentSwipe) … … 240 238 } 241 239 242 bool ViewGestureController::canSwipeInDirection(SwipeDirection direction)243 {244 auto& backForwardList = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page->backForwardList() : m_webPageProxy.backForwardList();245 if (direction == SwipeDirection::Back)246 return !!backForwardList.backItem();247 return !!backForwardList.forwardItem();248 }249 250 240 void ViewGestureController::endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *context, bool cancelled) 251 241 { -
trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm
r206930 r206950 273 273 } 274 274 275 ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback)276 : m_ trackSwipeCallback(WTFMove(trackSwipeCallback))275 ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, ViewGestureController& viewGestureController) 276 : m_viewGestureController(viewGestureController) 277 277 , m_webPageProxy(webPageProxy) 278 278 { … … 293 293 bool isPinnedToRight = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToRightSide(); 294 294 295 bool willSwipeBack = false; 296 bool willSwipeForward = false; 297 if (m_webPageProxy.userInterfaceLayoutDirection() == WebCore::UserInterfaceLayoutDirection::LTR) { 298 willSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().backItem(); 299 willSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().forwardItem(); 300 } else { 301 willSwipeBack = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().backItem(); 302 willSwipeForward = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().forwardItem(); 303 } 304 if (!willSwipeBack && !willSwipeForward) 305 return false; 306 307 potentialSwipeDirection = willSwipeBack ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward; 308 309 return true; 295 bool tryingToSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft; 296 bool tryingToSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight; 297 if (m_webPageProxy.userInterfaceLayoutDirection() != WebCore::UserInterfaceLayoutDirection::LTR) 298 std::swap(tryingToSwipeBack, tryingToSwipeForward); 299 300 if (!tryingToSwipeBack && !tryingToSwipeForward) 301 return false; 302 303 potentialSwipeDirection = tryingToSwipeBack ? SwipeDirection::Back : SwipeDirection::Forward; 304 return m_viewGestureController.canSwipeInDirection(potentialSwipeDirection); 310 305 } 311 306 … … 373 368 374 369 if (std::abs(m_cumulativeDelta.width()) >= minimumHorizontalSwipeDistance) 375 m_ trackSwipeCallback(event, m_direction);370 m_viewGestureController.trackSwipeGesture(event, m_direction); 376 371 else 377 372 m_state = State::InsufficientMagnitude;
Note: See TracChangeset
for help on using the changeset viewer.