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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 keyModifiers = key.getAttribute("modifiers"); |
97 if (keyModifiers) | 97 let modifiers = keyModifiers ? keyModifiers.toUpperCase().match(/\w+/g) :
null; |
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 for (let variant of variants.split(/\s*,\s*/)) |
114 { | 119 { |
115 if (!variant) | 120 if (!variant) |
116 continue; | 121 continue; |
117 | 122 |
118 let keyData = | 123 let keyData = |
119 { | 124 { |
120 shift: false, | 125 shift: false, |
121 meta: false, | 126 meta: false, |
122 alt: false, | 127 alt: false, |
123 control: false, | 128 control: false, |
124 char: null, | 129 char: null, |
125 code: null, | 130 code: null, |
126 codeName: null | 131 codeName: null |
127 }; | 132 }; |
128 for each (let part in variant.toUpperCase().split(/\s+/)) | 133 |
| 134 for (let part of variant.toUpperCase().split(/\s+/)) |
129 { | 135 { |
130 if (part in validModifiers) | 136 if (part in validModifiers) |
131 keyData[validModifiers[part]] = true; | 137 keyData[validModifiers[part]] = true; |
132 else if (part.length == 1) | 138 else if (part.length == 1) |
133 keyData.char = part; | 139 keyData.char = part; |
134 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) | 140 else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) |
135 { | 141 { |
136 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; | 142 keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; |
137 keyData.codeName = "VK_" + part; | 143 keyData.codeName = "VK_" + part; |
138 } | 144 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return false; | 212 return false; |
207 if (key.meta != event.metaKey || key.control != event.ctrlKey) | 213 if (key.meta != event.metaKey || key.control != event.ctrlKey) |
208 return false; | 214 return false; |
209 | 215 |
210 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) |
211 return true; | 217 return true; |
212 if (key.code && event.keyCode && event.keyCode == key.code) | 218 if (key.code && event.keyCode && event.keyCode == key.code) |
213 return true; | 219 return true; |
214 return false; | 220 return false; |
215 }; | 221 }; |
OLD | NEW |