Changeset 163795 in webkit


Ignore:
Timestamp:
Feb 10, 2014 10:09:55 AM (10 years ago)
Author:
timothy_horton@apple.com
Message:

[iOS][wk2] WebKit2 View Gestures (Swipe): Forward swipe gesture
https://bugs.webkit.org/show_bug.cgi?id=128523
<rdar://problem/16020378>

Reviewed by Darin Adler.

We can't install the gesture recognizer on a view that's going to be
reparented during the swipe, because the gesture will be cancelled.
Install the recognizer on the WKView and move the WKView's scrollview
child around instead.

  • UIProcess/API/ios/WKViewIOS.mm:

(-[WKView setAllowsBackForwardNavigationGestures:]):
We'll install the gesture recognizer on the WKView, but swipe the scrollview.

  • UIProcess/ios/ViewGestureControllerIOS.mm:

(-[WKSwipeTransitionController initWithViewGestureController:gestureRecognizerView:]):
Clarify that WKSwipeTransitionController gets handed only the view to install the gesture recognizer on.
(-[WKSwipeTransitionController gestureRecognizerForInteractiveTransition:WithTarget:action:]):
Use public enum values so we can get rid of one private header.

(WebKit::ViewGestureController::installSwipeHandler):
Separate out the gesture recognizer view from the one that gets swiped.

(WebKit::ViewGestureController::beginSwipeGesture):
Record a snapshot before beginning the swipe. This is important for the back-then-forward
swipe case, and matches the behavior of the Mac implementation.

(WebKit::ViewGestureController::endSwipeGesture):

  • UIProcess/mac/ViewGestureController.h:

