| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 {IDC_BOOKMARK_ALL_TABS, NSCommandKeyMask | NSShiftKeyMask, ui::VKEY_D}, | 99 {IDC_BOOKMARK_ALL_TABS, NSCommandKeyMask | NSShiftKeyMask, ui::VKEY_D}, |
| 100 {IDC_MINIMIZE_WINDOW, NSCommandKeyMask, ui::VKEY_M}, | 100 {IDC_MINIMIZE_WINDOW, NSCommandKeyMask, ui::VKEY_M}, |
| 101 {IDC_SELECT_NEXT_TAB, NSCommandKeyMask | NSAlternateKeyMask, ui::VKEY_RIGHT}, | 101 {IDC_SELECT_NEXT_TAB, NSCommandKeyMask | NSAlternateKeyMask, ui::VKEY_RIGHT}, |
| 102 {IDC_SELECT_PREVIOUS_TAB, NSCommandKeyMask | NSAlternateKeyMask, | 102 {IDC_SELECT_PREVIOUS_TAB, NSCommandKeyMask | NSAlternateKeyMask, |
| 103 ui::VKEY_LEFT}, | 103 ui::VKEY_LEFT}, |
| 104 {IDC_HELP_PAGE_VIA_MENU, NSCommandKeyMask | NSShiftKeyMask, ui::VKEY_OEM_2}, | 104 {IDC_HELP_PAGE_VIA_MENU, NSCommandKeyMask | NSShiftKeyMask, ui::VKEY_OEM_2}, |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // Create a Cocoa platform accelerator given a cross platform |key_code| and | 107 // Create a Cocoa platform accelerator given a cross platform |key_code| and |
| 108 // the |cocoa_modifiers|. | 108 // the |cocoa_modifiers|. |
| 109 scoped_ptr<ui::PlatformAccelerator> PlatformAcceleratorFromKeyCode( | 109 std::unique_ptr<ui::PlatformAccelerator> PlatformAcceleratorFromKeyCode( |
| 110 ui::KeyboardCode key_code, | 110 ui::KeyboardCode key_code, |
| 111 NSUInteger cocoa_modifiers) { | 111 NSUInteger cocoa_modifiers) { |
| 112 unichar shifted_character; | 112 unichar shifted_character; |
| 113 int result = ui::MacKeyCodeForWindowsKeyCode(key_code, cocoa_modifiers, | 113 int result = ui::MacKeyCodeForWindowsKeyCode(key_code, cocoa_modifiers, |
| 114 &shifted_character, nullptr); | 114 &shifted_character, nullptr); |
| 115 DCHECK(result != -1); | 115 DCHECK(result != -1); |
| 116 NSString* key_equivalent = | 116 NSString* key_equivalent = |
| 117 [NSString stringWithFormat:@"%C", shifted_character]; | 117 [NSString stringWithFormat:@"%C", shifted_character]; |
| 118 | 118 |
| 119 return scoped_ptr<ui::PlatformAccelerator>( | 119 return std::unique_ptr<ui::PlatformAccelerator>( |
| 120 new ui::PlatformAcceleratorCocoa(key_equivalent, cocoa_modifiers)); | 120 new ui::PlatformAcceleratorCocoa(key_equivalent, cocoa_modifiers)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Create a cross platform accelerator given a cross platform |key_code| and | 123 // Create a cross platform accelerator given a cross platform |key_code| and |
| 124 // the |cocoa_modifiers|. | 124 // the |cocoa_modifiers|. |
| 125 ui::Accelerator AcceleratorFromKeyCode(ui::KeyboardCode key_code, | 125 ui::Accelerator AcceleratorFromKeyCode(ui::KeyboardCode key_code, |
| 126 NSUInteger cocoa_modifiers) { | 126 NSUInteger cocoa_modifiers) { |
| 127 int cross_platform_modifiers = ui::EventFlagsFromModifiers(cocoa_modifiers); | 127 int cross_platform_modifiers = ui::EventFlagsFromModifiers(cocoa_modifiers); |
| 128 ui::Accelerator accelerator(key_code, cross_platform_modifiers); | 128 ui::Accelerator accelerator(key_code, cross_platform_modifiers); |
| 129 | 129 |
| 130 scoped_ptr<ui::PlatformAccelerator> platform_accelerator = | 130 std::unique_ptr<ui::PlatformAccelerator> platform_accelerator = |
| 131 PlatformAcceleratorFromKeyCode(key_code, cocoa_modifiers); | 131 PlatformAcceleratorFromKeyCode(key_code, cocoa_modifiers); |
| 132 accelerator.set_platform_accelerator(std::move(platform_accelerator)); | 132 accelerator.set_platform_accelerator(std::move(platform_accelerator)); |
| 133 return accelerator; | 133 return accelerator; |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| 137 | 137 |
| 138 AcceleratorsCocoa::AcceleratorsCocoa() { | 138 AcceleratorsCocoa::AcceleratorsCocoa() { |
| 139 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { | 139 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { |
| 140 const AcceleratorMapping& entry = kAcceleratorMap[i]; | 140 const AcceleratorMapping& entry = kAcceleratorMap[i]; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 NSUInteger mask = platform_accelerator->modifier_mask(); | 186 NSUInteger mask = platform_accelerator->modifier_mask(); |
| 187 BOOL maskEqual = | 187 BOOL maskEqual = |
| 188 (mask == modifiers) || ((mask & (~NSShiftKeyMask)) == modifiers); | 188 (mask == modifiers) || ((mask & (~NSShiftKeyMask)) == modifiers); |
| 189 NSString* string = [NSString stringWithFormat:@"%C", shifted_character]; | 189 NSString* string = [NSString stringWithFormat:@"%C", shifted_character]; |
| 190 if ([string isEqual:key_equivalent] && maskEqual) | 190 if ([string isEqual:key_equivalent] && maskEqual) |
| 191 return &*it; | 191 return &*it; |
| 192 } | 192 } |
| 193 | 193 |
| 194 return NULL; | 194 return NULL; |
| 195 } | 195 } |
| OLD | NEW |