OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/form_manager.h" | 5 #include "chrome/renderer/form_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/scoped_vector.h" | 8 #include "base/scoped_vector.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 using WebKit::WebVector; | 38 using WebKit::WebVector; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // The number of fields required by AutoFill. Ideally we could send the forms | 42 // The number of fields required by AutoFill. Ideally we could send the forms |
43 // to AutoFill no matter how many fields are in the forms; however, finding the | 43 // to AutoFill no matter how many fields are in the forms; however, finding the |
44 // label for each field is a costly operation and we can't spare the cycles if | 44 // label for each field is a costly operation and we can't spare the cycles if |
45 // it's not necessary. | 45 // it's not necessary. |
46 const size_t kRequiredAutoFillFields = 3; | 46 const size_t kRequiredAutoFillFields = 3; |
47 | 47 |
48 // Returns the node value of the first child of |element| if the first child | 48 // Returns the node value of the first offspring of |element| that is a text |
49 // is text. This is faster alternative to |innerText()| for performance | 49 // node. This is a faster alternative to |innerText()| for performance |
50 // critical operations when the child structure of element is known. | 50 // critical operations when the child structure of |element| is known. |
51 string16 GetChildText(const WebElement& element) { | 51 string16 GetChildText(const WebElement& element) { |
52 string16 element_text; | 52 string16 element_text; |
53 WebNode child = element.firstChild(); | 53 WebNode child = element.firstChild(); |
54 if (!child.isNull() && child.isTextNode()) { | 54 // Find the text node. |
| 55 while (!child.isNull() && !child.isTextNode()) |
| 56 child = child.firstChild(); |
| 57 if (!child.isNull()) { |
55 element_text = child.nodeValue(); | 58 element_text = child.nodeValue(); |
56 TrimWhitespace(element_text, TRIM_ALL, &element_text); | 59 TrimWhitespace(element_text, TRIM_ALL, &element_text); |
57 } | 60 } |
58 return element_text; | 61 return element_text; |
59 } | 62 } |
60 | 63 |
61 } // namespace | 64 } // namespace |
62 | 65 |
63 FormManager::FormManager() { | 66 FormManager::FormManager() { |
64 } | 67 } |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 inferred_label = GetChildText(element); | 579 inferred_label = GetChildText(element); |
577 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); | 580 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); |
578 } | 581 } |
579 } | 582 } |
580 } | 583 } |
581 } | 584 } |
582 } | 585 } |
583 | 586 |
584 return inferred_label; | 587 return inferred_label; |
585 } | 588 } |
OLD | NEW |