summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/form_manager.cc
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 00:07:59 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 00:07:59 +0000
commitc619032fad7707aee5e9fc8ecaed43419e41165d (patch)
tree4d8e3f4a6de0f00495802bf97ba0e42934101747 /chrome/renderer/form_manager.cc
parentaa2cf38beabe222641b145e1cf985c72acd46c1e (diff)
downloadchromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.zip
chromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.tar.gz
chromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.tar.bz2
AutoFill: Fix scraping a label from a div table.
BUG=61439 TEST=FormManagerTest.LabelsInferredFromDivTable Review URL: http://codereview.chromium.org/4248002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64691 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/form_manager.cc')
-rw-r--r--chrome/renderer/form_manager.cc30
1 files changed, 26 insertions, 4 deletions
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 52bc6cf..265d0c2 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -190,6 +190,26 @@ string16 InferLabelFromTable(
}
// Helper for |InferLabelForElement()| that infers a label, if possible, from
+// a surrounding div table.
+// Eg. <div>Some Text<span><input ...></span></div>
+string16 InferLabelFromDivTable(
+ const WebFormControlElement& element) {
+ WebNode parent = element.parentNode();
+ while (!parent.isNull() && parent.isElementNode() &&
+ !parent.to<WebElement>().hasTagName("div"))
+ parent = parent.parentNode();
+
+ if (parent.isNull() || !parent.isElementNode())
+ return string16();
+
+ WebElement e = parent.to<WebElement>();
+ if (e.isNull() || !e.hasTagName("div"))
+ return string16();
+
+ return FindChildText(e);
+}
+
+// Helper for |InferLabelForElement()| that infers a label, if possible, from
// a surrounding definition list.
// Eg. <dl><dt>Some Text</dt><dd><input ...></dd></dl>
// Eg. <dl><dt><b>Some Text</b></dt><dd><b><input ...></b></dd></dl>
@@ -702,14 +722,16 @@ string16 FormManager::InferLabelForElement(
string16 inferred_label = InferLabelFromPrevious(element);
// If we didn't find a label, check for table cell case.
- if (inferred_label.empty()) {
+ if (inferred_label.empty())
inferred_label = InferLabelFromTable(element);
- }
+
+ // If we didn't find a label, check for div table case.
+ if (inferred_label.empty())
+ inferred_label = InferLabelFromDivTable(element);
// If we didn't find a label, check for definition list case.
- if (inferred_label.empty()) {
+ if (inferred_label.empty())
inferred_label = InferLabelFromDefinitionList(element);
- }
return inferred_label;
}