Title: [244553] trunk/Source/WebKit
Revision
244553
Author
[email protected]
Date
2019-04-23 11:15:39 -0700 (Tue, 23 Apr 2019)

Log Message

Action sheet shares a stringified URL instead of a URL object
https://bugs.webkit.org/show_bug.cgi?id=197185
<rdar://problem/49962249>

Reviewed by Darin Adler.

* UIProcess/Cocoa/WKShareSheet.h:
* UIProcess/Cocoa/WKShareSheet.mm:
(-[WKShareSheet presentWithParameters:inRect:completionHandler:]):
(-[WKShareSheet presentWithParameters:completionHandler:]): Deleted.
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::showShareSheet):
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::showShareSheet):
Make it possible to optionally provide WKShareSheet with
a rect to present relative to.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _showShareSheet:inRect:completionHandler:]):
(-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):
(-[WKContentView _showShareSheet:completionHandler:]): Deleted.
Instead of stringifying the URL and using the text selection assistant's
share method, hand WKShareSheet a proper URL.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (244552 => 244553)


--- trunk/Source/WebKit/ChangeLog	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/ChangeLog	2019-04-23 18:15:39 UTC (rev 244553)
@@ -1,3 +1,30 @@
+2019-04-23  Tim Horton  <[email protected]>
+
+        Action sheet shares a stringified URL instead of a URL object
+        https://bugs.webkit.org/show_bug.cgi?id=197185
+        <rdar://problem/49962249>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/Cocoa/WKShareSheet.h:
+        * UIProcess/Cocoa/WKShareSheet.mm:
+        (-[WKShareSheet presentWithParameters:inRect:completionHandler:]):
+        (-[WKShareSheet presentWithParameters:completionHandler:]): Deleted.
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::showShareSheet):
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::showShareSheet):
+        Make it possible to optionally provide WKShareSheet with
+        a rect to present relative to.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _showShareSheet:inRect:completionHandler:]):
+        (-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):
+        (-[WKContentView _showShareSheet:completionHandler:]): Deleted.
+        Instead of stringifying the URL and using the text selection assistant's
+        share method, hand WKShareSheet a proper URL.
+
 2019-04-23  Ryosuke Niwa  <[email protected]>
 
         [iOS] element.focus() sometimes fails to reveal the focused element when it becomes editable dynamically

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2019-04-23 18:15:39 UTC (rev 244553)
@@ -38,7 +38,7 @@
 
 - (instancetype)initWithView:(WKWebView *)view;
 
-- (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL&)data completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
+- (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL&)data inRect:(WTF::Optional<WebCore::FloatRect>)rect completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
 - (void)dismiss;
 
 @property (nonatomic, weak) id <WKShareSheetDelegate> delegate;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2019-04-23 18:15:39 UTC (rev 244553)
@@ -68,7 +68,7 @@
     return self;
 }
 
-- (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL &)data completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler
+- (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL &)data inRect:(WTF::Optional<WebCore::FloatRect>)rect completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler
 {
     auto shareDataArray = adoptNS([[NSMutableArray alloc] init]);
     
@@ -103,12 +103,17 @@
     
     // WKShareSheet can be released under NSSharingServicePicker delegate callbacks.
     RetainPtr<WKShareSheet> protector(self);
-    
-    NSPoint location = [NSEvent mouseLocation];
-    NSRect mouseLocationRect = NSMakeRect(location.x, location.y, 1.0, 1.0);
-    NSRect mouseLocationInWindow = [webView.window convertRectFromScreen:mouseLocationRect];
-    NSRect mouseLocationInView = [webView convertRect:mouseLocationInWindow fromView:nil];
-    [_sharingServicePicker showRelativeToRect:mouseLocationInView ofView:webView preferredEdge:NSMinYEdge];
+    NSRect presentationRect;
+
+    if (rect)
+        presentationRect = *rect;
+    else {
+        NSPoint location = [NSEvent mouseLocation];
+        NSRect mouseLocationRect = NSMakeRect(location.x, location.y, 1.0, 1.0);
+        NSRect mouseLocationInWindow = [webView.window convertRectFromScreen:mouseLocationRect];
+        presentationRect = [webView convertRect:mouseLocationInWindow fromView:nil];
+    }
+    [_sharingServicePicker showRelativeToRect:presentationRect ofView:webView preferredEdge:NSMinYEdge];
 #else
     _shareSheetViewController = adoptNS([[UIActivityViewController alloc] initWithActivityItems:shareDataArray.get() applicationActivities:nil]);
     [_shareSheetViewController setCompletionWithItemsHandler:^(NSString *, BOOL completed, NSArray *, NSError *) {
@@ -117,7 +122,11 @@
     }];
     
     UIPopoverPresentationController *popoverController = [_shareSheetViewController popoverPresentationController];
-    popoverController._centersPopoverIfSourceViewNotSet = YES;
+    if (rect) {
+        popoverController.sourceView = webView;
+        popoverController.sourceRect = *rect;
+    } else
+        popoverController._centersPopoverIfSourceViewNotSet = YES;
     
     _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:webView];
     [_presentationViewController presentViewController:_shareSheetViewController.get() animated:YES completion:nil];

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2019-04-23 18:15:39 UTC (rev 244553)
@@ -2782,7 +2782,7 @@
     _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:view]);
     [_shareSheet setDelegate:view];
     
