Changeset 292184 in webkit
- Timestamp:
- Mar 31, 2022, 2:58:55 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 6 edited
-
WebCore/PAL/ChangeLog (modified) (1 diff)
-
WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h (modified) (1 diff)
-
WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/ios/WKContentViewInteraction.h (modified) (2 diffs)
-
WebKit/UIProcess/ios/WKContentViewInteraction.mm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/PAL/ChangeLog
r292035 r292184 1 2022-03-31 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] Add support for temporarily installing VKCImageAnalysisInteraction on WKContentView 4 https://bugs.webkit.org/show_bug.cgi?id=238582 5 6 Reviewed by Tim Horton. 7 8 Soft link against the image analysis interaction class. 9 10 * pal/cocoa/VisionKitCoreSoftLink.h: 11 * pal/cocoa/VisionKitCoreSoftLink.mm: 12 1 13 2022-03-28 Simon Fraser <simon.fraser@apple.com> 2 14 -
trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.h
r289763 r292184 37 37 SOFT_LINK_CLASS_FOR_HEADER(PAL, VKCImageAnalyzerRequest) 38 38 SOFT_LINK_CLASS_FOR_HEADER(PAL, VKCImageAnalysis) 39 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 40 SOFT_LINK_CLASS_FOR_HEADER(PAL, VKCImageAnalysisInteraction) 41 #endif 39 42 40 43 #if USE(APPLE_INTERNAL_SDK) -
trunk/Source/WebCore/PAL/pal/cocoa/VisionKitCoreSoftLink.mm
r289763 r292184 37 37 SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKCImageAnalyzerRequest, PAL_EXPORT, true) 38 38 SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKCImageAnalysis, PAL_EXPORT, true) 39 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 40 SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT_AND_IS_OPTIONAL(PAL, VisionKitCore, VKCImageAnalysisInteraction, PAL_EXPORT, true) 41 #endif 39 42 40 43 #if USE(APPLE_INTERNAL_SDK) -
trunk/Source/WebKit/ChangeLog
r292183 r292184 1 2022-03-31 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] Add support for temporarily installing VKCImageAnalysisInteraction on WKContentView 4 https://bugs.webkit.org/show_bug.cgi?id=238582 5 6 Reviewed by Tim Horton. 7 8 Add helper methods for temporarily creating and installing an image analysis interaction on the root view. See 9 below for more details. 10 11 * UIProcess/ios/WKContentViewInteraction.h: 12 * UIProcess/ios/WKContentViewInteraction.mm: 13 (-[WKContentView hasSelectablePositionAtPoint:]): 14 (-[WKContentView pointIsNearMarkedText:]): 15 (-[WKContentView textInteractionGesture:shouldBeginAtPoint:]): 16 17 If Live Text exists at the given location, suppress default WebKit text selection behaviors in favor of Live 18 Text instead. 19 20 (-[WKContentView _singleTapRecognized:]): 21 22 Since we only allow the image analysis interaction to begin when interacting directly with regions of the 23 content view that contain Live Text, we need to (manually) clear the native text selection here when handling a 24 tap over other parts of the web view that are not covered by Live Text. 25 26 (-[WKContentView _didCommitLoadForMainFrame]): 27 28 Uninstall the interaction when loading a new page. 29 30 (-[WKContentView gestureRecognizer:shouldIgnoreWebTouchWithEvent:]): 31 (-[WKContentView deferringGestureRecognizer:willBeginTouchesWithEvent:]): 32 33 Don't allow touch events to even begin, if the gesture starts over a region of Live Text. 34 35 (-[WKContentView _tearDownImageAnalysis]): 36 37 Uninstall the interaction when the web process terminates or swaps. 38 39 (-[WKContentView installImageAnalysisInteraction:]): 40 (-[WKContentView uninstallImageAnalysisInteraction]): 41 42 These are the two main helper methods for adding or removing the image analysis interaction. 43 44 (-[WKContentView contentsRectForImageAnalysisInteraction:]): 45 (-[WKContentView imageAnalysisInteraction:shouldBeginAtPoint:forAnalysisType:]): 46 47 Only allow Live Text interaction gestures to begin if there's interactable content at the given location. The 48 only reason why this isn't default behavior already is that the image analysis interaction handles taps that 49 happen outside of Live Text by clearing any active selection; to ensure that this continues to work, we handle 50 the tap ourselves, and clear the native selection directly (see `-_singleTapRecognized:` above). 51 1 52 2022-03-31 Elliott Williams <emw@apple.com> 2 53 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r291770 r292184 113 113 @class AVPlayerViewController; 114 114 @class QLPreviewController; 115 @class VKCImageAnalysisInteraction; 115 116 @class WebEvent; 116 117 @class WebTextIndicatorLayer; … … 541 542 uint32_t _fullscreenVideoExtractionRequestIdentifier; 542 543 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 544 RetainPtr<VKCImageAnalysisInteraction> _imageAnalysisInteraction; 545 WebCore::FloatRect _imageAnalysisInteractionBounds; 543 546 std::optional<WebKit::ImageAnalysisMarkupData> _imageAnalysisMarkupData; 544 547 #endif -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r291863 r292184 232 232 #endif // ENABLE(IMAGE_ANALYSIS) 233 233 234 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 235 236 @interface WKContentView (ImageAnalysisInteraction) <VKCImageAnalysisInteractionDelegate> 237 @end 238 239 #endif 240 234 241 #if USE(APPLE_INTERNAL_SDK) 235 242 #import <WebKitAdditions/WKContentViewInteractionAdditions.mm> … … 2981 2988 - (BOOL)hasSelectablePositionAtPoint:(CGPoint)point 2982 2989 { 2990 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 2991 if ([_imageAnalysisInteraction interactableItemExistsAtPoint:point]) 2992 return NO; 2993 #endif 2994 2983 2995 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 2984 2996 if (!self.webView.configuration._textInteractionGesturesEnabled) … … 3009 3021 - (BOOL)pointIsNearMarkedText:(CGPoint)point 3010 3022 { 3023 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 3024 if ([_imageAnalysisInteraction interactableItemExistsAtPoint:point]) 3025 return NO; 3026 #endif 3027 3011 3028 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 3012 3029 if (!self.webView.configuration._textInteractionGesturesEnabled) … … 3028 3045 - (BOOL)textInteractionGesture:(UIWKGestureType)gesture shouldBeginAtPoint:(CGPoint)point 3029 3046 { 3047 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 3048 if ([_imageAnalysisInteraction interactableItemExistsAtPoint:point]) 3049 return NO; 3050 #endif 3051 3030 3052 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 3031 3053 if (!self.webView.configuration._textInteractionGesturesEnabled) … … 3367 3389 if (!_isExpectingFastSingleTapCommit) 3368 3390 [self _finishInteraction]; 3391 3392 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 3393 if (![_imageAnalysisInteraction interactableItemExistsAtPoint:_lastInteractionLocation]) 3394 [_imageAnalysisInteraction resetSelection]; 3395 #endif 3369 3396 } 3370 3397 … … 5056 5083 #if HAVE(UIKIT_WITH_MOUSE_SUPPORT) 5057 5084 [_hoverPlatter dismissPlatterWithAnimation:NO]; 5085 #endif 5086 5087 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 5088 [self uninstallImageAnalysisInteraction]; 5058 5089 #endif 5059 5090 } … … 7878 7909 _touchEventsCanPreventNativeGestures = YES; 7879 7910 7911 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 7912 if ([_imageAnalysisInteraction interactableItemExistsAtPoint:[gestureRecognizer locationInView:self]]) 7913 return YES; 7914 #endif 7915 7880 7916 return [self gestureRecognizer:gestureRecognizer isInterruptingMomentumScrollingWithEvent:event]; 7881 7917 } … … 8287 8323 { 8288 8324 self.gestureRecognizerConsistencyEnforcer.beginTracking(deferringGestureRecognizer); 8325 8326 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 8327 if ([_imageAnalysisInteraction interactableItemExistsAtPoint:[deferringGestureRecognizer locationInView:self]]) 8328 return WebKit::ShouldDeferGestures::No; 8329 #endif 8289 8330 8290 8331 return [self gestureRecognizer:deferringGestureRecognizer isInterruptingMomentumScrollingWithEvent:event] ? WebKit::ShouldDeferGestures::No : WebKit::ShouldDeferGestures::Yes; … … 10629 10670 [self _invokeAllActionsToPerformAfterPendingImageAnalysis:WebKit::ProceedWithTextSelectionInImage::No]; 10630 10671 #if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) 10672 [self uninstallImageAnalysisInteraction]; 10631 10673 _imageAnalysisMarkupData = std::nullopt; 10632 10674 #endif … … 10945 10987 }]; 10946 10988 }); 10989 } 10990 10991 - (void)installImageAnalysisInteraction:(VKCImageAnalysis *)analysis 10992 { 10993 if (!_imageAnalysisInteraction) { 10994 _imageAnalysisInteraction = adoptNS([PAL::allocVKCImageAnalysisInteractionInstance() init]); 10995 [_imageAnalysisInteraction setActiveInteractionTypes:VKImageAnalysisInteractionTypeTextSelection | VKImageAnalysisInteractionTypeDataDetectors]; 10996 [_imageAnalysisInteraction setDelegate:self]; 10997 [_imageAnalysisInteraction setWantsAutomaticContentsRectCalculation:NO]; 10998 [self addInteraction:_imageAnalysisInteraction.get()]; 10999 } 11000 [_imageAnalysisInteraction setAnalysis:analysis]; 11001 [_imageAnalysisDeferringGestureRecognizer setEnabled:NO]; 11002 [_imageAnalysisGestureRecognizer setEnabled:NO]; 11003 } 11004 11005 - (void)uninstallImageAnalysisInteraction 11006 { 11007 if (!_imageAnalysisInteraction) 11008 return; 11009 11010 [self removeInteraction:_imageAnalysisInteraction.get()]; 11011 _imageAnalysisInteraction = nil; 11012 [_imageAnalysisDeferringGestureRecognizer setEnabled:WebKit::isLiveTextAvailableAndEnabled()]; 11013 [_imageAnalysisGestureRecognizer setEnabled:WebKit::isLiveTextAvailableAndEnabled()]; 11014 } 11015 11016 #pragma mark - VKCImageAnalysisInteractionDelegate 11017 11018 - (CGRect)contentsRectForImageAnalysisInteraction:(VKCImageAnalysisInteraction *)interaction 11019 { 11020 auto unitInteractionRect = _imageAnalysisInteractionBounds; 11021 WebCore::FloatRect unobscuredRect = self.bounds; 11022 unitInteractionRect.moveBy(-unobscuredRect.location()); 11023 unitInteractionRect.scale(1 / unobscuredRect.size()); 11024 return unitInteractionRect; 11025 } 11026 11027 - (BOOL)imageAnalysisInteraction:(VKCImageAnalysisInteraction *)interaction shouldBeginAtPoint:(CGPoint)point forAnalysisType:(VKImageAnalysisInteractionTypes)analysisType 11028 { 11029 return [_imageAnalysisInteraction interactableItemExistsAtPoint:point]; 10947 11030 } 10948 11031
Note:
See TracChangeset
for help on using the changeset viewer.