Title: [170361] trunk/Source/WebKit2
Revision
170361
Author
ander...@apple.com
Date
2014-06-24 07:38:17 -0700 (Tue, 24 Jun 2014)

Log Message

WKWebView doesn't respect -[UIScrollView contentInset]
https://bugs.webkit.org/show_bug.cgi?id=134230
<rdar://problem/17429107>

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
Call initWithFrame and pass the WKWebView along.

(-[WKWebView _adjustedContentOffset:]):
New helper method that takes a content offset as a CGPoint and offsets it by the computed content inset.

(-[WKWebView _computedContentInset]):
New helper method that returns the _obscuredInsets, or if it's zero, the scroll view's content inset.

(-[WKWebView _processDidExit]):
Use _computedContentInset.

(-[WKWebView _didCommitLayerTree:WebKit::]):
use _computedContentInset.

(-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
Use _computedContentInset.

(-[WKWebView _scrollToContentOffset:WebCore::]):
Use _computedContentInset.

(-[WKWebView _updateVisibleContentRects]):
If we have a custom content view, call web_computedContentInsetDidChange.

(-[WKWebView _setObscuredInsets:]):
Don't call web_setObscuredInsets: if we have a custom content view.

* UIProcess/API/Cocoa/WKWebViewInternal.h:
Add new methods.

* UIProcess/Cocoa/WKWebViewContentProvider.h:
Add new methods.

* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView web_initWithFrame:webView:]):
Set the _webView and _scrollView ivars.

(-[WKPDFView _offsetForPageNumberIndicator]):
Get the computed content offset from the WKWebView.

(-[WKPDFView web_computedContentInsetDidChange]):
Update the page indicator.

(-[WKPDFView initWithFrame:]): Deleted.
(-[WKPDFView web_setObscuredInsets:]): Deleted.

* UIProcess/ios/WKScrollView.mm:
(-[WKScrollView setContentInset:]):
Call _updateVisibleContentRects.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (170360 => 170361)


--- trunk/Source/WebKit2/ChangeLog	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/ChangeLog	2014-06-24 14:38:17 UTC (rev 170361)
@@ -1,3 +1,62 @@
+2014-06-24  Anders Carlsson  <ander...@apple.com>
+
+        WKWebView doesn't respect -[UIScrollView contentInset]
+        https://bugs.webkit.org/show_bug.cgi?id=134230
+        <rdar://problem/17429107>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _setHasCustomContentView:loadedMIMEType:WTF::]):
+        Call initWithFrame and pass the WKWebView along.
+
+        (-[WKWebView _adjustedContentOffset:]):
+        New helper method that takes a content offset as a CGPoint and offsets it by the computed content inset.
+
+        (-[WKWebView _computedContentInset]):
+        New helper method that returns the _obscuredInsets, or if it's zero, the scroll view's content inset.
+
+        (-[WKWebView _processDidExit]):
+        Use _computedContentInset.
+
+        (-[WKWebView _didCommitLayerTree:WebKit::]):
+        use _computedContentInset.
+
+        (-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
+        Use _computedContentInset.
+
+        (-[WKWebView _scrollToContentOffset:WebCore::]):
+        Use _computedContentInset.
+
+        (-[WKWebView _updateVisibleContentRects]):
+        If we have a custom content view, call web_computedContentInsetDidChange.
+
+        (-[WKWebView _setObscuredInsets:]):
+        Don't call web_setObscuredInsets: if we have a custom content view.
+
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        Add new methods.
+
+        * UIProcess/Cocoa/WKWebViewContentProvider.h:
+        Add new methods.
+
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView web_initWithFrame:webView:]):
+        Set the _webView and _scrollView ivars.
+
+        (-[WKPDFView _offsetForPageNumberIndicator]):
+        Get the computed content offset from the WKWebView.
+
+        (-[WKPDFView web_computedContentInsetDidChange]):
+        Update the page indicator.
+        
+        (-[WKPDFView initWithFrame:]): Deleted.
+        (-[WKPDFView web_setObscuredInsets:]): Deleted.
+
+        * UIProcess/ios/WKScrollView.mm:
+        (-[WKScrollView setContentInset:]):
+        Call _updateVisibleContentRects.
+
 2014-06-23  Jaehun Lim  <ljaehun....@samsung.com>
 
         Unreviewed, fix build warning.

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


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-06-24 14:38:17 UTC (rev 170361)
@@ -589,7 +589,7 @@
 
         Class representationClass = [[_configuration _contentProviderRegistry] providerForMIMEType:mimeType];
         ASSERT(representationClass);
-        _customContentView = adoptNS([[representationClass alloc] init]);
+        _customContentView = adoptNS([[representationClass alloc] web_initWithFrame:self.bounds webView:self]);
         _customContentFixedOverlayView = adoptNS([[UIView alloc] initWithFrame:self.bounds]);
         [_customContentFixedOverlayView setUserInteractionEnabled:NO];
 
