remove compatibility.ini; add .gitignore
[x_full.git] / .mozilla / firefox / default / extensions / keyconfig@dorando / components / keyconfig-service.js
1 function NSGetModule(compMgr, fileSpec) { return keyconfigModule; }\r
2 \r
3 var keyconfigModule = {\r
4   CID: Components.ID("{e9f7950e-d78d-4aaa-900a-c43588052eba}"),\r
5   contractID : "@dorando.at/keyconfig;1",\r
6   className  : "keyconfigService",\r
7 \r
8   registerSelf: function (aComponentManager, aFileSpec, aLocation, aType) \r
9   {\r
10     aComponentManager = aComponentManager.QueryInterface(Components.interfaces.nsIComponentRegistrar);\r
11 \r
12     aComponentManager.registerFactoryLocation(this.CID, this.className, this.contractID, aFileSpec, aLocation, aType);\r
13 \r
14     var CategoryManager = Components.classes["@mozilla.org/categorymanager;1"]\r
15                                     .getService(Components.interfaces.nsICategoryManager);\r
16     CategoryManager.addCategoryEntry("app-startup", this.className, "service," + this.contractID, true, true, null);\r
17   },\r
18   \r
19   getClassObject: function (aComponentManager, aCID, aIID) \r
20   {\r
21     if (!aIID.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED;\r
22 \r
23     if (aCID.equals(this.CID)) return this.factory;\r
24     \r
25     throw Components.results.NS_ERROR_NO_INTERFACE;\r
26   },\r
27 \r
28   factory: {\r
29     createInstance: function (aOuter, aIID)\r
30     {\r
31       if (aOuter != null) throw Components.results.NS_ERROR_NO_AGGREGATION;\r
32 \r
33       return new keyconfigService();\r
34     }\r
35   },\r
36   \r
37   canUnload: function () { return true; }\r
38 };\r
39 \r
40 function keyconfigService() { }\r
41 \r
42 keyconfigService.prototype = {\r
43   os: Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService),\r
44   ps: Components.classes['@mozilla.org/preferences-service;1']\r
45                 .getService(Components.interfaces.nsIPrefService).getBranch(""),\r
46   bug174320fixed: Components.interfaces.nsIDOMNSFeatureFactory ? true : false,\r
47   haspageshow: Components.interfaces.nsIDOMPageTransitionEvent ? true : false,\r
48 \r
49   observe: function (aSubject, aTopic, aData) {\r
50     if(aTopic == "app-startup") this.os.addObserver(this,"domwindowopened",false);\r
51     else if(aTopic == "domwindowopened") {\r
52       aSubject.keyconfig = {service: this};\r
53       aSubject.addEventListener("load",this.load,this.bug174320fixed);\r
54     }\r
55   },\r
56 \r
57   load: function(event) {\r
58     this.removeEventListener(event.type,this.keyconfig.service.load,true);\r
59 \r
60     if(event.eventPhase == 2 && this.keyconfig.service.bug174320fixed)\r
61      if(this.keyconfig.service.haspageshow)\r
62       this.addEventListener("pageshow",this.keyconfig.service.init,false);\r
63      else\r
64       this.keyconfig.service.init.call(this);\r
65     else\r
66       this.addEventListener("load",this.keyconfig.service.init,false);\r
67   },\r
68 \r
69   init: function() {\r
70     this.removeEventListener("pageshow",this.keyconfig.service.init,false);\r
71 \r
72     this.keyconfig.removedKeys = this.document.createElement("keyset");\r
73     this.keyconfig.profile = "keyconfig." + this.keyconfig.service.ps.getCharPref("keyconfig.profile") + ".";\r
74 \r
75     var i, l;\r
76 \r
77     var keyset = this.document.getElementsByTagName("keyset")[0] ||\r
78                  this.document.documentElement.appendChild(this.document.createElement("keyset"));\r
79 \r
80     var nodes = this.document.getElementsByTagName("key");\r
81     for(i = 0, l = nodes.length; i < l; i++) if(!nodes[i].id)\r
82       nodes[i].id = "xxx_key"+ i +"_"+nodes[i].getAttribute("command")+nodes[i].getAttribute("oncommand");\r
83 \r
84     var keys = this.keyconfig.service.ps.getChildList(this.keyconfig.profile, {});\r
85 \r
86     for(i = 0, l = keys.length; i < l; i++) {\r
87       var key, node;\r
88       try {\r
89        key = this.keyconfig.service.ps.getComplexValue(keys[i], Components.interfaces.nsISupportsString).data.split("][");\r
90       } catch(e) { continue; }\r
91       if(key[3] && (!key[4] || key[4] == this.document.location)) {\r
92         node = keyset.appendChild(this.document.createElement("key"));\r
93         node.id = keys[i].substr(this.keyconfig.profile.length);\r
94         node.setAttribute("oncommand",key[3]);\r
95       } else {\r
96         node = this.document.getElementById(keys[i].substr(this.keyconfig.profile.length));\r
97         if(!node) continue;\r
98       }\r
99 \r
100       node.removeAttribute("modifiers"); node.removeAttribute("key"); node.removeAttribute("keycode");\r
101       node.removeAttribute("charcode");\r
102       if(key[0] == "!") {this.keyconfig.removedKeys.appendChild(node); continue;}\r
103 \r
104       if(key[0]) node.setAttribute("modifiers",key[0]);\r
105       if(key[1]) node.setAttribute("key",key[1]);\r
106       if(key[2]) node.setAttribute("keycode",key[2]);\r
107     }\r
108   }\r
109 \r
110 }\r