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. |
tapted
2015/08/26 03:04:49
Should say, "If the NSWindow's firstResponder impl
jackhou1
2015/08/26 06:24:42
Done.
|
+// 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 |
tapted
2015/08/26 03:04:49
declare performKeyEquivalent:(NSvent*)
jackhou1
2015/08/26 06:24:42
Done.
|
+ |
+// Implements a set of hooks into the -performKeyEquivalent flow. |
tapted
2015/08/26 03:04:49
perhaps more like "Provides CommandDispatcher with
jackhou1
2015/08/26 06:24:43
Done.
|
+@protocol CommandDispatcherDelegate<NSObject> |
+- (BOOL)handledByExtensionCommand:(NSEvent*)event |
tapted
2015/08/26 03:04:49
nit: objc style guide says stuff in .h must have a
jackhou1
2015/08/26 06:24:42
Done.
|
+ 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. |
tapted
2015/08/26 03:04:49
Is `RenderWidgetHostView` relevant to this part? I
jackhou1
2015/08/26 06:24:43
Done.
|
+// See CommandDispatcherImpl for usage. |
+@protocol CommandDispatcher |
tapted
2015/08/26 03:04:49
I think call this `CommandDispatchingWindow` (or C
jackhou1
2015/08/26 06:24:42
Done.
|
+- (void)setCommandDispatcherDelegate:(id<CommandDispatcherDelegate>)delegate; |
tapted
2015/08/26 03:04:49
Not sure if this belongs here (coming back to this
jackhou1
2015/08/26 06:24:43
Moved to NativeWidgetMacNSWindow.
|
+// Sends a key event to |NSApp sendEvent:|, but also makes sure that it's not |
tapted
2015/08/26 03:04:49
nit: blank line before
jackhou1
2015/08/26 06:24:42
Done.
|
+// short-circuited to the RWHV. This is used to send keyboard events to the menu |
tapted
2015/08/26 03:04:48
RHHV -> CommandDispatcherTarget
jackhou1
2015/08/26 06:24:42
Done.
|
+// 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 |
tapted
2015/08/26 03:04:49
nit: blank line before
jackhou1
2015/08/26 06:24:42
Done.
|
+// CommandDispatcherImpl calls as part of its -performKeyEquivalent flow. |
+- (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; |
+@end |
+ |
+// Handles dispatch of key events including redispatching an unhandled event |
tapted
2015/08/26 03:04:49
I think this class should be declared first in thi
jackhou1
2015/08/26 06:24:42
Done.
Re-wrote most of the commentary in this fil
|
+// to NSApplication. |
+@interface CommandDispatcherImpl : NSObject { |
tapted
2015/08/26 03:04:48
Then this can just be called `CommandDispatcher`
jackhou1
2015/08/26 06:24:42
Done.
|
+ @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; |
tapted
2015/08/26 03:04:48
@property? (then it doesn't need a comment :p)
jackhou1
2015/08/26 06:24:42
Done.
|
+ |
+// The CommandDispatcher should override -[NSResponder performKeyEquivalent:] |
tapted
2015/08/26 03:04:48
CommandDispatcher -> CommandDispatchingWindow
jackhou1
2015/08/26 06:24:42
Done.
|
+// with this. Handles various keyboard shortcut hooks before and after native |
tapted
2015/08/26 03:04:49
nit: with this -> and call this instead
jackhou1
2015/08/26 06:24:43
Done.
|
+// -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_ |