From 7526131cd169b208ed499e62cd493b3d48598a6e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 8 Feb 2011 13:37:52 +0100 Subject: Cocoa: Mouse-grabbing in pop-up menus on OS X isn't working The reason is that we special case handling of popups, but have forgotten to check for mouse grabs. This patch checks the grabs, also for popups --- src/gui/kernel/qt_cocoa_helpers_mac.mm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index b9d24b5..e50bdd3 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1103,22 +1103,27 @@ QWidget *qt_mac_getTargetForMouseEvent( if (returnWidgetUnderMouse) *returnWidgetUnderMouse = widgetUnderMouse; - // Resolve the target for the mouse event. Default will be widgetUnderMouse, except - // if there is a popup-"grab", mousegrab, or button-down-"grab": + // Resolve the target for the mouse event. Default will be + // widgetUnderMouse, except if there is a grab (popup/mouse/button-down): if (popup && !mouseGrabber) { - if (!popup->isAncestorOf(widgetUnderMouse)) { - // The popup will always grab the mouse unless the - // mouse is over a child, or the user scrolls: + // We special case handling of popups, since they have an implicitt mouse grab. + QWidget *candidate = buttonDownNotBlockedByModal ? qt_button_down : widgetUnderMouse; + if (!popup->isAncestorOf(candidate)) { + // INVARIANT: we have a popup, but the candidate is not + // in it. But the popup will grab the mouse anyway, + // except if the user scrolls: if (eventType == QEvent::Wheel) return 0; returnLocalPoint = popup->mapFromGlobal(returnGlobalPoint); return popup; - } else if (popup == widgetUnderMouse) { + } else if (popup == candidate) { + // INVARIANT: The candidate is the popup itself, and not a child: returnLocalPoint = popup->mapFromGlobal(returnGlobalPoint); return popup; } else { - returnLocalPoint = widgetUnderMouse->mapFromGlobal(returnGlobalPoint); - return widgetUnderMouse; + // INVARIANT: The candidate is a child inside the popup: + returnLocalPoint = candidate->mapFromGlobal(returnGlobalPoint); + return candidate; } } -- cgit v0.12