Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Side by Side Diff: ui/base/cocoa/command_dispatcher.h

Issue 1255783002: [Mac] Factor out keyboard shortcut handling from ChromeEventProcessingWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@execute
Patch Set: And a couple more minor comment nits. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_BASE_COCOA_COMMAND_DISPATCHER_H_
6 #define UI_BASE_COCOA_COMMAND_DISPATCHER_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #import "base/mac/scoped_nsobject.h"
11
12 @protocol CommandDispatcherDelegate;
13 @protocol CommandDispatchingWindow;
14
15 // CommandDispatcher guides the processing of key events to ensure key commands
16 // are executed in the appropriate order. In particular, it allows a first
17 // responder implementing CommandDispatcherTarget to handle an event
18 // asynchronously and return unhandled events via -redispatchKeyEvent. An
19 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow
20 // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:]
21 // to call the respective CommandDispatcher methods.
22 @interface CommandDispatcher : NSObject
23
24 @property(assign, nonatomic) id<CommandDispatcherDelegate> delegate;
25
26 - (instancetype)initWithOwner:(NSWindow<CommandDispatchingWindow>*)owner;
27
28 // The main entry point for key events. The CommandDispatchingWindow should
29 // override -[NSResponder performKeyEquivalent:] and call this instead. Returns
30 // YES if the event is handled.
31 - (BOOL)performKeyEquivalent:(NSEvent*)event;
32
33 // Sends a key event to -[NSApp sendEvent:]. This is used to allow default
34 // AppKit handling of an event that comes back from CommandDispatcherTarget,
35 // e.g. key equivalents in the menu, or window manager commands like Cmd+`. Once
36 // the event returns to the window at -preSendEvent, handling will stop. The
Robert Sesek 2015/08/27 23:25:23 nit: -preSendEvent: (colon part of name)
jackhou1 2015/08/28 01:00:47 Done.
37 // event must be of type |NSKeyDown|, |NSKeyUp|, or |NSFlagsChanged|. Returns
38 // YES if the event is handled.
39 - (BOOL)redispatchKeyEvent:(NSEvent*)event;
40
41 // The CommandDispatchingWindow should override -[NSWindow sendEvent:] and call
42 // this before a native -sendEvent. Ensures that a redispatched event is not
Robert Sesek 2015/08/27 23:25:23 nit: -sendEvent:
jackhou1 2015/08/28 01:00:47 Done.
43 // reposted infinitely. Returns YES if the event is handled.
44 - (BOOL)preSendEvent:(NSEvent*)event;
45
46 @end
47
48 // If the NSWindow's firstResponder implements CommandDispatcherTarget, it is
49 // given the first opportunity to process a command.
50 @protocol CommandDispatcherTarget
51
52 // To handle an event asynchronously, return YES. If the event is ultimately not
53 // handled, return the event to the CommandDispatchingWindow via -[[event
54 // window] redispatchKeyEvent:event].
55 - (BOOL)performKeyEquivalent:(NSEvent*)event;
56
57 @end
58
59 // Provides CommandDispatcher with the means to redirect key equivalents at
60 // different stages of event handling.
61 @protocol CommandDispatcherDelegate<NSObject>
62
63 // Called before any other event handling, and possibly again if an unhandled
64 // event comes back from CommandDispatcherTarget.
65 - (BOOL)eventHandledByExtensionCommand:(NSEvent*)event
66 isRedispatch:(BOOL)isRedispatch;
67
68 // Called before the default -performKeyEquivalent, but after the
69 // CommandDispatcherTarget has had a chance to intercept it. |window| is the
70 // CommandDispatchingWindow that owns CommandDispatcher.
71 - (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
72
73 // Called after the default -performKeyEquivalent. |window| is the
74 // CommandDispatchingWindow that owns CommandDispatcher.
75 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
76
77 @end
78
79 // The set of methods an NSWindow subclass needs to implement to use
80 // CommandDispatcher.
81 @protocol CommandDispatchingWindow
82
83 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's
84 // so that callers can simply return events to the NSWindow.
85 - (BOOL)redispatchKeyEvent:(NSEvent*)event;
86
87 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which
88 // CommandDispatcher calls as part of its -performKeyEquivalent flow.
89 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event;
90
91 @end
92
93 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698