2011-02-19 Ryuan Choi <ryuan.choi@samsung.com>
[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 "TextCheckerClient.h"
36
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 "TextCheckerClientEnchant.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::EditCommand> > undoStack;
62         WTF::Deque<WTF::RefPtr<WebCore::EditCommand> > redoStack;
63
64     public:
65         EditorClient(WebKitWebView*);
66         ~EditorClient();
67         WebKitWebView* webView() { return m_webView; }
68         bool treatContextCommitAsKeyEvent() { return m_treatContextCommitAsKeyEvent; }
69         bool preventNextCompositionCommit() { return m_preventNextCompositionCommit; }
70         void clearPendingComposition() { m_pendingComposition.set(0); }
71         bool hasPendingComposition() { return m_pendingComposition; }
72         void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
73         void updatePendingComposition(const char*);
74         void generateEditorCommands(const WebCore::KeyboardEvent*);
75         bool executePendingEditorCommands(WebCore::Frame*, bool);
76
77         // from EditorClient
78         virtual void pageDestroyed();
79
80         virtual bool shouldDeleteRange(WebCore::Range*);
81         virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
82         virtual bool smartInsertDeleteEnabled();
83         virtual bool isSelectTrailingWhitespaceEnabled();
84         virtual bool isContinuousSpellCheckingEnabled();
85         virtual void toggleContinuousSpellChecking();
86         virtual bool isGrammarCheckingEnabled();
87         virtual void toggleGrammarChecking();
88         virtual int spellCheckerDocumentTag();
89
90         virtual bool isEditable();
91
92         virtual bool shouldBeginEditing(WebCore::Range*);
93         virtual bool shouldEndEditing(WebCore::Range*);
94         virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction);
95         virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
96         virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting);
97
98         virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
99
100         virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
101
102         virtual void didBeginEditing();
103         virtual void respondToChangedContents();
104         virtual void respondToChangedSelection();
105         virtual void didEndEditing();
106         virtual void didWriteSelectionToPasteboard();
107         virtual void didSetSelectionTypesForPasteboard();
108
109         virtual void registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>);
110         virtual void registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>);
111         virtual void clearUndoRedoOperations();
112
113         virtual bool canCopyCut(bool defaultValue) const;
114         virtual bool canPaste(bool defaultValue) const;
115         virtual bool canUndo() const;
116         virtual bool canRedo() const;
117
118         virtual void undo();
119         virtual void redo();
120
121         virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
122         virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
123         virtual void handleInputMethodMousePress();
124
125         virtual void textFieldDidBeginEditing(WebCore::Element*);
126         virtual void textFieldDidEndEditing(WebCore::Element*);
127         virtual void textDidChangeInTextField(WebCore::Element*);
128         virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
129         virtual void textWillBeDeletedInTextField(WebCore::Element*);
130         virtual void textDidChangeInTextArea(WebCore::Element*);
131
132         virtual WebCore::TextCheckerClient* textChecker() { return &m_textCheckerClient; }
133
134         virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
135         virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
136         virtual void showSpellingUI(bool show);
137         virtual bool spellingUIIsShowing();
138         virtual void willSetInputMethodState();
139         virtual void setInputMethodState(bool enabled);
140
141     private:
142 #if ENABLE(SPELLCHECK)
143         TextCheckerClientEnchant m_textCheckerClient;
144 #else
145         WebCore::EmptyTextCheckerClient m_textCheckerClient;
146 #endif
147         WebKitWebView* m_webView;
148         bool m_preventNextCompositionCommit;
149         bool m_treatContextCommitAsKeyEvent;
150         GOwnPtr<gchar> m_pendingComposition;
151         Vector<const char*> m_pendingEditorCommands;
152         GRefPtr<GtkWidget> m_nativeWidget;
153     };
154 }
155
156 #endif
157
158 // vim: ts=4 sw=4 et