| 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 = Object.create(null); | 
|    8 { |    8 validModifiers.ACCEL = null; | 
|    9   ACCEL: null, |    9 validModifiers.CTRL = "control"; | 
|   10   CTRL: "control", |   10 validModifiers.CONTROL = "control"; | 
|   11   CONTROL: "control", |   11 validModifiers.SHIFT = "shift"; | 
|   12   SHIFT: "shift", |   12 validModifiers.ALT = "alt"; | 
|   13   ALT: "alt", |   13 validModifiers.META = "meta"; | 
|   14   META: "meta", |  | 
|   15   __proto__: null |  | 
|   16 }; |  | 
|   17  |   14  | 
|   18 /** |   15 /** | 
|   19  * Sets the correct value of validModifiers.ACCEL. |   16  * Sets the correct value of validModifiers.ACCEL. | 
|   20  */ |   17  */ | 
|   21 function initAccelKey() |   18 function initAccelKey() | 
|   22 { |   19 { | 
|   23   validModifiers.ACCEL = "control"; |   20   validModifiers.ACCEL = "control"; | 
|   24   try |   21   try | 
|   25   { |   22   { | 
|   26     let accelKey = Services.prefs.getIntPref("ui.key.accelKey"); |   23     let accelKey = Services.prefs.getIntPref("ui.key.accelKey"); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   59   _existingShortcuts: null, |   56   _existingShortcuts: null, | 
|   60  |   57  | 
|   61   /** |   58   /** | 
|   62    * Sets up _existingShortcuts property for a window. |   59    * Sets up _existingShortcuts property for a window. | 
|   63    */ |   60    */ | 
|   64   _initExistingShortcuts: function(/**ChromeWindow*/ window) |   61   _initExistingShortcuts: function(/**ChromeWindow*/ window) | 
|   65   { |   62   { | 
|   66     if (!validModifiers.ACCEL) |   63     if (!validModifiers.ACCEL) | 
|   67       initAccelKey(); |   64       initAccelKey(); | 
|   68  |   65  | 
|   69     this._existingShortcuts = {__proto__: null}; |   66     this._existingShortcuts = Object.create(null); | 
|   70  |   67  | 
|   71     let keys = window.document.getElementsByTagName("key"); |   68     let keys = window.document.getElementsByTagName("key"); | 
|   72     for (let i = 0; i < keys.length; i++) |   69     for (let i = 0; i < keys.length; i++) | 
|   73     { |   70     { | 
|   74       let key = keys[i]; |   71       let key = keys[i]; | 
|   75       let keyData = |   72       let keyData = | 
|   76       { |   73       { | 
|   77         shift: false, |   74         shift: false, | 
|   78         meta: false, |   75         meta: false, | 
|   79         alt: false, |   76         alt: false, | 
|   80         control: false, |   77         control: false, | 
|   81         char: null, |   78         char: null, | 
|   82         code: null |   79         code: null | 
|   83       }; |   80       }; | 
|   84  |   81  | 
|   85       let keyChar = key.getAttribute("key"); |   82       let keyChar = key.getAttribute("key"); | 
|   86       if (keyChar && keyChar.length == 1) |   83       if (keyChar && keyChar.length == 1) | 
|   87         keyData.char = keyChar.toUpperCase(); |   84         keyData.char = keyChar.toUpperCase(); | 
|   88  |   85  | 
|   89       let keyCode = key.getAttribute("keycode"); |   86       let keyCode = key.getAttribute("keycode"); | 
|   90       if (keyCode && "DOM_" + keyCode.toUpperCase() in Ci.nsIDOMKeyEvent) |   87       if (keyCode && "DOM_" + keyCode.toUpperCase() in Ci.nsIDOMKeyEvent) | 
|   91         keyData.code = Ci.nsIDOMKeyEvent["DOM_" + keyCode.toUpperCase()]; |   88         keyData.code = Ci.nsIDOMKeyEvent["DOM_" + keyCode.toUpperCase()]; | 
|   92  |   89  | 
|   93       if (!keyData.char && !keyData.code) |   90       if (!keyData.char && !keyData.code) | 
|   94         continue; |   91         continue; | 
|   95  |   92  | 
|   96       let keyModifiers = key.getAttribute("modifiers"); |   93       let keyModifiers = key.getAttribute("modifiers"); | 
|   97       if (keyModifiers) |   94       if (keyModifiers) | 
|   98         for each (let modifier in keyModifiers.toUpperCase().match(/\w+/g)) |   95         for (let modifier of keyModifiers.toUpperCase().match(/\w+/g)) | 
|   99           if (modifier in validModifiers) |   96           if (modifier in validModifiers) | 
|  100             keyData[validModifiers[modifier]] = true; |   97             keyData[validModifiers[modifier]] = true; | 
|  101  |   98  | 
|  102       let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control
     , keyData.char || keyData.code].join(" "); |   99       let canonical = [keyData.shift, keyData.meta, keyData.alt, keyData.control
     , keyData.char || keyData.code].join(" "); | 
|  103       this._existingShortcuts[canonical] = true; |  100       this._existingShortcuts[canonical] = true; | 
|  104     } |  101     } | 
|  105   }, |  102   }, | 
|  106  |  103  | 
|  107   /** |  104   /** | 
|  108    * Selects a keyboard shortcut variant that isn't already taken, |  105    * Selects a keyboard shortcut variant that isn't already taken, | 
|  109    * parses it into an object. |  106    * parses it into an object. | 
|  110    */ |  107    */ | 
|  111   selectKey: function(/**String*/ variants) /**Object*/ |  108   selectKey: function(/**String*/ variants) /**Object*/ | 
|  112   { |  109   { | 
|  113     for each (let variant in variants.split(/\s*,\s*/)) |  110     for (let variant of variants.split(/\s*,\s*/)) | 
|  114     { |  111     { | 
|  115       if (!variant) |  112       if (!variant) | 
|  116         continue; |  113         continue; | 
|  117  |  114  | 
|  118       let keyData = |  115       let keyData = | 
|  119       { |  116       { | 
|  120         shift: false, |  117         shift: false, | 
|  121         meta: false, |  118         meta: false, | 
|  122         alt: false, |  119         alt: false, | 
|  123         control: false, |  120         control: false, | 
|  124         char: null, |  121         char: null, | 
|  125         code: null, |  122         code: null, | 
|  126         codeName: null |  123         codeName: null | 
|  127       }; |  124       }; | 
|  128       for each (let part in variant.toUpperCase().split(/\s+/)) |  125       for (let part of variant.toUpperCase().split(/\s+/)) | 
|  129       { |  126       { | 
|  130         if (part in validModifiers) |  127         if (part in validModifiers) | 
|  131           keyData[validModifiers[part]] = true; |  128           keyData[validModifiers[part]] = true; | 
|  132         else if (part.length == 1) |  129         else if (part.length == 1) | 
|  133           keyData.char = part; |  130           keyData.char = part; | 
|  134         else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) |  131         else if ("DOM_VK_" + part in Ci.nsIDOMKeyEvent) | 
|  135         { |  132         { | 
|  136           keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; |  133           keyData.code = Ci.nsIDOMKeyEvent["DOM_VK_" + part]; | 
|  137           keyData.codeName = "VK_" + part; |  134           keyData.codeName = "VK_" + part; | 
|  138         } |  135         } | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  206     return false; |  203     return false; | 
|  207   if (key.meta != event.metaKey || key.control != event.ctrlKey) |  204   if (key.meta != event.metaKey || key.control != event.ctrlKey) | 
|  208     return false; |  205     return false; | 
|  209  |  206  | 
|  210   if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC
     ase() == key.char) |  207   if (key.char && event.charCode && String.fromCharCode(event.charCode).toUpperC
     ase() == key.char) | 
|  211     return true; |  208     return true; | 
|  212   if (key.code && event.keyCode && event.keyCode == key.code) |  209   if (key.code && event.keyCode && event.keyCode == key.code) | 
|  213     return true; |  210     return true; | 
|  214   return false; |  211   return false; | 
|  215 }; |  212 }; | 
| OLD | NEW |