<!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>[277501] trunk</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/277501">277501</a></dd>
<dt>Author</dt> <dd>drousso@apple.com</dd>
<dt>Date</dt> <dd>2021-05-14 11:56:34 -0700 (Fri, 14 May 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] contextmenu hints can be clipped by the WKWebView
https://bugs.webkit.org/show_bug.cgi?id=224204
<rdar://problem/77089174>

Reviewed by Wenson Hsieh.

Source/WebKit:

<a href="http://trac.webkit.org/projects/webkit/changeset/275562">r275562</a> tried to fix this by moving the interaction previews to a separate `UIWindow`, but
this had the unfortunate consequence of placing those previews on top of everything in the
current `UIWindow` (e.g. above the share sheet). As such, WebKit can't use a `UIWindow` for
this as the `WKWebView` has no idea what the view hierarchy above it looks like.

Test: ContextMenu.HintPreviewContainer

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
Add new SPI `-[WKUIDelegate _contextMenuHintPreviewContainerViewForWebView:]` that's used as
the container for the `UIPreviewTarget` created for the contextmenu hint preview.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanUpInteraction]):
(-[WKContentView cleanUpInteractionPreviewContainers]): Added.
(-[WKContentView _didCommitLoadForMainFrame]):
(-[WKContentView _createPreviewContainerWithLayerName:]):
(-[WKContentView containerForDropPreviews]):
(-[WKContentView _removeContainerForDropPreviews]): Added.
(-[WKContentView containerForDragPreviews]):
(-[WKContentView _removeContainerForDragPreviews]): Added.
(-[WKContentView containerForContextMenuHintPreviews]):
(-[WKContentView _removeContainerForContextMenuHintPreviews]): Added.
(-[WKContentView cleanUpDragSourceSessionState]):
(-[WKContentView _removeContextMenuViewIfPossible]):
(-[WKContentView dropInteraction:concludeDrop:]):
(-[WKContentView _hideTargetedPreviewContainerViews]): Deleted.
Clean up and centralize logic around creating and removing interaction preview containers.

