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

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: Similarity=30 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 @private
24 BOOL redispatchingEvent_;
25 BOOL eventHandled_;
26 NSWindow<CommandDispatchingWindow>* owner_; // Weak, owns us.
27 }
28
29 @property(retain, nonatomic) id<CommandDispatcherDelegate> delegate;
30
31 - (id)initWithOwner:(NSWindow<CommandDispatchingWindow>*)owner;
32
33 // The main entry point for key events. The CommandDispatchingWindow should
34 // override -[NSResponder performKeyEquivalent:] and call this instead. Returns
35 // YES if the event is handled.
36 - (BOOL)performKeyEquivalent:(NSEvent*)event;
37
38 // Sends a key event to -[NSApp sendEvent:], but also ensures it is not short-
39 // circuited to the CommandDispatcherTarget. This is used to allow default
40 // AppKit handling of an event that comes back from CommandDispatcherTarget,
41 // e.g. key equivalents in the menu, or window manager commands like Cmd+`. The
42 // event must be of type |NSKeyDown|, |NSKeyUp|, or |NSFlagsChanged|. Returns
43 // YES if the event is handled.
44 - (BOOL)redispatchKeyEvent:(NSEvent*)event;
45
46 // The CommandDispatchingWindow should call this before a native -sendEvent.
47 // Ensures that a redispatched event is not reposted infinitely. Returns YES if
48 // the event is handled.
49 - (BOOL)preSendEvent:(NSEvent*)event;
50
51 @end
52
53 // If the NSWindow's firstResponder implements CommandDispatcherTarget, it is
54 // given the first opportunity to process a command. To handle an event
tapted 2015/08/26 06:46:54 nit: Move from "To handle an event..." onto a comm
jackhou1 2015/08/26 07:38:17 Done.
55 // asynchronously, return YES. If the event is ultimately not handled, return
56 // the event to the CommandDispatchingWindow via -[[event window]
57 // redispatchKeyEvent:event].
58 @protocol CommandDispatcherTarget
59 - (BOOL)performKeyEquivalent:(NSEvent*)event;
60 @end
61
62 // Provides CommandDispatcher with the means to redirect key equivalents at
63 // different stages of event handling.
64 @protocol CommandDispatcherDelegate<NSObject>
65
66 // Called before any other event handling, and possibly again if an unhandled
67 // event comes back from CommandDispatcherTarget.
68 - (BOOL)handledByExtensionCommand:(NSEvent*)event
69 isRedispatch:(BOOL)isRedispatch;
70
71 // Called before the default -performKeyEquivalent, but after the
72 // CommandDispatcherTarget has had a chance to intercept it.
73 - (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
74
75 // Called after the default -performKeyEquivalent.
76 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
77
78 @end
79
80 // The set of methods an NSWindow subclass needs to implement to use
81 // CommandDispatcher.
82 @protocol CommandDispatchingWindow
83
84 // This can be implemented with -[CommandDispatcher -redispatchKeyEvent:]. It's
85 // so that callers can simply return events to the NSWindow.
86 - (BOOL)redispatchKeyEvent:(NSEvent*)event;
87
88 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which
89 // CommandDispatcher calls as part of its -performKeyEquivalent flow.
90 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event;
91
92 @end
93
94 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698