| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 Cu.import("resource://gre/modules/Services.jsm"); | 5 Cu.import("resource://gre/modules/Services.jsm"); |
| 6 | 6 |
| 7 let validModifiers = | 7 let validModifiers = |
| 8 { | 8 { |
| 9 ACCEL: null, | 9 ACCEL: null, |
| 10 CTRL: "control", | 10 CTRL: "control", |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 let keyCode = key.getAttribute("keycode"); | 89 let keyCode = key.getAttribute("keycode"); |
| 90 if (keyCode && "DOM_" + keyCode.toUpperCase() in Ci.nsIDOMKeyEvent) | 90 if (keyCode && "DOM_" + keyCode.toUpperCase() in Ci.nsIDOMKeyEvent) |
| 91 keyData.code = Ci.nsIDOMKeyEvent["DOM_" + keyCode.toUpperCase()]; | 91 keyData.code = Ci.nsIDOMKeyEvent["DOM_" + keyCode.toUpperCase()]; |
| 92 | 92 |
| 93 if (!keyData.char && !keyData.code) | 93 if (!keyData.char && !keyData.code) |
| 94 continue; | 94 continue; |
| 95 | 95 |
| 96 let keyModifiers = key.getAttribute("modifiers"); | 96 let keyModifiers = key.getAttribute("modifiers"); |
| 97 if (keyModifiers) | 97 if (keyModifiers) |
| 98 for each (let modifier in keyModifiers.toUpperCase().match(/\w+/g)) | 98 for (let modifier of keyModifiers.toUpperCase().match(/\w+/g)) |
| 99 if (modifier in validModifiers) | 99 if (modifier in validModifiers) |
| 100 keyData[validModifiers[modifier]] = true; | 100 keyData[validModifiers[modifier]] = true; |
| 101 | 101 |
| 102 let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control
, keyData.char || keyData.code].join(" "); | 102 let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control
, keyData.char || keyData.code].join(" "); |
| 103 this._existingShortcuts[canonical] = true; | 103 this._existingShortcuts[canonical] = true; |
| 104 } | 104 } |
| 105 }, | 105 }, |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Selects a keyboard shortcut variant that isn't already taken, | 108 * Selects a keyboard shortcut variant that isn't already taken, |
| 109 * parses it into an object. | 109 * parses it into an object. |
| 110 */ | 110 */ |
| 111 selectKey: function(/**String*/ variants) /**Object*/ | 111 selectKey: function(/**String*/ variants) /**Object*/ |
| 112 { | 112 { |
| 113 for each (let variant in variants.split(/\s*,\s*/)) | 113 for (let variant of variants.split(/\s*,\s*/)) |
| 114 { | 114 { |
| 115 if (!variant) | 115 if (!variant) |
| 116 continue; | 116 continue; |
| 117 | 117 |
| 118 let keyData = | 118 let keyData = |
| 119 { | 119 { |
| 120 shift: false, | 120 shift: false, |
| 121 meta: false, | 121 meta: false, |
| 122 alt: false, | 122 alt: false, |
| 123 control: false, | 123 control: false, |
| 124 char: null, | 124 char: null, |
| 125 code: null, | 125 code: null, |
| 126 codeName: null | 126 codeName: null |
| 127 }; | 127 }; |
| 128 for each (let part in variant.toUpperCase().split(/\s+/)) | 128 for (let part of variant.toUpperCase().split(/\s+/)) |
| 129 { | 129 { |
| 130 if (part in validModifiers) | 130 if (part in validModifiers) |
| 131 keyData[validModifiers[part]] = true; | 131 keyData[validModifiers[part]] = true; |
| 132 else if (part.length == 1) | 132 else if (part.length == 1) |
| 133 keyData.char = part; | 133 keyData.char = part; |
| 134 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) | 134 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) |
| 135 { | 135 { |
| 136 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; | 136 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; |
| 137 keyData.codeName = "VK_" + part; | 137 keyData.codeName = "VK_" + part; |
| 138 } | 138 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return false; | 206 return false; |
| 207 if (key.meta != event.metaKey || key.control != event.ctrlKey) | 207 if (key.meta != event.metaKey || key.control != event.ctrlKey) |
| 208 return false; | 208 return false; |
| 209 | 209 |
| 210 if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC
ase() == key.char) | 210 if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC
ase() == key.char) |
| 211 return true; | 211 return true; |
| 212 if (key.code && event.keyCode && event.keyCode == key.code) | 212 if (key.code && event.keyCode && event.keyCode == key.code) |
| 213 return true; | 213 return true; |
| 214 return false; | 214 return false; |
| 215 }; | 215 }; |
| OLD | NEW |