| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 if (keyChar && keyChar.length == 1) | 86 if (keyChar && keyChar.length == 1) |
| 87 keyData.char = keyChar.toUpperCase(); | 87 keyData.char = keyChar.toUpperCase(); |
| 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 modifiers = key.getAttribute("modifiers"); | 96 let keyModifiers = key.getAttribute("modifiers"); |
| 97 modifiers = modifiers ? modifiers.toUpperCase().match(/\w+/g) : null; | 97 let modifiers = keyModifiers ? keyModifiers.toUpperCase().match(/\w+/g) : null; |
|
Wladimir Palant
2014/11/17 20:05:17
If you are doing it this way, why not use [] inste
|
Wladimir Palant
2014/12/09 21:24:49
Comment from previous round not addressed or repli
|
| 98 if (modifiers) | 98 if (modifiers) |
| 99 { | 99 { |
| 100 for (let modifier of modifiers) | 100 for (let modifier of modifiers) |
| 101 { | 101 { |
| 102 if (modifier in validModifiers) | 102 if (modifier in validModifiers) |
| 103 keyData[validModifiers[modifier]] = true; | 103 keyData[validModifiers[modifier]] = true; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control , keyData.char || keyData.code].join(" "); | 107 let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control , keyData.char || keyData.code].join(" "); |
| 108 this._existingShortcuts[canonical] = true; | 108 this._existingShortcuts[canonical] = true; |
| 109 } | 109 } |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * Selects a keyboard shortcut variant that isn't already taken, | 113 * Selects a keyboard shortcut variant that isn't already taken, |
| 114 * parses it into an object. | 114 * parses it into an object. |
| 115 */ | 115 */ |
| 116 selectKey: function(/**String*/ variants) /**Object*/ | 116 selectKey: function(/**String*/ variants) /**Object*/ |
| 117 { | 117 { |
| 118 variants = variants.split(/\s*,\s*/); | 118 for (let variant of variants.split(/\s*,\s*/)) |
| 119 if (!variants) | |
|
Wladimir Palant
2014/11/17 20:05:17
This condition can never be true - String.split()
| |
| 120 return null; | |
| 121 | |
| 122 for (let variant of variants) | |
| 123 { | 119 { |
| 124 if (!variant) | 120 if (!variant) |
| 125 continue; | 121 continue; |
| 126 | 122 |
| 127 let keyData = | 123 let keyData = |
| 128 { | 124 { |
| 129 shift: false, | 125 shift: false, |
| 130 meta: false, | 126 meta: false, |
| 131 alt: false, | 127 alt: false, |
| 132 control: false, | 128 control: false, |
| 133 char: null, | 129 char: null, |
| 134 code: null, | 130 code: null, |
| 135 codeName: null | 131 codeName: null |
| 136 }; | 132 }; |
| 137 | 133 |
| 138 variant = variant.toUpperCase().split(/\s+/); | 134 for (let part of variant.toUpperCase().split(/\s+/)) |
| 139 if (!variant) | |
|
Wladimir Palant
2014/11/17 20:05:17
Same here, this if block is pointless.
| |
| 140 continue; | |
| 141 | |
| 142 for (let part of variant) | |
| 143 { | 135 { |
| 144 if (part in validModifiers) | 136 if (part in validModifiers) |
| 145 keyData[validModifiers[part]] = true; | 137 keyData[validModifiers[part]] = true; |
| 146 else if (part.length == 1) | 138 else if (part.length == 1) |
| 147 keyData.char = part; | 139 keyData.char = part; |
| 148 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) | 140 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) |
| 149 { | 141 { |
| 150 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; | 142 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; |
| 151 keyData.codeName = "VK_" + part; | 143 keyData.codeName = "VK_" + part; |
| 152 } | 144 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return false; | 212 return false; |
| 221 if (key.meta != event.metaKey || key.control != event.ctrlKey) | 213 if (key.meta != event.metaKey || key.control != event.ctrlKey) |
| 222 return false; | 214 return false; |
| 223 | 215 |
| 224 if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC ase() == key.char) | 216 if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC ase() == key.char) |
| 225 return true; | 217 return true; |
| 226 if (key.code && event.keyCode && event.keyCode == key.code) | 218 if (key.code && event.keyCode && event.keyCode == key.code) |
| 227 return true; | 219 return true; |
| 228 return false; | 220 return false; |
| 229 }; | 221 }; |
| LEFT | RIGHT |