forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using text capitalization value in web (flutter#19564)
* using text capitalization value in web engine * update editing state * add capitalization support to autofill fields * add autocapitalize attribute for mobile browsers which effects on screen keyboards * removing changes on the input value. only keeping onscreen keyboard changes * update unit tests. tests are added for ios-safari. android chrome is still not supported * changing license files this time don't update LICENSES file * Update licenses_flutter * addresing reviewer comments
- Loading branch information
nturgut
authored
Jul 10, 2020
1 parent
3dc8163
commit b16c47d
Showing
5 changed files
with
281 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 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 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.