[osx] Exclude subviews from click gestures

Fixes #3418.
This commit is contained in:
Minh Nguyễn
2016-05-09 00:17:22 -07:00
committed by Minh Nguyễn
parent c4b3c0142c
commit df1cae8d3a
2 changed files with 23 additions and 3 deletions

View File

@@ -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];
}
}
}

View File

@@ -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 {