summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/render_widget_host_view_qt.cpp48
-rw-r--r--src/core/web_event_factory.cpp50
-rw-r--r--tests/auto/quick/qmltests/data/keyboardModifierMapping.html36
-rw-r--r--tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml119
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro6
5 files changed, 250 insertions, 9 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 9555c85a5..e17459634 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -152,12 +152,37 @@ static inline bool compareTouchPoints(const QTouchEvent::TouchPoint &lhs, const
return lhs.state() < rhs.state();
}
+static inline int flagsFromModifiers(Qt::KeyboardModifiers modifiers)
+{
+ int modifierFlags = ui::EF_NONE;
+#if defined(Q_OS_OSX)
+ if (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ if ((modifiers & Qt::ControlModifier) != 0)
+ modifierFlags |= ui::EF_COMMAND_DOWN;
+ if ((modifiers & Qt::MetaModifier) != 0)
+ modifierFlags |= ui::EF_CONTROL_DOWN;
+ } else
+#endif
+ {
+ if ((modifiers & Qt::ControlModifier) != 0)
+ modifierFlags |= ui::EF_CONTROL_DOWN;
+ if ((modifiers & Qt::MetaModifier) != 0)
+ modifierFlags |= ui::EF_COMMAND_DOWN;
+ }
+ if ((modifiers & Qt::ShiftModifier) != 0)
+ modifierFlags |= ui::EF_SHIFT_DOWN;
+ if ((modifiers & Qt::AltModifier) != 0)
+ modifierFlags |= ui::EF_ALT_DOWN;
+ return modifierFlags;
+}
+
class MotionEventQt : public ui::MotionEvent {
public:
- MotionEventQt(const QList<QTouchEvent::TouchPoint> &touchPoints, const base::TimeTicks &eventTime, Action action, int index = -1)
+ MotionEventQt(const QList<QTouchEvent::TouchPoint> &touchPoints, const base::TimeTicks &eventTime, Action action, const Qt::KeyboardModifiers modifiers, int index = -1)
: touchPoints(touchPoints)
, eventTime(eventTime)
, action(action)
+ , flags(flagsFromModifiers(modifiers))
, index(index)
{
// ACTION_DOWN and ACTION_UP must be accesssed through pointer_index 0
@@ -173,7 +198,21 @@ public:
virtual float GetY(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pos().y(); }
virtual float GetRawX(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).screenPos().x(); }
virtual float GetRawY(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).screenPos().y(); }
- virtual float GetTouchMajor(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).rect().height(); }
+ virtual float GetTouchMajor(size_t pointer_index) const Q_DECL_OVERRIDE
+ {
+ QRectF touchRect = touchPoints.at(pointer_index).rect();
+ return std::max(touchRect.height(), touchRect.width());
+ }
+ virtual float GetTouchMinor(size_t pointer_index) const Q_DECL_OVERRIDE
+ {
+ QRectF touchRect = touchPoints.at(pointer_index).rect();
+ return std::min(touchRect.height(), touchRect.width());
+ }
+ virtual float GetOrientation(size_t pointer_index) const Q_DECL_OVERRIDE
+ {
+ return 0;
+ }
+ virtual int GetFlags() const Q_DECL_OVERRIDE { return flags; }
virtual float GetPressure(size_t pointer_index) const Q_DECL_OVERRIDE { return touchPoints.at(pointer_index).pressure(); }
virtual base::TimeTicks GetEventTime() const Q_DECL_OVERRIDE { return eventTime; }
@@ -189,6 +228,7 @@ private:
QList<QTouchEvent::TouchPoint> touchPoints;
base::TimeTicks eventTime;
Action action;
+ int flags;
int index;
};
@@ -929,7 +969,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
QList<QTouchEvent::TouchPoint> touchPoints = mapTouchPointIds(ev->touchPoints());
if (ev->type() == QEvent::TouchCancel) {
- MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL);
+ MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL, ev->modifiers());
processMotionEvent(cancelEvent);
return;
}
@@ -962,7 +1002,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
continue;
}
- MotionEventQt motionEvent(touchPoints, eventTimestamp, action, i);
+ MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), i);
processMotionEvent(motionEvent);
}
}
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index 36e96121c..8dfb2c574 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -64,6 +64,7 @@
#include "web_event_factory.h"
#include "third_party/WebKit/Source/platform/WindowsKeyboardCodes.h"
+#include <QCoreApplication>
#include <QElapsedTimer>
#include <QKeyEvent>
#include <QMouseEvent>
@@ -478,14 +479,52 @@ static unsigned mouseButtonsModifiersForEvent(const T* event)
return ret;
}
+// If only a modifier key is pressed, Qt only reports the key code.
+// But Chromium also expects the modifier being set.
+static inline WebInputEvent::Modifiers modifierForKeyCode(int key)
+{
+ switch (key) {
+ case Qt::Key_Shift:
+ return WebInputEvent::ShiftKey;
+ case Qt::Key_Alt:
+ return WebInputEvent::AltKey;
+#if defined(Q_OS_OSX)
+ case Qt::Key_Control:
+ return (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) ? WebInputEvent::MetaKey : WebInputEvent::ControlKey;
+ case Qt::Key_Meta:
+ return (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) ? WebInputEvent::ControlKey : WebInputEvent::MetaKey;
+#else
+ case Qt::Key_Control:
+ return WebInputEvent::ControlKey;
+ case Qt::Key_Meta:
+ return WebInputEvent::MetaKey;
+#endif
+ default:
+ return static_cast<WebInputEvent::Modifiers>(0);
+ }
+}
+
static inline WebInputEvent::Modifiers modifiersForEvent(const QInputEvent* event)
{
unsigned result = 0;
Qt::KeyboardModifiers modifiers = event->modifiers();
+#if defined(Q_OS_OSX)
+ if (!qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
+ if (modifiers & Qt::ControlModifier)
+ result |= WebInputEvent::MetaKey;
+ if (modifiers & Qt::MetaModifier)
+ result |= WebInputEvent::ControlKey;
+ } else
+#endif
+ {
+ if (modifiers & Qt::ControlModifier)
+ result |= WebInputEvent::ControlKey;
+ if (modifiers & Qt::MetaModifier)
+ result |= WebInputEvent::MetaKey;
+ }
+
if (modifiers & Qt::ShiftModifier)
result |= WebInputEvent::ShiftKey;
- if (modifiers & Qt::ControlModifier)
- result |= WebInputEvent::ControlKey;
if (modifiers & Qt::AltModifier)
result |= WebInputEvent::AltKey;
if (modifiers & Qt::MetaModifier)
@@ -503,9 +542,12 @@ static inline WebInputEvent::Modifiers modifiersForEvent(const QInputEvent* even
result |= mouseButtonsModifiersForEvent(static_cast<const QWheelEvent*>(event));
break;
case QEvent::KeyPress:
- case QEvent::KeyRelease:
- if (static_cast<const QKeyEvent*>(event)->isAutoRepeat())
+ case QEvent::KeyRelease: {
+ const QKeyEvent *keyEvent = static_cast<const QKeyEvent*>(event);
+ if (keyEvent->isAutoRepeat())
result |= WebInputEvent::IsAutoRepeat;
+ result |= modifierForKeyCode(keyEvent->key());
+ }
default:
break;
}
diff --git a/tests/auto/quick/qmltests/data/keyboardModifierMapping.html b/tests/auto/quick/qmltests/data/keyboardModifierMapping.html
new file mode 100644
index 000000000..b6d291207
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/keyboardModifierMapping.html
@@ -0,0 +1,36 @@
+<html>
+<body>
+<kbd>Alt</kbd> is <span id="alt_state">no</span><br>
+<kbd>Ctrl</kbd> is <span id="ctrl_state">no</span><br>
+<kbd>Meta</kbd> is <span id="meta_state">no</span><br>
+last keycode: <span id="last_keycode">none</span><br>
+
+<script>
+
+document.body.onkeydown = function(e) {
+ if (e.altKey)
+ alt_state.textContent = 'pressed'
+ if (e.ctrlKey)
+ ctrl_state.textContent = 'pressed'
+ if (e.metaKey)
+ meta_state.textContent = 'pressed'
+ last_keycode.textContent = e.keyCode
+};
+document.body.onkeyup = function(e) {
+ if (e.altKey)
+ alt_state.textContent = 'released'
+ if (e.ctrlKey)
+ ctrl_state.textContent = 'released'
+ if (e.metaKey)
+ meta_state.textContent = 'released'
+ last_keycode.textContent = e.keyCode
+};
+
+function getPressedModifiers() {
+ return "alt:" + alt_state.textContent + " ctrl:" + ctrl_state.textContent + " meta:" + meta_state.textContent
+}
+
+</script>
+</body>
+</html>
+
diff --git a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
new file mode 100644
index 000000000..ddf025281
--- /dev/null
+++ b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Quick Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtTest 1.0
+import QtWebEngine 1.0
+
+TestWebEngineView {
+ id: webEngineView
+ width: 400
+ height: 300
+
+ SignalSpy {
+ id: spy
+ target: webEngineView
+ signalName: "titleChanged"
+ }
+
+ TestCase {
+ name: "WebEngineViewKeyboardModifierMapping"
+
+ when: false
+ Timer {
+ running: parent.windowShown
+ repeat: false
+ interval: 1
+ onTriggered: parent.when = true
+ }
+
+ function test_keyboardModifierMapping() {
+ webEngineView.url = Qt.resolvedUrl("keyboardModifierMapping.html")
+ waitForLoadSucceeded();
+ var callbackCalled = false;
+
+ // Alt
+ keyPress(Qt.Key_Alt);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:pressed ctrl:no meta:no");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.Key_Alt)
+ callbackCalled = false;
+
+ // Ctrl
+ // On mac Qt automatically translates Meta to Ctrl and vice versa.
+ // However, if sending the events manually no mapping is being done,
+ // so we have to do this here manually.
+ // For testing we assume that the flag Qt::AA_MacDontSwapCtrlAndMeta is NOT set.
+ keyPress(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:pressed meta:no");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
+ callbackCalled = false;
+
+ // Meta (Command on Mac)
+ keyPress(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:released meta:pressed");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ keyRelease(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
+ callbackCalled = false;
+
+ runJavaScript("getPressedModifiers()", function(result) {
+ compare(result, "alt:released ctrl:released meta:released");
+ callbackCalled = true;
+ });
+ wait(100);
+ verify(callbackCalled);
+ callbackCalled = false;
+ }
+ }
+}
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 33a864cf1..6789b714b 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -16,6 +16,8 @@ OTHER_FILES += \
$$PWD/data/test1.html \
$$PWD/data/test2.html \
$$PWD/data/test3.html \
+ $$PWD/data/test4.html \
+ $$PWD/data/keyboardModifierMapping.html \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
$$PWD/data/tst_favIconLoad.qml \
$$PWD/data/tst_linkHovered.qml \
@@ -29,7 +31,9 @@ OTHER_FILES += \
$$PWD/data/tst_navigationRequested.qml \
$$PWD/data/tst_properties.qml \
$$PWD/data/tst_runJavaScript.qml \
- $$PWD/data/tst_titleChanged.qml
+ $$PWD/data/tst_titleChanged.qml \
+ $$PWD/data/tst_keyboardModifierMapping.qml \
+
load(qt_build_paths)
DEFINES += QUICK_TEST_SOURCE_DIR=\"\\\"$$PWD$${QMAKE_DIR_SEP}data\\\"\"