[macos] Use gesture recognizer for context menu

NSView’s built-in context menu handling preempts non-right-click gesture recognizers, so preempt it with a right-click gesture recognizer that does essentially the same thing. With this change, two-finger double-tapping on a trackpad also zooms out, consistent with MapKit.

Fixes #5078.
This commit is contained in:
Minh Nguyễn
2016-07-06 11:21:30 -07:00
committed by Konstantin Käfer
parent d929e32217
commit e603cf46f1
3 changed files with 15 additions and 1 deletions

View File

@@ -395,6 +395,10 @@ public:
clickGestureRecognizer.delaysPrimaryMouseButtonEvents = NO;
[self addGestureRecognizer:clickGestureRecognizer];
NSClickGestureRecognizer *rightClickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightClickGesture:)];
rightClickGestureRecognizer.buttonMask = 0x2;
[self addGestureRecognizer:rightClickGestureRecognizer];
NSClickGestureRecognizer *doubleClickGestureRecognizer = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleClickGesture:)];
doubleClickGestureRecognizer.numberOfClicksRequired = 2;
doubleClickGestureRecognizer.delaysPrimaryMouseButtonEvents = NO;
@@ -1359,6 +1363,14 @@ public:
}
}
/// Right-click to show the context menu.
- (void)handleRightClickGesture:(NSClickGestureRecognizer *)gestureRecognizer {
NSMenu *menu = [self menuForEvent:[NSApp currentEvent]];
if (menu) {
[NSMenu popUpContextMenu:menu withEvent:[NSApp currentEvent] forView:self];
}
}
/// Double-click or double-tap to zoom in.
- (void)handleDoubleClickGesture:(NSClickGestureRecognizer *)gestureRecognizer {
if (!self.zoomEnabled || gestureRecognizer.state != NSGestureRecognizerStateEnded