diff options
author | thestig <thestig@chromium.org> | 2015-03-18 17:27:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-19 00:28:44 +0000 |
commit | cd1401c2d863a44ea405a313e94d8fcbfbfb7ada (patch) | |
tree | d53ef35bdccee234a96a0b6526f1a6019189db03 | |
parent | 7c0b1291c525a2b6aa3fe810fd69098952bc2d5f (diff) | |
download | chromium_src-cd1401c2d863a44ea405a313e94d8fcbfbfb7ada.zip chromium_src-cd1401c2d863a44ea405a313e94d8fcbfbfb7ada.tar.gz chromium_src-cd1401c2d863a44ea405a313e94d8fcbfbfb7ada.tar.bz2 |
Autofill: Improve the order of heuristics to apply when inferring labels
Right now the order is somewhat arbitrary. Instead, look at the types of
a field's ancestors to determine the order.
BUG=465587
Review URL: https://codereview.chromium.org/1012093004
Cr-Commit-Position: refs/heads/master@{#321249}
4 files changed, 76 insertions, 74 deletions
diff --git a/chrome/test/data/autofill/heuristics/output/12_register_officedepot.com.out b/chrome/test/data/autofill/heuristics/output/12_register_officedepot.com.out index d5132a5..f94b063 100644 --- a/chrome/test/data/autofill/heuristics/output/12_register_officedepot.com.out +++ b/chrome/test/data/autofill/heuristics/output/12_register_officedepot.com.out @@ -3,7 +3,7 @@ NAME_MIDDLE_INITIAL | addrsForm[0].middleInitial | Middle Initial: | | addrsFor NAME_LAST | addrsForm[0].lastName | *Last Name: | | addrsForm[0].firstName_1-default COMPANY_NAME | addrsForm[0].shiptoName | Company Name | | addrsForm[0].firstName_1-default ADDRESS_HOME_LINE1 | addrsForm[0].address1 | *Address | | addrsForm[0].firstName_1-default -ADDRESS_HOME_LINE2 | addrsForm[0].address2 | *First Name:Middle Initial:*Last Name:Company Name | | addrsForm[0].firstName_1-default +ADDRESS_HOME_LINE2 | addrsForm[0].address2 | | | addrsForm[0].firstName_1-default ADDRESS_HOME_CITY | addrsForm[0].city | *City | | addrsForm[0].firstName_1-default ADDRESS_HOME_STATE | addrsForm[0].state | *State | {blank} | addrsForm[0].firstName_1-default ADDRESS_HOME_ZIP | addrsForm[0].postalCode1 | *Zip Code | | addrsForm[0].firstName_1-default @@ -26,7 +26,7 @@ NAME_MIDDLE_INITIAL | addrsForm[2].middleInitial | Middle Initial: | | addrsFor NAME_LAST | addrsForm[2].lastName | *Last Name: | | addrsForm[2].firstName_1-default COMPANY_NAME | addrsForm[2].shiptoName | Company Name | | addrsForm[2].firstName_1-default ADDRESS_HOME_LINE1 | addrsForm[2].address1 | *Address | | addrsForm[2].firstName_1-default -ADDRESS_HOME_LINE2 | addrsForm[2].address2 | * Indicates required field *First Name:Middle Initial:*Last Name:Company Name | | addrsForm[2].firstName_1-default +ADDRESS_HOME_LINE2 | addrsForm[2].address2 | | | addrsForm[2].firstName_1-default ADDRESS_HOME_CITY | addrsForm[2].city | *City | | addrsForm[2].firstName_1-default ADDRESS_HOME_STATE | addrsForm[2].state | *State | {blank} | addrsForm[2].firstName_1-default ADDRESS_HOME_ZIP | addrsForm[2].postalCode1 | *Zip Code | | addrsForm[2].firstName_1-default diff --git a/chrome/test/data/autofill/heuristics/output/20_register_epson.com.mx.out b/chrome/test/data/autofill/heuristics/output/20_register_epson.com.mx.out index 3c6a52f..8d33cc7 100644 --- a/chrome/test/data/autofill/heuristics/output/20_register_epson.com.mx.out +++ b/chrome/test/data/autofill/heuristics/output/20_register_epson.com.mx.out @@ -1,5 +1,5 @@ UNKNOWN_TYPE | doAction | | | doAction_1-default -ADDRESS_HOME_COUNTRY | idPaiseReg | n del producto *dd/mm/yyyySerial *Acerca del nro. de Serie | MX | doAction_1-default +ADDRESS_HOME_COUNTRY | idPaiseReg | | MX | doAction_1-default UNKNOWN_TYPE | fechaCompra | *dd/mm/yyyy | | doAction_1-default UNKNOWN_TYPE | serialNumber | Serial * | | doAction_1-default UNKNOWN_TYPE | idProducto | Serial * | | doAction_1-default diff --git a/chrome/test/data/autofill/heuristics/output/bug_465587.out b/chrome/test/data/autofill/heuristics/output/bug_465587.out index ed43f40..7bc8116 100644 --- a/chrome/test/data/autofill/heuristics/output/bug_465587.out +++ b/chrome/test/data/autofill/heuristics/output/bug_465587.out @@ -2,30 +2,30 @@ UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler. UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType | Paypal | payPalPayment | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType | Gift Certificate | giftCertificate | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default CREDIT_CARD_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.creditCardType | Credit Card Type | visa | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -CREDIT_CARD_NAME | cardholder | Credit Card Type | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -CREDIT_CARD_NUMBER | cardnumber | Credit Card Type | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -CREDIT_CARD_EXP_MONTH | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.expirationMonth | Credit Card Type | 01 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -CREDIT_CARD_EXP_4_DIGIT_YEAR | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.expirationYear | Credit Card Type | 2015 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -CREDIT_CARD_TYPE | secureid | Credit Card Type | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.billingSameAsShipping | Credit Card Type | true | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default -CREDIT_CARD_NAME | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName | First Name | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-cc -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.lastName | Last Name | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | APO FPO DPO | APO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | APO | FPO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | FPO | DPO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_COUNTRY | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.country | Country | US | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_LINE1 | address1 | Address | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_LINE2 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.address2 | Address | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_CITY | city | City | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -ADDRESS_HOME_ZIP | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.postalCode | Zip / Postal Code | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -PHONE_HOME_WHOLE_NUMBER | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.phoneNumber | Phone | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/commerce/cart/item/3281003514/item_qty | Optimum Nutrition Gold Standard 100% Whey Delicious Strawberry, 1 Lb. $14.98 | 1 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | 1 Day Delivers in 1 business day $16.48 | 1 Day (Order By 3:00 p.m. PST) | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | 2 Day Delivers in 2 business days $11.98 | 2 Day | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | Standard Delivers in 2-3 business days $5.97 | Standard (3-5 Days) | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.isSignupNewsletter | Orders are subject to Bodybuilding.com'sTerms of Use and Privacy Policy. | true | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default -UNKNOWN_TYPE | formhandler | Orders are subject to Bodybuilding.com'sTerms of Use and Privacy Policy. | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName_1-default +CREDIT_CARD_NAME | cardholder | Cardholder Name | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc +CREDIT_CARD_NUMBER | cardnumber | Credit Card Number | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc +CREDIT_CARD_EXP_MONTH | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.expirationMonth | Expiration Date | 01 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc +CREDIT_CARD_EXP_4_DIGIT_YEAR | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.expirationYear | Expiration Date | 2015 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc +CREDIT_CARD_VERIFICATION_CODE | secureid | CVC/CVV | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-cc +UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.billingSameAsShipping | | true | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +NAME_FIRST | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.firstName | First Name | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +NAME_LAST | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.lastName | Last Name | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | APO FPO DPO | APO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | APO | FPO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.militaryAddressInd | FPO | DPO | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_COUNTRY | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.country | Country | US | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_LINE1 | address1 | Address | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_LINE2 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.address2 | Address | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_CITY | city | City | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_STATE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.state | State: | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +ADDRESS_HOME_ZIP | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.postalCode | Zip / Postal Code | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +PHONE_HOME_WHOLE_NUMBER | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.creditCard.billingAddress.phoneNumber | Phone | | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/commerce/cart/item/3281003514/item_qty | Optimum Nutrition Gold Standard 100% Whey Delicious Strawberry, 1 Lb. $14.98 | 1 | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | 1 Day Delivers in 1 business day $16.48 | 1 Day (Order By 3:00 p.m. PST) | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | 2 Day Delivers in 2 business days $11.98 | 2 Day | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/shipping/group/sg1157540843 | Standard Delivers in 2-3 business days $5.97 | Standard (3-5 Days) | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.isSignupNewsletter | Orders are subject to Bodybuilding.com'sTerms of Use and Privacy Policy. | true | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default +UNKNOWN_TYPE | formhandler | Orders are subject to Bodybuilding.com'sTerms of Use and Privacy Policy. | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler | /bodybuilding/commerce/order/purchase/CardPaymentInfoFormHandler.billingInfo.paymentType_1-default diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc index 90fa11f..91d3572 100644 --- a/components/autofill/content/renderer/form_autofill_util.cc +++ b/components/autofill/content/renderer/form_autofill_util.cc @@ -129,6 +129,21 @@ bool IsElementInsideFormOrFieldSet(const WebElement& element) { return false; } +// Returns true if |node| is an element and it is a container type that +// InferLabelForElement() can traverse. +bool IsTraversableContainerElement(const WebNode& node) { + if (!node.isElementNode()) + return false; + + std::string tag_name = node.toConst<WebElement>().tagName().utf8(); + return (tag_name == "DD" || + tag_name == "DIV" || + tag_name == "FIELDSET" || + tag_name == "LI" || + tag_name == "TD" || + tag_name == "TABLE"); +} + // Check whether the given field satisfies the REQUIRE_AUTOCOMPLETE requirement. bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) { return input_element.autoComplete(); @@ -546,8 +561,6 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { // Search the sibling and parent <div>s until we find a candidate label. base::string16 inferred_label; CR_DEFINE_STATIC_LOCAL(WebString, kDiv, ("div")); - CR_DEFINE_STATIC_LOCAL(WebString, kTable, ("table")); - CR_DEFINE_STATIC_LOCAL(WebString, kFieldSet, ("fieldset")); CR_DEFINE_STATIC_LOCAL(WebString, kLabel, ("label")); while (inferred_label.empty() && !node.isNull()) { if (HasTagName(node, kDiv)) { @@ -573,9 +586,8 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { WebLabelElement label_element = node.to<WebLabelElement>(); if (label_element.correspondingControl().isNull()) inferred_label = FindChildText(node); - } else if (looking_for_parent && - (HasTagName(node, kTable) || HasTagName(node, kFieldSet))) { - // If the element is in a table or fieldset, its label most likely is too. + } else if (looking_for_parent && IsTraversableContainerElement(node)) { + // If the element is in a non-div container, its label most likely is too. break; } @@ -617,23 +629,20 @@ base::string16 InferLabelFromDefinitionList( return FindChildText(previous); } -// Returns true if the closest ancestor is a <div> and not a <td>. -// Returns false if the closest ancestor is a <td> tag, -// or if there is no <div> or <td> ancestor. -bool ClosestAncestorIsDivAndNotTD(const WebFormControlElement& element) { +// Returns the element type for all ancestor nodes in CAPS, starting with the +// parent node. +std::vector<std::string> AncestorTagNames( + const WebFormControlElement& element) { + std::vector<std::string> tag_names; for (WebNode parent_node = element.parentNode(); !parent_node.isNull(); parent_node = parent_node.parentNode()) { if (!parent_node.isElementNode()) continue; - WebElement cur_element = parent_node.to<WebElement>(); - if (cur_element.hasHTMLTagName("div")) - return true; - if (cur_element.hasHTMLTagName("td")) - return false; + tag_names.push_back(parent_node.to<WebElement>().tagName().utf8()); } - return false; + return tag_names; } // Infers corresponding label for |element| from surrounding context in the DOM, @@ -655,40 +664,33 @@ base::string16 InferLabelForElement(const WebFormControlElement& element) { if (!inferred_label.empty()) return inferred_label; - // If we didn't find a label, check for list item case. - inferred_label = InferLabelFromListItem(element); - if (!inferred_label.empty()) - return inferred_label; + // For all other searches that involve traversing up the tree, the search + // order is based on which tag is the closest ancestor to |element|. + std::vector<std::string> tag_names = AncestorTagNames(element); + std::set<std::string> seen_tag_names; + for (const std::string& tag_name : tag_names) { + if (ContainsKey(seen_tag_names, tag_name)) + continue; - // If we didn't find a label, check for definition list case. - inferred_label = InferLabelFromDefinitionList(element); - if (!inferred_label.empty()) - return inferred_label; + seen_tag_names.insert(tag_name); + if (tag_name == "DIV") { + inferred_label = InferLabelFromDivTable(element); + } else if (tag_name == "TD") { + inferred_label = InferLabelFromTableColumn(element); + if (inferred_label.empty()) + inferred_label = InferLabelFromTableRow(element); + } else if (tag_name == "DD") { + inferred_label = InferLabelFromDefinitionList(element); + } else if (tag_name == "LI") { + inferred_label = InferLabelFromListItem(element); + } else if (tag_name == "FIELDSET") { + break; + } - bool check_div_first = ClosestAncestorIsDivAndNotTD(element); - if (check_div_first) { - // If we didn't find a label, check for div table case first since it's the - // closest ancestor. - inferred_label = InferLabelFromDivTable(element); if (!inferred_label.empty()) - return inferred_label; + break; } - // If we didn't find a label, check for table cell case. - inferred_label = InferLabelFromTableColumn(element); - if (!inferred_label.empty()) - return inferred_label; - - // If we didn't find a label, check for table row case. - inferred_label = InferLabelFromTableRow(element); - if (!inferred_label.empty()) - return inferred_label; - - if (!check_div_first) { - // If we didn't find a label from the table, check for div table case if we - // haven't already. - inferred_label = InferLabelFromDivTable(element); - } return inferred_label; } |