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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #import "base/mac/sdk_forward_declarations.h" 10 #import "base/mac/sdk_forward_declarations.h"
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 case ui::TEXT_INPUT_TYPE_NONE: 753 case ui::TEXT_INPUT_TYPE_NONE:
754 case ui::TEXT_INPUT_TYPE_PASSWORD: 754 case ui::TEXT_INPUT_TYPE_PASSWORD:
755 return nil; 755 return nil;
756 default: 756 default:
757 return [super inputContext]; 757 return [super inputContext];
758 } 758 }
759 } 759 }
760 760
761 // NSResponder implementation. 761 // NSResponder implementation.
762 762
763 - (BOOL)_wantsKeyDownForEvent:(NSEvent*)event {
764 // This is a SPI that AppKit apparently calls after |performKeyEquivalent:|
765 // returned NO. If this function returns |YES|, Cocoa sends the event to
766 // |keyDown:| instead of doing other things with it. Ctrl-tab will be sent
767 // to us instead of doing key view loop control, ctrl-left/right get handled
768 // correctly, etc.
769 // (However, there are still some keys that Cocoa swallows, e.g. the key
770 // equivalent that Cocoa uses for toggling the input language. In this case,
771 // that's actually a good thing, though -- see http://crbug.com/26115 .)
772 return YES;
773 }
774
763 - (void)keyDown:(NSEvent*)theEvent { 775 - (void)keyDown:(NSEvent*)theEvent {
764 // Convert the event into an action message, according to OSX key mappings. 776 // Convert the event into an action message, according to OSX key mappings.
765 keyDownEvent_ = theEvent; 777 keyDownEvent_ = theEvent;
766 [self interpretKeyEvents:@[ theEvent ]]; 778 [self interpretKeyEvents:@[ theEvent ]];
779
780 if (keyDownEvent_) {
tapted 2016/11/18 07:28:04 comment above: // If |keyDownEvent_| wasn't cl
themblsha 2016/11/18 13:31:50 Done.
781 ui::KeyEvent event(keyDownEvent_);
782 [self handleKeyEvent:&event];
783 }
784
767 keyDownEvent_ = nil; 785 keyDownEvent_ = nil;
768 } 786 }
769 787
770 - (void)keyUp:(NSEvent*)theEvent { 788 - (void)keyUp:(NSEvent*)theEvent {
771 ui::KeyEvent event(theEvent); 789 ui::KeyEvent event(theEvent);
772 [self handleKeyEvent:&event]; 790 [self handleKeyEvent:&event];
773 } 791 }
774 792
775 - (void)scrollWheel:(NSEvent*)theEvent { 793 - (void)scrollWheel:(NSEvent*)theEvent {
776 if (!hostedView_) 794 if (!hostedView_)
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 1295
1278 - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint { 1296 - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint {
1279 NOTIMPLEMENTED(); 1297 NOTIMPLEMENTED();
1280 return 0; 1298 return 0;
1281 } 1299 }
1282 1300
1283 - (void)doCommandBySelector:(SEL)selector { 1301 - (void)doCommandBySelector:(SEL)selector {
1284 // Like the renderer, handle insert action messages as a regular key dispatch. 1302 // Like the renderer, handle insert action messages as a regular key dispatch.
1285 // This ensures, e.g., insertTab correctly changes focus between fields. 1303 // This ensures, e.g., insertTab correctly changes focus between fields.
1286 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) { 1304 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) {
1287 ui::KeyEvent event(keyDownEvent_); 1305 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.
1288 [self handleKeyEvent:&event]; 1306 [self handleKeyEvent:&event];
1307 keyDownEvent_ = nil;
1289 return; 1308 return;
1290 } 1309 }
1291 1310
1292 if ([self respondsToSelector:selector]) 1311 if ([self respondsToSelector:selector]) {
1293 [self performSelector:selector withObject:nil]; 1312 [self performSelector:selector withObject:nil];
1294 else 1313 keyDownEvent_ = nil;
1295 [[self nextResponder] doCommandBySelector:selector]; 1314 return;
1315 }
1316
1317 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.
1318 ui::KeyEvent event(keyDownEvent_);
1319 keyDownEvent_ = nil;
1320 [self handleKeyEvent:&event];
1321 if (event.handled())
1322 return;
1323 }
1324
1325 [[self nextResponder] doCommandBySelector:selector];
1296 } 1326 }
1297 1327
1298 - (NSRect)firstRectForCharacterRange:(NSRange)range 1328 - (NSRect)firstRectForCharacterRange:(NSRange)range
1299 actualRange:(NSRangePointer)actualNSRange { 1329 actualRange:(NSRangePointer)actualNSRange {
1300 gfx::Range actualRange; 1330 gfx::Range actualRange;
1301 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_, 1331 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_,
1302 gfx::Range(range), &actualRange); 1332 gfx::Range(range), &actualRange);
1303 if (actualNSRange) 1333 if (actualNSRange)
1304 *actualNSRange = actualRange.ToNSRange(); 1334 *actualNSRange = actualRange.ToNSRange();
1305 return gfx::ScreenRectToNSRect(rect); 1335 return gfx::ScreenRectToNSRect(rect);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1462 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1433 } 1463 }
1434 1464
1435 - (id)accessibilityFocusedUIElement { 1465 - (id)accessibilityFocusedUIElement {
1436 if (!hostedView_) 1466 if (!hostedView_)
1437 return nil; 1467 return nil;
1438 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; 1468 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement];
1439 } 1469 }
1440 1470
1441 @end 1471 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698