REGRESSION (r245006): Setting scrollview.scrollEnabled clobbers any scrollEnabled...
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jun 2019 05:05:45 +0000 (05:05 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jun 2019 05:05:45 +0000 (05:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198656
<rdar://problem/51494585>

Reviewed by Tim Horton.

Allow client to disable scrolling and zooming.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didCommitLayerTree:]):
* UIProcess/ios/WKScrollView.h:
* UIProcess/ios/WKScrollView.mm:
(-[WKScrollView initWithFrame:]):
(-[WKScrollView setScrollEnabled:]):
(-[WKScrollView _setScrollEnabledInternal:]):
(-[WKScrollView _updateScrollability]):
(-[WKScrollView setZoomEnabled:]):
(-[WKScrollView _setZoomEnabledInternal:]):
(-[WKScrollView _updateZoomability]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246230 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKScrollView.h
Source/WebKit/UIProcess/ios/WKScrollView.mm

index dd9bb5f..02848ee 100644 (file)
@@ -1,3 +1,25 @@
+2019-06-07  Antti Koivisto  <antti@apple.com>
+
+        REGRESSION (r245006): Setting scrollview.scrollEnabled clobbers any scrollEnabled set by a client
+        https://bugs.webkit.org/show_bug.cgi?id=198656
+        <rdar://problem/51494585>
+
+        Reviewed by Tim Horton.
+
+        Allow client to disable scrolling and zooming.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _didCommitLayerTree:]):
+        * UIProcess/ios/WKScrollView.h:
+        * UIProcess/ios/WKScrollView.mm:
+        (-[WKScrollView initWithFrame:]):
+        (-[WKScrollView setScrollEnabled:]):
+        (-[WKScrollView _setScrollEnabledInternal:]):
+        (-[WKScrollView _updateScrollability]):
+        (-[WKScrollView setZoomEnabled:]):
+        (-[WKScrollView _setZoomEnabledInternal:]):
+        (-[WKScrollView _updateZoomability]):
+
 2019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebView methods
index fa221ba..263c359 100644 (file)
@@ -1986,11 +1986,11 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
 
     [_scrollView setMinimumZoomScale:layerTreeTransaction.minimumScaleFactor()];
     [_scrollView setMaximumZoomScale:layerTreeTransaction.maximumScaleFactor()];
-    [_scrollView setZoomEnabled:layerTreeTransaction.allowsUserScaling()];
+    [_scrollView _setZoomEnabledInternal:layerTreeTransaction.allowsUserScaling()];
 #if ENABLE(ASYNC_SCROLLING)
     bool hasDockedInputView = !CGRectIsEmpty(_inputViewBounds);
     bool isZoomed = layerTreeTransaction.pageScaleFactor() > layerTreeTransaction.initialScaleFactor();
-    [_scrollView setScrollEnabled:_page->scrollingCoordinatorProxy()->hasScrollableMainFrame() || hasDockedInputView || isZoomed];
+    [_scrollView _setScrollEnabledInternal:_page->scrollingCoordinatorProxy()->hasScrollableMainFrame() || hasDockedInputView || isZoomed];
 #endif
     if (!layerTreeTransaction.scaleWasSetByUIProcess() && ![_scrollView isZooming] && ![_scrollView isZoomBouncing] && ![_scrollView _isAnimatingZoom] && [_scrollView zoomScale] != layerTreeTransaction.pageScaleFactor()) {
         LOG_WITH_STREAM(VisibleRects, stream << " updating scroll view with pageScaleFactor " << layerTreeTransaction.pageScaleFactor());
index 7aa9148..4090864 100644 (file)
@@ -34,6 +34,8 @@
 @property (nonatomic, assign) WKWebView <UIScrollViewDelegate> *internalDelegate;
 
 - (void)_setContentSizePreservingContentOffsetDuringRubberband:(CGSize)contentSize;
+- (void)_setScrollEnabledInternal:(BOOL)enabled;
+- (void)_setZoomEnabledInternal:(BOOL)enabled;
 
 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
 @property (nonatomic, assign, readonly) BOOL _contentInsetAdjustmentBehaviorWasExternallyOverridden;
index 0e73a3e..67c63b5 100644 (file)
@@ -130,6 +130,10 @@ static BOOL shouldForwardScrollViewDelegateMethodToExternalDelegate(SEL selector
     BOOL _contentInsetAdjustmentBehaviorWasExternallyOverridden;
 #endif
     CGFloat _keyboardBottomInsetAdjustment;
+    BOOL _scrollEnabledByClient;
+    BOOL _scrollEnabledInternal;
+    BOOL _zoomEnabledByClient;
+    BOOL _zoomEnabledInternal;
 }
 
 - (id)initWithFrame:(CGRect)frame
@@ -139,6 +143,11 @@ static BOOL shouldForwardScrollViewDelegateMethodToExternalDelegate(SEL selector
     if (!self)
         return nil;
 
+    _scrollEnabledByClient = YES;
+    _scrollEnabledInternal = YES;
+    _zoomEnabledByClient = YES;
+    _zoomEnabledInternal = YES;
+
     self.alwaysBounceVertical = YES;
     self.directionalLockEnabled = YES;
     [self _setIndicatorInsetAdjustmentBehavior:UIScrollViewIndicatorInsetAdjustmentAlways];
@@ -354,6 +363,40 @@ static inline bool valuesAreWithinOnePixel(CGFloat a, CGFloat b)
     return systemContentInset;
 }
 
+- (void)setScrollEnabled:(BOOL)value
+{
+    _scrollEnabledByClient = value;
+    [self _updateScrollability];
+}
+
+- (void)_setScrollEnabledInternal:(BOOL)value
+{
+    _scrollEnabledInternal = value;
+    [self _updateScrollability];
+}
+
+- (void)_updateScrollability
+{
+    [super setScrollEnabled:(_scrollEnabledByClient && _scrollEnabledInternal)];
+}
+
+- (void)setZoomEnabled:(BOOL)value
+{
+    _zoomEnabledByClient = value;
+    [self _updateZoomability];
+}
+
+- (void)_setZoomEnabledInternal:(BOOL)value
+{
+    _zoomEnabledInternal = value;
+    [self _updateZoomability];
+}
+
+- (void)_updateZoomability
+{
+    [super setZoomEnabled:(_zoomEnabledByClient && _zoomEnabledInternal)];
+}
+
 #if PLATFORM(WATCHOS)
 
 - (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer