Title: [270436] trunk/Source/WebKit
Revision
270436
Author
drou...@apple.com
Date
2020-12-04 10:56:48 -0800 (Fri, 04 Dec 2020)

Log Message

[iOS] Provide a context menu action to perform accessibility image extraction
https://bugs.webkit.org/show_bug.cgi?id=219524
<rdar://problem/69969613>

Reviewed by Wenson Hsieh.

* UIProcess/API/Cocoa/_WKElementAction.h:
* UIProcess/API/Cocoa/_WKElementAction.mm:
(+[_WKElementAction _elementActionWithType:customTitle:assistant:]):
(+[_WKElementAction imageForElementActionType:]):
(elementActionTypeToUIActionIdentifier):
(uiActionIdentifierToElementActionType):
Add a new `_WKElementActionTypeImageExtraction` enum type with a default icon and title.

* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
(-[WKActionSheetAssistant defaultActionsForImageSheet:]):
(-[WKActionSheetAssistant handleElementActionWithType:element:needsInteraction:]):
If the `WKActionSheetAssistantDelegate` allows it, add a `_WKElementActionTypeImageExtraction`
action for images (including those inside links). Call out to the `WKActionSheetAssistantDelegate`
when handling the action.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (270435 => 270436)


--- trunk/Source/WebKit/ChangeLog	2020-12-04 18:12:18 UTC (rev 270435)
+++ trunk/Source/WebKit/ChangeLog	2020-12-04 18:56:48 UTC (rev 270436)
@@ -1,3 +1,28 @@
+2020-12-04  Devin Rousso  <drou...@apple.com>
+
+        [iOS] Provide a context menu action to perform accessibility image extraction
+        https://bugs.webkit.org/show_bug.cgi?id=219524
+        <rdar://problem/69969613>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/Cocoa/_WKElementAction.h:
+        * UIProcess/API/Cocoa/_WKElementAction.mm:
+        (+[_WKElementAction _elementActionWithType:customTitle:assistant:]):
+        (+[_WKElementAction imageForElementActionType:]):
+        (elementActionTypeToUIActionIdentifier):
+        (uiActionIdentifierToElementActionType):
+        Add a new `_WKElementActionTypeImageExtraction` enum type with a default icon and title.
+
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+        (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+        (-[WKActionSheetAssistant handleElementActionWithType:element:needsInteraction:]):
+        If the `WKActionSheetAssistantDelegate` allows it, add a `_WKElementActionTypeImageExtraction`
+        action for images (including those inside links). Call out to the `WKActionSheetAssistantDelegate`
+        when handling the action.
+
 2020-12-04  Peng Liu  <peng.l...@apple.com>
 
         [MSE] Move track buffer management from SourceBuffer to SourceBufferPrivate

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.h (270435 => 270436)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.h	2020-12-04 18:12:18 UTC (rev 270435)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.h	2020-12-04 18:56:48 UTC (rev 270436)
@@ -54,6 +54,7 @@
     _WKElementActionTypeOpenInNewWindow WK_API_AVAILABLE(macos(10.15), ios(13.0)),
     _WKElementActionTypeDownload WK_API_AVAILABLE(macos(10.15), ios(13.0)),
     _WKElementActionToggleShowLinkPreviews WK_API_AVAILABLE(macos(10.15), ios(13.0)),
+    _WKElementActionTypeImageExtraction WK_API_AVAILABLE(ios(WK_IOS_TBA)),
 } WK_API_AVAILABLE(macos(10.10), ios(8.0));
 
 WK_CLASS_AVAILABLE(macos(10.10), ios(8.0))

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm (270435 => 270436)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm	2020-12-04 18:12:18 UTC (rev 270435)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm	2020-12-04 18:56:48 UTC (rev 270436)
@@ -61,6 +61,7 @@
 static UIActionIdentifier const WKElementActionTypeOpenInNewWindowIdentifier = @"WKElementActionTypeOpenInNewWindow";
 static UIActionIdentifier const WKElementActionTypeDownloadIdentifier = @"WKElementActionTypeDownload";
 UIActionIdentifier const WKElementActionTypeToggleShowLinkPreviewsIdentifier = @"WKElementActionTypeToggleShowLinkPreviews";
+static UIActionIdentifier const WKElementActionTypeImageExtractionIdentifier = @"WKElementActionTypeImageExtraction";
 
 static NSString * const webkitShowLinkPreviewsPreferenceKey = @"WebKitShowLinkPreviews";
 static NSString * const webkitShowLinkPreviewsPreferenceChangedNotification = @"WebKitShowLinkPreviewsPreferenceChanged";
