|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +// @dart = 2.6 |
| 6 | +part of engine; |
| 7 | + |
| 8 | +/// Maps AutofillHints from the framework to the autofill hints that is used for |
| 9 | +/// browsers. |
| 10 | +/// See: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/autofill.dart |
| 11 | +/// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete |
| 12 | +class BrowserAutofillHints { |
| 13 | + static final BrowserAutofillHints _singletonInstance = |
| 14 | + BrowserAutofillHints._(); |
| 15 | + |
| 16 | + /// The [BrowserAutofillHints] singleton. |
| 17 | + static BrowserAutofillHints get instance => _singletonInstance; |
| 18 | + |
| 19 | + final Map<String, String> _flutterToEngineMap; |
| 20 | + |
| 21 | + BrowserAutofillHints._() |
| 22 | + : _flutterToEngineMap = { |
| 23 | + 'birthday': 'bday', |
| 24 | + 'birthdayDay': 'bday-day', |
| 25 | + 'birthdayMonth': 'bday-month', |
| 26 | + 'birthdayYear': 'bday-year', |
| 27 | + 'countryCode': 'country', |
| 28 | + 'countryName': 'country-name', |
| 29 | + 'creditCardExpirationDate': 'cc-exp', |
| 30 | + 'creditCardExpirationMonth': 'cc-exp-month', |
| 31 | + 'creditCardExpirationYear': 'cc-exp-year', |
| 32 | + 'creditCardFamilyName': 'cc-family-name', |
| 33 | + 'creditCardGivenName': 'cc-given-name', |
| 34 | + 'creditCardMiddleName': 'cc-additional-name', |
| 35 | + 'creditCardName': 'cc-name', |
| 36 | + 'creditCardNumber': 'cc-number', |
| 37 | + 'creditCardSecurityCode': 'cc-csc', |
| 38 | + 'creditCardType': 'cc-type', |
| 39 | + 'email': 'email', |
| 40 | + 'familyName': 'familyName', |
| 41 | + 'fullStreetAddress': 'street-address', |
| 42 | + 'gender': 'sex', |
| 43 | + 'givenName': 'given-name', |
| 44 | + 'impp': 'impp', |
| 45 | + 'jobTitle': 'organization-title', |
| 46 | + 'language': 'language', |
| 47 | + 'middleName': 'middleName', |
| 48 | + 'name': 'name', |
| 49 | + 'namePrefix': 'honorific-prefix', |
| 50 | + 'nameSuffix': 'honorific-suffix', |
| 51 | + 'newPassword': 'new-password', |
| 52 | + 'nickname': 'nickname', |
| 53 | + 'oneTimeCode': 'one-time-code', |
| 54 | + 'organizationName': 'organization', |
| 55 | + 'password': 'current-password', |
| 56 | + 'photo': 'photo', |
| 57 | + 'postalCode': 'postal-code', |
| 58 | + 'streetAddressLevel1': 'address-level1', |
| 59 | + 'streetAddressLevel2': 'address-level2', |
| 60 | + 'streetAddressLevel3': 'address-level3', |
| 61 | + 'streetAddressLevel4': 'address-level4', |
| 62 | + 'streetAddressLine1': 'address-line1', |
| 63 | + 'streetAddressLine2': 'address-line2', |
| 64 | + 'streetAddressLine3': 'address-line3', |
| 65 | + 'telephoneNumber': 'tel', |
| 66 | + 'telephoneNumberAreaCode': 'tel-area-code', |
| 67 | + 'telephoneNumberCountryCode': 'tel-country-code', |
| 68 | + 'telephoneNumberExtension': 'tel-extension', |
| 69 | + 'telephoneNumberLocal': 'tel-local', |
| 70 | + 'telephoneNumberLocalPrefix': 'tel-local-prefix', |
| 71 | + 'telephoneNumberLocalSuffix': 'tel-local-suffix', |
| 72 | + 'telephoneNumberNational': 'tel-national', |
| 73 | + 'transactionAmount': 'transaction-amount', |
| 74 | + 'transactionCurrency': 'transaction-currency', |
| 75 | + 'url': 'url', |
| 76 | + 'username': 'username', |
| 77 | + }; |
| 78 | + |
| 79 | + /// Converts the Flutter AutofillHint to the autofill hint value used by the |
| 80 | + /// browsers. |
| 81 | + /// See: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/autofill.dart |
| 82 | + /// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete |
| 83 | + String flutterToEngine(String flutterAutofillHint) { |
| 84 | + // Use the hints as it is. |
| 85 | + return _flutterToEngineMap[flutterAutofillHint] ?? flutterAutofillHint; |
| 86 | + } |
| 87 | +} |
0 commit comments