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

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

Issue 1259903002: DO NOT COMMIT: [Mac] Refactor keyboard shortcut handling so it can be reused in Views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to new CommandDispatcher design. 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..a14550ff8c8a3e41ef282f270075ed5085bf3d21 100644
--- a/ui/views/cocoa/native_widget_mac_nswindow.mm
+++ b/ui/views/cocoa/native_widget_mac_nswindow.mm
@@ -22,6 +22,27 @@
@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])) {
+ commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]);
+ }
+ return self;
+}
+
+// Public methods.
+
+- (void)setCommandDispatcherDelegate:(id<CommandDispatcherDelegate>)delegate {
+ [commandDispatcher_ setDelegate:delegate];
+}
+
+// Private methods.
+
- (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]);
}
@@ -36,6 +57,8 @@
return menuController && menuController->owner() == [self viewsWidget];
}
+// NSWindow overrides.
+
- (BOOL)_isTitleHidden {
if (![self delegate])
return NO;
@@ -64,6 +87,10 @@
// menu while it is active, and while still allowing any native subview to
// retain firstResponder status.
- (void)sendEvent:(NSEvent*)event {
+ // Let CommandDispatcher check if this is a redispatched event.
+ if ([commandDispatcher_ preSendEvent:event])
+ return;
+
NSEventType type = [event type];
if ((type != NSKeyDown && type != NSKeyUp) || ![self hasViewsMenuActive]) {
[super sendEvent:event];
@@ -104,6 +131,10 @@
// NSResponder implementation.
+- (BOOL)performKeyEquivalent:(NSEvent*)event {
+ return [commandDispatcher_ 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 +155,28 @@
[super cursorUpdate:theEvent];
}
+// CommandDispatcher implementation.
+
+@synthesize commandHandler;
+
+- (BOOL)redispatchKeyEvent:(NSEvent*)event {
+ return [commandDispatcher_ redispatchKeyEvent:event];
+}
+
+- (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
+ return [super performKeyEquivalent:event];
+}
+
+- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
+ return [[self commandHandler] validateUserInterfaceItem:item window:self];
+}
+
+- (void)commandDispatch:(id)sender {
+ [[self commandHandler] commandDispatch:sender window:self];
+}
+
+- (void)commandDispatchUsingKeyModifiers:(id)sender {
+ [[self commandHandler] commandDispatchUsingKeyModifiers:sender window:self];
+}
+
@end
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.h ('k') | ui/views/controls/webview/unhandled_keyboard_event_handler_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698