Title: [250015] trunk
Revision
250015
Author
[email protected]
Date
2019-09-17 18:20:41 -0700 (Tue, 17 Sep 2019)

Log Message

Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
https://bugs.webkit.org/show_bug.cgi?id=201864
<rdar://55190038>

Reviewed by Simon Fraser.

Source/WebKit:

* UIProcess/ios/WKActionSheetAssistant.mm: Remove the toggle action from the
default values.
(-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
* UIProcess/ios/WKContentViewInteraction.mm: No longer try to add a toggle when
it isn't there.
(-[WKContentView assignLegacyDataForContextMenuInteraction]):
(menuWithShowLinkPreviewAction): Deleted.

Tools:

Test for the suggested actions.

* TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
(-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
(-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuWillPresentForElement:]):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (250014 => 250015)


--- trunk/Source/WebKit/ChangeLog	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Source/WebKit/ChangeLog	2019-09-18 01:20:41 UTC (rev 250015)
@@ -1,3 +1,19 @@
+2019-09-17  Dean Jackson  <[email protected]>
+
+        Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+        https://bugs.webkit.org/show_bug.cgi?id=201864
+        <rdar://55190038>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/ios/WKActionSheetAssistant.mm: Remove the toggle action from the
+        default values.
+        (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+        * UIProcess/ios/WKContentViewInteraction.mm: No longer try to add a toggle when
+        it isn't there.
+        (-[WKContentView assignLegacyDataForContextMenuInteraction]):
+        (menuWithShowLinkPreviewAction): Deleted.
+
 2019-09-17  Chris Dumez  <[email protected]>
 
         Stop calling Page::setSessionID() from WebKit2

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKElementAction.mm	2019-09-18 01:20:41 UTC (rev 250015)
@@ -121,8 +121,8 @@
 
 + (instancetype)_elementActionWithType:(_WKElementActionType)type customTitle:(NSString *)customTitle assistant:(WKActionSheetAssistant *)assistant
 {
-    NSString *title;
-    WKElementActionHandlerInternal handler;
+    NSString *title = @"";
+    WKElementActionHandlerInternal handler = nil;
     switch (type) {
     case _WKElementActionTypeCopy:
         title = WEB_UI_STRING_KEY("Copy", "Copy (ActionSheet)", "Title for Copy Link or Image action button");
@@ -164,17 +164,9 @@
             [assistant.delegate actionSheetAssistant:assistant shareElementWithURL:actionInfo.URL ?: actionInfo.imageURL rect:actionInfo.boundingRect];
         };
         break;
-    case _WKElementActionToggleShowLinkPreviews: {
-        bool showingLinkPreviews = true;
-        if (NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:webkitShowLinkPreviewsPreferenceKey])
-            showingLinkPreviews = value.boolValue;
-
-        title = showingLinkPreviews ? WEB_UI_STRING("Hide Link Previews", "Title for Hide Link Previews action button") : WEB_UI_STRING("Show Link Previews", "Title for Show Link Previews action button");
-        handler = ^(WKActionSheetAssistant *, _WKActivatedElementInfo *) {
-            [[NSUserDefaults standardUserDefaults] setBool:!showingLinkPreviews forKey:webkitShowLinkPreviewsPreferenceKey];
-        };
+    case _WKElementActionToggleShowLinkPreviews:
+        // This action must still exist for compatibility, but doesn't do anything.
         break;
-    }
     default:
         [NSException raise:NSInvalidArgumentException format:@"There is no standard web element action of type %ld.", (long)type];
         return nil;

Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm (250014 => 250015)


--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2019-09-18 01:20:41 UTC (rev 250015)
@@ -558,8 +558,6 @@
         [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionTypeShare assistant:self]];
     }
 
-    [defaultActions addObject:[_WKElementAction _elementActionWithType:_WKElementActionToggleShowLinkPreviews assistant:self]];
-
     return defaultActions;
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (250014 => 250015)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-18 01:20:41 UTC (rev 250015)
@@ -7875,32 +7875,6 @@
     return [UIMenu menuWithTitle:title children:actions];
 }
 
