OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/chrome_event_processing_window.h" | 5 #import "chrome/browser/cocoa/chrome_event_processing_window.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "chrome/browser/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/cocoa/browser_command_executor.h" |
9 #import "chrome/browser/cocoa/browser_frame_view.h" | 9 #import "chrome/browser/cocoa/browser_frame_view.h" |
10 #import "chrome/browser/cocoa/tab_strip_controller.h" | 10 #import "chrome/browser/cocoa/tab_strip_controller.h" |
11 #import "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 11 #import "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
12 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 12 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
13 | 13 |
14 typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int); | 14 typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int); |
15 | 15 |
16 @implementation ChromeEventProcessingWindow | 16 @implementation ChromeEventProcessingWindow |
17 | 17 |
18 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable: | 18 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable: |
19 (KeyToCommandMapper)commandForKeyboardShortcut { | 19 (KeyToCommandMapper)commandForKeyboardShortcut { |
20 // Extract info from |event|. | 20 // Extract info from |event|. |
21 NSUInteger modifers = [event modifierFlags]; | 21 NSUInteger modifers = [event modifierFlags]; |
22 const bool cmdKey = modifers & NSCommandKeyMask; | 22 const bool cmdKey = modifers & NSCommandKeyMask; |
23 const bool shiftKey = modifers & NSShiftKeyMask; | 23 const bool shiftKey = modifers & NSShiftKeyMask; |
24 const bool cntrlKey = modifers & NSControlKeyMask; | 24 const bool cntrlKey = modifers & NSControlKeyMask; |
25 const bool optKey = modifers & NSAlternateKeyMask; | 25 const bool optKey = modifers & NSAlternateKeyMask; |
26 const int keyCode = [event keyCode]; | 26 const int keyCode = [event keyCode]; |
27 | 27 |
28 int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, optKey, | 28 int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, optKey, |
29 keyCode); | 29 keyCode); |
30 | 30 |
31 BrowserWindowController* controller = | |
32 (BrowserWindowController*)[self delegate]; | |
33 // A bit of sanity. | |
34 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); | |
35 DCHECK([controller respondsToSelector:@selector(executeCommand:)]); | |
36 | |
37 if (cmdNum != -1) { | 31 if (cmdNum != -1) { |
38 [controller executeCommand:cmdNum]; | 32 id executor = [self delegate]; |
| 33 // A bit of sanity. |
| 34 DCHECK([executor conformsToProtocol:@protocol(BrowserCommandExecutor)]); |
| 35 DCHECK([executor respondsToSelector:@selector(executeCommand:)]); |
| 36 [executor executeCommand:cmdNum]; |
39 return YES; | 37 return YES; |
40 } | 38 } |
41 return NO; | 39 return NO; |
42 } | 40 } |
43 | 41 |
44 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { | 42 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { |
45 return [self handleExtraKeyboardShortcut:event | 43 return [self handleExtraKeyboardShortcut:event |
46 fromTable:CommandForWindowKeyboardShortcut]; | 44 fromTable:CommandForWindowKeyboardShortcut]; |
47 } | 45 } |
48 | 46 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 101 |
104 - (void)sendEvent:(NSEvent*)event { | 102 - (void)sendEvent:(NSEvent*)event { |
105 if (!redispatchingEvent_) | 103 if (!redispatchingEvent_) |
106 [super sendEvent:event]; | 104 [super sendEvent:event]; |
107 else | 105 else |
108 eventHandled_ = NO; | 106 eventHandled_ = NO; |
109 } | 107 } |
110 | 108 |
111 @end // ChromeEventProcessingWindow | 109 @end // ChromeEventProcessingWindow |
112 | 110 |
OLD | NEW |