Title: [197626] trunk
Revision
197626
Author
wei...@apple.com
Date
2016-03-05 18:17:29 -0800 (Sat, 05 Mar 2016)

Log Message

Add support for processing the autofill field name out of form control elements ultimately to aid input methods
<rdar://problem/23041180>
https://bugs.webkit.org/show_bug.cgi?id=155079

Reviewed by Enrica Casucci.

Source/WebCore:

Added additional cases to fast/forms/autocomplete-tokens.html.

* WebCore.xcodeproj/project.pbxproj:
Add Autofill.h/cpp

* html/Autofill.cpp: Added.
(WebCore::fieldNameMap):
(WebCore::toAutofillFieldName):
(WebCore::isContactToken):
(WebCore::maxTokensForAutofillFieldCategory):
(WebCore::AutofillData::createFromHTMLFormControlElement):
* html/Autofill.h: Added.
(WebCore::AutofillData::AutofillData):
Refactored the autofill data processing algorithm into it's own file and added support
returning not just the IDL-exposed autofill value but also the autofill field name. The
code is structured simply enough that if we find a need for the hint set or scope information
we could return it as well.

* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::autocomplete):
(WebCore::HTMLFormControlElement::setAutocomplete):
(WebCore::HTMLFormControlElement::autofillMantle):
(WebCore::HTMLFormControlElement::autofillData):
Use AutofillData to implement these.

* html/HTMLFormControlElement.h:
Expose accessor for mantle and AutofillData.

* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::autocomplete):
* html/HTMLFormElement.h:
Switch to return an AtomicString as it will always
return one of two known values.

* testing/Internals.cpp:
(WebCore::Internals::autofillFieldName):
* testing/Internals.h:
* testing/Internals.idl:
Add accessor of the field name for testing purposes.

Source/WebKit2:

* Shared/AssistedNodeInformation.cpp:
(WebKit::AssistedNodeInformation::encode):
(WebKit::AssistedNodeInformation::decode):
* Shared/AssistedNodeInformation.h:
Add AutofillFieldName. Convert some coders to use encodeEnum/decodeEnum instead of casting.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView textInputTraits]):
Map AutofillFieldNames to the associated UITextContentTypes.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getAssistedNodeInformation):
Extract the AutofillFieldNames onto the AssistedNodeInformation for <input> elements 
and <textarea> elements.

LayoutTests:

* fast/forms/autocomplete-tokens-expected.txt:
* fast/forms/autocomplete-tokens.html:
Update test to also test field names, as they are now exposed via internals.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (197625 => 197626)


--- trunk/LayoutTests/ChangeLog	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/LayoutTests/ChangeLog	2016-03-06 02:17:29 UTC (rev 197626)
@@ -1,3 +1,15 @@
+2016-03-05  Sam Weinig  <s...@webkit.org>
+
+        Add support for processing the autofill field name out of form control elements ultimately to aid input methods
+        <rdar://problem/23041180>
+        https://bugs.webkit.org/show_bug.cgi?id=155079
+
+        Reviewed by Enrica Casucci.
+
+        * fast/forms/autocomplete-tokens-expected.txt:
+        * fast/forms/autocomplete-tokens.html:
+        Update test to also test field names, as they are now exposed via internals.
+
 2016-03-05  Simon Fraser  <simon.fra...@apple.com>
 
         Add support for the object-position CSS property

Modified: trunk/LayoutTests/fast/forms/autocomplete-tokens-expected.txt (197625 => 197626)


--- trunk/LayoutTests/fast/forms/autocomplete-tokens-expected.txt	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/LayoutTests/fast/forms/autocomplete-tokens-expected.txt	2016-03-06 02:17:29 UTC (rev 197626)
@@ -5,202 +5,395 @@
 
 Valid keywords:
 PASS input.autocomplete is "name"
+PASS window.internals.autofillFieldName(input) is "name"
 PASS input.autocomplete is "honorific-prefix"
+PASS window.internals.autofillFieldName(input) is "honorific-prefix"
 PASS input.autocomplete is "given-name"
+PASS window.internals.autofillFieldName(input) is "given-name"
 PASS input.autocomplete is "additional-name"
+PASS window.internals.autofillFieldName(input) is "additional-name"
 PASS input.autocomplete is "family-name"
+PASS window.internals.autofillFieldName(input) is "family-name"
 PASS input.autocomplete is "honorific-suffix"
+PASS window.internals.autofillFieldName(input) is "honorific-suffix"
 PASS input.autocomplete is "nickname"
+PASS window.internals.autofillFieldName(input) is "nickname"
 PASS input.autocomplete is "organization-title"
+PASS window.internals.autofillFieldName(input) is "organization-title"
 PASS input.autocomplete is "username"
+PASS window.internals.autofillFieldName(input) is "username"
 PASS input.autocomplete is "new-password"
+PASS window.internals.autofillFieldName(input) is "new-password"
 PASS input.autocomplete is "current-password"
+PASS window.internals.autofillFieldName(input) is "current-password"
 PASS input.autocomplete is "organization"
+PASS window.internals.autofillFieldName(input) is "organization"
 PASS input.autocomplete is "street-address"
+PASS window.internals.autofillFieldName(input) is "street-address"
 PASS input.autocomplete is "address-line1"
+PASS window.internals.autofillFieldName(input) is "address-line1"
 PASS input.autocomplete is "address-line2"
+PASS window.internals.autofillFieldName(input) is "address-line2"
 PASS input.autocomplete is "address-line3"
+PASS window.internals.autofillFieldName(input) is "address-line3"
 PASS input.autocomplete is "address-level4"
+PASS window.internals.autofillFieldName(input) is "address-level4"
 PASS input.autocomplete is "address-level3"
+PASS window.internals.autofillFieldName(input) is "address-level3"
 PASS input.autocomplete is "address-level2"
+PASS window.internals.autofillFieldName(input) is "address-level2"
 PASS input.autocomplete is "address-level1"
+PASS window.internals.autofillFieldName(input) is "address-level1"
 PASS input.autocomplete is "country"
+PASS window.internals.autofillFieldName(input) is "country"
 PASS input.autocomplete is "country-name"
+PASS window.internals.autofillFieldName(input) is "country-name"
 PASS input.autocomplete is "postal-code"
+PASS window.internals.autofillFieldName(input) is "postal-code"
 PASS input.autocomplete is "cc-name"
+PASS window.internals.autofillFieldName(input) is "cc-name"
 PASS input.autocomplete is "cc-given-name"
+PASS window.internals.autofillFieldName(input) is "cc-given-name"
 PASS input.autocomplete is "cc-additional-name"
+PASS window.internals.autofillFieldName(input) is "cc-additional-name"
 PASS input.autocomplete is "cc-family-name"
+PASS window.internals.autofillFieldName(input) is "cc-family-name"
 PASS input.autocomplete is "cc-number"
+PASS window.internals.autofillFieldName(input) is "cc-number"
 PASS input.autocomplete is "cc-exp"
+PASS window.internals.autofillFieldName(input) is "cc-exp"
 PASS input.autocomplete is "cc-exp-month"
+PASS window.internals.autofillFieldName(input) is "cc-exp-month"
 PASS input.autocomplete is "cc-exp-year"
+PASS window.internals.autofillFieldName(input) is "cc-exp-year"
 PASS input.autocomplete is "cc-csc"
+PASS window.internals.autofillFieldName(input) is "cc-csc"
 PASS input.autocomplete is "cc-type"
+PASS window.internals.autofillFieldName(input) is "cc-type"
 PASS input.autocomplete is "transaction-currency"
+PASS window.internals.autofillFieldName(input) is "transaction-currency"
 PASS input.autocomplete is "transaction-amount"
+PASS window.internals.autofillFieldName(input) is "transaction-amount"
 PASS input.autocomplete is "language"
+PASS window.internals.autofillFieldName(input) is "language"
 PASS input.autocomplete is "bday"
+PASS window.internals.autofillFieldName(input) is "bday"
 PASS input.autocomplete is "bday-day"
+PASS window.internals.autofillFieldName(input) is "bday-day"
 PASS input.autocomplete is "bday-month"
