| 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_window_controller.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { | 43 - (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event { |
| 44 return [self handleExtraKeyboardShortcut:event | 44 return [self handleExtraKeyboardShortcut:event |
| 45 fromTable:CommandForWindowKeyboardShortcut]; | 45 fromTable:CommandForWindowKeyboardShortcut]; |
| 46 } | 46 } |
| 47 | 47 |
| 48 - (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { | 48 - (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event { |
| 49 return [self handleExtraKeyboardShortcut:event | 49 return [self handleExtraKeyboardShortcut:event |
| 50 fromTable:CommandForBrowserKeyboardShortcut]; | 50 fromTable:CommandForBrowserKeyboardShortcut]; |
| 51 } | 51 } |
| 52 | 52 |
| 53 - (BOOL)shortcircuitEvent:(NSEvent*)event { |
| 54 if (!redispatchingEvent_ && |
| 55 ([event type] == NSKeyDown || [event type] == NSKeyUp)) { |
| 56 if ([[self firstResponder] |
| 57 isKindOfClass:[RenderWidgetHostViewCocoa class]]) { |
| 58 // No other mac browser sends keyup() for keyboard equivalents, so let's |
| 59 // suppress this. |
| 60 if (([event modifierFlags] & NSCommandKeyMask) && [event type] == NSKeyUp) |
| 61 return YES; |
| 62 |
| 63 RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>( |
| 64 [self firstResponder]); |
| 65 [rwhv keyEvent:event]; |
| 66 return YES; |
| 67 } |
| 68 } |
| 69 return NO; |
| 70 } |
| 71 |
| 53 - (BOOL)performKeyEquivalent:(NSEvent*)event { | 72 - (BOOL)performKeyEquivalent:(NSEvent*)event { |
| 54 // We have some magic in |CrApplication sendEvent:| that always sends key | 73 if (redispatchingEvent_) |
| 55 // events to |RWHVCocoa keyEvent:| so that cocoa doesn't have a chance to | 74 return NO; |
| 56 // intercept it. | 75 |
| 76 // |shortcircuitEvent:| should handle all events directed to the RWHV. |
| 57 DCHECK(![[self firstResponder] | 77 DCHECK(![[self firstResponder] |
| 58 isKindOfClass:[RenderWidgetHostViewCocoa class]]); | 78 isKindOfClass:[RenderWidgetHostViewCocoa class]]); |
| 59 | 79 |
| 60 // Handle per-window shortcuts like cmd-1, but do not handle browser-level | 80 // Handle per-window shortcuts like cmd-1, but do not handle browser-level |
| 61 // shortcuts like cmd-left (else, cmd-left would do history navigation even | 81 // shortcuts like cmd-left (else, cmd-left would do history navigation even |
| 62 // if e.g. the Omnibox has focus). If the web has focus, don't do this here, | 82 // if e.g. the Omnibox has focus). If the web has focus, don't do this here, |
| 63 // since the web needs to get a chance at swallowing the event first. | 83 // since the web needs to get a chance at swallowing the event first. |
| 64 if ([self handleExtraWindowKeyboardShortcut:event]) | 84 if ([self handleExtraWindowKeyboardShortcut:event]) |
| 65 return YES; | 85 return YES; |
| 66 return [super performKeyEquivalent:event]; | 86 return [super performKeyEquivalent:event]; |
| 67 } | 87 } |
| 68 | 88 |
| 89 - (void)redispatchEvent:(NSEvent*)event { |
| 90 DCHECK([event window] == self); |
| 91 redispatchingEvent_ = YES; |
| 92 [NSApp sendEvent:event]; |
| 93 redispatchingEvent_ = NO; |
| 94 } |
| 95 |
| 96 - (void)sendEvent:(NSEvent*)event { |
| 97 if (!redispatchingEvent_) |
| 98 [super sendEvent:event]; |
| 99 } |
| 100 |
| 69 @end // ChromeEventProcessingWindow | 101 @end // ChromeEventProcessingWindow |
| 70 | 102 |
| OLD | NEW |