| 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 int length = input_element->value().length(); | 543 int length = input_element->value().length(); |
| 544 input_element->setSelectionRange(length, length); | 544 input_element->setSelectionRange(length, length); |
| 545 // Clear the current IME composition (the underline), if there is one. | 545 // Clear the current IME composition (the underline), if there is one. |
| 546 input_element->document().frame()->unmarkText(); | 546 input_element->document().frame()->unmarkText(); |
| 547 } | 547 } |
| 548 } else if (IsTextAreaElement(*field)) { | 548 } else if (IsTextAreaElement(*field)) { |
| 549 WebTextAreaElement text_area = field->to<WebTextAreaElement>(); | 549 WebTextAreaElement text_area = field->to<WebTextAreaElement>(); |
| 550 if (text_area.value() != data.value) { | 550 if (text_area.value() != data.value) { |
| 551 text_area.setValue(data.value); | 551 text_area.setValue(data.value); |
| 552 text_area.dispatchFormControlChangeEvent(); | 552 text_area.dispatchFormControlChangeEvent(); |
| 553 if (is_initiating_node) { |
| 554 int length = text_area.value().length(); |
| 555 text_area.setSelectionRange(length, length); |
| 556 // Clear the current IME composition (the underline), if there is one. |
| 557 text_area.document().frame()->unmarkText(); |
| 558 } |
| 553 } | 559 } |
| 554 } else if (IsSelectElement(*field)) { | 560 } else if (IsSelectElement(*field)) { |
| 555 WebSelectElement select_element = field->to<WebSelectElement>(); | 561 WebSelectElement select_element = field->to<WebSelectElement>(); |
| 556 if (select_element.value() != data.value) { | 562 if (select_element.value() != data.value) { |
| 557 select_element.setValue(data.value); | 563 select_element.setValue(data.value); |
| 558 select_element.dispatchFormControlChangeEvent(); | 564 select_element.dispatchFormControlChangeEvent(); |
| 559 } | 565 } |
| 560 } else { | 566 } else { |
| 561 DCHECK(IsCheckableElement(input_element)); | 567 DCHECK(IsCheckableElement(input_element)); |
| 562 input_element->setChecked(data.is_checked, true); | 568 input_element->setChecked(data.is_checked, true); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 585 if (is_initiating_node) { | 591 if (is_initiating_node) { |
| 586 // Select the part of the text that the user didn't type. | 592 // Select the part of the text that the user didn't type. |
| 587 input_element->setSelectionRange( | 593 input_element->setSelectionRange( |
| 588 input_element->value().length(), | 594 input_element->value().length(), |
| 589 input_element->suggestedValue().length()); | 595 input_element->suggestedValue().length()); |
| 590 } | 596 } |
| 591 } else if (IsTextAreaElement(*field)) { | 597 } else if (IsTextAreaElement(*field)) { |
| 592 WebTextAreaElement textarea = field->to<WebTextAreaElement>(); | 598 WebTextAreaElement textarea = field->to<WebTextAreaElement>(); |
| 593 textarea.setSuggestedValue(data.value); | 599 textarea.setSuggestedValue(data.value); |
| 594 field->setAutofilled(true); | 600 field->setAutofilled(true); |
| 601 if (is_initiating_node) { |
| 602 // Select the part of the text that the user didn't type. |
| 603 textarea.setSelectionRange( |
| 604 textarea.value().length(), |
| 605 textarea.suggestedValue().length()); |
| 606 } |
| 595 } | 607 } |
| 596 } | 608 } |
| 597 | 609 |
| 598 std::string RetrievalMethodToString( | 610 std::string RetrievalMethodToString( |
| 599 const WebElementDescriptor::RetrievalMethod& method) { | 611 const WebElementDescriptor::RetrievalMethod& method) { |
| 600 switch (method) { | 612 switch (method) { |
| 601 case WebElementDescriptor::CSS_SELECTOR: | 613 case WebElementDescriptor::CSS_SELECTOR: |
| 602 return "CSS_SELECTOR"; | 614 return "CSS_SELECTOR"; |
| 603 case WebElementDescriptor::ID: | 615 case WebElementDescriptor::ID: |
| 604 return "ID"; | 616 return "ID"; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 790 |
| 779 field->is_autofilled = input_element->isAutofilled(); | 791 field->is_autofilled = input_element->isAutofilled(); |
| 780 field->is_focusable = input_element->isFocusable(); | 792 field->is_focusable = input_element->isFocusable(); |
| 781 field->is_checkable = IsCheckableElement(input_element); | 793 field->is_checkable = IsCheckableElement(input_element); |
| 782 field->is_checked = input_element->isChecked(); | 794 field->is_checked = input_element->isChecked(); |
| 783 field->should_autocomplete = input_element->autoComplete(); | 795 field->should_autocomplete = input_element->autoComplete(); |
| 784 field->text_direction = input_element->directionForFormData() == "rtl" ? | 796 field->text_direction = input_element->directionForFormData() == "rtl" ? |
| 785 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; | 797 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; |
| 786 } else if (IsTextAreaElement(element)) { | 798 } else if (IsTextAreaElement(element)) { |
| 787 // Nothing more to do in this case. | 799 // Nothing more to do in this case. |
| 800 field->is_autofilled = element.isAutofilled(); |
| 801 field->is_focusable = element.isFocusable(); |
| 788 } else if (extract_mask & EXTRACT_OPTIONS) { | 802 } else if (extract_mask & EXTRACT_OPTIONS) { |
| 789 // Set option strings on the field if available. | 803 // Set option strings on the field if available. |
| 790 DCHECK(IsSelectElement(element)); | 804 DCHECK(IsSelectElement(element)); |
| 791 const WebSelectElement select_element = element.toConst<WebSelectElement>(); | 805 const WebSelectElement select_element = element.toConst<WebSelectElement>(); |
| 792 GetOptionStringsFromElement(select_element, | 806 GetOptionStringsFromElement(select_element, |
| 793 &field->option_values, | 807 &field->option_values, |
| 794 &field->option_contents); | 808 &field->option_contents); |
| 795 } | 809 } |
| 796 | 810 |
| 797 if (!(extract_mask & EXTRACT_VALUE)) | 811 if (!(extract_mask & EXTRACT_VALUE)) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 | 978 |
| 965 // Copy the created FormFields into the resulting FormData object. | 979 // Copy the created FormFields into the resulting FormData object. |
| 966 for (ScopedVector<FormFieldData>::const_iterator iter = form_fields.begin(); | 980 for (ScopedVector<FormFieldData>::const_iterator iter = form_fields.begin(); |
| 967 iter != form_fields.end(); ++iter) { | 981 iter != form_fields.end(); ++iter) { |
| 968 form->fields.push_back(**iter); | 982 form->fields.push_back(**iter); |
| 969 } | 983 } |
| 970 | 984 |
| 971 return true; | 985 return true; |
| 972 } | 986 } |
| 973 | 987 |
| 974 bool FindFormAndFieldForInputElement(const WebInputElement& element, | 988 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, |
| 975 FormData* form, | 989 FormData* form, |
| 976 FormFieldData* field, | 990 FormFieldData* field, |
| 977 RequirementsMask requirements) { | 991 RequirementsMask requirements) { |
| 978 if (!IsAutofillableElement(element)) | 992 if (!IsAutofillableElement(element)) |
| 979 return false; | 993 return false; |
| 980 | 994 |
| 981 const WebFormElement form_element = element.form(); | 995 const WebFormElement form_element = element.form(); |
| 982 if (form_element.isNull()) | 996 if (form_element.isNull()) |
| 983 return false; | 997 return false; |
| 984 | 998 |
| 985 ExtractMask extract_mask = | 999 ExtractMask extract_mask = |
| 986 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | 1000 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); |
| 987 return WebFormElementToFormData(form_element, | 1001 return WebFormElementToFormData(form_element, |
| 988 element, | 1002 element, |
| 989 requirements, | 1003 requirements, |
| 990 extract_mask, | 1004 extract_mask, |
| 991 form, | 1005 form, |
| 992 field); | 1006 field); |
| 993 } | 1007 } |
| 994 | 1008 |
| 995 void FillForm(const FormData& form, const WebInputElement& element) { | 1009 void FillForm(const FormData& form, const WebFormControlElement& element) { |
| 996 WebFormElement form_element = element.form(); | 1010 WebFormElement form_element = element.form(); |
| 997 if (form_element.isNull()) | 1011 if (form_element.isNull()) |
| 998 return; | 1012 return; |
| 999 | 1013 |
| 1000 ForEachMatchingFormField(form_element, | 1014 ForEachMatchingFormField(form_element, |
| 1001 element, | 1015 element, |
| 1002 form, | 1016 form, |
| 1003 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1017 FILTER_ALL_NON_EDITIABLE_ELEMENTS, |
| 1004 false, /* dont force override */ | 1018 false, /* dont force override */ |
| 1005 &FillFormField); | 1019 &FillFormField); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1026 return; | 1040 return; |
| 1027 | 1041 |
| 1028 ForEachMatchingFormField(form_element, | 1042 ForEachMatchingFormField(form_element, |
| 1029 WebInputElement(), | 1043 WebInputElement(), |
| 1030 form_data, | 1044 form_data, |
| 1031 FILTER_NONE, | 1045 FILTER_NONE, |
| 1032 true, /* force override */ | 1046 true, /* force override */ |
| 1033 &FillFormField); | 1047 &FillFormField); |
| 1034 } | 1048 } |
| 1035 | 1049 |
| 1036 void PreviewForm(const FormData& form, const WebInputElement& element) { | 1050 void PreviewForm(const FormData& form, const WebFormControlElement& element) { |
| 1037 WebFormElement form_element = element.form(); | 1051 WebFormElement form_element = element.form(); |
| 1038 if (form_element.isNull()) | 1052 if (form_element.isNull()) |
| 1039 return; | 1053 return; |
| 1040 | 1054 |
| 1041 ForEachMatchingFormField(form_element, | 1055 ForEachMatchingFormField(form_element, |
| 1042 element, | 1056 element, |
| 1043 form, | 1057 form, |
| 1044 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1058 FILTER_ALL_NON_EDITIABLE_ELEMENTS, |
| 1045 false, /* dont force override */ | 1059 false, /* dont force override */ |
| 1046 &PreviewFormField); | 1060 &PreviewFormField); |
| 1047 } | 1061 } |
| 1048 | 1062 |
| 1049 bool ClearPreviewedFormWithElement(const WebInputElement& element, | 1063 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
| 1050 bool was_autofilled) { | 1064 bool was_autofilled) { |
| 1051 WebFormElement form_element = element.form(); | 1065 WebFormElement form_element = element.form(); |
| 1052 if (form_element.isNull()) | 1066 if (form_element.isNull()) |
| 1053 return false; | 1067 return false; |
| 1054 | 1068 |
| 1055 std::vector<WebFormControlElement> control_elements; | 1069 std::vector<WebFormControlElement> control_elements; |
| 1056 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1070 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, |
| 1057 &control_elements); | 1071 &control_elements); |
| 1058 for (size_t i = 0; i < control_elements.size(); ++i) { | 1072 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 1059 // There might be unrelated elements in this form which have already been | 1073 // There might be unrelated elements in this form which have already been |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 input_element->setSelectionRange(length, length); | 1110 input_element->setSelectionRange(length, length); |
| 1097 } | 1111 } |
| 1098 } else if (IsTextAreaElement(control_element)) { | 1112 } else if (IsTextAreaElement(control_element)) { |
| 1099 WebTextAreaElement text_area = control_element.to<WebTextAreaElement>(); | 1113 WebTextAreaElement text_area = control_element.to<WebTextAreaElement>(); |
| 1100 text_area.setSuggestedValue(WebString()); | 1114 text_area.setSuggestedValue(WebString()); |
| 1101 bool is_initiating_node = (element == text_area); | 1115 bool is_initiating_node = (element == text_area); |
| 1102 if (is_initiating_node) | 1116 if (is_initiating_node) |
| 1103 control_element.setAutofilled(was_autofilled); | 1117 control_element.setAutofilled(was_autofilled); |
| 1104 else | 1118 else |
| 1105 control_element.setAutofilled(false); | 1119 control_element.setAutofilled(false); |
| 1120 if (is_initiating_node) { |
| 1121 int length = text_area.value().length(); |
| 1122 text_area.setSelectionRange(length, length); |
| 1123 } |
| 1106 } | 1124 } |
| 1107 } | 1125 } |
| 1108 | 1126 |
| 1109 return true; | 1127 return true; |
| 1110 } | 1128 } |
| 1111 | 1129 |
| 1112 bool FormWithElementIsAutofilled(const WebInputElement& element) { | 1130 bool FormWithElementIsAutofilled(const WebInputElement& element) { |
| 1113 WebFormElement form_element = element.form(); | 1131 WebFormElement form_element = element.form(); |
| 1114 if (form_element.isNull()) | 1132 if (form_element.isNull()) |
| 1115 return false; | 1133 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 tag_is_allowed = true; | 1190 tag_is_allowed = true; |
| 1173 break; | 1191 break; |
| 1174 } | 1192 } |
| 1175 } | 1193 } |
| 1176 if (!tag_is_allowed) | 1194 if (!tag_is_allowed) |
| 1177 return false; | 1195 return false; |
| 1178 } | 1196 } |
| 1179 return true; | 1197 return true; |
| 1180 } | 1198 } |
| 1181 | 1199 |
| 1182 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { | 1200 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
| 1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1201 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1184 return gfx::RectF(bounding_box.x() * scale, | 1202 return gfx::RectF(bounding_box.x() * scale, |
| 1185 bounding_box.y() * scale, | 1203 bounding_box.y() * scale, |
| 1186 bounding_box.width() * scale, | 1204 bounding_box.width() * scale, |
| 1187 bounding_box.height() * scale); | 1205 bounding_box.height() * scale); |
| 1188 } | 1206 } |
| 1189 | 1207 |
| 1190 } // namespace autofill | 1208 } // namespace autofill |
| OLD | NEW |