diff options
author | Jesse Crocker <Jesse@datamongers.net> | 2016-12-01 11:50:20 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-12-01 11:50:20 -0800 |
commit | 5dd71d3c3048c1a521f65f3a2f7b13c9c0fed279 (patch) | |
tree | 23243e1cac7a20a70754e02335e8ae16d85dd22a /platform/macos | |
parent | b2c2d4ebc4041d4ca5d71bf589dfa5826ec5bf46 (diff) | |
download | qtlocation-mapboxgl-5dd71d3c3048c1a521f65f3a2f7b13c9c0fed279.tar.gz |
[ios, macos] Make tap gesture recognizer fail if it doesn’t do anything (#7246)
* Make tap gesture recognizer fail if it doesn’t do anything.
* fix typo
* Use the right nullable
* update changelog
* Make single click gesture recognizer fail if it doesn’t select an annotation
* fix changelog typo
* Remove singleTapGestureRecognizer from public header
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 24 |
2 files changed, 21 insertions, 4 deletions
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 9675ec8447..37e51d7c58 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -57,6 +57,7 @@ * Fixed an issue where the map view’s center would always be calculated as if the view occupied the entire window. ([#6102](https://github.com/mapbox/mapbox-gl-native/pull/6102)) * Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794)) * Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879)) +* The NSClickGestureRecognizer on MGLMapView that is used for selecting annotations now fails if a click does not select an annotation. ([#7246](https://github.com/mapbox/mapbox-gl-native/pull/7246)) ## 0.2.1 - July 19, 2016 diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index ba07048262..204efd4987 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -145,7 +145,7 @@ public: NSString *imageReuseIdentifier; }; -@interface MGLMapView () <NSPopoverDelegate, MGLMultiPointDelegate> +@interface MGLMapView () <NSPopoverDelegate, MGLMultiPointDelegate, NSGestureRecognizerDelegate> @property (nonatomic, readwrite) NSSegmentedControl *zoomControls; @property (nonatomic, readwrite) NSSlider *compass; @@ -172,6 +172,7 @@ public: NSPanGestureRecognizer *_panGestureRecognizer; NSMagnificationGestureRecognizer *_magnificationGestureRecognizer; NSRotationGestureRecognizer *_rotationGestureRecognizer; + NSClickGestureRecognizer *_singleClickRecognizer; double _scaleAtBeginningOfGesture; CLLocationDirection _directionAtBeginningOfGesture; CGFloat _pitchAtBeginningOfGesture; @@ -408,9 +409,10 @@ public: _panGestureRecognizer.delaysKeyEvents = YES; [self addGestureRecognizer:_panGestureRecognizer]; - NSClickGestureRecognizer *clickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleClickGesture:)]; - clickGestureRecognizer.delaysPrimaryMouseButtonEvents = NO; - [self addGestureRecognizer:clickGestureRecognizer]; + _singleClickRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleClickGesture:)]; + _singleClickRecognizer.delaysPrimaryMouseButtonEvents = NO; + _singleClickRecognizer.delegate = self; + [self addGestureRecognizer:_singleClickRecognizer]; NSClickGestureRecognizer *rightClickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightClickGesture:)]; rightClickGestureRecognizer.buttonMask = 0x2; @@ -1540,6 +1542,20 @@ public: return nil; } +#pragma mark NSGestureRecognizerDelegate methods +- (BOOL)gestureRecognizer:(NSGestureRecognizer *)gestureRecognizer shouldAttemptToRecognizeWithEvent:(NSEvent *)event { + if (gestureRecognizer == _singleClickRecognizer) { + if (!self.selectedAnnotation) { + NSPoint gesturePoint = [self convertPoint:[event locationInWindow] fromView:nil]; + MGLAnnotationTag hitAnnotationTag = [self annotationTagAtPoint:gesturePoint persistingResults:NO]; + if (hitAnnotationTag == MGLAnnotationTagNotFound) { + return NO; + } + } + } + return YES; +} + #pragma mark Keyboard events - (void)keyDown:(NSEvent *)event { |