@@ -116,7 +116,7 @@ class EngineAutofillForm {
116
116
final Map <String , dynamic > autofillInfo = field['autofill' ];
117
117
final AutofillInfo autofill = AutofillInfo .fromFrameworkMessage (
118
118
autofillInfo,
119
- textCapitalization: TextCapitalizationUtil .fromInputConfiguration (
119
+ textCapitalization: TextCapitalizationConfig .fromInputConfiguration (
120
120
field['textCapitalization' ]));
121
121
122
122
// The focused text editing element will not be created here.
@@ -241,7 +241,7 @@ class AutofillInfo {
241
241
///
242
242
/// On the other hand for the multi element forms, for the input elements
243
243
/// other the focused field, we need to use this information.
244
- final TextCapitalizationUtil textCapitalization;
244
+ final TextCapitalizationConfig textCapitalization;
245
245
246
246
/// Attribute used for autofill.
247
247
///
@@ -251,8 +251,8 @@ class AutofillInfo {
251
251
final String hint;
252
252
253
253
factory AutofillInfo .fromFrameworkMessage (Map <String , dynamic > autofill,
254
- {TextCapitalizationUtil textCapitalization =
255
- const TextCapitalizationUtil .defaultCapitalization ()}) {
254
+ {TextCapitalizationConfig textCapitalization =
255
+ const TextCapitalizationConfig .defaultCapitalization ()}) {
256
256
assert (autofill != null ); // ignore: unnecessary_null_comparison
257
257
final String uniqueIdentifier = autofill['uniqueIdentifier' ]! ;
258
258
final List <dynamic > hintsList = autofill['hints' ];
@@ -332,18 +332,18 @@ class EditingState {
332
332
/// [domElement] can be a [InputElement] or a [TextAreaElement] depending on
333
333
/// the [InputType] of the text field.
334
334
factory EditingState .fromDomElement (html.HtmlElement ? domElement,
335
- {TextCapitalizationUtil textCapitalization =
336
- const TextCapitalizationUtil .defaultCapitalization ()}) {
335
+ {TextCapitalizationConfig textCapitalization =
336
+ const TextCapitalizationConfig .defaultCapitalization ()}) {
337
337
if (domElement is html.InputElement ) {
338
338
html.InputElement element = domElement;
339
339
return EditingState (
340
- text: textCapitalization. capitializeTextValue ( element.value) ,
340
+ text: element.value,
341
341
baseOffset: element.selectionStart,
342
342
extentOffset: element.selectionEnd);
343
343
} else if (domElement is html.TextAreaElement ) {
344
344
html.TextAreaElement element = domElement;
345
345
return EditingState (
346
- text: textCapitalization. capitializeTextValue ( element.value) ,
346
+ text: element.value,
347
347
baseOffset: element.selectionStart,
348
348
extentOffset: element.selectionEnd);
349
349
} else {
@@ -439,7 +439,7 @@ class InputConfiguration {
439
439
inputAction = flutterInputConfiguration['inputAction' ],
440
440
obscureText = flutterInputConfiguration['obscureText' ],
441
441
autocorrect = flutterInputConfiguration['autocorrect' ],
442
- textCapitalization = TextCapitalizationUtil .fromInputConfiguration (
442
+ textCapitalization = TextCapitalizationConfig .fromInputConfiguration (
443
443
flutterInputConfiguration['textCapitalization' ]),
444
444
autofill = flutterInputConfiguration.containsKey ('autofill' )
445
445
? AutofillInfo .fromFrameworkMessage (
@@ -471,7 +471,7 @@ class InputConfiguration {
471
471
472
472
final EngineAutofillForm ? autofillGroup;
473
473
474
- final TextCapitalizationUtil textCapitalization;
474
+ final TextCapitalizationConfig textCapitalization;
475
475
}
476
476
477
477
typedef _OnChangeCallback = void Function (EditingState ? editingState);
@@ -626,8 +626,6 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
626
626
domElement.setAttribute ('type' , 'password' );
627
627
}
628
628
629
- inputConfig.textCapitalization.setStyleAttribute (domElement);
630
-
631
629
inputConfig.autofill? .applyToDomElement (domElement, focusedElement: true );
632
630
633
631
final String autocorrectValue = inputConfig.autocorrect! ? 'on' : 'off' ;
@@ -1489,154 +1487,3 @@ class EditableTextGeometry {
1489
1487
..transform = cssTransform;
1490
1488
}
1491
1489
}
1492
-
1493
- /// Controls the capitalization of the text.
1494
- ///
1495
- /// This corresponds to Flutter's [TextCapitalization] .
1496
- ///
1497
- /// Uses `text-transform` css property.
1498
- /// See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform
1499
- enum TextCapitalization {
1500
- /// Uppercase for the first letter of each word.
1501
- words,
1502
-
1503
- /// Currently not implemented on Flutter Web. Uppercase for the first letter
1504
- /// of each sentence.
1505
- sentences,
1506
-
1507
- /// Uppercase for each letter.
1508
- characters,
1509
-
1510
- /// Lowercase for each letter.
1511
- none,
1512
- }
1513
-
1514
- /// Helper class for text capitalization.
1515
- ///
1516
- /// Uses `text-transform` css property.
1517
- /// See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform
1518
- class TextCapitalizationUtil {
1519
- final TextCapitalization textCapitalization;
1520
-
1521
- static final RegExp wordExp = new RegExp (r"(\w+)" );
1522
- static final RegExp whiteSpaceExp = new RegExp (r"(\s+)" );
1523
-
1524
- const TextCapitalizationUtil .defaultCapitalization ()
1525
- : textCapitalization = TextCapitalization .none;
1526
-
1527
- // TODO: support sentence level text capitalization.
1528
- TextCapitalizationUtil .fromInputConfiguration (String inputConfiguration)
1529
- : this .textCapitalization =
1530
- inputConfiguration == 'TextCapitalization.words'
1531
- ? TextCapitalization .words
1532
- : (inputConfiguration == 'TextCapitalization.characters' )
1533
- ? TextCapitalization .characters
1534
- : TextCapitalization .none;
1535
-
1536
- void setStyleAttribute (html.HtmlElement domElement) {
1537
- final html.CssStyleDeclaration elementStyle = domElement.style;
1538
-
1539
- switch (textCapitalization) {
1540
- case TextCapitalization .words:
1541
- elementStyle.textTransform = 'capitalize' ;
1542
- break ;
1543
- case TextCapitalization .characters:
1544
- elementStyle.textTransform = 'uppercase' ;
1545
- break ;
1546
- case TextCapitalization .sentences:
1547
- case TextCapitalization .none:
1548
- default :
1549
- elementStyle.textTransform = 'lowercase' ;
1550
- break ;
1551
- }
1552
- }
1553
-
1554
- /// Change the capitalization of the focused text field's value depending on
1555
- /// the [TextCapitalization] .
1556
- ///
1557
- /// For [TextCapitalization.words] , this method makes all first letter of each
1558
- /// word uppercase.
1559
- ///
1560
- /// For [TextCapitalization.characters] , this method makes all letters of each
1561
- /// word uppercase.
1562
- ///
1563
- /// For [TextCapitalization.sentence] is not supported for now.
1564
- String capitializeTextValue (String value) {
1565
- if (value.isEmpty) {
1566
- return value;
1567
- }
1568
- switch (textCapitalization) {
1569
- case TextCapitalization .words:
1570
- final Iterable <RegExpMatch > wordMatches = wordExp.allMatches (value);
1571
- final List <String > words = wordMatches.map ((RegExpMatch match) {
1572
- final String ? word = match.group (0 );
1573
- return (word == null ) ? '' : word;
1574
- }).toList ();
1575
- final Iterable <RegExpMatch > whiteSpaceMatches =
1576
- whiteSpaceExp.allMatches (value);
1577
- final List <String > whiteSpaces =
1578
- whiteSpaceMatches.map ((RegExpMatch match) {
1579
- final String ? word = match.group (0 );
1580
- return (word == null ) ? '' : word;
1581
- }).toList ();
1582
- final StringBuffer textValueBuffer = new StringBuffer ();
1583
- for (int i = 0 ; i < words.length && ! words[i].isEmpty; i++ ) {
1584
- final String word = words[i];
1585
- textValueBuffer.write ('${word [0 ].toUpperCase ()}${word .substring (1 )}' );
1586
- if (whiteSpaces.length > i) {
1587
- textValueBuffer.write (whiteSpaces[i]);
1588
- }
1589
- }
1590
- return textValueBuffer.toString ();
1591
- case TextCapitalization .characters:
1592
- return value.toUpperCase ();
1593
- case TextCapitalization .sentences:
1594
- case TextCapitalization .none:
1595
- default :
1596
- return value;
1597
- }
1598
- }
1599
-
1600
- /// Sets `autocapitalize` attribute on input elements.
1601
- ///
1602
- /// This attribute is only available for mobile browsers.
1603
- ///
1604
- /// Note that in mobile browsers the onscreen keyboards provide sentence
1605
- /// level capitalization as default as apposed to no capitalization on desktop
1606
- /// browser.
1607
- ///
1608
- /// See: https://developers.google.com/web/updates/2015/04/autocapitalize
1609
- /// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize
1610
- void setAutocapitalizeAttribute (html.HtmlElement domElement) {
1611
- String autocapitalize = '' ;
1612
- switch (textCapitalization) {
1613
- case TextCapitalization .words:
1614
- // TODO: There is a bug for `words` level capitalization in IOS now.
1615
- // For now go back to default. Remove the check after bug is resolved.
1616
- // https://bugs.webkit.org/show_bug.cgi?id=148504
1617
- if (browserEngine == BrowserEngine .webkit) {
1618
- autocapitalize = 'sentences' ;
1619
- } else {
1620
- autocapitalize = 'words' ;
1621
- }
1622
- break ;
1623
- case TextCapitalization .characters:
1624
- autocapitalize = 'characters' ;
1625
- break ;
1626
- case TextCapitalization .sentences:
1627
- autocapitalize = 'sentences' ;
1628
- break ;
1629
- case TextCapitalization .none:
1630
- default :
1631
- autocapitalize = 'off' ;
1632
- break ;
1633
- }
1634
- if (domElement is html.InputElement ) {
1635
- html.InputElement element = domElement;
1636
- element.setAttribute ('autocapitalize' , autocapitalize);
1637
- } else if (domElement is html.TextAreaElement ) {
1638
- html.TextAreaElement element = domElement;
1639
- element.setAttribute ('autocapitalize' , autocapitalize);
1640
- }
1641
- }
1642
- }
0 commit comments