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

Side by Side Diff: webkit/glue/editor_client_impl.cc

Issue 62143: Fix for a regression introduced by an autofill change (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/editor_client_impl.h ('k') | webkit/glue/webview_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 627 }
628 628
629 // 629 //
630 // End of code block subject to Apple, Inc. copyright 630 // End of code block subject to Apple, Inc. copyright
631 // 631 //
632 632
633 void EditorClientImpl::handleKeyboardEvent(WebCore::KeyboardEvent* evt) { 633 void EditorClientImpl::handleKeyboardEvent(WebCore::KeyboardEvent* evt) {
634 if (evt->keyCode() == WebCore::VKEY_DOWN || 634 if (evt->keyCode() == WebCore::VKEY_DOWN ||
635 evt->keyCode() == WebCore::VKEY_UP) { 635 evt->keyCode() == WebCore::VKEY_UP) {
636 DCHECK(evt->target()->toNode()); 636 DCHECK(evt->target()->toNode());
637 ShowAutofillForNode(evt->target()->toNode()); 637 ShowFormAutofillForNode(evt->target()->toNode());
638 } 638 }
639 639
640 if (handleEditingKeyboardEvent(evt)) 640 if (handleEditingKeyboardEvent(evt))
641 evt->setDefaultHandled(); 641 evt->setDefaultHandled();
642 } 642 }
643 643
644 void EditorClientImpl::handleInputMethodKeydown(WebCore::KeyboardEvent* keyEvent ) { 644 void EditorClientImpl::handleInputMethodKeydown(WebCore::KeyboardEvent* keyEvent ) {
645 // We handle IME within chrome. 645 // We handle IME within chrome.
646 } 646 }
647 647
648 void EditorClientImpl::textFieldDidBeginEditing(WebCore::Element*) { 648 void EditorClientImpl::textFieldDidBeginEditing(WebCore::Element*) {
649 } 649 }
650 650
651 void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) { 651 void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) {
652 // Notification that focus was lost. Be careful with this, it's also sent 652 // Notification that focus was lost. Be careful with this, it's also sent
653 // when the page is being closed. 653 // when the page is being closed.
654 654
655 // Cancel any pending DoAutofill calls. 655 // Cancel any pending DoAutofill calls.
656 autofill_factory_.RevokeAll(); 656 autofill_factory_.RevokeAll();
657 657
658 // Hide any showing popup. 658 // Hide any showing popup.
659 web_view_->HideAutoCompletePopup(); 659 web_view_->HideAutoCompletePopup();
660 } 660 }
661 661
662 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { 662 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) {
663 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag)); 663 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag));
664 // Note that we only show the autofill popup in this case if the caret is at 664 // Note that we only show the autofill popup in this case if the caret is at
665 // the end. This matches FireFox and Safari but not IE. 665 // the end. This matches FireFox and Safari but not IE.
666 Autofill(static_cast<WebCore::HTMLInputElement*>(element), false, true); 666 Autofill(static_cast<WebCore::HTMLInputElement*>(element),
667 false, false, true);
667 } 668 }
668 669
669 bool EditorClientImpl::ShowAutofillForNode(WebCore::Node* node) { 670 bool EditorClientImpl::ShowFormAutofillForNode(WebCore::Node* node) {
670 WebCore::HTMLInputElement* input_element = 671 WebCore::HTMLInputElement* input_element =
671 webkit_glue::NodeToHTMLInputElement(node); 672 webkit_glue::NodeToHTMLInputElement(node);
672 if (input_element) 673 if (input_element)
673 return Autofill(input_element, true, false); 674 return Autofill(input_element, true, true, false);
674 return false; 675 return false;
675 } 676 }
676 677
677 bool EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element, 678 bool EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element,
679 bool form_autofill_only,
678 bool autofill_on_empty_value, 680 bool autofill_on_empty_value,
679 bool requires_caret_at_end) { 681 bool requires_caret_at_end) {
680 // Cancel any pending DoAutofill calls. 682 // Cancel any pending DoAutofill calls.
681 autofill_factory_.RevokeAll(); 683 autofill_factory_.RevokeAll();
682 684
683 // Let's try to trigger autofill for that field, if applicable. 685 // Let's try to trigger autofill for that field, if applicable.
684 if (!input_element->isEnabled() || !input_element->isTextField() || 686 if (!input_element->isEnabled() || !input_element->isTextField() ||
685 input_element->isPasswordField() || !input_element->autoComplete()) { 687 input_element->isPasswordField() || !input_element->autoComplete()) {
686 return false; 688 return false;
687 } 689 }
688 690
689 std::wstring name = AutofillForm::GetNameForInputElement(input_element); 691 std::wstring name = AutofillForm::GetNameForInputElement(input_element);
690 if (name.empty()) // If the field has no name, then we won't have values. 692 if (name.empty()) // If the field has no name, then we won't have values.
691 return false; 693 return false;
692 694
693 // Don't attempt to autofill with values that are too large. 695 // Don't attempt to autofill with values that are too large.
694 if (input_element->value().length() > kMaximumTextSizeForAutofill) 696 if (input_element->value().length() > kMaximumTextSizeForAutofill)
695 return false; 697 return false;
696 698
697 if (!requires_caret_at_end) { 699 if (!requires_caret_at_end) {
698 DoAutofill(input_element, autofill_on_empty_value, 700 DoAutofill(input_element, form_autofill_only, autofill_on_empty_value,
699 false, backspace_pressed_); 701 false, backspace_pressed_);
700 } else { 702 } else {
701 // We post a task for doing the autofill as the caret position is not set 703 // We post a task for doing the autofill as the caret position is not set
702 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and 704 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
703 // we need it to determine whether or not to trigger autofill. 705 // we need it to determine whether or not to trigger autofill.
704 std::wstring value = 706 std::wstring value =
705 webkit_glue::StringToStdWString(input_element->value()); 707 webkit_glue::StringToStdWString(input_element->value());
706 MessageLoop::current()->PostTask( 708 MessageLoop::current()->PostTask(
707 FROM_HERE, 709 FROM_HERE,
708 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill, 710 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill,
709 input_element, 711 input_element,
712 form_autofill_only,
710 autofill_on_empty_value, 713 autofill_on_empty_value,
711 true, 714 true,
712 backspace_pressed_)); 715 backspace_pressed_));
713 } 716 }
714 return true; 717 return true;
715 } 718 }
716 719
717 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, 720 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element,
721 bool form_autofill_only,
718 bool autofill_on_empty_value, 722 bool autofill_on_empty_value,
719 bool requires_caret_at_end, 723 bool requires_caret_at_end,
720 bool backspace) { 724 bool backspace) {
721 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); 725 std::wstring value = webkit_glue::StringToStdWString(input_element->value());
722 726
723 // Enforce autofill_on_empty_value and caret_at_end. 727 // Enforce autofill_on_empty_value and caret_at_end.
724 bool is_caret_at_end = requires_caret_at_end ? 728 bool is_caret_at_end = requires_caret_at_end ?
725 input_element->selectionStart() == input_element->selectionEnd() && 729 input_element->selectionStart() == input_element->selectionEnd() &&
726 input_element->selectionEnd() == static_cast<int>(value.length()) : 730 input_element->selectionEnd() == static_cast<int>(value.length()) :
727 true; // When |requires_caret_at_end| is false, just pretend we are at 731 true; // When |requires_caret_at_end| is false, just pretend we are at
728 // the end. 732 // the end.
729 if ((!autofill_on_empty_value && value.empty()) || !is_caret_at_end) { 733 if ((!autofill_on_empty_value && value.empty()) || !is_caret_at_end) {
730 web_view_->HideAutoCompletePopup(); 734 web_view_->HideAutoCompletePopup();
731 return; 735 return;
732 } 736 }
733 737
734 // First let's see if there is a password listener for that element. 738 // First let's see if there is a password listener for that element.
739 // We won't trigger form autofill in that case, as having both behavior on
740 // a node would be confusing.
735 WebFrameImpl* webframe = 741 WebFrameImpl* webframe =
736 WebFrameImpl::FromFrame(input_element->document()->frame()); 742 WebFrameImpl::FromFrame(input_element->document()->frame());
737 webkit_glue::PasswordAutocompleteListener* listener = 743 webkit_glue::PasswordAutocompleteListener* listener =
738 webframe->GetPasswordListener(input_element); 744 webframe->GetPasswordListener(input_element);
739 if (listener) { 745 if (listener) {
746 if (form_autofill_only)
747 return;
748
740 if (backspace) // No autocomplete for password on backspace. 749 if (backspace) // No autocomplete for password on backspace.
741 return; 750 return;
742 751
743 listener->OnInlineAutocompleteNeeded(input_element, value); 752 listener->OnInlineAutocompleteNeeded(input_element, value);
744 return; 753 return;
745 } 754 }
746 755
747 // Then trigger form autofill. 756 // Then trigger form autofill.
748 std::wstring name = AutofillForm::GetNameForInputElement(input_element); 757 std::wstring name = AutofillForm::GetNameForInputElement(input_element);
749 DCHECK_GT(static_cast<int>(name.length()), 0); 758 DCHECK_GT(static_cast<int>(name.length()), 0);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 929 }
921 return L"(UNKNOWN AFFINITY)"; 930 return L"(UNKNOWN AFFINITY)";
922 } 931 }
923 932
924 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { 933 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) {
925 // TODO(pamg): Implement me. It's not clear what WebKit produces for this 934 // TODO(pamg): Implement me. It's not clear what WebKit produces for this
926 // (their [style description] method), and none of the layout tests provide 935 // (their [style description] method), and none of the layout tests provide
927 // an example. But because none of them use it, it's not yet important. 936 // an example. But because none of them use it, it's not yet important.
928 return std::wstring(); 937 return std::wstring();
929 } 938 }
OLDNEW
« no previous file with comments | « webkit/glue/editor_client_impl.h ('k') | webkit/glue/webview_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698