Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ iOS ] 3x editing/spelling/* (layout-tests) are constant failures #27003

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

whsieh
Copy link
Member

@whsieh whsieh commented Apr 9, 2024

697b1a8

[ iOS ] 3x editing/spelling/* (layout-tests) are constant failures
https://bugs.webkit.org/show_bug.cgi?id=271864
rdar://125585822

Reviewed by Aditya Keerthi.

Among the many other changes to adopt `BETextInput`, iOS 17.4 refactored `WKContentView` to stop
relying on the UIKit internal method `-_requiresKeyboardWhenFirstResponder`. Instead, UIKit now
returns `YES` when the delegate is a `BETextInput`, as long as either of the following are true:

1. The hardware keyboard is connected.
2. An editable element is focused.

However, a consequence of this refactoring is that `WKContentView` now vends text input traits to
keyboard code in UIKit when a hardware keyboard is attached, even in the case where there is no
focused element. In practice, this doesn't really matter, since these text input traits (which
contain `UITextAutocorrectionTypeNo`) are effectively unused. However, in the case of these three
layout tests that programmatically focus text inputs, insert text, and expect spellchecking to
occur outside of the context of any input session, we end up failing because the spelling
corrections are disabled by the traits.

To fix this, restore pre-iOS 17.4 behavior by reverting to `WKExtendedTextInputTraits`'s default
values when no element is focused (or being focused). Namely, this ensures that the autocorrection
type is set to `UITextAutocorrectionTypeDefault`, which matches shipping behavior in the case when
the user isn't focusing anything editable, but still enables continuous spellchecking when
programmatically inserting text.

* LayoutTests/platform/ios/TestExpectations:

Mark these layout test as passing again.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateTextInputTraits:]):
(-[WKContentView extendedTraitsDelegate]):

See above for more details.

* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.h:
* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm:
(-[WKExtendedTextInputTraits init]):
(-[WKExtendedTextInputTraits setSelectionColorsToMatchTintColor:]):
(-[WKExtendedTextInputTraits restoreDefaultValues]):

Add a new method to restore all default text input traits.

(-[WKExtendedTextInputTraits setSelectionBarColor:]): Deleted.
(-[WKExtendedTextInputTraits selectionBarColor]): Deleted.

Remove some old versions of the `UIAsyncTextInput` implementation that are no longer necessary,
since they've all been superceded by `BETextInput`.

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

41e070e

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
loading πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv loading-orange πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@whsieh whsieh requested a review from cdumez as a code owner April 9, 2024 01:09
@whsieh whsieh self-assigned this Apr 9, 2024
@whsieh whsieh added the New Bugs Unclassified bugs are placed in this component until the correct component can be determined. label Apr 9, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 9, 2024
@whsieh whsieh removed the merging-blocked Applied to prevent a change from being merged label Apr 9, 2024
self.selectionHighlightColor = shouldUseTintColor ? [tintColor colorWithAlphaComponent:selectionHighlightAlphaComponent] : nil;
}

- (void)restoreDefaultValues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk if the property list in this method gets out-of-date? (I think no, but want to confirm)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right β€” it would get out of date if we added a new @property to WKExtendedTextInputTraits, but didn't update this method as well. That said, I think it's not that easy to make that mistake, as long as whoever's adding the new property searches the existing code for any of the other existing properties, and follows the same precedent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my question is more specifically: "What would the effect be (if any) if the list were to get out-of-date?".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. It's pretty unlikely this would user-facing effects even if the list were to get out-of-date, since this would only affect the case where UIKit relies on text input traits outside of text input. The only other trait that falls into this category is selection highlight and handle color (which I made sure to update separately, in this patch), and apparently this autocorrectionType which influences whether or not continuous spellchecking is enabled.

@whsieh whsieh added the merge-queue Applied to send a pull request to merge-queue label Apr 9, 2024
@whsieh
Copy link
Member Author

whsieh commented Apr 9, 2024

Thanks for the review!

https://bugs.webkit.org/show_bug.cgi?id=271864
rdar://125585822

Reviewed by Aditya Keerthi.

Among the many other changes to adopt `BETextInput`, iOS 17.4 refactored `WKContentView` to stop
relying on the UIKit internal method `-_requiresKeyboardWhenFirstResponder`. Instead, UIKit now
returns `YES` when the delegate is a `BETextInput`, as long as either of the following are true:

1. The hardware keyboard is connected.
2. An editable element is focused.

However, a consequence of this refactoring is that `WKContentView` now vends text input traits to
keyboard code in UIKit when a hardware keyboard is attached, even in the case where there is no
focused element. In practice, this doesn't really matter, since these text input traits (which
contain `UITextAutocorrectionTypeNo`) are effectively unused. However, in the case of these three
layout tests that programmatically focus text inputs, insert text, and expect spellchecking to
occur outside of the context of any input session, we end up failing because the spelling
corrections are disabled by the traits.

To fix this, restore pre-iOS 17.4 behavior by reverting to `WKExtendedTextInputTraits`'s default
values when no element is focused (or being focused). Namely, this ensures that the autocorrection
type is set to `UITextAutocorrectionTypeDefault`, which matches shipping behavior in the case when
the user isn't focusing anything editable, but still enables continuous spellchecking when
programmatically inserting text.

* LayoutTests/platform/ios/TestExpectations:

Mark these layout test as passing again.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _updateTextInputTraits:]):
(-[WKContentView extendedTraitsDelegate]):

See above for more details.

* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.h:
* Source/WebKit/UIProcess/ios/WKExtendedTextInputTraits.mm:
(-[WKExtendedTextInputTraits init]):
(-[WKExtendedTextInputTraits setSelectionColorsToMatchTintColor:]):
(-[WKExtendedTextInputTraits restoreDefaultValues]):

Add a new method to restore all default text input traits.

(-[WKExtendedTextInputTraits setSelectionBarColor:]): Deleted.
(-[WKExtendedTextInputTraits selectionBarColor]): Deleted.

Remove some old versions of the `UIAsyncTextInput` implementation that are no longer necessary,
since they've all been superceded by `BETextInput`.

Canonical link: https://commits.webkit.org/277233@main
@webkit-commit-queue
Copy link
Collaborator

Committed 277233@main (697b1a8): https://commits.webkit.org/277233@main

Reviewed commits have been landed. Closing PR #27003 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 697b1a8 into WebKit:main Apr 9, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Bugs Unclassified bugs are placed in this component until the correct component can be determined.
Projects
None yet
5 participants