@@ -598,8 +598,6 @@
         [self addSubview:_customContentFixedOverlayView.get()];
 
         [_customContentView web_setMinimumSize:self.bounds.size];
-        [_customContentView web_setScrollView:_scrollView.get()];
-        [_customContentView web_setObscuredInsets:_obscuredInsets];
         [_customContentView web_setFixedOverlayView:_customContentFixedOverlayView.get()];
     } else if (_customContentView) {
         [_customContentView removeFromSuperview];
@@ -689,6 +687,25 @@
     return _usesMinimalUI;
 }
 
+- (CGPoint)_adjustedContentOffset:(CGPoint)point
+{
+    CGPoint result = point;
+    UIEdgeInsets contentInset = [self _computedContentInset];
+
+    result.x -= contentInset.left;
+    result.y -= contentInset.top;
+
+    return result;
+}
+
+- (UIEdgeInsets)_computedContentInset
+{
+    if (!UIEdgeInsetsEqualToEdgeInsets(_obscuredInsets, UIEdgeInsetsZero))
+        return _obscuredInsets;
+
+    return [_scrollView contentInset];
+}
+
 - (void)_processDidExit
 {
     if (!_customContentView && _isAnimatingResize) {
@@ -702,7 +719,7 @@
     }
     [_contentView setFrame:self.bounds];
     [_scrollView setBackgroundColor:[UIColor whiteColor]];
-    [_scrollView setContentOffset:CGPointMake(-_obscuredInsets.left, -_obscuredInsets.top)];
+    [_scrollView setContentOffset:[self _adjustedContentOffset:CGPointZero]];
     [_scrollView setZoomScale:1];
 
     _viewportMetaTagWidth = -1;
@@ -778,7 +795,7 @@
 
     if (_needsResetViewStateAfterCommitLoadForMainFrame && layerTreeTransaction.transactionID() >= _firstPaintAfterCommitLoadTransactionID) {
         _needsResetViewStateAfterCommitLoadForMainFrame = NO;
-        [_scrollView setContentOffset:CGPointMake(-_obscuredInsets.left, -_obscuredInsets.top)];
+        [_scrollView setContentOffset:[self _adjustedContentOffset:CGPointZero]];
         [self _updateVisibleContentRects];
     }
 
@@ -819,9 +836,7 @@
         double scale = newScale / currentTargetScale;
         _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
 
-        CGPoint newContentOffset = CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale);
-        newContentOffset.x -= _obscuredInsets.left;
-        newContentOffset.y -= _obscuredInsets.top;
+        CGPoint newContentOffset = [self _adjustedContentOffset:CGPointMake(newScrollPosition.x * newScale, newScrollPosition.y * newScale)];
         CGPoint currentContentOffset = [_scrollView contentOffset];
 
         _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
@@ -942,8 +957,7 @@
     CGFloat zoomScale = contentZoomScale(self);
     scaledOffset.scale(zoomScale, zoomScale);
 
-    scaledOffset -= WebCore::FloatSize(_obscuredInsets.left, _obscuredInsets.top);
-    [_scrollView setContentOffset:scaledOffset];
+    [_scrollView setContentOffset:[self _adjustedContentOffset:scaledOffset]];
 }
 
 - (BOOL)_scrollToRect:(WebCore::FloatRect)targetRect origin:(WebCore::FloatPoint)origin minimumScrollDistance:(float)minimumScrollDistance
@@ -1267,8 +1281,10 @@
 
 - (void)_updateVisibleContentRects
 {
-    if (![self usesStandardContentView])
-        return;
+    if (![self usesStandardContentView]) {
+        [_customContentView web_computedContentInsetDidChange];
+        return
+    }
 
     if (_delayUpdateVisibleContentRects) {
         _hadDelayedUpdateVisibleContentRects = YES;
@@ -1284,7 +1300,7 @@
     CGRect fullViewRect = self.bounds;
     CGRect visibleRectInContentCoordinates = [self convertRect:fullViewRect toView:_contentView.get()];
 
-    CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, _obscuredInsets);
+    CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, [self _computedContentInset]);
     CGRect unobscuredRectInContentCoordinates = [self convertRect:unobscuredRect toView:_contentView.get()];
 
     CGFloat scaleFactor = contentZoomScale(self);
@@ -1923,7 +1939,6 @@
     _obscuredInsets = obscuredInsets;
 
     [self _updateVisibleContentRects];
-    [_customContentView web_setObscuredInsets:obscuredInsets];
 }
 
 - (void)_setInterfaceOrientationOverride:(UIInterfaceOrientation)interfaceOrientation

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h (170360 => 170361)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h	2014-06-24 14:38:17 UTC (rev 170361)
@@ -88,6 +88,11 @@
 
 - (void)_willInvokeUIScrollViewDelegateCallback;
 - (void)_didInvokeUIScrollViewDelegateCallback;
