Title: [293454] trunk
Revision
293454
Author
[email protected]
Date
2022-04-26 14:51:06 -0700 (Tue, 26 Apr 2022)

Log Message

Show the option to Markup Image in the callout bar only when appropriate
https://bugs.webkit.org/show_bug.cgi?id=239779
rdar://88941823

Reviewed by Darin Adler.

Source/WebKit:

Make a minor adjustment to only show this callout bar action in the case where `_imageAnalysisMarkupData` has
already been computed and cached.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView imageAnalysisMarkupMenu]):

Tools:

Adjust some API tests so that they continue passing after these changes.

* TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm:
(TestWebKitAPI::iconImage):
(TestWebKitAPI::simulateCalloutBarAppearance):
(TestWebKitAPI::invokeImageMarkupAction):
(TestWebKitAPI::TEST):
(TestWebKitAPI::runMarkupTest):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (293453 => 293454)


--- trunk/Source/WebKit/ChangeLog	2022-04-26 21:35:01 UTC (rev 293453)
+++ trunk/Source/WebKit/ChangeLog	2022-04-26 21:51:06 UTC (rev 293454)
@@ -1,3 +1,17 @@
+2022-04-26  Wenson Hsieh  <[email protected]>
+
+        Show the option to Markup Image in the callout bar only when appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=239779
+        rdar://88941823
+
+        Reviewed by Darin Adler.
+
+        Make a minor adjustment to only show this callout bar action in the case where `_imageAnalysisMarkupData` has
+        already been computed and cached.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView imageAnalysisMarkupMenu]):
+
 2022-04-26  Manuel Rego Casasnovas  <[email protected]>
 
         Remove AriaReflectionEnabled runtime flag

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (293453 => 293454)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-26 21:35:01 UTC (rev 293453)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-26 21:51:06 UTC (rev 293454)
@@ -4750,9 +4750,12 @@
     if (!_page || !_page->preferences().imageAnalysisMarkupEnabled())
         return nil;
 
-    if (_page->editorState().isMissingPostLayoutData || !_page->editorState().postLayoutData().selectedEditableImage)
+    if (_page->editorState().isMissingPostLayoutData || !_imageAnalysisMarkupData)
         return nil;
 
+    if (_imageAnalysisMarkupData->element != _page->editorState().postLayoutData().selectedEditableImage)
+        return nil;
+
     return [self menuWithInlineAction:WebCore::contextMenuItemTitleMarkupImage() identifier:@"WKActionMarkupImage" handler:[](WKContentView *view) {
         if (!view->_imageAnalysisMarkupData)
             return;

Modified: trunk/Tools/ChangeLog (293453 => 293454)


--- trunk/Tools/ChangeLog	2022-04-26 21:35:01 UTC (rev 293453)
+++ trunk/Tools/ChangeLog	2022-04-26 21:51:06 UTC (rev 293454)
@@ -1,3 +1,20 @@
+2022-04-26  Wenson Hsieh  <[email protected]>
+
+        Show the option to Markup Image in the callout bar only when appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=239779
+        rdar://88941823
+
+        Reviewed by Darin Adler.
+
+        Adjust some API tests so that they continue passing after these changes.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm:
+        (TestWebKitAPI::iconImage):
+        (TestWebKitAPI::simulateCalloutBarAppearance):
+        (TestWebKitAPI::invokeImageMarkupAction):
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::runMarkupTest):
+
 2022-04-26  Simon Fraser  <[email protected]>
 
         [ iOS EWS ] css3/background/background-repeat-round-auto2.html is a image failure

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm (293453 => 293454)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm	2022-04-26 21:35:01 UTC (rev 293453)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm	2022-04-26 21:51:06 UTC (rev 293454)
@@ -324,8 +324,35 @@
 
 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) && PLATFORM(IOS_FAMILY)
 
