From c67f46877c72d1c04cb643f33e820d86e64128d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 14 Oct 2021 16:27:31 +0200 Subject: 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 --- src/plugins/platforms/cocoa/qnsview_mouse.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 8ea509e54a..f9038e08da 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -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; -- cgit v1.2.3