[iOS] Capture WKActionSheetAssistant's interaction with WKContentView in a @protocol
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Oct 2014 16:26:51 +0000 (16:26 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Oct 2014 16:26:51 +0000 (16:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137792

Reviewed by Tim Horton.

WKPDFView would like to use WKActionSheetAssistant to show an action sheet when long-pressing a link, but it
can't so long as WKActionSheetAssistant is tightly coupled to WKContentView. Resolve this by factoring
WKActionSheetAssistant's interaction with WKContentView into a new protocol called
WKActionSheetAssistantDelegate and having WKContentView conform to this protocol.

* UIProcess/API/Cocoa/_WKElementAction.mm:
(+[_WKElementAction elementActionWithTitle:actionHandler:]): Changed instances of WKContentView * to id <WKActionSheetAssistantDelegate>.
(+[_WKElementAction elementActionWithType:customTitle:]): Ditto.
(-[_WKElementAction _runActionWithElementInfo:delegate:]): Ditto.
(copyElement): Deleted.
(saveImage): Deleted.
(-[_WKElementAction _runActionWithElementInfo:view:]): Deleted.
* UIProcess/API/Cocoa/_WKElementActionInternal.h:
* UIProcess/ios/WKActionSheet.h:
* UIProcess/ios/WKActionSheet.mm:
(-[WKActionSheet init]): Renamed from initWithView: since WKActionSheet no longer needs to know about a view.
(-[WKActionSheet _didRotateAndLayout]): Called -[WKActionSheetDelegate updatePositionInformation].
(-[WKActionSheet initWithView:]): Deleted.
* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant delegate]): Added a getter for the delegate property.
(-[WKActionSheetAssistant setDelegate:]): Added a setter for the delegate property.
(-[WKActionSheetAssistant initWithView:]): Changed argument type from WKContentView * to UIView *.
(-[WKActionSheetAssistant initialPresentationRectInHostViewForSheet]): Returned CGRectZero if there is no delegate.
Otherwise, retrieved positionInformation from the delegate.
(-[WKActionSheetAssistant presentationRectInHostViewForSheet]): Ditto.
(-[WKActionSheetAssistant updatePositionInformation]): Called -[WKActionSheetAssistantDelegate updatePositionInformation].
(-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Returned early if there is no delegate.
Otherwise, retrieved positionInformation from the delegate.
(-[WKActionSheetAssistant showImageSheet]): Ditto.
(-[WKActionSheetAssistant showLinkSheet]): Ditto.
(-[WKActionSheetAssistant showDataDetectorsSheet]): Ditto.
(-[WKActionSheetAssistant cleanupSheet]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]): Installed self as WKActionSheetAssistant's delegate.
(-[WKContentView updatePositionInformation]): Renamed from _updatePositionInformation.
(-[WKContentView performAction:]): Renamed from _performAction:.
(-[WKContentView openElementAtLocation:]): Called _attemptClickAtLocation:.
(-[WKContentView actionsForElement:defaultActions:]): Called API::UIClient::actionsForElement().
(-[WKContentView startInteractionWithElement:]): Called WebPageProxy::startInteractionWithElementAtPosition().
(-[WKContentView stopInteraction]): Called WebPageProxy::stopInteraction().
(-[WKContentView _updatePositionInformation]): Deleted.
(-[WKContentView _performAction:]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174885 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm
Source/WebKit2/UIProcess/API/Cocoa/_WKElementActionInternal.h
Source/WebKit2/UIProcess/ios/WKActionSheet.h
Source/WebKit2/UIProcess/ios/WKActionSheet.mm
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index ec32867..9e69ac4 100644 (file)
@@ -1,3 +1,55 @@
+2014-10-16  Andy Estes  <aestes@apple.com>
+
+        [iOS] Capture WKActionSheetAssistant's interaction with WKContentView in a @protocol
+        https://bugs.webkit.org/show_bug.cgi?id=137792
+
+        Reviewed by Tim Horton.
+
+        WKPDFView would like to use WKActionSheetAssistant to show an action sheet when long-pressing a link, but it
+        can't so long as WKActionSheetAssistant is tightly coupled to WKContentView. Resolve this by factoring
+        WKActionSheetAssistant's interaction with WKContentView into a new protocol called
+        WKActionSheetAssistantDelegate and having WKContentView conform to this protocol.
+
+        * UIProcess/API/Cocoa/_WKElementAction.mm:
+        (+[_WKElementAction elementActionWithTitle:actionHandler:]): Changed instances of WKContentView * to id <WKActionSheetAssistantDelegate>.
+        (+[_WKElementAction elementActionWithType:customTitle:]): Ditto.
+        (-[_WKElementAction _runActionWithElementInfo:delegate:]): Ditto.
+        (copyElement): Deleted.
+        (saveImage): Deleted.
+        (-[_WKElementAction _runActionWithElementInfo:view:]): Deleted.
+        * UIProcess/API/Cocoa/_WKElementActionInternal.h:
+        * UIProcess/ios/WKActionSheet.h:
+        * UIProcess/ios/WKActionSheet.mm:
+        (-[WKActionSheet init]): Renamed from initWithView: since WKActionSheet no longer needs to know about a view.
+        (-[WKActionSheet _didRotateAndLayout]): Called -[WKActionSheetDelegate updatePositionInformation].
+        (-[WKActionSheet initWithView:]): Deleted.
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant delegate]): Added a getter for the delegate property.
+        (-[WKActionSheetAssistant setDelegate:]): Added a setter for the delegate property.
+        (-[WKActionSheetAssistant initWithView:]): Changed argument type from WKContentView * to UIView *.
+        (-[WKActionSheetAssistant initialPresentationRectInHostViewForSheet]): Returned CGRectZero if there is no delegate.
+        Otherwise, retrieved positionInformation from the delegate.
+        (-[WKActionSheetAssistant presentationRectInHostViewForSheet]): Ditto.
+        (-[WKActionSheetAssistant updatePositionInformation]): Called -[WKActionSheetAssistantDelegate updatePositionInformation].
+        (-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]): Returned early if there is no delegate.
+        Otherwise, retrieved positionInformation from the delegate.
+        (-[WKActionSheetAssistant showImageSheet]): Ditto.
+        (-[WKActionSheetAssistant showLinkSheet]): Ditto.
+        (-[WKActionSheetAssistant showDataDetectorsSheet]): Ditto.
+        (-[WKActionSheetAssistant cleanupSheet]):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView setupInteraction]): Installed self as WKActionSheetAssistant's delegate.
+        (-[WKContentView updatePositionInformation]): Renamed from _updatePositionInformation.
+        (-[WKContentView performAction:]): Renamed from _performAction:.
+        (-[WKContentView openElementAtLocation:]): Called _attemptClickAtLocation:.
+        (-[WKContentView actionsForElement:defaultActions:]): Called API::UIClient::actionsForElement().
+        (-[WKContentView startInteractionWithElement:]): Called WebPageProxy::startInteractionWithElementAtPosition().
+        (-[WKContentView stopInteraction]): Called WebPageProxy::stopInteraction().
+        (-[WKContentView _updatePositionInformation]): Deleted.
+        (-[WKContentView _performAction:]): Deleted.
+
 2014-10-20  Carlos Garnacho  <carlosg@gnome.org>
 
         [GTK] Improve zooming gesture positioning
