waft_services/autofill.rs
1//! Flutter counterpart: `services/autofill.dart`.
2//!
3//! `AutofillConfiguration` lives in `waft-embedder` (re-exported from
4//! `text_input.rs`) because `View` names `TextInputConfiguration`.
5
6use waft_foundation::{App, Handle, HandleId};
7
8use crate::text_input::{
9 AnyTextInputClient, TextEditingValue, TextInput, TextInputConfiguration, TextInputConnection,
10};
11use waft_foundation::Ref;
12
13/// A collection of commonly used autofill hint strings on different platforms.
14///
15/// Each hint is pre-defined on at least one supported platform. See their
16/// documentation for their availability on each platform, and the platform
17/// values each autofill hint corresponds to.
18pub struct AutofillHints;
19
20impl AutofillHints {
21 /// The input field expects an address locality (city/town).
22 ///
23 /// This hint will be translated to the below values on different platforms:
24 ///
25 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY).
26 /// * iOS: [addressCity](https://developer.apple.com/documentation/uikit/uitextcontenttype).
27 /// * Otherwise, the hint string will be used as-is.
28 pub const ADDRESS_CITY: &str = "addressCity";
29
30 /// The input field expects a city name combined with a state name.
31 ///
32 /// This hint will be translated to the below values on different platforms:
33 ///
34 /// * iOS: [addressCityAndState](https://developer.apple.com/documentation/uikit/uitextcontenttype).
35 /// * Otherwise, the hint string will be used as-is.
36 pub const ADDRESS_CITY_AND_STATE: &str = "addressCityAndState";
37
38 /// The input field expects a region/state.
39 ///
40 /// This hint will be translated to the below values on different platforms:
41 ///
42 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_REGION](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_REGION).
43 /// * iOS: [addressState](https://developer.apple.com/documentation/uikit/uitextcontenttype).
44 /// * Otherwise, the hint string will be used as-is.
45 pub const ADDRESS_STATE: &str = "addressState";
46
47 /// The input field expects a person's full birth date.
48 ///
49 /// This hint will be translated to the below values on different platforms:
50 ///
51 /// * Android: [AUTOFILL_HINT_BIRTH_DATE_FULL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_FULL).
52 /// * web: ["bday"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
53 /// * Otherwise, the hint string will be used as-is.
54 pub const BIRTHDAY: &str = "birthday";
55
56 /// The input field expects a person's birth day(of the month).
57 ///
58 /// This hint will be translated to the below values on different platforms:
59 ///
60 /// * Android: [AUTOFILL_HINT_BIRTH_DATE_DAY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_DAY).
61 /// * web: ["bday-day"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
62 /// * Otherwise, the hint string will be used as-is.
63 pub const BIRTHDAY_DAY: &str = "birthdayDay";
64
65 /// The input field expects a person's birth month.
66 ///
67 /// This hint will be translated to the below values on different platforms:
68 ///
69 /// * Android: [AUTOFILL_HINT_BIRTH_DATE_MONTH](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_MONTH).
70 /// * web: ["bday-month"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
71 /// * Otherwise, the hint string will be used as-is.
72 pub const BIRTHDAY_MONTH: &str = "birthdayMonth";
73
74 /// The input field expects a person's birth year.
75 ///
76 /// This hint will be translated to the below values on different platforms:
77 ///
78 /// * Android: [AUTOFILL_HINT_BIRTH_DATE_YEAR](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_BIRTH_DATE_YEAR).
79 /// * web: ["bday-year"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
80 /// * Otherwise, the hint string will be used as-is.
81 pub const BIRTHDAY_YEAR: &str = "birthdayYear";
82
83 /// The input field expects an
84 /// [ISO 3166-1-alpha-2](https://www.iso.org/standard/63545.html) country code.
85 ///
86 /// This hint will be translated to the below values on different platforms:
87 ///
88 /// * web: ["country"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
89 /// * Otherwise, the hint string will be used as-is.
90 pub const COUNTRY_CODE: &str = "countryCode";
91
92 /// The input field expects a country name.
93 ///
94 /// This hint will be translated to the below values on different platforms:
95 ///
96 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY).
97 /// * iOS: [countryName](https://developer.apple.com/documentation/uikit/uitextcontenttype).
98 /// * web: ["country-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
99 /// * Otherwise, the hint string will be used as-is.
100 pub const COUNTRY_NAME: &str = "countryName";
101
102 /// The input field expects a credit card expiration date.
103 ///
104 /// This hint will be translated to the below values on different platforms:
105 ///
106 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_NUMBER).
107 /// * web: ["cc-exp"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
108 /// * Otherwise, the hint string will be used as-is.
109 pub const CREDIT_CARD_EXPIRATION_DATE: &str = "creditCardExpirationDate";
110
111 /// The input field expects a credit card expiration day.
112 ///
113 /// This hint will be translated to the below values on different platforms:
114 ///
115 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY).
116 /// * Otherwise, the hint string will be used as-is.
117 pub const CREDIT_CARD_EXPIRATION_DAY: &str = "creditCardExpirationDay";
118
119 /// The input field expects a credit card expiration month.
120 ///
121 /// This hint will be translated to the below values on different platforms:
122 ///
123 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH).
124 /// * web: ["cc-exp-month"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
125 /// * Otherwise, the hint string will be used as-is.
126 pub const CREDIT_CARD_EXPIRATION_MONTH: &str = "creditCardExpirationMonth";
127
128 /// The input field expects a credit card expiration year.
129 ///
130 /// This hint will be translated to the below values on different platforms:
131 ///
132 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR).
133 /// * web: ["cc-exp-year"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
134 /// * Otherwise, the hint string will be used as-is.
135 pub const CREDIT_CARD_EXPIRATION_YEAR: &str = "creditCardExpirationYear";
136
137 /// The input field expects the holder's last/family name as given on a credit
138 /// card.
139 ///
140 /// This hint will be translated to the below values on different platforms:
141 ///
142 /// * web: ["cc-family-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
143 /// * Otherwise, the hint string will be used as-is.
144 pub const CREDIT_CARD_FAMILY_NAME: &str = "creditCardFamilyName";
145
146 /// The input field expects the holder's first/given name as given on a credit
147 /// card.
148 ///
149 /// This hint will be translated to the below values on different platforms:
150 ///
151 /// * web: ["cc-given-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
152 /// * Otherwise, the hint string will be used as-is.
153 pub const CREDIT_CARD_GIVEN_NAME: &str = "creditCardGivenName";
154
155 /// The input field expects the holder's middle name as given on a credit
156 /// card.
157 ///
158 /// This hint will be translated to the below values on different platforms:
159 ///
160 /// * web: ["cc-additional-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
161 /// * Otherwise, the hint string will be used as-is.
162 pub const CREDIT_CARD_MIDDLE_NAME: &str = "creditCardMiddleName";
163
164 /// The input field expects the holder's full name as given on a credit card.
165 ///
166 /// This hint will be translated to the below values on different platforms:
167 ///
168 /// * web: ["cc-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
169 /// * Otherwise, the hint string will be used as-is.
170 pub const CREDIT_CARD_NAME: &str = "creditCardName";
171
172 /// The input field expects a credit card number.
173 ///
174 /// This hint will be translated to the below values on different platforms:
175 ///
176 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_NUMBER).
177 /// * iOS: [creditCardNumber](https://developer.apple.com/documentation/uikit/uitextcontenttype).
178 /// * web: ["cc-number"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
179 /// * Otherwise, the hint string will be used as-is.
180 pub const CREDIT_CARD_NUMBER: &str = "creditCardNumber";
181
182 /// The input field expects a credit card security code.
183 ///
184 /// This hint will be translated to the below values on different platforms:
185 ///
186 /// * Android: [AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE).
187 /// * web: ["cc-csc"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
188 /// * Otherwise, the hint string will be used as-is.
189 pub const CREDIT_CARD_SECURITY_CODE: &str = "creditCardSecurityCode";
190
191 /// The input field expects the type of a credit card, for example "Visa".
192 ///
193 /// This hint will be translated to the below values on different platforms:
194 ///
195 /// * web: ["cc-type"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
196 /// * Otherwise, the hint string will be used as-is.
197 pub const CREDIT_CARD_TYPE: &str = "creditCardType";
198
199 /// The input field expects an email address.
200 ///
201 /// This hint will be translated to the below values on different platforms:
202 ///
203 /// * Android: [AUTOFILL_HINT_EMAIL_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_EMAIL_ADDRESS).
204 /// * iOS: [emailAddress](https://developer.apple.com/documentation/uikit/uitextcontenttype).
205 /// * web: ["email"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
206 /// * Otherwise, the hint string will be used as-is.
207 pub const EMAIL: &str = "email";
208
209 /// The input field expects a person's last/family name.
210 ///
211 /// This hint will be translated to the below values on different platforms:
212 ///
213 /// * Android: [AUTOFILL_HINT_PERSON_NAME_FAMILY](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_FAMILY).
214 /// * iOS: [familyName](https://developer.apple.com/documentation/uikit/uitextcontenttype).
215 /// * web: ["family-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
216 /// * Otherwise, the hint string will be used as-is.
217 pub const FAMILY_NAME: &str = "familyName";
218
219 /// The input field expects a street address that fully identifies a location.
220 ///
221 /// This hint will be translated to the below values on different platforms:
222 ///
223 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS).
224 /// * iOS: [fullStreetAddress](https://developer.apple.com/documentation/uikit/uitextcontenttype).
225 /// * web: ["street-address"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
226 /// * Otherwise, the hint string will be used as-is.
227 pub const FULL_STREET_ADDRESS: &str = "fullStreetAddress";
228
229 /// The input field expects a gender.
230 ///
231 /// This hint will be translated to the below values on different platforms:
232 ///
233 /// * Android: [AUTOFILL_HINT_GENDER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_GENDER).
234 /// * web: ["sex"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
235 /// * Otherwise, the hint string will be used as-is.
236 pub const GENDER: &str = "gender";
237
238 /// The input field expects a person's first/given name.
239 ///
240 /// This hint will be translated to the below values on different platforms:
241 ///
242 /// * Android: [AUTOFILL_HINT_PERSON_NAME_GIVEN](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_GIVEN).
243 /// * iOS: [givenName](https://developer.apple.com/documentation/uikit/uitextcontenttype).
244 /// * web: ["given-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
245 /// * Otherwise, the hint string will be used as-is.
246 pub const GIVEN_NAME: &str = "givenName";
247
248 /// The input field expects a URL representing an instant messaging protocol
249 /// endpoint.
250 ///
251 /// This hint will be translated to the below values on different platforms:
252 ///
253 /// * web: ["impp"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
254 /// * Otherwise, the hint string will be used as-is.
255 pub const IMPP: &str = "impp";
256
257 /// The input field expects a job title.
258 ///
259 /// This hint will be translated to the below values on different platforms:
260 ///
261 /// * iOS: [jobTitle](https://developer.apple.com/documentation/uikit/uitextcontenttype).
262 /// * web: ["organization-title"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
263 /// * Otherwise, the hint string will be used as-is.
264 pub const JOB_TITLE: &str = "jobTitle";
265
266 /// The input field expects the preferred language of the user.
267 ///
268 /// This hint will be translated to the below values on different platforms:
269 ///
270 /// * web: ["language"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
271 /// * Otherwise, the hint string will be used as-is.
272 pub const LANGUAGE: &str = "language";
273
274 /// The input field expects a location, such as a point of interest, an
275 /// address,or another way to identify a location.
276 ///
277 /// This hint will be translated to the below values on different platforms:
278 ///
279 /// * iOS: [location](https://developer.apple.com/documentation/uikit/uitextcontenttype).
280 /// * Otherwise, the hint string will be used as-is.
281 pub const LOCATION: &str = "location";
282
283 /// The input field expects a person's middle initial.
284 ///
285 /// This hint will be translated to the below values on different platforms:
286 ///
287 /// * Android: [AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL).
288 /// * Otherwise, the hint string will be used as-is.
289 pub const MIDDLE_INITIAL: &str = "middleInitial";
290
291 /// The input field expects a person's middle name.
292 ///
293 /// This hint will be translated to the below values on different platforms:
294 ///
295 /// * Android: [AUTOFILL_HINT_PERSON_NAME_MIDDLE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_MIDDLE).
296 /// * iOS: [middleName](https://developer.apple.com/documentation/uikit/uitextcontenttype).
297 /// * web: ["additional-name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
298 /// * Otherwise, the hint string will be used as-is.
299 pub const MIDDLE_NAME: &str = "middleName";
300
301 /// The input field expects a person's full name.
302 ///
303 /// This hint will be translated to the below values on different platforms:
304 ///
305 /// * Android: [AUTOFILL_HINT_PERSON_NAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME).
306 /// * iOS: [name](https://developer.apple.com/documentation/uikit/uitextcontenttype).
307 /// * web: ["name"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
308 /// * Otherwise, the hint string will be used as-is.
309 pub const NAME: &str = "name";
310
311 /// The input field expects a person's name prefix or title, such as "Dr.".
312 ///
313 /// This hint will be translated to the below values on different platforms:
314 ///
315 /// * Android: [AUTOFILL_HINT_PERSON_NAME_PREFIX](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_PREFIX).
316 /// * iOS: [namePrefix](https://developer.apple.com/documentation/uikit/uitextcontenttype).
317 /// * web: ["honorific-prefix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
318 /// * Otherwise, the hint string will be used as-is.
319 pub const NAME_PREFIX: &str = "namePrefix";
320
321 /// The input field expects a person's name suffix, such as "Jr.".
322 ///
323 /// This hint will be translated to the below values on different platforms:
324 ///
325 /// * Android: [AUTOFILL_HINT_PERSON_NAME_SUFFIX](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PERSON_NAME_SUFFIX).
326 /// * iOS: [nameSuffix](https://developer.apple.com/documentation/uikit/uitextcontenttype).
327 /// * web: ["honorific-suffix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
328 /// * Otherwise, the hint string will be used as-is.
329 pub const NAME_SUFFIX: &str = "nameSuffix";
330
331 /// The input field expects a newly created password for save/update.
332 ///
333 /// This hint will be translated to the below values on different platforms:
334 ///
335 /// * Android: [AUTOFILL_HINT_NEW_PASSWORD](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_NEW_PASSWORD).
336 /// * iOS: [newPassword](https://developer.apple.com/documentation/uikit/uitextcontenttype).
337 /// * web: ["new-password"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
338 /// * Otherwise, the hint string will be used as-is.
339 pub const NEW_PASSWORD: &str = "newPassword";
340
341 /// The input field expects a newly created username for save/update.
342 ///
343 /// This hint will be translated to the below values on different platforms:
344 ///
345 /// * Android: [AUTOFILL_HINT_NEW_USERNAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_NEW_USERNAME).
346 /// * Otherwise, the hint string will be used as-is.
347 pub const NEW_USERNAME: &str = "newUsername";
348
349 /// The input field expects a nickname.
350 ///
351 /// This hint will be translated to the below values on different platforms:
352 ///
353 /// * iOS: [nickname](https://developer.apple.com/documentation/uikit/uitextcontenttype).
354 /// * web: ["nickname"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
355 /// * Otherwise, the hint string will be used as-is.
356 pub const NICKNAME: &str = "nickname";
357
358 /// The input field expects a SMS one-time code.
359 ///
360 /// This hint will be translated to the below values on different platforms:
361 ///
362 /// * Android: [AUTOFILL_HINT_SMS_OTP](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_SMS_OTP).
363 /// * iOS: [oneTimeCode](https://developer.apple.com/documentation/uikit/uitextcontenttype).
364 /// * web: ["one-time-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
365 /// * Otherwise, the hint string will be used as-is.
366 pub const ONE_TIME_CODE: &str = "oneTimeCode";
367
368 /// The input field expects an email one-time code.
369 ///
370 /// This hint will be translated to the below values on different platforms:
371 ///
372 /// * Android: [AUTOFILL_HINT_EMAIL_OTP](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_EMAIL_OTP).
373 /// * Otherwise, the hint string will be used as-is.
374 pub const EMAIL_OTP_CODE: &str = "emailOTPCode";
375
376 /// The input field expects an organization name corresponding to the person,
377 /// address, or contact information in the other fields associated with this
378 /// field.
379 ///
380 /// This hint will be translated to the below values on different platforms:
381 ///
382 /// * iOS: [organizationName](https://developer.apple.com/documentation/uikit/uitextcontenttype).
383 /// * web: ["organization"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
384 /// * Otherwise, the hint string will be used as-is.
385 pub const ORGANIZATION_NAME: &str = "organizationName";
386
387 /// The input field expects a password.
388 ///
389 /// This hint will be translated to the below values on different platforms:
390 ///
391 /// * Android: [AUTOFILL_HINT_PASSWORD](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PASSWORD).
392 /// * iOS: [password](https://developer.apple.com/documentation/uikit/uitextcontenttype).
393 /// * web: ["current-password"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
394 /// * Otherwise, the hint string will be used as-is.
395 pub const PASSWORD: &str = "password";
396
397 /// The input field expects a photograph, icon, or other image corresponding
398 /// to the company, person, address, or contact information in the other
399 /// fields associated with this field.
400 ///
401 /// This hint will be translated to the below values on different platforms:
402 ///
403 /// * web: ["photo"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
404 /// * Otherwise, the hint string will be used as-is.
405 pub const PHOTO: &str = "photo";
406
407 /// The input field expects a postal address.
408 ///
409 /// This hint will be translated to the below values on different platforms:
410 ///
411 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS).
412 /// * Otherwise, the hint string will be used as-is.
413 pub const POSTAL_ADDRESS: &str = "postalAddress";
414
415 /// The input field expects an auxiliary address details.
416 ///
417 /// This hint will be translated to the below values on different platforms:
418 ///
419 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS).
420 /// * Otherwise, the hint string will be used as-is.
421 pub const POSTAL_ADDRESS_EXTENDED: &str = "postalAddressExtended";
422
423 /// The input field expects an extended ZIP/POSTAL code.
424 ///
425 /// This hint will be translated to the below values on different platforms:
426 ///
427 /// * Android: [AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE).
428 /// * Otherwise, the hint string will be used as-is.
429 pub const POSTAL_ADDRESS_EXTENDED_POSTAL_CODE: &str = "postalAddressExtendedPostalCode";
430
431 /// The input field expects a postal code.
432 ///
433 /// This hint will be translated to the below values on different platforms:
434 ///
435 /// * Android: [AUTOFILL_HINT_POSTAL_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_POSTAL_CODE).
436 /// * iOS: [postalCode](https://developer.apple.com/documentation/uikit/uitextcontenttype).
437 /// * web: ["postal-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
438 /// * Otherwise, the hint string will be used as-is.
439 pub const POSTAL_CODE: &str = "postalCode";
440
441 /// The first administrative level in the address. This is typically the
442 /// province in which the address is located. In the United States, this would
443 /// be the state. In Switzerland, the canton. In the United Kingdom, the post
444 /// town.
445 ///
446 /// This hint will be translated to the below values on different platforms:
447 ///
448 /// * web: ["address-level1"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
449 /// * Otherwise, the hint string will be used as-is.
450 pub const STREET_ADDRESS_LEVEL1: &str = "streetAddressLevel1";
451
452 /// The second administrative level, in addresses with at least two of them.
453 /// In countries with two administrative levels, this would typically be the
454 /// city, town, village, or other locality in which the address is located.
455 ///
456 /// This hint will be translated to the below values on different platforms:
457 ///
458 /// * web: ["address-level2"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
459 /// * Otherwise, the hint string will be used as-is.
460 pub const STREET_ADDRESS_LEVEL2: &str = "streetAddressLevel2";
461
462 /// The third administrative level, in addresses with at least three
463 /// administrative levels.
464 ///
465 /// This hint will be translated to the below values on different platforms:
466 ///
467 /// * web: ["address-level3"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
468 /// * Otherwise, the hint string will be used as-is.
469 pub const STREET_ADDRESS_LEVEL3: &str = "streetAddressLevel3";
470
471 /// The finest-grained administrative level, in addresses which have four
472 /// levels.
473 ///
474 /// This hint will be translated to the below values on different platforms:
475 ///
476 /// * web: ["address-level4"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
477 /// * Otherwise, the hint string will be used as-is.
478 pub const STREET_ADDRESS_LEVEL4: &str = "streetAddressLevel4";
479
480 /// The input field expects the first line of a street address.
481 ///
482 /// This hint will be translated to the below values on different platforms:
483 ///
484 /// * iOS: [streetAddressLine1](https://developer.apple.com/documentation/uikit/uitextcontenttype).
485 /// * web: ["address-line1"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
486 /// * Otherwise, the hint string will be used as-is.
487 pub const STREET_ADDRESS_LINE1: &str = "streetAddressLine1";
488
489 /// The input field expects the second line of a street address.
490 ///
491 /// This hint will be translated to the below values on different platforms:
492 ///
493 /// * iOS: [streetAddressLine2](https://developer.apple.com/documentation/uikit/uitextcontenttype).
494 /// As of iOS 14.2 this hint does not trigger autofill.
495 /// * web: ["address-line2"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
496 /// * Otherwise, the hint string will be used as-is.
497 pub const STREET_ADDRESS_LINE2: &str = "streetAddressLine2";
498
499 /// The input field expects the third line of a street address.
500 ///
501 /// This hint will be translated to the below values on different platforms:
502 ///
503 /// * web: ["address-line3"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
504 /// * Otherwise, the hint string will be used as-is.
505 pub const STREET_ADDRESS_LINE3: &str = "streetAddressLine3";
506
507 /// The input field expects a sublocality.
508 ///
509 /// This hint will be translated to the below values on different platforms:
510 ///
511 /// * iOS: [sublocality](https://developer.apple.com/documentation/uikit/uitextcontenttype).
512 /// * Otherwise, the hint string will be used as-is.
513 pub const SUBLOCALITY: &str = "sublocality";
514
515 /// The input field expects a telephone number.
516 ///
517 /// This hint will be translated to the below values on different platforms:
518 ///
519 /// * Android: [AUTOFILL_HINT_PHONE_NUMBER](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NUMBER).
520 /// * iOS: [telephoneNumber](https://developer.apple.com/documentation/uikit/uitextcontenttype).
521 /// * web: ["tel"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
522 /// * Otherwise, the hint string will be used as-is.
523 pub const TELEPHONE_NUMBER: &str = "telephoneNumber";
524
525 /// The input field expects a phone number's area code, with a country
526 /// -internal prefix applied if applicable.
527 ///
528 /// This hint will be translated to the below values on different platforms:
529 ///
530 /// * web: ["tel-area-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
531 /// * Otherwise, the hint string will be used as-is.
532 pub const TELEPHONE_NUMBER_AREA_CODE: &str = "telephoneNumberAreaCode";
533
534 /// The input field expects a phone number's country code.
535 ///
536 /// This hint will be translated to the below values on different platforms:
537 ///
538 /// * Android: [AUTOFILL_HINT_PHONE_COUNTRY_CODE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_COUNTRY_CODE).
539 /// * web: ["tel-country-code"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
540 /// * Otherwise, the hint string will be used as-is.
541 pub const TELEPHONE_NUMBER_COUNTRY_CODE: &str = "telephoneNumberCountryCode";
542
543 /// The input field expects the current device's phone number, usually for
544 /// Sign Up / OTP flows.
545 ///
546 /// This hint will be translated to the below values on different platforms:
547 ///
548 /// * Android: [AUTOFILL_HINT_PHONE_NUMBER_DEVICE](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NUMBER_DEVICE).
549 /// * Otherwise, the hint string will be used as-is.
550 pub const TELEPHONE_NUMBER_DEVICE: &str = "telephoneNumberDevice";
551
552 /// The input field expects a phone number's internal extension code.
553 ///
554 /// This hint will be translated to the below values on different platforms:
555 ///
556 /// * web: ["tel-extension"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
557 /// * Otherwise, the hint string will be used as-is.
558 pub const TELEPHONE_NUMBER_EXTENSION: &str = "telephoneNumberExtension";
559
560 /// The input field expects a phone number without the country code and area
561 /// code components.
562 ///
563 /// This hint will be translated to the below values on different platforms:
564 ///
565 /// * web: ["tel-local"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
566 /// * Otherwise, the hint string will be used as-is.
567 pub const TELEPHONE_NUMBER_LOCAL: &str = "telephoneNumberLocal";
568
569 /// The input field expects the first part of the component of the telephone
570 /// number that follows the area code, when that component is split into two
571 /// components.
572 ///
573 /// This hint will be translated to the below values on different platforms:
574 ///
575 /// * web: ["tel-local-prefix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
576 /// * Otherwise, the hint string will be used as-is.
577 pub const TELEPHONE_NUMBER_LOCAL_PREFIX: &str = "telephoneNumberLocalPrefix";
578
579 /// The input field expects the second part of the component of the telephone
580 /// number that follows the area code, when that component is split into two
581 /// components.
582 ///
583 /// This hint will be translated to the below values on different platforms:
584 ///
585 /// * web: ["tel-local-suffix"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
586 /// * Otherwise, the hint string will be used as-is.
587 pub const TELEPHONE_NUMBER_LOCAL_SUFFIX: &str = "telephoneNumberLocalSuffix";
588
589 /// The input field expects a phone number without country code.
590 ///
591 /// This hint will be translated to the below values on different platforms:
592 ///
593 /// * Android: [AUTOFILL_HINT_PHONE_NATIONAL](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_PHONE_NATIONAL).
594 /// * web: ["tel-national"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
595 /// * Otherwise, the hint string will be used as-is.
596 pub const TELEPHONE_NUMBER_NATIONAL: &str = "telephoneNumberNational";
597
598 /// The amount that the user would like for the transaction (e.g. when
599 /// entering a bid or sale price).
600 ///
601 /// This hint will be translated to the below values on different platforms:
602 ///
603 /// * web: ["transaction-amount"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
604 /// * Otherwise, the hint string will be used as-is.
605 pub const TRANSACTION_AMOUNT: &str = "transactionAmount";
606
607 /// The currency that the user would prefer the transaction to use, in [ISO
608 /// 4217 currency code](https://www.iso.org/iso-4217-currency-codes.html).
609 ///
610 /// This hint will be translated to the below values on different platforms:
611 ///
612 /// * web: ["transaction-currency"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
613 /// * Otherwise, the hint string will be used as-is.
614 pub const TRANSACTION_CURRENCY: &str = "transactionCurrency";
615
616 /// The input field expects a URL.
617 ///
618 /// This hint will be translated to the below values on different platforms:
619 ///
620 /// * iOS: [URL](https://developer.apple.com/documentation/uikit/uitextcontenttype).
621 /// * web: ["url"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
622 /// * Otherwise, the hint string will be used as-is.
623 pub const URL: &str = "url";
624
625 /// The input field expects a username or an account name.
626 ///
627 /// This hint will be translated to the below values on different platforms:
628 ///
629 /// * Android: [AUTOFILL_HINT_USERNAME](https://developer.android.com/reference/androidx/autofill/HintConstants#AUTOFILL_HINT_USERNAME).
630 /// * iOS: [username](https://developer.apple.com/documentation/uikit/uitextcontenttype).
631 /// * web: ["username"](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls:-the-autocomplete-attribute).
632 /// * Otherwise, the hint string will be used as-is.
633 pub const USERNAME: &str = "username";
634}
635
636/// An object that represents an autofillable input field in the autofill workflow.
637///
638/// An [`AutofillClient`] provides autofill-related information of the input field
639/// it represents to the platform, and consumes autofill inputs from the platform.
640pub trait AutofillClient: Sized + 'static {
641 /// The unique identifier of this [`AutofillClient`].
642 ///
643 /// The identifier must not be changed.
644 fn autofill_id(self: Handle<Self>, app: &App) -> String;
645
646 /// The [`TextInputConfiguration`] that describes this [`AutofillClient`].
647 ///
648 /// In order to participate in autofill, its
649 /// [`TextInputConfiguration::autofill_configuration`] must not be
650 /// [`AutofillConfiguration::DISABLED`](crate::AutofillConfiguration::DISABLED).
651 fn text_input_configuration(self: Handle<Self>, app: &App) -> TextInputConfiguration;
652
653 /// Requests this [`AutofillClient`] update its [`TextEditingValue`] to the given
654 /// value.
655 fn autofill(self: Handle<Self>, app: &mut App, new_editing_value: TextEditingValue);
656
657 /// This client as the erased [`AnyAutofillClient`].
658 fn as_autofill_client(self: Handle<Self>) -> AnyAutofillClient {
659 AnyAutofillClient {
660 id: self.id(),
661 vtable: const { &AutofillClientVTable::of::<Self>() },
662 }
663 }
664}
665
666struct AutofillClientVTable {
667 autofill_id: fn(&App, HandleId) -> String,
668 text_input_configuration: fn(&App, HandleId) -> TextInputConfiguration,
669 autofill: fn(&mut App, HandleId, TextEditingValue),
670}
671
672fn resolve<T: 'static>(id: HandleId) -> Handle<T> {
673 Handle::from_id(id)
674}
675
676impl AutofillClientVTable {
677 const fn of<C: AutofillClient>() -> AutofillClientVTable {
678 AutofillClientVTable {
679 autofill_id: |app, id| C::autofill_id(resolve(id), app),
680 text_input_configuration: |app, id| C::text_input_configuration(resolve(id), app),
681 autofill: |app, id, value| C::autofill(resolve(id), app, value),
682 }
683 }
684}
685
686/// Erased [`AutofillClient`]: one identity and a static vtable.
687#[derive(Clone, Copy)]
688pub struct AnyAutofillClient {
689 id: HandleId,
690 vtable: &'static AutofillClientVTable,
691}
692
693impl AnyAutofillClient {
694 pub fn autofill_id(self, app: &App) -> String {
695 (self.vtable.autofill_id)(app, self.id)
696 }
697
698 pub fn text_input_configuration(self, app: &App) -> TextInputConfiguration {
699 (self.vtable.text_input_configuration)(app, self.id)
700 }
701
702 pub fn autofill(self, app: &mut App, new_editing_value: TextEditingValue) {
703 (self.vtable.autofill)(app, self.id, new_editing_value);
704 }
705}
706
707impl PartialEq for AnyAutofillClient {
708 fn eq(&self, other: &AnyAutofillClient) -> bool {
709 self.id == other.id
710 }
711}
712
713impl Eq for AnyAutofillClient {}
714
715/// An ordered group within which [`AutofillClient`]s are logically connected.
716///
717/// [`AutofillClient`]s within the same [`AutofillScope`] are isolated from other
718/// input fields during autofill. That is, when an autofillable `TextInputClient`
719/// gains focus, only the [`AutofillClient`]s within the same [`AutofillScope`] will
720/// be visible to the autofill service, in the same order as they appear in
721/// [`AutofillScope::autofill_clients`].
722///
723/// [`AutofillScope`] also allows `TextInput` to redirect autofill values from the
724/// platform to the [`AutofillClient`] with the given identifier, by calling
725/// [`AutofillScope::get_autofill_client`].
726///
727/// An [`AutofillClient`] that's not tied to any [`AutofillScope`] will only
728/// participate in autofill if the autofill is directly triggered by its own
729/// `TextInputClient`.
730pub trait AutofillScope: Sized + 'static {
731 /// Gets the [`AutofillClient`] associated with the given `autofill_id`, in
732 /// this [`AutofillScope`].
733 ///
734 /// Returns [`None`] if there's no matching [`AutofillClient`].
735 fn get_autofill_client(
736 self: Handle<Self>,
737 app: &App,
738 autofill_id: &str,
739 ) -> Option<AnyAutofillClient>;
740
741 /// The collection of [`AutofillClient`]s currently tied to this [`AutofillScope`].
742 ///
743 /// Every [`AutofillClient`] in this list must have autofill enabled (i.e. its
744 /// [`AutofillClient::text_input_configuration`] must have a non-disabled
745 /// [`crate::AutofillConfiguration`].)
746 fn autofill_clients(self: Handle<Self>, app: &App) -> Vec<AnyAutofillClient>;
747
748 /// Allows a `TextInputClient` to attach to this scope. This method should be
749 /// called in lieu of [`TextInput::attach`], when the `TextInputClient` wishes to
750 /// participate in autofill.
751 ///
752 /// Flutter `AutofillScopeMixin.attach`.
753 fn attach(
754 self: Handle<Self>,
755 app: &mut App,
756 trigger: AnyTextInputClient,
757 configuration: TextInputConfiguration,
758 ) -> Ref<TextInputConnection> {
759 debug_assert!(
760 !self.autofill_clients(app).iter().any(|client| {
761 !client
762 .text_input_configuration(app)
763 .autofill_configuration
764 .enabled
765 }),
766 "Every client in AutofillScope.autofillClients must enable autofill"
767 );
768 TextInput::attach(app, trigger, configuration)
769 }
770}
771
772/// A partial implementation of [`AutofillScope`].
773///
774/// The mixin provides a default implementation for [`AutofillScope::attach`].
775pub trait AutofillScopeMixin: AutofillScope {}
776
777impl<T: AutofillScope> AutofillScopeMixin for T {}
778
779#[cfg(test)]
780mod tests {
781 use waft_foundation::AppCell;
782
783 use super::*;
784 use crate::text_input::TextInputClient;
785
786 #[test]
787 fn hint_strings_match_dart() {
788 assert_eq!(AutofillHints::EMAIL, "email");
789 assert_eq!(AutofillHints::ONE_TIME_CODE, "oneTimeCode");
790 assert_eq!(AutofillHints::EMAIL_OTP_CODE, "emailOTPCode");
791 }
792
793 #[derive(Default)]
794 struct RecordingField {
795 autofill_id: String,
796 value: TextEditingValue,
797 filled: Option<TextEditingValue>,
798 }
799
800 impl AutofillClient for RecordingField {
801 fn autofill_id(self: Handle<Self>, app: &App) -> String {
802 app.get(self).autofill_id.clone()
803 }
804
805 fn text_input_configuration(self: Handle<Self>, app: &App) -> TextInputConfiguration {
806 TextInputConfiguration::builder()
807 .autofill_configuration(crate::AutofillConfiguration::new(
808 app.get(self).autofill_id.clone(),
809 vec![AutofillHints::EMAIL.to_owned()],
810 app.get(self).value.clone(),
811 ))
812 .build()
813 }
814
815 fn autofill(self: Handle<Self>, app: &mut App, new_editing_value: TextEditingValue) {
816 app.get_mut(self).filled = Some(new_editing_value);
817 }
818 }
819
820 impl TextInputClient for RecordingField {
821 fn current_text_editing_value(self: Handle<Self>, app: &App) -> Option<TextEditingValue> {
822 Some(app.get(self).value.clone())
823 }
824
825 fn update_editing_value(self: Handle<Self>, app: &mut App, value: TextEditingValue) {
826 app.get_mut(self).value = value;
827 }
828
829 fn perform_action(self: Handle<Self>, _app: &mut App, _action: crate::TextInputAction) {}
830
831 fn connection_closed(self: Handle<Self>, _app: &mut App) {}
832 }
833
834 struct RecordingScope {
835 clients: Vec<AnyAutofillClient>,
836 }
837
838 impl AutofillScope for RecordingScope {
839 fn get_autofill_client(
840 self: Handle<Self>,
841 app: &App,
842 autofill_id: &str,
843 ) -> Option<AnyAutofillClient> {
844 self.autofill_clients(app)
845 .into_iter()
846 .find(|client| client.autofill_id(app) == autofill_id)
847 }
848
849 fn autofill_clients(self: Handle<Self>, app: &App) -> Vec<AnyAutofillClient> {
850 app.get(self).clients.clone()
851 }
852 }
853
854 #[test]
855 fn scope_attach_uses_text_input_attach() {
856 let cell = AppCell::new();
857 let mut app = cell.borrow_mut();
858 let field = app.create(RecordingField {
859 autofill_id: "email".into(),
860 ..RecordingField::default()
861 });
862 let scope = app.create(RecordingScope {
863 clients: vec![field.as_autofill_client()],
864 });
865 let configuration = field.text_input_configuration(&app);
866 let connection = scope.attach(&mut app, field.as_text_input_client(), configuration);
867 assert!(connection.attached(&mut app));
868 assert_eq!(
869 scope
870 .get_autofill_client(&app, "email")
871 .map(|c| c.autofill_id(&app)),
872 Some("email".into())
873 );
874 field
875 .as_autofill_client()
876 .autofill(&mut app, TextEditingValue::new().text("user@example.com"));
877 assert_eq!(
878 app.get(&field).filled.as_ref().map(|v| v.text.as_str()),
879 Some("user@example.com")
880 );
881 }
882}