Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: ui/views/cocoa/native_widget_mac_nswindow.mm

Issue 1255783002: [Mac] Factor out keyboard shortcut handling from ChromeEventProcessingWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@execute
Patch Set: Separate CommandDispatcher and CommandDispatcherDelegate. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/cocoa/native_widget_mac_nswindow.mm
diff --git a/ui/views/cocoa/native_widget_mac_nswindow.mm b/ui/views/cocoa/native_widget_mac_nswindow.mm
index 8799ee15a35550cea141390c6a4f51f9d5de6c6c..dcbcb46dbf1a06770e323b8db5b3409d6b78acb7 100644
--- a/ui/views/cocoa/native_widget_mac_nswindow.mm
+++ b/ui/views/cocoa/native_widget_mac_nswindow.mm
@@ -22,6 +22,20 @@
@implementation NativeWidgetMacNSWindow
+- (instancetype)initWithContentRect:(NSRect)contentRect
+ styleMask:(NSUInteger)windowStyle
+ backing:(NSBackingStoreType)bufferingType
+ defer:(BOOL)deferCreation {
+ if ((self = [super initWithContentRect:contentRect
+ styleMask:windowStyle
+ backing:bufferingType
+ defer:deferCreation])) {
+ commandDispatcherImpl_.reset(
+ [[CommandDispatcherImpl alloc] initWithOwner:self]);
+ }
+ return self;
+}
+
- (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]);
}
@@ -64,6 +78,10 @@
// menu while it is active, and while still allowing any native subview to
// retain firstResponder status.
- (void)sendEvent:(NSEvent*)event {
+ // Let CommandDispatcherImpl check if this is a redispatched event.
+ if ([commandDispatcherImpl_ preSendEvent:event])
+ return;
+
NSEventType type = [event type];
if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) {
[super sendEvent:event];
@@ -104,6 +122,10 @@
// NSResponder implementation.
+- (BOOL)performKeyEquivalent:(NSEvent*)event {
+ return [commandDispatcherImpl_ performKeyEquivalent:event];
+}
+
- (void)cursorUpdate:(NSEvent*)theEvent {
// The cursor provided by the delegate should only be applied within the
// content area. This is because we rely on the contentView to track the
@@ -124,4 +146,18 @@
[super cursorUpdate:theEvent];
}
+// CommandDispatcher implementation.
+
+- (void)setCommandDispatcherDelegate:(id<CommandDispatcherDelegate>)delegate {
+ [commandDispatcherImpl_ setDelegate:delegate];
+}
+
+- (BOOL)redispatchKeyEvent:(NSEvent*)event {
+ return [commandDispatcherImpl_ redispatchKeyEvent:event];
+}
+
+- (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
+ return [super performKeyEquivalent:event];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698