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

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: 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)performKeyEquivalent:(NSEvent*)theEvent {
tapted 2016/11/17 08:20:14 I think there's more we have to do here. Have a lo
themblsha 2016/11/17 17:52:16 Good catch!
764 // Normally having the keyDown: would be enough for processing accelerator
765 // events, but some only result in keyUp: calls. The approach is similar to
766 // what we're doing in keyDown: with the exception that we should not fallback
767 // to next responder in doCommandBySelector:, as this will result in NSBeep().
768
769 // Convert the event into an action message, according to OSX key mappings.
770 performKeyEquivalentEvent_ = theEvent;
771 performKeyEquivalentEventHandled_.reset();
772 [self interpretKeyEvents:@[ theEvent ]];
773 if (auto result = performKeyEquivalentEventHandled_) {
774 DCHECK(!performKeyEquivalentEvent_);
775 performKeyEquivalentEventHandled_.reset();
776 return *result;
777 }
778
779 DCHECK(performKeyEquivalentEvent_);
780 ui::KeyEvent event(performKeyEquivalentEvent_);
781 [self handleKeyEvent:&event];
782 performKeyEquivalentEvent_ = nil;
783 performKeyEquivalentEventHandled_.reset();
784 return event.handled() ? YES : NO;
785 }
786
763 - (void)keyDown:(NSEvent*)theEvent { 787 - (void)keyDown:(NSEvent*)theEvent {
764 // Convert the event into an action message, according to OSX key mappings. 788 // Convert the event into an action message, according to OSX key mappings.
765 keyDownEvent_ = theEvent; 789 keyDownEvent_ = theEvent;
766 [self interpretKeyEvents:@[ theEvent ]]; 790 [self interpretKeyEvents:@[ theEvent ]];
791
767 keyDownEvent_ = nil; 792 keyDownEvent_ = nil;
768 } 793 }
769 794
770 - (void)keyUp:(NSEvent*)theEvent { 795 - (void)keyUp:(NSEvent*)theEvent {
771 ui::KeyEvent event(theEvent); 796 ui::KeyEvent event(theEvent);
772 [self handleKeyEvent:&event]; 797 [self handleKeyEvent:&event];
773 } 798 }
774 799
775 - (void)scrollWheel:(NSEvent*)theEvent { 800 - (void)scrollWheel:(NSEvent*)theEvent {
776 if (!hostedView_) 801 if (!hostedView_)
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 NOTIMPLEMENTED(); 1304 NOTIMPLEMENTED();
1280 return 0; 1305 return 0;
1281 } 1306 }
1282 1307
1283 - (void)doCommandBySelector:(SEL)selector { 1308 - (void)doCommandBySelector:(SEL)selector {
1284 // Like the renderer, handle insert action messages as a regular key dispatch. 1309 // Like the renderer, handle insert action messages as a regular key dispatch.
1285 // This ensures, e.g., insertTab correctly changes focus between fields. 1310 // This ensures, e.g., insertTab correctly changes focus between fields.
1286 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) { 1311 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) {
1287 ui::KeyEvent event(keyDownEvent_); 1312 ui::KeyEvent event(keyDownEvent_);
1288 [self handleKeyEvent:&event]; 1313 [self handleKeyEvent:&event];
1314 performKeyEquivalentEvent_ = nil;
1315 performKeyEquivalentEventHandled_ = YES;
1289 return; 1316 return;
1290 } 1317 }
1291 1318
1292 if ([self respondsToSelector:selector]) 1319 if ([self respondsToSelector:selector]) {
1293 [self performSelector:selector withObject:nil]; 1320 [self performSelector:selector withObject:nil];
1294 else 1321 performKeyEquivalentEvent_ = nil;
1295 [[self nextResponder] doCommandBySelector:selector]; 1322 performKeyEquivalentEventHandled_ = YES;
1323 return;
1324 }
1325
1326 if (performKeyEquivalentEvent_) {
1327 ui::KeyEvent event(performKeyEquivalentEvent_);
1328 [self handleKeyEvent:&event];
1329 performKeyEquivalentEvent_ = nil;
1330 performKeyEquivalentEventHandled_ = event.handled() ? YES : NO;
1331 // If the event was not handled we must return NO in performKeyEquivalent:
1332 // so the menu bar could have a chance on handling the event. Regardless of
1333 // that, we don't want to call doCommandBySelector: on nextResponder, as
1334 // this will probably result in NSBeep().
1335 return;
1336 }
1337
1338 [[self nextResponder] doCommandBySelector:selector];
1296 } 1339 }
1297 1340
1298 - (NSRect)firstRectForCharacterRange:(NSRange)range 1341 - (NSRect)firstRectForCharacterRange:(NSRange)range
1299 actualRange:(NSRangePointer)actualNSRange { 1342 actualRange:(NSRangePointer)actualNSRange {
1300 gfx::Range actualRange; 1343 gfx::Range actualRange;
1301 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_, 1344 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_,
1302 gfx::Range(range), &actualRange); 1345 gfx::Range(range), &actualRange);
1303 if (actualNSRange) 1346 if (actualNSRange)
1304 *actualNSRange = actualRange.ToNSRange(); 1347 *actualNSRange = actualRange.ToNSRange();
1305 return gfx::ScreenRectToNSRect(rect); 1348 return gfx::ScreenRectToNSRect(rect);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1475 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1433 } 1476 }
1434 1477
1435 - (id)accessibilityFocusedUIElement { 1478 - (id)accessibilityFocusedUIElement {
1436 if (!hostedView_) 1479 if (!hostedView_)
1437 return nil; 1480 return nil;
1438 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; 1481 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement];
1439 } 1482 }
1440 1483
1441 @end 1484 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698