OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved. |
3 * Copyright (C) 2009 Google, Inc. All rights reserved. | 3 * Copyright (C) 2009 Google, Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "EventNames.h" | 34 #include "EventNames.h" |
35 #include "Frame.h" | 35 #include "Frame.h" |
36 #include "KeyboardCodes.h" | 36 #include "KeyboardCodes.h" |
37 #include "HTMLInputElement.h" | 37 #include "HTMLInputElement.h" |
38 #include "HTMLNames.h" | 38 #include "HTMLNames.h" |
39 #include "KeyboardEvent.h" | 39 #include "KeyboardEvent.h" |
40 #include "PlatformKeyboardEvent.h" | 40 #include "PlatformKeyboardEvent.h" |
41 #include "PlatformString.h" | 41 #include "PlatformString.h" |
42 #include "RenderObject.h" | 42 #include "RenderObject.h" |
43 | 43 |
| 44 #include "DOMUtilitiesPrivate.h" |
| 45 #include "PasswordAutocompleteListener.h" |
44 #include "WebEditingAction.h" | 46 #include "WebEditingAction.h" |
| 47 #include "WebFrameImpl.h" |
45 #include "WebKit.h" | 48 #include "WebKit.h" |
46 #include "WebNode.h" | 49 #include "WebNode.h" |
47 #include "WebRange.h" | 50 #include "WebRange.h" |
48 #include "WebTextAffinity.h" | 51 #include "WebTextAffinity.h" |
49 #include "WebViewClient.h" | 52 #include "WebViewClient.h" |
50 #include "DOMUtilitiesPrivate.h" | 53 #include "WebViewImpl.h" |
51 #include "PasswordAutocompleteListener.h" | |
52 #include "webkit/glue/webview_impl.h" | |
53 | 54 |
54 using namespace WebCore; | 55 using namespace WebCore; |
55 | 56 |
56 namespace WebKit { | 57 namespace WebKit { |
57 | 58 |
58 // Arbitrary depth limit for the undo stack, to keep it from using | 59 // Arbitrary depth limit for the undo stack, to keep it from using |
59 // unbounded memory. This is the maximum number of distinct undoable | 60 // unbounded memory. This is the maximum number of distinct undoable |
60 // actions -- unbroken stretches of typed characters are coalesced | 61 // actions -- unbroken stretches of typed characters are coalesced |
61 // into a single action. | 62 // into a single action. |
62 static const size_t maximumUndoStackDepth = 1000; | 63 static const size_t maximumUndoStackDepth = 1000; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return true; | 108 return true; |
108 #else | 109 #else |
109 return false; | 110 return false; |
110 #endif | 111 #endif |
111 } | 112 } |
112 | 113 |
113 bool EditorClientImpl::shouldSpellcheckByDefault() | 114 bool EditorClientImpl::shouldSpellcheckByDefault() |
114 { | 115 { |
115 // Spellcheck should be enabled for all editable areas (such as textareas, | 116 // Spellcheck should be enabled for all editable areas (such as textareas, |
116 // contentEditable regions, and designMode docs), except text inputs. | 117 // contentEditable regions, and designMode docs), except text inputs. |
117 const Frame* frame = m_webView->GetFocusedWebCoreFrame(); | 118 const Frame* frame = m_webView->focusedWebCoreFrame(); |
118 if (!frame) | 119 if (!frame) |
119 return false; | 120 return false; |
120 const Editor* editor = frame->editor(); | 121 const Editor* editor = frame->editor(); |
121 if (!editor) | 122 if (!editor) |
122 return false; | 123 return false; |
123 if (editor->spellCheckingEnabledInFocusedNode()) | 124 if (editor->spellCheckingEnabledInFocusedNode()) |
124 return true; | 125 return true; |
125 const Document* document = frame->document(); | 126 const Document* document = frame->document(); |
126 if (!document) | 127 if (!document) |
127 return false; | 128 return false; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 259 |
259 void EditorClientImpl::didBeginEditing() | 260 void EditorClientImpl::didBeginEditing() |
260 { | 261 { |
261 if (m_webView->client()) | 262 if (m_webView->client()) |
262 m_webView->client()->didBeginEditing(); | 263 m_webView->client()->didBeginEditing(); |
263 } | 264 } |
264 | 265 |
265 void EditorClientImpl::respondToChangedSelection() | 266 void EditorClientImpl::respondToChangedSelection() |
266 { | 267 { |
267 if (m_webView->client()) { | 268 if (m_webView->client()) { |
268 Frame* frame = m_webView->GetFocusedWebCoreFrame(); | 269 Frame* frame = m_webView->focusedWebCoreFrame(); |
269 if (frame) | 270 if (frame) |
270 m_webView->client()->didChangeSelection(!frame->selection()->isRange()); | 271 m_webView->client()->didChangeSelection(!frame->selection()->isRange()); |
271 } | 272 } |
272 } | 273 } |
273 | 274 |
274 void EditorClientImpl::respondToChangedContents() | 275 void EditorClientImpl::respondToChangedContents() |
275 { | 276 { |
276 if (m_webView->client()) | 277 if (m_webView->client()) |
277 m_webView->client()->didChangeContents(); | 278 m_webView->client()->didChangeContents(); |
278 } | 279 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 void EditorClientImpl::textFieldDidEndEditing(Element* element) | 647 void EditorClientImpl::textFieldDidEndEditing(Element* element) |
647 { | 648 { |
648 // Notification that focus was lost. Be careful with this, it's also sent | 649 // Notification that focus was lost. Be careful with this, it's also sent |
649 // when the page is being closed. | 650 // when the page is being closed. |
650 | 651 |
651 // Cancel any pending DoAutofill call. | 652 // Cancel any pending DoAutofill call. |
652 m_autofillArgs.clear(); | 653 m_autofillArgs.clear(); |
653 m_autofillTimer.stop(); | 654 m_autofillTimer.stop(); |
654 | 655 |
655 // Hide any showing popup. | 656 // Hide any showing popup. |
656 m_webView->HideAutoCompletePopup(); | 657 m_webView->hideAutoCompletePopup(); |
657 | 658 |
658 if (!m_webView->client()) | 659 if (!m_webView->client()) |
659 return; // The page is getting closed, don't fill the password. | 660 return; // The page is getting closed, don't fill the password. |
660 | 661 |
661 // Notify any password-listener of the focus change. | 662 // Notify any password-listener of the focus change. |
662 HTMLInputElement* inputElement = WebKit::toHTMLInputElement(element); | 663 HTMLInputElement* inputElement = WebKit::toHTMLInputElement(element); |
663 if (!inputElement) | 664 if (!inputElement) |
664 return; | 665 return; |
665 | 666 |
666 WebFrameImpl* webframe = WebFrameImpl::FromFrame(inputElement->document()->frame()); | 667 WebFrameImpl* webframe = WebFrameImpl::fromFrame(inputElement->document()->frame()); |
667 PasswordAutocompleteListener* listener = webframe->GetPasswordListener(inputElement); | 668 PasswordAutocompleteListener* listener = webframe->getPasswordListener(inputElement); |
668 if (!listener) | 669 if (!listener) |
669 return; | 670 return; |
670 | 671 |
671 listener->didBlurInputElement(inputElement->value()); | 672 listener->didBlurInputElement(inputElement->value()); |
672 } | 673 } |
673 | 674 |
674 void EditorClientImpl::textDidChangeInTextField(Element* element) | 675 void EditorClientImpl::textDidChangeInTextField(Element* element) |
675 { | 676 { |
676 ASSERT(element->hasLocalName(HTMLNames::inputTag)); | 677 ASSERT(element->hasLocalName(HTMLNames::inputTag)); |
677 // Note that we only show the autofill popup in this case if the caret is at | 678 // Note that we only show the autofill popup in this case if the caret is at |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 const String& value = inputElement->value(); | 738 const String& value = inputElement->value(); |
738 | 739 |
739 // Enforce autofill_on_empty_value and caret_at_end. | 740 // Enforce autofill_on_empty_value and caret_at_end. |
740 | 741 |
741 bool isCaretAtEnd = true; | 742 bool isCaretAtEnd = true; |
742 if (args->requireCaretAtEnd) | 743 if (args->requireCaretAtEnd) |
743 isCaretAtEnd = inputElement->selectionStart() == inputElement->selectionEnd() | 744 isCaretAtEnd = inputElement->selectionStart() == inputElement->selectionEnd() |
744 && inputElement->selectionEnd() == static_cast<int>(value.length()); | 745 && inputElement->selectionEnd() == static_cast<int>(value.length()); |
745 | 746 |
746 if ((!args->autofillOnEmptyValue && value.isEmpty()) || !isCaretAtEnd) { | 747 if ((!args->autofillOnEmptyValue && value.isEmpty()) || !isCaretAtEnd) { |
747 m_webView->HideAutoCompletePopup(); | 748 m_webView->hideAutoCompletePopup(); |
748 return; | 749 return; |
749 } | 750 } |
750 | 751 |
751 // 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. |
752 // 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 |
753 // a node would be confusing. | 754 // a node would be confusing. |
754 WebFrameImpl* webframe = WebFrameImpl::FromFrame(inputElement->document()->frame()); | 755 WebFrameImpl* webframe = WebFrameImpl::fromFrame(inputElement->document()->frame()); |
755 PasswordAutocompleteListener* listener = webframe->GetPasswordListener(inputElement); | 756 PasswordAutocompleteListener* listener = webframe->getPasswordListener(inputElement); |
756 if (listener) { | 757 if (listener) { |
757 if (args->autofillFormOnly) | 758 if (args->autofillFormOnly) |
758 return; | 759 return; |
759 | 760 |
760 listener->performInlineAutocomplete(value, | 761 listener->performInlineAutocomplete(value, |
761 args->backspaceOrDeletePressed, | 762 args->backspaceOrDeletePressed, |
762 true); | 763 true); |
763 return; | 764 return; |
764 } | 765 } |
765 | 766 |
766 // Then trigger form autofill. | 767 // Then trigger form autofill. |
767 WebString name = WebKit::nameOfInputElement(inputElement); | 768 WebString name = WebKit::nameOfInputElement(inputElement); |
768 ASSERT(static_cast<int>(name.length()) > 0); | 769 ASSERT(static_cast<int>(name.length()) > 0); |
769 | 770 |
770 if (m_webView->client()) | 771 if (m_webView->client()) |
771 m_webView->client()->queryAutofillSuggestions(WebNode(inputElement), | 772 m_webView->client()->queryAutofillSuggestions(WebNode(inputElement), |
772 name, WebString(value)); | 773 name, WebString(value)); |
773 } | 774 } |
774 | 775 |
775 void EditorClientImpl::cancelPendingAutofill() | 776 void EditorClientImpl::cancelPendingAutofill() |
776 { | 777 { |
777 m_autofillArgs.clear(); | 778 m_autofillArgs.clear(); |
778 m_autofillTimer.stop(); | 779 m_autofillTimer.stop(); |
779 } | 780 } |
780 | 781 |
781 void EditorClientImpl::onAutofillSuggestionAccepted(HTMLInputElement* textField) | 782 void EditorClientImpl::onAutofillSuggestionAccepted(HTMLInputElement* textField) |
782 { | 783 { |
783 WebFrameImpl* webframe = WebFrameImpl::FromFrame(textField->document()->frame()); | 784 WebFrameImpl* webframe = WebFrameImpl::fromFrame(textField->document()->frame()); |
784 PasswordAutocompleteListener* listener = webframe->GetPasswordListener(textField); | 785 PasswordAutocompleteListener* listener = webframe->getPasswordListener(textField); |
785 // Password listeners need to autocomplete other fields that depend on the | 786 // Password listeners need to autocomplete other fields that depend on the |
786 // input element with autofill suggestions. | 787 // input element with autofill suggestions. |
787 if (listener) | 788 if (listener) |
788 listener->performInlineAutocomplete(textField->value(), false, false); | 789 listener->performInlineAutocomplete(textField->value(), false, false); |
789 } | 790 } |
790 | 791 |
791 bool EditorClientImpl::doTextFieldCommandFromEvent(Element* element, | 792 bool EditorClientImpl::doTextFieldCommandFromEvent(Element* element, |
792 KeyboardEvent* event) | 793 KeyboardEvent* event) |
793 { | 794 { |
794 // Remember if backspace was pressed for the autofill. It is not clear how to | 795 // Remember if backspace was pressed for the autofill. It is not clear how to |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 notImplemented(); | 905 notImplemented(); |
905 } | 906 } |
906 | 907 |
907 void EditorClientImpl::setInputMethodState(bool enabled) | 908 void EditorClientImpl::setInputMethodState(bool enabled) |
908 { | 909 { |
909 if (m_webView->client()) | 910 if (m_webView->client()) |
910 m_webView->client()->setInputMethodEnabled(enabled); | 911 m_webView->client()->setInputMethodEnabled(enabled); |
911 } | 912 } |
912 | 913 |
913 } // namesace WebKit | 914 } // namesace WebKit |
OLD | NEW |