Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fc97a476c1ba96242447c97545d192d3aa7453ef
      
https://github.com/WebKit/WebKit/commit/fc97a476c1ba96242447c97545d192d3aa7453ef
  Author: Wenson Hsieh <wenson_hs...@apple.com>
  Date:   2025-03-20 (Thu, 20 Mar 2025)

  Changed paths:
    A 
LayoutTests/editing/selection/ios/selection-highlight-for-live-text-in-scrollable-area-expected.txt
    A 
LayoutTests/editing/selection/ios/selection-highlight-for-live-text-in-scrollable-area.html
    M LayoutTests/resources/ui-helper.js
    M Source/WebKit/UIProcess/Cocoa/WKTextSelectionRect.h
    M Source/WebKit/UIProcess/Cocoa/WKTextSelectionRect.mm
    M Source/WebKit/UIProcess/ios/UIKitUtilities.h
    M Source/WebKit/UIProcess/ios/UIKitUtilities.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
    M Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

  Log Message:
  -----------
  [iOS] [SelectionHonorsOverflowScrolling] Live Text selection handles are 
incorrectly positioned in overflow scrollers
https://bugs.webkit.org/show_bug.cgi?id=290115
rdar://147430337

Reviewed by Abrar Rahman Protyasha.

In order to support rotated text selections for Live Text in images, we make 
`WKTextSelectionRect`
return custom selection handle info (i.e., a `CGPoint` quad indicating where 
the selection handles
should be placed relative to the container). Currently, the points that 
comprise this quad is in
root view coordinates, but with the "Selection Honors Overflow Scrolling" 
feature enabled, this is
no longer (generally) correct, since the selection container may now be a child 
compositing view
under the content view.

This incorrect coordinate space causes just the handles of the selection to be 
terribly offset in
some cases — e.g., when the image with Live Text is inside of a subscrollable 
container. To fix this
bug, we map the custom selection handle quad into selection container 
coordinates through a new
`WKTextSelectionRectDelegate` method implemented by `WKContentView`.

See below for more details.

* 
LayoutTests/editing/selection/ios/selection-highlight-for-live-text-in-scrollable-area-expected.txt:
 Added.
* 
LayoutTests/editing/selection/ios/selection-highlight-for-live-text-in-scrollable-area.html:
 Added.

Add a layout test to exercise this change, by verifying that selection UI in 
Live Text is contained
within the image element's bounds.

* LayoutTests/resources/ui-helper.js:
(window.UIHelper.rectContainsOtherRect):
* Source/WebKit/UIProcess/Cocoa/WKTextSelectionRect.h:
* Source/WebKit/UIProcess/Cocoa/WKTextSelectionRect.mm:

Add an optional `WKTextSelectionRectDelegate` argument to the initializer here, 
which takes the
place of the `scaleFactor` argument. Instead, this new delegate has two 
methods: one that returns
the current content scale factor (replacing the `_scaleFactor` ivar) and 
another method to convert
a `FloatQuad` into selection container coordinates, which we use below to fix 
the bug.

(-[WKTextSelectionRect initWithCGRect:]):
(-[WKTextSelectionRect initWithSelectionGeometry:delegate:]):
(-[WKTextSelectionRect _path]):
(-[WKTextSelectionRect _convertQuadToSelectionContainer:]):
(-[WKTextSelectionRect _customHandleInfo]):

See above for more information.

(-[WKTextSelectionRect initWithSelectionGeometry:scaleFactor:]): Deleted.
* Source/WebKit/UIProcess/ios/UIKitUtilities.h:
* Source/WebKit/UIProcess/ios/UIKitUtilities.mm:
(-[UIView _wk_convertQuad:toCoordinateSpace:]):

Add a helper method to convert a `WebCore::FloatQuad` into the given coordinate 
space (inspired by
existing UIKit API to convert `CGPoint` / `CGRect` from one coordinate space to 
another).

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _textSelectionRects:]):
(-[WKContentView scaleFactorForSelectionRect:]):
(-[WKContentView selectionRect:convertQuadToSelectionContainer:]):

Implement the new `WKTextSelectionRectDelegate` methods.

(-[WKContentView selectedTextRange]):
(-[WKContentView markedTextRange]):
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::computeEnclosingLayerID const):

Additionally, make Live Text selections parented in the the enclosing layer of 
the host image,
rather than being inside the absolutely positioned containers in the UA shadow 
DOM. This prevents
unnecessarily unparenting/reparenting of the managed text interaction subviews 
when selecting Live
Text across word or line boundaries.

* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::sanityCheckCustomHandlePath):
(WTR::UIScriptControllerIOS::selectionStartGrabberViewRect const):
(WTR::UIScriptControllerIOS::selectionEndGrabberViewRect const):

Add some more assertions to sanity check the custom path of the selection 
handles, and verify that
they're never so far outside of the bounds of the handle view itself, that they 
don't intersect with
the handle view.

Canonical link: https://commits.webkit.org/292449@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to