-static UIMenu *menuWithShowLinkPreviewAction(UIMenu *originalMenu)
-{
-    if (!originalMenu)
-        return nil;
-
-    // Look for a UIAction that has the WKElementActionTypeToggleShowLinkPreviewsIdentifier.
-    NSUInteger result = [originalMenu.children indexOfObjectPassingTest:^BOOL(UIMenuElement *element, NSUInteger index, BOOL *stop) {
-        if (![element isKindOfClass:[UIAction class]])
-            return NO;
-        if ([(UIAction *)element identifier] == WKElementActionTypeToggleShowLinkPreviewsIdentifier) {
-            *stop = YES;
-            return YES;
-        }
-        return NO;
-    }];
-    if (result != NSNotFound)
-        return originalMenu;
-
-    // We didn't find one, so make a new UIMenu with the toggle action.
-    NSMutableArray<UIMenuElement *> *menuElements = [NSMutableArray arrayWithCapacity:(originalMenu.children.count + 1)];
-    [menuElements addObjectsFromArray:originalMenu.children];
-    _WKElementAction *toggleAction = [_WKElementAction elementActionWithType:_WKElementActionToggleShowLinkPreviews];
-    [menuElements addObject:[toggleAction uiActionForElementInfo:nil]];
-    return [originalMenu menuByReplacingChildren:menuElements];
-}
-
 - (void)assignLegacyDataForContextMenuInteraction
 {
     ASSERT(!_contextMenuHasRequestedLegacyData);
@@ -7953,7 +7927,7 @@
                     _contextMenuLegacyPreviewController = dataDetectorsResult.get().previewProvider();
                 if (dataDetectorsResult && dataDetectorsResult.get().actionProvider) {
                     auto menuElements = menuElementsFromDefaultActions(defaultActionsFromAssistant, elementInfo);
-                    _contextMenuLegacyMenu = menuWithShowLinkPreviewAction(dataDetectorsResult.get().actionProvider(menuElements));
+                    _contextMenuLegacyMenu = dataDetectorsResult.get().actionProvider(menuElements);
                 }
                 END_BLOCK_OBJC_EXCEPTIONS;
             }

Modified: trunk/Tools/ChangeLog (250014 => 250015)


--- trunk/Tools/ChangeLog	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Tools/ChangeLog	2019-09-18 01:20:41 UTC (rev 250015)
@@ -1,3 +1,18 @@
+2019-09-17  Dean Jackson  <[email protected]>
+
+        Remove the "Show Link Previews" and "Hide Link Previews" action menus in the preview platter
+        https://bugs.webkit.org/show_bug.cgi?id=201864
+        <rdar://55190038>
+
+        Reviewed by Simon Fraser.
+
+        Test for the suggested actions.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm:
+        (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuConfigurationForElement:completionHandler:]):
+        (-[TestContextMenuSuggestedActionsUIDelegate webView:contextMenuWillPresentForElement:]):
+        (TEST):
+
 2019-09-17  Jonathan Bedard  <[email protected]>
 
         results.webkit.org results bubbles' tooltips should include SDK information

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm (250014 => 250015)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-09-18 01:15:21 UTC (rev 250014)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContextMenus.mm	2019-09-18 01:20:41 UTC (rev 250015)
@@ -73,7 +73,7 @@
     contextMenuRequested = true;
     UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
     {
-        return [UIViewController new];
+        return [[[UIViewController alloc] init] autorelease];
     };
     UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
     {
@@ -248,5 +248,56 @@
 
 #pragma clang diagnostic pop
 
+@interface TestContextMenuSuggestedActionsUIDelegate : NSObject <WKUIDelegate>
+@end
 
+@implementation TestContextMenuSuggestedActionsUIDelegate
+
+- (void)webView:(WKWebView *)webView contextMenuConfigurationForElement:(WKContextMenuElementInfo *)elementInfo completionHandler:(void(^)(UIContextMenuConfiguration * _Nullable))completionHandler
+{
+    EXPECT_TRUE([elementInfo.linkURL.absoluteString isEqualToString:[linkURL absoluteString]]);
+    contextMenuRequested = true;
+    UIContextMenuContentPreviewProvider previewProvider = ^UIViewController * ()
+    {
+        return [[[UIViewController alloc] init] autorelease];
+    };
+    UIContextMenuActionProvider actionProvider = ^UIMenu *(NSArray<UIMenuElement *> *suggestedActions)
+    {
+        NSArray<NSString *> *expectedIdentifiers = @[
+            @"WKElementActionTypeOpen",
+            @"WKElementActionTypeAddToReadingList",
+            @"WKElementActionTypeCopy",
+            @"WKElementActionTypeShare"
+        ];
+        EXPECT_TRUE(expectedIdentifiers.count == suggestedActions.count);
+
+        [suggestedActions enumerateObjectsUsingBlock:^(UIMenuElement *menuElement, NSUInteger index, BOOL *) {
+            EXPECT_TRUE([menuElement isKindOfClass:[UIAction class]]);
+            EXPECT_TRUE([[(UIAction *)menuElement identifier] isEqualToString:expectedIdentifiers[index]]);
+        }];
+        return [UIMenu menuWithTitle:@"" children:suggestedActions];
+    };
+    completionHandler([UIContextMenuConfiguration configurationWithIdentifier:nil previewProvider:previewProvider actionProvider:actionProvider]);
+}
+
+- (void)webView:(WKWebView *)webView contextMenuWillPresentForElement:(WKContextMenuElementInfo *)elementInfo
+{
+    willPresentCalled = true;
+}
+
+@end
+
+TEST(WebKit, ContextMenuSuggestedActions)
+{
+    auto driver = contextMenuWebViewDriver([TestContextMenuSuggestedActionsUIDelegate class]);
+    [driver begin:^(BOOL result) {
+        EXPECT_TRUE(result);
+        [driver clickDown];
+        [driver clickUp];
+    }];
+    TestWebKitAPI::Util::run(&willPresentCalled);
+    EXPECT_TRUE(contextMenuRequested);
+    EXPECT_TRUE(willPresentCalled);
+}
+
 #endif // PLATFORM(IOS) && USE(UICONTEXTMENU)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to