| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef EditorClientImpl_h | |
| 32 #define EditorClientImpl_h | |
| 33 | |
| 34 #include "EditorClient.h" | |
| 35 #include "Timer.h" | |
| 36 #include <wtf/Deque.h> | |
| 37 | |
| 38 namespace WebCore { | |
| 39 class HTMLInputElement; | |
| 40 } | |
| 41 | |
| 42 namespace WebKit { | |
| 43 class WebViewImpl; | |
| 44 | |
| 45 class EditorClientImpl : public WebCore::EditorClient { | |
| 46 public: | |
| 47 EditorClientImpl(WebViewImpl* webView); | |
| 48 | |
| 49 virtual ~EditorClientImpl(); | |
| 50 virtual void pageDestroyed(); | |
| 51 | |
| 52 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*); | |
| 53 virtual bool smartInsertDeleteEnabled(); | |
| 54 virtual bool isSelectTrailingWhitespaceEnabled(); | |
| 55 virtual bool isContinuousSpellCheckingEnabled(); | |
| 56 virtual void toggleContinuousSpellChecking(); | |
| 57 virtual bool isGrammarCheckingEnabled(); | |
| 58 virtual void toggleGrammarChecking(); | |
| 59 virtual int spellCheckerDocumentTag(); | |
| 60 virtual bool isEditable(); | |
| 61 virtual bool shouldBeginEditing(WebCore::Range*); | |
| 62 virtual bool shouldEndEditing(WebCore::Range*); | |
| 63 virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction); | |
| 64 virtual bool shouldInsertText(const WebCore::String&, WebCore::Range*, WebCore::EditorInsertAction); | |
| 65 virtual bool shouldDeleteRange(WebCore::Range*); | |
| 66 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, | |
| 67 WebCore::Range* toRange, | |
| 68 WebCore::EAffinity, | |
| 69 bool stillSelecting); | |
| 70 virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*); | |
| 71 virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*); | |
| 72 virtual void didBeginEditing(); | |
| 73 virtual void respondToChangedContents(); | |
| 74 virtual void respondToChangedSelection(); | |
| 75 virtual void didEndEditing(); | |
| 76 virtual void didWriteSelectionToPasteboard(); | |
| 77 virtual void didSetSelectionTypesForPasteboard(); | |
| 78 virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>); | |
| 79 virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>); | |
| 80 virtual void clearUndoRedoOperations(); | |
| 81 virtual bool canUndo() const; | |
| 82 virtual bool canRedo() const; | |
| 83 virtual void undo(); | |
| 84 virtual void redo(); | |
| 85 virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*); | |
| 86 virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*); | |
| 87 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*); | |
| 88 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*); | |
| 89 virtual void textFieldDidBeginEditing(WebCore::Element*); | |
| 90 virtual void textFieldDidEndEditing(WebCore::Element*); | |
| 91 virtual void textDidChangeInTextField(WebCore::Element*); | |
| 92 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*); | |
| 93 virtual void textWillBeDeletedInTextField(WebCore::Element*); | |
| 94 virtual void textDidChangeInTextArea(WebCore::Element*); | |
| 95 virtual void ignoreWordInSpellDocument(const WebCore::String&); | |
| 96 virtual void learnWord(const WebCore::String&); | |
| 97 virtual void checkSpellingOfString(const UChar*, int length, | |
| 98 int* misspellingLocation, | |
| 99 int* misspellingLength); | |
| 100 virtual void checkGrammarOfString(const UChar*, int length, | |
| 101 WTF::Vector<WebCore::GrammarDetail>&, | |
| 102 int* badGrammarLocation, | |
| 103 int* badGrammarLength); | |
| 104 virtual WebCore::String getAutoCorrectSuggestionForMisspelledWord(const WebCore::String&); | |
| 105 virtual void updateSpellingUIWithGrammarString(const WebCore::String&, const WebCore::GrammarDetail&); | |
| 106 virtual void updateSpellingUIWithMisspelledWord(const WebCore::String&); | |
| 107 virtual void showSpellingUI(bool show); | |
| 108 virtual bool spellingUIIsShowing(); | |
| 109 virtual void getGuessesForWord(const WebCore::String& word, | |
| 110 WTF::Vector<WebCore::String>& guesses); | |
| 111 virtual void setInputMethodState(bool enabled); | |
| 112 | |
| 113 // Shows the form autofill popup for |node| if it is an HTMLInputElement and | |
| 114 // it is empty. This is called when you press the up or down arrow in a | |
| 115 // text-field or when clicking an already focused text-field. | |
| 116 // Returns true if the autofill popup has been scheduled to be shown, false | |
| 117 // otherwise. | |
| 118 virtual bool showFormAutofillForNode(WebCore::Node*); | |
| 119 | |
| 120 // Notification that the text changed due to acceptance of a suggestion | |
| 121 // provided by an autofill popup. Having a separate callback in this case | |
| 122 // is a simple way to break the cycle that would otherwise occur if | |
| 123 // textDidChangeInTextField was called. | |
| 124 virtual void onAutofillSuggestionAccepted(WebCore::HTMLInputElement*); | |
| 125 | |
| 126 private: | |
| 127 void modifySelection(WebCore::Frame*, WebCore::KeyboardEvent*); | |
| 128 | |
| 129 // Triggers autofill for an input element if applicable. This can be form | |
| 130 // autofill (via a popup-menu) or password autofill depending on the | |
| 131 // input element. If |formAutofillOnly| is true, password autofill is not | |
| 132 // triggered. | |
| 133 // |autofillOnEmptyValue| indicates whether the autofill should be shown | |
| 134 // when the text-field is empty. | |
| 135 // If |requiresCaretAtEnd| is true, the autofill popup is only shown if the | |
| 136 // caret is located at the end of the entered text. | |
| 137 // Returns true if the autofill popup has been scheduled to be shown, false | |
| 138 // otherwise. | |
| 139 bool autofill(WebCore::HTMLInputElement*, | |
| 140 bool formAutofillOnly, bool autofillOnEmptyValue, | |
| 141 bool requiresCaretAtEnd); | |
| 142 | |
| 143 // Called to process the autofill described by m_autofillArgs. | |
| 144 // This method is invoked asynchronously if the caret position is not | |
| 145 // reflecting the last text change yet, and we need it to decide whether or | |
| 146 // not to show the autofill popup. | |
| 147 void doAutofill(WebCore::Timer<EditorClientImpl>*); | |
| 148 | |
| 149 void cancelPendingAutofill(); | |
| 150 | |
| 151 // Returns whether or not the focused control needs spell-checking. | |
| 152 // Currently, this function just retrieves the focused node and determines | |
| 153 // whether or not it is a <textarea> element or an element whose | |
| 154 // contenteditable attribute is true. | |
| 155 // FIXME: Bug 740540: This code just implements the default behavior | |
| 156 // proposed in this issue. We should also retrieve "spellcheck" attributes | |
| 157 // for text fields and create a flag to over-write the default behavior. | |
| 158 bool shouldSpellcheckByDefault(); | |
| 159 | |
| 160 WebViewImpl* m_webView; | |
| 161 bool m_inRedo; | |
| 162 | |
| 163 typedef Deque<RefPtr<WebCore::EditCommand> > EditCommandStack; | |
| 164 EditCommandStack m_undoStack; | |
| 165 EditCommandStack m_redoStack; | |
| 166 | |
| 167 // Whether the last entered key was a backspace. | |
| 168 bool m_backspaceOrDeletePressed; | |
| 169 | |
| 170 // This flag is set to false if spell check for this editor is manually | |
| 171 // turned off. The default setting is SpellCheckAutomatic. | |
| 172 enum { | |
| 173 SpellCheckAutomatic, | |
| 174 SpellCheckForcedOn, | |
| 175 SpellCheckForcedOff | |
| 176 }; | |
| 177 int m_spellCheckThisFieldStatus; | |
| 178 | |
| 179 // Used to delay autofill processing. | |
| 180 WebCore::Timer<EditorClientImpl> m_autofillTimer; | |
| 181 | |
| 182 struct AutofillArgs { | |
| 183 RefPtr<WebCore::HTMLInputElement> inputElement; | |
| 184 bool autofillFormOnly; | |
| 185 bool autofillOnEmptyValue; | |
| 186 bool requireCaretAtEnd; | |
| 187 bool backspaceOrDeletePressed; | |
| 188 }; | |
| 189 OwnPtr<AutofillArgs> m_autofillArgs; | |
| 190 }; | |
| 191 | |
| 192 } // namespace WebKit | |
| 193 | |
| 194 #endif | |
| OLD | NEW |