Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } // namespace | 267 } // namespace |
| 268 | 268 |
| 269 @interface BridgedContentView () | 269 @interface BridgedContentView () |
| 270 | 270 |
| 271 // Returns the active menu controller corresponding to |hostedView_|, | 271 // Returns the active menu controller corresponding to |hostedView_|, |
| 272 // nil otherwise. | 272 // nil otherwise. |
| 273 - (MenuController*)activeMenuController; | 273 - (MenuController*)activeMenuController; |
| 274 | 274 |
| 275 // Passes |event| to the InputMethod for dispatch. | 275 // Passes |event| to the InputMethod for dispatch. |
| 276 - (void)handleKeyEvent:(ui::KeyEvent*)event; | 276 - (void)handleKeyEvent:(ui::KeyEvent*)event; |
| 277 | 277 |
|
tapted
2016/11/21 06:41:02
// Allows accelerators to be handled at different
themblsha
2016/11/21 12:44:20
Done. But this forward-declaration interface block
tapted
2016/11/21 22:00:16
Method/prototype declarations on private categorie
| |
| 278 // Handles an NSResponder Action Message by mapping it to a corresponding text | 278 // Handles an NSResponder Action Message by mapping it to a corresponding text |
| 279 // editing command from ui_strings.grd and, when not being sent to a | 279 // editing command from ui_strings.grd and, when not being sent to a |
| 280 // TextInputClient, the keyCode that toolkit-views expects internally. | 280 // TextInputClient, the keyCode that toolkit-views expects internally. |
| 281 // For example, moveToLeftEndOfLine: would pass ui::VKEY_HOME in non-RTL locales | 281 // For example, moveToLeftEndOfLine: would pass ui::VKEY_HOME in non-RTL locales |
| 282 // even though the Home key on Mac defaults to moveToBeginningOfDocument:. | 282 // even though the Home key on Mac defaults to moveToBeginningOfDocument:. |
| 283 // This approach also allows action messages a user | 283 // This approach also allows action messages a user |
| 284 // may have remapped in ~/Library/KeyBindings/DefaultKeyBinding.dict to be | 284 // may have remapped in ~/Library/KeyBindings/DefaultKeyBinding.dict to be |
| 285 // catered for. | 285 // catered for. |
| 286 // Note: default key bindings in Mac can be read from StandardKeyBinding.dict | 286 // Note: default key bindings in Mac can be read from StandardKeyBinding.dict |
| 287 // which lives in /System/Library/Frameworks/AppKit.framework/Resources. Do | 287 // which lives in /System/Library/Frameworks/AppKit.framework/Resources. Do |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 // the NSTextInputClient protocol. | 756 // the NSTextInputClient protocol. |
| 757 switch (textInputClient_->GetTextInputType()) { | 757 switch (textInputClient_->GetTextInputType()) { |
| 758 case ui::TEXT_INPUT_TYPE_NONE: | 758 case ui::TEXT_INPUT_TYPE_NONE: |
| 759 case ui::TEXT_INPUT_TYPE_PASSWORD: | 759 case ui::TEXT_INPUT_TYPE_PASSWORD: |
| 760 return nil; | 760 return nil; |
| 761 default: | 761 default: |
| 762 return [super inputContext]; | 762 return [super inputContext]; |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 - (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.
| |
| 767 if (!keyDownEvent_) | |
| 768 return NO; | |
| 769 | |
| 770 ui::KeyEvent event(keyDownEvent_); | |
| 771 [self handleKeyEvent:&event]; | |
| 772 keyDownEvent_ = nil; | |
| 773 return event.handled(); | |
| 774 } | |
| 775 | |
| 766 // NSResponder implementation. | 776 // NSResponder implementation. |
| 767 | 777 |
| 778 - (BOOL)_wantsKeyDownForEvent:(NSEvent*)event { | |
| 779 // This is a SPI that AppKit apparently calls after |performKeyEquivalent:| | |
| 780 // returned NO. If this function returns |YES|, Cocoa sends the event to | |
| 781 // |keyDown:| instead of doing other things with it. Ctrl-tab will be sent | |
| 782 // to us instead of doing key view loop control, ctrl-left/right get handled | |
| 783 // correctly, etc. | |
| 784 // (However, there are still some keys that Cocoa swallows, e.g. the key | |
| 785 // equivalent that Cocoa uses for toggling the input language. In this case, | |
| 786 // that's actually a good thing, though -- see http://crbug.com/26115 .) | |
| 787 return YES; | |
| 788 } | |
| 789 | |
| 768 - (void)keyDown:(NSEvent*)theEvent { | 790 - (void)keyDown:(NSEvent*)theEvent { |
| 769 // Convert the event into an action message, according to OSX key mappings. | 791 // Convert the event into an action message, according to OSX key mappings. |
| 770 keyDownEvent_ = theEvent; | 792 keyDownEvent_ = theEvent; |
| 771 [self interpretKeyEvents:@[ theEvent ]]; | 793 [self interpretKeyEvents:@[ theEvent ]]; |
| 772 keyDownEvent_ = nil; | 794 |
| 795 // If |keyDownEvent_| wasn't cleared during -interpretKeyEvents:, it wasn't | |
| 796 // handled. Give Widget accelerators a chance to handle it. | |
| 797 [self handleUnhandledKeyDownAsKeyEvent]; | |
| 798 DCHECK(!keyDownEvent_); | |
| 773 } | 799 } |
| 774 | 800 |
| 775 - (void)keyUp:(NSEvent*)theEvent { | 801 - (void)keyUp:(NSEvent*)theEvent { |
| 776 ui::KeyEvent event(theEvent); | 802 ui::KeyEvent event(theEvent); |
| 777 [self handleKeyEvent:&event]; | 803 [self handleKeyEvent:&event]; |
| 778 } | 804 } |
| 779 | 805 |
| 780 - (void)scrollWheel:(NSEvent*)theEvent { | 806 - (void)scrollWheel:(NSEvent*)theEvent { |
| 781 if (!hostedView_) | 807 if (!hostedView_) |
| 782 return; | 808 return; |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1281 } | 1307 } |
| 1282 | 1308 |
| 1283 - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint { | 1309 - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint { |
| 1284 NOTIMPLEMENTED(); | 1310 NOTIMPLEMENTED(); |
| 1285 return 0; | 1311 return 0; |
| 1286 } | 1312 } |
| 1287 | 1313 |
| 1288 - (void)doCommandBySelector:(SEL)selector { | 1314 - (void)doCommandBySelector:(SEL)selector { |
| 1289 // Like the renderer, handle insert action messages as a regular key dispatch. | 1315 // Like the renderer, handle insert action messages as a regular key dispatch. |
| 1290 // This ensures, e.g., insertTab correctly changes focus between fields. | 1316 // This ensures, e.g., insertTab correctly changes focus between fields. |
| 1291 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) { | 1317 if (keyDownEvent_ && [NSStringFromSelector(selector) hasPrefix:@"insert"]) { |
|
tapted
2016/11/21 06:41:02
nit: no curlies
themblsha
2016/11/21 12:44:20
Done.
| |
| 1292 ui::KeyEvent event(keyDownEvent_); | 1318 return; // Handle in -keyDown:. |
| 1293 [self handleKeyEvent:&event]; | 1319 } |
| 1320 | |
| 1321 if ([self respondsToSelector:selector]) { | |
| 1322 [self performSelector:selector withObject:nil]; | |
| 1323 keyDownEvent_ = nil; | |
| 1294 return; | 1324 return; |
| 1295 } | 1325 } |
| 1296 | 1326 |
| 1297 if ([self respondsToSelector:selector]) | 1327 // For events that AppKit sends via doCommandBySelector:, first attempt to |
| 1298 [self performSelector:selector withObject:nil]; | 1328 // handle as a Widget accelerator. Forward along the responder chain only if |
| 1299 else | 1329 // the Widget doesn't handle it. |
| 1330 if (![self handleUnhandledKeyDownAsKeyEvent]) | |
| 1300 [[self nextResponder] doCommandBySelector:selector]; | 1331 [[self nextResponder] doCommandBySelector:selector]; |
| 1301 } | 1332 } |
| 1302 | 1333 |
| 1303 - (NSRect)firstRectForCharacterRange:(NSRange)range | 1334 - (NSRect)firstRectForCharacterRange:(NSRange)range |
| 1304 actualRange:(NSRangePointer)actualNSRange { | 1335 actualRange:(NSRangePointer)actualNSRange { |
| 1305 gfx::Range actualRange; | 1336 gfx::Range actualRange; |
| 1306 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_, | 1337 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_, |
| 1307 gfx::Range(range), &actualRange); | 1338 gfx::Range(range), &actualRange); |
| 1308 if (actualNSRange) | 1339 if (actualNSRange) |
| 1309 *actualNSRange = actualRange.ToNSRange(); | 1340 *actualNSRange = actualRange.ToNSRange(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1463 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1433 } | 1464 } |
| 1434 | 1465 |
| 1435 - (id)accessibilityFocusedUIElement { | 1466 - (id)accessibilityFocusedUIElement { |
| 1436 if (!hostedView_) | 1467 if (!hostedView_) |
| 1437 return nil; | 1468 return nil; |
| 1438 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1469 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
| 1439 } | 1470 } |
| 1440 | 1471 |
| 1441 @end | 1472 @end |
| OLD | NEW |