+static RetainPtr<UIImage> iconImage()
+{
+    auto iconPath = [NSBundle.mainBundle pathForResource:@"icon" ofType:@"png" inDirectory:@"TestWebKitAPI.resources"];
+    return [UIImage imageWithContentsOfFile:iconPath];
+}
+
+static void simulateCalloutBarAppearance(TestWKWebView *webView)
+{
+    __block bool done = false;
+    [webView.textInputContentView requestRectsToEvadeForSelectionCommandsWithCompletionHandler:^(NSArray<NSValue *> *) {
+        done = true;
+    }];
+    Util::run(&done);
+}
+
+static void invokeImageMarkupAction(TestWKWebView *webView)
+{
+    simulateCalloutBarAppearance(webView);
+
+    auto menuBuilder = adoptNS([[TestUIMenuBuilder alloc] init]);
+    [webView buildMenuWithBuilder:menuBuilder.get()];
+    [[menuBuilder actionWithTitle:WebCore::contextMenuItemTitleMarkupImage()] _performActionWithSender:nil];
+    [webView waitForNextPresentationUpdate];
+}
+
 TEST(ImageAnalysisTests, MenuControllerItems)
 {
+    ImageAnalysisMarkupSwizzler swizzler { [iconImage() CGImage], CGRectMake(10, 10, 215, 174) };
+
     auto webView = createWebViewWithTextRecognitionEnhancements();
     auto inputDelegate = adoptNS([TestInputDelegate new]);
     [inputDelegate setFocusStartsInputSessionPolicyHandler:[](WKWebView *, id <_WKFocusedElementInfo>) {
@@ -337,6 +364,7 @@
     [webView synchronouslyLoadTestPageNamed:@"multiple-images"];
     [webView objectByEvaluatingJavaScript:@"let image = document.images[0]; getSelection().setBaseAndExtent(image, 0, image, 1);"];
     [webView waitForNextPresentationUpdate];
+    simulateCalloutBarAppearance(webView.get());
 
     auto menuBuilder = adoptNS([[TestUIMenuBuilder alloc] init]);
     [webView buildMenuWithBuilder:menuBuilder.get()];
@@ -344,6 +372,7 @@
 
     [webView selectAll:nil];
     [webView waitForNextPresentationUpdate];
+    simulateCalloutBarAppearance(webView.get());
 
     [menuBuilder reset];
     [webView buildMenuWithBuilder:menuBuilder.get()];
@@ -351,6 +380,7 @@
 
     [webView objectByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(document.body, 0, document.images[0], 1);"];
     [webView waitForNextPresentationUpdate];
+    simulateCalloutBarAppearance(webView.get());
 
     [menuBuilder reset];
     [webView buildMenuWithBuilder:menuBuilder.get()];
@@ -357,26 +387,9 @@
     EXPECT_NOT_NULL([menuBuilder actionWithTitle:WebCore::contextMenuItemTitleMarkupImage()]);
 }
 
-static void invokeImageMarkupAction(TestWKWebView *webView)
-{
-    // Simulate callout bar appearance.
-    __block bool done = false;
-    [webView.textInputContentView requestRectsToEvadeForSelectionCommandsWithCompletionHandler:^(NSArray<NSValue *> *) {
-        done = true;
-    }];
-    Util::run(&done);
-
-    auto menuBuilder = adoptNS([[TestUIMenuBuilder alloc] init]);
-    [webView buildMenuWithBuilder:menuBuilder.get()];
-    [[menuBuilder actionWithTitle:WebCore::contextMenuItemTitleMarkupImage()] _performActionWithSender:nil];
-    [webView waitForNextPresentationUpdate];
-}
-
 static void runMarkupTest(NSString *testPage, NSString *scriptToSelectText, Function<void(TestWKWebView *, NSString *)>&& checkWebView)
 {
-    auto iconPath = [NSBundle.mainBundle pathForResource:@"icon" ofType:@"png" inDirectory:@"TestWebKitAPI.resources"];
-    RetainPtr iconImage = [UIImage imageWithContentsOfFile:iconPath];
-    ImageAnalysisMarkupSwizzler swizzler { [iconImage CGImage], CGRectMake(10, 10, 215, 174) };
+    ImageAnalysisMarkupSwizzler swizzler { [iconImage() CGImage], CGRectMake(10, 10, 215, 174) };
 
     auto webView = createWebViewWithTextRecognitionEnhancements();
     auto inputDelegate = adoptNS([TestInputDelegate new]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to