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