From ef1d61a3516182b0a39330b5ac5988f92c82bc4f Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 3 Oct 2017 13:14:58 +0200 Subject: Pass editor shortcuts to Chromium by ForwardKeyboardEventWithCommands Moreover, extend the list of supported editor shortcuts and stabilize the corresponding auto test. Task-number: QTBUG-54692 Task-number: QTBUG-54812 Task-number: QTBUG-54221 Task-number: QTBUG-59053 Change-Id: I4dd8230519639ea6e3340992dbb54a609ecfcd91 Reviewed-by: Alexandru Croitor --- src/core/web_event_factory.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/core/web_event_factory.cpp') diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index c31de19a2..8c997335c 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1328,3 +1328,83 @@ content::NativeWebKeyboardEvent WebEventFactory::toWebKeyboardEvent(QKeyEvent *e return webKitEvent; } + +bool WebEventFactory::getEditCommand(QKeyEvent *event, std::string *editCommand) +{ + // Assign Qt standard key bindings to blink editor commands. Editor command names + // come from chromium/third_party/WebKit/Source/editing/commands/EditorCommandNames.h + static struct { + QKeySequence::StandardKey standardKey; + std::string name; + } editCommands[] = { + { QKeySequence::Delete, "Delete" }, + { QKeySequence::Cut, "Cut" }, + { QKeySequence::Copy, "Copy" }, + { QKeySequence::Paste, "Paste" }, + { QKeySequence::Undo, "Undo" }, + { QKeySequence::Redo, "Redo" }, + { QKeySequence::SelectAll, "SelectAll" }, + { QKeySequence::Bold, "Bold" }, + { QKeySequence::Italic, "Italic" }, + { QKeySequence::Underline, "Underline" }, + + { QKeySequence::MoveToNextChar, "MoveRight" }, + { QKeySequence::MoveToPreviousChar, "MoveLeft" }, + { QKeySequence::MoveToNextWord, "MoveWordForward" }, + { QKeySequence::MoveToPreviousWord, "MoveWordBackward" }, + { QKeySequence::MoveToNextLine, "MoveDown" }, + { QKeySequence::MoveToPreviousLine, "MoveUp" }, + { QKeySequence::MoveToNextPage, "MovePageDown" }, + { QKeySequence::MoveToPreviousPage, "MovePageUp" }, + { QKeySequence::MoveToStartOfLine, "MoveToBeginningOfLine" }, + { QKeySequence::MoveToEndOfLine, "MoveToEndOfLine" }, + { QKeySequence::MoveToStartOfBlock, "MoveToBeginningOfParagraph" }, + { QKeySequence::MoveToEndOfBlock, "MoveToEndOfParagraph" }, + { QKeySequence::MoveToStartOfDocument, "MoveToBeginningOfDocument" }, + { QKeySequence::MoveToEndOfDocument, "MoveToEndOfDocument" }, + + { QKeySequence::SelectNextChar, "MoveRightAndModifySelection" }, + { QKeySequence::SelectPreviousChar, "MoveLeftAndModifySelection" }, + { QKeySequence::SelectNextWord, "MoveWordForwardAndModifySelection" }, + { QKeySequence::SelectPreviousWord, "MoveWordBackwardAndModifySelection" }, + { QKeySequence::SelectNextLine, "MoveDownAndModifySelection" }, + { QKeySequence::SelectPreviousLine, "MoveUpAndModifySelection" }, + { QKeySequence::SelectNextPage, "MovePageDownAndModifySelection" }, + { QKeySequence::SelectPreviousPage, "MovePageUpAndModifySelection" }, + { QKeySequence::SelectStartOfLine, "MoveToBeginningOfLineAndModifySelection" }, + { QKeySequence::SelectEndOfLine, "MoveToEndOfLineAndModifySelection" }, + { QKeySequence::SelectStartOfBlock, "MoveToBeginningOfParagraphAndModifySelection" }, + { QKeySequence::SelectEndOfBlock, "MoveToEndOfParagraphAndModifySelection" }, + { QKeySequence::SelectStartOfDocument, "MoveToBeginningOfDocumentAndModifySelection" }, + { QKeySequence::SelectEndOfDocument, "MoveToEndOfDocumentAndModifySelection" }, + + { QKeySequence::DeleteStartOfWord, "DeleteWordBackward" }, + { QKeySequence::DeleteEndOfWord, "DeleteWordForward" }, + { QKeySequence::DeleteEndOfLine, "DeleteToEndOfLine" }, + { QKeySequence::Deselect, "Unselect" }, + { QKeySequence::Backspace, "BackwardDelete" }, + + { QKeySequence::UnknownKey, "" } + }; + + for (int i = 0; editCommands[i].standardKey != QKeySequence::UnknownKey; ++i) { + if (event == editCommands[i].standardKey) { + *editCommand = editCommands[i].name; + return true; + } + } + +#ifdef Q_OS_MACOS + Qt::KeyboardModifier cmdKey = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta) ? + Qt::MetaModifier : + Qt::ControlModifier; + if ((event->modifiers() & ~Qt::ShiftModifier) == cmdKey) { + if (event->key() == Qt::Key_Backspace) { + *editCommand = "DeleteToBeginningOfLine"; + return true; + } + } +#endif + + return false; +} -- cgit v1.2.3 From 64ad0e8b335509970062ba550a06018426b7c285 Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Mon, 30 Oct 2017 17:32:39 +0100 Subject: Fill pointerType member of pointer events Fix pointerType of the currently supported (mouse and touch) events. Support of pen and eraser types is coming with QTBUG-62975. Task-number: QTBUG-63266 Change-Id: Ief32b9680ab5acfb15537aba74c2bcdd6f51c978 Reviewed-by: Peter Varga --- src/core/web_event_factory.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/web_event_factory.cpp') diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index 8c997335c..dcd81efe8 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1190,6 +1190,7 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev, double dpiScale) webKitEvent.button = mouseButtonForEvent(ev); webKitEvent.click_count = 0; + webKitEvent.pointer_type = WebPointerProperties::PointerType::kMouse; return webKitEvent; } @@ -1204,6 +1205,7 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale) webKitEvent.SetPositionInWidget(ev->pos().x() / dpiScale, ev->pos().y() / dpiScale); webKitEvent.movement_x = ev->pos().x() - ev->oldPos().x(); webKitEvent.movement_y = ev->pos().y() - ev->oldPos().y(); + webKitEvent.pointer_type = WebPointerProperties::PointerType::kMouse; return webKitEvent; } -- cgit v1.2.3 From 4de8486b6614896a2b84cc64b69606c7b3bd07e8 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 6 Nov 2017 16:04:45 +0100 Subject: Notify Chromium about leaving view Forward QEvent::Leave for Widget and QEvent::HoverLeave for Quick. Task-number: QTBUG-64265 Change-Id: Ide32768902956476d24b1d4115e305392b62feb3 Reviewed-by: Allan Sandfeld Jensen --- src/core/web_event_factory.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/core/web_event_factory.cpp') diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index f5264708d..0e46aced5 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1019,12 +1019,14 @@ static ui::DomKey getDomKeyFromQKeyEvent(QKeyEvent *ev) } } -static inline double currentTimeForEvent(const QInputEvent* event) +static inline double currentTimeForEvent(const QEvent *event) { Q_ASSERT(event); - if (event->timestamp()) - return static_cast(event->timestamp()) / 1000; + if (const QInputEvent *inputEvent = static_cast(event)) { + if (inputEvent->timestamp()) + return static_cast(inputEvent->timestamp()) / 1000; + } static QElapsedTimer timer; if (!timer.isValid()) @@ -1211,6 +1213,16 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale) return webKitEvent; } +WebMouseEvent WebEventFactory::toWebMouseEvent(QEvent *ev) +{ + Q_ASSERT(ev->type() == QEvent::Leave || ev->type() == QEvent::HoverLeave); + + WebMouseEvent webKitEvent; + webKitEvent.timeStampSeconds = currentTimeForEvent(ev); + webKitEvent.type = WebInputEvent::MouseLeave; + return webKitEvent; +} + #ifndef QT_NO_GESTURES WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev, double dpiScale) { -- cgit v1.2.3