Title: [170926] trunk/Source/WebKit2
Revision
170926
Author
benja...@webkit.org
Date
2014-07-09 12:47:44 -0700 (Wed, 09 Jul 2014)

Log Message

[iOS][WK2] subviews of the unscaled view drift out during CA animations
https://bugs.webkit.org/show_bug.cgi?id=134751

Patch by Benjamin Poulain <bpoul...@apple.com> on 2014-07-09
Reviewed by Enrica Casucci.

It is not possible to animate the WKContentView and the inverse view in such a way
that the combined matrix remain the identity for every frame of the animation.

This patch solves the issue by moving the unscaled view as a sibling of WKContentView
instead of a child so that we do not need to update two scales simultaneously.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
(-[WKWebView _processDidExit]):
(-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
Set the z scale to 1 or no coordinate transform will work with this view.

(-[WKWebView _beginAnimatedResizeWithUpdates:]):
(-[WKWebView _endAnimatedResize]):
* UIProcess/ios/WKContentView.mm:
(-[WKContentView didUpdateVisibleRect:unobscuredRect:unobscuredRectInScrollViewCoordinates:scale:minimumScale:inStableState:isChangingObscuredInsetsInteractively:]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]):
Since we need to observe changes inside the animation block, the code now use KVO to observe changes of scale.

(-[WKContentView cleanupInteraction]):
(-[WKContentView unscaledView]):
(-[WKContentView inverseScale]):
(-[WKContentView observeValueForKeyPath:ofObject:change:context:]):
We update the utility views as usual. The extra bits here are to deal with views coming in during an animation.

If a new utility view comes in during a scaling animation, we do not want to start a new animation with the same curve
to end up at the right place. To avoid any issue, we just hide the view until the animation is finished.

(-[WKContentView hitTest:withEvent:]):
(-[WKContentView _showTapHighlight]):
(-[WKContentView _updateUnscaledView]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (170925 => 170926)


--- trunk/Source/WebKit2/ChangeLog	2014-07-09 19:31:33 UTC (rev 170925)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-09 19:47:44 UTC (rev 170926)
@@ -1,3 +1,44 @@
+2014-07-09  Benjamin Poulain  <bpoul...@apple.com>
+
+        [iOS][WK2] subviews of the unscaled view drift out during CA animations
+        https://bugs.webkit.org/show_bug.cgi?id=134751
+
+        Reviewed by Enrica Casucci.
+
+        It is not possible to animate the WKContentView and the inverse view in such a way
+        that the combined matrix remain the identity for every frame of the animation.
+
+        This patch solves the issue by moving the unscaled view as a sibling of WKContentView
+        instead of a child so that we do not need to update two scales simultaneously.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        (-[WKWebView _processDidExit]):
+        (-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
+        Set the z scale to 1 or no coordinate transform will work with this view.
+
+        (-[WKWebView _beginAnimatedResizeWithUpdates:]):
+        (-[WKWebView _endAnimatedResize]):
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView didUpdateVisibleRect:unobscuredRect:unobscuredRectInScrollViewCoordinates:scale:minimumScale:inStableState:isChangingObscuredInsetsInteractively:]):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView setupInteraction]):
+        Since we need to observe changes inside the animation block, the code now use KVO to observe changes of scale.
+
+        (-[WKContentView cleanupInteraction]):
+        (-[WKContentView unscaledView]):
+        (-[WKContentView inverseScale]):
+        (-[WKContentView observeValueForKeyPath:ofObject:change:context:]):
+        We update the utility views as usual. The extra bits here are to deal with views coming in during an animation.
+
+        If a new utility view comes in during a scaling animation, we do not want to start a new animation with the same curve
+        to end up at the right place. To avoid any issue, we just hide the view until the animation is finished.
+
+        (-[WKContentView hitTest:withEvent:]):
+        (-[WKContentView _showTapHighlight]):
+        (-[WKContentView _updateUnscaledView]): Deleted.
+
 2014-07-09  Tim Horton  <timothy_hor...@apple.com>
 
         Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (170925 => 170926)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-07-09 19:31:33 UTC (rev 170925)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-07-09 19:47:44 UTC (rev 170926)
@@ -288,6 +288,7 @@
     [_contentView layer].anchorPoint = CGPointZero;
     [_contentView setFrame:bounds];
     [_scrollView addSubview:_contentView.get()];
+    [_scrollView addSubview:[_contentView unscaledView]];
     _viewportMetaTagWidth = -1;
 
     [self _frameOrBoundsChanged];
