Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 632
633 } // namespace 633 } // namespace
634 634
635 const size_t kMaxParseableFields = 200; 635 const size_t kMaxParseableFields = 200;
636 636
637 bool IsMonthInput(const WebInputElement* element) { 637 bool IsMonthInput(const WebInputElement* element) {
638 CR_DEFINE_STATIC_LOCAL(WebString, kMonth, ("month")); 638 CR_DEFINE_STATIC_LOCAL(WebString, kMonth, ("month"));
639 return element && element->formControlType() == kMonth; 639 return element && element->formControlType() == kMonth;
640 } 640 }
641 641
642 bool IsPasswordInput(const WebInputElement* element) {
643 CR_DEFINE_STATIC_LOCAL(WebString, kPassword, ("password"));
644 return element && element->formControlType() == kPassword;
Ilya Sherman 2014/03/21 22:35:19 There is already an "element.isPasswordField()" me
ziran.sun 2014/03/25 18:25:26 Done.
645 }
646
642 // All text fields, including password fields, should be extracted. 647 // All text fields, including password fields, should be extracted.
643 bool IsTextInput(const WebInputElement* element) { 648 bool IsTextInput(const WebInputElement* element) {
644 return element && element->isTextField(); 649 return element && element->isTextField();
645 } 650 }
646 651
647 bool IsSelectElement(const WebFormControlElement& element) { 652 bool IsSelectElement(const WebFormControlElement& element) {
648 // Static for improved performance. 653 // Static for improved performance.
649 CR_DEFINE_STATIC_LOCAL(WebString, kSelectOne, ("select-one")); 654 CR_DEFINE_STATIC_LOCAL(WebString, kSelectOne, ("select-one"));
650 return element.formControlType() == kSelectOne; 655 return element.formControlType() == kSelectOne;
651 } 656 }
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1045
1041 ForEachMatchingFormField(form_element, 1046 ForEachMatchingFormField(form_element,
1042 element, 1047 element,
1043 form, 1048 form,
1044 FILTER_ALL_NON_EDITIABLE_ELEMENTS, 1049 FILTER_ALL_NON_EDITIABLE_ELEMENTS,
1045 false, /* dont force override */ 1050 false, /* dont force override */
1046 &PreviewFormField); 1051 &PreviewFormField);
1047 } 1052 }
1048 1053
1049 bool ClearPreviewedFormWithElement(const WebInputElement& element, 1054 bool ClearPreviewedFormWithElement(const WebInputElement& element,
1050 bool was_autofilled) { 1055 RequirementsMask requirements,
1056 bool was_autofilled,
1057 bool was_password_autofilled) {
1051 WebFormElement form_element = element.form(); 1058 WebFormElement form_element = element.form();
1052 if (form_element.isNull()) 1059 if (form_element.isNull())
1053 return false; 1060 return false;
1054 1061
1055 std::vector<WebFormControlElement> control_elements; 1062 std::vector<WebFormControlElement> control_elements;
1056 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, 1063 ExtractAutofillableElements(form_element, requirements, &control_elements);
Ilya Sherman 2014/03/21 22:35:19 Hmm, would anything go wrong if we were to just al
ziran.sun 2014/03/25 18:25:26 I feel that it might be safe to use REQUIRE_NONE h
Ilya Sherman 2014/03/25 19:45:27 I think since neither of us sees any reason not to
1057 &control_elements);
1058 for (size_t i = 0; i < control_elements.size(); ++i) { 1064 for (size_t i = 0; i < control_elements.size(); ++i) {
1059 // There might be unrelated elements in this form which have already been 1065 // There might be unrelated elements in this form which have already been
1060 // auto-filled. For example, the user might have already filled the address 1066 // auto-filled. For example, the user might have already filled the address
1061 // part of a form and now be dealing with the credit card section. We only 1067 // part of a form and now be dealing with the credit card section. We only
1062 // want to reset the auto-filled status for fields that were previewed. 1068 // want to reset the auto-filled status for fields that were previewed.
1063 WebFormControlElement control_element = control_elements[i]; 1069 WebFormControlElement control_element = control_elements[i];
1064 1070
1065 // Only text input and textarea elements can be previewed. 1071 // Only text input and textarea elements can be previewed.
1066 WebInputElement* input_element = toWebInputElement(&control_element); 1072 WebInputElement* input_element = toWebInputElement(&control_element);
1067 if (!IsTextInput(input_element) && 1073 if (!IsTextInput(input_element) &&
(...skipping 14 matching lines...) Expand all
1082 control_element.to<WebTextAreaElement>().suggestedValue().isEmpty())) 1088 control_element.to<WebTextAreaElement>().suggestedValue().isEmpty()))
1083 continue; 1089 continue;
1084 1090
1085 // Clear the suggested value. For the initiating node, also restore the 1091 // Clear the suggested value. For the initiating node, also restore the
1086 // original value. 1092 // original value.
1087 if (IsTextInput(input_element) || IsMonthInput(input_element)) { 1093 if (IsTextInput(input_element) || IsMonthInput(input_element)) {
1088 input_element->setSuggestedValue(WebString()); 1094 input_element->setSuggestedValue(WebString());
1089 bool is_initiating_node = (element == *input_element); 1095 bool is_initiating_node = (element == *input_element);
1090 if (is_initiating_node) 1096 if (is_initiating_node)
1091 input_element->setAutofilled(was_autofilled); 1097 input_element->setAutofilled(was_autofilled);
1098 else if (IsPasswordInput(input_element))
1099 input_element->setAutofilled(was_password_autofilled);
1092 else 1100 else
1093 input_element->setAutofilled(false); 1101 input_element->setAutofilled(false);
1094 1102
1095 // Clearing the suggested value in the focused node (above) can cause 1103 // Clearing the suggested value in the focused node (above) can cause
1096 // selection to be lost. We force selection range to restore the text 1104 // selection to be lost. We force selection range to restore the text
1097 // cursor. 1105 // cursor.
1098 if (is_initiating_node) { 1106 if (is_initiating_node) {
1099 int length = input_element->value().length(); 1107 int length = input_element->value().length();
1100 input_element->setSelectionRange(length, length); 1108 input_element->setSelectionRange(length, length);
1101 } 1109 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 1194
1187 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { 1195 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) {
1188 gfx::Rect bounding_box(element->boundsInViewportSpace()); 1196 gfx::Rect bounding_box(element->boundsInViewportSpace());
1189 return gfx::RectF(bounding_box.x() * scale, 1197 return gfx::RectF(bounding_box.x() * scale,
1190 bounding_box.y() * scale, 1198 bounding_box.y() * scale,
1191 bounding_box.width() * scale, 1199 bounding_box.width() * scale,
1192 bounding_box.height() * scale); 1200 bounding_box.height() * scale);
1193 } 1201 }
1194 1202
1195 } // namespace autofill 1203 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698