Title: [292935] trunk/Source/WebKit
Revision
292935
Author
[email protected]
Date
2022-04-15 18:16:01 -0700 (Fri, 15 Apr 2022)

Log Message

Add a helper function to perform additional setup on VKCImageAnalysis(Interaction|OverlayView)
https://bugs.webkit.org/show_bug.cgi?id=239391
rdar://91466567

Reviewed by Tim Horton.

Add a helper function to ImageAnalysisUtilities, and call it on both iOS (WKContentView) and macOS
(WebViewImpl).

* Platform/cocoa/ImageAnalysisUtilities.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::installImageAnalysisOverlayView):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _singleTapIdentified:]):
(-[WKContentView installImageAnalysisInteraction:]):
(-[WKContentView imageAnalysisInteraction:shouldBeginAtPoint:forAnalysisType:]):

Add support for toggling the Live Text overlay when tapping on the image analysis button owned by the
interaction. This custom handling is necessary, since the synthetic tap gesture recognizer does not recognize
simultaneously alongside the tap gesture for VisionKit's UIButton, and we can't (easily) grab VisionKit's
button's tap gesture to add failure requirements to our synthetic tap gesture.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292934 => 292935)


--- trunk/Source/WebKit/ChangeLog	2022-04-16 01:11:06 UTC (rev 292934)
+++ trunk/Source/WebKit/ChangeLog	2022-04-16 01:16:01 UTC (rev 292935)
@@ -1,3 +1,27 @@
+2022-04-15  Wenson Hsieh  <[email protected]>
+
+        Add a helper function to perform additional setup on VKCImageAnalysis(Interaction|OverlayView)
+        https://bugs.webkit.org/show_bug.cgi?id=239391
+        rdar://91466567
+
+        Reviewed by Tim Horton.
+
+        Add a helper function to ImageAnalysisUtilities, and call it on both iOS (WKContentView) and macOS
+        (WebViewImpl).
+
+        * Platform/cocoa/ImageAnalysisUtilities.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::installImageAnalysisOverlayView):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _singleTapIdentified:]):
+        (-[WKContentView installImageAnalysisInteraction:]):
+        (-[WKContentView imageAnalysisInteraction:shouldBeginAtPoint:forAnalysisType:]):
+
+        Add support for toggling the Live Text overlay when tapping on the image analysis button owned by the
+        interaction. This custom handling is necessary, since the synthetic tap gesture recognizer does not recognize
+        simultaneously alongside the tap gesture for VisionKit's UIButton, and we can't (easily) grab VisionKit's
+        button's tap gesture to add failure requirements to our synthetic tap gesture.
+
 2022-04-15  Yusuke Suzuki  <[email protected]>
 
         [JSC] Remove VM& parameter from structure related code including jsDyamicCast

Modified: trunk/Source/WebKit/Platform/cocoa/ImageAnalysisUtilities.h (292934 => 292935)


--- trunk/Source/WebKit/Platform/cocoa/ImageAnalysisUtilities.h	2022-04-16 01:11:06 UTC (rev 292934)
+++ trunk/Source/WebKit/Platform/cocoa/ImageAnalysisUtilities.h	2022-04-16 01:16:01 UTC (rev 292935)
@@ -60,7 +60,14 @@
 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
 void requestImageAnalysisWithIdentifier(CocoaImageAnalyzer *, const String& identifier, CGImageRef, CompletionHandler<void(WebCore::TextRecognitionResult&&)>&&);
 void requestImageAnalysisMarkup(CGImageRef, CompletionHandler<void(CGImageRef, CGRect)>&&);
+
+#if PLATFORM(IOS_FAMILY)
+using PlatformImageAnalysisObject = VKCImageAnalysisInteraction;
+#else
+using PlatformImageAnalysisObject = VKCImageAnalysisOverlayView;
 #endif
+void setUpAdditionalImageAnalysisBehaviors(PlatformImageAnalysisObject *);
+#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
 
 }
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (292934 => 292935)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2022-04-16 01:11:06 UTC (rev 292934)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2022-04-16 01:16:01 UTC (rev 292935)
@@ -5938,6 +5938,7 @@
         [m_imageAnalysisOverlayView setDelegate:m_imageAnalysisOverlayViewDelegate.get()];
         [m_imageAnalysisOverlayView setActiveInteractionTypes:VKImageAnalysisInteractionTypeTextSelection | VKImageAnalysisInteractionTypeDataDetectors];
         [m_imageAnalysisOverlayView setWantsAutomaticContentsRectCalculation:NO];
+        setUpAdditionalImageAnalysisBehaviors(m_imageAnalysisOverlayView.get());
     }
 
     [m_imageAnalysisOverlayView setAnalysis:analysis];

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (292934 => 292935)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-16 01:11:06 UTC (rev 292934)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-16 01:16:01 UTC (rev 292935)
@@ -3273,6 +3273,19 @@
 
 - (void)_singleTapIdentified:(UITapGestureRecognizer *)gestureRecognizer
 {
+    auto position = [self _locationForGesture:gestureRecognizer];
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+    if (UIButton *analysisButton = [_imageAnalysisInteraction analysisButton]) {
+        auto hitTestedView = dynamic_objc_cast<UIButton>([self hitTest:position withEvent:nil]);
+        // FIXME: Instead of a class check, this should be a straightforward equality check.
+        // However, rdar://91828384 currently prevents us from doing so. We can simplify this logic
+        // once the fix for that bug has landed.
+        if (hitTestedView.class == analysisButton.class)
+            [_imageAnalysisInteraction setHighlightSelectableItems:![_imageAnalysisInteraction highlightSelectableItems]];
+        return;
+    }
+#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+
     ASSERT(gestureRecognizer == _singleTapGestureRecognizer);
     ASSERT(!_potentialTapInProgress);
     [self _resetIsDoubleTapPending];
@@ -3289,7 +3302,7 @@
     if (shouldRequestMagnificationInformation)
         RELEASE_LOG(ViewGestures, "Single tap identified. Request details on potential zoom. (%p, pageProxyID=%llu)", self, _page->identifier().toUInt64());
 
-    _page->potentialTapAtPosition([self _locationForGesture:gestureRecognizer], shouldRequestMagnificationInformation, [self nextTapIdentifier]);
+    _page->potentialTapAtPosition(position, shouldRequestMagnificationInformation, [self nextTapIdentifier]);
     _potentialTapInProgress = YES;
     _isTapHighlightIDValid = YES;
     _isExpectingFastSingleTapCommit = !_doubleTapGestureRecognizer.get().enabled;
@@ -11016,6 +11029,7 @@
         [_imageAnalysisInteraction setActiveInteractionTypes:VKImageAnalysisInteractionTypeTextSelection | VKImageAnalysisInteractionTypeDataDetectors];
         [_imageAnalysisInteraction setDelegate:self];
         [_imageAnalysisInteraction setWantsAutomaticContentsRectCalculation:NO];
+        WebKit::setUpAdditionalImageAnalysisBehaviors(_imageAnalysisInteraction.get());
         [self addInteraction:_imageAnalysisInteraction.get()];
     }
     [_imageAnalysisInteraction setAnalysis:analysis];
@@ -11047,7 +11061,7 @@
 
 - (BOOL)imageAnalysisInteraction:(VKCImageAnalysisInteraction *)interaction shouldBeginAtPoint:(CGPoint)point forAnalysisType:(VKImageAnalysisInteractionTypes)analysisType
 {
-    return [_imageAnalysisInteraction interactableItemExistsAtPoint:point];
+    return interaction.hasActiveTextSelection || [interaction interactableItemExistsAtPoint:point];
 }
 
 #endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to