From bf1e0b6008227f3a0c0e5dce4cde64c57c4a6839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 13 Mar 2015 11:19:29 +0100 Subject: iOS: Check if window was active on setVisible(false) through native APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a QWindow is closed and destroyed it resets QGuiApp::focus_window before calling setVisible(false) on the platform window, so we don't have the needed information anymore to check if the window we are hiding was the focus-window. To work around this we use the native state instead, which should still be valid if the window was the focus window. Change-Id: I98057e6393411471f03668e3e5ce544f6b49c01d Reviewed-by: Richard Moe Gustavsen Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qioswindow.mm | 2 +- src/plugins/platforms/ios/quiview.h | 1 + src/plugins/platforms/ios/quiview.mm | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index fd04ecf474..b22fa4ec58 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -120,7 +120,7 @@ void QIOSWindow::setVisible(bool visible) if (visible && shouldAutoActivateWindow()) { requestActivateWindow(); - } else if (!visible && qGuiApp->focusWindow() == window()) { + } else if (!visible && [m_view isActiveWindow]) { // Our window was active/focus window but now hidden, so relinquish // focus to the next possible window in the stack. NSArray *subviews = m_view.viewController.view.subviews; diff --git a/src/plugins/platforms/ios/quiview.h b/src/plugins/platforms/ios/quiview.h index 065c52f881..dfe0927b00 100644 --- a/src/plugins/platforms/ios/quiview.h +++ b/src/plugins/platforms/ios/quiview.h @@ -56,6 +56,7 @@ class QIOSWindow; - (id)initWithQIOSWindow:(QIOSWindow *)window; - (void)sendUpdatedExposeEvent; +- (BOOL)isActiveWindow; @end @interface QUIView (Accessibility) diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index a56db1d6f5..8be3515cb5 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -261,6 +261,23 @@ return YES; } +- (BOOL)isActiveWindow +{ + // Normally this is determined exclusivly by being firstResponder, but + // since we employ a separate first responder for text input we need to + // handle both cases as this view being the active Qt window. + + if ([self isFirstResponder]) + return YES; + + UIResponder *firstResponder = [UIResponder currentFirstResponder]; + if ([firstResponder isKindOfClass:[QIOSTextInputResponder class]] + && [firstResponder nextResponder] == self) + return YES; + + return NO; +} + // ------------------------------------------------------------------------- -- cgit v1.2.3