* UIProcess/ios/WKContentView.mm:
(-[WKContentView didMoveToWindow]):
If the `WKWebView` is removed from it's parent, make sure to remove the contextmenu hint
preview as well as it could be outside the view hierarchy of the `WKWebView` from the SPI.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
(-[TestContextMenuHintPreviewContainerUIDelegate webView:contextMenuWillPresentForElement:]): Added.
(-[TestContextMenuHintPreviewContainerUIDelegate _contextMenuHintPreviewContainerViewForWebView:]): Added.
(TEST.ContextMenu.HintPreviewContainer): Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKUIDelegatePrivateh">trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewmm">trunk/Source/WebKit/UIProcess/ios/WKContentView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionh">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaContextMenusmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Source/WebKit/ChangeLog       2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -1,3 +1,45 @@
</span><ins>+2021-05-14  Devin Rousso  <drousso@apple.com>
+
+        [iOS] contextmenu hints can be clipped by the WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=224204
+        <rdar://problem/77089174>
+
+        Reviewed by Wenson Hsieh.
+
+        r275562 tried to fix this by moving the interaction previews to a separate `UIWindow`, but
+        this had the unfortunate consequence of placing those previews on top of everything in the
+        current `UIWindow` (e.g. above the share sheet). As such, WebKit can't use a `UIWindow` for
+        this as the `WKWebView` has no idea what the view hierarchy above it looks like.
+
+        Test: ContextMenu.HintPreviewContainer
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        Add new SPI `-[WKUIDelegate _contextMenuHintPreviewContainerViewForWebView:]` that's used as
+        the container for the `UIPreviewTarget` created for the contextmenu hint preview.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView cleanUpInteraction]):
+        (-[WKContentView cleanUpInteractionPreviewContainers]): Added.
+        (-[WKContentView _didCommitLoadForMainFrame]):
+        (-[WKContentView _createPreviewContainerWithLayerName:]):
+        (-[WKContentView containerForDropPreviews]):
+        (-[WKContentView _removeContainerForDropPreviews]): Added.
+        (-[WKContentView containerForDragPreviews]):
+        (-[WKContentView _removeContainerForDragPreviews]): Added.
+        (-[WKContentView containerForContextMenuHintPreviews]):
+        (-[WKContentView _removeContainerForContextMenuHintPreviews]): Added.
+        (-[WKContentView cleanUpDragSourceSessionState]):
+        (-[WKContentView _removeContextMenuViewIfPossible]):
+        (-[WKContentView dropInteraction:concludeDrop:]):
+        (-[WKContentView _hideTargetedPreviewContainerViews]): Deleted.
+        Clean up and centralize logic around creating and removing interaction preview containers.
+
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView didMoveToWindow]):
+        If the `WKWebView` is removed from it's parent, make sure to remove the contextmenu hint
+        preview as well as it could be outside the view hierarchy of the `WKWebView` from the SPI.
+
</ins><span class="cx"> 2021-05-14  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Introduce FileSystem::updateFileModificationTime()
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKUIDelegatePrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h    2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h       2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -191,6 +191,7 @@
</span><span class="cx"> - (NSArray *)_attachmentListForWebView:(WKWebView *)webView sourceIsManaged:(BOOL*)sourceIsManaged WK_API_AVAILABLE(ios(10.3));
</span><span class="cx"> - (NSUInteger)_webView:(WKWebView *)webView indexIntoAttachmentListForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(10.3));
</span><span class="cx"> - (UIEdgeInsets)_webView:(WKWebView *)webView finalObscuredInsetsForScrollView:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset WK_API_AVAILABLE(ios(9.0));
</span><ins>+- (UIView *)_contextMenuHintPreviewContainerViewForWebView:(WKWebView *)webView WK_API_AVAILABLE(ios(WK_IOS_TBA));
</ins><span class="cx"> - (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForURL:(NSURL *)url defaultActions:(NSArray<_WKElementAction *> *)actions elementInfo:(_WKActivatedElementInfo *)elementInfo WK_API_DEPRECATED_WITH_REPLACEMENT("webView:contextMenuConfigurationForElement:completionHandler:", ios(9.0, 13.0));
</span><span class="cx"> - (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForAnimatedImageAtURL:(NSURL *)url defaultActions:(NSArray<_WKElementAction *> *)actions elementInfo:(_WKActivatedElementInfo *)elementInfo imageSize:(CGSize)imageSize WK_API_DEPRECATED_WITH_REPLACEMENT("webView:contextMenuConfigurationForElement:completionHandler:", ios(9.0, 13.0));
</span><span class="cx"> - (UIViewController *)_presentingViewControllerForWebView:(WKWebView *)webView WK_API_AVAILABLE(ios(10.0));
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm       2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm  2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -349,6 +349,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (self.window)
</span><span class="cx">         [self setUpInteraction];
</span><ins>+    else
+        [self cleanUpInteractionPreviewContainers];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ALLOW_DEPRECATED_DECLARATIONS_BEGIN
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h     2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h        2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -531,6 +531,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)setUpInteraction;
</span><span class="cx"> - (void)cleanUpInteraction;
</span><ins>+- (void)cleanUpInteractionPreviewContainers;
</ins><span class="cx"> 
</span><span class="cx"> - (void)scrollViewWillStartPanOrPinchGesture;
</span><span class="cx"> 
</span><span class="lines">@@ -579,7 +580,6 @@
</span><span class="cx"> - (void)_elementDidFocus:(const WebKit::FocusedElementInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode activityStateChanges:(OptionSet<WebCore::ActivityState::Flag>)activityStateChanges userObject:(NSObject <NSSecureCoding> *)userObject;
</span><span class="cx"> - (void)_updateInputContextAfterBlurringAndRefocusingElement;
</span><span class="cx"> - (void)_elementDidBlur;
</span><del>-- (void)_hideTargetedPreviewContainerViews;
</del><span class="cx"> - (void)_didUpdateInputMode:(WebCore::InputMode)mode;
</span><span class="cx"> - (void)_didUpdateEditorState;
</span><span class="cx"> - (void)_hardwareKeyboardAvailabilityChanged;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -1058,6 +1058,10 @@
</span><span class="cx"> 
</span><span class="cx">     _layerTreeTransactionIdAtLastInteractionStart = { };
</span><span class="cx"> 
</span><ins>+#if USE(UICONTEXTMENU)
+    [self _removeContextMenuViewIfPossible];
+#endif // USE(UICONTEXTMENU)
+
</ins><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="cx">     [existingLocalDragSessionContext(_dragDropInteractionState.dragSession()) cleanUpTemporaryDirectories];
</span><span class="cx">     [self teardownDragAndDropInteractions];
</span><span class="lines">@@ -1112,6 +1116,10 @@
</span><span class="cx">     [self _tearDownImageExtraction];
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    [self _removeContainerForContextMenuHintPreviews];
+    [self _removeContainerForDragPreviews];
+    [self _removeContainerForDropPreviews];
+
</ins><span class="cx">     _hasSetUpInteractions = NO;
</span><span class="cx">     _suppressSelectionAssistantReasons = { };
</span><span class="cx"> 
</span><span class="lines">@@ -1122,6 +1130,11 @@
</span><span class="cx">     _cachedSelectedTextRange = nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)cleanUpInteractionPreviewContainers
+{
+    [self _removeContainerForContextMenuHintPreviews];
+}
+
</ins><span class="cx"> - (void)_cancelPendingKeyEventHandler
</span><span class="cx"> {
</span><span class="cx">     if (!_page)
</span><span class="lines">@@ -4562,7 +4575,9 @@
</span><span class="cx"> #endif
</span><span class="cx">     [self _elementDidBlur];
</span><span class="cx">     [self _cancelLongPressGestureRecognizer];
</span><del>-    [self _hideTargetedPreviewContainerViews];
</del><ins>+    [self _removeContainerForContextMenuHintPreviews];
+    [self _removeContainerForDragPreviews];
+    [self _removeContainerForDropPreviews];
</ins><span class="cx">     [_webView _didCommitLoadForMainFrame];
</span><span class="cx"> 
</span><span class="cx">     _textInteractionDidChangeFocusedElement = NO;
</span><span class="lines">@@ -7633,45 +7648,75 @@
</span><span class="cx">     auto container = adoptNS([[UIView alloc] init]);
</span><span class="cx">     [container layer].anchorPoint = CGPointZero;
</span><span class="cx">     [container layer].name = layerName;
</span><del>-    [_interactionViewsContainerView addSubview:container.get()];
</del><span class="cx">     return container;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (UIView *)containerForDropPreviews
</span><span class="cx"> {
</span><del>-    if (!_dropPreviewContainerView)
</del><ins>+    if (!_dropPreviewContainerView) {
</ins><span class="cx">         _dropPreviewContainerView = [self _createPreviewContainerWithLayerName:@"Drop Preview Container"];
</span><ins>+        [_interactionViewsContainerView addSubview:_dropPreviewContainerView.get()];
+    }
</ins><span class="cx"> 
</span><span class="cx">     ASSERT([_dropPreviewContainerView superview]);
</span><del>-    [_dropPreviewContainerView setHidden:NO];
</del><span class="cx">     return _dropPreviewContainerView.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_removeContainerForDropPreviews
+{
+    if (!_dropPreviewContainerView)
+        return;
+
+    [std::exchange(_dropPreviewContainerView, nil) removeFromSuperview];
+}
+
</ins><span class="cx"> - (UIView *)containerForDragPreviews
</span><span class="cx"> {
</span><del>-    if (!_dragPreviewContainerView)
</del><ins>+    if (!_dragPreviewContainerView) {
</ins><span class="cx">         _dragPreviewContainerView = [self _createPreviewContainerWithLayerName:@"Drag Preview Container"];
</span><ins>+        [_interactionViewsContainerView addSubview:_dragPreviewContainerView.get()];
+    }
</ins><span class="cx"> 
</span><span class="cx">     ASSERT([_dragPreviewContainerView superview]);
</span><del>-    [_dragPreviewContainerView setHidden:NO];
</del><span class="cx">     return _dragPreviewContainerView.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_removeContainerForDragPreviews
+{
+    if (!_dragPreviewContainerView)
+        return;
+
+    [std::exchange(_dragPreviewContainerView, nil) removeFromSuperview];
+}
+
</ins><span class="cx"> - (UIView *)containerForContextMenuHintPreviews
</span><span class="cx"> {
</span><del>-    if (!_contextMenuHintContainerView)
</del><ins>+    if (!_contextMenuHintContainerView) {
</ins><span class="cx">         _contextMenuHintContainerView = [self _createPreviewContainerWithLayerName:@"Context Menu Hint Preview Container"];
</span><span class="cx"> 
</span><ins>+        RetainPtr<UIView> containerView;
+
+        if (auto uiDelegate = static_cast<id<WKUIDelegatePrivate>>(self.webView.UIDelegate)) {
+            if ([uiDelegate respondsToSelector:@selector(_contextMenuHintPreviewContainerViewForWebView:)])
+                containerView = [uiDelegate _contextMenuHintPreviewContainerViewForWebView:self.webView];
+        }
+
+        if (!containerView)
+            containerView = _interactionViewsContainerView;
+
+        [containerView addSubview:_contextMenuHintContainerView.get()];
+    }
+
</ins><span class="cx">     ASSERT([_contextMenuHintContainerView superview]);
</span><del>-    [_contextMenuHintContainerView setHidden:NO];
</del><span class="cx">     return _contextMenuHintContainerView.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)_hideTargetedPreviewContainerViews
</del><ins>+- (void)_removeContainerForContextMenuHintPreviews
</ins><span class="cx"> {
</span><del>-    [_dropPreviewContainerView setHidden:YES];
-    [_dragPreviewContainerView setHidden:YES];
-    [_contextMenuHintContainerView setHidden:YES];
</del><ins>+    if (!_contextMenuHintContainerView)
+        return;
+
+    [std::exchange(_contextMenuHintContainerView, nil) removeFromSuperview];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #pragma mark - WKDeferringGestureRecognizerDelegate
</span><span class="lines">@@ -7992,7 +8037,7 @@
</span><span class="cx">     [[WebItemProviderPasteboard sharedInstance] clearRegistrationLists];
</span><span class="cx">     [self _restoreCalloutBarIfNeeded];
</span><span class="cx"> 
</span><del>-    [std::exchange(_dragPreviewContainerView, nil) removeFromSuperview];
</del><ins>+    [self _removeContainerForDragPreviews];
</ins><span class="cx">     [std::exchange(_visibleContentViewSnapshot, nil) removeFromSuperview];
</span><span class="cx">     [_editDropCaretView remove];
</span><span class="cx">     _editDropCaretView = nil;
</span><span class="lines">@@ -8431,7 +8476,7 @@
</span><span class="cx">     if ([self selectControl])
</span><span class="cx">         return;
</span><span class="cx">     
</span><del>-    [std::exchange(_contextMenuHintContainerView, nil) removeFromSuperview];
</del><ins>+    [self _removeContainerForContextMenuHintPreviews];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // USE(UICONTEXTMENU)
</span><span class="lines">@@ -8928,7 +8973,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)dropInteraction:(UIDropInteraction *)interaction concludeDrop:(id <UIDropSession>)session
</span><span class="cx"> {
</span><del>-    [std::exchange(_dropPreviewContainerView, nil) removeFromSuperview];
</del><ins>+    [self _removeContainerForDropPreviews];
</ins><span class="cx">     [std::exchange(_visibleContentViewSnapshot, nil) removeFromSuperview];
</span><span class="cx">     [std::exchange(_unselectedContentSnapshot, nil) removeFromSuperview];
</span><span class="cx">     _dragDropInteractionState.clearAllDelayedItemPreviewProviders();
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Tools/ChangeLog       2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-05-14  Devin Rousso  <drousso@apple.com>
+
+        [iOS] contextmenu hints can be clipped by the WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=224204
+        <rdar://problem/77089174>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+        (-[TestContextMenuHintPreviewContainerUIDelegate webView:contextMenuWillPresentForElement:]): Added.
+        (-[TestContextMenuHintPreviewContainerUIDelegate _contextMenuHintPreviewContainerViewForWebView:]): Added.
+        (TEST.ContextMenu.HintPreviewContainer): Added.
+
</ins><span class="cx"> 2021-05-14  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Introduce FileSystem::updateFileModificationTime()
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaContextMenusmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (277500 => 277501)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm      2021-05-14 18:34:33 UTC (rev 277500)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm 2021-05-14 18:56:34 UTC (rev 277501)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> static bool previewingViewControllerCalled;
</span><span class="cx"> static bool previewActionItemsCalled;
</span><span class="cx"> static bool didEndCalled;
</span><ins>+static bool didAskForHintPreviewContainer;
</ins><span class="cx"> static bool alternateURLRequested;
</span><span class="cx"> static RetainPtr<NSURL> linkURL;
</span><span class="cx"> 
</span><span class="lines">@@ -352,4 +353,35 @@
</span><span class="cx">     EXPECT_TRUE(willPresentCalled);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+@interface TestContextMenuHintPreviewContainerUIDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation TestContextMenuHintPreviewContainerUIDelegate
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+    willPresentCalled = true;
+}
+
+- (UIView *)_contextMenuHintPreviewContainerViewForWebView:(WKWebView *)webView
+{
+    didAskForHintPreviewContainer = true;
+    return nil;
+}
+
+@end
+
+// FIXME: Re-enable this test once rdar://59610140 is resolved
+TEST(ContextMenu, DISABLED_HintPreviewContainer)
+{
+    auto driver = contextMenuWebViewDriver([TestContextMenuHintPreviewContainerUIDelegate class]);
+    [driver begin:^(BOOL result) {
+        EXPECT_TRUE(result);
+        [driver clickDown];
+        [driver clickUp];
+    }];
+    TestWebKitAPI::Util::run(&willPresentCalled);
+    EXPECT_TRUE(didAskForHintPreviewContainer);
+}
+
</ins><span class="cx"> #endif // USE(UICONTEXTMENU)
</span></span></pre>
</div>
</div>

</body>
</html>