@@ -159,6 +160,14 @@
     case _WKElementActionToggleShowLinkPreviews:
         // This action must still exist for compatibility, but doesn't do anything.
         break;
+    case _WKElementActionTypeImageExtraction:
+#if ENABLE(IMAGE_EXTRACTION)
+        title = WebCore::localizedNSString(@"Get Info");
+        handler = ^(WKActionSheetAssistant *assistant, _WKActivatedElementInfo *actionInfo) {
+            [assistant handleElementActionWithType:type element:actionInfo needsInteraction:YES];
+        };
+#endif
+        break;
     default:
         [NSException raise:NSInvalidArgumentException format:@"There is no standard web element action of type %ld.", (long)type];
         return nil;
@@ -225,6 +234,8 @@
         return [UIImage systemImageNamed:@"arrow.down.circle"];
     case _WKElementActionToggleShowLinkPreviews:
         return nil; // Intentionally empty.
+    case _WKElementActionTypeImageExtraction:
+        return [UIImage systemImageNamed:@"info.circle"];
     }
 }
 
@@ -255,6 +266,8 @@
         return WKElementActionTypeDownloadIdentifier;
     case _WKElementActionToggleShowLinkPreviews:
         return WKElementActionTypeToggleShowLinkPreviewsIdentifier;
+    case _WKElementActionTypeImageExtraction:
+        return WKElementActionTypeImageExtractionIdentifier;
     }
 }
 
@@ -284,7 +297,8 @@
         return _WKElementActionTypeDownload;
     if ([identifier isEqualToString:WKElementActionTypeToggleShowLinkPreviewsIdentifier])
         return _WKElementActionToggleShowLinkPreviews;
-
+    if ([identifier isEqualToString:WKElementActionTypeImageExtractionIdentifier])
+        return _WKElementActionTypeImageExtraction;
     return _WKElementActionTypeCustom;
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h (270435 => 270436)


--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h	2020-12-04 18:12:18 UTC (rev 270435)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h	2020-12-04 18:56:48 UTC (rev 270436)
@@ -71,6 +71,10 @@
 - (void)removeContextMenuViewIfPossibleForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
 #endif
 - (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithImage:(UIImage *)image rect:(CGRect)boundingRect;
+#if ENABLE(IMAGE_EXTRACTION)
+- (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeImageExtractionActionForElement:(_WKActivatedElementInfo *)element;
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant handleImageExtraction:(UIImage *)image;
+#endif
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm (270435 => 270436)


--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2020-12-04 18:12:18 UTC (rev 270435)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2020-12-04 18:56:48 UTC (rev 270436)
@@ -563,6 +563,13 @@
         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeShare assistant:self]];
     }
 
+#if ENABLE(IMAGE_EXTRACTION)
+    if (elementInfo.type == _WKActivatedElementTypeImage || [elementInfo image]) {
+        if ([_delegate respondsToSelector:@selector(actionSheetAssistant:shouldIncludeImageExtractionActionForElement:)] && [_delegate actionSheetAssistant:self shouldIncludeImageExtractionActionForElement:elementInfo])
+            [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeImageExtraction assistant:self]];
+    }
+#endif
+
     return defaultActions;
 }
 
@@ -586,6 +593,11 @@
     if (!targetURL.scheme.length || [targetURL.scheme caseInsensitiveCompare:@"_javascript_"] != NSOrderedSame)
         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeCopy assistant:self]];
 
+#if ENABLE(IMAGE_EXTRACTION)
+    if ([_delegate respondsToSelector:@selector(actionSheetAssistant:shouldIncludeImageExtractionActionForElement:)] && [_delegate actionSheetAssistant:self shouldIncludeImageExtractionActionForElement:elementInfo])
+        [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeImageExtraction assistant:self]];
+#endif
+
     return defaultActions;
 }
 
@@ -835,6 +847,11 @@
         else
             [delegate actionSheetAssistant:self shareElementWithURL:element.URL ?: element.imageURL rect:element.boundingRect];
         break;
+    case _WKElementActionTypeImageExtraction:
+#if ENABLE(IMAGE_EXTRACTION)
+        [delegate actionSheetAssistant:self handleImageExtraction:element.image];
+#endif
+        break;
     default:
         ASSERT_NOT_REACHED();
         break;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to