[iOS] Support multiple file selection in UIDocumentPickerViewController
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 22:41:08 +0000 (22:41 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 22:41:08 +0000 (22:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197014
<rdar://problem/49963514>

Reviewed by Tim Horton.

Source/WebCore:

* platform/LocalizedStrings.h:
Exported multipleFileUploadText().

Source/WebKit:

* UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel _showDocumentPickerMenu]):
Allowed multiple file selection in our UIDocumentPickerViewController when
_allowMultipleFiles is YES.

(displayStringForDocumentsAtURLs):
(-[WKFileUploadPanel documentPicker:didPickDocumentsAtURLs:]):
Changed to support multiple file selection. When more than one file is selected, use
WebCore::multipleFileUploadText() as the display string.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/LocalizedStrings.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm

index cbe4747..14fdaee 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-17  Andy Estes  <aestes@apple.com>
+
+        [iOS] Support multiple file selection in UIDocumentPickerViewController
+        https://bugs.webkit.org/show_bug.cgi?id=197014
+        <rdar://problem/49963514>
+
+        Reviewed by Tim Horton.
+
+        * platform/LocalizedStrings.h:
+        Exported multipleFileUploadText().
+
 2019-04-17  John Wilander  <wilander@apple.com>
 
         Add prioritization of ad click conversions and cleaning of sent ad click conversions
index b4e111e..e8029ff 100644 (file)
@@ -236,7 +236,7 @@ namespace WebCore {
     String unsupportedPluginText();
     WEBCORE_EXPORT String pluginTooSmallText();
 
-    String multipleFileUploadText(unsigned numberOfFiles);
+    WEBCORE_EXPORT String multipleFileUploadText(unsigned numberOfFiles);
     String unknownFileSizeText();
 
 #if PLATFORM(WIN)
index 2532a72..5aa201f 100644 (file)
@@ -1,3 +1,21 @@
+2019-04-17  Andy Estes  <aestes@apple.com>
+
+        [iOS] Support multiple file selection in UIDocumentPickerViewController
+        https://bugs.webkit.org/show_bug.cgi?id=197014
+        <rdar://problem/49963514>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (-[WKFileUploadPanel _showDocumentPickerMenu]):
+        Allowed multiple file selection in our UIDocumentPickerViewController when
+        _allowMultipleFiles is YES.
+
+        (displayStringForDocumentsAtURLs):
+        (-[WKFileUploadPanel documentPicker:didPickDocumentsAtURLs:]):
+        Changed to support multiple file selection. When more than one file is selected, use
+        WebCore::multipleFileUploadText() as the display string.
+
 2019-04-17  Alex Christensen  <achristensen@webkit.org>
 
         Make WebCompiledContentRuleListData non-default-constructible, move its nonserialized member to API::ContentRuleList
index 2468651..4263c66 100644 (file)
@@ -413,8 +413,7 @@ static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
 
     NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[(__bridge NSString *)kUTTypeItem];
     if (shouldPresentDocumentMenuViewController) {
-        // FIXME: UIDocumentMenuViewController is deprecated, we should use UIDocumentPickerViewController instead.
-        // FIXME 49963514: Support multiple file selection
+        // FIXME 49979442: UIDocumentMenuViewController is deprecated. Use UIDocumentPickerViewController instead to support multiple file selection.
         _documentMenuController = adoptNS([[UIDocumentMenuViewController alloc] _initIgnoringApplicationEntitlementForImportOfTypes:documentTypes]);
         [_documentMenuController setDelegate:self];
 
@@ -433,8 +432,8 @@ static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
         [self _presentMenuOptionForCurrentInterfaceIdiom:_documentMenuController.get()];
     } else {
         // Image and Video types are not accepted so bypass the menu and open the file picker directly.
-        // FIXME 49963514: Support multiple file selection
         _documentPickerController = adoptNS([[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport]);
+        [_documentPickerController setAllowsMultipleSelection:_allowMultipleFiles];
         [_documentPickerController setDelegate:self];
         [self _presentFullscreenViewController:_documentPickerController.get() animated:YES];
     }
@@ -551,13 +550,21 @@ IGNORE_WARNINGS_END
 
 #pragma mark - UIDocumentPickerControllerDelegate implementation
 
-- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray <NSURL *> *)urls
+static NSString *displayStringForDocumentsAtURLs(NSArray<NSURL *> *urls)
 {
-    // FIXME 49963514: Support multiple file selection
-    ASSERT(urls.count == 1);
-    NSURL *url = urls[0];
+    auto urlsCount = urls.count;
+    ASSERT(urlsCount);
+    if (urlsCount == 1)
+        return urls[0].lastPathComponent;
+
+    return WebCore::multipleFileUploadText(urlsCount);
+}
+
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
+{
+    ASSERT(urls.count);
     [self _dismissDisplayAnimated:YES];
-    [self _chooseFiles:urls displayString:url.lastPathComponent iconImage:iconForFile(url)];
+    [self _chooseFiles:urls displayString:displayStringForDocumentsAtURLs(urls) iconImage:iconForFile(urls[0])];
 }
 
 - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)documentPicker