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 <richard.gustavsen@digia.com>
This commit is contained in:
Tor Arne Vestbø 2014-10-15 17:33:27 +02:00
parent 31e987f8f0
commit 3ab4e869e2
3 changed files with 28 additions and 11 deletions

View File

@ -66,6 +66,8 @@ public:
void raise() { raiseOrLower(true); }
void lower() { raiseOrLower(false); }
bool shouldAutoActivateWindow() const;
void requestActivateWindow();
qreal devicePixelRatio() const;

View File

@ -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<QIOSWindow *>(w->handle())->requestActivateWindow();
break;
}
}
if (view.hidden)
continue;
QWindow *w = view.qwindow;
if (!w || !w->isTopLevel())
continue;
QIOSWindow *iosWindow = static_cast<QIOSWindow *>(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);

View File

@ -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;