Chromium Code Reviews| 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 cr.define('cr.ui', function() { | 5 cr.define('cr.ui', function() { |
| 6 /** @const */ var Command = cr.ui.Command; | 6 /** @const */ var Command = cr.ui.Command; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates a new menu item element. | 9 * Creates a new menu item element. |
| 10 * @param {Object=} opt_propertyBag Optional properties. | 10 * @param {Object=} opt_propertyBag Optional properties. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 var shortcuts = this.command_.shortcut.split(/\s+/); | 138 var shortcuts = this.command_.shortcut.split(/\s+/); |
| 139 | 139 |
| 140 if (shortcuts.length == 0) | 140 if (shortcuts.length == 0) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 var shortcut = shortcuts[0]; | 143 var shortcut = shortcuts[0]; |
| 144 var mods = {}; | 144 var mods = {}; |
| 145 var ident = ''; | 145 var ident = ''; |
| 146 shortcut.split('-').forEach(function(part) { | 146 shortcut.split('|').forEach(function(part) { |
| 147 var partUc = part.toUpperCase(); | 147 var partUc = part.toUpperCase(); |
| 148 switch (partUc) { | 148 switch (partUc) { |
| 149 case 'CTRL': | 149 case 'CTRL': |
| 150 case 'ALT': | 150 case 'ALT': |
| 151 case 'SHIFT': | 151 case 'SHIFT': |
| 152 case 'META': | 152 case 'META': |
| 153 mods[partUc] = true; | 153 mods[partUc] = true; |
| 154 break; | 154 break; |
| 155 default: | 155 default: |
| 156 console.assert(!ident, 'Shortcut has two non-modifier keys'); | 156 console.assert(!ident, 'Shortcut has two non-modifier keys'); |
| 157 ident = part; | 157 ident = part; |
| 158 } | 158 } |
| 159 }); | 159 }); |
| 160 | 160 |
| 161 var shortcutText = ''; | 161 var shortcutText = ''; |
| 162 | 162 |
| 163 // TODO(zvorygin): if more cornercases appear - optimize following | |
| 164 // code. Currently 'Enter' keystroke is passed as 'Enter', but 'Space' | |
| 165 // and 'Backspace' are passed as 'U+0020' and 'U+0008'. | |
| 166 if (ident == 'U+0020') | |
| 167 ident = 'Space'; | |
| 168 else if (ident == 'U+0008') | |
| 169 ident = 'Backspace'; | |
| 170 | |
| 171 ['CTRL', 'ALT', 'SHIFT', 'META'].forEach(function(mod) { | 163 ['CTRL', 'ALT', 'SHIFT', 'META'].forEach(function(mod) { |
| 172 if (mods[mod]) | 164 if (mods[mod]) |
| 173 shortcutText += loadTimeData.getString('SHORTCUT_' + mod) + '+'; | 165 shortcutText += loadTimeData.getString('SHORTCUT_' + mod) + '+'; |
| 174 }); | 166 }); |
| 175 | 167 |
| 176 if (ident.indexOf('U+') != 0) { | 168 if (ident == ' ') |
| 169 ident = 'Space'; | |
| 170 | |
| 171 if (ident.length != 1) { | |
|
Dan Beam
2016/06/29 23:34:17
what's going on here?
dtapuska
2016/06/30 14:16:50
So previously it would check if started with index
| |
| 177 shortcutText += | 172 shortcutText += |
| 178 loadTimeData.getString('SHORTCUT_' + ident.toUpperCase()); | 173 loadTimeData.getString('SHORTCUT_' + ident.toUpperCase()); |
| 179 } else { | 174 } else { |
| 180 shortcutText += | 175 shortcutText += ident.toUpperCase(); |
| 181 String.fromCharCode(parseInt(ident.substring(2), 16)); | |
| 182 } | 176 } |
| 183 | 177 |
| 184 this.setAttribute('shortcutText', shortcutText); | 178 this.setAttribute('shortcutText', shortcutText); |
| 185 }, | 179 }, |
| 186 | 180 |
| 187 /** | 181 /** |
| 188 * Handles mouseup events. This dispatches an activate event; if there is an | 182 * Handles mouseup events. This dispatches an activate event; if there is an |
| 189 * associated command, that command is executed. | 183 * associated command, that command is executed. |
| 190 * @param {!Event} e The mouseup event object. | 184 * @param {!Event} e The mouseup event object. |
| 191 * @private | 185 * @private |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 /** | 264 /** |
| 271 * Whether the menu item is checkable or not. | 265 * Whether the menu item is checkable or not. |
| 272 */ | 266 */ |
| 273 cr.defineProperty(MenuItem, 'checkable', cr.PropertyKind.BOOL_ATTR); | 267 cr.defineProperty(MenuItem, 'checkable', cr.PropertyKind.BOOL_ATTR); |
| 274 | 268 |
| 275 // Export | 269 // Export |
| 276 return { | 270 return { |
| 277 MenuItem: MenuItem | 271 MenuItem: MenuItem |
| 278 }; | 272 }; |
| 279 }); | 273 }); |
| OLD | NEW |