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

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

Issue 53017: Fix the form autofill showing when pressing the up arrow key (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 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 if (ShowAutofillForNode(evt->target()->toNode())) {
638 // We will show an autofill popup. Let's return so we don't handle the
639 // event. The handling could change the caret position, preventing the
640 // popup from showing (since the actual showing is delayed, see
641 // DoAutofill).
642 return;
643 }
638 } 644 }
639 645
640 if (handleEditingKeyboardEvent(evt)) 646 if (handleEditingKeyboardEvent(evt))
641 evt->setDefaultHandled(); 647 evt->setDefaultHandled();
642 } 648 }
643 649
644 void EditorClientImpl::handleInputMethodKeydown(WebCore::KeyboardEvent* keyEvent ) { 650 void EditorClientImpl::handleInputMethodKeydown(WebCore::KeyboardEvent* keyEvent ) {
645 // We handle IME within chrome. 651 // We handle IME within chrome.
646 } 652 }
647 653
648 void EditorClientImpl::textFieldDidBeginEditing(WebCore::Element*) { 654 void EditorClientImpl::textFieldDidBeginEditing(WebCore::Element*) {
649 } 655 }
650 656
651 void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) { 657 void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) {
652 // Notification that focus was lost. Be careful with this, it's also sent 658 // Notification that focus was lost. Be careful with this, it's also sent
653 // when the page is being closed. 659 // when the page is being closed.
654 660
655 // Cancel any pending DoAutofill calls. 661 // Cancel any pending DoAutofill calls.
656 autofill_factory_.RevokeAll(); 662 autofill_factory_.RevokeAll();
657 663
658 // Hide any showing popup. 664 // Hide any showing popup.
659 web_view_->HideAutoCompletePopup(); 665 web_view_->HideAutoCompletePopup();
660 } 666 }
661 667
662 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { 668 void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) {
663 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag)); 669 DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag));
664 Autofill(static_cast<WebCore::HTMLInputElement*>(element), false); 670 Autofill(static_cast<WebCore::HTMLInputElement*>(element), false);
665 } 671 }
666 672
667 void EditorClientImpl::ShowAutofillForNode(WebCore::Node* node) { 673 bool EditorClientImpl::ShowAutofillForNode(WebCore::Node* node) {
668 WebCore::HTMLInputElement* input_element = 674 WebCore::HTMLInputElement* input_element =
669 webkit_glue::NodeToHTMLInputElement(node); 675 webkit_glue::NodeToHTMLInputElement(node);
670 if (input_element) 676 if (input_element)
671 Autofill(input_element, true); 677 return Autofill(input_element, true);
678 return false;
672 } 679 }
673 680
674 void EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element, 681 bool EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element,
675 bool autofill_on_empty_value) { 682 bool autofill_on_empty_value) {
676 // Cancel any pending DoAutofill calls. 683 // Cancel any pending DoAutofill calls.
677 autofill_factory_.RevokeAll(); 684 autofill_factory_.RevokeAll();
678 685
679 // Let's try to trigger autofill for that field, if applicable. 686 // Let's try to trigger autofill for that field, if applicable.
680 if (!input_element->isEnabled() || !input_element->isTextField() || 687 if (!input_element->isEnabled() || !input_element->isTextField() ||
681 input_element->isPasswordField() || !input_element->autoComplete()) { 688 input_element->isPasswordField() || !input_element->autoComplete()) {
682 return; 689 return false;
683 } 690 }
684 691
685 std::wstring name = AutofillForm::GetNameForInputElement(input_element); 692 std::wstring name = AutofillForm::GetNameForInputElement(input_element);
686 if (name.empty()) // If the field has no name, then we won't have values. 693 if (name.empty()) // If the field has no name, then we won't have values.
687 return; 694 return false;
688 695
689 // Don't attempt to autofill with values that are too large. 696 // Don't attempt to autofill with values that are too large.
690 if (input_element->value().length() > kMaximumTextSizeForAutofill) 697 if (input_element->value().length() > kMaximumTextSizeForAutofill)
691 return; 698 return false;
692 699
693 // We post a task for doing the autofill as the caret position is not set 700 // We post a task for doing the autofill as the caret position is not set
694 // properly at this point ( http://bugs.webkit.org/show_bug.cgi?id=16976) 701 // properly at this point ( http://bugs.webkit.org/show_bug.cgi?id=16976)
695 // and we need it to determine whether or not to trigger autofill. 702 // and we need it to determine whether or not to trigger autofill.
696 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); 703 std::wstring value = webkit_glue::StringToStdWString(input_element->value());
697 MessageLoop::current()->PostTask( 704 MessageLoop::current()->PostTask(
698 FROM_HERE, 705 FROM_HERE,
699 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill, 706 autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill,
700 input_element, 707 input_element,
701 autofill_on_empty_value, 708 autofill_on_empty_value,
702 backspace_pressed_)); 709 backspace_pressed_));
710 return true;
703 } 711 }
704 712
705 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, 713 void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element,
706 bool autofill_on_empty_value, 714 bool autofill_on_empty_value,
707 bool backspace) { 715 bool backspace) {
708 std::wstring value = webkit_glue::StringToStdWString(input_element->value()); 716 std::wstring value = webkit_glue::StringToStdWString(input_element->value());
709 717
710 // Only autofill when there is some text and the caret is at the end. 718 // Only autofill when there is some text and the caret is at the end.
711 bool caret_at_end = 719 bool caret_at_end =
712 input_element->selectionStart() == input_element->selectionEnd() && 720 input_element->selectionStart() == input_element->selectionEnd() &&
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 } 913 }
906 return L"(UNKNOWN AFFINITY)"; 914 return L"(UNKNOWN AFFINITY)";
907 } 915 }
908 916
909 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { 917 std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) {
910 // TODO(pamg): Implement me. It's not clear what WebKit produces for this 918 // TODO(pamg): Implement me. It's not clear what WebKit produces for this
911 // (their [style description] method), and none of the layout tests provide 919 // (their [style description] method), and none of the layout tests provide
912 // an example. But because none of them use it, it's not yet important. 920 // an example. But because none of them use it, it's not yet important.
913 return std::wstring(); 921 return std::wstring();
914 } 922 }
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