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_command_executor.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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 return YES; | 37 return YES; |
38 } | 38 } |
39 return NO; | 39 return NO; |
40 } | 40 } |
41 | 41 |
42 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { | 42 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { |
43 return [self handleExtraKeyboardShortcut:event | 43 return [self handleExtraKeyboardShortcut:event |
44 fromTable:CommandForWindowKeyboardShortcut]; | 44 fromTable:CommandForWindowKeyboardShortcut]; |
45 } | 45 } |
46 | 46 |
| 47 - (BOOL)handleDelayedWindowKeyboardShortcut:(NSEvent*)event { |
| 48 return [self handleExtraKeyboardShortcut:event |
| 49 fromTable:CommandForDelayedWindowKeyboardShortcut]; |
| 50 } |
| 51 |
47 - (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { | 52 - (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { |
48 return [self handleExtraKeyboardShortcut:event | 53 return [self handleExtraKeyboardShortcut:event |
49 fromTable:CommandForBrowserKeyboardShortcut]; | 54 fromTable:CommandForBrowserKeyboardShortcut]; |
50 } | 55 } |
51 | 56 |
52 - (BOOL)performKeyEquivalent:(NSEvent*)event { | 57 - (BOOL)performKeyEquivalent:(NSEvent*)event { |
53 if (redispatchingEvent_) | 58 if (redispatchingEvent_) |
54 return NO; | 59 return NO; |
55 | 60 |
56 // Give the web site a chance to handle the event. If it doesn't want to | 61 // Give the web site a chance to handle the event. If it doesn't want to |
57 // handle it, it will call us back with one of the |handle*| methods above. | 62 // handle it, it will call us back with one of the |handle*| methods above. |
58 NSResponder* r = [self firstResponder]; | 63 NSResponder* r = [self firstResponder]; |
59 if ([r isKindOfClass:[RenderWidgetHostViewCocoa class]]) | 64 if ([r isKindOfClass:[RenderWidgetHostViewCocoa class]]) |
60 return [r performKeyEquivalent:event]; | 65 return [r performKeyEquivalent:event]; |
61 | 66 |
62 // Handle per-window shortcuts like cmd-1, but do not handle browser-level | 67 // Handle per-window shortcuts like cmd-1, but do not handle browser-level |
63 // shortcuts like cmd-left (else, cmd-left would do history navigation even | 68 // shortcuts like cmd-left (else, cmd-left would do history navigation even |
64 // if e.g. the Omnibox has focus). | 69 // if e.g. the Omnibox has focus). |
65 if ([self handleExtraWindowKeyboardShortcut:event]) | 70 if ([self handleExtraWindowKeyboardShortcut:event]) |
66 return YES; | 71 return YES; |
67 return [super performKeyEquivalent:event]; | 72 |
| 73 if ([super performKeyEquivalent:event]) |
| 74 return YES; |
| 75 |
| 76 // Handle per-window shortcuts like Esc after giving everybody else a chance |
| 77 // to handle them |
| 78 return [self handleDelayedWindowKeyboardShortcut:event]; |
68 } | 79 } |
69 | 80 |
70 - (BOOL)redispatchEvent:(NSEvent*)event { | 81 - (BOOL)redispatchEvent:(NSEvent*)event { |
71 DCHECK(event); | 82 DCHECK(event); |
72 DCHECK_EQ([event window], self); | 83 DCHECK_EQ([event window], self); |
73 eventHandled_ = YES; | 84 eventHandled_ = YES; |
74 redispatchingEvent_ = YES; | 85 redispatchingEvent_ = YES; |
75 [NSApp sendEvent:event]; | 86 [NSApp sendEvent:event]; |
76 redispatchingEvent_ = NO; | 87 redispatchingEvent_ = NO; |
77 | 88 |
78 // If the event was not handled by [NSApp sendEvent:], the sendEvent: | 89 // If the event was not handled by [NSApp sendEvent:], the sendEvent: |
79 // method below will be called, and because |redispatchingEvent_| is YES, | 90 // method below will be called, and because |redispatchingEvent_| is YES, |
80 // |eventHandled_| will be set to NO. | 91 // |eventHandled_| will be set to NO. |
81 return eventHandled_; | 92 return eventHandled_; |
82 } | 93 } |
83 | 94 |
84 - (void)sendEvent:(NSEvent*)event { | 95 - (void)sendEvent:(NSEvent*)event { |
85 if (!redispatchingEvent_) | 96 if (!redispatchingEvent_) |
86 [super sendEvent:event]; | 97 [super sendEvent:event]; |
87 else | 98 else |
88 eventHandled_ = NO; | 99 eventHandled_ = NO; |
89 } | 100 } |
90 | 101 |
91 @end // ChromeEventProcessingWindow | 102 @end // ChromeEventProcessingWindow |
92 | 103 |
OLD | NEW |