[GTK] REGRESSION(r116135): Keys that confirm composition trigger a default action
[WebKit-https.git] / Source / WebKit / gtk / WebCoreSupport / EditorClientGtk.h
1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
4  * Copyright (C) 2006 Apple Computer, Inc.
5  * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org>
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * 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 EditorClientGtk_h
32 #define EditorClientGtk_h
33
34 #include "EditorClient.h"
35 #include "KeyBindingTranslator.h"
36 #include "TextCheckerClient.h"
37 #include <wtf/Deque.h>
38 #include <wtf/Forward.h>
39 #include <wtf/gobject/GOwnPtr.h>
40 #include <wtf/gobject/GRefPtr.h>
41
42 #if ENABLE(SPELLCHECK)
43 #include "TextCheckerClientGtk.h"
44 #else
45 #include "EmptyClients.h"
46 #endif
47
48 typedef struct _WebKitWebView WebKitWebView;
49
50 namespace WebCore {
51 class Frame;
52 class KeyboardEvent;
53 }
54
55 namespace WebKit {
56
57 class EditorClient : public WebCore::EditorClient {
58     protected:
59         bool m_isInRedo;
60
61         WTF::Deque<WTF::RefPtr<WebCore::UndoStep> > undoStack;
62         WTF::Deque<WTF::RefPtr<WebCore::UndoStep> > redoStack;
63
64     public:
65         EditorClient(WebKitWebView*);
66         ~EditorClient();
67         WebKitWebView* webView() { return m_webView; }
68         void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
69         void generateEditorCommands(const WebCore::KeyboardEvent*);
70         bool executePendingEditorCommands(WebCore::Frame*, bool);
71
72         // from EditorClient
73         virtual void pageDestroyed();
74         virtual void frameWillDetachPage(WebCore::Frame*) { }
75
76         virtual bool shouldDeleteRange(WebCore::Range*);
77         virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
78         virtual bool smartInsertDeleteEnabled();
79         void setSmartInsertDeleteEnabled(bool);
80         virtual bool isSelectTrailingWhitespaceEnabled();
81         virtual bool isContinuousSpellCheckingEnabled();
82         virtual void toggleContinuousSpellChecking();
83         virtual bool isGrammarCheckingEnabled();
84         virtual void toggleGrammarChecking();
85         virtual int spellCheckerDocumentTag();
86
87         virtual bool shouldBeginEditing(WebCore::Range*);
88         virtual bool shouldEndEditing(WebCore::Range*);
89         virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction);
90         virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
91         virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting);
92
93         virtual bool shouldApplyStyle(WebCore::StylePropertySet*, WebCore::Range*);
94
95         virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
96
97         virtual void didBeginEditing();
98         virtual void respondToChangedContents();
99         virtual void respondToChangedSelection(WebCore::Frame*);
100         virtual void didEndEditing();
101         virtual void didWriteSelectionToPasteboard();
102         virtual void didSetSelectionTypesForPasteboard();
103
104         virtual void registerUndoStep(WTF::PassRefPtr<WebCore::UndoStep>);
105         virtual void registerRedoStep(WTF::PassRefPtr<WebCore::UndoStep>);
106         virtual void clearUndoRedoOperations();
107
108         virtual bool canCopyCut(WebCore::Frame*, bool defaultValue) const;
109         virtual bool canPaste(WebCore::Frame*, bool defaultValue) const;
110         virtual bool canUndo() const;
111         virtual bool canRedo() const;
112
113         virtual void undo();
114         virtual void redo();
115
116         virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
117         virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
118
119         virtual void textFieldDidBeginEditing(WebCore::Element*);
120         virtual void textFieldDidEndEditing(WebCore::Element*);
121         virtual void textDidChangeInTextField(WebCore::Element*);
122         virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
123         virtual void textWillBeDeletedInTextField(WebCore::Element*);
124         virtual void textDidChangeInTextArea(WebCore::Element*);
125
126         virtual WebCore::TextCheckerClient* textChecker() { return &m_textCheckerClient; }
127
128         virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
129         virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
130         virtual void showSpellingUI(bool show);
131         virtual bool spellingUIIsShowing();
132         virtual void willSetInputMethodState();
133         virtual void setInputMethodState(bool enabled);
134
135         virtual bool shouldShowUnicodeMenu();
136
137     private:
138 #if ENABLE(SPELLCHECK)
139         TextCheckerClientGtk m_textCheckerClient;
140 #else
141         WebCore::EmptyTextCheckerClient m_textCheckerClient;
142 #endif
143         WebKitWebView* m_webView;
144         WebCore::KeyBindingTranslator m_keyBindingTranslator;
145         Vector<WTF::String> m_pendingEditorCommands;
146         bool m_smartInsertDeleteEnabled;
147     };
148 }
149
150 #endif
151
152 // vim: ts=4 sw=4 et