| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/content/renderer/form_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 inferred_label = FindChildText(previous); | 267 inferred_label = FindChildText(previous); |
| 268 | 268 |
| 269 break; | 269 break; |
| 270 } | 270 } |
| 271 | 271 |
| 272 base::TrimWhitespace(inferred_label, base::TRIM_ALL, &inferred_label); | 272 base::TrimWhitespace(inferred_label, base::TRIM_ALL, &inferred_label); |
| 273 return inferred_label; | 273 return inferred_label; |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Helper for |InferLabelForElement()| that infers a label, if possible, from | 276 // Helper for |InferLabelForElement()| that infers a label, if possible, from |
| 277 // placeholder text, |
| 278 base::string16 InferLabelFromPlaceholder(const WebFormControlElement& element) { |
| 279 CR_DEFINE_STATIC_LOCAL(WebString, kPlaceholder, ("placeholder")); |
| 280 if (element.hasAttribute(kPlaceholder)) |
| 281 return element.getAttribute(kPlaceholder); |
| 282 |
| 283 return base::string16(); |
| 284 } |
| 285 |
| 286 // Helper for |InferLabelForElement()| that infers a label, if possible, from |
| 277 // enclosing list item, | 287 // enclosing list item, |
| 278 // e.g. <li>Some Text<input ...><input ...><input ...></tr> | 288 // e.g. <li>Some Text<input ...><input ...><input ...></tr> |
| 279 base::string16 InferLabelFromListItem(const WebFormControlElement& element) { | 289 base::string16 InferLabelFromListItem(const WebFormControlElement& element) { |
| 280 WebNode parent = element.parentNode(); | 290 WebNode parent = element.parentNode(); |
| 281 CR_DEFINE_STATIC_LOCAL(WebString, kListItem, ("li")); | 291 CR_DEFINE_STATIC_LOCAL(WebString, kListItem, ("li")); |
| 282 while (!parent.isNull() && parent.isElementNode() && | 292 while (!parent.isNull() && parent.isElementNode() && |
| 283 !parent.to<WebElement>().hasHTMLTagName(kListItem)) { | 293 !parent.to<WebElement>().hasHTMLTagName(kListItem)) { |
| 284 parent = parent.parentNode(); | 294 parent = parent.parentNode(); |
| 285 } | 295 } |
| 286 | 296 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 return FindChildText(previous); | 424 return FindChildText(previous); |
| 415 } | 425 } |
| 416 | 426 |
| 417 // Infers corresponding label for |element| from surrounding context in the DOM, | 427 // Infers corresponding label for |element| from surrounding context in the DOM, |
| 418 // e.g. the contents of the preceding <p> tag or text element. | 428 // e.g. the contents of the preceding <p> tag or text element. |
| 419 base::string16 InferLabelForElement(const WebFormControlElement& element) { | 429 base::string16 InferLabelForElement(const WebFormControlElement& element) { |
| 420 base::string16 inferred_label = InferLabelFromPrevious(element); | 430 base::string16 inferred_label = InferLabelFromPrevious(element); |
| 421 if (!inferred_label.empty()) | 431 if (!inferred_label.empty()) |
| 422 return inferred_label; | 432 return inferred_label; |
| 423 | 433 |
| 434 // If we didn't find a label, check for placeholder text. |
| 435 inferred_label = InferLabelFromPlaceholder(element); |
| 436 if (!inferred_label.empty()) |
| 437 return inferred_label; |
| 438 |
| 424 // If we didn't find a label, check for list item case. | 439 // If we didn't find a label, check for list item case. |
| 425 inferred_label = InferLabelFromListItem(element); | 440 inferred_label = InferLabelFromListItem(element); |
| 426 if (!inferred_label.empty()) | 441 if (!inferred_label.empty()) |
| 427 return inferred_label; | 442 return inferred_label; |
| 428 | 443 |
| 429 // If we didn't find a label, check for table cell case. | 444 // If we didn't find a label, check for table cell case. |
| 430 inferred_label = InferLabelFromTableColumn(element); | 445 inferred_label = InferLabelFromTableColumn(element); |
| 431 if (!inferred_label.empty()) | 446 if (!inferred_label.empty()) |
| 432 return inferred_label; | 447 return inferred_label; |
| 433 | 448 |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 | 1203 |
| 1189 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { | 1204 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
| 1190 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1205 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1191 return gfx::RectF(bounding_box.x() * scale, | 1206 return gfx::RectF(bounding_box.x() * scale, |
| 1192 bounding_box.y() * scale, | 1207 bounding_box.y() * scale, |
| 1193 bounding_box.width() * scale, | 1208 bounding_box.width() * scale, |
| 1194 bounding_box.height() * scale); | 1209 bounding_box.height() * scale); |
| 1195 } | 1210 } |
| 1196 | 1211 |
| 1197 } // namespace autofill | 1212 } // namespace autofill |
| OLD | NEW |