WebEditorClientGtk.cpp [plain text]
#include "config.h"
#include "WebEditorClient.h"
#include <WebCore/Document.h>
#include <WebCore/Editor.h>
#include <WebCore/EventNames.h>
#include <WebCore/Frame.h>
#include <WebCore/KeyboardEvent.h>
#include <WebCore/Pasteboard.h>
#include <WebCore/PlatformKeyboardEvent.h>
#include <WebCore/markup.h>
#include <wtf/glib/GRefPtr.h>
namespace WebKit {
using namespace WebCore;
bool WebEditorClient::executePendingEditorCommands(Frame* frame, const Vector<WTF::String>& pendingEditorCommands, bool allowTextInsertion)
{
Vector<Editor::Command> commands;
for (auto& commandString : pendingEditorCommands) {
Editor::Command command = frame->editor().command(commandString);
if (command.isTextInsertion() && !allowTextInsertion)
return false;
commands.append(WTFMove(command));
}
for (auto& command : commands) {
if (!command.execute())
return false;
}
return true;
}
void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
{
auto* platformEvent = event->underlyingPlatformEvent();
if (!platformEvent)
return;
if (platformEvent->handledByInputMethod())
return;
ASSERT(event->target());
auto* frame = downcast<Node>(event->target())->document().frame();
ASSERT(frame);
const Vector<String> pendingEditorCommands = platformEvent->commands();
if (!pendingEditorCommands.isEmpty()) {
if (platformEvent->type() == PlatformEvent::RawKeyDown) {
if (executePendingEditorCommands(frame, pendingEditorCommands, false))
event->setDefaultHandled();
return;
}
if (executePendingEditorCommands(frame, pendingEditorCommands, frame->editor().canEdit())) {
event->setDefaultHandled();
return;
}
}
if (!frame->editor().canEdit())
return;
if (event->type() != eventNames().keypressEvent)
return;
if (event->charCode() < ' ')
return;
if (platformEvent->ctrlKey() || platformEvent->altKey())
return;
if (frame->editor().insertText(platformEvent->text(), event))
event->setDefaultHandled();
}
void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event)
{
auto* platformEvent = event->underlyingPlatformEvent();
if (platformEvent && platformEvent->handledByInputMethod())
event->setDefaultHandled();
}
void WebEditorClient::updateGlobalSelection(Frame* frame)
{
if (!frame->selection().isRange())
return;
RefPtr<Range> range = frame->selection().toNormalizedRange();
if (!range)
return;
PasteboardWebContent pasteboardContent;
pasteboardContent.canSmartCopyOrDelete = false;
pasteboardContent.text = range->text();
pasteboardContent.markup = serializePreservingVisualAppearance(frame->selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
Pasteboard::createForGlobalSelection()->write(pasteboardContent);
}
bool WebEditorClient::shouldShowUnicodeMenu()
{
return true;
}
}