-    [_shareSheet presentWithParameters:data completionHandler:WTFMove(completionHandler)];
+    [_shareSheet presentWithParameters:data inRect:WTF::nullopt completionHandler:WTFMove(completionHandler)];
 }
     
 void WebViewImpl::shareSheetDidDismiss(WKShareSheet *shareSheet)

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2019-04-23 18:15:39 UTC (rev 244553)
@@ -586,7 +586,7 @@
 
 bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
 {
-    [m_contentView _showShareSheet:shareData completionHandler:WTFMove(completionHandler)];
+    [m_contentView _showShareSheet:shareData inRect:WTF::nullopt completionHandler:WTFMove(completionHandler)];
     return true;
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-04-23 18:15:39 UTC (rev 244553)
@@ -429,7 +429,7 @@
 - (void)_scrollingNodeScrollingDidEnd;
 - (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect routeSharingPolicy:(WebCore::RouteSharingPolicy)policy routingContextUID:(NSString *)contextUID;
 - (void)_showRunOpenPanel:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
-- (void)_showShareSheet:(const WebCore::ShareDataWithParsedURL&)shareData completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
+- (void)_showShareSheet:(const WebCore::ShareDataWithParsedURL&)shareData inRect:(WTF::Optional<WebCore::FloatRect>)rect completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
 - (void)dismissFilePicker;
 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled;
 - (Vector<WebKit::OptionItem>&) focusedSelectElementOptions;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (244552 => 244553)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-04-23 18:06:29 UTC (rev 244552)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-04-23 18:15:39 UTC (rev 244553)
@@ -5793,7 +5793,7 @@
     _fileUploadPanel = nil;
 }
 
-- (void)_showShareSheet:(const WebCore::ShareDataWithParsedURL&)data completionHandler:(CompletionHandler<void(bool)>&&)completionHandler
+- (void)_showShareSheet:(const WebCore::ShareDataWithParsedURL&)data inRect:(WTF::Optional<WebCore::FloatRect>)rect completionHandler:(CompletionHandler<void(bool)>&&)completionHandler
 {
 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     if (_shareSheet)
@@ -5802,7 +5802,7 @@
     _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:_webView]);
     [_shareSheet setDelegate:self];
     
-    [_shareSheet presentWithParameters:data completionHandler:WTFMove(completionHandler)];
+    [_shareSheet presentWithParameters:data inRect:rect completionHandler:WTFMove(completionHandler)];
 #endif
 }
 
@@ -5903,8 +5903,9 @@
 
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithURL:(NSURL *)url rect:(CGRect)boundingRect
 {
-    if (_textSelectionAssistant)
-        [_textSelectionAssistant showShareSheetFor:WTF::userVisibleString(url) fromRect:boundingRect];
+    WebCore::ShareDataWithParsedURL shareData;
+    shareData.url = { url };
+    [self _showShareSheet:shareData inRect: { [self convertRect:boundingRect toView:_webView] } completionHandler:[] (bool success) { }];
 }
 
 #if HAVE(APP_LINKS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to