@@ -1487,3 +1487,90 @@ class EditableTextGeometry {
14871487 ..transform = cssTransform;
14881488 }
14891489}
1490+
1491+ /// Controls the capitalization of the text.
1492+ ///
1493+ /// This corresponds to Flutter's [TextCapitalization] .
1494+ ///
1495+ /// Uses `text-transform` css property.
1496+ /// See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform
1497+ enum TextCapitalization {
1498+ /// Uppercase for the first letter of each word.
1499+ words,
1500+
1501+ /// Currently not implemented on Flutter Web. Uppercase for the first letter
1502+ /// of each sentence.
1503+ sentences,
1504+
1505+ /// Uppercase for each letter.
1506+ characters,
1507+
1508+ /// Lowercase for each letter.
1509+ none,
1510+ }
1511+
1512+ /// Helper class for text capitalization.
1513+ ///
1514+ /// Uses `text-transform` css property.
1515+ /// See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform
1516+ class TextCapitalizationConfig {
1517+ final TextCapitalization textCapitalization;
1518+
1519+ static final RegExp wordExp = new RegExp (r"(\w+)" );
1520+ static final RegExp whiteSpaceExp = new RegExp (r"(\s+)" );
1521+
1522+ const TextCapitalizationConfig .defaultCapitalization ()
1523+ : textCapitalization = TextCapitalization .none;
1524+
1525+ // TODO: support sentence level text capitalization.
1526+ TextCapitalizationConfig .fromInputConfiguration (String inputConfiguration)
1527+ : this .textCapitalization =
1528+ inputConfiguration == 'TextCapitalization.words'
1529+ ? TextCapitalization .words
1530+ : (inputConfiguration == 'TextCapitalization.characters' )
1531+ ? TextCapitalization .characters
1532+ : TextCapitalization .none;
1533+
1534+ /// Sets `autocapitalize` attribute on input elements.
1535+ ///
1536+ /// This attribute is only available for mobile browsers.
1537+ ///
1538+ /// Note that in mobile browsers the onscreen keyboards provide sentence
1539+ /// level capitalization as default as apposed to no capitalization on desktop
1540+ /// browser.
1541+ ///
1542+ /// See: https://developers.google.com/web/updates/2015/04/autocapitalize
1543+ /// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize
1544+ void setAutocapitalizeAttribute (html.HtmlElement domElement) {
1545+ String autocapitalize = '' ;
1546+ switch (textCapitalization) {
1547+ case TextCapitalization .words:
1548+ // TODO: There is a bug for `words` level capitalization in IOS now.
1549+ // For now go back to default. Remove the check after bug is resolved.
1550+ // https://bugs.webkit.org/show_bug.cgi?id=148504
1551+ if (browserEngine == BrowserEngine .webkit) {
1552+ autocapitalize = 'sentences' ;
1553+ } else {
1554+ autocapitalize = 'words' ;
1555+ }
1556+ break ;
1557+ case TextCapitalization .characters:
1558+ autocapitalize = 'characters' ;
1559+ break ;
1560+ case TextCapitalization .sentences:
1561+ autocapitalize = 'sentences' ;
1562+ break ;
1563+ case TextCapitalization .none:
1564+ default :
1565+ autocapitalize = 'off' ;
1566+ break ;
1567+ }
1568+ if (domElement is html.InputElement ) {
1569+ html.InputElement element = domElement;
1570+ element.setAttribute ('autocapitalize' , autocapitalize);
1571+ } else if (domElement is html.TextAreaElement ) {
1572+ html.TextAreaElement element = domElement;
1573+ element.setAttribute ('autocapitalize' , autocapitalize);
1574+ }
1575+ }
1576+ }
0 commit comments