Provide delegate SPI for clients to notify WebKit about content inset changes
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 22:17:42 +0000 (22:17 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 22:17:42 +0000 (22:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146482
<rdar://problem/21602741>

Reviewed by Darin Adler.

Provide a new SPI for WebKit client applications to use to inform WebKit of planned
adjustments to the edge insets of the view.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Add new optional delegate method.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView scrollViewWillEndDragging:withVelocity:targetContentOffset:]): If the new delegate
method exists, use the specified content insets, rather than the current state of the view.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index 070dc2a..ac81224 100644 (file)
@@ -1,3 +1,19 @@
+2015-07-02  Brent Fulgham  <bfulgham@apple.com>
+
+        Provide delegate SPI for clients to notify WebKit about content inset changes
+        https://bugs.webkit.org/show_bug.cgi?id=146482
+        <rdar://problem/21602741>
+
+        Reviewed by Darin Adler.
+
+        Provide a new SPI for WebKit client applications to use to inform WebKit of planned
+        adjustments to the edge insets of the view.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: Add new optional delegate method.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView scrollViewWillEndDragging:withVelocity:targetContentOffset:]): If the new delegate
+        method exists, use the specified content insets, rather than the current state of the view.
+
 2015-07-02  Beth Dakin  <bdakin@apple.com>
 
         Allow the UIDelegate to customize an image preview
index 54a56fc..aba5692 100644 (file)
 #import <WebKit/WKSecurityOrigin.h>
 #import <WebKit/_WKActivatedElementInfo.h>
 
+@class UIScrollView;
 @class UIViewController;
 @class _WKFrameHandle;
 
 @protocol WKUIDelegatePrivate <WKUIDelegate>
 
+struct UIEdgeInsets;
+
 @optional
 
 // FIXME: This should be handled by the WKWebsiteDataStore delegate.
@@ -59,6 +62,7 @@
 - (void)_webView:(WKWebView *)webView willPreviewImageWithURL:(NSURL *)imageURL WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 - (void)_webView:(WKWebView *)webView commitPreviewedImageWithURL:(NSURL *)imageURL WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 - (void)_webView:(WKWebView *)webView didDismissPreviewViewController:(UIViewController *)previewedViewController;
+- (UIEdgeInsets)_webView:(WKWebView *)webView finalObscuredInsetsForScrollView:(UIScrollView *)scrolView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
 #endif
 
 @end
index 2a1e054..a8690e7 100644 (file)
@@ -1461,7 +1461,16 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
         CGSize maxScrollOffsets = CGSizeMake(scrollView.contentSize.width - scrollView.bounds.size.width, scrollView.contentSize.height - scrollView.bounds.size.height);
         
         CGRect fullViewRect = self.bounds;
-        CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, [self _computedContentInset]);
+
+        UIEdgeInsets contentInset;
+
+        id<WKUIDelegatePrivate> uiDelegatePrivate = static_cast<id <WKUIDelegatePrivate>>([self UIDelegate]);
+        if ([uiDelegatePrivate respondsToSelector:@selector(_webView:finalObscuredInsetsForScrollView:withVelocity:targetContentOffset:)])
+            contentInset = [uiDelegatePrivate _webView:self finalObscuredInsetsForScrollView:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
+        else
+            UIEdgeInsets contentInset = [self _computedContentInset];
+
+        CGRect unobscuredRect = UIEdgeInsetsInsetRect(fullViewRect, contentInset);
         
         coordinator->adjustTargetContentOffsetForSnapping(maxScrollOffsets, velocity, unobscuredRect.origin.y, targetContentOffset);
     }