2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef EditorClientImpl_h
32 #define EditorClientImpl_h
34 #include "EditorClient.h"
35 #include "TextCheckerClient.h"
37 #include <wtf/Deque.h>
40 class HTMLInputElement;
47 class EditorClientImpl : public WebCore::EditorClient, public WebCore::TextCheckerClient {
49 EditorClientImpl(WebViewImpl* webView);
51 virtual ~EditorClientImpl();
52 virtual void pageDestroyed();
54 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
55 virtual bool smartInsertDeleteEnabled();
56 virtual bool isSelectTrailingWhitespaceEnabled();
57 virtual bool isContinuousSpellCheckingEnabled();
58 virtual void toggleContinuousSpellChecking();
59 virtual bool isGrammarCheckingEnabled();
60 virtual void toggleGrammarChecking();
61 virtual int spellCheckerDocumentTag();
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 WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
66 virtual bool shouldDeleteRange(WebCore::Range*);
67 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange,
68 WebCore::Range* toRange,
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 canCopyCut(WebCore::Frame*, bool defaultValue) const;
83 virtual bool canPaste(WebCore::Frame*, bool defaultValue) const;
84 virtual bool canUndo() const;
85 virtual bool canRedo() const;
88 virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
89 virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
90 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
91 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
92 virtual void textFieldDidBeginEditing(WebCore::Element*);
93 virtual void textFieldDidEndEditing(WebCore::Element*);
94 virtual void textDidChangeInTextField(WebCore::Element*);
95 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
96 virtual void textWillBeDeletedInTextField(WebCore::Element*);
97 virtual void textDidChangeInTextArea(WebCore::Element*);
98 virtual void ignoreWordInSpellDocument(const WTF::String&);
99 virtual void learnWord(const WTF::String&);
100 virtual void checkSpellingOfString(const UChar*, int length,
101 int* misspellingLocation,
102 int* misspellingLength);
103 virtual void checkGrammarOfString(const UChar*, int length,
104 WTF::Vector<WebCore::GrammarDetail>&,
105 int* badGrammarLocation,
106 int* badGrammarLength);
107 virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&);
108 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
109 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
110 virtual void showSpellingUI(bool show);
111 virtual bool spellingUIIsShowing();
112 virtual void getGuessesForWord(const WTF::String& word,
113 const WTF::String& context,
114 WTF::Vector<WTF::String>& guesses);
115 virtual void willSetInputMethodState();
116 virtual void setInputMethodState(bool enabled);
117 virtual void requestCheckingOfString(WebCore::SpellChecker*, int, WebCore::TextCheckingTypeMask, const WTF::String&);
119 virtual WebCore::TextCheckerClient* textChecker() { return this; }
122 void modifySelection(WebCore::Frame*, WebCore::KeyboardEvent*);
124 // Returns whether or not the focused control needs spell-checking.
125 // Currently, this function just retrieves the focused node and determines
126 // whether or not it is a <textarea> element or an element whose
127 // contenteditable attribute is true.
128 // FIXME: Bug 740540: This code just implements the default behavior
129 // proposed in this issue. We should also retrieve "spellcheck" attributes
130 // for text fields and create a flag to over-write the default behavior.
131 bool shouldSpellcheckByDefault();
133 WebViewImpl* m_webView;
136 typedef Deque<RefPtr<WebCore::EditCommand> > EditCommandStack;
137 EditCommandStack m_undoStack;
138 EditCommandStack m_redoStack;
140 // This flag is set to false if spell check for this editor is manually
141 // turned off. The default setting is SpellCheckAutomatic.
147 int m_spellCheckThisFieldStatus;
150 } // namespace WebKit