From 3ab4e869e205ecd9bbce46281d6c1cc74da94228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 15 Oct 2014 17:33:27 +0200 Subject: [PATCH] iOS: Don't auto-activate popup windows unless they are standalone We try to emulate a traditional window manager by activating windows on touch press (before delivering the event), and on showing/hiding windows, but this logic should not apply to popup windows (including tooltips and tool windows), as they are in most cases already active through their parent or transient parent, and should not steal keyboard focus and bring the virtual keyboard down. Change-Id: If10082bd48cdf1a9e1c41d8809066e86dafd7ffc Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/qioswindow.h | 2 ++ src/plugins/platforms/ios/qioswindow.mm | 35 ++++++++++++++++++------- src/plugins/platforms/ios/quiview.mm | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/ios/qioswindow.h b/src/plugins/platforms/ios/qioswindow.h index 6c52763610a..65b4f6dd7d3 100644 --- a/src/plugins/platforms/ios/qioswindow.h +++ b/src/plugins/platforms/ios/qioswindow.h @@ -66,6 +66,8 @@ public: void raise() { raiseOrLower(true); } void lower() { raiseOrLower(false); } + + bool shouldAutoActivateWindow() const; void requestActivateWindow(); qreal devicePixelRatio() const; diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index c6997019e27..b0c5f153067 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -117,24 +117,39 @@ void QIOSWindow::setVisible(bool visible) return; } - if (visible) { + if (visible && shouldAutoActivateWindow()) { requestActivateWindow(); - } else { - // Activate top-most visible QWindow: + } else if (!visible && qGuiApp->focusWindow() == window()) { + // 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; for (int i = int(subviews.count) - 1; i >= 0; --i) { UIView *view = [subviews objectAtIndex:i]; - if (!view.hidden) { - QWindow *w = view.qwindow; - if (w && w->isTopLevel()) { - static_cast(w->handle())->requestActivateWindow(); - break; - } - } + if (view.hidden) + continue; + + QWindow *w = view.qwindow; + if (!w || !w->isTopLevel()) + continue; + + QIOSWindow *iosWindow = static_cast(w->handle()); + if (!iosWindow->shouldAutoActivateWindow()) + continue; + + iosWindow->requestActivateWindow(); + break; } } } +bool QIOSWindow::shouldAutoActivateWindow() const +{ + // We don't want to do automatic window activation for popup windows + // (including Tool, ToolTip and SplashScreen windows), unless they + // are standalone (no parent/transient parent), and hence not active. + return !(window()->type() & Qt::Popup) || !window()->isActive(); +} + void QIOSWindow::setOpacity(qreal level) { m_view.alpha = qBound(0.0, level, 1.0); diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index 81f82ba97dc..c46ed4c0b1c 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -271,7 +271,7 @@ m_activeTouches[touch].id = m_nextTouchId++; } - if (m_activeTouches.size() == 1) { + if (m_qioswindow->shouldAutoActivateWindow() && m_activeTouches.size() == 1) { QPlatformWindow *topLevel = m_qioswindow; while (QPlatformWindow *p = topLevel->parent()) topLevel = p;