OS X: Forward key events to popup window if present

On OS X we don't treat popup windows as worthy of being activated and
focus windows (key windows). Instead we keep track of the active popup
windows and forward events to them manually.

The forwarding logic is split between QPA, which handles mouse, and
QWidgetWindow and QQuickWindowPrivate, which handles key events.

This commit adds the logic for key events to QPA, which is the right
platform layer for this kind of workarounds. The widget code is left
as is for now, and the QQuickWindowPrivate code can be removed in
a follow up.

Task-number: QTBUG-39415
Change-Id: Iee411fcba9fc81ddcc3a7bc82591184675a6d7a2
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
This commit is contained in:
Tor Arne Vestbø 2015-09-04 22:50:11 +02:00
parent a623fe8d2a
commit 676edc006e

View File

@ -1441,12 +1441,17 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
if (!(modifiers & (Qt::ControlModifier | Qt::MetaModifier)) && (ch.unicode() < 0xf700 || ch.unicode() > 0xf8ff))
text = QCFString::toQString(characters);
QWindow *focusWindow = [self topLevelWindow];
QWindow *window = [self topLevelWindow];
// Popups implicitly grab key events; forward to the active popup if there is one.
// This allows popups to e.g. intercept shortcuts and close the popup in response.
if (QCocoaWindow *popup = QCocoaIntegration::instance()->activePopupWindow())
window = popup->window();
if (eventType == QEvent::KeyPress) {
if (m_composingText.isEmpty()) {
m_sendKeyEvent = !QWindowSystemInterface::handleShortcutEvent(focusWindow, timestamp, keyCode,
m_sendKeyEvent = !QWindowSystemInterface::handleShortcutEvent(window, timestamp, keyCode,
modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1);
}
@ -1469,7 +1474,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
}
if (m_sendKeyEvent && m_composingText.isEmpty())
QWindowSystemInterface::handleExtendedKeyEvent(focusWindow, timestamp, QEvent::Type(eventType), keyCode, modifiers,
QWindowSystemInterface::handleExtendedKeyEvent(window, timestamp, QEvent::Type(eventType), keyCode, modifiers,
nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1, false);
m_sendKeyEvent = false;