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

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 2505943002: MacViews: Fix accelerator handling while Omnibox is in focus. (Closed)
Patch Set: Remove performKeyEquivalent:, update keyDown:, add tests. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 7c49cd0444346d7291793796970f16a6d7a7c505..625140b35c8dd2996aa669e4b98273f0f2f89595 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -760,10 +760,28 @@ NSAttributedString* GetAttributedString(
// 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 ]];
+
+ if (keyDownEvent_) {
tapted 2016/11/18 07:28:04 comment above: // If |keyDownEvent_| wasn't cl
themblsha 2016/11/18 13:31:50 Done.
+ ui::KeyEvent event(keyDownEvent_);
+ [self handleKeyEvent:&event];
+ }
+
keyDownEvent_ = nil;
}
@@ -1286,13 +1304,25 @@ NSAttributedString* GetAttributedString(
if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) {
ui::KeyEvent event(keyDownEvent_);
tapted 2016/11/18 07:28:04 Can this just return here? I.e. return; // Han
themblsha 2016/11/18 13:31:50 Yep, should work.
[self handleKeyEvent:&event];
+ keyDownEvent_ = nil;
return;
}
- if ([self respondsToSelector:selector])
+ if ([self respondsToSelector:selector]) {
[self performSelector:selector withObject:nil];
- else
- [[self nextResponder] doCommandBySelector:selector];
+ keyDownEvent_ = nil;
+ return;
+ }
+
+ if (keyDownEvent_) {
tapted 2016/11/18 07:28:04 This needs a comment to say why it can't be done i
themblsha 2016/11/18 13:31:50 Nice, removes quite a bit of duplicate code.
+ ui::KeyEvent event(keyDownEvent_);
+ keyDownEvent_ = nil;
+ [self handleKeyEvent:&event];
+ if (event.handled())
+ return;
+ }
+
+ [[self nextResponder] doCommandBySelector:selector];
}
- (NSRect)firstRectForCharacterRange:(NSRange)range

Powered by Google App Engine
This is Rietveld 408576698