macOS: Only send mouse press to input context if clicking input item

Our QNSView can represent many controls, not just the current input item,
so we need to ensure the click happens inside the input item before we
ask the input context to handle the event.

This allows clicking controls such as buttons and check boxes while
composing complex text, without cancelling or otherwise affecting
the composition.

Fixes: QTBUG-57347
Pick-to: 6.2
Change-Id: I8449c8d74fd21b1ee1d5bd75f960751b64d7e078
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Tor Arne Vestbø 2021-10-14 16:27:31 +02:00
parent 1dfc74970c
commit c67f46877c

View File

@ -429,9 +429,20 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID)
return;
}
bool handleMouseEvent = true;
// FIXME: AppKit doesn't limit itself to passing the event on to the input method
// based on there being marked text or not. It also transfers first responder to
// the view before calling mouseDown, whereas we only transfer focus once the mouse
// press is delivered.
if ([self hasMarkedText]) {
[[NSTextInputContext currentInputContext] handleEvent:theEvent];
} else {
if (QPlatformInputContext::inputItemClipRectangle().contains(qtWindowPoint)) {
qCDebug(lcQpaInputMethods) << "Asking input context to handle mouse press";
[NSTextInputContext.currentInputContext handleEvent:theEvent];
handleMouseEvent = false;
}
}
if (handleMouseEvent) {
if (!m_dontOverrideCtrlLMB && (theEvent.modifierFlags & NSEventModifierFlagControl)) {
m_buttons |= Qt::RightButton;
m_sendUpAsRightButton = true;