5a2b9d52c89bb6fd35cc75c415c6d63e6a0799f7
[WebKit-https.git] / WebKit / gtk / WebCoreSupport / EditorClientGtk.cpp
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  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "config.h"
31 #include "EditorClientGtk.h"
32
33 #include "EditCommand.h"
34 #include "Editor.h"
35 #include "FocusController.h"
36 #include "Frame.h"
37 #include "KeyboardCodes.h"
38 #include "KeyboardEvent.h"
39 #include "NotImplemented.h"
40 #include "Page.h"
41 #include "PlatformKeyboardEvent.h"
42 #include "webkitgtkprivate.h"
43
44 #include <stdio.h>
45
46 using namespace WebCore;
47
48 namespace WebKit {
49
50 bool EditorClient::shouldDeleteRange(Range*)
51 {
52     notImplemented();
53     return true;
54 }
55
56 bool EditorClient::shouldShowDeleteInterface(HTMLElement*)
57 {
58     return false;
59 }
60
61 bool EditorClient::isContinuousSpellCheckingEnabled()
62 {
63     notImplemented();
64     return false;
65 }
66
67 bool EditorClient::isGrammarCheckingEnabled()
68 {
69     notImplemented();
70     return false;
71 }
72
73 int EditorClient::spellCheckerDocumentTag()
74 {
75     notImplemented();
76     return 0;
77 }
78
79 bool EditorClient::shouldBeginEditing(WebCore::Range*)
80 {
81     notImplemented();
82     return true;
83 }
84
85 bool EditorClient::shouldEndEditing(WebCore::Range*)
86 {
87     notImplemented();
88     return true;
89 }
90
91 bool EditorClient::shouldInsertText(String, Range*, EditorInsertAction)
92 {
93     notImplemented();
94     return true;
95 }
96
97 bool EditorClient::shouldChangeSelectedRange(Range*, Range*, EAffinity, bool)
98 {
99     notImplemented();
100     return true;
101 }
102
103 bool EditorClient::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
104                                       WebCore::Range*)
105 {
106     notImplemented();
107     return true;
108 }
109
110 bool EditorClient::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*)
111 {
112     notImplemented();
113     return true;
114 }
115
116 void EditorClient::didBeginEditing()
117 {
118     notImplemented();
119 }
120
121 void EditorClient::respondToChangedContents()
122 {
123     notImplemented();
124 }
125
126 void EditorClient::respondToChangedSelection()
127 {
128     notImplemented();
129 }
130
131 void EditorClient::didEndEditing()
132 {
133     notImplemented();
134 }
135
136 void EditorClient::didWriteSelectionToPasteboard()
137 {
138     notImplemented();
139 }
140
141 void EditorClient::didSetSelectionTypesForPasteboard()
142 {
143     notImplemented();
144 }
145
146 bool EditorClient::isEditable()
147 {
148     notImplemented();
149     return false;
150 }
151
152 void EditorClient::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>)
153 {
154     notImplemented();
155 }
156
157 void EditorClient::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
158 {
159     notImplemented();
160 }
161
162 void EditorClient::clearUndoRedoOperations()
163 {
164     notImplemented();
165 }
166
167 bool EditorClient::canUndo() const
168 {
169     notImplemented();
170     return false;
171 }
172
173 bool EditorClient::canRedo() const
174 {
175     notImplemented();
176     return false;
177 }
178
179 void EditorClient::undo()
180 {
181     notImplemented();
182 }
183
184 void EditorClient::redo()
185 {
186     notImplemented();
187 }
188
189 bool EditorClient::shouldInsertNode(Node*, Range*, EditorInsertAction)
190 {
191     notImplemented();
192     return true;
193 }
194
195 void EditorClient::pageDestroyed()
196 {
197     delete this;
198 }
199
200 bool EditorClient::smartInsertDeleteEnabled()
201 {
202     notImplemented();
203     return false;
204 }
205
206 void EditorClient::toggleContinuousSpellChecking()
207 {
208     notImplemented();
209 }
210
211 void EditorClient::toggleGrammarChecking()
212 {
213 }
214
215 void EditorClient::handleKeypress(KeyboardEvent* event)
216 {
217     Frame* frame = core(m_page)->focusController()->focusedOrMainFrame();
218     if (!frame)
219         return;
220
221     const PlatformKeyboardEvent* kevent = event->keyEvent();
222     if (!kevent->isKeyUp()) {
223         Node* start = frame->selectionController()->start().node();
224         if (start && start->isContentEditable()) {
225             switch (kevent->WindowsKeyCode()) {
226             case VK_BACK:
227                 frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
228                                                      CharacterGranularity, false, true);
229                 break;
230             case VK_DELETE:
231                 frame->editor()->deleteWithDirection(SelectionController::FORWARD,
232                                                      CharacterGranularity, false, true);
233                 break;
234             case VK_LEFT:
235                 frame->editor()->execCommand("MoveLeft");
236                 break;
237             case VK_RIGHT:
238                 frame->editor()->execCommand("MoveRight");
239                 break;
240             case VK_UP:
241                 frame->editor()->execCommand("MoveUp");
242                 break;
243             case VK_DOWN:
244                 frame->editor()->execCommand("MoveDown");
245                 break;
246             default:
247                 if (kevent->text().length() == 1) {
248                     UChar ch = kevent->text()[0];
249                     // Don't insert null or control characters as they can result in unexpected behaviour
250                     if (ch < ' ')
251                         break;
252                 }
253                 frame->editor()->insertText(kevent->text(), event);
254             }
255             event->setDefaultHandled();
256         }
257     }
258 }
259
260
261 void EditorClient::handleInputMethodKeypress(KeyboardEvent*)
262 {
263     notImplemented();
264 }
265
266 EditorClient::EditorClient(WebKitPage* page)
267     : m_page(page)
268 {
269 }
270
271 void EditorClient::textFieldDidBeginEditing(Element*)
272 {
273     notImplemented();
274 }
275
276 void EditorClient::textFieldDidEndEditing(Element*)
277 {
278     notImplemented();
279 }
280
281 void EditorClient::textDidChangeInTextField(Element*)
282 {
283     notImplemented();
284 }
285
286 bool EditorClient::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
287 {
288     notImplemented();
289     return false;
290 }
291
292 void EditorClient::textWillBeDeletedInTextField(Element*)
293 {
294     notImplemented();
295 }
296
297 void EditorClient::textDidChangeInTextArea(Element*)
298 {
299     notImplemented();
300 }
301
302 void EditorClient::ignoreWordInSpellDocument(const String&)
303 {
304     notImplemented();
305 }
306
307 void EditorClient::learnWord(const String&)
308 {
309     notImplemented();
310 }
311
312 void EditorClient::checkSpellingOfString(const UChar*, int, int*, int*)
313 {
314     notImplemented();
315 }
316
317 void EditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
318 {
319     notImplemented();
320 }
321
322 void EditorClient::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
323 {
324     notImplemented();
325 }
326
327 void EditorClient::updateSpellingUIWithMisspelledWord(const String&)
328 {
329     notImplemented();
330 }
331
332 void EditorClient::showSpellingUI(bool)
333 {
334     notImplemented();
335 }
336
337 bool EditorClient::spellingUIIsShowing()
338 {
339     notImplemented();
340     return false;
341 }
342
343 void EditorClient::getGuessesForWord(const String&, Vector<String>&)
344 {
345     notImplemented();
346 }
347
348 void EditorClient::setInputMethodState(bool)
349 {
350 }
351
352 }
353
354 // vim: ts=4 sw=4 et