+PASS window.internals.autofillFieldName(input) is "bday-month"
 PASS input.autocomplete is "bday-year"
+PASS window.internals.autofillFieldName(input) is "bday-year"
 PASS input.autocomplete is "sex"
+PASS window.internals.autofillFieldName(input) is "sex"
 PASS input.autocomplete is "url"
+PASS window.internals.autofillFieldName(input) is "url"
 PASS input.autocomplete is "photo"
+PASS window.internals.autofillFieldName(input) is "photo"
 PASS input.autocomplete is "tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 
 Contact scope:
 PASS input.autocomplete is "home tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "home tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "home tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "home tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "home tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "home tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "home tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "home tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "home email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "home impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 PASS input.autocomplete is "work tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "work tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "work tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "work tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "work tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "work tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "work tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "work tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "work email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "work impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 PASS input.autocomplete is "mobile tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "mobile tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "mobile tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "mobile tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "mobile tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "mobile tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "mobile tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "mobile tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "mobile email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "mobile impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 PASS input.autocomplete is "fax tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "fax tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "fax tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "fax tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "fax tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "fax tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "fax tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "fax tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "fax email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "fax impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 PASS input.autocomplete is "pager tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "pager tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "pager tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "pager tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "pager tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "pager tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "pager tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "pager tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "pager email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "pager impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 
 Mode:
 PASS input.autocomplete is "shipping street-address"
+PASS window.internals.autofillFieldName(input) is "street-address"
 PASS input.autocomplete is "shipping address-line1"
+PASS window.internals.autofillFieldName(input) is "address-line1"
 PASS input.autocomplete is "shipping address-line2"
+PASS window.internals.autofillFieldName(input) is "address-line2"
 PASS input.autocomplete is "shipping address-line3"
+PASS window.internals.autofillFieldName(input) is "address-line3"
 PASS input.autocomplete is "shipping address-level4"
+PASS window.internals.autofillFieldName(input) is "address-level4"
 PASS input.autocomplete is "shipping address-level3"
+PASS window.internals.autofillFieldName(input) is "address-level3"
 PASS input.autocomplete is "shipping address-level2"
+PASS window.internals.autofillFieldName(input) is "address-level2"
 PASS input.autocomplete is "shipping address-level1"
+PASS window.internals.autofillFieldName(input) is "address-level1"
 PASS input.autocomplete is "shipping country"
+PASS window.internals.autofillFieldName(input) is "country"
 PASS input.autocomplete is "shipping country-name"
+PASS window.internals.autofillFieldName(input) is "country-name"
 PASS input.autocomplete is "shipping postal-code"
+PASS window.internals.autofillFieldName(input) is "postal-code"
 PASS input.autocomplete is "billing street-address"
+PASS window.internals.autofillFieldName(input) is "street-address"
 PASS input.autocomplete is "billing address-line1"
+PASS window.internals.autofillFieldName(input) is "address-line1"
 PASS input.autocomplete is "billing address-line2"
+PASS window.internals.autofillFieldName(input) is "address-line2"
 PASS input.autocomplete is "billing address-line3"
+PASS window.internals.autofillFieldName(input) is "address-line3"
 PASS input.autocomplete is "billing address-level4"
+PASS window.internals.autofillFieldName(input) is "address-level4"
 PASS input.autocomplete is "billing address-level3"
+PASS window.internals.autofillFieldName(input) is "address-level3"
 PASS input.autocomplete is "billing address-level2"
+PASS window.internals.autofillFieldName(input) is "address-level2"
 PASS input.autocomplete is "billing address-level1"
+PASS window.internals.autofillFieldName(input) is "address-level1"
 PASS input.autocomplete is "billing country"
+PASS window.internals.autofillFieldName(input) is "country"
 PASS input.autocomplete is "billing country-name"
+PASS window.internals.autofillFieldName(input) is "country-name"
 PASS input.autocomplete is "billing postal-code"
+PASS window.internals.autofillFieldName(input) is "postal-code"
 
 Section:
 PASS input.autocomplete is "section-parent name"
+PASS window.internals.autofillFieldName(input) is "name"
 PASS input.autocomplete is "section-parent honorific-prefix"
+PASS window.internals.autofillFieldName(input) is "honorific-prefix"
 PASS input.autocomplete is "section-parent given-name"
+PASS window.internals.autofillFieldName(input) is "given-name"
 PASS input.autocomplete is "section-parent additional-name"
+PASS window.internals.autofillFieldName(input) is "additional-name"
 PASS input.autocomplete is "section-parent family-name"
+PASS window.internals.autofillFieldName(input) is "family-name"
 PASS input.autocomplete is "section-parent honorific-suffix"
+PASS window.internals.autofillFieldName(input) is "honorific-suffix"
 PASS input.autocomplete is "section-parent nickname"
+PASS window.internals.autofillFieldName(input) is "nickname"
 PASS input.autocomplete is "section-parent organization-title"
+PASS window.internals.autofillFieldName(input) is "organization-title"
 PASS input.autocomplete is "section-parent username"
+PASS window.internals.autofillFieldName(input) is "username"
 PASS input.autocomplete is "section-parent new-password"
+PASS window.internals.autofillFieldName(input) is "new-password"
 PASS input.autocomplete is "section-parent current-password"
+PASS window.internals.autofillFieldName(input) is "current-password"
 PASS input.autocomplete is "section-parent organization"
+PASS window.internals.autofillFieldName(input) is "organization"
 PASS input.autocomplete is "section-parent street-address"
+PASS window.internals.autofillFieldName(input) is "street-address"
 PASS input.autocomplete is "section-parent address-line1"
+PASS window.internals.autofillFieldName(input) is "address-line1"
 PASS input.autocomplete is "section-parent address-line2"
+PASS window.internals.autofillFieldName(input) is "address-line2"
 PASS input.autocomplete is "section-parent address-line3"
+PASS window.internals.autofillFieldName(input) is "address-line3"
 PASS input.autocomplete is "section-parent address-level4"
+PASS window.internals.autofillFieldName(input) is "address-level4"
 PASS input.autocomplete is "section-parent address-level3"
+PASS window.internals.autofillFieldName(input) is "address-level3"
 PASS input.autocomplete is "section-parent address-level2"
+PASS window.internals.autofillFieldName(input) is "address-level2"
 PASS input.autocomplete is "section-parent address-level1"
+PASS window.internals.autofillFieldName(input) is "address-level1"
 PASS input.autocomplete is "section-parent country"
+PASS window.internals.autofillFieldName(input) is "country"
 PASS input.autocomplete is "section-parent country-name"
+PASS window.internals.autofillFieldName(input) is "country-name"
 PASS input.autocomplete is "section-parent postal-code"
+PASS window.internals.autofillFieldName(input) is "postal-code"
 PASS input.autocomplete is "section-parent cc-name"
+PASS window.internals.autofillFieldName(input) is "cc-name"
 PASS input.autocomplete is "section-parent cc-given-name"
+PASS window.internals.autofillFieldName(input) is "cc-given-name"
 PASS input.autocomplete is "section-parent cc-additional-name"
+PASS window.internals.autofillFieldName(input) is "cc-additional-name"
 PASS input.autocomplete is "section-parent cc-family-name"
+PASS window.internals.autofillFieldName(input) is "cc-family-name"
 PASS input.autocomplete is "section-parent cc-number"
+PASS window.internals.autofillFieldName(input) is "cc-number"
 PASS input.autocomplete is "section-parent cc-exp"
+PASS window.internals.autofillFieldName(input) is "cc-exp"
 PASS input.autocomplete is "section-parent cc-exp-month"
+PASS window.internals.autofillFieldName(input) is "cc-exp-month"
 PASS input.autocomplete is "section-parent cc-exp-year"
+PASS window.internals.autofillFieldName(input) is "cc-exp-year"
 PASS input.autocomplete is "section-parent cc-csc"
+PASS window.internals.autofillFieldName(input) is "cc-csc"
 PASS input.autocomplete is "section-parent cc-type"
+PASS window.internals.autofillFieldName(input) is "cc-type"
 PASS input.autocomplete is "section-parent transaction-currency"
