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
43 #include "WebFrame.h"
44 #include "WebFramePrivate.h"
45 #include "WebView.h"
46 #include "WebViewPrivate.h"
47
48 #include <stdio.h>
49
50 namespace WebCore {
51
~EditorClientWx()52 EditorClientWx::~EditorClientWx()
53 {
54 m_page = NULL;
55 }
56
setPage(Page * page)57 void EditorClientWx::setPage(Page* page)
58 {
59 m_page = page;
60 }
61
pageDestroyed()62 void EditorClientWx::pageDestroyed()
63 {
64 notImplemented();
65 }
66
shouldDeleteRange(Range *)67 bool EditorClientWx::shouldDeleteRange(Range*)
68 {
69 notImplemented();
70 return true;
71 }
72
shouldShowDeleteInterface(HTMLElement *)73 bool EditorClientWx::shouldShowDeleteInterface(HTMLElement*)
74 {
75 notImplemented();
76 return false;
77 }
78
smartInsertDeleteEnabled()79 bool EditorClientWx::smartInsertDeleteEnabled()
80 {
81 notImplemented();
82 return false;
83 }
84
isSelectTrailingWhitespaceEnabled()85 bool EditorClientWx::isSelectTrailingWhitespaceEnabled()
86 {
87 notImplemented();
88 return false;
89 }
90
isContinuousSpellCheckingEnabled()91 bool EditorClientWx::isContinuousSpellCheckingEnabled()
92 {
93 notImplemented();
94 return false;
95 }
96
toggleContinuousSpellChecking()97 void EditorClientWx::toggleContinuousSpellChecking()
98 {
99 notImplemented();
100 }
101
isGrammarCheckingEnabled()102 bool EditorClientWx::isGrammarCheckingEnabled()
103 {
104 notImplemented();
105 return false;
106 }
107
toggleGrammarChecking()108 void EditorClientWx::toggleGrammarChecking()
109 {
110 notImplemented();
111 }
112
spellCheckerDocumentTag()113 int EditorClientWx::spellCheckerDocumentTag()
114 {
115 notImplemented();
116 return 0;
117 }
118
selectWordBeforeMenuEvent()119 bool EditorClientWx::selectWordBeforeMenuEvent()
120 {
121 notImplemented();
122 return false;
123 }
124
isEditable()125 bool EditorClientWx::isEditable()
126 {
127 Frame* frame = m_page->focusController()->focusedOrMainFrame();
128
129 if (frame) {
130 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
131 if (webKitWin)
132 return webKitWin->IsEditable();
133 }
134 return false;
135 }
136
shouldBeginEditing(Range *)137 bool EditorClientWx::shouldBeginEditing(Range*)
138 {
139 notImplemented();
140 return true;
141 }
142
shouldEndEditing(Range *)143 bool EditorClientWx::shouldEndEditing(Range*)
144 {
145 notImplemented();
146 return true;
147 }
148
shouldInsertNode(Node *,Range *,EditorInsertAction)149 bool EditorClientWx::shouldInsertNode(Node*, Range*,
150 EditorInsertAction)
151 {
152 notImplemented();
153 return true;
154 }
155
shouldInsertText(const String &,Range *,EditorInsertAction)156 bool EditorClientWx::shouldInsertText(const String&, Range*,
157 EditorInsertAction)
158 {
159 notImplemented();
160 return true;
161 }
162
shouldApplyStyle(CSSStyleDeclaration *,Range *)163 bool EditorClientWx::shouldApplyStyle(CSSStyleDeclaration*,
164 Range*)
165 {
166 notImplemented();
167 return true;
168 }
169
shouldMoveRangeAfterDelete(Range *,Range *)170 bool EditorClientWx::shouldMoveRangeAfterDelete(Range*, Range*)
171 {
172 notImplemented();
173 return true;
174 }
175
shouldChangeSelectedRange(Range * fromRange,Range * toRange,EAffinity,bool stillSelecting)176 bool EditorClientWx::shouldChangeSelectedRange(Range* fromRange, Range* toRange,
177 EAffinity, bool stillSelecting)
178 {
179 notImplemented();
180 return true;
181 }
182
didBeginEditing()183 void EditorClientWx::didBeginEditing()
184 {
185 notImplemented();
186 }
187
respondToChangedContents()188 void EditorClientWx::respondToChangedContents()
189 {
190 notImplemented();
191 }
192
didEndEditing()193 void EditorClientWx::didEndEditing()
194 {
195 notImplemented();
196 }
197
didWriteSelectionToPasteboard()198 void EditorClientWx::didWriteSelectionToPasteboard()
199 {
200 notImplemented();
201 }
202
didSetSelectionTypesForPasteboard()203 void EditorClientWx::didSetSelectionTypesForPasteboard()
204 {
205 notImplemented();
206 }
207
registerCommandForUndo(PassRefPtr<EditCommand> command)208 void EditorClientWx::registerCommandForUndo(PassRefPtr<EditCommand> command)
209 {
210 Frame* frame = m_page->focusController()->focusedOrMainFrame();
211
212 if (frame) {
213 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
214 if (webKitWin) {
215 webKitWin->GetMainFrame()->m_impl->undoStack.append(EditCommandWx(command));
216 }
217 }
218 }
219
registerCommandForRedo(PassRefPtr<EditCommand> command)220 void EditorClientWx::registerCommandForRedo(PassRefPtr<EditCommand> command)
221 {
222 Frame* frame = m_page->focusController()->focusedOrMainFrame();
223
224 if (frame) {
225 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
226 if (webKitWin) {
227 webKitWin->GetMainFrame()->m_impl->redoStack.insert(0, EditCommandWx(command));
228 }
229 }
230 }
231
clearUndoRedoOperations()232 void EditorClientWx::clearUndoRedoOperations()
233 {
234 notImplemented();
235 }
236
canUndo() const237 bool EditorClientWx::canUndo() const
238 {
239 Frame* frame = m_page->focusController()->focusedOrMainFrame();
240
241 if (frame) {
242 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
243 if (webKitWin && webKitWin->GetMainFrame()) {
244 return webKitWin->GetMainFrame()->m_impl->undoStack.size() != 0;
245 }
246 }
247 return false;
248 }
249
canRedo() const250 bool EditorClientWx::canRedo() const
251 {
252 Frame* frame = m_page->focusController()->focusedOrMainFrame();
253
254 if (frame) {
255 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
256 if (webKitWin && webKitWin->GetMainFrame()) {
257 return webKitWin->GetMainFrame()->m_impl->redoStack.size() != 0;
258 }
259 }
260 return false;
261 }
262
undo()263 void EditorClientWx::undo()
264 {
265 Frame* frame = m_page->focusController()->focusedOrMainFrame();
266
267 if (frame) {
268 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
269 if (webKitWin && webKitWin->GetMainFrame()) {
270 webKitWin->GetMainFrame()->m_impl->undoStack.last().editCommand()->unapply();
271 webKitWin->GetMainFrame()->m_impl->undoStack.removeLast();
272 }
273 }
274 }
275
redo()276 void EditorClientWx::redo()
277 {
278 Frame* frame = m_page->focusController()->focusedOrMainFrame();
279
280 if (frame) {
281 wxWebView* webKitWin = dynamic_cast<wxWebView*>(frame->view()->platformWidget());
282 if (webKitWin && webKitWin->GetMainFrame()) {
283 webKitWin->GetMainFrame()->m_impl->redoStack.first().editCommand()->reapply();
284 webKitWin->GetMainFrame()->m_impl->redoStack.remove(0);
285 }
286 }
287 }
288
handleInputMethodKeydown(KeyboardEvent * event)289 void EditorClientWx::handleInputMethodKeydown(KeyboardEvent* event)
290 {
291 // NOTE: we don't currently need to handle this. When key events occur,
292 // both this method and handleKeyboardEvent get a chance at handling them.
293 // We might use this method later on for IME-specific handling.
294 }
295
handleKeyboardEvent(KeyboardEvent * event)296 void EditorClientWx::handleKeyboardEvent(KeyboardEvent* event)
297 {
298 Frame* frame = m_page->focusController()->focusedOrMainFrame();
299 if (!frame)
300 return;
301
302 const PlatformKeyboardEvent* kevent = event->keyEvent();
303 if (kevent->type() != PlatformKeyboardEvent::KeyUp) {
304 Node* start = frame->selection()->start().node();
305 if (!start || !start->isContentEditable())
306 return;
307
308 if (kevent->type() == PlatformKeyboardEvent::Char && !kevent->ctrlKey() && !kevent->altKey()) {
309 switch (kevent->windowsVirtualKeyCode()) {
310 // we handled these on key down, ignore them for char events
311 case VK_BACK:
312 case VK_DELETE:
313 case VK_LEFT:
314 case VK_RIGHT:
315 case VK_UP:
316 case VK_DOWN:
317 case VK_RETURN:
318 break;
319 default:
320 frame->editor()->insertText(kevent->text(), event);
321 }
322 event->setDefaultHandled();
323 return;
324 }
325
326 switch (kevent->windowsVirtualKeyCode()) {
327 case VK_BACK:
328 frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
329 CharacterGranularity, false, true);
330 break;
331 case VK_DELETE:
332 frame->editor()->deleteWithDirection(SelectionController::FORWARD,
333 CharacterGranularity, false, true);
334 break;
335 case VK_LEFT:
336 frame->editor()->command("MoveLeft").execute();
337 break;
338 case VK_RIGHT:
339 frame->editor()->command("MoveRight").execute();
340 break;
341 case VK_UP:
342 frame->editor()->command("MoveUp").execute();
343 break;
344 case VK_DOWN:
345 frame->editor()->command("MoveDown").execute();
346 break;
347 case VK_RETURN:
348 frame->editor()->command("InsertLineBreak").execute();
349 default:
350 break;
351 }
352
353 event->setDefaultHandled();
354 }
355 }
356
textFieldDidBeginEditing(Element *)357 void EditorClientWx::textFieldDidBeginEditing(Element*)
358 {
359 notImplemented();
360 }
361
textFieldDidEndEditing(Element *)362 void EditorClientWx::textFieldDidEndEditing(Element*)
363 {
364 notImplemented();
365 }
366
textDidChangeInTextField(Element *)367 void EditorClientWx::textDidChangeInTextField(Element*)
368 {
369 notImplemented();
370 }
371
doTextFieldCommandFromEvent(Element *,KeyboardEvent *)372 bool EditorClientWx::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
373 {
374 notImplemented();
375 return false;
376 }
377
textWillBeDeletedInTextField(Element *)378 void EditorClientWx::textWillBeDeletedInTextField(Element*)
379 {
380 notImplemented();
381 }
382
textDidChangeInTextArea(Element *)383 void EditorClientWx::textDidChangeInTextArea(Element*)
384 {
385 notImplemented();
386 }
387
respondToChangedSelection()388 void EditorClientWx::respondToChangedSelection()
389 {
390 notImplemented();
391 }
392
ignoreWordInSpellDocument(const String &)393 void EditorClientWx::ignoreWordInSpellDocument(const String&)
394 {
395 notImplemented();
396 }
397
learnWord(const String &)398 void EditorClientWx::learnWord(const String&)
399 {
400 notImplemented();
401 }
402
checkSpellingOfString(const UChar *,int length,int * misspellingLocation,int * misspellingLength)403 void EditorClientWx::checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength)
404 {
405 notImplemented();
406 }
407
checkGrammarOfString(const UChar *,int length,Vector<GrammarDetail> &,int * badGrammarLocation,int * badGrammarLength)408 void EditorClientWx::checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength)
409 {
410 notImplemented();
411 }
412
updateSpellingUIWithGrammarString(const String &,const GrammarDetail & detail)413 void EditorClientWx::updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail)
414 {
415 notImplemented();
416 }
417
updateSpellingUIWithMisspelledWord(const String &)418 void EditorClientWx::updateSpellingUIWithMisspelledWord(const String&)
419 {
420 notImplemented();
421 }
422
showSpellingUI(bool show)423 void EditorClientWx::showSpellingUI(bool show)
424 {
425 notImplemented();
426 }
427
spellingUIIsShowing()428 bool EditorClientWx::spellingUIIsShowing()
429 {
430 notImplemented();
431 return false;
432 }
433
getGuessesForWord(const String &,Vector<String> & guesses)434 void EditorClientWx::getGuessesForWord(const String&, Vector<String>& guesses)
435 {
436 notImplemented();
437 }
438
setInputMethodState(bool enabled)439 void EditorClientWx::setInputMethodState(bool enabled)
440 {
441 notImplemented();
442 }
443
444 }
445