Chromium Code Reviews| Index: components/autofill/content/renderer/form_autofill_util.cc |
| diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc |
| index d7a163c940ce59c30068fe47ec24778bb1128710..3c034135fa6f2db9fa8dce3f77d03ff35d289063 100644 |
| --- a/components/autofill/content/renderer/form_autofill_util.cc |
| +++ b/components/autofill/content/renderer/form_autofill_util.cc |
| @@ -422,6 +422,11 @@ base::string16 InferLabelFromTableRow(const WebFormControlElement& element) { |
| // a surrounding div table, |
| // e.g. <div>Some Text<span><input ...></span></div> |
| // e.g. <div>Some Text</div><div><input ...></div> |
| +// |
| +// Because this is already traversing the <div> structure, if it finds a <label> |
| +// sibling along the way, infer from that <label>. A possible future improvement |
| +// is to ignore <label for="valid_id"> since those are associated with other |
|
Evan Stade
2015/03/16 23:35:36
isn't it pretty easy to do this? just check WebLab
Lei Zhang
2015/03/17 00:23:37
Yes, I just didn't get to it, so I just wrote a no
|
| +// elements. |
| base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { |
| WebNode node = element.parentNode(); |
| bool looking_for_parent = true; |
| @@ -432,6 +437,7 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { |
| 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)) { |
| if (looking_for_parent) |
| @@ -452,6 +458,8 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { |
| } |
| looking_for_parent = false; |
| + } else if (!looking_for_parent && HasTagName(node, kLabel)) { |
| + 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. |