From 17dbebcdf8f84e44978a213659b2135c7ca388cc Mon Sep 17 00:00:00 2001 From: "bdakin@apple.com" Date: Fri, 30 Oct 2015 19:38:40 +0000 Subject: [PATCH] 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. 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 | 11 +++++++ .../WebCore/English.lproj/Localizable.strings | 3 ++ Source/WebKit2/ChangeLog | 30 +++++++++++++++++++ .../UIProcess/API/Cocoa/_WKElementAction.h | 1 + .../UIProcess/API/Cocoa/_WKElementAction.mm | 6 ++++ .../UIProcess/ios/WKActionSheetAssistant.h | 1 + .../UIProcess/ios/WKActionSheetAssistant.mm | 4 ++- .../UIProcess/ios/WKContentViewInteraction.mm | 8 +++++ Source/WebKit2/UIProcess/ios/WKPDFView.mm | 9 ++++++ 9 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index ee808e13460b..980ff0c0fc88 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,14 @@ +2015-10-30 Beth Dakin + + 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 Minor CGColor leaks seen on bots allocated in WebSystemBackdropLayer.mm diff --git a/Source/WebCore/English.lproj/Localizable.strings b/Source/WebCore/English.lproj/Localizable.strings index 5f72d11700d8..23ebc8ec5a02 100644 --- a/Source/WebCore/English.lproj/Localizable.strings +++ b/Source/WebCore/English.lproj/Localizable.strings @@ -496,6 +496,9 @@ /* 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"; diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index 3b39ac1cb579..e778c7958bd2 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,33 @@ +2015-10-30 Beth Dakin + + 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 WKView being inside WKWebView leads to weird API issues diff --git a/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h b/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h index 1f57392a9ea8..d31104110243 100644 --- a/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h +++ b/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h @@ -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); diff --git a/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm b/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm index dc25ab725ffd..301dd4f60b51 100644 --- a/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm +++ b/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm @@ -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; diff --git a/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h b/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h index 6aa4353090ce..face0ccd705d 100644 --- a/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h +++ b/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h @@ -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 diff --git a/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm b/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm index c7e66ad6a881..095c0296a027 100644 --- a/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm +++ b/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm @@ -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; } diff --git a/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm index 0ff69d7f14ab..578f65149071 100644 --- a/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm +++ b/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm @@ -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 { diff --git a/Source/WebKit2/UIProcess/ios/WKPDFView.mm b/Source/WebKit2/UIProcess/ios/WKPDFView.mm index e8d8cc069bcd..7144d43b0288 100644 --- a/Source/WebKit2/UIProcess/ios/WKPDFView.mm +++ b/Source/WebKit2/UIProcess/ios/WKPDFView.mm @@ -105,6 +105,8 @@ typedef struct { _WKFindOptions _nextCachedFindOptionsAffectingResults; dispatch_queue_t _findQueue; + + RetainPtr _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 { -- 2.36.0