OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill/form_manager.h" | 5 #include "chrome/renderer/autofill/form_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (previous.isNull()) | 146 if (previous.isNull()) |
147 return string16(); | 147 return string16(); |
148 | 148 |
149 if (previous.isTextNode()) { | 149 if (previous.isTextNode()) { |
150 inferred_label = previous.nodeValue(); | 150 inferred_label = previous.nodeValue(); |
151 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); | 151 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); |
152 } | 152 } |
153 | 153 |
154 // If we didn't find text, check for previous paragraph. | 154 // If we didn't find text, check for previous paragraph. |
155 // Eg. <p>Some Text</p><input ...> | 155 // Eg. <p>Some Text</p><input ...> |
156 // Note the lack of whitespace between <p> and <input> elements. | 156 // Eg. <b>Some Text</b><input ...> |
| 157 // Note the lack of whitespace between (<p> or <b>) and <input> elements. |
157 if (inferred_label.empty() && previous.isElementNode()) { | 158 if (inferred_label.empty() && previous.isElementNode()) { |
158 WebElement element = previous.to<WebElement>(); | 159 WebElement element = previous.to<WebElement>(); |
159 if (element.hasTagName("p")) { | 160 if (element.hasTagName("p") || element.hasTagName("b")) { |
160 inferred_label = FindChildText(element); | 161 inferred_label = FindChildText(element); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 // If we didn't find paragraph, check for previous paragraph to this. | 165 // If we didn't find paragraph, check for previous paragraph to this. |
165 // Eg. <p>Some Text</p> <input ...> | 166 // Eg. <p>Some Text</p> <input ...> |
166 // Note the whitespace between <p> and <input> elements. | 167 // Eg. <b>Some Text</b> <input ...> |
| 168 // Note the whitespace between (<p> or <b>) and <input> elements. |
167 if (inferred_label.empty()) { | 169 if (inferred_label.empty()) { |
168 WebNode sibling = previous.previousSibling(); | 170 WebNode sibling = previous.previousSibling(); |
169 if (!sibling.isNull() && sibling.isElementNode()) { | 171 if (!sibling.isNull() && sibling.isElementNode()) { |
170 WebElement element = sibling.to<WebElement>(); | 172 WebElement element = sibling.to<WebElement>(); |
171 if (element.hasTagName("p")) { | 173 if (element.hasTagName("p") || element.hasTagName("b")) { |
172 inferred_label = FindChildText(element); | 174 inferred_label = FindChildText(element); |
173 } | 175 } |
174 } | 176 } |
175 } | 177 } |
176 | 178 |
177 // Look for text node prior to <img> tag. | 179 // Look for text node prior to <img> or <br> tag. |
178 // Eg. Some Text<img/><input ...> | 180 // Eg. Some Text<img/><input ...> |
| 181 // Eg. Some Text<br/><input ...> |
179 if (inferred_label.empty()) { | 182 if (inferred_label.empty()) { |
180 while (inferred_label.empty() && !previous.isNull()) { | 183 while (inferred_label.empty() && !previous.isNull()) { |
181 if (previous.isTextNode()) { | 184 if (previous.isTextNode()) { |
182 inferred_label = previous.nodeValue(); | 185 inferred_label = previous.nodeValue(); |
183 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); | 186 TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label); |
184 } else if (previous.isElementNode()) { | 187 } else if (previous.isElementNode()) { |
185 WebElement element = previous.to<WebElement>(); | 188 WebElement element = previous.to<WebElement>(); |
186 if (!element.hasTagName("img")) | 189 if (!element.hasTagName("img") && !element.hasTagName("br")) |
187 break; | 190 break; |
188 } else { | 191 } else { |
189 break; | 192 break; |
190 } | 193 } |
191 previous = previous.previousSibling(); | 194 previous = previous.previousSibling(); |
192 } | 195 } |
193 } | 196 } |
194 | 197 |
195 // Look for label node prior to <input> tag. | 198 // Look for label node prior to <input> tag. |
196 // Eg. <label>Some Text</label><input ...> | 199 // Eg. <label>Some Text</label><input ...> |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 data->value.substr(0, input_element->maxLength())); | 966 data->value.substr(0, input_element->maxLength())); |
964 input_element->setAutofilled(true); | 967 input_element->setAutofilled(true); |
965 if (is_initiating_node) { | 968 if (is_initiating_node) { |
966 // Select the part of the text that the user didn't type. | 969 // Select the part of the text that the user didn't type. |
967 input_element->setSelectionRange(input_element->value().length(), | 970 input_element->setSelectionRange(input_element->value().length(), |
968 input_element->suggestedValue().length()); | 971 input_element->suggestedValue().length()); |
969 } | 972 } |
970 } | 973 } |
971 | 974 |
972 } // namespace autofill | 975 } // namespace autofill |
OLD | NEW |