blob: 507fbbe152da0d2c0ff9788c6a9483daa0777b44 [file] [log] [blame]
#include "WebEditorClient.h"
#include <WebCore/Document.h>
#include <WebCore/Editor.h>
#include <WebCore/Frame.h>
#include <WebCore/KeyboardEvent.h>
#include <WebCore/Node.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/PlatformKeyboardEvent.h>
#include <hid/usages.h>
#include <iostream>
#pragma clang diagnostic ignored "-Wunused-parameter"
#ifdef notImplemented
#undef notImplemented
#define notImplemented(...)
#endif
namespace WebKit {
using namespace WebCore;
using namespace std;
WebEditorClient::WebEditorClient(InputFocusDelegate delegate)
{
m_inputFocusDelegate = delegate;
}
bool WebEditorClient::shouldDeleteRange(Range* range)
{
return true;
}
bool WebEditorClient::smartInsertDeleteEnabled()
{
return false;
}
bool WebEditorClient::isSelectTrailingWhitespaceEnabled()
{
return true;
}
bool WebEditorClient::isContinuousSpellCheckingEnabled()
{
return false;
}
void WebEditorClient::toggleContinuousSpellChecking()
{
notImplemented();
}
bool WebEditorClient::isGrammarCheckingEnabled()
{
return false;
}
void WebEditorClient::toggleGrammarChecking()
{
notImplemented();
}
int WebEditorClient::spellCheckerDocumentTag()
{
notImplemented();
return false;
}
bool WebEditorClient::shouldBeginEditing(Range* range)
{
cerr << "WebEditorClient::shouldBeginEditing" << endl;
return true;
}
bool WebEditorClient::shouldEndEditing(Range* range)
{
cerr << "WebEditorClient::shouldEndEditing" << endl;
return true;
}
bool WebEditorClient::shouldInsertNode(Node* node, Range* rangeToReplace, EditorInsertAction action)
{
return true;
}
bool WebEditorClient::shouldInsertText(const String& text, Range* rangeToReplace, EditorInsertAction action)
{
return true;
}
bool WebEditorClient::shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting)
{
return true;
}
bool WebEditorClient::shouldApplyStyle(StyleProperties* style, Range* range)
{
return true;
}
void WebEditorClient::didApplyStyle()
{
notImplemented();
}
bool WebEditorClient::shouldMoveRangeAfterDelete(Range*, Range*)
{
return true;
}
void WebEditorClient::didBeginEditing()
{
cerr << "WebEditorClient::didBeginEditing" << endl;
notImplemented();
}
void WebEditorClient::respondToChangedContents()
{
notImplemented();
}
void WebEditorClient::respondToChangedSelection(Frame* frame)
{
notImplemented();
}
void WebEditorClient::didChangeSelectionAndUpdateLayout()
{
notImplemented();
}
void WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged()
{
notImplemented();
}
void WebEditorClient::discardedComposition(Frame*)
{
notImplemented();
}
void WebEditorClient::didEndEditing()
{
cerr << "WebEditorClient::didEndEditing" << endl;
notImplemented();
}
void WebEditorClient::didWriteSelectionToPasteboard()
{
notImplemented();
}
void WebEditorClient::willWriteSelectionToPasteboard(Range* range)
{
notImplemented();
}
void WebEditorClient::getClientPasteboardDataForRange(Range* range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer> >& pasteboardData)
{
notImplemented();
}
void WebEditorClient::registerUndoStep(PassRefPtr<UndoStep> step)
{
notImplemented();
}
void WebEditorClient::registerRedoStep(PassRefPtr<UndoStep>)
{
notImplemented();
}
void WebEditorClient::clearUndoRedoOperations()
{
notImplemented();
}
bool WebEditorClient::canCopyCut(Frame*, bool defaultValue) const
{
notImplemented();
return false;
}
bool WebEditorClient::canPaste(Frame*, bool defaultValue) const
{
notImplemented();
return false;
}
bool WebEditorClient::canUndo() const
{
notImplemented();
return false;
}
bool WebEditorClient::canRedo() const
{
notImplemented();
return false;
}
void WebEditorClient::undo()
{
notImplemented();
}
void WebEditorClient::redo()
{
notImplemented();
}
void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
{
Frame* frame = event->target()->toNode()->document().frame();
const WebCore::PlatformKeyboardEvent* platformEvent = event->keyEvent();
int keyCode = platformEvent->nativeVirtualKeyCode();
bool eventHandled = false;
bool shiftHeld = platformEvent->shiftKey();
String commandName = "";
switch (keyCode) {
case HID_USAGE_KEY_BACKSPACE:
commandName = "DeleteBackward";
break;
case HID_USAGE_KEY_DELETE:
commandName = "DeleteForward";
break;
case HID_USAGE_KEY_HOME:
if (shiftHeld)
commandName = "MoveToBeginningOfDocumentAndModifySelection";
else
commandName = "MoveToBeginningOfDocument";
break;
case HID_USAGE_KEY_END:
if (shiftHeld)
commandName = "MoveToEndOfDocumentAndModifySelection";
else
commandName = "MoveToEndOfDocument";
break;
case HID_USAGE_KEY_PAGEUP:
commandName = "ScrollPageBackward";
break;
case HID_USAGE_KEY_PAGEDOWN:
commandName = "ScrollPageForward";
break;
case HID_USAGE_KEY_ENTER:
commandName = "InsertNewline";
break;
case HID_USAGE_KEY_LEFT:
if (shiftHeld)
commandName = "MoveBackwardAndModifySelection";
else
commandName = "MoveBackward";
break;
case HID_USAGE_KEY_RIGHT:
if (shiftHeld)
commandName = "MoveForwardAndModifySelection";
else
commandName = "MoveForward";
break;
case HID_USAGE_KEY_UP:
if (shiftHeld)
commandName = "MoveUpAndModifySelection";
else
commandName = "MoveUp";
break;
case HID_USAGE_KEY_DOWN:
if (shiftHeld)
commandName = "MoveDownAndModifySelection";
else
commandName = "MoveDown";
break;
}
if (commandName == "") {
String text = platformEvent->text();
if (text.length() > 0) {
eventHandled = frame->editor().insertText(platformEvent->text(), event);
}
} else {
Editor::Command command(frame->editor().command(commandName));
if (!command.isTextInsertion() || platformEvent->type() == PlatformEvent::Char || commandName == "InsertNewline") {
eventHandled = command.execute(event);
}
}
if (eventHandled) {
event->setDefaultHandled();
}
}
void WebEditorClient::handleInputMethodKeydown(KeyboardEvent*)
{
notImplemented();
}
void WebEditorClient::textFieldDidBeginEditing(Element* element)
{
notImplemented();
}
void WebEditorClient::textFieldDidEndEditing(Element* element)
{
notImplemented();
}
void WebEditorClient::textDidChangeInTextField(Element* element)
{
notImplemented();
}
void WebEditorClient::textDidChangeInTextArea(Element* element)
{
notImplemented();
}
void WebEditorClient::overflowScrollPositionChanged()
{
notImplemented();
}
bool WebEditorClient::doTextFieldCommandFromEvent(Element* element, KeyboardEvent* event)
{
notImplemented();
return false;
}
void WebEditorClient::textWillBeDeletedInTextField(Element* element)
{
notImplemented();
}
bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType type) const
{
notImplemented();
return false;
}
void WebEditorClient::ignoreWordInSpellDocument(const String& word)
{
notImplemented();
}
void WebEditorClient::learnWord(const String& word)
{
notImplemented();
}
void WebEditorClient::checkSpellingOfString(StringView text, int* misspellingLocation, int* misspellingLength)
{
notImplemented();
}
String WebEditorClient::getAutoCorrectSuggestionForMisspelledWord(const String&)
{
notImplemented();
return String();
}
void WebEditorClient::checkGrammarOfString(StringView text, Vector<WebCore::GrammarDetail>& grammarDetails, int* badGrammarLocation, int* badGrammarLength)
{
notImplemented();
}
#if USE(UNIFIED_TEXT_CHECKING)
Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes, const VisibleSelection& currentSelection)
{
Vector<TextCheckingResult> results;
notImplemented();
return results;
}
#endif
void WebEditorClient::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
{
notImplemented();
}
void WebEditorClient::updateSpellingUIWithMisspelledWord(const String& misspelledWord)
{
notImplemented();
}
void WebEditorClient::showSpellingUI(bool)
{
notImplemented();
}
bool WebEditorClient::spellingUIIsShowing()
{
bool isShowing = false;
notImplemented();
return isShowing;
}
void WebEditorClient::getGuessesForWord(const String& word, const String& context, const VisibleSelection& currentSelection, Vector<String>& guesses)
{
notImplemented();
}
void WebEditorClient::requestCheckingOfString(WTF::PassRefPtr<TextCheckingRequest> prpRequest, const WebCore::VisibleSelection& currentSelection)
{
notImplemented();
}
void WebEditorClient::willSetInputMethodState()
{
notImplemented();
}
void WebEditorClient::setInputMethodState(bool enabled)
{
m_inputFocusDelegate(enabled);
}
bool WebEditorClient::supportsGlobalSelection()
{
return false;
}
}