This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
using text capitalization value in web #19564
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a38934
using text capitalization value in web engine
4258557
update editing state
0511c5b
add capitalization support to autofill fields
3ca9fe9
add autocapitalize attribute for mobile browsers which effects on scr…
8b49cd0
removing changes on the input value. only keeping onscreen keyboard c…
fb2d122
update unit tests. tests are added for ios-safari. android chrome is …
0cb9f12
changing license files this time don't update LICENSES file
ce17bfc
Update licenses_flutter
cead6ed
addresing reviewer comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
part of engine; | ||
|
||
/// Controls the capitalization of the text. | ||
/// | ||
/// This corresponds to Flutter's [TextCapitalization]. | ||
/// | ||
/// Uses `text-transform` css property. | ||
/// See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform | ||
enum TextCapitalization { | ||
/// Uppercase for the first letter of each word. | ||
words, | ||
|
||
/// Currently not implemented on Flutter Web. Uppercase for the first letter | ||
/// of each sentence. | ||
sentences, | ||
|
||
/// Uppercase for each letter. | ||
characters, | ||
|
||
/// Lowercase for each letter. | ||
none, | ||
} | ||
|
||
/// Helper class for text capitalization. | ||
/// | ||
/// Uses `autocapitalize` attribute on input element. | ||
/// See: https://developers.google.com/web/updates/2015/04/autocapitalize | ||
/// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize | ||
class TextCapitalizationConfig { | ||
final TextCapitalization textCapitalization; | ||
|
||
const TextCapitalizationConfig.defaultCapitalization() | ||
: textCapitalization = TextCapitalization.none; | ||
|
||
TextCapitalizationConfig.fromInputConfiguration(String inputConfiguration) | ||
: this.textCapitalization = | ||
inputConfiguration == 'TextCapitalization.words' | ||
? TextCapitalization.words | ||
: inputConfiguration == 'TextCapitalization.characters' | ||
? TextCapitalization.characters | ||
: inputConfiguration == 'TextCapitalization.sentences' | ||
? TextCapitalization.sentences | ||
: TextCapitalization.none; | ||
|
||
/// Sets `autocapitalize` attribute on input elements. | ||
/// | ||
/// This attribute is only available for mobile browsers. | ||
/// | ||
/// Note that in mobile browsers the onscreen keyboards provide sentence | ||
/// level capitalization as default as apposed to no capitalization on desktop | ||
/// browser. | ||
/// | ||
/// See: https://developers.google.com/web/updates/2015/04/autocapitalize | ||
/// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize | ||
void setAutocapitalizeAttribute(html.HtmlElement domElement) { | ||
String autocapitalize = ''; | ||
switch (textCapitalization) { | ||
case TextCapitalization.words: | ||
// TODO: 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 (browserEngine == BrowserEngine.webkit) { | ||
autocapitalize = 'sentences'; | ||
} else { | ||
autocapitalize = 'words'; | ||
} | ||
break; | ||
case TextCapitalization.characters: | ||
autocapitalize = 'characters'; | ||
break; | ||
case TextCapitalization.sentences: | ||
autocapitalize = 'sentences'; | ||
break; | ||
case TextCapitalization.none: | ||
default: | ||
autocapitalize = 'off'; | ||
break; | ||
} | ||
if (domElement is html.InputElement) { | ||
html.InputElement element = domElement; | ||
element.setAttribute('autocapitalize', autocapitalize); | ||
} else if (domElement is html.TextAreaElement) { | ||
html.TextAreaElement element = domElement; | ||
element.setAttribute('autocapitalize', autocapitalize); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way of handling non-nullability here? @yjbanov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you assign it to a local variable:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this part.
Thanks for the suggestion, it was also giving error Autofill? cannot be passed to Autofill when I tried to use a local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two things that can be null,
items
anditems![key]
.I imagine if we're null-asserting
items
, then we should make the field itself non-null.Otherwise, @mdebbar's suggestion should work.