+PASS window.internals.autofillFieldName(input) is "transaction-currency"
 PASS input.autocomplete is "section-parent transaction-amount"
+PASS window.internals.autofillFieldName(input) is "transaction-amount"
 PASS input.autocomplete is "section-parent language"
+PASS window.internals.autofillFieldName(input) is "language"
 PASS input.autocomplete is "section-parent bday"
+PASS window.internals.autofillFieldName(input) is "bday"
 PASS input.autocomplete is "section-parent bday-day"
+PASS window.internals.autofillFieldName(input) is "bday-day"
 PASS input.autocomplete is "section-parent bday-month"
+PASS window.internals.autofillFieldName(input) is "bday-month"
 PASS input.autocomplete is "section-parent bday-year"
+PASS window.internals.autofillFieldName(input) is "bday-year"
 PASS input.autocomplete is "section-parent sex"
+PASS window.internals.autofillFieldName(input) is "sex"
 PASS input.autocomplete is "section-parent url"
+PASS window.internals.autofillFieldName(input) is "url"
 PASS input.autocomplete is "section-parent photo"
+PASS window.internals.autofillFieldName(input) is "photo"
 PASS input.autocomplete is "section-parent tel"
+PASS window.internals.autofillFieldName(input) is "tel"
 PASS input.autocomplete is "section-parent tel-country-code"
+PASS window.internals.autofillFieldName(input) is "tel-country-code"
 PASS input.autocomplete is "section-parent tel-national"
+PASS window.internals.autofillFieldName(input) is "tel-national"
 PASS input.autocomplete is "section-parent tel-area-code"
+PASS window.internals.autofillFieldName(input) is "tel-area-code"
 PASS input.autocomplete is "section-parent tel-local"
+PASS window.internals.autofillFieldName(input) is "tel-local"
 PASS input.autocomplete is "section-parent tel-local-prefix"
+PASS window.internals.autofillFieldName(input) is "tel-local-prefix"
 PASS input.autocomplete is "section-parent tel-local-suffix"
+PASS window.internals.autofillFieldName(input) is "tel-local-suffix"
 PASS input.autocomplete is "section-parent tel-extension"
+PASS window.internals.autofillFieldName(input) is "tel-extension"
 PASS input.autocomplete is "section-parent email"
+PASS window.internals.autofillFieldName(input) is "email"
 PASS input.autocomplete is "section-parent impp"
+PASS window.internals.autofillFieldName(input) is "impp"
 
 Invalid combinations:
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
 PASS input.autocomplete is ""
+PASS window.internals.autofillFieldName(input) is "on"
+PASS inputInAutocompleteOffForm.autocomplete is ""
+PASS window.internals.autofillFieldName(inputInAutocompleteOffForm) is "off"
+PASS inputInAutocompleteOffForm.autocomplete is ""
+PASS window.internals.autofillFieldName(inputInAutocompleteOffForm) is "on"
 
 Non-autocompleteable controls:
 PASS button.autocomplete is "invalid"

Modified: trunk/LayoutTests/fast/forms/autocomplete-tokens.html (197625 => 197626)


--- trunk/LayoutTests/fast/forms/autocomplete-tokens.html	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/LayoutTests/fast/forms/autocomplete-tokens.html	2016-03-06 02:17:29 UTC (rev 197626)
@@ -24,6 +24,8 @@
             keywords.forEach(keyword => {
                 input.autocomplete = keyword;
                 shouldBeEqualToString('input.autocomplete', keyword);
+                if (window.internals)
+                    shouldBeEqualToString('window.internals.autofillFieldName(input)', keyword);
             });
 
             debug('');
@@ -34,6 +36,8 @@
                 contactTokens.forEach(contactToken => {
                     input.autocomplete = scopeToken + " " + contactToken;
                     shouldBeEqualToString('input.autocomplete', scopeToken + " " + contactToken);
+                    if (window.internals)
+                        shouldBeEqualToString('window.internals.autofillFieldName(input)', contactToken);
                 })
             });
 
@@ -45,6 +49,8 @@
                 addressTokens.forEach(addressToken => {
                     input.autocomplete = modeToken + " " + addressToken;
                     shouldBeEqualToString('input.autocomplete', modeToken + " " + addressToken);
+                    if (window.internals)
+                        shouldBeEqualToString('window.internals.autofillFieldName(input)', addressToken);
                 })
             });
 
@@ -54,6 +60,8 @@
                 var value = "section-parent " + keyword;
                 input.autocomplete = value;
                 shouldBeEqualToString('input.autocomplete', value);
+                if (window.internals)
+                    shouldBeEqualToString('window.internals.autofillFieldName(input)', keyword);
             });
 
             debug('');
@@ -61,37 +69,72 @@
             autocompleteableControls.forEach(control => {
                  control.autocomplete = 'invalid';
                  shouldBeEmptyString('input.autocomplete');
+                 if (window.internals)
+                     shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
             });
             // Two normal tokens
             input.autocomplete = "name name";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             input.autocomplete = "name bday";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             // Contact scope token + non-contact token.
             input.autocomplete = "pager bday";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             // Two contact scope tokens.
             input.autocomplete = "home work tel";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             // Two mode tokens.
             input.autocomplete = "shipping billing tel";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             // Two section tokens.
             input.autocomplete = "section-a section-b tel";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             // Anything + on/off.
             input.autocomplete = "tel on";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
             input.autocomplete = "tel off";
             shouldBeEmptyString('input.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(input)', "on");
 
+            // Test dynamically changing the form owner's autocomplete attribute
+            // to ensure the field name correctly reflects it.
+            var form = document.createElement("form");
+            var inputInAutocompleteOffForm = document.createElement("input");
+            form.appendChild(inputInAutocompleteOffForm);
+            document.body.appendChild(form);
+            form.autocomplete = "off";
+            inputInAutocompleteOffForm.autocomplete = "";
+            shouldBeEmptyString('inputInAutocompleteOffForm.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(inputInAutocompleteOffForm)', "off");
+
+            form.autocomplete = "on";
+            shouldBeEmptyString('inputInAutocompleteOffForm.autocomplete');
+            if (window.internals)
+                shouldBeEqualToString('window.internals.autofillFieldName(inputInAutocompleteOffForm)', "on");
+
             debug('');
             debug('Non-autocompleteable controls:');
             // Buttons and keygens are not autocompleteable, so their autocomplete attribute is not sanitized.

Modified: trunk/Source/WebCore/CMakeLists.txt (197625 => 197626)


--- trunk/Source/WebCore/CMakeLists.txt	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-03-06 02:17:29 UTC (rev 197626)
@@ -1612,6 +1612,7 @@
     history/PageCache.cpp
 
     html/AttributeDOMTokenList.cpp
+    html/Autofill.cpp
     html/BaseButtonInputType.cpp
     html/BaseCheckableInputType.cpp
     html/BaseChooserOnlyDateAndTimeInputType.cpp

Modified: trunk/Source/WebCore/ChangeLog (197625 => 197626)


