Tapping and holding a link should have a share option
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 19:38:40 +0000 (19:38 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 19:38:40 +0000 (19:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150693
-and corresponding-
rdar://problem/21319702

Reviewed by Tim Horton.

Source/WebCore:

* English.lproj/Localizable.strings:

Source/WebKit2:

New _WKElementActionType called _WKElementActionTypeShare.
* UIProcess/API/Cocoa/_WKElementAction.h:
* UIProcess/API/Cocoa/_WKElementAction.mm:
(+[_WKElementAction _elementActionWithType:customTitle:assistant:]):

_WKElementActionTypeShare is part of the default actions for links.
* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant defaultActionsForLinkSheet:]):

Handle the sharing part!
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):

To support this in PDF, PDF need to create a _webSelectionAssistant.
* UIProcess/ios/WKPDFView.mm:
(-[WKPDFView web_initWithFrame:webView:]):
(-[WKPDFView actionSheetAssistant:openElementAtLocation:]):
(-[WKPDFView actionSheetAssistant:shareElementWithURL:rect:]):
(-[WKPDFView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):

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

Source/WebCore/ChangeLog
Source/WebCore/English.lproj/Localizable.strings
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h
Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h
Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/UIProcess/ios/WKPDFView.mm

index ee808e13460b800ad5fa19af9a07e8eeed55e672..980ff0c0fc88d135b4fe44b179c605aa466cc7f0 100644 (file)
@@ -1,3 +1,14 @@
+2015-10-30  Beth Dakin  <bdakin@apple.com>
+
+        Tapping and holding a link should have a share option
+        https://bugs.webkit.org/show_bug.cgi?id=150693
+        -and corresponding-
+        rdar://problem/21319702
+
+        Reviewed by Tim Horton.
+
+        * English.lproj/Localizable.strings:
+
 2015-10-30  Joseph Pecoraro  <pecoraro@apple.com>
 
         Minor CGColor leaks seen on bots allocated in WebSystemBackdropLayer.mm
index 5f72d11700d8bd77e6777a79d974de0ce89a1657..23ebc8ec5a02d391ba5311fed58c728c608cd0cf 100644 (file)
 /* Undo action name */
 "Set Writing Direction (Undo action name)" = "Set Writing Direction";
 
+/* Title for Share action button */
+"Share…" = "Share…";
+
 /* Show colors context menu item */
 "Show Colors" = "Show Colors";
 
index 3b39ac1cb5790c1a06006dec88aa4ac76216ab79..e778c7958bd255823587de941b83b6292d164613 100644 (file)
@@ -1,3 +1,33 @@
+2015-10-30  Beth Dakin  <bdakin@apple.com>
+
+        Tapping and holding a link should have a share option
+        https://bugs.webkit.org/show_bug.cgi?id=150693
+        -and corresponding-
+        rdar://problem/21319702
+
+        Reviewed by Tim Horton.
+
+        New _WKElementActionType called _WKElementActionTypeShare.
+        * UIProcess/API/Cocoa/_WKElementAction.h:
+        * UIProcess/API/Cocoa/_WKElementAction.mm:
+        (+[_WKElementAction _elementActionWithType:customTitle:assistant:]):
+
+        _WKElementActionTypeShare is part of the default actions for links.
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+
+        Handle the sharing part!
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):
+
+        To support this in PDF, PDF need to create a _webSelectionAssistant.
+        * UIProcess/ios/WKPDFView.mm:
+        (-[WKPDFView web_initWithFrame:webView:]):
+        (-[WKPDFView actionSheetAssistant:openElementAtLocation:]):
+        (-[WKPDFView actionSheetAssistant:shareElementWithURL:rect:]):
+        (-[WKPDFView actionSheetAssistant:shouldIncludeAppLinkActionsForElement:]):
+
 2015-10-30  Tim Horton  <timothy_horton@apple.com>
 
         WKView being inside WKWebView leads to weird API issues
