Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fe4d97bab2682759cc7998a5ddb105cc747bf041
      
https://github.com/WebKit/WebKit/commit/fe4d97bab2682759cc7998a5ddb105cc747bf041
  Author: Wenson Hsieh <[email protected]>
  Date:   2023-12-22 (Fri, 22 Dec 2023)

  Changed paths:
    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

  Log Message:
  -----------
  [UIAsyncTextInput] Consolidate 
`-updateSelectionWithExtentPoint:(withBoundary:)completion:` into one method
https://bugs.webkit.org/show_bug.cgi?id=266795
rdar://120010505

Reviewed by Aditya Keerthi.

`UIWKInteractionViewProtocol` currently exposes the following two delegate 
methods, which behave in
totally different ways in WebKit:

1. `-updateSelectionWithExtentPoint:withBoundary:completionHandler:`, which is 
called when selecting
    text by clicking and dragging with a trackpad on iPadOS (for instance, a 
double-click-and-drag
    results in this being called with word granularity). In this case, we use 
`m_initialSelection`,
    previously set by `-selectTextWithGranularity:atPoint:completionHandler:`, 
as the selection base
    and update the selection such that the anchor is set to the DOM position 
corresponding to the
    given `point` in `-updateSelectionWithExtentPoint:completionHandler:`.

2. `-updateSelectionWithExtentPoint:completionHandler:`, which is called when 
selecting text with a
    shift-click or shift-tap, or by long-pressing the Space key on the software 
keyboard to enter
    floating cursor mode with the shift key held down. WebKit implements this 
by expanding the scope
    of the current selection, such that it encompasses the hit-tested DOM 
position or range at the
    given `point` (respecting the given `granularity` when hit-testing).

In rdar://119947213, UIKit intends to replace all calls to (2) with (1) 
instead, passing in
`UITextGranularityCharacter` as the boundary granularity. Without any changes 
in WebKit, this will
break shift-click/tap in webpages, since `m_initialSelection` may not have been 
set (or may be
stale). To avoid this, we refactor 
`-updateSelectionWithExtentPoint:withBoundary:completionHandler:`
such that it falls back to the logic in 
`-updateSelectionWithExtentPoint:completionHandler:` for the
case where we're using character granularity and we're also not dragging to 
change the selection,
and otherwise behaves the same as it did before this change (for the 
click-and-drag case).

* Source/WebKit/UIProcess/ios/UIKitUtilities.h:
* Source/WebKit/UIProcess/ios/UIKitUtilities.mm:
(-[UIGestureRecognizer _wk_hasRecognizedOrEnded]):

Drive-by refactoring: pull logic that checks whether the state of a gesture 
recognizer is one of
{`Began`, `Changed`, or `Ended`} into a separate helper method, and deploy it 
in several places
where we perform this check.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanUpInteraction]):
(-[WKContentView _isPanningScrollViewOrAncestor:]):
(-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
(-[WKContentView selectTextWithGranularity:atPoint:completionHandler:]):
(-[WKContentView updateSelectionWithExtentPoint:completionHandler:]):

This now just calls into 
`-updateSelectionWithExtentPoint:withBoundary:completionHandler:` using
character granularity; it's still needed for bincompat, but after 
rdar://119947213 lands we can
remove this method entirely.

(-[WKContentView 
updateSelectionWithExtentPoint:withBoundary:completionHandler:]):
(-[WKContentView mouseInteraction:changedWithEvent:]):

Reset `_usingMouseDragForSelection` back to NO after `mouseup`.

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


_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to