| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // The Mac interface forwards most of these commands to the application layer, | 5 // The Mac interface forwards most of these commands to the application layer, |
| 6 // and I'm not really sure what to do about most of them. | 6 // and I'm not really sure what to do about most of them. |
| 7 | 7 |
| 8 #include "config.h" | 8 #include "config.h" |
| 9 | 9 |
| 10 #include "Document.h" | 10 #include "Document.h" |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 if (!input_element) | 664 if (!input_element) |
| 665 return; | 665 return; |
| 666 | 666 |
| 667 WebFrameImpl* webframe = | 667 WebFrameImpl* webframe = |
| 668 WebFrameImpl::FromFrame(input_element->document()->frame()); | 668 WebFrameImpl::FromFrame(input_element->document()->frame()); |
| 669 webkit_glue::PasswordAutocompleteListener* listener = | 669 webkit_glue::PasswordAutocompleteListener* listener = |
| 670 webframe->GetPasswordListener(input_element); | 670 webframe->GetPasswordListener(input_element); |
| 671 if (!listener) | 671 if (!listener) |
| 672 return; | 672 return; |
| 673 | 673 |
| 674 std::wstring value = | 674 string16 value = |
| 675 webkit_glue::StringToStdWString(input_element->value()); | 675 webkit_glue::StringToString16(input_element->value()); |
| 676 listener->OnBlur(input_element, value); | 676 listener->OnBlur(input_element, value); |
| 677 } | 677 } |
| 678 | 678 |
| 679 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { | 679 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { |
| 680 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag)); | 680 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag)); |
| 681 // Note that we only show the autofill popup in this case if the caret is at | 681 // Note that we only show the autofill popup in this case if the caret is at |
| 682 // the end. This matches FireFox and Safari but not IE. | 682 // the end. This matches FireFox and Safari but not IE. |
| 683 Autofill(static_cast<WebCore::HTMLInputElement*>(element), | 683 Autofill(static_cast<WebCore::HTMLInputElement*>(element), |
| 684 false, false, true); | 684 false, false, true); |
| 685 } | 685 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 699 // Cancel any pending DoAutofill call. | 699 // Cancel any pending DoAutofill call. |
| 700 autofill_args_.clear(); | 700 autofill_args_.clear(); |
| 701 autofill_timer_.stop(); | 701 autofill_timer_.stop(); |
| 702 | 702 |
| 703 // Let's try to trigger autofill for that field, if applicable. | 703 // Let's try to trigger autofill for that field, if applicable. |
| 704 if (!input_element->isEnabledFormControl() || !input_element->isTextField() || | 704 if (!input_element->isEnabledFormControl() || !input_element->isTextField() || |
| 705 input_element->isPasswordField() || !input_element->autoComplete()) { | 705 input_element->isPasswordField() || !input_element->autoComplete()) { |
| 706 return false; | 706 return false; |
| 707 } | 707 } |
| 708 | 708 |
| 709 std::wstring name = AutofillForm::GetNameForInputElement(input_element); | 709 string16 name = AutofillForm::GetNameForInputElement(input_element); |
| 710 if (name.empty()) // If the field has no name, then we won't have values. | 710 if (name.empty()) // If the field has no name, then we won't have values. |
| 711 return false; | 711 return false; |
| 712 | 712 |
| 713 // Don't attempt to autofill with values that are too large. | 713 // Don't attempt to autofill with values that are too large. |
| 714 if (input_element->value().length() > kMaximumTextSizeForAutofill) | 714 if (input_element->value().length() > kMaximumTextSizeForAutofill) |
| 715 return false; | 715 return false; |
| 716 | 716 |
| 717 autofill_args_ = new AutofillArgs(); | 717 autofill_args_ = new AutofillArgs(); |
| 718 autofill_args_->input_element = input_element; | 718 autofill_args_->input_element = input_element; |
| 719 autofill_args_->autofill_form_only = autofill_form_only; | 719 autofill_args_->autofill_form_only = autofill_form_only; |
| 720 autofill_args_->autofill_on_empty_value = autofill_on_empty_value; | 720 autofill_args_->autofill_on_empty_value = autofill_on_empty_value; |
| 721 autofill_args_->require_caret_at_end = require_caret_at_end; | 721 autofill_args_->require_caret_at_end = require_caret_at_end; |
| 722 autofill_args_->backspace_or_delete_pressed = backspace_or_delete_pressed_; | 722 autofill_args_->backspace_or_delete_pressed = backspace_or_delete_pressed_; |
| 723 | 723 |
| 724 if (!require_caret_at_end) { | 724 if (!require_caret_at_end) { |
| 725 DoAutofill(NULL); | 725 DoAutofill(NULL); |
| 726 } else { | 726 } else { |
| 727 // We post a task for doing the autofill as the caret position is not set | 727 // We post a task for doing the autofill as the caret position is not set |
| 728 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) | 728 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) |
| 729 // and we need it to determine whether or not to trigger autofill. | 729 // and we need it to determine whether or not to trigger autofill. |
| 730 autofill_timer_.startOneShot(0.0); | 730 autofill_timer_.startOneShot(0.0); |
| 731 } | 731 } |
| 732 return true; | 732 return true; |
| 733 } | 733 } |
| 734 | 734 |
| 735 void EditorClientImpl::DoAutofill(WebCore::Timer<EditorClientImpl>* timer) { | 735 void EditorClientImpl::DoAutofill(WebCore::Timer<EditorClientImpl>* timer) { |
| 736 OwnPtr<AutofillArgs> args(autofill_args_.release()); | 736 OwnPtr<AutofillArgs> args(autofill_args_.release()); |
| 737 WebCore::HTMLInputElement* input_element = args->input_element.get(); | 737 WebCore::HTMLInputElement* input_element = args->input_element.get(); |
| 738 | 738 |
| 739 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); | 739 string16 value = webkit_glue::StringToString16(input_element->value()); |
| 740 | 740 |
| 741 // Enforce autofill_on_empty_value and caret_at_end. | 741 // Enforce autofill_on_empty_value and caret_at_end. |
| 742 bool is_caret_at_end = args->require_caret_at_end ? | 742 bool is_caret_at_end = args->require_caret_at_end ? |
| 743 input_element->selectionStart() == input_element->selectionEnd() && | 743 input_element->selectionStart() == input_element->selectionEnd() && |
| 744 input_element->selectionEnd() == static_cast<int>(value.length()) : | 744 input_element->selectionEnd() == static_cast<int>(value.length()) : |
| 745 true; // When |require_caret_at_end| is false, just pretend we are at | 745 true; // When |require_caret_at_end| is false, just pretend we are at |
| 746 // the end. | 746 // the end. |
| 747 if ((!args->autofill_on_empty_value && value.empty()) || !is_caret_at_end) { | 747 if ((!args->autofill_on_empty_value && value.empty()) || !is_caret_at_end) { |
| 748 webview_->HideAutoCompletePopup(); | 748 webview_->HideAutoCompletePopup(); |
| 749 return; | 749 return; |
| 750 } | 750 } |
| 751 | 751 |
| 752 // First let's see if there is a password listener for that element. | 752 // First let's see if there is a password listener for that element. |
| 753 // We won't trigger form autofill in that case, as having both behavior on | 753 // We won't trigger form autofill in that case, as having both behavior on |
| 754 // a node would be confusing. | 754 // a node would be confusing. |
| 755 WebFrameImpl* webframe = | 755 WebFrameImpl* webframe = |
| 756 WebFrameImpl::FromFrame(input_element->document()->frame()); | 756 WebFrameImpl::FromFrame(input_element->document()->frame()); |
| 757 webkit_glue::PasswordAutocompleteListener* listener = | 757 webkit_glue::PasswordAutocompleteListener* listener = |
| 758 webframe->GetPasswordListener(input_element); | 758 webframe->GetPasswordListener(input_element); |
| 759 if (listener) { | 759 if (listener) { |
| 760 if (args->autofill_form_only) | 760 if (args->autofill_form_only) |
| 761 return; | 761 return; |
| 762 | 762 |
| 763 listener->OnInlineAutocompleteNeeded( | 763 listener->OnInlineAutocompleteNeeded( |
| 764 input_element, value, args->backspace_or_delete_pressed, true); | 764 input_element, value, args->backspace_or_delete_pressed, true); |
| 765 return; | 765 return; |
| 766 } | 766 } |
| 767 | 767 |
| 768 // Then trigger form autofill. | 768 // Then trigger form autofill. |
| 769 std::wstring name = AutofillForm::GetNameForInputElement(input_element); | 769 string16 name = AutofillForm::GetNameForInputElement(input_element); |
| 770 ASSERT(static_cast<int>(name.length()) > 0); | 770 ASSERT(static_cast<int>(name.length()) > 0); |
| 771 | 771 |
| 772 if (webview_->delegate()) | 772 if (webview_->client()) { |
| 773 webview_->delegate()->QueryFormFieldAutofill(name, value, | 773 webview_->client()->queryAutofillSuggestions( |
| 774 reinterpret_cast<int64>(input_element)); | 774 webkit_glue::NodeToWebNode(input_element), name, value); |
| 775 } |
| 775 } | 776 } |
| 776 | 777 |
| 777 void EditorClientImpl::CancelPendingAutofill() { | 778 void EditorClientImpl::CancelPendingAutofill() { |
| 778 autofill_args_.clear(); | 779 autofill_args_.clear(); |
| 779 autofill_timer_.stop(); | 780 autofill_timer_.stop(); |
| 780 } | 781 } |
| 781 | 782 |
| 782 void EditorClientImpl::OnAutofillSuggestionAccepted( | 783 void EditorClientImpl::OnAutofillSuggestionAccepted( |
| 783 WebCore::HTMLInputElement* text_field) { | 784 WebCore::HTMLInputElement* text_field) { |
| 784 WebFrameImpl* webframe = | 785 WebFrameImpl* webframe = |
| 785 WebFrameImpl::FromFrame(text_field->document()->frame()); | 786 WebFrameImpl::FromFrame(text_field->document()->frame()); |
| 786 webkit_glue::PasswordAutocompleteListener* listener = | 787 webkit_glue::PasswordAutocompleteListener* listener = |
| 787 webframe->GetPasswordListener(text_field); | 788 webframe->GetPasswordListener(text_field); |
| 788 std::wstring value = webkit_glue::StringToStdWString(text_field->value()); | 789 string16 value = webkit_glue::StringToString16(text_field->value()); |
| 789 // Password listeners need to autocomplete other fields that depend on the | 790 // Password listeners need to autocomplete other fields that depend on the |
| 790 // input element with autofill suggestions. | 791 // input element with autofill suggestions. |
| 791 if (listener) | 792 if (listener) |
| 792 listener->OnInlineAutocompleteNeeded(text_field, value, false, false); | 793 listener->OnInlineAutocompleteNeeded(text_field, value, false, false); |
| 793 } | 794 } |
| 794 | 795 |
| 795 bool EditorClientImpl::doTextFieldCommandFromEvent( | 796 bool EditorClientImpl::doTextFieldCommandFromEvent( |
| 796 WebCore::Element* element, | 797 WebCore::Element* element, |
| 797 WebCore::KeyboardEvent* event) { | 798 WebCore::KeyboardEvent* event) { |
| 798 // Remember if backspace was pressed for the autofill. It is not clear how to | 799 // Remember if backspace was pressed for the autofill. It is not clear how to |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 901 |
| 901 void EditorClientImpl::getGuessesForWord(const WebCore::String&, | 902 void EditorClientImpl::getGuessesForWord(const WebCore::String&, |
| 902 WTF::Vector<WebCore::String>& guesses)
{ | 903 WTF::Vector<WebCore::String>& guesses)
{ |
| 903 NOTIMPLEMENTED(); | 904 NOTIMPLEMENTED(); |
| 904 } | 905 } |
| 905 | 906 |
| 906 void EditorClientImpl::setInputMethodState(bool enabled) { | 907 void EditorClientImpl::setInputMethodState(bool enabled) { |
| 907 if (webview_->client()) | 908 if (webview_->client()) |
| 908 webview_->client()->setInputMethodEnabled(enabled); | 909 webview_->client()->setInputMethodEnabled(enabled); |
| 909 } | 910 } |
| OLD | NEW |