Skip to content

Commit

Permalink
[iOS] Stop using -_presentMenuAtLocation: when `-[UIButton performP…
Browse files Browse the repository at this point in the history
…rimaryAction]` is available

https://bugs.webkit.org/show_bug.cgi?id=264503
rdar://114331050

Reviewed by Aditya Keerthi.

Remove the last usage of `-[UIContextMenuInteraction _presentMenuAtLocation:]`, by setting
`showsMenuAsPrimaryAction` to YES on the `CompactContextMenuPresenter`'s hidden `UIButton`, and then
using the new `-performPrimaryAction` method for programmatic menu presentation.

* Source/WebKit/Platform/spi/ios/UIKitSPI.h:
* Source/WebKit/UIProcess/ios/CompactContextMenuPresenter.mm:
(WebKit::CompactContextMenuPresenter::CompactContextMenuPresenter):
(WebKit::CompactContextMenuPresenter::present):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView presentContextMenu:atLocation:]): Deleted.

Canonical link: https://commits.webkit.org/270474@main
  • Loading branch information
whsieh committed Nov 9, 2023
1 parent ae05341 commit e1a9807
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
8 changes: 0 additions & 8 deletions Source/WebKit/Platform/spi/ios/UIKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -978,14 +978,6 @@ typedef NS_OPTIONS(NSInteger, UIWKDocumentRequestFlags) {
@property (nonatomic, strong) UIImage *image;
@end

#if USE(UICONTEXTMENU)

@interface UIContextMenuInteraction ()
- (void)_presentMenuAtLocation:(CGPoint)location;
@end

#endif // USE(UICONTEXTMENU)

#if HAVE(LINK_PREVIEW) && USE(UICONTEXTMENU)
@interface _UIClickInteraction : NSObject <UIInteraction>
@end
Expand Down
20 changes: 18 additions & 2 deletions Source/WebKit/UIProcess/ios/CompactContextMenuPresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@

#if USE(UICONTEXTMENU)

#import "UIKitSPI.h"
@interface UIContextMenuInteraction (SPI)
- (void)_presentMenuAtLocation:(CGPoint)location;
@end

#if HAVE(UI_BUTTON_PERFORM_PRIMARY_ACTION)
@interface UIButton (Staging_112292156)
- (void)performPrimaryAction;
@end
#endif

@interface WKCompactContextMenuPresenterButton : UIButton
@property (nonatomic, weak) id<UIContextMenuInteractionDelegate> externalDelegate;
Expand Down Expand Up @@ -81,6 +89,7 @@ - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willEndFo
[m_button setHidden:YES];
[m_button setUserInteractionEnabled:NO];
[m_button setContextMenuInteractionEnabled:YES];
[m_button setShowsMenuAsPrimaryAction:YES];
}

CompactContextMenuPresenter::~CompactContextMenuPresenter()
Expand Down Expand Up @@ -108,7 +117,14 @@ - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willEndFo
if (![m_button superview])
[m_rootView addSubview:m_button.get()];

// FIXME: This should present from the button itself instead of using `-_presentMenuAtLocation:`.
#if HAVE(UI_BUTTON_PERFORM_PRIMARY_ACTION)
static BOOL canPerformPrimaryAction = [UIButton instancesRespondToSelector:@selector(performPrimaryAction)];
if (canPerformPrimaryAction) {
[m_button performPrimaryAction];
return;
}
#endif

[interaction() _presentMenuAtLocation:CGPointMake(CGRectGetMidX(rectInRootView), CGRectGetMidY(rectInRootView))];
}

Expand Down
3 changes: 0 additions & 3 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,6 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)

#if USE(UICONTEXTMENU)
- (UIView *)textEffectsWindow;

- (void)presentContextMenu:(UIContextMenuInteraction *)contextMenuInteraction atLocation:(CGPoint)location;

- (UITargetedPreview *)_createTargetedContextMenuHintPreviewForFocusedElement:(WebKit::TargetedPreviewPositioning)positioning;
- (UITargetedPreview *)_createTargetedContextMenuHintPreviewIfPossible;
- (void)_removeContextMenuHintContainerIfPossible;
Expand Down
8 changes: 0 additions & 8 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9850,14 +9850,6 @@ - (void)_removeContextMenuHintContainerIfPossible
[self _removeContainerForContextMenuHintPreviews];
}

- (void)presentContextMenu:(UIContextMenuInteraction *)contextMenuInteraction atLocation:(CGPoint) location
{
if (!self.window)
return;

[contextMenuInteraction _presentMenuAtLocation:location];
}

#endif // USE(UICONTEXTMENU)

#if HAVE(UI_WK_DOCUMENT_CONTEXT)
Expand Down

0 comments on commit e1a9807

Please sign in to comment.