WebKit Bugzilla
Attachment 373073 Details for
Bug 199301
: Provide overrides for UIKit's suggested actions in UIContextMenuInteraction
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-199301-20190628104735.patch (text/plain), 11.64 KB, created by
Dean Jackson
on 2019-06-27 17:47:36 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Dean Jackson
Created:
2019-06-27 17:47:36 PDT
Size:
11.64 KB
patch
obsolete
>Subversion Revision: 246908 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index f9d9b1731875be17e94a592b03c548eceaea5699..cdbe70369b50ef90d9e083cddf1e71d46a4207d8 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,26 @@ >+2019-06-27 Dean Jackson <dino@apple.com> >+ >+ Provide overrides for UIKit's suggested actions in UIContextMenuInteraction >+ https://bugs.webkit.org/show_bug.cgi?id=199301 >+ <rdar://problem/52297380> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ We were previously wrapping the actionMenuProvider with our own block >+ in order to ensure the correct suggestedActions were passed to the provider. >+ UIKit added API for us to override the actions separately. >+ >+ Unfortunately we can't quite yet get rid of our access into the >+ UIContextMenuConfiguration, because we still need to override the preview >+ handler in the case where the user does not want link previews. >+ >+ * Platform/spi/ios/UIKitSPI.h: >+ * UIProcess/ios/WKContentViewInteraction.h: >+ * UIProcess/ios/WKContentViewInteraction.mm: >+ (-[WKContentView continueContextMenuInteraction:]): >+ (-[WKContentView _contextMenuInteraction:overrideSuggestedActionsForConfiguration:]): >+ Implement the new delegate SPI to provide our own actions. >+ > 2019-06-27 Daniel Bates <dabates@apple.com> > > [iOS] Select all with existing range selection replaces range instead of selecting all text >diff --git a/Source/WebKit/Platform/spi/ios/UIKitSPI.h b/Source/WebKit/Platform/spi/ios/UIKitSPI.h >index 13315ac3be728fa6c4c1d4fc37753e5bbb0dbff6..4ccf20e7ca8131b67abf09e15fd1d7f6b6097b03 100644 >--- a/Source/WebKit/Platform/spi/ios/UIKitSPI.h >+++ b/Source/WebKit/Platform/spi/ios/UIKitSPI.h >@@ -89,6 +89,9 @@ > #if HAVE(LINK_PREVIEW) > #import <UIKit/UIPreviewAction_Private.h> > #import <UIKit/UIPreviewItemController.h> >+#if USE(UICONTEXTMENU) >+#import <UIKit/UIContextMenuInteraction_ForWebKitOnly.h> >+#endif > #endif > > #if ENABLE(DRAG_SUPPORT) >@@ -1185,7 +1188,7 @@ static inline bool currentUserInterfaceIdiomIsPad() > @end > > #if HAVE(LINK_PREVIEW) && USE(UICONTEXTMENU) >-@interface UIContextMenuConfiguration (NeededUntil51288435Fixed) >+@interface UIContextMenuConfiguration (NeededUntil52295535Fixed) > @property (nonatomic, copy) id <NSCopying> identifier; > @property (nonatomic, copy) UIContextMenuContentPreviewProvider previewProvider; > @property (nonatomic, copy) UIContextMenuActionProvider actionProvider; >@@ -1196,6 +1199,7 @@ static inline bool currentUserInterfaceIdiomIsPad() > @property (nonatomic, weak) id <_UIClickInteractionDriverDelegate> delegate; > @end > >+// FIXME: I don't think this Radar is correct. 51288435 is about something else. > @class _UIClickPresentationInteraction; > @interface UIContextMenuInteraction (Radar51288435) > @property (nonatomic, strong) _UIClickPresentationInteraction *presentationInteraction; >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >index 90f784db9797e668853e8d7e28c99c9db1a1f565..db52020a15bdcfa161bdbfa60cbcd7e329e5e9ce 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h >@@ -254,6 +254,7 @@ struct WKAutoCorrectionData { > RetainPtr<UIViewController> _contextMenuLegacyPreviewController; > RetainPtr<UIMenu> _contextMenuLegacyMenu; > BOOL _contextMenuHasRequestedLegacyData; >+ BOOL _contextMenuActionProviderDelegateNeedsOverride; > RetainPtr<UITargetedPreview> _contextMenuInteractionTargetedPreview; > #endif > RetainPtr<UIPreviewItemController> _previewItemController; >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >index fa25ea91fa7997d4e7e11b3b3cd480acdf28ba8c..ae6135cba33cac38ec93fd377692b43a2c0f75a4 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >@@ -7776,8 +7776,9 @@ static NSString *titleForMenu(bool isLink, bool showLinkPreviews, const URL& url > _contextMenuLegacyPreviewController = nullptr; > _contextMenuLegacyMenu = nullptr; > _contextMenuHasRequestedLegacyData = NO; >+ _contextMenuActionProviderDelegateNeedsOverride = NO; > >- UIContextMenuActionProvider actionMenuProvider = [weakSelf = WeakObjCPtr<WKContentView>(self)] (NSArray<UIMenuElement *> *suggestedActions) -> UIMenu * { >+ UIContextMenuActionProvider actionMenuProvider = [weakSelf = WeakObjCPtr<WKContentView>(self)] (NSArray<UIMenuElement *> *) -> UIMenu * { > auto strongSelf = weakSelf.get(); > if (!strongSelf) > return nil; >@@ -7807,57 +7808,39 @@ static NSString *titleForMenu(bool isLink, bool showLinkPreviews, const URL& url > if (!strongSelf) > return completion(nil); > >- if (!configurationFromWKUIDelegate) { >+ if (configurationFromWKUIDelegate) { >+ strongSelf->_contextMenuActionProviderDelegateNeedsOverride = YES; >+ completion(configurationFromWKUIDelegate); >+ return; >+ } > >- strongSelf->_contextMenuElementInfo = nil; >+ // At this point we have an object we might want to show a context menu for, but the >+ // client was unable to handle it. Before giving up, we ask DataDetectors. > >- // At this point we have an object we might want to show a context menu for, but the >- // client was unable to handle it. Before giving up, we ask DataDetectors. >+ strongSelf->_contextMenuElementInfo = nil; > > #if ENABLE(DATA_DETECTION) >- // FIXME: Support JavaScript urls here. But make sure they don't show a preview. >- // <rdar://problem/50572283> >- if (!linkURL.protocolIsInHTTPFamily() && !WebCore::DataDetection::canBePresentedByDataDetectors(linkURL)) >- return completion(nil); >- >- BEGIN_BLOCK_OBJC_EXCEPTIONS; >- auto ddContextMenuActionClass = getDDContextMenuActionClass(); >- if ([ddContextMenuActionClass respondsToSelector:@selector(contextMenuConfigurationWithURL:inView:context:menuIdentifier:)]) { >- NSDictionary *context = [strongSelf dataDetectionContextForPositionInformation:strongSelf->_positionInformation]; >- UIContextMenuConfiguration *configurationFromDD = [ddContextMenuActionClass contextMenuConfigurationForURL:linkURL identifier:strongSelf->_positionInformation.dataDetectorIdentifier selectedText:[strongSelf selectedText] results:strongSelf->_positionInformation.dataDetectorResults.get() inView:strongSelf.get() context:context menuIdentifier:nil]; >- if (strongSelf->_showLinkPreviews) >- return completion(configurationFromDD); >- return completion([UIContextMenuConfiguration configurationWithIdentifier:[configurationFromDD identifier] previewProvider:[configurationFromDD previewProvider] actionProvider:[configurationFromDD actionProvider]]); >- } >- END_BLOCK_OBJC_EXCEPTIONS; >-#endif >+ // FIXME: Support JavaScript urls here. But make sure they don't show a preview. >+ // <rdar://problem/50572283> >+ if (!linkURL.protocolIsInHTTPFamily() && !WebCore::DataDetection::canBePresentedByDataDetectors(linkURL)) > return completion(nil); >- } >- >- id<NSCopying> identifier = [configurationFromWKUIDelegate identifier]; >- UIContextMenuContentPreviewProvider contentPreviewProvider = [configurationFromWKUIDelegate previewProvider]; >- UIContextMenuActionProvider actionMenuProvider = [configurationFromWKUIDelegate actionProvider]; >- >- auto actionProviderWrapper = [actionProviderFromUIDelegate = makeBlockPtr(actionMenuProvider), weakSelf = WTFMove(weakSelf)] (NSArray<UIMenuElement *> *suggestedActions) -> UIMenu * { >- auto strongSelf = weakSelf.get(); >- if (!strongSelf) >- return nil; > >- auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:strongSelf->_positionInformation]); >- RetainPtr<NSArray<_WKElementAction *>> defaultActionsFromAssistant = strongSelf->_positionInformation.isLink ? [strongSelf->_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()] : [strongSelf->_actionSheetAssistant defaultActionsForImageSheet:elementInfo.get()]; >- >- auto menuElements = menuElementsFromDefaultActions(defaultActionsFromAssistant, elementInfo); >- >- if (actionProviderFromUIDelegate) >- return actionProviderFromUIDelegate(menuElements); >- >- auto title = titleForMenu(strongSelf->_positionInformation.isLink, strongSelf->_showLinkPreviews, strongSelf->_positionInformation.url, strongSelf->_positionInformation.title); >- return [UIMenu menuWithTitle:title children:menuElements]; >- }; >- >- completion([UIContextMenuConfiguration configurationWithIdentifier:identifier previewProvider:contentPreviewProvider actionProvider:actionProviderWrapper]); >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ auto ddContextMenuActionClass = getDDContextMenuActionClass(); >+ if ([ddContextMenuActionClass respondsToSelector:@selector(contextMenuConfigurationWithURL:inView:context:menuIdentifier:)]) { >+ NSDictionary *context = [strongSelf dataDetectionContextForPositionInformation:strongSelf->_positionInformation]; >+ UIContextMenuConfiguration *configurationFromDD = [ddContextMenuActionClass contextMenuConfigurationForURL:linkURL identifier:strongSelf->_positionInformation.dataDetectorIdentifier selectedText:[strongSelf selectedText] results:strongSelf->_positionInformation.dataDetectorResults.get() inView:strongSelf.get() context:context menuIdentifier:nil]; >+ strongSelf->_contextMenuActionProviderDelegateNeedsOverride = YES; >+ if (strongSelf->_showLinkPreviews) >+ return completion(configurationFromDD); >+ return completion([UIContextMenuConfiguration configurationWithIdentifier:[configurationFromDD identifier] previewProvider:nil actionProvider:[configurationFromDD actionProvider]]); >+ } >+ END_BLOCK_OBJC_EXCEPTIONS; >+#endif >+ return completion(nil); > }); > >+ _contextMenuActionProviderDelegateNeedsOverride = NO; > _contextMenuElementInfo = wrapper(API::ContextMenuElementInfo::create(_positionInformation)); > if ([uiDelegate respondsToSelector:@selector(_webView:contextMenuConfigurationForElement:completionHandler:)]) { > auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:contextMenuConfigurationForElement:completionHandler:)); >@@ -7879,6 +7862,17 @@ static NSString *titleForMenu(bool isLink, bool showLinkPreviews, const URL& url > completionBlock(nil); > } > >+- (NSArray<UIMenuElement *> *)_contextMenuInteraction:(UIContextMenuInteraction *)interaction overrideSuggestedActionsForConfiguration:(UIContextMenuConfiguration *)configuration >+{ >+ if (_contextMenuActionProviderDelegateNeedsOverride) { >+ auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithInteractionInformationAtPosition:_positionInformation]); >+ RetainPtr<NSArray<_WKElementAction *>> defaultActionsFromAssistant = _positionInformation.isLink ? [_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()] : [_actionSheetAssistant defaultActionsForImageSheet:elementInfo.get()]; >+ return menuElementsFromDefaultActions(defaultActionsFromAssistant, elementInfo); >+ } >+ // If we're here we're in the legacy path, which ignores the suggested actions anyway. >+ return nil; >+} >+ > static RetainPtr<UIImage> uiImageForImage(WebCore::Image* image) > { > if (!image)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
thorton
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199301
: 373073