Permalink
Browse files

[BUG #4983] Add getKeyIdentifier() method to keyboard events

  • Loading branch information...
1 parent ca45fd6 commit 0f5acf178983658f020e27cb2eb16004af2ef607 @danielwagner danielwagner committed Mar 28, 2012
View
1 component/standalone/website/config.json
@@ -44,6 +44,7 @@
"qx.module.Event",
"qx.module.event.Native",
"qx.module.event.Mouse",
+ "qx.module.event.Keyboard",
"qx.module.Template",
"qx.module.Polyfill",
"q"
View
37 component/standalone/website/test/tests.js
@@ -1222,6 +1222,43 @@ testrunner.define({
});
testrunner.define({
+ classname : "event.Keyboard",
+
+ setUp : testrunner.globalSetup,
+ tearDown : testrunner.globalTeardown,
+
+ testEventNormalization : function()
+ {
+ var eventTypes = qx.module.event.Keyboard.TYPES;
+ this.assertArray(eventTypes);
+ this.assert(eventTypes.length > 0);
+ var registry = qx.module.Event.getRegistry();
+ for (var i=0,l=eventTypes.length; i<l; i++) {
+ this.assertKeyInMap(eventTypes[i], registry);
+ }
+ },
+
+ testEventMethods : function()
+ {
+ var test = q.create("<div id='foo'></div>");
+ test.appendTo(this.sandbox[0]);
+
+ var obj = {};
+
+ q("#sandbox #foo").on("keydown", function(ev) {
+ this.keyIdentifier = ev.getKeyIdentifier();
+ }, obj);
+
+ q("#sandbox #foo").emit("keydown", {
+ keyCode: 27
+ });
+
+ this.assertEquals("Escape", obj.keyIdentifier);
+ }
+});
+
+
+testrunner.define({
classname : "Templates",
setUp : testrunner.globalSetup,
View
31 framework/source/class/qx/module/event/Keyboard.js
@@ -0,0 +1,31 @@
+qx.Bootstrap.define("qx.module.event.Keyboard", {
+ statics :
+ {
+ TYPES : ["keydown", "keypress", "keyup"],
+
+ BIND_METHODS : ["getKeyIdentifier"],
+
+ getKeyIdentifier : function()
+ {
+ return qx.event.util.Keyboard.keyCodeToIdentifier(this.keyCode);
+ },
+
+ normalize : function(event, element) {
+ if (!event) {
+ return event;
+ }
+ var bindMethods = qx.module.event.Keyboard.BIND_METHODS;
+ for (var i=0, l=bindMethods.length; i<l; i++) {
+ if (typeof event[bindMethods[i]] != "function") {
+ event[bindMethods[i]] = qx.module.event.Keyboard[bindMethods[i]].bind(event);
+ }
+ }
+
+ return event;
+ }
+ },
+
+ defer : function(statics) {
+ q.registerEventNormalization(qx.module.event.Keyboard.TYPES, statics.normalize);
+ }
+});

0 comments on commit 0f5acf1

Please sign in to comment.