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