| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/events/keycodes/keyboard_code_conversion_mac.h" | 5 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #import <Carbon/Carbon.h> | 9 #import <Carbon/Carbon.h> |
| 10 | 10 |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 break; | 514 break; |
| 515 case kVK_ANSI_Slash: | 515 case kVK_ANSI_Slash: |
| 516 *character = '?'; | 516 *character = '?'; |
| 517 break; | 517 break; |
| 518 default: | 518 default: |
| 519 break; | 519 break; |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Control characters. | |
| 525 if (flags & NSControlKeyMask) { | |
| 526 if (keycode >= VKEY_A && keycode <= VKEY_Z) | |
| 527 *character = 1 + keycode - VKEY_A; | |
| 528 else if (macKeycode == kVK_ANSI_LeftBracket) | |
| 529 *character = 27; | |
| 530 else if (macKeycode == kVK_ANSI_Backslash) | |
| 531 *character = 28; | |
| 532 else if (macKeycode == kVK_ANSI_RightBracket) | |
| 533 *character = 29; | |
| 534 } | |
| 535 | |
| 536 // TODO(suzhe): Support characters for Option key bindings. | 524 // TODO(suzhe): Support characters for Option key bindings. |
| 537 return macKeycode; | 525 return macKeycode; |
| 538 } | 526 } |
| 539 | 527 |
| 540 KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) { | 528 KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) { |
| 541 KeyboardCode code = VKEY_UNKNOWN; | 529 KeyboardCode code = VKEY_UNKNOWN; |
| 542 | 530 |
| 543 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { | 531 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { |
| 544 NSString* characters = [event characters]; | 532 NSString* characters = [event characters]; |
| 545 if ([characters length] > 0) | 533 if ([characters length] > 0) |
| 546 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); | 534 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); |
| 547 if (code) | 535 if (code) |
| 548 return code; | 536 return code; |
| 549 | 537 |
| 550 characters = [event charactersIgnoringModifiers]; | 538 characters = [event charactersIgnoringModifiers]; |
| 551 if ([characters length] > 0) | 539 if ([characters length] > 0) |
| 552 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); | 540 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); |
| 553 if (code) | 541 if (code) |
| 554 return code; | 542 return code; |
| 555 } | 543 } |
| 556 return KeyboardCodeFromKeyCode([event keyCode]); | 544 return KeyboardCodeFromKeyCode([event keyCode]); |
| 557 } | 545 } |
| 558 | 546 |
| 559 const char* CodeFromNSEvent(NSEvent* event) { | 547 const char* CodeFromNSEvent(NSEvent* event) { |
| 560 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( | 548 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( |
| 561 [event keyCode]); | 549 [event keyCode]); |
| 562 } | 550 } |
| 563 | 551 |
| 564 } // namespace ui | 552 } // namespace ui |
| OLD | NEW |