iOS: bugfix touch events when not using alien

It seems that 130ee40b broke touch handling for
non-alien QWindows. For those cases, a QWindow that is a
child of another QWindow will get its own UIView to
back it up. The current code did not take this into
account when calculating the global coordinates of
touch events. Instead we need to search for the
top level QWindow it might be inside before we find the
view that acts as the "desktop" for it.

Change-Id: Ie3c19bf86c92fa3f247a0764116830e91b8322d2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2013-10-28 12:50:59 +01:00 committed by The Qt Project
parent eb64c765e3
commit fecc820c58

View File

@ -151,9 +151,16 @@
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
{
// We deliver touch events with global coordinates. But global in this respect means
// the coordinate system where this QWindow lives. And that is our superview.
CGSize parentSize = self.superview.frame.size;
// We deliver touch events in global coordinates. But global in this respect
// means the same coordinate system that we use for describing the geometry
// of the top level QWindow we're inside. And that would be the coordinate
// system of the superview of the UIView that backs that window:
QPlatformWindow *topLevel = m_qioswindow;
while (QPlatformWindow *topLevelParent = topLevel->parent())
topLevel = topLevelParent;
UIView *rootView = reinterpret_cast<UIView *>(topLevel->winId()).superview;
CGSize rootViewSize = rootView.frame.size;
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
if (![touches containsObject:uiTouch]) {
@ -161,9 +168,9 @@
} else {
touchPoint.state = state;
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
QPoint touchPos = fromCGPoint([uiTouch locationInView:self.superview]);
QPoint touchPos = fromCGPoint([uiTouch locationInView:rootView]);
touchPoint.area = QRectF(touchPos, QSize(0, 0));
touchPoint.normalPosition = QPointF(touchPos.x() / parentSize.width, touchPos.y() / parentSize.height);
touchPoint.normalPosition = QPointF(touchPos.x() / rootViewSize.width, touchPos.y() / rootViewSize.height);
}
}
}