aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-11-16 15:00:08 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-11-19 21:32:45 +0100
commit18c2b4f6dbdc0e0d7e235c2547394d4dafa6dd41 (patch)
treebf20b77f7e050c5fef600bd1288c6c5c05ab0783 /src/quick
parentfd9e4920b3d8235061d2bde19bca7ded566f6331 (diff)
Make sure we don't modify the incoming event objects when localizing
Restore the position of the single event point after event delivery. Where possible, don't make a localized copy which explicitly shares its data with the original anyway. Instead, access the original directly. Change-Id: I5efa44c336eddeef1a1ab00dc91e2d0f223ed31d Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickflickable.cpp9
-rw-r--r--src/quick/items/qquickmultipointtoucharea.cpp4
2 files changed, 9 insertions, 4 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index b451c275c2..2401f008aa 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -1452,9 +1452,12 @@ void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event)
// Now send the release
if (auto grabber = qmlobject_cast<QQuickItem *>(event->exclusiveGrabber(event->point(0)))) {
- QMutableSinglePointEvent localized(*event);
- localized.mutablePoint().setPosition(grabber->mapFromScene(localized.scenePosition()));
- QCoreApplication::sendEvent(window(), &localized);
+ // not copying or detaching anything, so make sure we return the original event unchanged
+ QMutableSinglePointEvent *localized = QMutableSinglePointEvent::from(event);
+ const auto oldPosition = localized->mutablePoint().position();
+ localized->mutablePoint().setPosition(grabber->mapFromScene(localized->scenePosition()));
+ QCoreApplication::sendEvent(window(), localized);
+ localized->mutablePoint().setPosition(oldPosition);
}
// And the event has been consumed
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp
index e23e7365df..ed424a3763 100644
--- a/src/quick/items/qquickmultipointtoucharea.cpp
+++ b/src/quick/items/qquickmultipointtoucharea.cpp
@@ -902,13 +902,14 @@ void QQuickMultiPointTouchArea::touchUngrabEvent()
bool QQuickMultiPointTouchArea::sendMouseEvent(QMouseEvent *event)
{
- QPointF localPos = mapFromScene(event->scenePosition());
+ const QPointF localPos = mapFromScene(event->scenePosition());
QQuickWindow *c = window();
QQuickItem *grabber = c ? c->mouseGrabberItem() : nullptr;
bool stealThisEvent = _stealMouse;
if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) {
QMutableSinglePointEvent mouseEvent(*event);
+ const auto oldPosition = mouseEvent.mutablePoint().position();
mouseEvent.mutablePoint().setPosition(localPos);
mouseEvent.setSource(Qt::MouseEventSynthesizedByQt);
mouseEvent.setAccepted(false);
@@ -931,6 +932,7 @@ bool QQuickMultiPointTouchArea::sendMouseEvent(QMouseEvent *event)
if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
grabMouse();
+ mouseEvent.mutablePoint().setPosition(oldPosition);
return stealThisEvent;
}
if (event->type() == QEvent::MouseButtonRelease) {