WebKit should respect TextCapitalization.words (#161027)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> Fixes https://github.com/flutter/flutter/issues/151118 https://github.com/user-attachments/assets/88a9baf9-8f2c-48fb-ad9c-1618fbce0795 Flutter web apps on iOS were forced to use `sentences` instead of `words` when `TextCapitalization.words` was specified, in order to work around this particular bug : https://bugs.webkit.org/show_bug.cgi?id=148504 That bug was fixed more than 4 years ago so it should be safe to use `words` now. With this change, legacy devices that are still on specific versions on iOS 13 or lower might experience the old WebKit bug when `TextCapitalization.words` is used, however the Flutter developer who expects such users can work around that bug by detecting the user agent and using `TextCapitalization.sentences` conditionally, in order to get the existing behavior prior to this change. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
This commit is contained in:
parent
2deb3b4be0
commit
d4c86003d9
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||
|
||||
import '../dom.dart';
|
||||
|
||||
/// Controls the capitalization of the text.
|
||||
@ -62,14 +60,7 @@ class TextCapitalizationConfig {
|
||||
String autocapitalize = '';
|
||||
switch (textCapitalization) {
|
||||
case TextCapitalization.words:
|
||||
// TODO(mdebbar): There is a bug for `words` level capitalization in IOS now.
|
||||
// For now go back to default. Remove the check after bug is resolved.
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=148504
|
||||
if (ui_web.browser.browserEngine == ui_web.BrowserEngine.webkit) {
|
||||
autocapitalize = 'sentences';
|
||||
} else {
|
||||
autocapitalize = 'words';
|
||||
}
|
||||
autocapitalize = 'words';
|
||||
case TextCapitalization.characters:
|
||||
autocapitalize = 'characters';
|
||||
case TextCapitalization.sentences:
|
||||
|
@ -1545,6 +1545,39 @@ Future<void> testMain() async {
|
||||
hideKeyboard();
|
||||
});
|
||||
|
||||
test('Words capitalization: setClient, setEditingState, show', () {
|
||||
// Create a configuration with an AutofillGroup of four text fields.
|
||||
final Map<String, dynamic> capitalizeWordsConfig = createFlutterConfig(
|
||||
'text',
|
||||
textCapitalization: 'TextCapitalization.words',
|
||||
);
|
||||
final MethodCall setClient = MethodCall('TextInput.setClient', <dynamic>[
|
||||
123,
|
||||
capitalizeWordsConfig,
|
||||
]);
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setClient));
|
||||
|
||||
const MethodCall setEditingState1 = MethodCall('TextInput.setEditingState', <String, dynamic>{
|
||||
'text': '',
|
||||
'selectionBase': 0,
|
||||
'selectionExtent': 0,
|
||||
});
|
||||
sendFrameworkMessage(codec.encodeMethodCall(setEditingState1));
|
||||
|
||||
const MethodCall show = MethodCall('TextInput.show');
|
||||
sendFrameworkMessage(codec.encodeMethodCall(show));
|
||||
spy.messages.clear();
|
||||
|
||||
// Test for mobile Safari.
|
||||
if (ui_web.browser.browserEngine == ui_web.BrowserEngine.webkit &&
|
||||
ui_web.browser.operatingSystem == ui_web.OperatingSystem.iOs) {
|
||||
expect(textEditing!.strategy.domElement!.getAttribute('autocapitalize'), 'words');
|
||||
}
|
||||
|
||||
spy.messages.clear();
|
||||
hideKeyboard();
|
||||
});
|
||||
|
||||
test(
|
||||
'setClient, setEditableSizeAndTransform, setStyle, setEditingState, show, clearClient',
|
||||
() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user