@@ -605,6 +606,7 @@
         _customContentFixedOverlayView = adoptNS([[UIView alloc] initWithFrame:self.bounds]);
         [_customContentFixedOverlayView setUserInteractionEnabled:NO];
 
+        [[_contentView unscaledView] removeFromSuperview];
         [_contentView removeFromSuperview];
         [_scrollView addSubview:_customContentView.get()];
         [self addSubview:_customContentFixedOverlayView.get()];
@@ -619,6 +621,7 @@
         _customContentFixedOverlayView = nullptr;
 
         [_scrollView addSubview:_contentView.get()];
+        [_scrollView addSubview:[_contentView unscaledView]];
         [_scrollView setContentSize:roundScrollViewContentSize(*_page, [_contentView frame].size)];
 
         [_customContentFixedOverlayView setFrame:self.bounds];
@@ -718,6 +721,7 @@
     if (!_customContentView && _isAnimatingResize) {
         NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
         [_scrollView insertSubview:_contentView.get() atIndex:indexOfResizeAnimationView];
+        [_scrollView insertSubview:[_contentView unscaledView] atIndex:indexOfResizeAnimationView + 1];
         [_resizeAnimationView removeFromSuperview];
         _resizeAnimationView = nil;
 
@@ -838,7 +842,7 @@
         CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
         double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
         double scale = newScale / currentTargetScale;
-        _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
+        _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 1);
 
         CGPoint newContentOffset = [self _adjustedContentOffset:CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale)];
         CGPoint currentContentOffset = [_scrollView contentOffset];
@@ -2101,6 +2105,7 @@
     _resizeAnimationView = adoptNS([[UIView alloc] init]);
     [_scrollView insertSubview:_resizeAnimationView.get() atIndex:indexOfContentView];
     [_resizeAnimationView addSubview:_contentView.get()];
+    [_resizeAnimationView addSubview:[_contentView unscaledView]];
 
     CGSize contentSizeInContentViewCoordinates = [_contentView bounds].size;
     [_scrollView setMinimumZoomScale:std::min(newMinimumLayoutSize.width() / contentSizeInContentViewCoordinates.width, [_scrollView minimumZoomScale])];
@@ -2159,6 +2164,7 @@
 
     NSUInteger indexOfResizeAnimationView = [[_scrollView subviews] indexOfObject:_resizeAnimationView.get()];
     [_scrollView insertSubview:_contentView.get() atIndex:indexOfResizeAnimationView];
+    [_scrollView insertSubview:[_contentView unscaledView] atIndex:indexOfResizeAnimationView + 1];
 
     CALayer *contentViewLayer = [_contentView layer];
     CGFloat adjustmentScale = _resizeAnimationTransformAdjustments.m11;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (170925 => 170926)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2014-07-09 19:31:33 UTC (rev 170925)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm	2014-07-09 19:47:44 UTC (rev 170926)
