Title: [284889] trunk/Source/WebKit
- Revision
- 284889
- Author
- [email protected]
- Date
- 2021-10-26 12:44:14 -0700 (Tue, 26 Oct 2021)
Log Message
REGRESSION (r281054): [iOS] Context menu presents from wrong location when long pressing a link in Mail
https://bugs.webkit.org/show_bug.cgi?id=232287
rdar://82671325
Reviewed by Tim Horton.
In the case where the WebKit client isn't overriding the context menu configuration via WebKit context menu UI
delegate methods, `_contextMenuElementInfo` on WKContentView will end up being nil while presenting the context
menu via long press.
After the changes in r281054, this means that when the last view is removed from our WKTargetedPreviewContainer,
we'll unparent WKTargetedPreviewContainer too early, since `_contextMenuElementInfo` won't prevent us from
bailing in `-_removeContextMenuHintContainerIfPossible`. To fix this, we add a boolean flag to track when the
context menu presentation animation is running, and avoid unparenting the preview container if the flag is set.
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setUpInteraction]):
(-[WKContentView _removeContextMenuHintContainerIfPossible]):
(-[WKContentView _contentsOfUserInterfaceItem:]):
(-[WKContentView contextMenuInteraction:willDisplayMenuForConfiguration:animator:]):
To test this change, add an assertion that fires if the context menu preview hint container has already been
unparented by the time we've presented the context menu. This assertion already fires during the extant layout
test fast/events/touch/ios/long-press-on-link.html, which technically exhibits the bug (albeit in a more subtle
way).
(-[WKContentView contextMenuInteraction:willEndForConfiguration:animator:]):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (284888 => 284889)
--- trunk/Source/WebKit/ChangeLog 2021-10-26 19:42:43 UTC (rev 284888)
+++ trunk/Source/WebKit/ChangeLog 2021-10-26 19:44:14 UTC (rev 284889)
@@ -1,3 +1,34 @@
+2021-10-26 Wenson Hsieh <[email protected]>
+
+ REGRESSION (r281054): [iOS] Context menu presents from wrong location when long pressing a link in Mail
+ https://bugs.webkit.org/show_bug.cgi?id=232287
+ rdar://82671325
+
+ Reviewed by Tim Horton.
+
+ In the case where the WebKit client isn't overriding the context menu configuration via WebKit context menu UI
+ delegate methods, `_contextMenuElementInfo` on WKContentView will end up being nil while presenting the context
+ menu via long press.
+
+ After the changes in r281054, this means that when the last view is removed from our WKTargetedPreviewContainer,
+ we'll unparent WKTargetedPreviewContainer too early, since `_contextMenuElementInfo` won't prevent us from
+ bailing in `-_removeContextMenuHintContainerIfPossible`. To fix this, we add a boolean flag to track when the
+ context menu presentation animation is running, and avoid unparenting the preview container if the flag is set.
+
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView setUpInteraction]):
+ (-[WKContentView _removeContextMenuHintContainerIfPossible]):
+ (-[WKContentView _contentsOfUserInterfaceItem:]):
+ (-[WKContentView contextMenuInteraction:willDisplayMenuForConfiguration:animator:]):
+
+ To test this change, add an assertion that fires if the context menu preview hint container has already been
+ unparented by the time we've presented the context menu. This assertion already fires during the extant layout
+ test fast/events/touch/ios/long-press-on-link.html, which technically exhibits the bug (albeit in a more subtle
+ way).
+
+ (-[WKContentView contextMenuInteraction:willEndForConfiguration:animator:]):
+
2021-10-26 Brady Eidson <[email protected]>
Add helper classes and messaging infrastructure to launch webpushd and round trip a message to it
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (284888 => 284889)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2021-10-26 19:42:43 UTC (rev 284888)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h 2021-10-26 19:44:14 UTC (rev 284889)
@@ -350,6 +350,7 @@
RetainPtr<UIMenu> _contextMenuLegacyMenu;
BOOL _contextMenuHasRequestedLegacyData;
BOOL _contextMenuActionProviderDelegateNeedsOverride;
+ BOOL _isDisplayingContextMenuWithAnimation;
#endif
RetainPtr<UIPreviewItemController> _previewItemController;
#endif
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (284888 => 284889)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-10-26 19:42:43 UTC (rev 284888)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2021-10-26 19:44:14 UTC (rev 284889)
@@ -1028,6 +1028,9 @@
_needsDeferredEndScrollingSelectionUpdate = NO;
_isChangingFocus = NO;
_isBlurringFocusedElement = NO;
+#if USE(UICONTEXTMENU)
+ _isDisplayingContextMenuWithAnimation = NO;
+#endif
#if USE(UICONTEXTMENU) && ENABLE(IMAGE_ANALYSIS)
_contextMenuWasTriggeredByImageAnalysisTimeout = NO;
@@ -8625,6 +8628,8 @@
if (_contextMenuElementInfo)
return;
#endif
+ if (_isDisplayingContextMenuWithAnimation)
+ return;
#if ENABLE(DATA_DETECTION)
// We are also using this container for the action sheet assistant...
if ([_actionSheetAssistant hasContextMenuInteraction])
@@ -10524,7 +10529,7 @@
#if HAVE(LINK_PREVIEW)
if ([userInterfaceItem isEqualToString:@"contextMenu"]) {
- if (self._shouldUseContextMenus)
+ if (self._shouldUseContextMenus) {
return @{ userInterfaceItem: @{
@"url": _positionInformation.url.isValid() ? WTF::userVisibleString(_positionInformation.url) : @"",
@"isLink": [NSNumber numberWithBool:_positionInformation.isLink],
@@ -10531,6 +10536,7 @@
@"isImage": [NSNumber numberWithBool:_positionInformation.isImage],
@"imageURL": _positionInformation.imageURL.isValid() ? WTF::userVisibleString(_positionInformation.imageURL) : @""
} };
+ }
NSString *url = "" previewData][UIPreviewDataLink];
return @{ userInterfaceItem: @{
@"url": url,
@@ -11132,9 +11138,19 @@
{
if (!_webView)
return;
+
+ _isDisplayingContextMenuWithAnimation = YES;
+ [animator addCompletion:[weakSelf = WeakObjCPtr<WKContentView>(self)] {
+ if (auto strongSelf = weakSelf.get()) {
+ ASSERT_IMPLIES(strongSelf->_isDisplayingContextMenuWithAnimation, [strongSelf->_contextMenuHintContainerView window]);
+ strongSelf->_isDisplayingContextMenuWithAnimation = NO;
+ }
+ }];
+
auto uiDelegate = static_cast<id<WKUIDelegatePrivate>>(self.webView.UIDelegate);
if (!uiDelegate)
return;
+
if ([uiDelegate respondsToSelector:@selector(webView:contextMenuWillPresentForElement:)])
[uiDelegate webView:self.webView contextMenuWillPresentForElement:_contextMenuElementInfo.get()];
else if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuWillPresentForElement:)]) {
@@ -11293,6 +11309,8 @@
auto strongSelf = weakSelf.get();
if (!strongSelf)
return;
+
+ strongSelf->_isDisplayingContextMenuWithAnimation = NO;
[strongSelf _removeContextMenuHintContainerIfPossible];
[strongSelf->_webView _didDismissContextMenu];
}];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes