Chromium Code Reviews| Index: ui/base/cocoa/command_dispatcher.h |
| diff --git a/ui/base/cocoa/command_dispatcher.h b/ui/base/cocoa/command_dispatcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c1905a71a51e637ef2a1f1dd1ac002d775797906 |
| --- /dev/null |
| +++ b/ui/base/cocoa/command_dispatcher.h |
| @@ -0,0 +1,74 @@ |
| +// 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. |
| + |
| +#ifndef UI_BASE_COCOA_COMMAND_DISPATCHER_H_ |
| +#define UI_BASE_COCOA_COMMAND_DISPATCHER_H_ |
| + |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#import "base/mac/scoped_nsobject.h" |
| + |
| +// CommandDispatcherImpl will dispatch -performKeyEquivalent to this first. |
| +// If the event is not handled, CommandDispatcherTarget is expected to return |
| +// the event via -redispatchKeyEvent. |
| +// The Mac RenderWidgetHostView implementation conforms to this protocol. |
| +@protocol CommandDispatcherTarget |
| +@end |
| + |
| +// Implements a set of hooks into the -performKeyEquivalent flow. |
| +@protocol CommandDispatcherDelegate<NSObject> |
| +- (BOOL)handledByExtensionCommand:(NSEvent*)event |
| + isRedispatch:(BOOL)isRedispatch; |
| +- (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; |
| +- (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; |
| +@end |
| + |
| +// Interface for an NSWindow that will dispatch key events to a |
| +// RenderWidgetHostView and handle redispatching them if they are not handled. |
| +// See CommandDispatcherImpl for usage. |
| +@protocol CommandDispatcher |
|
tapted
2015/08/18 07:22:12
I *think* this can be merged with CommandDispatche
jackhou1
2015/08/25 06:31:12
In MacViews, NativeWidgetMacNSWindow is the Comman
tapted
2015/08/26 03:04:48
Ahhhhh. Yep. my plan would only work if we could i
|
| +- (void)setCommandDispatcherDelegate:(id<CommandDispatcherDelegate>)delegate; |
| +// Sends a key event to |NSApp sendEvent:|, but also makes sure that it's not |
| +// short-circuited to the RWHV. This is used to send keyboard events to the menu |
| +// and the cmd-` handler if a keyboard event comes back unhandled from the |
| +// renderer. The event must be of type |NSKeyDown|, |NSKeyUp|, or |
| +// |NSFlagsChanged|. |
| +// Returns |YES| if |event| has been handled. |
| +- (BOOL)redispatchKeyEvent:(NSEvent*)event; |
| +// Short-circuit to the default -[NSResponder performKeyEquivalent:] which |
| +// CommandDispatcherImpl calls as part of its -performKeyEquivalent flow. |
| +- (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; |
| +@end |
| + |
| +// Handles dispatch of key events including redispatching an unhandled event |
| +// to NSApplication. |
| +@interface CommandDispatcherImpl : NSObject { |
| + @private |
| + BOOL redispatchingEvent_; |
| + BOOL eventHandled_; |
| + NSWindow<CommandDispatcher>* owner_; // Weak, owns us. |
| + base::scoped_nsprotocol<id<CommandDispatcherDelegate>> delegate_; |
| +} |
| + |
| +- (id)initWithOwner:(NSWindow<CommandDispatcher>*)owner; |
| + |
| +- (void)setDelegate:(id<CommandDispatcherDelegate>)delegate; |
| + |
| +// The CommandDispatcher should override -[NSResponder performKeyEquivalent:] |
| +// with this. Handles various keyboard shortcut hooks before and after native |
| +// -performKeyEquivalent. Returns YES if the event is handled. |
| +- (BOOL)performKeyEquivalent:(NSEvent*)event; |
| + |
| +// The CommandDispatcher should implement -redispatchKeyEvent: with this. Send |
| +// the event to NSApp so it can be handled natively. Ensures that the event is |
| +// not reposted infinitely. |
| +- (BOOL)redispatchKeyEvent:(NSEvent*)event; |
| + |
| +// The CommandDispatcher should call this before a native -sendEvent. Returns |
| +// YES if the event is handled. |
| +- (BOOL)preSendEvent:(NSEvent*)event; |
| + |
| +@end |
| + |
| +#endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ |