| 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 #include "webkit/glue/editor_client_impl.h" | 9 #include "webkit/glue/editor_client_impl.h" |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 d->UserMetricsRecordComputedAction(UTF8ToWide(command_name)); | 67 d->UserMetricsRecordComputedAction(UTF8ToWide(command_name)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } | 70 } |
| 71 | 71 |
| 72 EditorClientImpl::EditorClientImpl(WebView* web_view) | 72 EditorClientImpl::EditorClientImpl(WebView* web_view) |
| 73 : web_view_(static_cast<WebViewImpl*>(web_view)), | 73 : web_view_(static_cast<WebViewImpl*>(web_view)), |
| 74 use_editor_delegate_(false), | 74 use_editor_delegate_(false), |
| 75 in_redo_(false), | 75 in_redo_(false), |
| 76 backspace_pressed_(false), | 76 backspace_or_delete_pressed_(false), |
| 77 spell_check_this_field_status_(SPELLCHECK_AUTOMATIC), | 77 spell_check_this_field_status_(SPELLCHECK_AUTOMATIC), |
| 78 // Don't complain about using "this" in initializer list. | 78 // Don't complain about using "this" in initializer list. |
| 79 MSVC_PUSH_DISABLE_WARNING(4355) | 79 MSVC_PUSH_DISABLE_WARNING(4355) |
| 80 autofill_factory_(this) { | 80 autofill_factory_(this) { |
| 81 MSVC_POP_WARNING() | 81 MSVC_POP_WARNING() |
| 82 } | 82 } |
| 83 | 83 |
| 84 EditorClientImpl::~EditorClientImpl() { | 84 EditorClientImpl::~EditorClientImpl() { |
| 85 } | 85 } |
| 86 | 86 |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 std::wstring name = AutofillForm::GetNameForInputElement(input_element); | 742 std::wstring name = AutofillForm::GetNameForInputElement(input_element); |
| 743 if (name.empty()) // If the field has no name, then we won't have values. | 743 if (name.empty()) // If the field has no name, then we won't have values. |
| 744 return false; | 744 return false; |
| 745 | 745 |
| 746 // Don't attempt to autofill with values that are too large. | 746 // Don't attempt to autofill with values that are too large. |
| 747 if (input_element->value().length() > kMaximumTextSizeForAutofill) | 747 if (input_element->value().length() > kMaximumTextSizeForAutofill) |
| 748 return false; | 748 return false; |
| 749 | 749 |
| 750 if (!requires_caret_at_end) { | 750 if (!requires_caret_at_end) { |
| 751 DoAutofill(input_element, form_autofill_only, autofill_on_empty_value, | 751 DoAutofill(input_element, form_autofill_only, autofill_on_empty_value, |
| 752 false, backspace_pressed_); | 752 false, backspace_or_delete_pressed_); |
| 753 } else { | 753 } else { |
| 754 // We post a task for doing the autofill as the caret position is not set | 754 // We post a task for doing the autofill as the caret position is not set |
| 755 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and | 755 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 756 // we need it to determine whether or not to trigger autofill. | 756 // we need it to determine whether or not to trigger autofill. |
| 757 std::wstring value = | 757 std::wstring value = |
| 758 webkit_glue::StringToStdWString(input_element->value()); | 758 webkit_glue::StringToStdWString(input_element->value()); |
| 759 MessageLoop::current()->PostTask( | 759 MessageLoop::current()->PostTask( |
| 760 FROM_HERE, | 760 FROM_HERE, |
| 761 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill, | 761 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill, |
| 762 input_element, | 762 input_element, |
| 763 form_autofill_only, | 763 form_autofill_only, |
| 764 autofill_on_empty_value, | 764 autofill_on_empty_value, |
| 765 true, | 765 true, |
| 766 backspace_pressed_)); | 766 backspace_or_delete_pressed_)); |
| 767 } | 767 } |
| 768 return true; | 768 return true; |
| 769 } | 769 } |
| 770 | 770 |
| 771 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, | 771 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, |
| 772 bool form_autofill_only, | 772 bool form_autofill_only, |
| 773 bool autofill_on_empty_value, | 773 bool autofill_on_empty_value, |
| 774 bool requires_caret_at_end, | 774 bool requires_caret_at_end, |
| 775 bool backspace) { | 775 bool backspace) { |
| 776 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); | 776 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 790 // We won't trigger form autofill in that case, as having both behavior on | 790 // We won't trigger form autofill in that case, as having both behavior on |
| 791 // a node would be confusing. | 791 // a node would be confusing. |
| 792 WebFrameImpl* webframe = | 792 WebFrameImpl* webframe = |
| 793 WebFrameImpl::FromFrame(input_element->document()->frame()); | 793 WebFrameImpl::FromFrame(input_element->document()->frame()); |
| 794 webkit_glue::PasswordAutocompleteListener* listener = | 794 webkit_glue::PasswordAutocompleteListener* listener = |
| 795 webframe->GetPasswordListener(input_element); | 795 webframe->GetPasswordListener(input_element); |
| 796 if (listener) { | 796 if (listener) { |
| 797 if (form_autofill_only) | 797 if (form_autofill_only) |
| 798 return; | 798 return; |
| 799 | 799 |
| 800 if (backspace) // No autocomplete for password on backspace. | 800 listener->OnInlineAutocompleteNeeded(input_element, value, backspace, true); |
| 801 return; | |
| 802 | |
| 803 listener->OnInlineAutocompleteNeeded(input_element, value); | |
| 804 return; | 801 return; |
| 805 } | 802 } |
| 806 | 803 |
| 807 // Then trigger form autofill. | 804 // Then trigger form autofill. |
| 808 std::wstring name = AutofillForm::GetNameForInputElement(input_element); | 805 std::wstring name = AutofillForm::GetNameForInputElement(input_element); |
| 809 DCHECK_GT(static_cast<int>(name.length()), 0); | 806 DCHECK_GT(static_cast<int>(name.length()), 0); |
| 810 web_view_->delegate()->QueryFormFieldAutofill(name, value, | 807 web_view_->delegate()->QueryFormFieldAutofill(name, value, |
| 811 reinterpret_cast<int64>(input_element)); | 808 reinterpret_cast<int64>(input_element)); |
| 812 } | 809 } |
| 813 | 810 |
| 811 void EditorClientImpl::OnAutofillSuggestionAccepted( |
| 812 WebCore::HTMLInputElement* text_field) { |
| 813 WebFrameImpl* webframe = |
| 814 WebFrameImpl::FromFrame(text_field->document()->frame()); |
| 815 webkit_glue::PasswordAutocompleteListener* listener = |
| 816 webframe->GetPasswordListener(text_field); |
| 817 std::wstring value = webkit_glue::StringToStdWString(text_field->value()); |
| 818 // Password listeners need to autocomplete other fields that depend on the |
| 819 // input element with autofill suggestions. |
| 820 if (listener) |
| 821 listener->OnInlineAutocompleteNeeded(text_field, value, false, false); |
| 822 } |
| 823 |
| 814 bool EditorClientImpl::doTextFieldCommandFromEvent( | 824 bool EditorClientImpl::doTextFieldCommandFromEvent( |
| 815 WebCore::Element* element, | 825 WebCore::Element* element, |
| 816 WebCore::KeyboardEvent* event) { | 826 WebCore::KeyboardEvent* event) { |
| 817 // Remember if backspace was pressed for the autofill. It is not clear how to | 827 // Remember if backspace was pressed for the autofill. It is not clear how to |
| 818 // find if backspace was pressed from textFieldDidBeginEditing and | 828 // find if backspace was pressed from textFieldDidBeginEditing and |
| 819 // textDidChangeInTextField as when these methods are called the value of the | 829 // textDidChangeInTextField as when these methods are called the value of the |
| 820 // input element already contains the type character. | 830 // input element already contains the type character. |
| 821 backspace_pressed_ = (event->keyCode() == WebCore::VKEY_BACK); | 831 backspace_or_delete_pressed_ = (event->keyCode() == WebCore::VKEY_BACK) || |
| 832 (event->keyCode() == WebCore::VKEY_DELETE); |
| 822 | 833 |
| 823 // The Mac code appears to use this method as a hook to implement special | 834 // The Mac code appears to use this method as a hook to implement special |
| 824 // keyboard commands specific to Safari's auto-fill implementation. We | 835 // keyboard commands specific to Safari's auto-fill implementation. We |
| 825 // just return false to allow the default action. | 836 // just return false to allow the default action. |
| 826 return false; | 837 return false; |
| 827 } | 838 } |
| 828 | 839 |
| 829 void EditorClientImpl::textWillBeDeletedInTextField(WebCore::Element*) { | 840 void EditorClientImpl::textWillBeDeletedInTextField(WebCore::Element*) { |
| 830 } | 841 } |
| 831 | 842 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 } | 1012 } |
| 1002 return L"(UNKNOWN AFFINITY)"; | 1013 return L"(UNKNOWN AFFINITY)"; |
| 1003 } | 1014 } |
| 1004 | 1015 |
| 1005 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { | 1016 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { |
| 1006 // TODO(pamg): Implement me. It's not clear what WebKit produces for this | 1017 // TODO(pamg): Implement me. It's not clear what WebKit produces for this |
| 1007 // (their [style description] method), and none of the layout tests provide | 1018 // (their [style description] method), and none of the layout tests provide |
| 1008 // an example. But because none of them use it, it's not yet important. | 1019 // an example. But because none of them use it, it's not yet important. |
| 1009 return std::wstring(); | 1020 return std::wstring(); |
| 1010 } | 1021 } |
| OLD | NEW |