[webkit-changes] [WebKit/WebKit] 1cb03b: [iOS] -[WKContentView hasText] is incorrect when i...

Wenson Hsieh noreply at github.com
Thu Jan 18 22:22:52 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 1cb03ba5c4bb1ddc63bbc8a0565383a242fec767
      https://github.com/WebKit/WebKit/commit/1cb03ba5c4bb1ddc63bbc8a0565383a242fec767
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2024-01-18 (Thu, 18 Jan 2024)

  Changed paths:
    M Source/WebKit/Shared/FocusedElementInformation.h
    M Source/WebKit/Shared/FocusedElementInformation.serialization.in
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
    M Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

  Log Message:
  -----------
  [iOS] -[WKContentView hasText] is incorrect when initially focusing an editable element
https://bugs.webkit.org/show_bug.cgi?id=267729
rdar://120743391

Reviewed by Aditya Keerthi.

Currently, `-hasText` is based entirely on the last cached `EditorState`'s post layout data. In the
case where we've just started showing the keyboard for a focused editable element in
`-[WKContentView _elementDidFocus:…:userObject:]`, we're still waiting for a new `EditorState` to
arrive, so this result ends up being invalid (either `false` if we haven't received any post-layout
editor state yet, or stale editor state data).

To avoid this, we add a `hasPlainText` flag to `FocusedElementInformation` that represents whether
or not the focused element initially had non-empty text content upon focus; if we're currently in
the process of focusing (or are waiting for post-layout data) in `-hasText`, then use this initial
value instead of the `EditorState`.

Test: KeyboardInputTests.HasTextAfterFocusingTextField

* Source/WebKit/Shared/FocusedElementInformation.h:
* Source/WebKit/Shared/FocusedElementInformation.serialization.in:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView hasText]):
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::focusedElementInformation):

For text fields and text areas, instead of using `hasPlainText` (which relies on `TextIterator`),
simply check whether the `value` is non-empty instead to avoid any extra performance cost.

* Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:

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




More information about the webkit-changes mailing list