Redispatch events to handle native shortcuts
This commit is contained in:
parent
66fe1e48e8
commit
a2bbfea9e0
3 changed files with 53 additions and 24 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#include "atom/browser/native_window_mac.h"
|
||||||
#include "content/public/browser/native_web_keyboard_event.h"
|
#include "content/public/browser/native_web_keyboard_event.h"
|
||||||
#include "ui/events/keycodes/keyboard_codes.h"
|
#include "ui/events/keycodes/keyboard_codes.h"
|
||||||
|
|
||||||
|
@ -22,17 +23,9 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||||
if (event.windowsKeyCode == ui::VKEY_ESCAPE && is_html_fullscreen())
|
if (event.windowsKeyCode == ui::VKEY_ESCAPE && is_html_fullscreen())
|
||||||
ExitFullscreenModeForTab(source);
|
ExitFullscreenModeForTab(source);
|
||||||
|
|
||||||
BOOL handled = [[NSApp mainMenu] performKeyEquivalent:event.os_event];
|
if (event.os_event.window) {
|
||||||
if (!handled && event.os_event.window) {
|
AtomNSWindow* native_window = static_cast<AtomNSWindow*>(event.os_event.window);
|
||||||
// Handle the cmd+~ shortcut.
|
[native_window redispatchKeyEvent:event.os_event];
|
||||||
if ((event.os_event.modifierFlags & NSCommandKeyMask) /* cmd */ &&
|
|
||||||
(event.os_event.keyCode == 50 /* ~ */)) {
|
|
||||||
if (event.os_event.modifierFlags & NSShiftKeyMask) {
|
|
||||||
[NSApp sendAction:@selector(_cycleWindowsReversed:) to:nil from:nil];
|
|
||||||
} else {
|
|
||||||
[NSApp sendAction:@selector(_cycleWindows:) to:nil from:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,4 +152,21 @@ class NativeWindowMac : public NativeWindow {
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
||||||
|
@interface AtomNSWindow : NSWindow {
|
||||||
|
@private
|
||||||
|
atom::NativeWindowMac* shell_;
|
||||||
|
bool enable_larger_than_screen_;
|
||||||
|
BOOL redispatchingEvent_;
|
||||||
|
BOOL eventHandled_;
|
||||||
|
}
|
||||||
|
@property BOOL acceptsFirstMouse;
|
||||||
|
@property BOOL disableAutoHideCursor;
|
||||||
|
@property BOOL disableKeyOrMainWindow;
|
||||||
|
|
||||||
|
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||||
|
- (void)setEnableLargerThanScreen:(bool)enable;
|
||||||
|
- (BOOL)redispatchKeyEvent:(NSEvent*)event;
|
||||||
|
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
|
||||||
|
@end
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_NATIVE_WINDOW_MAC_H_
|
#endif // ATOM_BROWSER_NATIVE_WINDOW_MAC_H_
|
||||||
|
|
|
@ -270,19 +270,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AtomNSWindow : NSWindow {
|
|
||||||
@private
|
|
||||||
atom::NativeWindowMac* shell_;
|
|
||||||
bool enable_larger_than_screen_;
|
|
||||||
}
|
|
||||||
@property BOOL acceptsFirstMouse;
|
|
||||||
@property BOOL disableAutoHideCursor;
|
|
||||||
@property BOOL disableKeyOrMainWindow;
|
|
||||||
|
|
||||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
|
||||||
- (void)setEnableLargerThanScreen:(bool)enable;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation AtomNSWindow
|
@implementation AtomNSWindow
|
||||||
|
|
||||||
- (void)setShell:(atom::NativeWindowMac*)shell {
|
- (void)setShell:(atom::NativeWindowMac*)shell {
|
||||||
|
@ -347,6 +334,38 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
return !self.disableKeyOrMainWindow;
|
return !self.disableKeyOrMainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)sendEvent:(NSEvent*)event {
|
||||||
|
if (!redispatchingEvent_)
|
||||||
|
[super sendEvent:event];
|
||||||
|
else
|
||||||
|
eventHandled_ = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)performKeyEquivalent:(NSEvent*)event {
|
||||||
|
if (redispatchingEvent_)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
if ([super performKeyEquivalent:event])
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)redispatchKeyEvent:(NSEvent*)event {
|
||||||
|
NSEventType eventType = [event type];
|
||||||
|
if (eventType != NSKeyDown && eventType != NSKeyUp &&
|
||||||
|
eventType != NSFlagsChanged) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redispatch the event.
|
||||||
|
eventHandled_ = YES;
|
||||||
|
redispatchingEvent_ = YES;
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
redispatchingEvent_ = NO;
|
||||||
|
|
||||||
|
return eventHandled_;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface ControlRegionView : NSView
|
@interface ControlRegionView : NSView
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue