From fcf62ab10565b5b3c568e26b8f6fa7de94f18c1b Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 29 Oct 2024 20:53:52 +0000 Subject: [PATCH] NSViewComponentPeer: Fix coordinate system conversion in contains() The argument to hitTest must be in the superview's coordinate system. The old implementation would sometimes break in the presence of nested NSViews. --- .../native/juce_NSViewComponentPeer_mac.mm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm index 7c13bec982..e39eb373a5 100644 --- a/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm +++ b/modules/juce_gui_basics/native/juce_NSViewComponentPeer_mac.mm @@ -540,12 +540,20 @@ public: if (! isWindowAtPoint (viewWindow, screenPoint)) return false; - } } - NSView* v = [view hitTest: NSMakePoint (viewFrame.origin.x + localPos.getX(), - viewFrame.origin.y + localPos.getY())]; + const auto pointInSuperview = std::invoke ([&] + { + const auto local = NSMakePoint (localPos.x, localPos.y); + + if (auto* superview = [view superview]) + return [view convertPoint: local toView: superview]; + + return local; + }); + + NSView* v = [view hitTest: pointInSuperview]; return trueIfInAChildWindow ? (v != nil) : (v == view);