index 1f57392a9ea8b6efef55eec24d449aeb0f342584..d3110411024351029a34b71295a2fb6eb8f6fe9a 100644 (file)
@@ -43,6 +43,7 @@ typedef NS_ENUM(NSInteger, _WKElementActionType) {
     _WKElementActionTypeAddToReadingList,
     _WKElementActionTypeOpenInDefaultBrowser WK_ENUM_AVAILABLE(NA, 9_0),
     _WKElementActionTypeOpenInExternalApplication WK_ENUM_AVAILABLE(NA, 9_0),
+    _WKElementActionTypeShare WK_ENUM_AVAILABLE(NA, WK_IOS_TBA),
 #endif
 } WK_ENUM_AVAILABLE(10_10, 8_0);
 
index dc25ab725ffd201fcd880ca643432cafad1d1dff..301dd4f60b51620534ad07c8d564fa9d87c49f5c 100644 (file)
@@ -127,6 +127,12 @@ static void addToReadingList(NSURL *targetURL, NSString *title)
         };
         break;
 #endif
+    case _WKElementActionTypeShare:
+        title = WEB_UI_STRING("Share…", "Title for Share action button");
+        handler = ^(WKActionSheetAssistant *assistant, _WKActivatedElementInfo *actionInfo) {
+            [assistant.delegate actionSheetAssistant:assistant shareElementWithURL:actionInfo.URL rect:actionInfo.boundingRect];
+        };
+        break;
     default:
         [NSException raise:NSInvalidArgumentException format:@"There is no standard web element action of type %ld.", (long)type];
         return nil;
index 6aa4353090cea3d3de428e549402218bf0871d49..face0ccd705de233aa116579747384a4942130b9 100644 (file)
@@ -45,6 +45,7 @@ struct InteractionInformationAtPosition;
 - (const WebKit::InteractionInformationAtPosition&)positionInformationForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant performAction:(WebKit::SheetAction)action;
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant openElementAtLocation:(CGPoint)location;
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect;
 #if HAVE(APP_LINKS)
 - (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element;
 #endif
index c7e66ad6a8819369512286253d5b022ad7e03809..095c0296a02707b42b5ebc93df13a69a3130aa21 100644 (file)
@@ -343,8 +343,10 @@ static LSAppLink *appLinkForURL(NSURL *url)
     if ([getSSReadingListClass() supportsURL:targetURL])
         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeAddToReadingList assistant:self]];
 #endif
-    if (![[targetURL scheme] length] || [[targetURL scheme] caseInsensitiveCompare:@"javascript"] != NSOrderedSame)
+    if (![[targetURL scheme] length] || [[targetURL scheme] caseInsensitiveCompare:@"javascript"] != NSOrderedSame) {
         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeCopy assistant:self]];
+        [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeShare assistant:self]];
+    }
 
     return defaultActions;
 }
index 0ff69d7f14abe9ddf7cb02192532ea2ec9e0ebca..578f65149071cfc4e7334353364fbae255402911 100644 (file)
@@ -3370,6 +3370,14 @@ static bool isAssistableInputType(InputType type)
     [self _attemptClickAtLocation:location];
 }
 
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect
+{
+    if (_textSelectionAssistant)
+        [_textSelectionAssistant showShareSheetFor:url.absoluteString fromRect:boundingRect];
+    else if (_webSelectionAssistant)
+        [_webSelectionAssistant showShareSheetFor:url.absoluteString fromRect:boundingRect];
+}
+
 #if HAVE(APP_LINKS)
 - (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element
 {
index e8d8cc069bcd16620f6df6451fd67605421510c4..7144d43b0288199f27b5cf5b5feda3b96bacbfd5 100644 (file)
@@ -105,6 +105,8 @@ typedef struct {
     _WKFindOptions _nextCachedFindOptionsAffectingResults;
 
     dispatch_queue_t _findQueue;
+
+    RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
 }
 
 - (instancetype)web_initWithFrame:(CGRect)frame webView:(WKWebView *)webView
@@ -718,6 +720,13 @@ static NSStringCompareOptions stringCompareOptions(_WKFindOptions options)
     _webView->_page->navigateToPDFLinkWithSimulatedClick(_positionInformation.url, roundedIntPoint(location), roundedIntPoint(screenPoint));
 }
 
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect
+{
+    _webSelectionAssistant = adoptNS([[UIWKSelectionAssistant alloc] initWithView:self]);
+    [_webSelectionAssistant showShareSheetFor:url.absoluteString fromRect:boundingRect];
+    _webSelectionAssistant = nil;
+}
+
 #if HAVE(APP_LINKS)
 - (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element
 {