| 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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 | 1038 |
| 1039 ForEachMatchingFormField(form_element, | 1039 ForEachMatchingFormField(form_element, |
| 1040 element, | 1040 element, |
| 1041 form, | 1041 form, |
| 1042 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1042 FILTER_ALL_NON_EDITIABLE_ELEMENTS, |
| 1043 false, /* dont force override */ | 1043 false, /* dont force override */ |
| 1044 &PreviewFormField); | 1044 &PreviewFormField); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, | 1047 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
| 1048 bool was_autofilled) { | 1048 bool was_autofilled, |
| 1049 bool was_password_autofilled) { |
| 1049 WebFormElement form_element = element.form(); | 1050 WebFormElement form_element = element.form(); |
| 1050 if (form_element.isNull()) | 1051 if (form_element.isNull()) |
| 1051 return false; | 1052 return false; |
| 1052 | 1053 |
| 1053 std::vector<WebFormControlElement> control_elements; | 1054 std::vector<WebFormControlElement> control_elements; |
| 1054 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1055 ExtractAutofillableElements(form_element, REQUIRE_NONE, &control_elements); |
| 1055 &control_elements); | |
| 1056 for (size_t i = 0; i < control_elements.size(); ++i) { | 1056 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 1057 // There might be unrelated elements in this form which have already been | 1057 // There might be unrelated elements in this form which have already been |
| 1058 // auto-filled. For example, the user might have already filled the address | 1058 // auto-filled. For example, the user might have already filled the address |
| 1059 // part of a form and now be dealing with the credit card section. We only | 1059 // part of a form and now be dealing with the credit card section. We only |
| 1060 // want to reset the auto-filled status for fields that were previewed. | 1060 // want to reset the auto-filled status for fields that were previewed. |
| 1061 WebFormControlElement control_element = control_elements[i]; | 1061 WebFormControlElement control_element = control_elements[i]; |
| 1062 | 1062 |
| 1063 // Only text input, textarea and select elements can be previewed. | 1063 // Only text input, textarea and select elements can be previewed. |
| 1064 WebInputElement* input_element = toWebInputElement(&control_element); | 1064 WebInputElement* input_element = toWebInputElement(&control_element); |
| 1065 if (!IsTextInput(input_element) && | 1065 if (!IsTextInput(input_element) && |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1086 IsTextAreaElement(control_element)) { | 1086 IsTextAreaElement(control_element)) { |
| 1087 control_element.setSuggestedValue(WebString()); | 1087 control_element.setSuggestedValue(WebString()); |
| 1088 bool is_initiating_node = (element == control_element); | 1088 bool is_initiating_node = (element == control_element); |
| 1089 if (is_initiating_node) { | 1089 if (is_initiating_node) { |
| 1090 control_element.setAutofilled(was_autofilled); | 1090 control_element.setAutofilled(was_autofilled); |
| 1091 // Clearing the suggested value in the focused node (above) can cause | 1091 // Clearing the suggested value in the focused node (above) can cause |
| 1092 // selection to be lost. We force selection range to restore the text | 1092 // selection to be lost. We force selection range to restore the text |
| 1093 // cursor. | 1093 // cursor. |
| 1094 int length = control_element.value().length(); | 1094 int length = control_element.value().length(); |
| 1095 control_element.setSelectionRange(length, length); | 1095 control_element.setSelectionRange(length, length); |
| 1096 } else if (input_element->isPasswordField()) { |
| 1097 input_element->setAutofilled(was_password_autofilled); |
| 1096 } else { | 1098 } else { |
| 1097 control_element.setAutofilled(false); | 1099 control_element.setAutofilled(false); |
| 1098 } | 1100 } |
| 1099 } else if (IsSelectElement(control_element)) { | 1101 } else if (IsSelectElement(control_element)) { |
| 1100 control_element.setSuggestedValue(WebString()); | 1102 control_element.setSuggestedValue(WebString()); |
| 1101 control_element.setAutofilled(false); | 1103 control_element.setAutofilled(false); |
| 1102 } | 1104 } |
| 1103 } | 1105 } |
| 1104 | 1106 |
| 1105 return true; | 1107 return true; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 | 1180 |
| 1179 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { | 1181 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
| 1180 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1182 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1181 return gfx::RectF(bounding_box.x() * scale, | 1183 return gfx::RectF(bounding_box.x() * scale, |
| 1182 bounding_box.y() * scale, | 1184 bounding_box.y() * scale, |
| 1183 bounding_box.width() * scale, | 1185 bounding_box.width() * scale, |
| 1184 bounding_box.height() * scale); | 1186 bounding_box.height() * scale); |
| 1185 } | 1187 } |
| 1186 | 1188 |
| 1187 } // namespace autofill | 1189 } // namespace autofill |
| OLD | NEW |