@@ -574,8 +574,6 @@
 - (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect unobscuredRectInScrollViewCoordinates:(CGRect)unobscuredRectInScrollViewCoordinates
     scale:(CGFloat)zoomScale minimumScale:(CGFloat)minimumScale inStableState:(BOOL)isStableState isChangingObscuredInsetsInteractively:(BOOL)isChangingObscuredInsetsInteractively
 {
-    double oldDisplayedContentScale = _page->displayedContentScale();
-
     double timestamp = monotonicallyIncreasingTime();
     HistoricalVelocityData::VelocityData velocityData;
     if (!isStableState)
@@ -593,9 +591,6 @@
 
     if (auto drawingArea = _page->drawingArea())
         drawingArea->updateDebugIndicator();
-
-    if (!withinEpsilon(oldDisplayedContentScale, zoomScale))
-        [self _updateUnscaledView];
         
     [self updateFixedClippingView:fixedPositionRect];
 }

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (170925 => 170926)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2014-07-09 19:31:33 UTC (rev 170925)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2014-07-09 19:47:44 UTC (rev 170926)
@@ -101,7 +101,7 @@
     RetainPtr<UITextInputTraits> _traits;
     RetainPtr<UIWebFormAccessory> _formAccessoryView;
     RetainPtr<_UIHighlightView> _highlightView;
-    RetainPtr<UIView> _inverseScaleRootView;
+    RetainPtr<UIView> _interactionViewsContainerView;
     RetainPtr<NSString> _markedText;
     RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
     RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker;
@@ -181,7 +181,6 @@
 - (void)accessoryDone;
 - (void)_didHandleKeyEvent:(WebIOSEvent *)event;
 - (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions;
-- (void)_updateUnscaledView;
 - (void)_enableInspectorNodeSearch;
 - (void)_disableInspectorNodeSearch;
 @end

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (170925 => 170926)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-07-09 19:31:33 UTC (rev 170925)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-07-09 19:47:44 UTC (rev 170926)
@@ -138,6 +138,10 @@
 - (void)didHandleWebKeyEvent;
 @end
 
+@interface UIView (UIViewInternalHack)
++ (BOOL)_addCompletion:(void(^)(BOOL))completion;
+@end
+
 @interface WKFormInputSession : NSObject <_WKFormInputSession>
 
 - (instancetype)initWithContentView:(WKContentView *)view userObject:(NSObject <NSSecureCoding> *)userObject;
@@ -212,14 +216,13 @@
 
 - (void)setupInteraction
 {
-    if (!_inverseScaleRootView) {
-        _inverseScaleRootView = adoptNS([[UIView alloc] init]);
-        [_inverseScaleRootView setOpaque:NO];
-        [_inverseScaleRootView layer].anchorPoint = CGPointMake(0, 0);
+    if (!_interactionViewsContainerView) {
+        _interactionViewsContainerView = adoptNS([[UIView alloc] init]);
+        [_interactionViewsContainerView setOpaque:NO];
+        [_interactionViewsContainerView layer].anchorPoint = CGPointZero;
     }
-    [self addSubview:_inverseScaleRootView.get()];
-    CGFloat inverseScale = 1 / [[self layer] transform].m11;
-    [_inverseScaleRootView setTransform:CGAffineTransformMakeScale(inverseScale, inverseScale)];
+    [_interactionViewsContainerView setHidden:NO];
+    [self.layer addObserver:self forKeyPath:@"transform" options:NSKeyValueObservingOptionInitial context:nil];
 
     _touchEventGestureRecognizer = adoptNS([[UIWebTouchEventsGestureRecognizer alloc] initWithTarget:self action:@selector(_webTouchEventsRecognized:) touchDelegate:self]);
     [_touchEventGestureRecognizer setDelegate:self];
@@ -273,7 +276,8 @@
     [_formInputSession invalidate];
     _formInputSession = nil;
     [_highlightView removeFromSuperview];
-    [_inverseScaleRootView removeFromSuperview];
+    [self.layer removeObserver:self forKeyPath:@"transform"];
+    [_interactionViewsContainerView setHidden:YES];
     [_touchEventGestureRecognizer setDelegate:nil];
     [self removeGestureRecognizer:_touchEventGestureRecognizer.get()];
 
@@ -330,18 +334,29 @@
 
 - (UIView*)unscaledView
 {
-    return _inverseScaleRootView.get();
+    return _interactionViewsContainerView.get();
 }
 
 - (CGFloat)inverseScale
 {
-    return [[_inverseScaleRootView layer] transform].m11;
+    return 1 / [[self layer] transform].m11;
 }
 
-- (void)_updateUnscaledView
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
-    CGFloat inverseScale = 1 / [[self layer] transform].m11;
-    [_inverseScaleRootView setTransform:CGAffineTransformMakeScale(inverseScale, inverseScale)];
+    ASSERT([keyPath isEqualToString:@"transform"]);
+    ASSERT(object == self.layer);
+
+    if ([UIView _isInAnimationBlock] && _page->editorState().selectionIsNone) {
+        // If the utility views are not already visible, we don't want them to become visible during the animation since
+        // they could not start from a reasonable state.
+        // This is not perfect since views could also get updated during the animation, in practice this is rare and the end state
+        // remains correct.
+        [self _cancelInteraction];
+        [_interactionViewsContainerView setHidden:YES];
+        [UIView _addCompletion:^(BOOL){ [_interactionViewsContainerView setHidden:NO]; }];
+    }
+
     _selectionNeedsUpdate = YES;
     [self _updateChangedSelection];
     [self _updateTapHighlight];
@@ -369,7 +384,7 @@
 
 - (UIView *)hitTest:(CGPoint)point withEvent:(::UIEvent *)event
 {
-    for (UIView *subView in [_inverseScaleRootView.get() subviews]) {
+    for (UIView *subView in [_interactionViewsContainerView.get() subviews]) {
         UIView *hitView = [subView hitTest:[subView convertPoint:point fromView:self] withEvent:event];
         if (hitView)
             return hitView;
@@ -584,7 +599,7 @@
         [_highlightView setCornerRadius:minimumTapHighlightRadius];
     }
     [_highlightView layer].opacity = 1;
-    [_inverseScaleRootView addSubview:_highlightView.get()];
+    [_interactionViewsContainerView addSubview:_highlightView.get()];
     [self _updateTapHighlight];
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to