• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) 2007 Ryan Leavengood <leavengood@gmail.com>
6  * Copyright (C) 2007 Andrea Anzani <andrea.anzani@gmail.com>
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "config.h"
33 #include "EditorClientHaiku.h"
34 
35 #include "Document.h"
36 #include "Editor.h"
37 #include "FocusController.h"
38 #include "Frame.h"
39 #include "KeyboardCodes.h"
40 #include "KeyboardEvent.h"
41 #include "Page.h"
42 #include "PlatformKeyboardEvent.h"
43 
44 #include "NotImplemented.h"
45 
46 
47 namespace WebCore {
48 
EditorClientHaiku()49 EditorClientHaiku::EditorClientHaiku()
50     : m_editing(false)
51     , m_inUndoRedo(false)
52 {
53 }
54 
setPage(Page * page)55 void EditorClientHaiku::setPage(Page* page)
56 {
57     m_page = page;
58 }
59 
pageDestroyed()60 void EditorClientHaiku::pageDestroyed()
61 {
62     notImplemented();
63 }
64 
shouldDeleteRange(Range *)65 bool EditorClientHaiku::shouldDeleteRange(Range*)
66 {
67     notImplemented();
68     return true;
69 }
70 
shouldShowDeleteInterface(HTMLElement *)71 bool EditorClientHaiku::shouldShowDeleteInterface(HTMLElement*)
72 {
73     notImplemented();
74     return false;
75 }
76 
smartInsertDeleteEnabled()77 bool EditorClientHaiku::smartInsertDeleteEnabled()
78 {
79     notImplemented();
80     return false;
81 }
82 
isSelectTrailingWhitespaceEnabled()83 bool EditorClientHaiku::isSelectTrailingWhitespaceEnabled()
84 {
85     notImplemented();
86     return false;
87 }
88 
isContinuousSpellCheckingEnabled()89 bool EditorClientHaiku::isContinuousSpellCheckingEnabled()
90 {
91     notImplemented();
92     return false;
93 }
94 
toggleContinuousSpellChecking()95 void EditorClientHaiku::toggleContinuousSpellChecking()
96 {
97     notImplemented();
98 }
99 
isGrammarCheckingEnabled()100 bool EditorClientHaiku::isGrammarCheckingEnabled()
101 {
102     notImplemented();
103     return false;
104 }
105 
toggleGrammarChecking()106 void EditorClientHaiku::toggleGrammarChecking()
107 {
108     notImplemented();
109 }
110 
spellCheckerDocumentTag()111 int EditorClientHaiku::spellCheckerDocumentTag()
112 {
113     notImplemented();
114     return 0;
115 }
116 
isEditable()117 bool EditorClientHaiku::isEditable()
118 {
119     // FIXME: should be controllable
120     return false;
121 }
122 
shouldBeginEditing(WebCore::Range *)123 bool EditorClientHaiku::shouldBeginEditing(WebCore::Range*)
124 {
125     notImplemented();
126     return true;
127 }
128 
shouldEndEditing(WebCore::Range *)129 bool EditorClientHaiku::shouldEndEditing(WebCore::Range*)
130 {
131     notImplemented();
132     return true;
133 }
134 
shouldInsertNode(Node *,Range *,EditorInsertAction)135 bool EditorClientHaiku::shouldInsertNode(Node*, Range*, EditorInsertAction)
136 {
137     notImplemented();
138     return true;
139 }
140 
shouldInsertText(const String &,Range *,EditorInsertAction)141 bool EditorClientHaiku::shouldInsertText(const String&, Range*, EditorInsertAction)
142 {
143     notImplemented();
144     return true;
145 }
146 
shouldChangeSelectedRange(Range * fromRange,Range * toRange,EAffinity,bool stillSelecting)147 bool EditorClientHaiku::shouldChangeSelectedRange(Range* fromRange, Range* toRange,
148                                                   EAffinity, bool stillSelecting)
149 {
150     notImplemented();
151     return true;
152 }
153 
shouldApplyStyle(WebCore::CSSStyleDeclaration *,WebCore::Range *)154 bool EditorClientHaiku::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
155                                       WebCore::Range*)
156 {
157     notImplemented();
158     return true;
159 }
160 
shouldMoveRangeAfterDelete(Range *,Range *)161 bool EditorClientHaiku::shouldMoveRangeAfterDelete(Range*, Range*)
162 {
163     notImplemented();
164     return true;
165 }
166 
didBeginEditing()167 void EditorClientHaiku::didBeginEditing()
168 {
169     notImplemented();
170     m_editing = true;
171 }
172 
respondToChangedContents()173 void EditorClientHaiku::respondToChangedContents()
174 {
175     notImplemented();
176 }
177 
respondToChangedSelection()178 void EditorClientHaiku::respondToChangedSelection()
179 {
180     notImplemented();
181 }
182 
didEndEditing()183 void EditorClientHaiku::didEndEditing()
184 {
185     notImplemented();
186     m_editing = false;
187 }
188 
didWriteSelectionToPasteboard()189 void EditorClientHaiku::didWriteSelectionToPasteboard()
190 {
191     notImplemented();
192 }
193 
didSetSelectionTypesForPasteboard()194 void EditorClientHaiku::didSetSelectionTypesForPasteboard()
195 {
196     notImplemented();
197 }
198 
registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd)199 void EditorClientHaiku::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd)
200 {
201     notImplemented();
202 }
203 
registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)204 void EditorClientHaiku::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
205 {
206     notImplemented();
207 }
208 
clearUndoRedoOperations()209 void EditorClientHaiku::clearUndoRedoOperations()
210 {
211     notImplemented();
212 }
213 
canUndo() const214 bool EditorClientHaiku::canUndo() const
215 {
216     notImplemented();
217     return false;
218 }
219 
canRedo() const220 bool EditorClientHaiku::canRedo() const
221 {
222     notImplemented();
223     return false;
224 }
225 
undo()226 void EditorClientHaiku::undo()
227 {
228     notImplemented();
229     m_inUndoRedo = true;
230     m_inUndoRedo = false;
231 }
232 
redo()233 void EditorClientHaiku::redo()
234 {
235     notImplemented();
236     m_inUndoRedo = true;
237     m_inUndoRedo = false;
238 }
239 
handleKeyboardEvent(KeyboardEvent * event)240 void EditorClientHaiku::handleKeyboardEvent(KeyboardEvent* event)
241 {
242     Frame* frame = m_page->focusController()->focusedOrMainFrame();
243     if (!frame || !frame->document()->focusedNode())
244         return;
245 
246     const PlatformKeyboardEvent* kevent = event->keyEvent();
247     if (!kevent || kevent->type() == PlatformKeyboardEvent::KeyUp)
248         return;
249 
250     Node* start = frame->selection()->start().node();
251     if (!start)
252         return;
253 
254     if (start->isContentEditable()) {
255         switch(kevent->windowsVirtualKeyCode()) {
256         case VK_BACK:
257             frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
258                                                  kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
259                                                  false, true);
260             break;
261         case VK_DELETE:
262             frame->editor()->deleteWithDirection(SelectionController::FORWARD,
263                                                  kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
264                                                  false, true);
265             break;
266         case VK_LEFT:
267             frame->selection()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
268                                        SelectionController::LEFT,
269                                        kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
270                                        true);
271             break;
272         case VK_RIGHT:
273             frame->selection()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
274                                        SelectionController::RIGHT,
275                                        kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
276                                        true);
277             break;
278         case VK_UP:
279             frame->selection()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
280                                        SelectionController::BACKWARD,
281                                        kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
282                                        true);
283             break;
284         case VK_DOWN:
285             frame->selection()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
286                                        SelectionController::FORWARD,
287                                        kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
288                                        true);
289             break;
290         case VK_PRIOR:  // PageUp
291             frame->editor()->command("MoveUpByPageAndModifyCaret");
292             break;
293         case VK_NEXT:  // PageDown
294             frame->editor()->command("MoveDownByPageAndModifyCaret");
295             break;
296         case VK_RETURN:
297             frame->editor()->command("InsertLineBreak");
298             break;
299         case VK_TAB:
300             return;
301         default:
302             if (!kevent->ctrlKey() && !kevent->altKey() && !kevent->text().isEmpty()) {
303                 if (kevent->text().length() == 1) {
304                     UChar ch = kevent->text()[0];
305                     // Don't insert null or control characters as they can result in unexpected behaviour
306                     if (ch < ' ')
307                         break;
308                 }
309                 frame->editor()->insertText(kevent->text(), event);
310             } else if (kevent->ctrlKey()) {
311                 switch (kevent->windowsVirtualKeyCode()) {
312                 case VK_A:
313                     frame->editor()->command("SelectAll");
314                     break;
315                 case VK_B:
316                     frame->editor()->command("ToggleBold");
317                     break;
318                 case VK_C:
319                     frame->editor()->command("Copy");
320                     break;
321                 case VK_I:
322                     frame->editor()->command("ToggleItalic");
323                     break;
324                 case VK_V:
325                     frame->editor()->command("Paste");
326                     break;
327                 case VK_X:
328                     frame->editor()->command("Cut");
329                     break;
330                 case VK_Y:
331                     frame->editor()->command("Redo");
332                     break;
333                 case VK_Z:
334                     frame->editor()->command("Undo");
335                     break;
336                 default:
337                     return;
338                 }
339             } else return;
340         }
341     } else {
342         switch (kevent->windowsVirtualKeyCode()) {
343         case VK_UP:
344             frame->editor()->command("MoveUp");
345             break;
346         case VK_DOWN:
347             frame->editor()->command("MoveDown");
348             break;
349         case VK_PRIOR:  // PageUp
350             frame->editor()->command("MoveUpByPageAndModifyCaret");
351             break;
352         case VK_NEXT:  // PageDown
353             frame->editor()->command("MoveDownByPageAndModifyCaret");
354             break;
355         case VK_HOME:
356             if (kevent->ctrlKey())
357                 frame->editor()->command("MoveToBeginningOfDocument");
358             break;
359         case VK_END:
360             if (kevent->ctrlKey())
361                 frame->editor()->command("MoveToEndOfDocument");
362             break;
363         default:
364             if (kevent->ctrlKey()) {
365                 switch(kevent->windowsVirtualKeyCode()) {
366                     case VK_A:
367                         frame->editor()->command("SelectAll");
368                         break;
369                     case VK_C: case VK_X:
370                         frame->editor()->command("Copy");
371                         break;
372                     default:
373                         return;
374                 }
375             } else return;
376         }
377     }
378     event->setDefaultHandled();
379 }
380 
handleInputMethodKeydown(KeyboardEvent *)381 void EditorClientHaiku::handleInputMethodKeydown(KeyboardEvent*)
382 {
383     notImplemented();
384 }
385 
textFieldDidBeginEditing(Element *)386 void EditorClientHaiku::textFieldDidBeginEditing(Element*)
387 {
388     m_editing = true;
389 }
390 
textFieldDidEndEditing(Element *)391 void EditorClientHaiku::textFieldDidEndEditing(Element*)
392 {
393     m_editing = false;
394 }
395 
textDidChangeInTextField(Element *)396 void EditorClientHaiku::textDidChangeInTextField(Element*)
397 {
398     notImplemented();
399 }
400 
doTextFieldCommandFromEvent(Element *,KeyboardEvent *)401 bool EditorClientHaiku::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
402 {
403     return false;
404 }
405 
textWillBeDeletedInTextField(Element *)406 void EditorClientHaiku::textWillBeDeletedInTextField(Element*)
407 {
408     notImplemented();
409 }
410 
textDidChangeInTextArea(Element *)411 void EditorClientHaiku::textDidChangeInTextArea(Element*)
412 {
413     notImplemented();
414 }
415 
ignoreWordInSpellDocument(const String &)416 void EditorClientHaiku::ignoreWordInSpellDocument(const String&)
417 {
418     notImplemented();
419 }
420 
learnWord(const String &)421 void EditorClientHaiku::learnWord(const String&)
422 {
423     notImplemented();
424 }
425 
checkSpellingOfString(const UChar *,int,int *,int *)426 void EditorClientHaiku::checkSpellingOfString(const UChar*, int, int*, int*)
427 {
428     notImplemented();
429 }
430 
getAutoCorrectSuggestionForMisspelledWord(const String & misspelledWord)431 String EditorClientHaiku::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord)
432 {
433     notImplemented();
434     return String();
435 }
436 
checkGrammarOfString(const UChar *,int,Vector<GrammarDetail> &,int *,int *)437 void EditorClientHaiku::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
438 {
439     notImplemented();
440 }
441 
updateSpellingUIWithGrammarString(const String &,const GrammarDetail &)442 void EditorClientHaiku::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
443 {
444     notImplemented();
445 }
446 
updateSpellingUIWithMisspelledWord(const String &)447 void EditorClientHaiku::updateSpellingUIWithMisspelledWord(const String&)
448 {
449     notImplemented();
450 }
451 
showSpellingUI(bool)452 void EditorClientHaiku::showSpellingUI(bool)
453 {
454     notImplemented();
455 }
456 
spellingUIIsShowing()457 bool EditorClientHaiku::spellingUIIsShowing()
458 {
459     notImplemented();
460     return false;
461 }
462 
getGuessesForWord(const String &,Vector<String> &)463 void EditorClientHaiku::getGuessesForWord(const String&, Vector<String>&)
464 {
465     notImplemented();
466 }
467 
setInputMethodState(bool enabled)468 void EditorClientHaiku::setInputMethodState(bool enabled)
469 {
470     notImplemented();
471 }
472 
isEditing() const473 bool EditorClientHaiku::isEditing() const
474 {
475     return m_editing;
476 }
477 
478 } // namespace WebCore
479 
480