Chromium Code Reviews| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 | 431 |
| 432 // If we didn't find a label, check for definition list case. | 432 // If we didn't find a label, check for definition list case. |
| 433 inferred_label = InferLabelFromDefinitionList(element); | 433 inferred_label = InferLabelFromDefinitionList(element); |
| 434 if (!inferred_label.empty()) | 434 if (!inferred_label.empty()) |
| 435 return inferred_label; | 435 return inferred_label; |
| 436 | 436 |
| 437 // If we didn't find a label, check for div table case. | 437 // If we didn't find a label, check for div table case. |
| 438 return InferLabelFromDivTable(element); | 438 return InferLabelFromDivTable(element); |
| 439 } | 439 } |
| 440 | 440 |
| 441 WebString GetValue(const WebFormControlElement& element) { | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Please document each new function you add. F
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 442 const WebInputElement* input_element = toWebInputElement(&element); | |
| 443 if (IsAutofillableInputElement(input_element)) { | |
| 444 return input_element->value(); | |
| 445 } else if (IsTextAreaElement(element)) { | |
| 446 const WebTextAreaElement textarea_element = | |
| 447 element.toConst<WebTextAreaElement>(); | |
| 448 return textarea_element.toConst<WebTextAreaElement>().value(); | |
| 449 } else { | |
| 450 DCHECK(IsSelectElement(element)); | |
| 451 const WebSelectElement select_element = | |
| 452 element.toConst<WebSelectElement>(); | |
| 453 return select_element.value(); | |
| 454 } | |
| 455 } | |
|
Ilya Sherman
2014/02/26 00:12:07
You can reformat this method to be briefer and cle
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 456 | |
| 457 WebString GetSuggestedValue(const WebFormControlElement& element) { | |
| 458 const WebInputElement* input_element = toWebInputElement(&element); | |
| 459 if (IsAutofillableInputElement(input_element)) { | |
| 460 return input_element->suggestedValue(); | |
| 461 } else { | |
| 462 DCHECK(IsTextAreaElement(element)); | |
| 463 const WebTextAreaElement textarea_element = | |
| 464 element.toConst<WebTextAreaElement>(); | |
| 465 return textarea_element.suggestedValue(); | |
| 466 } | |
| 467 } | |
|
Ilya Sherman
2014/02/26 00:12:07
Please similarly reformat this method as well as t
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 468 | |
| 469 void SetSelectionRange(WebFormControlElement element, int start, int end) { | |
| 470 WebInputElement* input_element = toWebInputElement(&element); | |
| 471 if (IsAutofillableInputElement(input_element)) { | |
| 472 input_element->setSelectionRange(start, end); | |
| 473 } else if (IsTextAreaElement(element)) { | |
| 474 WebTextAreaElement textarea_element = | |
| 475 element.to<WebTextAreaElement>(); | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: This looks like it fits on a single line. It
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 476 textarea_element.setSelectionRange(start, end); | |
| 477 } | |
| 478 } | |
| 479 | |
| 480 void SetCommonAttributes(const WebFormControlElement& element, | |
| 481 FormFieldData* field) { | |
| 482 const WebInputElement* input_element = toWebInputElement(&element); | |
| 483 if (IsAutofillableInputElement(input_element) || | |
| 484 IsTextAreaElement(element)) { | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Please write this as an early return, i.e.
i
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 485 field->is_autofilled = element.isAutofilled(); | |
| 486 field->is_focusable = element.isFocusable(); | |
| 487 if (IsAutofillableInputElement(input_element)) { | |
| 488 field->should_autocomplete = input_element->autoComplete(); | |
| 489 field->text_direction = input_element->directionForFormData() == | |
| 490 "rtl" ? base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; | |
| 491 } else { | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: DCHECK(IsTextAreaElement(element);
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 492 const WebTextAreaElement textarea_element = | |
| 493 element.toConst<WebTextAreaElement>(); | |
| 494 field->should_autocomplete = textarea_element.autoComplete(); | |
| 495 field->text_direction = textarea_element.directionForFormData() == | |
| 496 "rtl" ? base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; | |
| 497 } | |
| 498 } | |
| 499 } | |
| 500 | |
| 441 // Fills |option_strings| with the values of the <option> elements present in | 501 // Fills |option_strings| with the values of the <option> elements present in |
| 442 // |select_element|. | 502 // |select_element|. |
| 443 void GetOptionStringsFromElement(const WebSelectElement& select_element, | 503 void GetOptionStringsFromElement(const WebSelectElement& select_element, |
| 444 std::vector<base::string16>* option_values, | 504 std::vector<base::string16>* option_values, |
| 445 std::vector<base::string16>* option_contents) { | 505 std::vector<base::string16>* option_contents) { |
| 446 DCHECK(!select_element.isNull()); | 506 DCHECK(!select_element.isNull()); |
| 447 | 507 |
| 448 option_values->clear(); | 508 option_values->clear(); |
| 449 option_contents->clear(); | 509 option_contents->clear(); |
| 450 WebVector<WebElement> list_items = select_element.listItems(); | 510 WebVector<WebElement> list_items = select_element.listItems(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 return; | 592 return; |
| 533 | 593 |
| 534 field->setAutofilled(true); | 594 field->setAutofilled(true); |
| 535 | 595 |
| 536 WebInputElement* input_element = toWebInputElement(field); | 596 WebInputElement* input_element = toWebInputElement(field); |
| 537 if (IsTextInput(input_element) || IsMonthInput(input_element)) { | 597 if (IsTextInput(input_element) || IsMonthInput(input_element)) { |
| 538 // If the maxlength attribute contains a negative value, maxLength() | 598 // If the maxlength attribute contains a negative value, maxLength() |
| 539 // returns the default maxlength value. | 599 // returns the default maxlength value. |
| 540 input_element->setValue( | 600 input_element->setValue( |
| 541 data.value.substr(0, input_element->maxLength()), true); | 601 data.value.substr(0, input_element->maxLength()), true); |
| 542 if (is_initiating_node) { | |
| 543 int length = input_element->value().length(); | |
| 544 input_element->setSelectionRange(length, length); | |
| 545 // Clear the current IME composition (the underline), if there is one. | |
| 546 input_element->document().frame()->unmarkText(); | |
| 547 } | |
| 548 } else if (IsTextAreaElement(*field)) { | 602 } else if (IsTextAreaElement(*field)) { |
| 549 WebTextAreaElement text_area = field->to<WebTextAreaElement>(); | 603 WebTextAreaElement text_area = field->to<WebTextAreaElement>(); |
| 550 if (text_area.value() != data.value) { | 604 if (text_area.value() != data.value) { |
| 551 text_area.setValue(data.value); | 605 text_area.setValue(data.value); |
| 552 text_area.dispatchFormControlChangeEvent(); | 606 text_area.dispatchFormControlChangeEvent(); |
| 553 } | 607 } |
| 554 } else if (IsSelectElement(*field)) { | 608 } else if (IsSelectElement(*field)) { |
| 555 WebSelectElement select_element = field->to<WebSelectElement>(); | 609 WebSelectElement select_element = field->to<WebSelectElement>(); |
| 556 if (select_element.value() != data.value) { | 610 if (select_element.value() != data.value) { |
| 557 select_element.setValue(data.value); | 611 select_element.setValue(data.value); |
| 558 select_element.dispatchFormControlChangeEvent(); | 612 select_element.dispatchFormControlChangeEvent(); |
| 559 } | 613 } |
| 560 } else { | 614 } else { |
| 561 DCHECK(IsCheckableElement(input_element)); | 615 DCHECK(IsCheckableElement(input_element)); |
| 562 input_element->setChecked(data.is_checked, true); | 616 input_element->setChecked(data.is_checked, true); |
| 563 } | 617 } |
| 618 | |
| 619 if (is_initiating_node && | |
| 620 ((input_element && | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: No need to check whether |input_element| is n
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 621 (IsTextInput(input_element) || | |
| 622 IsMonthInput(input_element))) || | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: IMO the code is a bit easier to read if this
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 623 IsTextAreaElement(*field))) { | |
| 624 int length = GetValue(*field).length(); | |
| 625 SetSelectionRange(*field, length, length); | |
| 626 field->document().frame()->unmarkText(); | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Please preserve the comment "// Clear the cur
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 627 } | |
|
Ilya Sherman
2014/02/26 00:12:07
Thanks for factoring out this shared logic -- it's
ziran.sun
2014/02/26 18:11:50
Thanks for helping me with this :).
| |
| 564 } | 628 } |
| 565 | 629 |
| 566 // Sets the |field|'s "suggested" (non JS visible) value to the value in |data|. | 630 // Sets the |field|'s "suggested" (non JS visible) value to the value in |data|. |
| 567 // Also sets the "autofilled" attribute, causing the background to be yellow. | 631 // Also sets the "autofilled" attribute, causing the background to be yellow. |
| 568 void PreviewFormField(const FormFieldData& data, | 632 void PreviewFormField(const FormFieldData& data, |
| 569 bool is_initiating_node, | 633 bool is_initiating_node, |
| 570 blink::WebFormControlElement* field) { | 634 blink::WebFormControlElement* field) { |
| 571 // Nothing to preview. | 635 // Nothing to preview. |
| 572 if (data.value.empty()) | 636 if (data.value.empty()) |
| 573 return; | 637 return; |
| 574 | 638 |
| 575 // Preview input and textarea fields. For input fields, excludes checkboxes | 639 // Preview input and textarea fields. For input fields, excludes checkboxes |
| 576 // and radio buttons, as there is no provision for setSuggestedCheckedValue | 640 // and radio buttons, as there is no provision for setSuggestedCheckedValue |
| 577 // in WebInputElement. | 641 // in WebInputElement. |
| 578 WebInputElement* input_element = toWebInputElement(field); | 642 WebInputElement* input_element = toWebInputElement(field); |
| 579 if (IsTextInput(input_element)) { | 643 if (IsTextInput(input_element)) { |
| 580 // If the maxlength attribute contains a negative value, maxLength() | 644 // If the maxlength attribute contains a negative value, maxLength() |
| 581 // returns the default maxlength value. | 645 // returns the default maxlength value. |
| 582 input_element->setSuggestedValue( | 646 input_element->setSuggestedValue( |
| 583 data.value.substr(0, input_element->maxLength())); | 647 data.value.substr(0, input_element->maxLength())); |
| 584 input_element->setAutofilled(true); | 648 input_element->setAutofilled(true); |
| 585 if (is_initiating_node) { | |
| 586 // Select the part of the text that the user didn't type. | |
| 587 input_element->setSelectionRange( | |
| 588 input_element->value().length(), | |
| 589 input_element->suggestedValue().length()); | |
| 590 } | |
| 591 } else if (IsTextAreaElement(*field)) { | 649 } else if (IsTextAreaElement(*field)) { |
| 592 WebTextAreaElement textarea = field->to<WebTextAreaElement>(); | 650 WebTextAreaElement textarea = field->to<WebTextAreaElement>(); |
| 593 textarea.setSuggestedValue(data.value); | 651 textarea.setSuggestedValue(data.value); |
| 594 field->setAutofilled(true); | 652 field->setAutofilled(true); |
| 595 } | 653 } |
| 654 | |
| 655 if (is_initiating_node && | |
| 656 ((input_element && | |
| 657 IsTextInput(input_element)) || | |
| 658 IsTextAreaElement(*field))) { | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Please format this as:
if (is_initiating_nod
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 659 // Select the part of the text that the user didn't type. | |
| 660 int start = GetValue(*field).length(); | |
| 661 int end = GetSuggestedValue(*field).length(); | |
| 662 SetSelectionRange(*field, start, end); | |
| 663 } | |
| 596 } | 664 } |
| 597 | 665 |
| 598 std::string RetrievalMethodToString( | 666 std::string RetrievalMethodToString( |
| 599 const WebElementDescriptor::RetrievalMethod& method) { | 667 const WebElementDescriptor::RetrievalMethod& method) { |
| 600 switch (method) { | 668 switch (method) { |
| 601 case WebElementDescriptor::CSS_SELECTOR: | 669 case WebElementDescriptor::CSS_SELECTOR: |
| 602 return "CSS_SELECTOR"; | 670 return "CSS_SELECTOR"; |
| 603 case WebElementDescriptor::ID: | 671 case WebElementDescriptor::ID: |
| 604 return "ID"; | 672 return "ID"; |
| 605 case WebElementDescriptor::NONE: | 673 case WebElementDescriptor::NONE: |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 if (field->autocomplete_attribute.size() > kMaxDataLength) { | 832 if (field->autocomplete_attribute.size() > kMaxDataLength) { |
| 765 // Discard overly long attribute values to avoid DOS-ing the browser | 833 // Discard overly long attribute values to avoid DOS-ing the browser |
| 766 // process. However, send over a default string to indicate that the | 834 // process. However, send over a default string to indicate that the |
| 767 // attribute was present. | 835 // attribute was present. |
| 768 field->autocomplete_attribute = "x-max-data-length-exceeded"; | 836 field->autocomplete_attribute = "x-max-data-length-exceeded"; |
| 769 } | 837 } |
| 770 | 838 |
| 771 if (!IsAutofillableElement(element)) | 839 if (!IsAutofillableElement(element)) |
| 772 return; | 840 return; |
| 773 | 841 |
| 842 SetCommonAttributes(element, field); | |
| 843 | |
| 774 const WebInputElement* input_element = toWebInputElement(&element); | 844 const WebInputElement* input_element = toWebInputElement(&element); |
| 775 if (IsAutofillableInputElement(input_element)) { | 845 if (IsAutofillableInputElement(input_element)) { |
| 776 if (IsTextInput(input_element)) | 846 if (IsTextInput(input_element)) |
| 777 field->max_length = input_element->maxLength(); | 847 field->max_length = input_element->maxLength(); |
| 778 | 848 |
| 779 field->is_autofilled = input_element->isAutofilled(); | 849 field->is_checkable = IsCheckableElement(input_element); |
| 780 field->is_focusable = input_element->isFocusable(); | 850 field->is_checked = input_element->isChecked(); |
| 781 field->is_checkable = IsCheckableElement(input_element); | |
| 782 field->is_checked = input_element->isChecked(); | |
| 783 field->should_autocomplete = input_element->autoComplete(); | |
| 784 field->text_direction = input_element->directionForFormData() == "rtl" ? | |
| 785 base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; | |
| 786 } else if (IsTextAreaElement(element)) { | 851 } else if (IsTextAreaElement(element)) { |
| 787 // Nothing more to do in this case. | 852 // Nothing more to do in this case. |
| 788 } else if (extract_mask & EXTRACT_OPTIONS) { | 853 } else if (extract_mask & EXTRACT_OPTIONS) { |
| 789 // Set option strings on the field if available. | 854 // Set option strings on the field if available. |
| 790 DCHECK(IsSelectElement(element)); | 855 DCHECK(IsSelectElement(element)); |
| 791 const WebSelectElement select_element = element.toConst<WebSelectElement>(); | 856 const WebSelectElement select_element = element.toConst<WebSelectElement>(); |
| 792 GetOptionStringsFromElement(select_element, | 857 GetOptionStringsFromElement(select_element, |
| 793 &field->option_values, | 858 &field->option_values, |
| 794 &field->option_contents); | 859 &field->option_contents); |
| 795 } | 860 } |
| 796 | 861 |
| 797 if (!(extract_mask & EXTRACT_VALUE)) | 862 if (!(extract_mask & EXTRACT_VALUE)) |
| 798 return; | 863 return; |
| 799 | 864 |
| 800 base::string16 value; | 865 base::string16 value; |
| 801 if (IsAutofillableInputElement(input_element)) { | 866 value = GetValue(element); |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Please combine these two lines into one, i.e.
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 802 value = input_element->value(); | |
| 803 } else if (IsTextAreaElement(element)) { | |
| 804 value = element.toConst<WebTextAreaElement>().value(); | |
| 805 } else { | |
| 806 DCHECK(IsSelectElement(element)); | |
| 807 const WebSelectElement select_element = element.toConst<WebSelectElement>(); | |
| 808 value = select_element.value(); | |
| 809 | 867 |
| 868 if (IsSelectElement(element)) { | |
| 869 const WebSelectElement select_element = | |
| 870 element.toConst<WebSelectElement>(); | |
|
Ilya Sherman
2014/02/26 00:12:07
nit: This line probably doesn't need to wrap.
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 810 // Convert the |select_element| value to text if requested. | 871 // Convert the |select_element| value to text if requested. |
| 811 if (extract_mask & EXTRACT_OPTION_TEXT) { | 872 if (extract_mask & EXTRACT_OPTION_TEXT) { |
| 812 WebVector<WebElement> list_items = select_element.listItems(); | 873 WebVector<WebElement> list_items = select_element.listItems(); |
| 813 for (size_t i = 0; i < list_items.size(); ++i) { | 874 for (size_t i = 0; i < list_items.size(); ++i) { |
| 814 if (IsOptionElement(list_items[i])) { | 875 if (IsOptionElement(list_items[i])) { |
| 815 const WebOptionElement option_element = | 876 const WebOptionElement option_element = |
| 816 list_items[i].toConst<WebOptionElement>(); | 877 list_items[i].toConst<WebOptionElement>(); |
| 817 if (option_element.value() == value) { | 878 if (option_element.value() == value) { |
| 818 value = option_element.text(); | 879 value = option_element.text(); |
| 819 break; | 880 break; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 | 1025 |
| 965 // Copy the created FormFields into the resulting FormData object. | 1026 // Copy the created FormFields into the resulting FormData object. |
| 966 for (ScopedVector<FormFieldData>::const_iterator iter = form_fields.begin(); | 1027 for (ScopedVector<FormFieldData>::const_iterator iter = form_fields.begin(); |
| 967 iter != form_fields.end(); ++iter) { | 1028 iter != form_fields.end(); ++iter) { |
| 968 form->fields.push_back(**iter); | 1029 form->fields.push_back(**iter); |
| 969 } | 1030 } |
| 970 | 1031 |
| 971 return true; | 1032 return true; |
| 972 } | 1033 } |
| 973 | 1034 |
| 974 bool FindFormAndFieldForInputElement(const WebInputElement& element, | 1035 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, |
| 975 FormData* form, | 1036 FormData* form, |
| 976 FormFieldData* field, | 1037 FormFieldData* field, |
| 977 RequirementsMask requirements) { | 1038 RequirementsMask requirements) { |
| 978 if (!IsAutofillableElement(element)) | 1039 if (!IsAutofillableElement(element)) |
| 979 return false; | 1040 return false; |
| 980 | 1041 |
| 981 const WebFormElement form_element = element.form(); | 1042 const WebFormElement form_element = element.form(); |
| 982 if (form_element.isNull()) | 1043 if (form_element.isNull()) |
| 983 return false; | 1044 return false; |
| 984 | 1045 |
| 985 ExtractMask extract_mask = | 1046 ExtractMask extract_mask = |
| 986 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | 1047 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); |
| 987 return WebFormElementToFormData(form_element, | 1048 return WebFormElementToFormData(form_element, |
| 988 element, | 1049 element, |
| 989 requirements, | 1050 requirements, |
| 990 extract_mask, | 1051 extract_mask, |
| 991 form, | 1052 form, |
| 992 field); | 1053 field); |
| 993 } | 1054 } |
| 994 | 1055 |
| 995 void FillForm(const FormData& form, const WebInputElement& element) { | 1056 void FillForm(const FormData& form, const WebFormControlElement& element) { |
| 996 WebFormElement form_element = element.form(); | 1057 WebFormElement form_element = element.form(); |
| 997 if (form_element.isNull()) | 1058 if (form_element.isNull()) |
| 998 return; | 1059 return; |
| 999 | 1060 |
| 1000 ForEachMatchingFormField(form_element, | 1061 ForEachMatchingFormField(form_element, |
| 1001 element, | 1062 element, |
| 1002 form, | 1063 form, |
| 1003 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1064 FILTER_ALL_NON_EDITIABLE_ELEMENTS, |
| 1004 false, /* dont force override */ | 1065 false, /* dont force override */ |
| 1005 &FillFormField); | 1066 &FillFormField); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1026 return; | 1087 return; |
| 1027 | 1088 |
| 1028 ForEachMatchingFormField(form_element, | 1089 ForEachMatchingFormField(form_element, |
| 1029 WebInputElement(), | 1090 WebInputElement(), |
| 1030 form_data, | 1091 form_data, |
| 1031 FILTER_NONE, | 1092 FILTER_NONE, |
| 1032 true, /* force override */ | 1093 true, /* force override */ |
| 1033 &FillFormField); | 1094 &FillFormField); |
| 1034 } | 1095 } |
| 1035 | 1096 |
| 1036 void PreviewForm(const FormData& form, const WebInputElement& element) { | 1097 void PreviewForm(const FormData& form, const WebFormControlElement& element) { |
| 1037 WebFormElement form_element = element.form(); | 1098 WebFormElement form_element = element.form(); |
| 1038 if (form_element.isNull()) | 1099 if (form_element.isNull()) |
| 1039 return; | 1100 return; |
| 1040 | 1101 |
| 1041 ForEachMatchingFormField(form_element, | 1102 ForEachMatchingFormField(form_element, |
| 1042 element, | 1103 element, |
| 1043 form, | 1104 form, |
| 1044 FILTER_ALL_NON_EDITIABLE_ELEMENTS, | 1105 FILTER_ALL_NON_EDITIABLE_ELEMENTS, |
| 1045 false, /* dont force override */ | 1106 false, /* dont force override */ |
| 1046 &PreviewFormField); | 1107 &PreviewFormField); |
| 1047 } | 1108 } |
| 1048 | 1109 |
| 1049 bool ClearPreviewedFormWithElement(const WebInputElement& element, | 1110 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
| 1050 bool was_autofilled) { | 1111 bool was_autofilled) { |
| 1051 WebFormElement form_element = element.form(); | 1112 WebFormElement form_element = element.form(); |
| 1052 if (form_element.isNull()) | 1113 if (form_element.isNull()) |
| 1053 return false; | 1114 return false; |
| 1054 | 1115 |
| 1055 std::vector<WebFormControlElement> control_elements; | 1116 std::vector<WebFormControlElement> control_elements; |
| 1056 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, | 1117 ExtractAutofillableElements(form_element, REQUIRE_AUTOCOMPLETE, |
| 1057 &control_elements); | 1118 &control_elements); |
| 1058 for (size_t i = 0; i < control_elements.size(); ++i) { | 1119 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 1059 // There might be unrelated elements in this form which have already been | 1120 // There might be unrelated elements in this form which have already been |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1085 bool is_initiating_node = (element == *input_element); | 1146 bool is_initiating_node = (element == *input_element); |
| 1086 if (is_initiating_node) | 1147 if (is_initiating_node) |
| 1087 input_element->setAutofilled(was_autofilled); | 1148 input_element->setAutofilled(was_autofilled); |
| 1088 else | 1149 else |
| 1089 input_element->setAutofilled(false); | 1150 input_element->setAutofilled(false); |
| 1090 | 1151 |
| 1091 // Clearing the suggested value in the focused node (above) can cause | 1152 // Clearing the suggested value in the focused node (above) can cause |
| 1092 // selection to be lost. We force selection range to restore the text | 1153 // selection to be lost. We force selection range to restore the text |
| 1093 // cursor. | 1154 // cursor. |
| 1094 if (is_initiating_node) { | 1155 if (is_initiating_node) { |
| 1095 int length = input_element->value().length(); | 1156 int length = GetValue(*input_element).length(); |
| 1096 input_element->setSelectionRange(length, length); | 1157 SetSelectionRange(*input_element, length, length); |
| 1097 } | 1158 } |
|
Ilya Sherman
2014/02/26 00:12:07
Please move this code as well as the comment outsi
ziran.sun
2014/02/26 18:11:50
Done.
| |
| 1098 } else if (IsTextAreaElement(control_element)) { | 1159 } else if (IsTextAreaElement(control_element)) { |
| 1099 WebTextAreaElement text_area = control_element.to<WebTextAreaElement>(); | 1160 WebTextAreaElement text_area = control_element.to<WebTextAreaElement>(); |
| 1100 text_area.setSuggestedValue(WebString()); | 1161 text_area.setSuggestedValue(WebString()); |
| 1101 bool is_initiating_node = (element == text_area); | 1162 bool is_initiating_node = (element == text_area); |
| 1102 if (is_initiating_node) | 1163 if (is_initiating_node) |
| 1103 control_element.setAutofilled(was_autofilled); | 1164 control_element.setAutofilled(was_autofilled); |
| 1104 else | 1165 else |
| 1105 control_element.setAutofilled(false); | 1166 control_element.setAutofilled(false); |
| 1167 | |
| 1168 if (is_initiating_node) { | |
| 1169 int length = GetValue(control_element).length(); | |
| 1170 SetSelectionRange(control_element, length, length); | |
| 1171 } | |
| 1106 } | 1172 } |
| 1107 } | 1173 } |
| 1108 | 1174 |
| 1109 return true; | 1175 return true; |
| 1110 } | 1176 } |
| 1111 | 1177 |
| 1112 bool FormWithElementIsAutofilled(const WebInputElement& element) { | 1178 bool FormWithElementIsAutofilled(const WebInputElement& element) { |
| 1113 WebFormElement form_element = element.form(); | 1179 WebFormElement form_element = element.form(); |
| 1114 if (form_element.isNull()) | 1180 if (form_element.isNull()) |
| 1115 return false; | 1181 return false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 tag_is_allowed = true; | 1238 tag_is_allowed = true; |
| 1173 break; | 1239 break; |
| 1174 } | 1240 } |
| 1175 } | 1241 } |
| 1176 if (!tag_is_allowed) | 1242 if (!tag_is_allowed) |
| 1177 return false; | 1243 return false; |
| 1178 } | 1244 } |
| 1179 return true; | 1245 return true; |
| 1180 } | 1246 } |
| 1181 | 1247 |
| 1182 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { | 1248 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
| 1183 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1249 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1184 return gfx::RectF(bounding_box.x() * scale, | 1250 return gfx::RectF(bounding_box.x() * scale, |
| 1185 bounding_box.y() * scale, | 1251 bounding_box.y() * scale, |
| 1186 bounding_box.width() * scale, | 1252 bounding_box.width() * scale, |
| 1187 bounding_box.height() * scale); | 1253 bounding_box.height() * scale); |
| 1188 } | 1254 } |
| 1189 | 1255 |
| 1190 } // namespace autofill | 1256 } // namespace autofill |
| OLD | NEW |