| 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 /** | 5 /** |
| 6 * @fileoverview A command is an abstraction of an action a user can do in the | 6 * @fileoverview A command is an abstraction of an action a user can do in the |
| 7 * UI. | 7 * UI. |
| 8 * | 8 * |
| 9 * When the focus changes in the document for each command a canExecute event | 9 * When the focus changes in the document for each command a canExecute event |
| 10 * is dispatched on the active element. By listening to this event you can | 10 * is dispatched on the active element. By listening to this event you can |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 * | 122 * |
| 123 * For example: | 123 * For example: |
| 124 * "F1" | 124 * "F1" |
| 125 * "Backspace|Meta" for Apple command backspace. | 125 * "Backspace|Meta" for Apple command backspace. |
| 126 * "a|Ctrl" for Control A | 126 * "a|Ctrl" for Control A |
| 127 * "Delete Backspace|Meta" for Delete and Command Backspace | 127 * "Delete Backspace|Meta" for Delete and Command Backspace |
| 128 * | 128 * |
| 129 * @type {string} | 129 * @type {string} |
| 130 */ | 130 */ |
| 131 shortcut_: '', | 131 shortcut_: '', |
| 132 get shortcut() { return this.shortcut_; }, | 132 get shortcut() { |
| 133 return this.shortcut_; |
| 134 }, |
| 133 set shortcut(shortcut) { | 135 set shortcut(shortcut) { |
| 134 var oldShortcut = this.shortcut_; | 136 var oldShortcut = this.shortcut_; |
| 135 if (shortcut !== oldShortcut) { | 137 if (shortcut !== oldShortcut) { |
| 136 this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) { | 138 this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) { |
| 137 return new KeyboardShortcut(shortcut); | 139 return new KeyboardShortcut(shortcut); |
| 138 }); | 140 }); |
| 139 | 141 |
| 140 // Set this after the keyboardShortcuts_ since that might throw. | 142 // Set this after the keyboardShortcuts_ since that might throw. |
| 141 this.shortcut_ = shortcut; | 143 this.shortcut_ = shortcut; |
| 142 cr.dispatchPropertyChange( | 144 cr.dispatchPropertyChange( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 */ | 305 */ |
| 304 command: null, | 306 command: null, |
| 305 | 307 |
| 306 /** | 308 /** |
| 307 * Whether the target can execute the command. Setting this also stops the | 309 * Whether the target can execute the command. Setting this also stops the |
| 308 * propagation and prevents the default. Callers can tell if an event has | 310 * propagation and prevents the default. Callers can tell if an event has |
| 309 * been handled via |this.defaultPrevented|. | 311 * been handled via |this.defaultPrevented|. |
| 310 * @type {boolean} | 312 * @type {boolean} |
| 311 */ | 313 */ |
| 312 canExecute_: false, | 314 canExecute_: false, |
| 313 get canExecute() { return this.canExecute_; }, | 315 get canExecute() { |
| 316 return this.canExecute_; |
| 317 }, |
| 314 set canExecute(canExecute) { | 318 set canExecute(canExecute) { |
| 315 this.canExecute_ = !!canExecute; | 319 this.canExecute_ = !!canExecute; |
| 316 this.stopPropagation(); | 320 this.stopPropagation(); |
| 317 this.preventDefault(); | 321 this.preventDefault(); |
| 318 } | 322 } |
| 319 }; | 323 }; |
| 320 | 324 |
| 321 // Export | 325 // Export |
| 322 return {Command: Command, CanExecuteEvent: CanExecuteEvent}; | 326 return {Command: Command, CanExecuteEvent: CanExecuteEvent}; |
| 323 }); | 327 }); |
| OLD | NEW |