--- trunk/Source/WebCore/ChangeLog	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/ChangeLog	2016-03-06 02:17:29 UTC (rev 197626)
@@ -1,3 +1,51 @@
+2016-03-05  Sam Weinig  <s...@webkit.org>
+
+        Add support for processing the autofill field name out of form control elements ultimately to aid input methods
+        <rdar://problem/23041180>
+        https://bugs.webkit.org/show_bug.cgi?id=155079
+
+        Reviewed by Enrica Casucci.
+
+        Added additional cases to fast/forms/autocomplete-tokens.html.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add Autofill.h/cpp
+
+        * html/Autofill.cpp: Added.
+        (WebCore::fieldNameMap):
+        (WebCore::toAutofillFieldName):
+        (WebCore::isContactToken):
+        (WebCore::maxTokensForAutofillFieldCategory):
+        (WebCore::AutofillData::createFromHTMLFormControlElement):
+        * html/Autofill.h: Added.
+        (WebCore::AutofillData::AutofillData):
+        Refactored the autofill data processing algorithm into it's own file and added support
+        returning not just the IDL-exposed autofill value but also the autofill field name. The
+        code is structured simply enough that if we find a need for the hint set or scope information
+        we could return it as well.
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::autocomplete):
+        (WebCore::HTMLFormControlElement::setAutocomplete):
+        (WebCore::HTMLFormControlElement::autofillMantle):
+        (WebCore::HTMLFormControlElement::autofillData):
+        Use AutofillData to implement these.
+
+        * html/HTMLFormControlElement.h:
+        Expose accessor for mantle and AutofillData.
+
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::autocomplete):
+        * html/HTMLFormElement.h:
+        Switch to return an AtomicString as it will always
+        return one of two known values.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::autofillFieldName):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Add accessor of the field name for testing purposes.
+
 2016-03-05  Ryosuke Niwa  <rn...@webkit.org>
 
         Build fix after r197612 (under ASAN/GuardMalloc).

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (197625 => 197626)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-06 02:17:29 UTC (rev 197626)
@@ -2721,6 +2721,8 @@
 		7AF9B20E18CFB5F400C64BEF /* JSVTTRegionList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AF9B20A18CFB5F300C64BEF /* JSVTTRegionList.cpp */; };
 		7AF9B20F18CFB5F400C64BEF /* JSVTTRegionList.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */; };
 		7BE7427381FA906FBB4F0F2C /* JSSVGGraphicsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 950C4C02BED8936F818E2F99 /* JSSVGGraphicsElement.h */; };
+		7C1843FD1C8B7283002EB973 /* Autofill.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1843FB1C8B7283002EB973 /* Autofill.cpp */; };
+		7C1843FE1C8B7283002EB973 /* Autofill.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C1843FC1C8B7283002EB973 /* Autofill.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C1E97271A9F9834007BF0FB /* AutoFillButtonElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1E97251A9F9834007BF0FB /* AutoFillButtonElement.cpp */; };
 		7C1E97281A9F9834007BF0FB /* AutoFillButtonElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C1E97261A9F9834007BF0FB /* AutoFillButtonElement.h */; };
 		7C2BDD3D17C7F98C0038FF15 /* JSDOMGlobalObjectTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */; };
@@ -10345,6 +10347,8 @@
 		7AF9B20A18CFB5F300C64BEF /* JSVTTRegionList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSVTTRegionList.cpp; sourceTree = "<group>"; };
 		7AF9B20B18CFB5F300C64BEF /* JSVTTRegionList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVTTRegionList.h; sourceTree = "<group>"; };
 		7C0406121C66EE9C00AF0711 /* NSScrollerImpSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSScrollerImpSPI.h; sourceTree = "<group>"; };
+		7C1843FB1C8B7283002EB973 /* Autofill.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Autofill.cpp; sourceTree = "<group>"; };
+		7C1843FC1C8B7283002EB973 /* Autofill.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Autofill.h; sourceTree = "<group>"; };
 		7C1E97251A9F9834007BF0FB /* AutoFillButtonElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutoFillButtonElement.cpp; sourceTree = "<group>"; };
 		7C1E97261A9F9834007BF0FB /* AutoFillButtonElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoFillButtonElement.h; sourceTree = "<group>"; };
 		7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMGlobalObjectTask.cpp; sourceTree = "<group>"; };
@@ -19035,6 +19039,8 @@
 				B1AD4E7713A12A7200846B27 /* track */,
 				A5F6E16C132ED46E008EDAE3 /* Autocapitalize.cpp */,
 				A501920C132EBF2E008BFE55 /* Autocapitalize.h */,
+				7C1843FB1C8B7283002EB973 /* Autofill.cpp */,
+				7C1843FC1C8B7283002EB973 /* Autofill.h */,
 				379E61C5126CA5C300B63E8D /* BaseButtonInputType.cpp */,
 				379E61C6126CA5C300B63E8D /* BaseButtonInputType.h */,
 				379E61C7126CA5C300B63E8D /* BaseCheckableInputType.cpp */,
@@ -26776,6 +26782,7 @@
 				B59DD69D11902A42007E9684 /* JSSQLTransactionCallback.h in Headers */,
 				B59DD6A111902A52007E9684 /* JSSQLTransactionErrorCallback.h in Headers */,
 				51E0BAEB0DA55D4A00A9E417 /* JSStorageEvent.h in Headers */,
+				7C1843FE1C8B7283002EB973 /* Autofill.h in Headers */,
 				89F60CDA15809D760075E157 /* JSStorageInfo.h in Headers */,
 				0FF5026A102BA9430066F39A /* JSStyleMedia.h in Headers */,
 				BCE0139B0C0BEF180043860A /* JSStyleSheet.h in Headers */,
@@ -31159,6 +31166,7 @@
 				93309E04099E64920056E581 /* RemoveNodeCommand.cpp in Sources */,
 				93309E06099E64920056E581 /* RemoveNodePreservingChildrenCommand.cpp in Sources */,
 				7CD494CC1A86EB1D000A87EC /* RenderAttachment.cpp in Sources */,
+				7C1843FD1C8B7283002EB973 /* Autofill.cpp in Sources */,
 				BCEA485F097D93020094C9E4 /* RenderBlock.cpp in Sources */,
 				BC10D76717D8EE6E005E2626 /* RenderBlockFlow.cpp in Sources */,
 				BCEA4852097D93020094C9E4 /* RenderBlockLineLayout.cpp in Sources */,

Added: trunk/Source/WebCore/html/Autofill.cpp (0 => 197626)


