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>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 #include "EditorClientHaiku.h"
37 #include "FocusController.h"
39 #include "KeyboardEvent.h"
40 #include "NotImplemented.h"
42 #include "PlatformKeyboardEvent.h"
43 #include "WindowsKeyboardCodes.h"
48 EditorClientHaiku::EditorClientHaiku()
54 void EditorClientHaiku::setPage(Page* page)
59 void EditorClientHaiku::pageDestroyed()
64 bool EditorClientHaiku::shouldDeleteRange(Range*)
70 bool EditorClientHaiku::shouldShowDeleteInterface(HTMLElement*)
76 bool EditorClientHaiku::smartInsertDeleteEnabled()
82 bool EditorClientHaiku::isSelectTrailingWhitespaceEnabled()
88 bool EditorClientHaiku::isContinuousSpellCheckingEnabled()
94 void EditorClientHaiku::toggleContinuousSpellChecking()
99 bool EditorClientHaiku::isGrammarCheckingEnabled()
105 void EditorClientHaiku::toggleGrammarChecking()
110 int EditorClientHaiku::spellCheckerDocumentTag()
116 bool EditorClientHaiku::shouldBeginEditing(WebCore::Range*)
122 bool EditorClientHaiku::shouldEndEditing(WebCore::Range*)
128 bool EditorClientHaiku::shouldInsertNode(Node*, Range*, EditorInsertAction)
134 bool EditorClientHaiku::shouldInsertText(const String&, Range*, EditorInsertAction)
140 bool EditorClientHaiku::shouldChangeSelectedRange(Range* fromRange, Range* toRange,
141 EAffinity, bool stillSelecting)
147 bool EditorClientHaiku::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
154 bool EditorClientHaiku::shouldMoveRangeAfterDelete(Range*, Range*)
160 void EditorClientHaiku::didBeginEditing()
166 void EditorClientHaiku::respondToChangedContents()
171 void EditorClientHaiku::respondToChangedSelection()
176 void EditorClientHaiku::didEndEditing()
182 void EditorClientHaiku::didWriteSelectionToPasteboard()
187 void EditorClientHaiku::didSetSelectionTypesForPasteboard()
192 void EditorClientHaiku::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd)
197 void EditorClientHaiku::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
202 void EditorClientHaiku::clearUndoRedoOperations()
207 bool EditorClientHaiku::canCopyCut(WebCore::Frame*, bool defaultValue) const
212 bool EditorClientHaiku::canPaste(WebCore::Frame*, bool defaultValue) const
217 bool EditorClientHaiku::canUndo() const
223 bool EditorClientHaiku::canRedo() const
229 void EditorClientHaiku::undo()
233 m_inUndoRedo = false;
236 void EditorClientHaiku::redo()
240 m_inUndoRedo = false;
243 void EditorClientHaiku::handleKeyboardEvent(KeyboardEvent* event)
245 Frame* frame = m_page->focusController()->focusedOrMainFrame();
246 if (!frame || !frame->document()->focusedNode())
249 const PlatformKeyboardEvent* kevent = event->keyEvent();
250 if (!kevent || kevent->type() == PlatformKeyboardEvent::KeyUp)
253 Node* start = frame->selection()->start().containerNode();
257 if (start->isContentEditable()) {
258 switch (kevent->windowsVirtualKeyCode()) {
260 frame->editor()->deleteWithDirection(DirectionBackward,
261 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
265 frame->editor()->deleteWithDirection(DirectionForward,
266 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
270 frame->selection()->modify(kevent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove,
272 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
276 frame->selection()->modify(kevent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove,
278 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
282 frame->selection()->modify(kevent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove,
284 kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
288 frame->selection()->modify(kevent->shiftKey() ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove,
290 kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
293 case VK_PRIOR: // PageUp
294 frame->editor()->command("MoveUpByPageAndModifyCaret");
296 case VK_NEXT: // PageDown
297 frame->editor()->command("MoveDownByPageAndModifyCaret");
300 frame->editor()->command("InsertLineBreak");
305 if (!kevent->ctrlKey() && !kevent->altKey() && !kevent->text().isEmpty()) {
306 if (kevent->text().length() == 1) {
307 UChar ch = kevent->text()[0];
308 // Don't insert null or control characters as they can result in unexpected behaviour
312 frame->editor()->insertText(kevent->text(), event);
313 } else if (kevent->ctrlKey()) {
314 switch (kevent->windowsVirtualKeyCode()) {
316 frame->editor()->command("SelectAll");
319 frame->editor()->command("ToggleBold");
322 frame->editor()->command("Copy");
325 frame->editor()->command("ToggleItalic");
328 frame->editor()->command("Paste");
331 frame->editor()->command("Cut");
334 frame->editor()->command("Redo");
337 frame->editor()->command("Undo");
346 switch (kevent->windowsVirtualKeyCode()) {
348 frame->editor()->command("MoveUp");
351 frame->editor()->command("MoveDown");
353 case VK_PRIOR: // PageUp
354 frame->editor()->command("MoveUpByPageAndModifyCaret");
356 case VK_NEXT: // PageDown
357 frame->editor()->command("MoveDownByPageAndModifyCaret");
360 if (kevent->ctrlKey())
361 frame->editor()->command("MoveToBeginningOfDocument");
364 if (kevent->ctrlKey())
365 frame->editor()->command("MoveToEndOfDocument");
368 if (kevent->ctrlKey()) {
369 switch (kevent->windowsVirtualKeyCode()) {
371 frame->editor()->command("SelectAll");
373 case VK_C: case VK_X:
374 frame->editor()->command("Copy");
383 event->setDefaultHandled();
386 void EditorClientHaiku::handleInputMethodKeydown(KeyboardEvent*)
391 void EditorClientHaiku::textFieldDidBeginEditing(Element*)
396 void EditorClientHaiku::textFieldDidEndEditing(Element*)
401 void EditorClientHaiku::textDidChangeInTextField(Element*)
406 bool EditorClientHaiku::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
411 void EditorClientHaiku::textWillBeDeletedInTextField(Element*)
416 void EditorClientHaiku::textDidChangeInTextArea(Element*)
421 void EditorClientHaiku::ignoreWordInSpellDocument(const String&)
426 void EditorClientHaiku::learnWord(const String&)
431 void EditorClientHaiku::checkSpellingOfString(const UChar*, int, int*, int*)
436 String EditorClientHaiku::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord)
442 void EditorClientHaiku::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
447 void EditorClientHaiku::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
452 void EditorClientHaiku::updateSpellingUIWithMisspelledWord(const String&)
457 void EditorClientHaiku::showSpellingUI(bool)
462 bool EditorClientHaiku::spellingUIIsShowing()
468 void EditorClientHaiku::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
473 void EditorClientHaiku::willSetInputMethodState()
478 void EditorClientHaiku::setInputMethodState(bool enabled)
483 bool EditorClientHaiku::isEditing() const
488 } // namespace WebCore