<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211679] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211679">211679</a></dd>
<dt>Author</dt> <dd>wenson_hsieh@apple.com</dd>
<dt>Date</dt> <dd>2017-02-04 23:19:53 -0800 (Sat, 04 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Data interaction on an image should make it stand out when presenting the action sheet
https://bugs.webkit.org/show_bug.cgi?id=167846
&lt;rdar://problem/30363014&gt;

Reviewed by Tim Horton.

Adds infrastructure to improve the behavior of data interaction for images. We make two changes to accomplish
this: first, add some plumbing to WebKit so the web process can tell the UI process when it is done handling a
request to start data interaction, so that the UI process is able to clean up UI-side state in the event that
the page prevented the default behavior.

Secondly, this patch tweaks the heuristic used to present action sheets as popovers. For image elements, if
there is sufficient space around the element, we will use the element rect as the target rect; otherwise, we
fall back to presenting the popover at the touch location.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::didHandleStartDataInteractionRequest):
* UIProcess/ios/WKActionSheet.h:
* UIProcess/ios/WKActionSheet.mm:
(-[WKActionSheet presentSheet:]):

Added a presentation style parameter, used to specify whether or not WKActionSheet should present the popover
using the element rect as the target rect, or the touch location.

(-[WKActionSheet doneWithSheet]):
(-[WKActionSheet updateSheetPosition]):
(-[WKActionSheet presentSheet]): Deleted.
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant presentationRectForIndicatedElement]):

Returns the (inflated) bounds of the element that is currently being indicated.

(-[WKActionSheetAssistant showImageSheet]):
(-[WKActionSheetAssistant _presentationStyleForImageAtElementRect:]):
(-[WKActionSheetAssistant showLinkSheet]):
(-[WKActionSheetAssistant showDataDetectorsSheet]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didHandleStartDataInteractionRequest):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:

Remove unnecessary function declarations and implementations.

(WebKit::PageClientImpl::didPerformDataInteractionControllerOperation): Deleted.
(WebKit::PageClientImpl::startDataInteractionWithImage): Deleted.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::requestStartDataInteraction):

