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

Side by Side Diff: chrome/renderer/autofill/form_autofill_util.cc

Issue 11348273: [autofill] Fill in values on a successful run of interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: estade@/isherman@ review Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_autofill_util.h" 5 #include "chrome/renderer/autofill/form_autofill_util.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 466 }
467 467
468 if (!element->isEnabled() || element->isReadOnly() || 468 if (!element->isEnabled() || element->isReadOnly() ||
469 !element->isFocusable()) 469 !element->isFocusable())
470 continue; 470 continue;
471 471
472 callback(element, &data.fields[i], is_initiating_element); 472 callback(element, &data.fields[i], is_initiating_element);
473 } 473 }
474 } 474 }
475 475
476 // Sets the |field|'s value to the value in |data|.
477 // Also sets the "autofilled" attribute, causing the background to be yellow.
478 void FillFormField(WebKit::WebFormControlElement* field,
479 const FormFieldData* data,
480 bool is_initiating_node) {
481 // Nothing to fill.
482 if (data->value.empty())
483 return;
484
485 WebInputElement* input_element = toWebInputElement(field);
486 if (IsTextInput(input_element)) {
487 // If the maxlength attribute contains a negative value, maxLength()
488 // returns the default maxlength value.
489 input_element->setValue(
490 data->value.substr(0, input_element->maxLength()), true);
491 input_element->setAutofilled(true);
492 if (is_initiating_node) {
493 int length = input_element->value().length();
494 input_element->setSelectionRange(length, length);
495 // Clear the current IME composition (the underline), if there is one.
496 input_element->document().frame()->unmarkText();
497 }
498 } else {
499 DCHECK(IsSelectElement(*field));
500 WebSelectElement select_element = field->to<WebSelectElement>();
501 if (select_element.value() != data->value) {
502 select_element.setValue(data->value);
503 select_element.dispatchFormControlChangeEvent();
504 }
505 }
506 }
507
508 // Sets the |field|'s "suggested" (non JS visible) value to the value in |data|. 476 // Sets the |field|'s "suggested" (non JS visible) value to the value in |data|.
509 // Also sets the "autofilled" attribute, causing the background to be yellow. 477 // Also sets the "autofilled" attribute, causing the background to be yellow.
510 void PreviewFormField(WebKit::WebFormControlElement* field, 478 void PreviewFormField(WebKit::WebFormControlElement* field,
511 const FormFieldData* data, 479 const FormFieldData* data,
512 bool is_initiating_node) { 480 bool is_initiating_node) {
513 // Nothing to preview. 481 // Nothing to preview.
514 if (data->value.empty()) 482 if (data->value.empty())
515 return; 483 return;
516 484
517 // Only preview input fields. 485 // Only preview input fields.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 WebFormElement form_element = element.form(); 784 WebFormElement form_element = element.form();
817 if (form_element.isNull()) 785 if (form_element.isNull())
818 return; 786 return;
819 787
820 ForEachMatchingFormField(form_element, 788 ForEachMatchingFormField(form_element,
821 element, 789 element,
822 form, 790 form,
823 &FillFormField); 791 &FillFormField);
824 } 792 }
825 793
794 // Sets the |field|'s value to the value in |data|.
795 // Also sets the "autofilled" attribute, causing the background to be yellow.
796 void FillFormField(WebKit::WebFormControlElement* field,
797 const FormFieldData* data,
798 bool is_initiating_node) {
799 // Nothing to fill.
800 if (data->value.empty())
801 return;
802
803 WebInputElement* input_element = toWebInputElement(field);
804 if (IsTextInput(input_element)) {
805 // If the maxlength attribute contains a negative value, maxLength()
806 // returns the default maxlength value.
807 input_element->setValue(
808 data->value.substr(0, input_element->maxLength()), true);
809 input_element->setAutofilled(true);
810 if (is_initiating_node) {
811 int length = input_element->value().length();
812 input_element->setSelectionRange(length, length);
813 // Clear the current IME composition (the underline), if there is one.
814 input_element->document().frame()->unmarkText();
815 }
816 } else {
817 DCHECK(IsSelectElement(*field));
818 WebSelectElement select_element = field->to<WebSelectElement>();
819 if (select_element.value() != data->value) {
820 select_element.setValue(data->value);
821 select_element.dispatchFormControlChangeEvent();
822 }
823 }
824 }
825
826 void PreviewForm(const FormData& form, const WebInputElement& element) { 826 void PreviewForm(const FormData& form, const WebInputElement& element) {
827 WebFormElement form_element = element.form(); 827 WebFormElement form_element = element.form();
828 if (form_element.isNull()) 828 if (form_element.isNull())
829 return; 829 return;
830 830
831 ForEachMatchingFormField(form_element, 831 ForEachMatchingFormField(form_element,
832 element, 832 element,
833 form, 833 form,
834 &PreviewFormField); 834 &PreviewFormField);
835 } 835 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 continue; 896 continue;
897 897
898 if (input_element->isAutofilled()) 898 if (input_element->isAutofilled())
899 return true; 899 return true;
900 } 900 }
901 901
902 return false; 902 return false;
903 } 903 }
904 904
905 } // namespace autofill 905 } // namespace autofill
OLDNEW
« chrome/renderer/autofill/autofill_agent.cc ('K') | « chrome/renderer/autofill/form_autofill_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698