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 Alp Toker <alp@atoker.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "EditorClientGtk.h"
34 #include "EditCommand.h"
36 #include "FocusController.h"
38 #include "KeyboardCodes.h"
39 #include "KeyboardEvent.h"
40 #include "NotImplemented.h"
42 #include "PlatformKeyboardEvent.h"
43 #include "webkitgtkprivate.h"
47 using namespace WebCore;
51 bool EditorClient::shouldDeleteRange(Range*)
57 bool EditorClient::shouldShowDeleteInterface(HTMLElement*)
62 bool EditorClient::isContinuousSpellCheckingEnabled()
68 bool EditorClient::isGrammarCheckingEnabled()
74 int EditorClient::spellCheckerDocumentTag()
80 bool EditorClient::shouldBeginEditing(WebCore::Range*)
86 bool EditorClient::shouldEndEditing(WebCore::Range*)
92 bool EditorClient::shouldInsertText(String, Range*, EditorInsertAction)
98 bool EditorClient::shouldChangeSelectedRange(Range*, Range*, EAffinity, bool)
104 bool EditorClient::shouldApplyStyle(WebCore::CSSStyleDeclaration*,
111 bool EditorClient::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*)
117 void EditorClient::didBeginEditing()
122 void EditorClient::respondToChangedContents()
127 void EditorClient::respondToChangedSelection()
132 void EditorClient::didEndEditing()
137 void EditorClient::didWriteSelectionToPasteboard()
142 void EditorClient::didSetSelectionTypesForPasteboard()
147 bool EditorClient::isEditable()
153 void EditorClient::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>)
158 void EditorClient::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>)
163 void EditorClient::clearUndoRedoOperations()
168 bool EditorClient::canUndo() const
174 bool EditorClient::canRedo() const
180 void EditorClient::undo()
185 void EditorClient::redo()
190 bool EditorClient::shouldInsertNode(Node*, Range*, EditorInsertAction)
196 void EditorClient::pageDestroyed()
201 bool EditorClient::smartInsertDeleteEnabled()
207 void EditorClient::toggleContinuousSpellChecking()
212 void EditorClient::toggleGrammarChecking()
216 void EditorClient::handleKeypress(KeyboardEvent* event)
218 Frame* frame = core(m_page)->focusController()->focusedOrMainFrame();
219 if (!frame || !frame->document()->focusedNode())
222 const PlatformKeyboardEvent* kevent = event->keyEvent();
223 if (!kevent || kevent->isKeyUp())
226 Node* start = frame->selectionController()->start().node();
230 // FIXME: Use GtkBindingSet instead of this hard-coded switch
231 // http://bugs.webkit.org/show_bug.cgi?id=15911
233 if (start->isContentEditable()) {
234 switch(kevent->WindowsKeyCode()) {
236 frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
237 kevent->ctrlKey() ? WordGranularity : CharacterGranularity, false, true);
240 frame->editor()->deleteWithDirection(SelectionController::FORWARD,
241 kevent->ctrlKey() ? WordGranularity : CharacterGranularity, false, true);
244 frame->selectionController()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
245 SelectionController::LEFT,
246 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
250 frame->selectionController()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
251 SelectionController::RIGHT,
252 kevent->ctrlKey() ? WordGranularity : CharacterGranularity,
256 frame->selectionController()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
257 SelectionController::BACKWARD,
258 kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
261 frame->selectionController()->modify(kevent->shiftKey() ? SelectionController::EXTEND : SelectionController::MOVE,
262 SelectionController::FORWARD,
263 kevent->ctrlKey() ? ParagraphGranularity : LineGranularity,
266 case VK_PRIOR: // PageUp
267 frame->editor()->execCommand("MoveUpByPageAndModifyCaret");
269 case VK_NEXT: // PageDown
270 frame->editor()->execCommand("MoveDownByPageAndModifyCaret");
273 frame->editor()->execCommand("InsertLineBreak");
278 if (!kevent->ctrlKey() && !kevent->altKey() && !kevent->text().isEmpty()) {
279 if (kevent->text().length() == 1) {
280 UChar ch = kevent->text()[0];
281 // Don't insert null or control characters as they can result in unexpected behaviour
285 frame->editor()->insertText(kevent->text(), event);
286 } else if (kevent->ctrlKey()) {
287 switch (kevent->WindowsKeyCode()) {
289 frame->editor()->execCommand("SelectAll");
292 frame->editor()->execCommand("ToggleBold");
295 frame->editor()->execCommand("Copy");
298 frame->editor()->execCommand("ToggleItalic");
301 frame->editor()->execCommand("Paste");
304 frame->editor()->execCommand("Cut");
307 frame->editor()->execCommand("Redo");
310 frame->editor()->execCommand("Undo");
318 switch (kevent->WindowsKeyCode()) {
320 frame->editor()->execCommand("MoveUp");
323 frame->editor()->execCommand("MoveDown");
325 case VK_PRIOR: // PageUp
326 frame->editor()->execCommand("MoveUpByPageAndModifyCaret");
328 case VK_NEXT: // PageDown
329 frame->editor()->execCommand("MoveDownByPageAndModifyCaret");
332 if (kevent->ctrlKey())
333 frame->editor()->execCommand("MoveToBeginningOfDocument");
336 if (kevent->ctrlKey())
337 frame->editor()->execCommand("MoveToEndOfDocument");
340 if (kevent->ctrlKey()) {
341 switch(kevent->WindowsKeyCode()) {
343 frame->editor()->execCommand("SelectAll");
345 case VK_C: case VK_X:
346 frame->editor()->execCommand("Copy");
354 event->setDefaultHandled();
358 void EditorClient::handleInputMethodKeypress(KeyboardEvent*)
363 EditorClient::EditorClient(WebKitPage* page)
368 void EditorClient::textFieldDidBeginEditing(Element*)
373 void EditorClient::textFieldDidEndEditing(Element*)
378 void EditorClient::textDidChangeInTextField(Element*)
383 bool EditorClient::doTextFieldCommandFromEvent(Element*, KeyboardEvent*)
389 void EditorClient::textWillBeDeletedInTextField(Element*)
394 void EditorClient::textDidChangeInTextArea(Element*)
399 void EditorClient::ignoreWordInSpellDocument(const String&)
404 void EditorClient::learnWord(const String&)
409 void EditorClient::checkSpellingOfString(const UChar*, int, int*, int*)
414 void EditorClient::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
419 void EditorClient::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
424 void EditorClient::updateSpellingUIWithMisspelledWord(const String&)
429 void EditorClient::showSpellingUI(bool)
434 bool EditorClient::spellingUIIsShowing()
440 void EditorClient::getGuessesForWord(const String&, Vector<String>&)
445 void EditorClient::setInputMethodState(bool)