Chromium Code Reviews| Index: chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.mm |
| diff --git a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm b/chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.mm |
| similarity index 82% |
| copy from chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
| copy to chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.mm |
| index 4dd2c644a574850fc78ae54c78c0da9b3a7c252b..68c6aed6f0dc32c856557b9247a443da0afaa55c 100644 |
| --- a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
| +++ b/chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.mm |
| @@ -1,8 +1,8 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| +#import "chrome/browser/ui/cocoa/chrome_command_dispatch_delegate.h" |
| #include "base/logging.h" |
| #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| @@ -99,21 +99,22 @@ NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) { |
| } // namespace |
| -@implementation ChromeEventProcessingWindow |
| +@implementation ChromeCommandDispatchDelegate |
| -- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event { |
| - return HandleExtraBrowserKeyboardShortcut(event, self) || |
| - HandleExtraWindowKeyboardShortcut(event, self) || |
| - HandleDelayedWindowKeyboardShortcut(event, self); |
| +- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event window:(NSWindow*)window { |
| + return HandleExtraBrowserKeyboardShortcut(event, window) || |
| + HandleExtraWindowKeyboardShortcut(event, window) || |
| + HandleDelayedWindowKeyboardShortcut(event, window); |
| } |
| -- (BOOL)performKeyEquivalent:(NSEvent*)event { |
| +- (BOOL)performKeyEquivalent:(NSEvent*)event |
| + window:(NSWindow*)window |
|
tapted
2015/07/31 03:06:49
Could the delegate simply have a (weak) NSWindow*
jackhou1
2015/08/04 01:03:58
Done.
|
| + nativeHandler:(BOOL (^)(NSEvent*))nativePerformKeyEquivalent { |
| // Some extension commands have higher priority than web content, and some |
| // have lower priority. Regardless of whether the event is being |
| // redispatched, let the extension system try to handle the event. |
| - NSWindow* window = event.window; |
| - if (window) { |
| - BrowserWindowController* controller = [window windowController]; |
| + if (event.window) { |
|
tapted
2015/07/31 03:06:49
event.window -> window? (or, owner_?) (or, comment
jackhou1
2015/08/04 01:03:58
Done.
|
| + BrowserWindowController* controller = [event.window windowController]; |
|
tapted
2015/07/31 03:06:49
ObjCCastStrict?
And.. that might actually fail. I
tapted
2015/07/31 03:06:50
event.window -> window?
jackhou1
2015/08/04 01:03:58
Done.
|
| if ([controller respondsToSelector:@selector(handledByExtensionCommand: |
| priority:)]) { |
| ui::AcceleratorManager::HandlerPriority priority = |
| @@ -129,29 +130,28 @@ NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) { |
| // Give the web site a chance to handle the event. If it doesn't want to |
| // handle it, it will call us back with one of the |handle*| methods above. |
| - NSResponder* r = [self firstResponder]; |
| + NSResponder* r = [window firstResponder]; |
| if ([r conformsToProtocol:@protocol(RenderWidgetHostViewMacBase)]) |
| return [r performKeyEquivalent:event]; |
| // Handle per-window shortcuts like cmd-1, but do not handle browser-level |
| // shortcuts like cmd-left (else, cmd-left would do history navigation even |
| // if e.g. the Omnibox has focus). |
| - if (HandleExtraWindowKeyboardShortcut(event, self)) |
| + if (HandleExtraWindowKeyboardShortcut(event, window)) |
| return YES; |
| - if ([super performKeyEquivalent:event]) |
| + if (nativePerformKeyEquivalent(event)) |
|
tapted
2015/07/31 03:06:50
e.g. this could become [owner_ defaultPerformKeyEq
jackhou1
2015/08/04 01:03:58
Done.
|
| return YES; |
| // Handle per-window shortcuts like Esc after giving everybody else a chance |
| // to handle them |
| - return HandleDelayedWindowKeyboardShortcut(event, self); |
| + return HandleDelayedWindowKeyboardShortcut(event, window); |
| } |
| -- (BOOL)redispatchKeyEvent:(NSEvent*)event { |
| +- (BOOL)redispatchKeyEvent:(NSEvent*)event window:(NSWindow*)window { |
| DCHECK(event); |
| NSEventType eventType = [event type]; |
| - if (eventType != NSKeyDown && |
| - eventType != NSKeyUp && |
| + if (eventType != NSKeyDown && eventType != NSKeyUp && |
| eventType != NSFlagsChanged) { |
| NOTREACHED(); |
| return YES; // Pretend it's been handled in an effort to limit damage. |
| @@ -163,8 +163,8 @@ NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) { |
| // the renderer is running slowly and several mode switches occur). In this |
| // rare case, we synthesize a new key event so that its associate window |
| // (number) is our own. |
| - if ([event window] != self) |
| - event = KeyEventForWindow(self, event); |
| + if ([event window] != window) |
| + event = KeyEventForWindow(window, event); |
| // Redispatch the event. |
| eventHandled_ = YES; |
| @@ -178,11 +178,13 @@ NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) { |
| return eventHandled_; |
| } |
| -- (void)sendEvent:(NSEvent*)event { |
| - if (!redispatchingEvent_) |
| - [super sendEvent:event]; |
| - else |
| +- (BOOL)preSendEvent:(NSEvent*)event { |
| + if (redispatchingEvent_) { |
| eventHandled_ = NO; |
| + return NO; |
| + } |
| + |
| + return YES; |
| } |
| -@end // ChromeEventProcessingWindow |
| +@end // ChromeCommandDispatchDelegate |