Index: ui/views/cocoa/bridged_content_view.mm |
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm |
index afbc34cc9e5459268fc63f735ced47e5aedc5e2e..139f5dbebef28f5024cf4ed4071fff0c814700fa 100644 |
--- a/ui/views/cocoa/bridged_content_view.mm |
+++ b/ui/views/cocoa/bridged_content_view.mm |
@@ -763,13 +763,39 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { |
} |
} |
+- (BOOL)handleUnhandledKeyDownAsKeyEvent { |
tapted
2016/11/21 06:41:02
This should be moved to after handleKeyEvent: (lin
themblsha
2016/11/21 12:44:20
Done.
|
+ if (!keyDownEvent_) |
+ return NO; |
+ |
+ ui::KeyEvent event(keyDownEvent_); |
+ [self handleKeyEvent:&event]; |
+ keyDownEvent_ = nil; |
+ return event.handled(); |
+} |
+ |
// NSResponder implementation. |
+- (BOOL)_wantsKeyDownForEvent:(NSEvent*)event { |
+ // This is a SPI that AppKit apparently calls after |performKeyEquivalent:| |
+ // returned NO. If this function returns |YES|, Cocoa sends the event to |
+ // |keyDown:| instead of doing other things with it. Ctrl-tab will be sent |
+ // to us instead of doing key view loop control, ctrl-left/right get handled |
+ // correctly, etc. |
+ // (However, there are still some keys that Cocoa swallows, e.g. the key |
+ // equivalent that Cocoa uses for toggling the input language. In this case, |
+ // that's actually a good thing, though -- see http://crbug.com/26115 .) |
+ return YES; |
+} |
+ |
- (void)keyDown:(NSEvent*)theEvent { |
// Convert the event into an action message, according to OSX key mappings. |
keyDownEvent_ = theEvent; |
[self interpretKeyEvents:@[ theEvent ]]; |
- keyDownEvent_ = nil; |
+ |
+ // If |keyDownEvent_| wasn't cleared during -interpretKeyEvents:, it wasn't |
+ // handled. Give Widget accelerators a chance to handle it. |
+ [self handleUnhandledKeyDownAsKeyEvent]; |
+ DCHECK(!keyDownEvent_); |
} |
- (void)keyUp:(NSEvent*)theEvent { |
@@ -1289,14 +1315,19 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { |
// Like the renderer, handle insert action messages as a regular key dispatch. |
// This ensures, e.g., insertTab correctly changes focus between fields. |
if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) { |
tapted
2016/11/21 06:41:02
nit: no curlies
themblsha
2016/11/21 12:44:20
Done.
|
- ui::KeyEvent event(keyDownEvent_); |
- [self handleKeyEvent:&event]; |
- return; |
+ return; // Handle in -keyDown:. |
} |
- if ([self respondsToSelector:selector]) |
+ if ([self respondsToSelector:selector]) { |
[self performSelector:selector withObject:nil]; |
- else |
+ keyDownEvent_ = nil; |
+ return; |
+ } |
+ |
+ // For events that AppKit sends via doCommandBySelector:, first attempt to |
+ // handle as a Widget accelerator. Forward along the responder chain only if |
+ // the Widget doesn't handle it. |
+ if (![self handleUnhandledKeyDownAsKeyEvent]) |
[[self nextResponder] doCommandBySelector:selector]; |
} |