index 37c5fc1..8061650 100644 (file)
@@ -31,6 +31,7 @@
 #if PLATFORM(IOS)
 
 #import "GestureTypes.h"
+#import "WKActionSheetAssistant.h"
 #import "WKContentViewInteraction.h"
 #import "_WKActivatedElementInfoInternal.h"
 #import <SafariServices/SSReadingList.h>
@@ -42,7 +43,7 @@
 SOFT_LINK_FRAMEWORK(SafariServices);
 SOFT_LINK_CLASS(SafariServices, SSReadingList);
 
-typedef void (^WKElementActionHandlerInternal)(WKContentView *, _WKActivatedElementInfo *);
+typedef void (^WKElementActionHandlerInternal)(id <WKActionSheetAssistantDelegate>, _WKActivatedElementInfo *);
 
 @implementation _WKElementAction  {
     RetainPtr<NSString> _title;
@@ -71,20 +72,10 @@ typedef void (^WKElementActionHandlerInternal)(WKContentView *, _WKActivatedElem
 
 + (instancetype)elementActionWithTitle:(NSString *)title actionHandler:(WKElementActionHandler)handler
 {
-    return [[[self alloc] _initWithTitle:title actionHandler:^(WKContentView *view, _WKActivatedElementInfo *actionInfo) { handler(actionInfo); }
+    return [[[self alloc] _initWithTitle:title actionHandler:^(id <WKActionSheetAssistantDelegate>, _WKActivatedElementInfo *actionInfo) { handler(actionInfo); }
        type:_WKElementActionTypeCustom] autorelease];
 }
 
-static void copyElement(WKContentView *view)
-{
-    [view _performAction:WebKit::SheetAction::Copy];
-}
-
-static void saveImage(WKContentView *view)
-{
-    [view _performAction:WebKit::SheetAction::SaveImage];
-}
-
 static void addToReadingList(NSURL *targetURL, NSString *title)
 {
     if (!title || [title length] == 0)
@@ -100,25 +91,25 @@ static void addToReadingList(NSURL *targetURL, NSString *title)
     switch (type) {
     case _WKElementActionTypeCopy:
         title = WEB_UI_STRING_KEY("Copy", "Copy ActionSheet Link", "Title for Copy Link or Image action button");
-        handler = ^(WKContentView *view, _WKActivatedElementInfo *actionInfo) {
-            copyElement(view);
+        handler = ^(id <WKActionSheetAssistantDelegate> delegate, _WKActivatedElementInfo *actionInfo) {
+            [delegate performAction:WebKit::SheetAction::Copy];
         };
         break;
     case _WKElementActionTypeOpen:
         title = WEB_UI_STRING_KEY("Open", "Open ActionSheet Link", "Title for Open Link action button");
-        handler = ^(WKContentView *view, _WKActivatedElementInfo *actionInfo) {
-            [view _attemptClickAtLocation:actionInfo._interactionLocation];
+        handler = ^(id <WKActionSheetAssistantDelegate> delegate, _WKActivatedElementInfo *actionInfo) {
+            [delegate openElementAtLocation:actionInfo._interactionLocation];
         };
         break;
     case _WKElementActionTypeSaveImage:
         title = WEB_UI_STRING_KEY("Save Image", "Save Image", "Title for Save Image action button");
-        handler = ^(WKContentView *view, _WKActivatedElementInfo *actionInfo) {
-            saveImage(view);
+        handler = ^(id <WKActionSheetAssistantDelegate> delegate, _WKActivatedElementInfo *actionInfo) {
+            [delegate performAction:WebKit::SheetAction::SaveImage];
         };
         break;
     case _WKElementActionTypeAddToReadingList:
         title = WEB_UI_STRING("Add to Reading List", "Title for Add to Reading List action button");
-        handler = ^(WKContentView *view, _WKActivatedElementInfo *actionInfo) {
+        handler = ^(id <WKActionSheetAssistantDelegate>, _WKActivatedElementInfo *actionInfo) {
             addToReadingList(actionInfo.URL, actionInfo.title);
         };
         break;
@@ -140,9 +131,9 @@ static void addToReadingList(NSURL *targetURL, NSString *title)
     return _title.get();
 }
 
-- (void)_runActionWithElementInfo:(_WKActivatedElementInfo *)info view:(WKContentView *)view
+- (void)_runActionWithElementInfo:(_WKActivatedElementInfo *)info delegate:(id <WKActionSheetAssistantDelegate>)delegate
 {
-    _actionHandler(view, info);
+    _actionHandler(delegate, info);
 }
 
 @end
index 51f5351..38aa8d2 100644 (file)
 #if PLATFORM(IOS)
 
 @class WKContentView;
+@protocol WKActionSheetAssistantDelegate;
 
 @interface _WKElementAction ()
 
-- (void)_runActionWithElementInfo:(_WKActivatedElementInfo *)info view:(WKContentView *)view;
+- (void)_runActionWithElementInfo:(_WKActivatedElementInfo *)info delegate:(id <WKActionSheetAssistantDelegate>)delegate;
 
 @end
 
index 1249f2a..1a2c07b 100644 (file)
@@ -35,7 +35,6 @@
 
 @property (nonatomic, assign) id <WKActionSheetDelegate> sheetDelegate;
 @property (nonatomic) UIPopoverArrowDirection arrowDirections;
-- (id)initWithView:(WKContentView *)view;
 - (void)doneWithSheet;
 - (BOOL)presentSheet;
 - (BOOL)presentSheetFromRect:(CGRect)presentationRect;
@@ -47,6 +46,7 @@
 - (UIView *)hostViewForSheet;
 - (CGRect)initialPresentationRectInHostViewForSheet;
 - (CGRect)presentationRectInHostViewForSheet;
+- (void)updatePositionInformation;
 @end
 
 #endif // PLATFORM(IOS)
index bd8b7b6..bc5f5b7 100644 (file)
 
 #if PLATFORM(IOS)
 
-#import "WKContentViewInteraction.h"
 #import <UIKit/UIAlertController_Private.h>
 #import <UIKit/UIWindow_Private.h>
+#import <wtf/RetainPtr.h>
 
 @implementation WKActionSheet {
     id <WKActionSheetDelegate> _sheetDelegate;
-    WKContentView *_view;
     UIPopoverArrowDirection _arrowDirections;
     BOOL _isRotating;
     BOOL _readyToPresentAfterRotation;
     RetainPtr<id <UIPopoverPresentationControllerDelegate>> _popoverPresentationControllerDelegateWhileRotating;
 }
 
-- (id)initWithView:(WKContentView *)view
+- (id)init
 {
     self = [super init];
     if (!self)
         return nil;
 
     _arrowDirections = UIPopoverArrowDirectionAny;
-    _view = view;
 
     if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
         // Only iPads support popovers that rotate. UIActionSheets actually block rotation on iPhone/iPod Touch
 {
     _isRotating = NO;
     _readyToPresentAfterRotation = YES;
-    [_view _updatePositionInformation];
+    [_sheetDelegate updatePositionInformation];
     [self updateSheetPosition];
 }
 
index 0e4a99a..0a046f0 100644 (file)
 
 #if PLATFORM(IOS)
 
+#import "GestureTypes.h"
 #import "WKActionSheet.h"
-
 #import <DataDetectorsUI/DDDetectionController.h>
 #import <UIKit/UIPopoverController.h>
-#import <WebKit/WKDeclarationSpecifiers.h>
 #import <wtf/RetainPtr.h>
 
-@protocol WKActionSheetDelegate;
-@class WKContentView;
-
 namespace WebKit {
 class WebPageProxy;
+struct InteractionInformationAtPosition;
 }
 
-@interface WKActionSheetAssistant : NSObject <WKActionSheetDelegate, DDDetectionControllerInteractionDelegate>
+@protocol WKActionSheetDelegate;
+@class _WKActivatedElementInfo;
+
+@protocol WKActionSheetAssistantDelegate
+@required
+@property (nonatomic, readonly) const WebKit::InteractionInformationAtPosition& positionInformation;
+- (void)updatePositionInformation;
+- (void)performAction:(WebKit::SheetAction)action;
+- (void)openElementAtLocation:(CGPoint)location;
+- (RetainPtr<NSArray>)actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions;
+- (void)startInteractionWithElement:(_WKActivatedElementInfo *)element;
+- (void)stopInteraction;
+@end
 
-- (id)initWithView:(WKContentView *)view;
+@interface WKActionSheetAssistant : NSObject <WKActionSheetDelegate, DDDetectionControllerInteractionDelegate>
+@property (nonatomic, weak) id <WKActionSheetAssistantDelegate> delegate;
+- (id)initWithView:(UIView *)view;
 - (void)showLinkSheet;
 - (void)showImageSheet;
 - (void)showDataDetectorsSheet;
index 5c9b4c3..430c214 100644 (file)
@@ -31,6 +31,7 @@
 #import "APIUIClient.h"
 #import "WKActionSheet.h"
 #import "WKContentViewInteraction.h"
+#import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
 #import "_WKActivatedElementInfoInternal.h"
 #import "_WKElementActionInternal.h"
@@ -65,12 +66,23 @@ SOFT_LINK_CLASS(DataDetectorsUI, DDDetectionController)
 using namespace WebKit;
 
 @implementation WKActionSheetAssistant {
+    WeakObjCPtr<id <WKActionSheetAssistantDelegate>> _delegate;
     RetainPtr<WKActionSheet> _interactionSheet;
     RetainPtr<_WKActivatedElementInfo> _elementInfo;
-    WKContentView *_view;
+    UIView *_view;
 }
 
-- (id)initWithView:(WKContentView *)view
+- (id <WKActionSheetAssistantDelegate>)delegate
+{
+    return _delegate.getAutoreleased();
+}
+
+- (void)setDelegate:(id <WKActionSheetAssistantDelegate>)delegate
+{
+    _delegate = delegate;
+}
+
+- (id)initWithView:(UIView *)view
 {
     _view = view;
     return self;
@@ -121,21 +133,25 @@ using namespace WebKit;
 - (CGRect)initialPresentationRectInHostViewForSheet
 {
     UIView *view = [self superviewForSheet];
-    if (!view)
+    auto delegate = _delegate.get();
+    if (!view || !delegate)
         return CGRectZero;
 
-    return [self _presentationRectForSheetGivenPoint:_view.positionInformation.point inHostView:view];
+    return [self _presentationRectForSheetGivenPoint:[delegate positionInformation].point inHostView:view];
 
 }
 
 - (CGRect)presentationRectInHostViewForSheet
 {
     UIView *view = [self superviewForSheet];
-    if (!view)
+    auto delegate = _delegate.get();
+    if (!view || !delegate)
         return CGRectZero;
 
-    CGRect boundingRect = _view.positionInformation.bounds;
-    CGPoint fromPoint = _view.positionInformation.point;
+    const auto& positionInformation = [delegate positionInformation];
+
+    CGRect boundingRect = positionInformation.bounds;
+    CGPoint fromPoint = positionInformation.point;
 
     // FIXME: We must adjust our presentation point to take into account a change in document scale.
 
@@ -146,6 +162,11 @@ using namespace WebKit;
     return [self _presentationRectForSheetGivenPoint:fromPoint inHostView:view];
 }
 
+- (void)updatePositionInformation
+{
+    [_delegate.get() updatePositionInformation];
+}
+
 - (BOOL)presentSheet
 {
     // Calculate the presentation rect just before showing.
@@ -167,13 +188,18 @@ using namespace WebKit;
 - (void)_createSheetWithElementActions:(NSArray *)actions showLinkTitle:(BOOL)showLinkTitle
 {
     ASSERT(!_interactionSheet);
+    auto delegate = _delegate.get();
+    if (!delegate)
+        return;
+
+    const auto& positionInformation = [delegate positionInformation];
 
-    NSURL *targetURL = [NSURL URLWithString:_view.positionInformation.url];
+    NSURL *targetURL = [NSURL URLWithString:positionInformation.url];
     NSString *urlScheme = [targetURL scheme];
     BOOL isJavaScriptURL = [urlScheme length] && [urlScheme caseInsensitiveCompare:@"javascript"] == NSOrderedSame;
     // FIXME: We should check if Javascript is enabled in the preferences.
 
-    _interactionSheet = adoptNS([[WKActionSheet alloc] initWithView:_view]);
+    _interactionSheet = adoptNS([[WKActionSheet alloc] init]);
     _interactionSheet.get().sheetDelegate = self;
     _interactionSheet.get().preferredStyle = UIAlertControllerStyleActionSheet;
 
@@ -187,7 +213,7 @@ using namespace WebKit;
             titleIsURL = YES;
         }
     } else
-        titleString = _view.positionInformation.title;
+        titleString = positionInformation.title;
 
     if ([titleString length]) {
         [_interactionSheet setTitle:titleString];
@@ -199,7 +225,7 @@ using namespace WebKit;
 
     for (_WKElementAction *action in actions) {
         [_interactionSheet _addActionWithTitle:[action title] style:UIAlertActionStyleDefault handler:^{
-            [action _runActionWithElementInfo:_elementInfo.get() view:_view];
+            [action _runActionWithElementInfo:_elementInfo.get() delegate:delegate.get()];
             [self cleanupSheet];
         } shouldDismissHandler:^{
             return (BOOL)(!action.dismissalHandler || action.dismissalHandler());
@@ -211,7 +237,7 @@ using namespace WebKit;
                                                         handler:^(UIAlertAction *action) {
                                                             [self cleanupSheet];
                                                         }]];
-    _view.page->startInteractionWithElementAtPosition(_view.positionInformation.point);
+    [delegate startInteractionWithElement:_elementInfo.get()];
 }
 
 - (void)showImageSheet
@@ -219,7 +245,11 @@ using namespace WebKit;
     ASSERT(!_interactionSheet);
     ASSERT(!_elementInfo);
 
-    const auto& positionInformation = _view.positionInformation;
+    auto delegate = _delegate.get();
+    if (!delegate)
+        return;
+
+    const auto& positionInformation = [delegate positionInformation];
 
     NSURL *targetURL = [NSURL URLWithString:positionInformation.url];
     auto defaultActions = adoptNS([[NSMutableArray alloc] init]);
@@ -235,7 +265,7 @@ using namespace WebKit;
     auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage
         URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
 
-    RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
+    RetainPtr<NSArray> actions = [delegate actionsForElement:elementInfo.get() defaultActions:WTF::move(defaultActions)];
 
     if (![actions count])
         return;
@@ -255,7 +285,11 @@ using namespace WebKit;
     ASSERT(!_interactionSheet);
     ASSERT(!_elementInfo);
 
-    const auto& positionInformation = _view.positionInformation;
+    auto delegate = _delegate.get();
+    if (!delegate)
+        return;
+
+    const auto& positionInformation = [delegate positionInformation];
 
     NSURL *targetURL = [NSURL URLWithString:positionInformation.url];
     if (!targetURL)
@@ -271,7 +305,7 @@ using namespace WebKit;
     RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink
         URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
 
-    RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
+    RetainPtr<NSArray> actions = [delegate actionsForElement:elementInfo.get() defaultActions:WTF::move(defaultActions)];
 
     if (![actions count])
         return;
@@ -289,7 +323,12 @@ using namespace WebKit;
 - (void)showDataDetectorsSheet
 {
     ASSERT(!_interactionSheet);
-    NSURL *targetURL = [NSURL URLWithString:_view.positionInformation.url];
+
+    auto delegate = _delegate.get();
+    if (!delegate)
+        return;
+
+    NSURL *targetURL = [NSURL URLWithString:[delegate positionInformation].url];
     if (!targetURL)
         return;
 
@@ -327,7 +366,7 @@ using namespace WebKit;
 
 - (void)cleanupSheet
 {
-    _view.page->stopInteraction();
+    [_delegate.get() stopInteraction];
 
     [_interactionSheet doneWithSheet];
     [_interactionSheet setSheetDelegate:nil];
index c9632b7..933a045 100644 (file)
 #import "AssistedNodeInformation.h"
 #import "GestureTypes.h"
 #import "InteractionInformationAtPosition.h"
-#import "WKSyntheticClickTapGestureRecognizer.h"
+#import "WKActionSheetAssistant.h"
 #import "WKAirPlayRoutePicker.h"
 #import "WKFileUploadPanel.h"
 #import "WKFormPeripheral.h"
+#import "WKSyntheticClickTapGestureRecognizer.h"
 #import <UIKit/UITextInput_Private.h>
 #import <UIKit/UIView.h>
 #import <UIKit/UIWKSelectionAssistant.h>
@@ -145,7 +146,7 @@ struct WKAutoCorrectionData {
 
 @end
 
-@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate>
+@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate, WKActionSheetAssistantDelegate>
 
 @property (nonatomic, readonly) CGPoint lastInteractionLocation;
 @property (nonatomic, readonly) BOOL isEditable;
@@ -170,8 +171,6 @@ struct WKAutoCorrectionData {
 - (BOOL)_interpretKeyEvent:(WebIOSEvent *)theEvent isCharEvent:(BOOL)isCharEvent;
 - (void)_positionInformationDidChange:(const WebKit::InteractionInformationAtPosition&)info;
 - (void)_attemptClickAtLocation:(CGPoint)location;
-- (void)_updatePositionInformation;
-- (void)_performAction:(WebKit::SheetAction)action;
 - (void)_willStartScrollingOrZooming;
 - (void)_didScroll;
 - (void)_didEndScrollingOrZooming;
index 1b60a3f..5333338 100644 (file)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(IOS)
 
+#import "APIUIClient.h"
 #import "EditingRange.h"
 #import "NativeWebKeyboardEvent.h"
 #import "NativeWebTouchEvent.h"
@@ -270,6 +271,7 @@ static UIWebSelectionMode toUIWebSelectionMode(WKSelectionGranularity granularit
     [self useSelectionAssistantWithMode:toUIWebSelectionMode([[_webView configuration] selectionGranularity])];
     
     _actionSheetAssistant = adoptNS([[WKActionSheetAssistant alloc] initWithView:self]);
+    [_actionSheetAssistant setDelegate:self];
     _smartMagnificationController = std::make_unique<SmartMagnificationController>(self);
 }
 
@@ -804,12 +806,6 @@ static inline bool isSamePair(UIGestureRecognizer *a, UIGestureRecognizer *b, UI
     }
 }
 
-- (void)_updatePositionInformation
-{
-    _hasValidPositionInformation = NO;
-    _page->requestPositionInformation(_positionInformation.point);
-}
-
 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
 {
     CGPoint point = [gestureRecognizer locationInView:self];
@@ -1370,11 +1366,6 @@ static void cancelPotentialTapIfNecessary(WKContentView* contentView)
     [_textSelectionAssistant hideTextStyleOptions];
 }
 
-- (void)_performAction:(SheetAction)action
-{
-    _page->performActionOnElement((uint32_t)action);
-}
-
 - (void)copy:(id)sender
 {
     _page->executeEditCommand(ASCIILiteral("copy"));
@@ -2695,6 +2686,39 @@ static UITextAutocapitalizationType toUITextAutocapitalize(WebAutocapitalizeType
     return YES;
 }
 
+#pragma mark - Implementation of WKActionSheetAssistantDelegate.
+
+- (void)updatePositionInformation
+{
+    _hasValidPositionInformation = NO;
+    _page->requestPositionInformation(_positionInformation.point);
+}
+
+- (void)performAction:(WebKit::SheetAction)action
+{
+    _page->performActionOnElement((uint32_t)action);
+}
+
+- (void)openElementAtLocation:(CGPoint)location
+{
+    [self _attemptClickAtLocation:location];
+}
+
+- (RetainPtr<NSArray>)actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(RetainPtr<NSArray>)defaultActions
+{
+    return _page->uiClient().actionsForElement(element, WTF::move(defaultActions));
+}
+
+- (void)startInteractionWithElement:(_WKActivatedElementInfo *)element
+{
+    _page->startInteractionWithElementAtPosition(_positionInformation.point);
+}
+
+- (void)stopInteraction
+{
+    _page->stopInteraction();
+}
+
 @end
 
 // UITextRange, UITextPosition and UITextSelectionRect implementations for WK2