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 class WebViewImpl; |
| 43 |
| 44 namespace WebKit { |
| 45 |
| 46 class EditorClientImpl : public WebCore::EditorClient { |
| 47 public: |
| 48 EditorClientImpl(WebViewImpl* webView); |
| 49 |
| 50 virtual ~EditorClientImpl(); |
| 51 virtual void pageDestroyed(); |
| 52 |
| 53 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*); |
| 54 virtual bool smartInsertDeleteEnabled(); |
| 55 virtual bool isSelectTrailingWhitespaceEnabled(); |
| 56 virtual bool isContinuousSpellCheckingEnabled(); |
| 57 virtual void toggleContinuousSpellChecking(); |
| 58 virtual bool isGrammarCheckingEnabled(); |
| 59 virtual void toggleGrammarChecking(); |
| 60 virtual int spellCheckerDocumentTag(); |
| 61 virtual bool isEditable(); |
| 62 virtual bool shouldBeginEditing(WebCore::Range*); |
| 63 virtual bool shouldEndEditing(WebCore::Range*); |
| 64 virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction); |
| 65 virtual bool shouldInsertText(const WebCore::String&, WebCore::Range*, WebCore::EditorInsertAction); |
| 66 virtual bool shouldDeleteRange(WebCore::Range*); |
| 67 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, |
| 68 WebCore::Range* toRange, |
| 69 WebCore::EAffinity, |
| 70 bool stillSelecting); |
| 71 virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*); |
| 72 virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*); |
| 73 virtual void didBeginEditing(); |
| 74 virtual void respondToChangedContents(); |
| 75 virtual void respondToChangedSelection(); |
| 76 virtual void didEndEditing(); |
| 77 virtual void didWriteSelectionToPasteboard(); |
| 78 virtual void didSetSelectionTypesForPasteboard(); |
| 79 virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>); |
| 80 virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>); |
| 81 virtual void clearUndoRedoOperations(); |
| 82 virtual bool canUndo() const; |
| 83 virtual bool canRedo() const; |
| 84 virtual void undo(); |
| 85 virtual void redo(); |
| 86 virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*); |
| 87 virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*); |
| 88 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*); |
| 89 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*); |
| 90 virtual void textFieldDidBeginEditing(WebCore::Element*); |
| 91 virtual void textFieldDidEndEditing(WebCore::Element*); |
| 92 virtual void textDidChangeInTextField(WebCore::Element*); |
| 93 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*); |
| 94 virtual void textWillBeDeletedInTextField(WebCore::Element*); |
| 95 virtual void textDidChangeInTextArea(WebCore::Element*); |
| 96 virtual void ignoreWordInSpellDocument(const WebCore::String&); |
| 97 virtual void learnWord(const WebCore::String&); |
| 98 virtual void checkSpellingOfString(const UChar*, int length, |
| 99 int* misspellingLocation, |
| 100 int* misspellingLength); |
| 101 virtual void checkGrammarOfString(const UChar*, int length, |
| 102 WTF::Vector<WebCore::GrammarDetail>&, |
| 103 int* badGrammarLocation, |
| 104 int* badGrammarLength); |
| 105 virtual WebCore::String getAutoCorrectSuggestionForMisspelledWord(const WebCore::String&); |
| 106 virtual void updateSpellingUIWithGrammarString(const WebCore::String&, const WebCore::GrammarDetail&); |
| 107 virtual void updateSpellingUIWithMisspelledWord(const WebCore::String&); |
| 108 virtual void showSpellingUI(bool show); |
| 109 virtual bool spellingUIIsShowing(); |
| 110 virtual void getGuessesForWord(const WebCore::String& word, |
| 111 WTF::Vector<WebCore::String>& guesses); |
| 112 virtual void setInputMethodState(bool enabled); |
| 113 |
| 114 // Shows the form autofill popup for |node| if it is an HTMLInputElement and |
| 115 // it is empty. This is called when you press the up or down arrow in a |
| 116 // text-field or when clicking an already focused text-field. |
| 117 // Returns true if the autofill popup has been scheduled to be shown, false |
| 118 // otherwise. |
| 119 virtual bool showFormAutofillForNode(WebCore::Node*); |
| 120 |
| 121 // Notification that the text changed due to acceptance of a suggestion |
| 122 // provided by an autofill popup. Having a separate callback in this case |
| 123 // is a simple way to break the cycle that would otherwise occur if |
| 124 // textDidChangeInTextField was called. |
| 125 virtual void onAutofillSuggestionAccepted(WebCore::HTMLInputElement*); |
| 126 |
| 127 private: |
| 128 void modifySelection(WebCore::Frame*, WebCore::KeyboardEvent*); |
| 129 |
| 130 // Triggers autofill for an input element if applicable. This can be form |
| 131 // autofill (via a popup-menu) or password autofill depending on the |
| 132 // input element. If |formAutofillOnly| is true, password autofill is not |
| 133 // triggered. |
| 134 // |autofillOnEmptyValue| indicates whether the autofill should be shown |
| 135 // when the text-field is empty. |
| 136 // If |requiresCaretAtEnd| is true, the autofill popup is only shown if the |
| 137 // caret is located at the end of the entered text. |
| 138 // Returns true if the autofill popup has been scheduled to be shown, false |
| 139 // otherwise. |
| 140 bool autofill(WebCore::HTMLInputElement*, |
| 141 bool formAutofillOnly, bool autofillOnEmptyValue, |
| 142 bool requiresCaretAtEnd); |
| 143 |
| 144 // Called to process the autofill described by m_autofillArgs. |
| 145 // This method is invoked asynchronously if the caret position is not |
| 146 // reflecting the last text change yet, and we need it to decide whether or |
| 147 // not to show the autofill popup. |
| 148 void doAutofill(WebCore::Timer<EditorClientImpl>*); |
| 149 |
| 150 void cancelPendingAutofill(); |
| 151 |
| 152 // Returns whether or not the focused control needs spell-checking. |
| 153 // Currently, this function just retrieves the focused node and determines |
| 154 // whether or not it is a <textarea> element or an element whose |
| 155 // contenteditable attribute is true. |
| 156 // FIXME: Bug 740540: This code just implements the default behavior |
| 157 // proposed in this issue. We should also retrieve "spellcheck" attributes |
| 158 // for text fields and create a flag to over-write the default behavior. |
| 159 bool shouldSpellcheckByDefault(); |
| 160 |
| 161 WebViewImpl* m_webView; |
| 162 bool m_inRedo; |
| 163 |
| 164 typedef Deque<RefPtr<WebCore::EditCommand> > EditCommandStack; |
| 165 EditCommandStack m_undoStack; |
| 166 EditCommandStack m_redoStack; |
| 167 |
| 168 // Whether the last entered key was a backspace. |
| 169 bool m_backspaceOrDeletePressed; |
| 170 |
| 171 // This flag is set to false if spell check for this editor is manually |
| 172 // turned off. The default setting is SpellCheckAutomatic. |
| 173 enum { |
| 174 SpellCheckAutomatic, |
| 175 SpellCheckForcedOn, |
| 176 SpellCheckForcedOff |
| 177 }; |
| 178 int m_spellCheckThisFieldStatus; |
| 179 |
| 180 // Used to delay autofill processing. |
| 181 WebCore::Timer<EditorClientImpl> m_autofillTimer; |
| 182 |
| 183 struct AutofillArgs { |
| 184 RefPtr<WebCore::HTMLInputElement> inputElement; |
| 185 bool autofillFormOnly; |
| 186 bool autofillOnEmptyValue; |
| 187 bool requireCaretAtEnd; |
| 188 bool backspaceOrDeletePressed; |
| 189 }; |
| 190 OwnPtr<AutofillArgs> m_autofillArgs; |
| 191 }; |
| 192 |
| 193 } // namespace WebKit |
| 194 |
| 195 #endif |
OLD | NEW |