OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 5 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" | 8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" |
9 | 9 |
10 @implementation ChromeEventProcessingWindow { | 10 @implementation ChromeEventProcessingWindow { |
11 @private | 11 @private |
12 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; | 12 base::scoped_nsobject<CommandDispatcher> commandDispatcher_; |
13 base::scoped_nsobject<ChromeCommandDispatcherDelegate> | 13 base::scoped_nsobject<ChromeCommandDispatcherDelegate> |
14 commandDispatcherDelegate_; | 14 commandDispatcherDelegate_; |
15 } | 15 } |
16 | 16 |
| 17 @synthesize commandHandler; |
| 18 |
17 - (instancetype)initWithContentRect:(NSRect)contentRect | 19 - (instancetype)initWithContentRect:(NSRect)contentRect |
18 styleMask:(NSUInteger)windowStyle | 20 styleMask:(NSUInteger)windowStyle |
19 backing:(NSBackingStoreType)bufferingType | 21 backing:(NSBackingStoreType)bufferingType |
20 defer:(BOOL)deferCreation { | 22 defer:(BOOL)deferCreation { |
21 if ((self = [super initWithContentRect:contentRect | 23 if ((self = [super initWithContentRect:contentRect |
22 styleMask:windowStyle | 24 styleMask:windowStyle |
23 backing:bufferingType | 25 backing:bufferingType |
24 defer:deferCreation])) { | 26 defer:deferCreation])) { |
25 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]); | 27 commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]); |
26 commandDispatcherDelegate_.reset( | 28 commandDispatcherDelegate_.reset( |
(...skipping 11 matching lines...) Expand all Loading... |
38 // CommandDispatchingWindow implementation. | 40 // CommandDispatchingWindow implementation. |
39 | 41 |
40 - (BOOL)redispatchKeyEvent:(NSEvent*)event { | 42 - (BOOL)redispatchKeyEvent:(NSEvent*)event { |
41 return [commandDispatcher_ redispatchKeyEvent:event]; | 43 return [commandDispatcher_ redispatchKeyEvent:event]; |
42 } | 44 } |
43 | 45 |
44 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { | 46 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event { |
45 return [super performKeyEquivalent:event]; | 47 return [super performKeyEquivalent:event]; |
46 } | 48 } |
47 | 49 |
| 50 - (void)commandDispatch:(id)sender { |
| 51 [[self commandHandler] commandDispatch:sender window:self]; |
| 52 } |
| 53 |
| 54 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
| 55 [[self commandHandler] commandDispatchUsingKeyModifiers:sender window:self]; |
| 56 } |
| 57 |
48 // NSWindow overrides. | 58 // NSWindow overrides. |
49 | 59 |
50 - (BOOL)performKeyEquivalent:(NSEvent*)event { | 60 - (BOOL)performKeyEquivalent:(NSEvent*)event { |
51 return [commandDispatcher_ performKeyEquivalent:event]; | 61 return [commandDispatcher_ performKeyEquivalent:event]; |
52 } | 62 } |
53 | 63 |
54 - (void)sendEvent:(NSEvent*)event { | 64 - (void)sendEvent:(NSEvent*)event { |
55 if (![commandDispatcher_ preSendEvent:event]) | 65 if (![commandDispatcher_ preSendEvent:event]) |
56 [super sendEvent:event]; | 66 [super sendEvent:event]; |
57 } | 67 } |
58 | 68 |
| 69 // NSWindow overrides (NSUserInterfaceValidations implementation). |
| 70 |
| 71 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 72 // Since this class implements these selectors, |super| will always say they |
| 73 // are enabled. Only use [super] to validate other selectors. If there is no |
| 74 // command handler, defer to AppController. |
| 75 if ([item action] == @selector(commandDispatch:) || |
| 76 [item action] == @selector(commandDispatchUsingKeyModifiers:)) { |
| 77 return |
| 78 [self commandHandler] |
| 79 ? [[self commandHandler] validateUserInterfaceItem:item window:self] |
| 80 : [[NSApp delegate] validateUserInterfaceItem:item]; |
| 81 } |
| 82 |
| 83 return [super validateUserInterfaceItem:item]; |
| 84 } |
| 85 |
59 @end // ChromeEventProcessingWindow | 86 @end // ChromeEventProcessingWindow |
OLD | NEW |