Notify the UI process that the web process is done handling a data interaction request, specifying whether or
not the request was granted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPageClienth">trunk/Source/WebKit2/UIProcess/PageClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosPageClientImplIOSh">trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosPageClientImplIOSmm">trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheeth">trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionh">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm">trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacPageClientImplh">trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacPageClientImplmm">trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -1,3 +1,61 @@
</span><ins>+2017-02-04  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
+
+        Data interaction on an image should make it stand out when presenting the action sheet
+        https://bugs.webkit.org/show_bug.cgi?id=167846
+        &lt;rdar://problem/30363014&gt;
+
+        Reviewed by Tim Horton.
+
+        Adds infrastructure to improve the behavior of data interaction for images. We make two changes to accomplish
+        this: first, add some plumbing to WebKit so the web process can tell the UI process when it is done handling a
+        request to start data interaction, so that the UI process is able to clean up UI-side state in the event that
+        the page prevented the default behavior.
+
+        Secondly, this patch tweaks the heuristic used to present action sheets as popovers. For image elements, if
+        there is sufficient space around the element, we will use the element rect as the target rect; otherwise, we
+        fall back to presenting the popover at the touch location.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::didHandleStartDataInteractionRequest):
+        * UIProcess/ios/WKActionSheet.h:
+        * UIProcess/ios/WKActionSheet.mm:
+        (-[WKActionSheet presentSheet:]):
+
+        Added a presentation style parameter, used to specify whether or not WKActionSheet should present the popover
+        using the element rect as the target rect, or the touch location.
+
+        (-[WKActionSheet doneWithSheet]):
+        (-[WKActionSheet updateSheetPosition]):
+        (-[WKActionSheet presentSheet]): Deleted.
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant presentationRectForIndicatedElement]):
+
+        Returns the (inflated) bounds of the element that is currently being indicated.
+
+        (-[WKActionSheetAssistant showImageSheet]):
+        (-[WKActionSheetAssistant _presentationStyleForImageAtElementRect:]):
+        (-[WKActionSheetAssistant showLinkSheet]):
+        (-[WKActionSheetAssistant showDataDetectorsSheet]):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didHandleStartDataInteractionRequest):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+
+        Remove unnecessary function declarations and implementations.
+
+        (WebKit::PageClientImpl::didPerformDataInteractionControllerOperation): Deleted.
+        (WebKit::PageClientImpl::startDataInteractionWithImage): Deleted.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestStartDataInteraction):
+
+        Notify the UI process that the web process is done handling a data interaction request, specifying whether or
+        not the request was granted.
+
</ins><span class="cx"> 2017-02-04  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Fix the key shortcut to enable resource usage overlay in GTK+.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPageClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/PageClient.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -383,6 +383,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">     virtual void didPerformDataInteractionControllerOperation() = 0;
</span><ins>+    virtual void didHandleStartDataInteractionRequest(bool started) = 0;
</ins><span class="cx">     virtual void startDataInteractionWithImage(const WebCore::IntPoint&amp; clientPosition, const ShareableBitmap::Handle&amp; image, const WebCore::FloatPoint&amp; anchorPoint, bool isLink) = 0;
</span><span class="cx"> #endif
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -553,6 +553,7 @@
</span><span class="cx">     void requestRectsAtSelectionOffsetWithText(int32_t offset, const String&amp;, std::function&lt;void(const Vector&lt;WebCore::SelectionRect&gt;&amp;, CallbackBase::Error)&gt;);
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">     void didPerformDataInteractionControllerOperation();
</span><ins>+    void didHandleStartDataInteractionRequest(bool started);
</ins><span class="cx">     void requestStartDataInteraction(const WebCore::IntPoint&amp; clientPosition, const WebCore::IntPoint&amp; globalPosition);
</span><span class="cx"> #endif
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -319,6 +319,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">     DidPerformDataInteractionControllerOperation()
</span><ins>+    DidHandleStartDataInteractionRequest(bool started)
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosPageClientImplIOSh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -203,6 +203,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx">     void didPerformDataInteractionControllerOperation() override;
</span><ins>+    void didHandleStartDataInteractionRequest(bool started) override;
</ins><span class="cx">     void startDataInteractionWithImage(const WebCore::IntPoint&amp; clientPosition, const ShareableBitmap::Handle&amp; image, const WebCore::FloatPoint&amp; anchorPoint, bool isLink) override;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosPageClientImplIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -768,6 +768,11 @@
</span><span class="cx">     [m_contentView _didPerformDataInteractionControllerOperation];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void PageClientImpl::didHandleStartDataInteractionRequest(bool started)
+{
+    [m_contentView _didHandleStartDataInteractionRequest:started];
+}
+
</ins><span class="cx"> void PageClientImpl::startDataInteractionWithImage(const IntPoint&amp; clientPosition, const ShareableBitmap::Handle&amp; image, const FloatPoint&amp; anchorPoint, bool isLink)
</span><span class="cx"> {
</span><span class="cx">     [m_contentView _startDataInteractionWithImage:ShareableBitmap::create(image)-&gt;makeCGImageCopy() atClientPosition:CGPointMake(clientPosition.x(), clientPosition.y()) anchorPoint:anchorPoint isLink:isLink];
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -28,6 +28,11 @@
</span><span class="cx"> #import &lt;UIKit/UIAlertController.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIPopoverController.h&gt;
</span><span class="cx"> 
</span><ins>+typedef NS_ENUM(NSInteger, WKActionSheetPresentationStyle) {
+    WKActionSheetPresentAtTouchLocation,
+    WKActionSheetPresentAtElementRect
+};
+
</ins><span class="cx"> @protocol WKActionSheetDelegate;
</span><span class="cx"> @class WKContentView;
</span><span class="cx"> 
</span><span class="lines">@@ -36,7 +41,7 @@
</span><span class="cx"> @property (nonatomic, assign) id &lt;WKActionSheetDelegate&gt; sheetDelegate;
</span><span class="cx"> @property (nonatomic) UIPopoverArrowDirection arrowDirections;
</span><span class="cx"> - (void)doneWithSheet;
</span><del>-- (BOOL)presentSheet;
</del><ins>+- (BOOL)presentSheet:(WKActionSheetPresentationStyle)style;
</ins><span class="cx"> - (BOOL)presentSheetFromRect:(CGRect)presentationRect;
</span><span class="cx"> - (void)updateSheetPosition;
</span><span class="cx"> @end
</span><span class="lines">@@ -45,6 +50,7 @@
</span><span class="cx"> @required
</span><span class="cx"> - (UIView *)hostViewForSheet;
</span><span class="cx"> - (CGRect)initialPresentationRectInHostViewForSheet;
</span><ins>+- (CGRect)presentationRectForIndicatedElement;
</ins><span class="cx"> - (CGRect)presentationRectInHostViewForSheet;
</span><span class="cx"> - (void)updatePositionInformation;
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx">     BOOL _isRotating;
</span><span class="cx">     BOOL _readyToPresentAfterRotation;
</span><span class="cx"> 
</span><ins>+    WKActionSheetPresentationStyle _currentPresentationStyle;
</ins><span class="cx">     RetainPtr&lt;UIViewController&gt; _currentPresentingViewController;
</span><span class="cx">     RetainPtr&lt;UIViewController&gt; _presentedViewControllerWhileRotating;
</span><span class="cx">     RetainPtr&lt;id &lt;UIPopoverPresentationControllerDelegate&gt;&gt; _popoverPresentationControllerDelegateWhileRotating;
</span><span class="lines">@@ -70,16 +71,17 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma mark - Sheet presentation code
</span><span class="cx"> 
</span><del>-- (BOOL)presentSheet
</del><ins>+- (BOOL)presentSheet:(WKActionSheetPresentationStyle)style
</ins><span class="cx"> {
</span><span class="cx">     // Calculate the presentation rect just before showing.
</span><span class="cx">     CGRect presentationRect = CGRectZero;
</span><span class="cx">     if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
</span><del>-        presentationRect = [_sheetDelegate initialPresentationRectInHostViewForSheet];
</del><ins>+        presentationRect = style == WKActionSheetPresentAtElementRect ? [_sheetDelegate presentationRectForIndicatedElement] : [_sheetDelegate initialPresentationRectInHostViewForSheet];
</ins><span class="cx">         if (CGRectIsEmpty(presentationRect))
</span><span class="cx">             return NO;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _currentPresentationStyle = style;
</ins><span class="cx">     return [self presentSheetFromRect:presentationRect];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -114,6 +116,7 @@
</span><span class="cx">     _currentPresentingViewController = nil;
</span><span class="cx">     _presentedViewControllerWhileRotating = nil;
</span><span class="cx">     _popoverPresentationControllerDelegateWhileRotating = nil;
</span><ins>+    _currentPresentationStyle = WKActionSheetPresentAtTouchLocation;
</ins><span class="cx"> 
</span><span class="cx">     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_didRotateAndLayout) object:nil];
</span><span class="cx"> }
</span><span class="lines">@@ -193,7 +196,7 @@
</span><span class="cx">     if (_isRotating || !_readyToPresentAfterRotation || isBeingPresented)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    CGRect presentationRect = [_sheetDelegate initialPresentationRectInHostViewForSheet];
</del><ins>+    CGRect presentationRect = _currentPresentationStyle == WKActionSheetPresentAtElementRect ? [_sheetDelegate presentationRectForIndicatedElement] : [_sheetDelegate initialPresentationRectInHostViewForSheet];
</ins><span class="cx">     BOOL wasPresentedViewControllerModal = [_presentedViewControllerWhileRotating isModalInPopover];
</span><span class="cx"> 
</span><span class="cx">     if (!CGRectIsEmpty(presentationRect) || wasPresentedViewControllerModal) {
</span><span class="lines">@@ -204,7 +207,7 @@
</span><span class="cx">         if (!CGRectIsEmpty(intersection))
</span><span class="cx">             [self presentSheetFromRect:intersection];
</span><span class="cx">         else if (wasPresentedViewControllerModal)
</span><del>-            [self presentSheet];
</del><ins>+            [self presentSheet:_currentPresentationStyle];
</ins><span class="cx"> 
</span><span class="cx">         _presentedViewControllerWhileRotating = nil;
</span><span class="cx">         _popoverPresentationControllerDelegateWhileRotating = nil;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -152,6 +152,18 @@
</span><span class="cx">     return [self superviewForSheet];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (CGRect)presentationRectForIndicatedElement
+{
+    UIView *view = [self superviewForSheet];
+    auto delegate = _delegate.get();
+    if (!view || !delegate)
+        return CGRectZero;
+
+    static const CGFloat presentationElementRectPadding = 15;
+    auto elementBounds = [delegate positionInformationForActionSheetAssistant:self].bounds;
+    return CGRectInset([view convertRect:elementBounds fromView:_view], -presentationElementRectPadding, -presentationElementRectPadding);
+}
+
</ins><span class="cx"> - (CGRect)initialPresentationRectInHostViewForSheet
</span><span class="cx"> {
</span><span class="cx">     UIView *view = [self superviewForSheet];
</span><span class="lines">@@ -293,7 +305,8 @@
</span><span class="cx">     const auto&amp; positionInformation = [delegate positionInformationForActionSheetAssistant:self];
</span><span class="cx"> 
</span><span class="cx">     NSURL *targetURL = [NSURL _web_URLWithWTFString:positionInformation.url];
</span><del>-    auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:positionInformation.request.point title:positionInformation.title ID:positionInformation.idAttribute rect:positionInformation.bounds image:positionInformation.image.get()]);
</del><ins>+    auto elementBounds = positionInformation.bounds;
+    auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:positionInformation.request.point title:positionInformation.title ID:positionInformation.idAttribute rect:elementBounds image:positionInformation.image.get()]);
</ins><span class="cx">     if ([delegate respondsToSelector:@selector(actionSheetAssistant:showCustomSheetForElement:)] &amp;&amp; [delegate actionSheetAssistant:self showCustomSheetForElement:elementInfo.get()])
</span><span class="cx">         return;
</span><span class="cx">     auto defaultActions = [self defaultActionsForImageSheet:elementInfo.get()];
</span><span class="lines">@@ -309,10 +322,30 @@
</span><span class="cx"> 
</span><span class="cx">     _elementInfo = WTFMove(elementInfo);
</span><span class="cx"> 
</span><del>-    if (![_interactionSheet presentSheet])
</del><ins>+    if (![_interactionSheet presentSheet:[self _presentationStyleForImageAtElementRect:elementBounds]])
</ins><span class="cx">         [self cleanupSheet];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (WKActionSheetPresentationStyle)_presentationStyleForImageAtElementRect:(CGRect)elementRect
+{
+    auto apparentElementRect = [_view convertRect:elementRect toView:_view.window];
+    auto windowRect = _view.window.bounds;
+    apparentElementRect = CGRectIntersection(apparentElementRect, windowRect);
+
+    auto leftInset = CGRectGetMinX(apparentElementRect) - CGRectGetMinX(windowRect);
+    auto topInset = CGRectGetMinY(apparentElementRect) - CGRectGetMinY(windowRect);
+    auto rightInset = CGRectGetMaxX(windowRect) - CGRectGetMaxX(apparentElementRect);
+    auto bottomInset = CGRectGetMaxY(windowRect) - CGRectGetMaxY(apparentElementRect);
+
+    // 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;
+    if (std::max(leftInset, rightInset) &gt; minimumAvailableWidthOrHeightRatio * CGRectGetWidth(windowRect) || std::max(topInset, bottomInset) &gt; minimumAvailableWidthOrHeightRatio * CGRectGetHeight(windowRect))
+        return WKActionSheetPresentAtElementRect;
+
+    return WKActionSheetPresentAtTouchLocation;
+}
+
</ins><span class="cx"> - (void)_appendOpenActionsForURL:(NSURL *)url actions:(NSMutableArray *)defaultActions elementInfo:(_WKActivatedElementInfo *)elementInfo
</span><span class="cx"> {
</span><span class="cx"> #if HAVE(APP_LINKS)
</span><span class="lines">@@ -428,7 +461,7 @@
</span><span class="cx"> 
</span><span class="cx">     _elementInfo = WTFMove(elementInfo);
</span><span class="cx"> 
</span><del>-    if (![_interactionSheet presentSheet])
</del><ins>+    if (![_interactionSheet presentSheet:WKActionSheetPresentAtTouchLocation])
</ins><span class="cx">         [self cleanupSheet];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -494,7 +527,7 @@
</span><span class="cx">     if (elementActions.count &lt;= 1)
</span><span class="cx">         _interactionSheet.get().arrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
</span><span class="cx"> 
</span><del>-    if (![_interactionSheet presentSheet])
</del><ins>+    if (![_interactionSheet presentSheet:WKActionSheetPresentAtTouchLocation])
</ins><span class="cx">         [self cleanupSheet];
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -252,6 +252,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx"> - (void)_didPerformDataInteractionControllerOperation;
</span><ins>+- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
</ins><span class="cx"> - (void)_startDataInteractionWithImage:(RetainPtr&lt;CGImageRef&gt;)image atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint isLink:(BOOL)isLink;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWebPageProxyIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -1121,6 +1121,11 @@
</span><span class="cx">     m_pageClient.didPerformDataInteractionControllerOperation();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::didHandleStartDataInteractionRequest(bool started)
+{
+    m_pageClient.didHandleStartDataInteractionRequest(started);
+}
+
</ins><span class="cx"> void WebPageProxy::requestStartDataInteraction(const WebCore::IntPoint&amp; clientPosition, const WebCore::IntPoint&amp; globalPosition)
</span><span class="cx"> {
</span><span class="cx">     if (isValid())
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacPageClientImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -232,11 +232,6 @@
</span><span class="cx">     _WKRemoteObjectRegistry *remoteObjectRegistry() override;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if ENABLE(DATA_INTERACTION)
-    void didPerformDataInteractionControllerOperation() override;
-    void startDataInteractionWithImage(const WebCore::IntPoint&amp; clientPosition, const ShareableBitmap::Handle&amp; image, const WebCore::FloatPoint&amp; anchorPoint, bool isLink) override;
-#endif
-
</del><span class="cx">     NSView *m_view;
</span><span class="cx">     WKWebView *m_webView;
</span><span class="cx">     WebViewImpl* m_impl { nullptr };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacPageClientImplmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -875,18 +875,6 @@
</span><span class="cx">     return m_impl-&gt;windowIsFrontWindowUnderMouse(event.nativeEvent());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(DATA_INTERACTION)
-void PageClientImpl::didPerformDataInteractionControllerOperation()
-{
-    // FIXME: Implement me.
-}
-
-void PageClientImpl::startDataInteractionWithImage(const IntPoint&amp;, const ShareableBitmap::Handle&amp;, const FloatPoint&amp;, bool)
-{
-    // FIXME: Implement me.
-}
-#endif
-
</del><span class="cx"> WebCore::UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
</span><span class="cx"> {
</span><span class="cx">     if (!m_view)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (211678 => 211679)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-02-05 07:02:30 UTC (rev 211678)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2017-02-05 07:19:53 UTC (rev 211679)
</span><span class="lines">@@ -625,7 +625,8 @@
</span><span class="cx"> #if ENABLE(DATA_INTERACTION)
</span><span class="cx"> void WebPage::requestStartDataInteraction(const IntPoint&amp; clientPosition, const IntPoint&amp; globalPosition)
</span><span class="cx"> {
</span><del>-    m_page-&gt;mainFrame().eventHandler().tryToBeginDataInteractionAtPoint(clientPosition, globalPosition);
</del><ins>+    bool didStart = m_page-&gt;mainFrame().eventHandler().tryToBeginDataInteractionAtPoint(clientPosition, globalPosition);
+    send(Messages::WebPageProxy::DidHandleStartDataInteractionRequest(didStart));
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>