+
+- (void)_updateVisibleContentRects;
+
+@property (nonatomic, readonly) UIEdgeInsets _computedContentInset;
+
 #endif
 @end
 

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WKWebViewContentProvider.h (170360 => 170361)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WKWebViewContentProvider.h	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WKWebViewContentProvider.h	2014-06-24 14:38:17 UTC (rev 170361)
@@ -32,6 +32,7 @@
 @class NSData;
 @class UIScrollView;
 @class UIView;
+@class WKWebView;
 @protocol NSObject;
 @protocol UIScrollViewDelegate;
 struct CGSize;
@@ -40,11 +41,11 @@
 // FIXME: This should be API (and probably should not be a UIScrollViewDelegate).
 @protocol WKWebViewContentProvider <NSObject, UIScrollViewDelegate>
 
+- (instancetype)web_initWithFrame:(CGRect) frame webView:(WKWebView *)webView;
 - (void)web_setContentProviderData:(NSData *)data suggestedFilename:(NSString *)filename;
 - (void)web_setMinimumSize:(CGSize)size;
-- (void)web_setScrollView:(UIScrollView *)scrollView;
-- (void)web_setObscuredInsets:(UIEdgeInsets)insets;
 - (void)web_setOverlaidAccessoryViewsInset:(CGSize)inset;
+- (void)web_computedContentInsetDidChange;
 - (void)web_setFixedOverlayView:(UIView *)fixedOverlayView;
 
 @end

Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (170360 => 170361)


--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2014-06-24 14:38:17 UTC (rev 170361)
@@ -29,7 +29,9 @@
 #if PLATFORM(IOS)
 
 #import "WKPDFPageNumberIndicator.h"
+#import "WKWebViewInternal.h"
 #import <CorePDF/UIPDFDocument.h>
+#import <CorePDF/UIPDFPage.h>
 #import <CorePDF/UIPDFPageView.h>
 #import <WebCore/FloatRect.h>
 #import <wtf/RetainPtr.h>
@@ -60,18 +62,26 @@
 
     CGSize _minimumSize;
     CGSize _overlaidAccessoryViewsInset;
-    UIEdgeInsets _obscuredInsets;
+    WKWebView *_webView;
     UIScrollView *_scrollView;
     UIView *_fixedOverlayView;
 }
 
-- (instancetype)initWithFrame:(CGRect)frame
+- (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
 {
     if (!(self = [super initWithFrame:frame]))
         return nil;
 
     self.backgroundColor = [UIColor grayColor];
 
+    _webView = webView;
+
+    _scrollView = webView.scrollView;
+    [_scrollView setMinimumZoomScale:pdfMinimumZoomScale];
+    [_scrollView setMaximumZoomScale:pdfMaximumZoomScale];
+    [_scrollView setContentSize:_documentFrame.size];
+    [_scrollView setBackgroundColor:[UIColor grayColor]];
+
     return self;
 }
 
@@ -175,7 +185,8 @@
 
 - (CGPoint)_offsetForPageNumberIndicator
 {
-    return CGPointMake(_obscuredInsets.left, _obscuredInsets.top + _overlaidAccessoryViewsInset.height);
+    UIEdgeInsets contentInset = [_webView _computedContentInset];
+    return CGPointMake(contentInset.left, contentInset.top + _overlaidAccessoryViewsInset.height);
 }
 
 - (void)_updatePageNumberIndicator
@@ -189,22 +200,17 @@
     [_pageNumberIndicator moveToPoint:[self _offsetForPageNumberIndicator] animated:NO];
 }
 
-- (void)web_setObscuredInsets:(UIEdgeInsets)insets
-{
-    if (UIEdgeInsetsEqualToEdgeInsets(insets, _obscuredInsets))
-        return;
-
-    _obscuredInsets = insets;
-
-    [self _updatePageNumberIndicator];
-}
-
 - (void)web_setOverlaidAccessoryViewsInset:(CGSize)inset
 {
     _overlaidAccessoryViewsInset = inset;
     [_pageNumberIndicator moveToPoint:[self _offsetForPageNumberIndicator] animated:YES];
 }
 
+- (void)web_computedContentInsetDidChange
+{
+    [self _updatePageNumberIndicator];
+}
+
 - (void)web_setFixedOverlayView:(UIView *)fixedOverlayView
 {
     _fixedOverlayView = fixedOverlayView;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm (170360 => 170361)


--- trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm	2014-06-24 14:24:05 UTC (rev 170360)
+++ trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm	2014-06-24 14:38:17 UTC (rev 170361)
@@ -191,6 +191,13 @@
     return [super _rubberBandOffsetForOffset:newOffset maxOffset:maxOffset minOffset:minOffset range:range outside:outside];
 }
 
+- (void)setContentInset:(UIEdgeInsets)contentInset
+{
+    [super setContentInset:contentInset];
+
+    [_internalDelegate _updateVisibleContentRects];
+}
+
 @end
 
 #endif // PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to