From df1cae8d3a141a76432be798a3f34aeb2fc495e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 9 May 2016 00:17:22 -0700 Subject: [PATCH] [osx] Exclude subviews from click gestures Fixes #3418. --- platform/osx/app/MapDocument.m | 6 +++++- platform/osx/src/MGLMapView.mm | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/platform/osx/app/MapDocument.m b/platform/osx/app/MapDocument.m index bc692ba21..c75e1d68c 100644 --- a/platform/osx/app/MapDocument.m +++ b/platform/osx/app/MapDocument.m @@ -405,7 +405,11 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { - (void)handlePressGesture:(NSPressGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state == NSGestureRecognizerStateBegan) { NSPoint location = [gestureRecognizer locationInView:self.mapView]; - [self dropPinAtPoint:location]; + if (!NSPointInRect([gestureRecognizer locationInView:self.mapView.compass], self.mapView.compass.bounds) + && !NSPointInRect([gestureRecognizer locationInView:self.mapView.zoomControls], self.mapView.zoomControls.bounds) + && !NSPointInRect([gestureRecognizer locationInView:self.mapView.attributionView], self.mapView.attributionView.bounds)) { + [self dropPinAtPoint:location]; + } } } diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 741f0a7c0..e06086cf3 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -1344,7 +1344,8 @@ public: /// Click or tap to select an annotation. - (void)handleClickGesture:(NSClickGestureRecognizer *)gestureRecognizer { - if (gestureRecognizer.state != NSGestureRecognizerStateEnded) { + if (gestureRecognizer.state != NSGestureRecognizerStateEnded + || [self subviewContainingGesture:gestureRecognizer]) { return; } @@ -1375,7 +1376,8 @@ public: /// Double-click or double-tap to zoom in. - (void)handleDoubleClickGesture:(NSClickGestureRecognizer *)gestureRecognizer { - if (!self.zoomEnabled || gestureRecognizer.state != NSGestureRecognizerStateEnded) { + if (!self.zoomEnabled || gestureRecognizer.state != NSGestureRecognizerStateEnded + || [self subviewContainingGesture:gestureRecognizer]) { return; } @@ -1461,6 +1463,20 @@ public: } } +/// Returns the subview that the gesture is located in. +- (NSView *)subviewContainingGesture:(NSGestureRecognizer *)gestureRecognizer { + if (NSPointInRect([gestureRecognizer locationInView:self.compass], self.compass.bounds)) { + return self.compass; + } + if (NSPointInRect([gestureRecognizer locationInView:self.zoomControls], self.zoomControls.bounds)) { + return self.zoomControls; + } + if (NSPointInRect([gestureRecognizer locationInView:self.attributionView], self.attributionView.bounds)) { + return self.attributionView; + } + return nil; +} + #pragma mark Keyboard events - (void)keyDown:(NSEvent *)event {