Changeset 258092 in webkit
- Timestamp:
- Mar 7, 2020, 7:41:24 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/en.lproj/Localizable.strings (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Platform/spi/ios/UIKitSPI.h (modified) (2 diffs)
-
WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r258087 r258092 1 2020-03-07 Megan Gardner <megan_gardner@apple.com> 2 3 Adopt UIContextMenu for WKFileUploadPanel 4 https://bugs.webkit.org/show_bug.cgi?id=208687 5 6 Reviewed by Tim Horton. 7 8 New string, no tests needed. 9 10 * en.lproj/Localizable.strings: 11 1 12 2020-03-07 Daniel Bates <dabates@apple.com> 2 13 -
trunk/Source/WebCore/en.lproj/Localizable.strings
r257877 r258092 155 155 "Book with Apple Pay" = "Book with Apple Pay"; 156 156 157 /* File Upload alert sheet button string for choosing an existing file from the file brower */ 158 "Browse (file upload action sheet)" = "Browse"; 159 157 160 /* Option in segmented control for inserting a bulleted list in text editing */ 158 161 "Bulleted list" = "Bulleted list"; -
trunk/Source/WebKit/ChangeLog
r258090 r258092 1 2020-03-07 Megan Gardner <megan_gardner@apple.com> 2 3 Adopt UIContextMenu for WKFileUploadPanel 4 https://bugs.webkit.org/show_bug.cgi?id=208687 5 6 Reviewed by Tim Horton. 7 8 Move from the depricated UIDocumentMenuViewController to UIContextMenu. 9 UI change, not currently testable. 10 11 * Platform/spi/ios/UIKitSPI.h: 12 * UIProcess/ios/forms/WKFileUploadPanel.mm: 13 (-[WKFileUploadPanel dealloc]): 14 (-[WKFileUploadPanel presentWithParameters:resultListener:]): 15 (-[WKFileUploadPanel dismiss]): 16 (-[WKFileUploadPanel _browseFilesButtonLabel]): 17 (-[WKFileUploadPanel contextMenuInteraction:previewForHighlightingMenuWithConfiguration:]): 18 (-[WKFileUploadPanel _contextMenuInteraction:styleForMenuWithConfiguration:]): 19 (-[WKFileUploadPanel contextMenuInteraction:configurationForMenuAtLocation:]): 20 (-[WKFileUploadPanel contextMenuInteraction:willEndForConfiguration:animator:]): 21 (-[WKFileUploadPanel _removeInteraction]): 22 (-[WKFileUploadPanel _initInteraction]): 23 (-[WKFileUploadPanel _showFilePickerMenu]): 24 (-[WKFileUploadPanel _showDocumentPickerMenu]): 25 (-[WKFileUploadPanel _presentPopoverWithContentViewController:animated:]): 26 (-[WKFileUploadPanel _presentFullscreenViewController:animated:]): 27 (photoLibraryIcon): Deleted. 28 (cameraIcon): Deleted. 29 (-[WKFileUploadPanel documentMenu:didPickDocumentPicker:]): Deleted. 30 (-[WKFileUploadPanel documentMenuWasCancelled:]): Deleted. 31 1 32 2020-03-07 Peng Liu <peng.liu6@apple.com> 2 33 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r258088 r258092 1099 1099 @end 1100 1100 1101 typedef NS_ENUM(NSUInteger, _UIContextMenuLayout) { 1102 _UIContextMenuLayoutActionsOnly = 1, 1103 _UIContextMenuLayoutCompactMenu = 3, 1104 }; 1105 1101 1106 @interface _UIContextMenuStyle : NSObject <NSCopying> 1107 @property (nonatomic) _UIContextMenuLayout preferredLayout; 1108 + (instancetype)defaultStyle; 1102 1109 @end 1103 1110 … … 1106 1113 @property (nonatomic, strong, setter=_setOverridePositionTrackingView:) UIView *overridePositionTrackingView; 1107 1114 @end 1115 1116 @interface UIContextMenuInteraction () 1117 - (void)_presentMenuAtLocation:(CGPoint)location; 1118 @end 1119 1108 1120 #endif // USE(UICONTEXTMENU) 1109 1121 -
trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm
r253663 r258092 48 48 #import <WebCore/UTIUtilities.h> 49 49 #import <wtf/RetainPtr.h> 50 #import <wtf/WeakObjCPtr.h> 50 51 #import <wtf/text/StringView.h> 51 52 … … 66 67 } 67 68 return false; 68 }69 70 #pragma mark - Document picker icons71 72 static inline UIImage *photoLibraryIcon()73 {74 return _UIImageGetWebKitPhotoLibraryIcon();75 }76 77 static inline UIImage *cameraIcon()78 {79 return _UIImageGetWebKitTakePhotoOrVideoIcon();80 69 } 81 70 … … 162 151 #pragma mark - WKFileUploadPanel 163 152 164 @interface WKFileUploadPanel () <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, UI DocumentMenuDelegate>153 @interface WKFileUploadPanel () <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, UIContextMenuInteractionDelegate> 165 154 @end 166 155 167 156 @implementation WKFileUploadPanel { 168 W KContentView *_view;157 WeakObjCPtr<WKContentView> _view; 169 158 RefPtr<WebKit::WebOpenPanelResultListenerProxy> _listener; 170 159 RetainPtr<NSArray> _mimeTypes; … … 177 166 RetainPtr<UIPopoverController> _presentationPopover; // iPad for action sheet and Photo Library. 178 167 ALLOW_DEPRECATED_DECLARATIONS_END 179 RetainPtr<UI DocumentMenuViewController> _documentMenuController;168 RetainPtr<UIContextMenuInteraction> _documentContextMenuInteraction; 180 169 RetainPtr<UIDocumentPickerViewController> _documentPickerController; 181 170 WebCore::MediaCaptureType _mediaCaptureType; … … 194 183 [_imagePicker setDelegate:nil]; 195 184 [_presentationPopover setDelegate:nil]; 196 [_documentMenuController setDelegate:nil];197 185 [_documentPickerController setDelegate:nil]; 186 [self removeContextMenuInteraction]; 198 187 199 188 [super dealloc]; … … 279 268 } 280 269 281 [self _showDocumentPickerMenu];270 [self showDocumentPickerMenu]; 282 271 } 283 272 … … 287 276 // If there is any kind of view controller presented on this view, it will be removed. 288 277 289 [[UIViewController _viewControllerForFullScreenPresentationFromView:_view ] dismissViewControllerAnimated:NO completion:nil];278 [[UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()] dismissViewControllerAnimated:NO completion:nil]; 290 279 291 280 [_presentationPopover setDelegate:nil]; … … 319 308 320 309 NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects; 321 BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage);322 BOOL containsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie);323 if ( containsImageMediaType || containsVideoMediaType) {310 BOOL allowsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage); 311 BOOL allowsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie); 312 if (allowsImageMediaType || allowsVideoMediaType) { 324 313 [actionTitles addObject:@"Photo Library"]; 325 if ( containsImageMediaType && containsVideoMediaType)314 if (allowsImageMediaType && allowsVideoMediaType) 326 315 [actionTitles addObject:@"Take Photo or Video"]; 327 else if ( containsVideoMediaType)316 else if (allowsVideoMediaType) 328 317 [actionTitles addObject:@"Take Video"]; 329 318 else … … 387 376 #pragma mark - Source selection menu 388 377 378 - (NSString *)_browseFilesButtonLabel 379 { 380 return WEB_UI_STRING_KEY("Browse", "Browse (file upload action sheet)", "File Upload alert sheet button string for choosing an existing file from the file brower"); 381 } 382 389 383 - (NSString *)_photoLibraryButtonLabel 390 384 { … … 404 398 } 405 399 406 - (void)_showDocumentPickerMenu 400 - (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction previewForHighlightingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration 401 { 402 RetainPtr<UIPreviewParameters> unusedPreviewParameters = adoptNS([[UIPreviewParameters alloc] init]); 403 RetainPtr<UIPreviewTarget> previewTarget = adoptNS([[UIPreviewTarget alloc] initWithContainer:_view.getAutoreleased() center:CGPointMake(_interactionPoint.x, _interactionPoint.y)]); 404 RetainPtr<UITargetedPreview> preview = adoptNS([[UITargetedPreview alloc] initWithView:_view.getAutoreleased() parameters:unusedPreviewParameters.get() target:previewTarget.get()]); 405 406 return preview.autorelease(); 407 } 408 409 - (_UIContextMenuStyle *)_contextMenuInteraction:(UIContextMenuInteraction *)interaction styleForMenuWithConfiguration:(UIContextMenuConfiguration *)configuration 410 { 411 _UIContextMenuStyle *style = [_UIContextMenuStyle defaultStyle]; 412 style.preferredLayout = _UIContextMenuLayoutCompactMenu; 413 return style; 414 } 415 416 - (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location { 417 418 UIContextMenuActionProvider actionMenuProvider = [self, weakSelf = WeakObjCPtr<WKFileUploadPanel>(self)] (NSArray<UIMenuElement *> *) -> UIMenu * { 419 NSArray *actions; 420 NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects; 421 422 BOOL allowsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage); 423 BOOL allowsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie); 424 auto strongSelf = weakSelf.get(); 425 426 if (!strongSelf) 427 return nil; 428 429 UIAction *browseAction = [UIAction actionWithTitle:[strongSelf _browseFilesButtonLabel] image:[UIImage systemImageNamed:@"ellipsis"] identifier:@"browse" handler:^(__kindof UIAction *action) { 430 [self showFilePickerMenu]; 431 }]; 432 433 UIAction *photoAction = [UIAction actionWithTitle:[strongSelf _photoLibraryButtonLabel] image:[UIImage systemImageNamed:@"rectangle.on.rectangle"] identifier:@"photo" handler:^(__kindof UIAction *action) { 434 [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 435 }]; 436 437 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 438 NSString *cameraString = [strongSelf _cameraButtonLabelAllowingPhoto:allowsImageMediaType allowingVideo:allowsVideoMediaType]; 439 UIAction *cameraAction = [UIAction actionWithTitle:cameraString image:[UIImage systemImageNamed:@"camera.fill"] identifier:@"camera" handler:^(__kindof UIAction *action) { 440 _usingCamera = YES; 441 [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypeCamera]; 442 }]; 443 actions = @[photoAction, cameraAction, browseAction]; 444 } else 445 actions = @[photoAction, browseAction]; 446 447 return [UIMenu menuWithTitle:@"" children:actions]; 448 }; 449 450 return [UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:nil actionProvider:actionMenuProvider]; 451 } 452 453 - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willEndForConfiguration:(UIContextMenuConfiguration *)configuration animator:(id<UIContextMenuInteractionAnimating>)animator 454 { 455 [animator addCompletion:^{ 456 [self removeContextMenuInteraction]; 457 [self _cancel]; 458 }]; 459 } 460 461 - (void)removeContextMenuInteraction 462 { 463 if (_documentContextMenuInteraction) { 464 [_view removeInteraction:_documentContextMenuInteraction.get()]; 465 _documentContextMenuInteraction = nil; 466 } 467 } 468 469 - (void)ensureContextMenuInteraction 470 { 471 if (!_documentContextMenuInteraction) { 472 _documentContextMenuInteraction = adoptNS([[UIContextMenuInteraction alloc] initWithDelegate:self]); 473 [_view addInteraction:_documentContextMenuInteraction.get()]; 474 } 475 } 476 477 - (void)showFilePickerMenu 407 478 { 408 479 NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects; 409 410 BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage); 411 BOOL containsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie); 412 480 NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[(__bridge NSString *)kUTTypeItem]; 481 482 _documentPickerController = adoptNS([[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport]); 483 [_documentPickerController setAllowsMultipleSelection:_allowMultipleFiles]; 484 [_documentPickerController setDelegate:self]; 485 [self _presentFullscreenViewController:_documentPickerController.get() animated:YES]; 486 } 487 488 - (void)showDocumentPickerMenu 489 { 490 NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects; 491 413 492 #if PLATFORM(MACCATALYST) 414 493 // FIXME 49961589: Support picking media with UIImagePickerController 415 494 BOOL shouldPresentDocumentMenuViewController = NO; 416 495 #else 417 BOOL shouldPresentDocumentMenuViewController = containsImageMediaType || containsVideoMediaType; 496 BOOL allowsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage); 497 BOOL allowsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie); 498 BOOL shouldPresentDocumentMenuViewController = allowsImageMediaType || allowsVideoMediaType; 418 499 #endif 419 420 NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[(__bridge NSString *)kUTTypeItem];421 500 if (shouldPresentDocumentMenuViewController) { 422 // FIXME 49979442: UIDocumentMenuViewController is deprecated. Use UIDocumentPickerViewController instead to support multiple file selection. 423 _documentMenuController = adoptNS([[UIDocumentMenuViewController alloc] _initIgnoringApplicationEntitlementForImportOfTypes:documentTypes]); 424 [_documentMenuController setDelegate:self]; 425 426 [_documentMenuController addOptionWithTitle:[self _photoLibraryButtonLabel] image:photoLibraryIcon() order:UIDocumentMenuOrderFirst handler:^{ 427 [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 428 }]; 429 430 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 431 NSString *cameraString = [self _cameraButtonLabelAllowingPhoto:containsImageMediaType allowingVideo:containsVideoMediaType]; 432 [_documentMenuController addOptionWithTitle:cameraString image:cameraIcon() order:UIDocumentMenuOrderFirst handler:^{ 433 _usingCamera = YES; 434 [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypeCamera]; 435 }]; 436 } 437 438 [self _presentMenuOptionForCurrentInterfaceIdiom:_documentMenuController.get()]; 439 } else { 440 // Image and Video types are not accepted so bypass the menu and open the file picker directly. 441 _documentPickerController = adoptNS([[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport]); 442 [_documentPickerController setAllowsMultipleSelection:_allowMultipleFiles]; 443 [_documentPickerController setDelegate:self]; 444 [self _presentFullscreenViewController:_documentPickerController.get() animated:YES]; 445 } 446 447 // Clear out the view controller we just presented. Don't save a reference to the UIDocumentMenuViewController / UIDocumentPickerViewController as it is self dismissing. 501 [self ensureContextMenuInteraction]; 502 [_documentContextMenuInteraction _presentMenuAtLocation:CGPointMake(_interactionPoint.x, _interactionPoint.y)]; 503 } else // Image and Video types are not accepted so bypass the menu and open the file picker directly. 504 [self showFilePickerMenu]; 505 506 // Clear out the view controller we just presented. Don't save a reference to the UIDocumentPickerViewController as it is self dismissing. 448 507 _presentationViewController = nil; 449 508 } … … 521 580 ALLOW_DEPRECATED_DECLARATIONS_END 522 581 [_presentationPopover setDelegate:self]; 523 [_presentationPopover presentPopoverFromRect:CGRectIntegral(CGRectMake(_interactionPoint.x, _interactionPoint.y, 1, 1)) inView:_view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];582 [_presentationPopover presentPopoverFromRect:CGRectIntegral(CGRectMake(_interactionPoint.x, _interactionPoint.y, 1, 1)) inView:_view.getAutoreleased() permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated]; 524 583 } 525 584 … … 528 587 [self _dismissDisplayAnimated:animated]; 529 588 530 _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_view ];589 _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()]; 531 590 [_presentationViewController presentViewController:viewController animated:animated completion:nil]; 532 591 } … … 538 597 ALLOW_DEPRECATED_IMPLEMENTATIONS_END 539 598 { 540 [self _cancel];541 }542 543 #pragma mark - UIDocumentMenuDelegate implementation544 545 - (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker546 {547 documentPicker.delegate = self;548 [self _presentFullscreenViewController:documentPicker animated:YES];549 }550 551 - (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu552 {553 [self _dismissDisplayAnimated:YES];554 599 [self _cancel]; 555 600 }
Note:
See TracChangeset
for help on using the changeset viewer.