Title: [219287] trunk/Source/WebKit2
Revision
219287
Author
wenson_hs...@apple.com
Date
2017-07-10 03:04:53 -0700 (Mon, 10 Jul 2017)

Log Message

[WK2] Action sheets for links fail to present in WebKit2 PDF view
https://bugs.webkit.org/show_bug.cgi?id=174307
<rdar://problem/31412128>

Reviewed by Tim Horton.

Currently, presenting an action sheet for a link always uses the WKActionSheetPresentAtClosestIndicatorRect
codepath, which requires text indicator data for the link. However, when showing an action sheet for a link via
WKPDFView, a text indicator for the link is not included, so the popover rect ends up being an empty rect at the
origin, which causes us to bail from presenting the popover.

To address this, we tweak our heuristic for determining which action sheet presentation style to use, so that we
only use the closest indicator rect for a link if the text indicator data is also present (otherwise, we fall
back to using the element rect). All other behavior is the same.

* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant showImageSheet]):
(presentationStyleForView):

Refactor _shouldPresentAtTouchLocationForElementRect into presentationStyleForView, a static function that
returns a WKActionSheetPresentationStyle.

(-[WKActionSheetAssistant showLinkSheet]):
(-[WKActionSheetAssistant _shouldPresentAtTouchLocationForElementRect:]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (219286 => 219287)


--- trunk/Source/WebKit2/ChangeLog	2017-07-10 05:58:57 UTC (rev 219286)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-10 10:04:53 UTC (rev 219287)
@@ -1,3 +1,30 @@
+2017-07-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [WK2] Action sheets for links fail to present in WebKit2 PDF view
+        https://bugs.webkit.org/show_bug.cgi?id=174307
+        <rdar://problem/31412128>
+
+        Reviewed by Tim Horton.
+
+        Currently, presenting an action sheet for a link always uses the WKActionSheetPresentAtClosestIndicatorRect
+        codepath, which requires text indicator data for the link. However, when showing an action sheet for a link via
+        WKPDFView, a text indicator for the link is not included, so the popover rect ends up being an empty rect at the
+        origin, which causes us to bail from presenting the popover.
+
+        To address this, we tweak our heuristic for determining which action sheet presentation style to use, so that we
+        only use the closest indicator rect for a link if the text indicator data is also present (otherwise, we fall
+        back to using the element rect). All other behavior is the same.
+
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant showImageSheet]):
+        (presentationStyleForView):
+
+        Refactor _shouldPresentAtTouchLocationForElementRect into presentationStyleForView, a static function that
+        returns a WKActionSheetPresentationStyle.
+
+        (-[WKActionSheetAssistant showLinkSheet]):
+        (-[WKActionSheetAssistant _shouldPresentAtTouchLocationForElementRect:]): Deleted.
+
 2017-07-09  Brady Eidson  <beid...@apple.com>
 
         Remove some obsolete WebKitVersionChecks.

Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (219286 => 219287)


--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm	2017-07-10 05:58:57 UTC (rev 219286)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm	2017-07-10 10:04:53 UTC (rev 219287)
@@ -371,7 +371,7 @@
 
         _elementInfo = WTFMove(elementInfo);
 
-        if (![_interactionSheet presentSheet:[self _shouldPresentAtTouchLocationForElementRect:elementBounds] ? WKActionSheetPresentAtTouchLocation : WKActionSheetPresentAtElementRect])
+        if (![_interactionSheet presentSheet:presentationStyleForView(_view.getAutoreleased(), _positionInformation.value(), _elementInfo.get())])
             [self cleanupSheet];
     };
 
@@ -393,10 +393,9 @@
     showImageSheetWithAlternateURLBlock(nil, nil);
 }
 
-- (BOOL)_shouldPresentAtTouchLocationForElementRect:(CGRect)elementRect
+static WKActionSheetPresentationStyle presentationStyleForView(UIView *view, const InteractionInformationAtPosition& positionInfo, _WKActivatedElementInfo *elementInfo)
 {
-    UIView *view = _view.getAutoreleased();
-    auto apparentElementRect = [view convertRect:elementRect toView:view.window];
+    auto apparentElementRect = [view convertRect:positionInfo.bounds toView:view.window];
     auto windowRect = view.window.bounds;
     apparentElementRect = CGRectIntersection(apparentElementRect, windowRect);
 
@@ -408,7 +407,13 @@
     // If at least this much of the window is available for the popover to draw in, then target the element rect when presenting the action menu popover.
     // Otherwise, there is not enough space to position the popover around the element, so revert to using the touch location instead.
     static const CGFloat minimumAvailableWidthOrHeightRatio = 0.4;
-    return std::max(leftInset, rightInset) <= minimumAvailableWidthOrHeightRatio * CGRectGetWidth(windowRect) && std::max(topInset, bottomInset) <= minimumAvailableWidthOrHeightRatio * CGRectGetHeight(windowRect);
+    if (std::max(leftInset, rightInset) <= minimumAvailableWidthOrHeightRatio * CGRectGetWidth(windowRect) && std::max(topInset, bottomInset) <= minimumAvailableWidthOrHeightRatio * CGRectGetHeight(windowRect))
+        return WKActionSheetPresentAtTouchLocation;
+
+    if (elementInfo.type == _WKActivatedElementTypeLink && positionInfo.linkIndicator.textRectsInBoundingRectCoordinates.size())
+        return WKActionSheetPresentAtClosestIndicatorRect;
+
+    return WKActionSheetPresentAtElementRect;
 }
 
 - (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
@@ -530,7 +535,7 @@
 
     _elementInfo = WTFMove(elementInfo);
 
-    if (![_interactionSheet presentSheet:[self _shouldPresentAtTouchLocationForElementRect:_positionInformation->bounds] ? WKActionSheetPresentAtTouchLocation : WKActionSheetPresentAtClosestIndicatorRect])
+    if (![_interactionSheet presentSheet:presentationStyleForView(_view.getAutoreleased(), _positionInformation.value(), _elementInfo.get())])
         [self cleanupSheet];
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to