From ac7823129a529a71d2725fdeadc5eff7a2b0788a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 7 Nov 2013 13:16:48 +0100 Subject: iOS: Cancel any active touches when destroying a QIOSWindow Keeps the internal state of QtGui sane when it comes to which buttons are active, etc. Change-Id: Ic63e74d2546469e085ec46b74f4cf159dd409b07 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qioswindow.mm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 70f4cc4267..fa0519a37c 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -226,6 +226,9 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { + if (!touches && m_activeTouches.isEmpty()) + return; + if (!touches) { m_activeTouches.clear(); } else { @@ -238,9 +241,11 @@ m_nextTouchId = 0; + NSTimeInterval timestamp = event ? event.timestamp : [[NSProcessInfo processInfo] systemUptime]; + // Send cancel touch event synchronously QIOSIntegration *iosIntegration = static_cast(QGuiApplicationPrivate::platformIntegration()); - QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(event.timestamp * 1000), iosIntegration->touchDevice()); + QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); QWindowSystemInterface::flushWindowSystemEvents(); } @@ -342,6 +347,13 @@ QIOSWindow::QIOSWindow(QWindow *window) QIOSWindow::~QIOSWindow() { + // According to the UIResponder documentation, Cocoa Touch should react to system interruptions + // that "might cause the view to be removed from the window" by sending touchesCancelled, but in + // practice this doesn't seem to happen when removing the view from its superview. To ensure that + // Qt's internal state for touch and mouse handling is kept consistent, we therefor have to force + // cancellation of all touch events. + [m_view touchesCancelled:0 withEvent:0]; + [m_view removeFromSuperview]; [m_view release]; } -- cgit v1.2.3