Slight geometry adjustments due to the change in targetted view.

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r163794 r163795  
     12014-02-10  Tim Horton  <timothy_horton@apple.com>
     2
     3        [iOS][wk2] WebKit2 View Gestures (Swipe): Forward swipe gesture
     4        https://bugs.webkit.org/show_bug.cgi?id=128523
     5        <rdar://problem/16020378>
     6
     7        Reviewed by Darin Adler.
     8
     9        We can't install the gesture recognizer on a view that's going to be
     10        reparented during the swipe, because the gesture will be cancelled.
     11        Install the recognizer on the WKView and move the WKView's scrollview
     12        child around instead.
     13
     14        * UIProcess/API/ios/WKViewIOS.mm:
     15        (-[WKView setAllowsBackForwardNavigationGestures:]):
     16        We'll install the gesture recognizer on the WKView, but swipe the scrollview.
     17
     18        * UIProcess/ios/ViewGestureControllerIOS.mm:
     19        (-[WKSwipeTransitionController initWithViewGestureController:gestureRecognizerView:]):
     20        Clarify that WKSwipeTransitionController gets handed only the view to install the gesture recognizer on.
     21        (-[WKSwipeTransitionController gestureRecognizerForInteractiveTransition:WithTarget:action:]):
     22        Use public enum values so we can get rid of one private header.
     23
     24        (WebKit::ViewGestureController::installSwipeHandler):
     25        Separate out the gesture recognizer view from the one that gets swiped.
     26
     27        (WebKit::ViewGestureController::beginSwipeGesture):
     28        Record a snapshot before beginning the swipe. This is important for the back-then-forward
     29        swipe case, and matches the behavior of the Mac implementation.
     30
     31        (WebKit::ViewGestureController::endSwipeGesture):
     32        * UIProcess/mac/ViewGestureController.h:
     33        Slight geometry adjustments due to the change in targetted view.
     34
    1352014-02-10  Filip Pizlo  <fpizlo@apple.com>
    236
  • trunk/Source/WebKit2/UIProcess/API/ios/WKViewIOS.mm

    r163666 r163795  
    117117    if (allowsBackForwardNavigationGestures && !_gestureController) {
    118118        _gestureController = std::make_unique<ViewGestureController>(*webPageProxy);
    119         _gestureController->installSwipeHandler(self);
     119        _gestureController->installSwipeHandler(self, [self scrollView]);
    120120    } else
    121121        _gestureController = nullptr;
  • trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm

    r163666 r163795  
    3636#import "WebProcessProxy.h"
    3737#import <QuartzCore/QuartzCore.h>
    38 #import <UIKit/UIApplication_Private.h>
    3938#import <UIKit/UIScreenEdgePanGestureRecognizer.h>
    4039#import <UIKit/UIViewControllerTransitioning_Private.h>
     
    5150
    5251@interface WKSwipeTransitionController : NSObject <_UINavigationInteractiveTransitionBaseDelegate>
    53 - (instancetype)initWithViewGestureController:(WebKit::ViewGestureController*)gestureController swipingView:(UIView *)view;
     52- (instancetype)initWithViewGestureController:(WebKit::ViewGestureController*)gestureController gestureRecognizerView:(UIView *)gestureRecognizerView;
    5453@end
    5554
     
    5857    WebKit::ViewGestureController *_gestureController;
    5958    RetainPtr<_UINavigationInteractiveTransitionBase> _backTransitionController;
     59    RetainPtr<_UINavigationInteractiveTransitionBase> _forwardTransitionController;
    6060}
    6161
     
    6363static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 3_s;
    6464
    65 - (instancetype)initWithViewGestureController:(WebKit::ViewGestureController*)gestureController swipingView:(UIView *)view
     65- (instancetype)initWithViewGestureController:(WebKit::ViewGestureController*)gestureController gestureRecognizerView:(UIView *)gestureRecognizerView
    6666{
    6767    self = [super init];
     
    7070
    7171        _backTransitionController = adoptNS([_UINavigationInteractiveTransitionBase alloc]);
    72         _backTransitionController = [_backTransitionController initWithGestureRecognizerView:view animator:nil delegate:self];
     72        _backTransitionController = [_backTransitionController initWithGestureRecognizerView:gestureRecognizerView animator:nil delegate:self];
     73       
     74        _forwardTransitionController = adoptNS([_UINavigationInteractiveTransitionBase alloc]);
     75        _forwardTransitionController = [_forwardTransitionController initWithGestureRecognizerView:gestureRecognizerView animator:nil delegate:self];
     76        [_forwardTransitionController setShouldReverseTranslation:YES];
    7377    }
    7478    return self;
     
    105109    switch ([self directionForTransition:transition]) {
    106110    case WebKit::ViewGestureController::SwipeDirection::Left:
    107         [recognizer setEdges:UIMinXEdge];
     111        [recognizer setEdges:UIRectEdgeLeft];
    108112        break;
    109113    case WebKit::ViewGestureController::SwipeDirection::Right:
    110         [recognizer setEdges:UIMaxXEdge];
     114        [recognizer setEdges:UIRectEdgeRight];
    111115        break;
    112116    }
     
    130134}
    131135
    132 void ViewGestureController::installSwipeHandler(UIView *view)
     136void ViewGestureController::installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView)
    133137{
    134138    ASSERT(!m_swipeInteractiveTransitionDelegate);
    135     m_swipeInteractiveTransitionDelegate = adoptNS([[WKSwipeTransitionController alloc] initWithViewGestureController:this swipingView:view]);
    136     m_liveSwipeView = view;
     139    m_swipeInteractiveTransitionDelegate = adoptNS([[WKSwipeTransitionController alloc] initWithViewGestureController:this gestureRecognizerView:gestureRecognizerView]);
     140    m_liveSwipeView = swipingView;
    137141}
    138142
     
    141145    if (m_activeGestureType != ViewGestureType::None)
    142146        return;
     147   
     148    ViewSnapshotStore::shared().recordSnapshot(m_webPageProxy);
    143149
    144150    WebKit::WebBackForwardListItem* targetItem = direction == SwipeDirection::Left ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
     
    147153
    148154    RetainPtr<UIViewController> snapshotViewController = adoptNS([[UIViewController alloc] init]);
    149     m_snapshotView = adoptNS([[UIView alloc] initWithFrame:[m_liveSwipeView bounds]]);
     155    m_snapshotView = adoptNS([[UIView alloc] initWithFrame:[m_liveSwipeView frame]]);
    150156    if (snapshot) {
    151157#if USE(IOSURFACE)
     
    172178    [targettedViewController setView:m_liveSwipeView];
    173179
    174     m_originalLiveSwipeViewFrame = m_liveSwipeView.frame;
    175     m_liveSwipeView.frame = m_liveSwipeView.bounds;
    176    
    177180    UINavigationControllerOperation transitionOperation = direction == SwipeDirection::Left ? UINavigationControllerOperationPop : UINavigationControllerOperationPush;
    178181    RetainPtr<_UINavigationParallaxTransition> animationController = adoptNS([[_UINavigationParallaxTransition alloc] initWithCurrentOperation:transitionOperation]);
     
    182185    [transitionContext _setToViewController:snapshotViewController.get()];
    183186    [transitionContext _setContainerView:m_transitionContainerView.get()];
    184     [transitionContext _setFromStartFrame:[m_liveSwipeView bounds]];
    185     [transitionContext _setToEndFrame:[m_liveSwipeView bounds]];
     187    [transitionContext _setFromStartFrame:[m_liveSwipeView frame]];
     188    [transitionContext _setToEndFrame:[m_liveSwipeView frame]];
    186189    [transitionContext _setToStartFrame:CGRectZero];
    187190    [transitionContext _setFromEndFrame:CGRectZero];
     
    215218    m_transitionContainerView = nullptr;
    216219   
    217     [m_liveSwipeView setFrame:m_originalLiveSwipeViewFrame];
    218     [m_snapshotView setFrame:m_originalLiveSwipeViewFrame];
    219    
    220220    if (cancelled) {
    221221        removeSwipeSnapshot();
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h

    r163666 r163795  
    8888    void endActiveGesture();
    8989#else
    90     void installSwipeHandler(UIView *);
     90    void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
    9191    bool canSwipeInDirection(SwipeDirection);
    9292    void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection);
     
    145145    bool m_hasPendingSwipe;
    146146    SwipeDirection m_pendingSwipeDirection;
    147 #else
    148     CGRect m_originalLiveSwipeViewFrame;
    149    
     147#else   
    150148    UIView *m_liveSwipeView;
    151149    RetainPtr<UIView> m_snapshotView;
Note: See TracChangeset for help on using the changeset viewer.