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_cache.h" | 5 #include "components/autofill/content/renderer/form_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/autofill/content/renderer/form_autofill_util.h" | 9 #include "components/autofill/content/renderer/form_autofill_util.h" |
10 #include "components/autofill/core/common/autofill_constants.h" | 10 #include "components/autofill/core/common/autofill_constants.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 if (IsTextInput(input_element) || IsMonthInput(input_element)) { | 199 if (IsTextInput(input_element) || IsMonthInput(input_element)) { |
200 input_element->setValue(base::string16(), true); | 200 input_element->setValue(base::string16(), true); |
201 | 201 |
202 // Clearing the value in the focused node (above) can cause selection | 202 // Clearing the value in the focused node (above) can cause selection |
203 // to be lost. We force selection range to restore the text cursor. | 203 // to be lost. We force selection range to restore the text cursor. |
204 if (element == *input_element) { | 204 if (element == *input_element) { |
205 int length = input_element->value().length(); | 205 int length = input_element->value().length(); |
206 input_element->setSelectionRange(length, length); | 206 input_element->setSelectionRange(length, length); |
207 } | 207 } |
208 } else if (IsTextAreaElement(control_element)) { | 208 } else if (IsTextAreaElement(control_element)) { |
209 WebTextAreaElement text_area = control_element.to<WebTextAreaElement>(); | 209 control_element.setValue(base::string16(), true); |
210 text_area.setValue(base::string16()); | |
211 text_area.dispatchFormControlChangeEvent(); | |
212 } else if (IsSelectElement(control_element)) { | 210 } else if (IsSelectElement(control_element)) { |
213 WebSelectElement select_element = control_element.to<WebSelectElement>(); | 211 WebSelectElement select_element = control_element.to<WebSelectElement>(); |
214 | 212 |
215 std::map<const WebSelectElement, base::string16>::const_iterator | 213 std::map<const WebSelectElement, base::string16>::const_iterator |
216 initial_value_iter = initial_select_values_.find(select_element); | 214 initial_value_iter = initial_select_values_.find(select_element); |
217 if (initial_value_iter != initial_select_values_.end() && | 215 if (initial_value_iter != initial_select_values_.end() && |
218 select_element.value() != initial_value_iter->second) { | 216 select_element.value() != initial_value_iter->second) { |
219 select_element.setValue(initial_value_iter->second); | 217 select_element.setValue(initial_value_iter->second, true); |
220 select_element.dispatchFormControlChangeEvent(); | |
221 } | 218 } |
222 } else { | 219 } else { |
223 WebInputElement input_element = control_element.to<WebInputElement>(); | 220 WebInputElement input_element = control_element.to<WebInputElement>(); |
224 DCHECK(IsCheckableElement(&input_element)); | 221 DCHECK(IsCheckableElement(&input_element)); |
225 std::map<const WebInputElement, bool>::const_iterator it = | 222 std::map<const WebInputElement, bool>::const_iterator it = |
226 initial_checked_state_.find(input_element); | 223 initial_checked_state_.find(input_element); |
227 if (it != initial_checked_state_.end() && | 224 if (it != initial_checked_state_.end() && |
228 input_element.isChecked() != it->second) { | 225 input_element.isChecked() != it->second) { |
229 input_element.setChecked(it->second, true); | 226 input_element.setChecked(it->second, true); |
230 } | 227 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 element->setAttribute("placeholder", | 296 element->setAttribute("placeholder", |
300 WebString(base::UTF8ToUTF16(placeholder))); | 297 WebString(base::UTF8ToUTF16(placeholder))); |
301 } | 298 } |
302 element->setAttribute("title", WebString(title)); | 299 element->setAttribute("title", WebString(title)); |
303 } | 300 } |
304 | 301 |
305 return true; | 302 return true; |
306 } | 303 } |
307 | 304 |
308 } // namespace autofill | 305 } // namespace autofill |
OLD | NEW |