--- trunk/Source/WebCore/html/Autofill.cpp	                        (rev 0)
+++ trunk/Source/WebCore/html/Autofill.cpp	2016-03-06 02:17:29 UTC (rev 197626)
@@ -0,0 +1,316 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Autofill.h"
+
+#include "HTMLFormControlElement.h"
+#include "HTMLFormElement.h"
+#include "HTMLNames.h"
+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/AtomicStringHash.h>
+
+namespace WebCore {
+
+enum class AutofillCategory {
+    Off,
+    Automatic,
+    Normal,
+    Contact,
+};
+
+struct AutofillInfo {
+    AutofillFieldName fieldName;
+    AutofillCategory category;
+};
+
+static HashMap<AtomicString, AutofillInfo>& fieldNameMap()
+{
+    static NeverDestroyed<HashMap<AtomicString, AutofillInfo>> map;
+    if (map.get().isEmpty()) {
+        map.get().add(AtomicString("on", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::None, AutofillCategory::Off });
+        map.get().add(AtomicString("off", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::None,  AutofillCategory::Automatic });
+        map.get().add(AtomicString("name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Name, AutofillCategory::Normal });
+        map.get().add(AtomicString("honorific-prefix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::HonorificPrefix, AutofillCategory::Normal });
+        map.get().add(AtomicString("given-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::GivenName, AutofillCategory::Normal });
+        map.get().add(AtomicString("additional-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AdditionalName, AutofillCategory::Normal });
+        map.get().add(AtomicString("family-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::FamilyName, AutofillCategory::Normal });
+        map.get().add(AtomicString("honorific-suffix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::HonorificSuffix, AutofillCategory::Normal });
+        map.get().add(AtomicString("nickname", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Nickname, AutofillCategory::Normal });
+        map.get().add(AtomicString("username", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Username, AutofillCategory::Normal });
+        map.get().add(AtomicString("new-password", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::NewPassword, AutofillCategory::Normal });
+        map.get().add(AtomicString("current-password", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CurrentPassword, AutofillCategory::Normal });
+        map.get().add(AtomicString("organization-title", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::OrganizationTitle, AutofillCategory::Normal });
+        map.get().add(AtomicString("organization", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Organization, AutofillCategory::Normal });
+        map.get().add(AtomicString("street-address", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::StreetAddress, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-line1", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine1, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-line2", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine2, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-line3", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine3, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-level4", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel4, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-level3", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel3, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-level2", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel2, AutofillCategory::Normal });
+        map.get().add(AtomicString("address-level1", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel1, AutofillCategory::Normal });
+        map.get().add(AtomicString("country", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Country, AutofillCategory::Normal });
+        map.get().add(AtomicString("country-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CountryName, AutofillCategory::Normal });
+        map.get().add(AtomicString("postal-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::PostalCode, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcName, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-given-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcGivenName, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-additional-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcAdditionalName, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-family-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcFamilyName, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-number", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcNumber, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-exp", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExp, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-exp-month", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExpMonth, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-exp-year", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExpYear, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-csc", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcCsc, AutofillCategory::Normal });
+        map.get().add(AtomicString("cc-type", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcType, AutofillCategory::Normal });
+        map.get().add(AtomicString("transaction-currency", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TransactionCurrency, AutofillCategory::Normal });
+        map.get().add(AtomicString("transaction-amount", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TransactionAmount, AutofillCategory::Normal });
+        map.get().add(AtomicString("language", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Language, AutofillCategory::Normal });
+        map.get().add(AtomicString("bday", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Bday, AutofillCategory::Normal });
+        map.get().add(AtomicString("bday-day", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayDay, AutofillCategory::Normal });
+        map.get().add(AtomicString("bday-month", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayMonth, AutofillCategory::Normal });
+        map.get().add(AtomicString("bday-year", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayYear, AutofillCategory::Normal });
+        map.get().add(AtomicString("sex", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Sex, AutofillCategory::Normal });
+        map.get().add(AtomicString("url", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::URL, AutofillCategory::Normal });
+        map.get().add(AtomicString("photo", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Photo, AutofillCategory::Normal });
+
+        map.get().add(AtomicString("tel", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Tel, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-country-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelCountryCode, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-national", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelNational, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-area-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelAreaCode, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-local", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocal, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-local-prefix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocalPrefix, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-local-suffix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocalSuffix, AutofillCategory::Contact });
+        map.get().add(AtomicString("tel-extension", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelExtension, AutofillCategory::Contact });
+        map.get().add(AtomicString("email", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Email, AutofillCategory::Contact });
+        map.get().add(AtomicString("impp", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Impp, AutofillCategory::Contact });
+    }
+
+    return map;
+}
+
+AutofillFieldName toAutofillFieldName(const AtomicString& value)
+{
+    auto map = fieldNameMap();
+    auto it = map.find(value);
+    if (it == map.end())
+        return AutofillFieldName::None;
+    return it->value.fieldName;
+}
+
+static inline bool isContactToken(const AtomicString& token)
+{
+    static NeverDestroyed<AtomicString> home("home", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> work("work", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> mobile("mobile", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> fax("fax", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> pager("pager", AtomicString::ConstructFromLiteral);
+
+    return token == home || token == work || token == mobile || token == fax || token == pager;
+}
+
+static unsigned maxTokensForAutofillFieldCategory(AutofillCategory category)
+{
+    switch (category) {
+    case AutofillCategory::Automatic:
+    case AutofillCategory::Off:
+        return 1;
+
+    case AutofillCategory::Normal:
+        return 3;
+
+    case AutofillCategory::Contact:
+        return 4;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+// https://html.spec.whatwg.org/multipage/forms.html#processing-model-3
+AutofillData AutofillData::createFromHTMLFormControlElement(const HTMLFormControlElement& element)
+{
+    static NeverDestroyed<AtomicString> on("on", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> off("off", AtomicString::ConstructFromLiteral);
+
+    // Label: Default
+    // 26. Let the element's IDL-exposed autofill value be the empty string, and its autofill hint set and autofill scope be empty.
+    // 27. If the element's autocomplete attribute is wearing the autofill anchor mantle, then let the element's autofill field name be the empty string and abort these steps.
+    // 28. Let form be the element's form owner, if any, or null otherwise.
+    // 29. If form is not null and form's autocomplete attribute is in the off state, then let the element's autofill field name be "off". Otherwise, let the element's autofill field name be "on".
+    auto defaultLabel = [&] () -> AutofillData {
+        if (element.autofillMantle() == AutofillMantle::Anchor)
+            return { emptyString(), emptyString() };
+        
+        auto form = element.form();
+        if (form && form->autocomplete() == off)
+            return { off, emptyString() };
+        return { on, emptyString() };
+    };
+
+
+    const AtomicString& attributeValue = element.fastGetAttribute(HTMLNames::autocompleteAttr);
+
+    // 1. If the element has no autocomplete attribute, then jump to the step labeled default.
+    if (attributeValue == nullAtom)
+        return defaultLabel();
+
+    // 2. Let tokens be the result of splitting the attribute's value on spaces.
+    SpaceSplitString tokens(attributeValue, true);
+
+    // 3. If tokens is empty, then jump to the step labeled default.
+    if (tokens.isEmpty())
+        return defaultLabel();
+    
+    // 4. Let index be the index of the last token in tokens
+    unsigned index = tokens.size() - 1;
+
+    // 5. If the indexth token in tokens is not an ASCII case-insensitive match for one of the
+    // tokens given in the first column of the following table, or if the number of tokens in
+    // tokens is greater than the maximum number given in the cell in the second column of that
+    // token's row, then jump to the step labeled default. Otherwise, let field be the string given
+    // in the cell of the first column of the matching row, and let category be the value of the
+    // cell in the third column of that same row.
+    auto& map = fieldNameMap();
+
+    auto it = map.find(tokens[index]);
+    if (it == map.end())
+        return defaultLabel();
+    
+    auto category = it->value.category;
+
+    if (tokens.size() > maxTokensForAutofillFieldCategory(category))
+        return defaultLabel();
+
+    const auto& field = tokens[index];
+
+    // 6. If category is Off or Automatic but the element's autocomplete attribute is wearing the
+    // autofill anchor mantle, then jump to the step labeled default.
+    auto mantle = element.autofillMantle();
+    if ((category == AutofillCategory::Off || category == AutofillCategory::Automatic) && mantle == AutofillMantle::Anchor)
+        return defaultLabel();
+
+    // 7. If category is Off, let the element's autofill field name be the string "off", let its
+    // autofill hint set be empty, and let its IDL-exposed autofill value be the string "off".
+    // Then, abort these steps.
+    if (category == AutofillCategory::Off)
+        return { off, off.get().string() };
+
+    // 8. If category is Automatic, let the element's autofill field name be the string "on",
+    // let its autofill hint set be empty, and let its IDL-exposed autofill value be the string
+    // "on". Then, abort these steps.
+    if (category == AutofillCategory::Off)
+        return { on, on.get().string() };
+
+    // 9. Let scope tokens be an empty list.
+    // 10. Let hint tokens be an empty set.
+
+    // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere.
+
+    // 11. Let IDL value have the same value as field.
+    String idlValue = field;
+
+    // 12, If the indexth token in tokens is the first entry, then skip to the step labeled done.
+    if (index == 0)
+        return { field, idlValue };
+
+    // 13. Decrement index by one
+    index--;
+
+    // 14. If category is Contact and the indexth token in tokens is an ASCII case-insensitive match
+    // for one of the strings in the following list, then run the substeps that follow:
+    const auto& contactToken = tokens[index];
+    if (category == AutofillCategory::Contact && isContactToken(contactToken)) {
+        // 1. Let contact be the matching string from the list above.
+        const auto& contact = contactToken;
+
+        // 2. Insert contact at the start of scope tokens.
+        // 3. Add contact to hint tokens.
+
+        // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere.
+
+        // 4. Let IDL value be the concatenation of contact, a U+0020 SPACE character, and the previous
+        // value of IDL value (which at this point will always be field).
+        idlValue = WTF::makeString(contact, " ", idlValue);
+
+        // 5. If the indexth entry in tokens is the first entry, then skip to the step labeled done.
+        if (index == 0)
+            return { field, idlValue };
+
+        // 6. Decrement index by one.
+        index--;
+    }
+
+    // 15. If the indexth token in tokens is an ASCII case-insensitive match for one of the strings
+    // in the following list, then run the substeps that follow:
+    const auto& modeToken = tokens[index];
+    if (equalIgnoringASCIICase(modeToken, "shipping") || equalIgnoringASCIICase(modeToken, "billing")) {
+        // 1. Let mode be the matching string from the list above.
+        const auto& mode = modeToken;
+
+        // 2. Insert mode at the start of scope tokens.
+        // 3. Add mode to hint tokens.
+
+        // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere.
+
+        // 4. Let IDL value be the concatenation of mode, a U+0020 SPACE character, and the previous
+        // value of IDL value (which at this point will either be field or the concatenation of contact,
+        // a space, and field).
+        idlValue = WTF::makeString(mode, " ", idlValue);
+
+        // 5. If the indexth entry in tokens is the first entry, then skip to the step labeled done.
+        if (index == 0)
+            return { field, idlValue };
+
+        // 6. Decrement index by one.
+        index--;
+    }
+
+    // 16. If the indexth entry in tokens is not the first entry, then jump to the step labeled default.
+    if (index != 0)
+        return defaultLabel();
+
+    // 17. If the first eight characters of the indexth token in tokens are not an ASCII case-insensitive
+    // match for the string "section-", then jump to the step labeled default.
+    const auto& sectionToken = tokens[index];
+    if (!sectionToken.startsWithIgnoringASCIICase("section-"))
+        return defaultLabel();
+
+    // 18. Let section be the indexth token in tokens, converted to ASCII lowercase.
+    const auto& section = sectionToken;
+
+    // 19. Insert section at the start of scope tokens.
+
+    // NOTE: We are ignoring this step as we don't currently make use of scope tokens or hint tokens anywhere.
+
+    // 20. Let IDL value be the concatenation of section, a U+0020 SPACE character, and the previous
+    // value of IDL value.
+    idlValue = WTF::makeString(section, " ", idlValue);
+
+    return { field, idlValue };
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/html/Autofill.h (0 => 197626)


--- trunk/Source/WebCore/html/Autofill.h	                        (rev 0)
+++ trunk/Source/WebCore/html/Autofill.h	2016-03-06 02:17:29 UTC (rev 197626)
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef Autofill_h
+#define Autofill_h
+
+#include <wtf/text/AtomicString.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+enum class AutofillMantle {
+    Expectation,
+    Anchor
+};
+
+enum class AutofillFieldName {
+    None,
+    Name,
+    HonorificPrefix,
+    GivenName,
+    AdditionalName,
+    FamilyName,
+    HonorificSuffix,
+    Nickname,
+    Username,
+    NewPassword,
+    CurrentPassword,
+    OrganizationTitle,
+    Organization,
+    StreetAddress,
+    AddressLine1,
+    AddressLine2,
+    AddressLine3,
+    AddressLevel4,
+    AddressLevel3,
+    AddressLevel2,
+    AddressLevel1,
+    Country,
+    CountryName,
+    PostalCode,
+    CcName,
+    CcGivenName,
+    CcAdditionalName,
+    CcFamilyName,
+    CcNumber,
+    CcExp,
+    CcExpMonth,
+    CcExpYear,
+    CcCsc,
+    CcType,
+    TransactionCurrency,
+    TransactionAmount,
+    Language,
+    Bday,
+    BdayDay,
+    BdayMonth,
+    BdayYear,
+    Sex,
+    URL,
+    Photo,
+    Tel,
+    TelCountryCode,
+    TelNational,
+    TelAreaCode,
+    TelLocal,
+    TelLocalPrefix,
+    TelLocalSuffix,
+    TelExtension,
+    Email,
+    Impp
+};
+
+WEBCORE_EXPORT AutofillFieldName toAutofillFieldName(const AtomicString&);
+
+class HTMLFormControlElement;
+
+class AutofillData {
+public:
+    static AutofillData createFromHTMLFormControlElement(const HTMLFormControlElement&);
+
+    AutofillData(const AtomicString& fieldName, const String& idlExposedValue)
+        : fieldName(fieldName)
+        , idlExposedValue(idlExposedValue)
+    {
+    }
+
+    // We could add support for hint tokens and scope tokens if those ever became useful to anyone.
+
+    AtomicString fieldName;
+    String idlExposedValue;
+};
+
+} // namespace
+
+#endif // Autofill_h

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (197625 => 197626)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2016-03-06 02:17:29 UTC (rev 197626)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "HTMLFormControlElement.h"
 
+#include "Autofill.h"
 #include "ControlStates.h"
 #include "ElementAncestorIterator.h"
 #include "Event.h"
@@ -611,167 +612,28 @@
     return nullptr;
 }
 
-static inline bool isContactToken(const AtomicString& token)
+String HTMLFormControlElement::autocomplete() const
 {
-    return token == "home" || token == "work" || token == "mobile" || token == "fax" || token == "pager";
+    return autofillData().idlExposedValue;
 }
 
-enum class AutofillCategory {
-    Invalid,
-    Off,
-    Automatic,
-    Normal,
-    Contact,
-};
-
-static inline AutofillCategory categoryForAutofillFieldToken(const AtomicString& token)
+void HTMLFormControlElement::setAutocomplete(const String& value)
 {
-    static NeverDestroyed<HashMap<AtomicString, AutofillCategory>> map;
-    if (map.get().isEmpty()) {
-        map.get().add(AtomicString("off", AtomicString::ConstructFromLiteral), AutofillCategory::Off);
-        map.get().add(AtomicString("on", AtomicString::ConstructFromLiteral), AutofillCategory::Automatic);
-
-        map.get().add(AtomicString("name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("honorific-prefix", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("given-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("additional-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("family-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("honorific-suffix", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("nickname", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("username", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("new-password", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("current-password", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("organization-title", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("organization", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("street-address", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-line1", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-line2", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-line3", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-level4", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-level3", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-level2", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("address-level1", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("country", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("country-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("postal-code", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-given-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-additional-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-family-name", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-number", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-exp", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-exp-month", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-exp-year", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-csc", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("cc-type", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("transaction-currency", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("transaction-amount", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("language", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("bday", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("bday-day", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("bday-month", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("bday-year", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("sex", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("url", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-        map.get().add(AtomicString("photo", AtomicString::ConstructFromLiteral), AutofillCategory::Normal);
-
-        map.get().add(AtomicString("tel", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-country-code", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-national", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-area-code", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-local", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-local-prefix", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-local-suffix", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("tel-extension", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("email", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-        map.get().add(AtomicString("impp", AtomicString::ConstructFromLiteral), AutofillCategory::Contact);
-    }
-
-    return map.get().get(token);
+    setAttribute(autocompleteAttr, value);
 }
 
-static inline unsigned maxTokensForAutofillFieldCategory(AutofillCategory category)
+AutofillMantle HTMLFormControlElement::autofillMantle() const
 {
-    switch (category) {
-    case AutofillCategory::Invalid:
-        return 0;
-
-    case AutofillCategory::Automatic:
-    case AutofillCategory::Off:
-        return 1;
-
-    case AutofillCategory::Normal:
-        return 3;
-
-    case AutofillCategory::Contact:
-        return 4;
-    }
-    ASSERT_NOT_REACHED();
-    return 0;
+    return is<HTMLInputElement>(*this) && downcast<HTMLInputElement>(this)->isInputTypeHidden() ? AutofillMantle::Anchor : AutofillMantle::Expectation;
 }
 
-// https://html.spec.whatwg.org/multipage/forms.html#processing-model-3
-String HTMLFormControlElement::autocomplete() const
+AutofillData HTMLFormControlElement::autofillData() const
 {
-    bool wearingAutofillAnchorMantle = is<HTMLInputElement>(*this) && downcast<HTMLInputElement>(this)->isInputTypeHidden();
+    // FIXME: We could cache the AutofillData if we we had an efficient way to invalidate the cache when
+    // the autofill mantle changed (due to a type change on an <input> element) or the element's form
+    // owner's autocomplete attribute changed or the form owner itself changed.
 
-    const AtomicString& attributeValue = fastGetAttribute(autocompleteAttr);
-    SpaceSplitString tokens(attributeValue, true);
-    if (tokens.isEmpty()) {
-        if (wearingAutofillAnchorMantle)
-            return String();
-        return form() ? form()->autocomplete() : ASCIILiteral("on");
-    }
-
-    size_t currentTokenIndex = tokens.size() - 1;
-    const auto& fieldToken = tokens[currentTokenIndex];
-    auto category = categoryForAutofillFieldToken(fieldToken);
-    if (category == AutofillCategory::Invalid)
-        return String();
-
-    if (tokens.size() > maxTokensForAutofillFieldCategory(category))
-        return String();
-
-    if ((category == AutofillCategory::Off || category == AutofillCategory::Automatic) && wearingAutofillAnchorMantle)
-        return String();
-
-    if (category == AutofillCategory::Off)
-        return ASCIILiteral("off");
-
-    if (category == AutofillCategory::Automatic)
-        return ASCIILiteral("on");
-
-    String result = fieldToken;
-    if (!currentTokenIndex--)
-        return result;
-
-    const auto& contactToken = tokens[currentTokenIndex];
-    if (category == AutofillCategory::Contact && isContactToken(contactToken)) {
-        result = contactToken + " " + result;
-        if (!currentTokenIndex--)
-            return result;
-    }
-
-    const auto& modeToken = tokens[currentTokenIndex];
-    if (modeToken == "shipping" || modeToken == "billing") {
-        result = modeToken + " " + result;
-        if (!currentTokenIndex--)
-            return result;
-    }
-
-    if (currentTokenIndex)
-        return String();
-
-    const auto& sectionToken = tokens[currentTokenIndex];
-    if (!sectionToken.startsWith("section-"))
-        return String();
-
-    return sectionToken + " " + result;
+    return AutofillData::createFromHTMLFormControlElement(*this);
 }
 
-void HTMLFormControlElement::setAutocomplete(const String& value)
-{
-    setAttribute(autocompleteAttr, value);
-}
-
 } // namespace Webcore

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (197625 => 197626)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2016-03-06 02:17:29 UTC (rev 197626)
@@ -24,6 +24,7 @@
 #ifndef HTMLFormControlElement_h
 #define HTMLFormControlElement_h
 
+#include "Autofill.h"
 #include "FormAssociatedElement.h"
 #include "LabelableElement.h"
 
@@ -120,6 +121,10 @@
     String autocomplete() const;
     void setAutocomplete(const String&);
 
+    AutofillMantle autofillMantle() const;
+
+    WEBCORE_EXPORT AutofillData autofillData() const;
+
     using Node::ref;
     using Node::deref;
 

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (197625 => 197626)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2016-03-06 02:17:29 UTC (rev 197626)
@@ -865,10 +865,10 @@
     setAttributeWithoutSynchronization(autocompleteAttr, value);
 }
 
-const String& HTMLFormElement::autocomplete() const
+const AtomicString& HTMLFormElement::autocomplete() const
 {
-    static NeverDestroyed<const String> on("on", String::ConstructFromLiteral);
-    static NeverDestroyed<const String> off("off", String::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> on("on", AtomicString::ConstructFromLiteral);
+    static NeverDestroyed<AtomicString> off("off", AtomicString::ConstructFromLiteral);
 
     return equalIgnoringASCIICase(fastGetAttribute(autocompleteAttr), "off") ? off : on;
 }

Modified: trunk/Source/WebCore/html/HTMLFormElement.h (197625 => 197626)


--- trunk/Source/WebCore/html/HTMLFormElement.h	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/html/HTMLFormElement.h	2016-03-06 02:17:29 UTC (rev 197626)
@@ -67,7 +67,7 @@
     bool shouldAutocomplete() const;
 
     void setAutocomplete(const AtomicString&);
-    const String& autocomplete() const;
+    const AtomicString& autocomplete() const;
 
 #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE)
     WEBCORE_EXPORT bool autocorrect() const;

Modified: trunk/Source/WebCore/testing/Internals.cpp (197625 => 197626)


--- trunk/Source/WebCore/testing/Internals.cpp	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/testing/Internals.cpp	2016-03-06 02:17:29 UTC (rev 197626)
@@ -31,6 +31,7 @@
 #include "ActiveDOMCallbackMicrotask.h"
 #include "AnimationController.h"
 #include "ApplicationCacheStorage.h"
+#include "Autofill.h"
 #include "BackForwardController.h"
 #include "BitmapImage.h"
 #include "CachedImage.h"
@@ -1369,6 +1370,21 @@
     frameView->scrollElementToRect(*element, IntRect(x, y, w, h));
 }
 
+String Internals::autofillFieldName(Element* element, ExceptionCode& ec)
+{
+    if (!element) {
+        ec = INVALID_ACCESS_ERR;
+        return { };
+    }
+
+    if (!is<HTMLFormControlElement>(*element)) {
+        ec = INVALID_NODE_TYPE_ERR;
+        return { };
+    }
+
+    return downcast<HTMLFormControlElement>(*element).autofillData().fieldName;
+}
+
 void Internals::paintControlTints(ExceptionCode& ec)
 {
     Document* document = contextDocument();

Modified: trunk/Source/WebCore/testing/Internals.h (197625 => 197626)


--- trunk/Source/WebCore/testing/Internals.h	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/testing/Internals.h	2016-03-06 02:17:29 UTC (rev 197626)
@@ -183,6 +183,8 @@
     void setShowAutoFillButton(Element*, const String& autoFillButtonType, ExceptionCode&);
     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
 
+    String autofillFieldName(Element*, ExceptionCode&);
+
     void paintControlTints(ExceptionCode&);
 
     RefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&);

Modified: trunk/Source/WebCore/testing/Internals.idl (197625 => 197626)


--- trunk/Source/WebCore/testing/Internals.idl	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebCore/testing/Internals.idl	2016-03-06 02:17:29 UTC (rev 197626)
@@ -162,6 +162,8 @@
     [RaisesException] void setShowAutoFillButton(Element inputElement, AutoFillButtonType autoFillButtonType);
     [RaisesException] unsigned long countMatchesForText(DOMString text, unsigned long findOptions, DOMString markMatches);
 
+    [RaisesException] DOMString autofillFieldName(Element formControlElement);
+
     [RaisesException] void paintControlTints();
 
     [RaisesException] void scrollElementToRect(Element element, long x, long y, long w, long h);

Modified: trunk/Source/WebKit2/ChangeLog (197625 => 197626)


--- trunk/Source/WebKit2/ChangeLog	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-06 02:17:29 UTC (rev 197626)
@@ -1,3 +1,26 @@
+2016-03-05  Sam Weinig  <s...@webkit.org>
+
+        Add support for processing the autofill field name out of form control elements ultimately to aid input methods
+        <rdar://problem/23041180>
+        https://bugs.webkit.org/show_bug.cgi?id=155079
+
+        Reviewed by Enrica Casucci.
+
+        * Shared/AssistedNodeInformation.cpp:
+        (WebKit::AssistedNodeInformation::encode):
+        (WebKit::AssistedNodeInformation::decode):
+        * Shared/AssistedNodeInformation.h:
+        Add AutofillFieldName. Convert some coders to use encodeEnum/decodeEnum instead of casting.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView textInputTraits]):
+        Map AutofillFieldNames to the associated UITextContentTypes.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getAssistedNodeInformation):
+        Extract the AutofillFieldNames onto the AssistedNodeInformation for <input> elements 
+        and <textarea> elements.
+
 2016-03-05  Timothy Hatcher  <timo...@apple.com>
 
         Implement the Automation protocol commands by tracking WebPageProxy objects

Modified: trunk/Source/WebKit2/Shared/AssistedNodeInformation.cpp (197625 => 197626)


--- trunk/Source/WebKit2/Shared/AssistedNodeInformation.cpp	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebKit2/Shared/AssistedNodeInformation.cpp	2016-03-06 02:17:29 UTC (rev 197626)
@@ -71,8 +71,8 @@
     encoder << hasNextNode;
     encoder << hasPreviousNode;
     encoder << isAutocorrect;
-    encoder << (uint32_t)autocapitalizeType;
-    encoder << (uint32_t)elementType;
+    encoder.encodeEnum(autocapitalizeType);
+    encoder.encodeEnum(elementType);
     encoder << formAction;
     encoder << selectOptions;
     encoder << selectedIndex;
@@ -83,6 +83,7 @@
     encoder << value;
     encoder << valueAsNumber;
     encoder << title;
+    encoder.encodeEnum(autofillFieldName);
 }
 
 bool AssistedNodeInformation::decode(IPC::ArgumentDecoder& decoder, AssistedNodeInformation& result)
@@ -111,10 +112,10 @@
     if (!decoder.decode(result.isAutocorrect))
         return false;
 
-    if (!decoder.decode((uint32_t&)result.autocapitalizeType))
+    if (!decoder.decodeEnum(result.autocapitalizeType))
         return false;
 
-    if (!decoder.decode((uint32_t&)result.elementType))
+    if (!decoder.decodeEnum(result.elementType))
         return false;
 
     if (!decoder.decode(result.formAction))
@@ -147,6 +148,9 @@
     if (!decoder.decode(result.title))
         return false;
 
+    if (!decoder.decodeEnum(result.autofillFieldName))
+        return false;
+
     return true;
 }
 #endif

Modified: trunk/Source/WebKit2/Shared/AssistedNodeInformation.h (197625 => 197626)


--- trunk/Source/WebKit2/Shared/AssistedNodeInformation.h	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebKit2/Shared/AssistedNodeInformation.h	2016-03-06 02:17:29 UTC (rev 197626)
@@ -27,6 +27,7 @@
 #define AssistedNodeInformation_h
 
 #include "ArgumentCoders.h"
+#include <WebCore/Autofill.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/WebAutocapitalize.h>
 #include <wtf/text/WTFString.h>
@@ -130,6 +131,7 @@
     String value;
     double valueAsNumber;
     String title;
+    WebCore::AutofillFieldName autofillFieldName { WebCore::AutofillFieldName::None };
 
     void encode(IPC::ArgumentEncoder&) const;
     static bool decode(IPC::ArgumentDecoder&, AssistedNodeInformation&);

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (197625 => 197626)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2016-03-06 02:17:29 UTC (rev 197626)
@@ -2822,6 +2822,106 @@
          [_traits setKeyboardType:UIKeyboardTypeDefault];
     }
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000
+    switch (_assistedNodeInformation.autofillFieldName) {
+    case WebCore::AutofillFieldName::Name:
+        [_traits setTextContentType:UITextContentTypeName];
+        break;
+    case WebCore::AutofillFieldName::HonorificPrefix:
+        [_traits setTextContentType:UITextContentTypeNamePrefix];
+        break;
+    case WebCore::AutofillFieldName::GivenName:
+        [_traits setTextContentType:UITextContentTypeMiddleName];
+        break;
+    case WebCore::AutofillFieldName::AdditionalName:
+        [_traits setTextContentType:UITextContentTypeMiddleName];
+        break;
+    case WebCore::AutofillFieldName::FamilyName:
+        [_traits setTextContentType:UITextContentTypeFamilyName];
+        break;
+    case WebCore::AutofillFieldName::HonorificSuffix:
+        [_traits setTextContentType:UITextContentTypeNameSuffix];
+        break;
+    case WebCore::AutofillFieldName::Nickname:
+        [_traits setTextContentType:UITextContentTypeNickname];
+        break;
+    case WebCore::AutofillFieldName::OrganizationTitle:
+        [_traits setTextContentType:UITextContentTypeJobTitle];
+        break;
+    case WebCore::AutofillFieldName::Organization:
+        [_traits setTextContentType:UITextContentTypeOrganizationName];
+        break;
+    case WebCore::AutofillFieldName::StreetAddress:
+        [_traits setTextContentType:UITextContentTypeFullStreetAddress];
+        break;
+    case WebCore::AutofillFieldName::AddressLine1:
+        [_traits setTextContentType:UITextContentTypeStreetAddressLine1];
+        break;
+    case WebCore::AutofillFieldName::AddressLine2:
+        [_traits setTextContentType:UITextContentTypeStreetAddressLine2];
+        break;
+    case WebCore::AutofillFieldName::AddressLevel3:
+        [_traits setTextContentType:UITextContentTypeSublocality];
+        break;
+    case WebCore::AutofillFieldName::AddressLevel2:
+        [_traits setTextContentType:UITextContentTypeAddressCity];
+        break;
+    case WebCore::AutofillFieldName::AddressLevel1:
+        [_traits setTextContentType:UITextContentTypeAddressState];
+        break;
+    case WebCore::AutofillFieldName::CountryName:
+        [_traits setTextContentType:UITextContentTypeCountryName];
+        break;
+    case WebCore::AutofillFieldName::PostalCode:
+        [_traits setTextContentType:UITextContentTypePostalCode];
+        break;
+    case WebCore::AutofillFieldName::Tel:
+        [_traits setTextContentType:UITextContentTypeTelephoneNumber];
+        break;
+    case WebCore::AutofillFieldName::Email:
+        [_traits setTextContentType:UITextContentTypeEmailAddress];
+        break;
+    case WebCore::AutofillFieldName::URL:
+        [_traits setTextContentType:UITextContentTypeURL];
+        break;
+    case WebCore::AutofillFieldName::None:
+    case WebCore::AutofillFieldName::Username:
+    case WebCore::AutofillFieldName::NewPassword:
+    case WebCore::AutofillFieldName::CurrentPassword:
+    case WebCore::AutofillFieldName::AddressLine3:
+    case WebCore::AutofillFieldName::AddressLevel4:
+    case WebCore::AutofillFieldName::Country:
+    case WebCore::AutofillFieldName::CcName:
+    case WebCore::AutofillFieldName::CcGivenName:
+    case WebCore::AutofillFieldName::CcAdditionalName:
+    case WebCore::AutofillFieldName::CcFamilyName:
+    case WebCore::AutofillFieldName::CcNumber:
+    case WebCore::AutofillFieldName::CcExp:
+    case WebCore::AutofillFieldName::CcExpMonth:
+    case WebCore::AutofillFieldName::CcExpYear:
+    case WebCore::AutofillFieldName::CcCsc:
+    case WebCore::AutofillFieldName::CcType:
+    case WebCore::AutofillFieldName::TransactionCurrency:
+    case WebCore::AutofillFieldName::TransactionAmount:
+    case WebCore::AutofillFieldName::Language:
+    case WebCore::AutofillFieldName::Bday:
+    case WebCore::AutofillFieldName::BdayDay:
+    case WebCore::AutofillFieldName::BdayMonth:
+    case WebCore::AutofillFieldName::BdayYear:
+    case WebCore::AutofillFieldName::Sex:
+    case WebCore::AutofillFieldName::Photo:
+    case WebCore::AutofillFieldName::TelCountryCode:
+    case WebCore::AutofillFieldName::TelNational:
+    case WebCore::AutofillFieldName::TelAreaCode:
+    case WebCore::AutofillFieldName::TelLocal:
+    case WebCore::AutofillFieldName::TelLocalPrefix:
+    case WebCore::AutofillFieldName::TelLocalSuffix:
+    case WebCore::AutofillFieldName::TelExtension:
+    case WebCore::AutofillFieldName::Impp:
+        break;
+    };
+#endif
+
     return _traits.get();
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (197625 => 197626)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-03-06 01:52:38 UTC (rev 197625)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2016-03-06 02:17:29 UTC (rev 197626)
@@ -49,6 +49,7 @@
 #import "WebPageProxyMessages.h"
 #import "WebProcess.h"
 #import <CoreText/CTFont.h>
+#import <WebCore/Autofill.h>
 #import <WebCore/Chrome.h>
 #import <WebCore/DataDetection.h>
 #import <WebCore/DiagnosticLoggingClient.h>
@@ -2425,6 +2426,7 @@
         information.elementType = InputType::TextArea;
         information.isReadOnly = element.isReadOnly();
         information.value = element.value();
+        information.autofillFieldName = WebCore::toAutofillFieldName(element.autofillData().fieldName);
     } else if (is<HTMLInputElement>(*m_assistedNode)) {
         HTMLInputElement& element = downcast<HTMLInputElement>(*m_assistedNode);
         HTMLFormElement* form = element.form();
@@ -2472,6 +2474,7 @@
         information.value = element.value();
         information.valueAsNumber = element.valueAsNumber();
         information.title = element.title();
+        information.autofillFieldName = WebCore::toAutofillFieldName(element.autofillData().fieldName);
     } else if (m_assistedNode->hasEditableStyle()) {
         information.elementType = InputType::ContentEditable;
         information.isAutocorrect = true;   // FIXME: Should we look at the attribute?
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to