[qooxdoo-commit] SF.net SVN: qooxdoo: [8919] trunk/qooxdoo/frontend
Brought to you by:
ecker,
martinwittemann
From: <fj...@us...> - 2007-07-10 15:37:00
|
Revision: 8919 http://svn.sourceforge.net/qooxdoo/?rev=8919&view=rev Author: fjakobs Date: 2007-07-10 08:36:50 -0700 (Tue, 10 Jul 2007) Log Message: ----------- include key handling to low level event layer Modified Paths: -------------- trunk/qooxdoo/frontend/application/demobrowser/source/html/test/Event2_1.html trunk/qooxdoo/frontend/framework/source/class/qx/html2/EventRegistration.js Added Paths: ----------- trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEvent.js trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEventHandler.js Modified: trunk/qooxdoo/frontend/application/demobrowser/source/html/test/Event2_1.html =================================================================== --- trunk/qooxdoo/frontend/application/demobrowser/source/html/test/Event2_1.html 2007-07-10 14:31:59 UTC (rev 8918) +++ trunk/qooxdoo/frontend/application/demobrowser/source/html/test/Event2_1.html 2007-07-10 15:36:50 UTC (rev 8919) @@ -65,6 +65,8 @@ </div> </div> + <input type="text" id="input"></input> + <div id="scroll"> Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners Juhu Kinners @@ -95,7 +97,9 @@ qx.html2.EventRegistration.addEventListener(this._juhu, "click", this._onclick1, this); qx.html2.EventRegistration.addEventListener(this._juhu, "click", this._onclick2, this); + qx.html2.EventRegistration.addEventListener(document.getElementById("input"), "keydown", this._onkeydown, this); + for (var i=1; i<10; i++) { var div = document.getElementById("div"+i); qx.html2.EventRegistration.addEventListener(div, "click", this._cascadeCapture, this, true); @@ -110,6 +114,11 @@ ); }, + _onkeydown: function(e) { + this.debug("keydown: " + e.getKeyIdentifier()); + console.log(e); + }, + _scroll: function(e) { this.debug("scroll"); }, Modified: trunk/qooxdoo/frontend/framework/source/class/qx/html2/EventRegistration.js =================================================================== --- trunk/qooxdoo/frontend/framework/source/class/qx/html2/EventRegistration.js 2007-07-10 14:31:59 UTC (rev 8918) +++ trunk/qooxdoo/frontend/framework/source/class/qx/html2/EventRegistration.js 2007-07-10 15:36:50 UTC (rev 8919) @@ -1,3 +1,9 @@ +/* ************************************************************************ + +#require(qx.html2.KeyEventHandler) + +************************************************************************ */ + /** * Wrapper for browser DOM event handling. * @@ -59,6 +65,27 @@ __inlineRegistry : {}, + __init : function() + { + var keyHandler = qx.lang.Function.bind(this.__keyEventHandler, this); + this.__keyEventHandler = new qx.html2.KeyEventHandler(keyHandler); + this.__customHandler = { + "keydown": qx.lang.Function.bind( + this.__keyEventHandler.onKeyUpDown, + this.__keyEventHandler + ), + "keyup": qx.lang.Function.bind( + this.__keyEventHandler.onKeyUpDown, + this.__keyEventHandler + ), + "keypress": qx.lang.Function.bind( + this.__keyEventHandler.onKeyPress, + this.__keyEventHandler + ) + } + }, + + /** * Use the low level browser functionality to attach event listeners * to DOM nodes. Uses <code>attachEvent</code> in IE and @@ -150,10 +177,11 @@ var reg = this.__registry; if (!reg[type]) { reg[type] = {}; + var eventHandler = this.__customHandler[type] || this.__documentEventHandler; this._nativeAddEventListener( window.document.documentElement, type, - this.__documentEventHandler + eventHandler ); } @@ -181,16 +209,34 @@ }, + __keyEventHandler : function(domEvent, eventType, keyCode, charCode, keyIdentifier) + { + var event = new qx.html2.KeyEvent.getInstance( + -1, domEvent, eventType, keyCode, charCode, keyIdentifier + ); + this.__dispatchDocumentEvent(event); + }, + + /** - * Central event handler for all bubbling events. This function dispatches - * the event to the event handlers and emulates the capturing and - * bubbling phase. + * Central event handler for all bubbling events. * * @param domEvent {Event} DOM event passed by the browser. */ - __documentEventHandler : function(domEvent) + __documentEventHandler : function(domEvent) { + var event = qx.html2.Event.getInstance(-1, window.event || domEvent); + qx.html2.EventRegistration.__dispatchDocumentEvent(event); + }, + + + /** + * This function dispatches the event to the event handlers and emulates + * the capturing and bubbling phase. + * + * @param event {qx.html2.Event} event object to dispatch + */ + __dispatchDocumentEvent : function(event) { - var event = qx.html2.Event.getInstance(-1, window.event || domEvent); var target = event.getTarget(); var node = target; @@ -441,6 +487,10 @@ } + }, + + defer : function(statics) { + statics.__init(); } }); Added: trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEvent.js =================================================================== --- trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEvent.js (rev 0) +++ trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEvent.js 2007-07-10 15:36:50 UTC (rev 8919) @@ -0,0 +1,167 @@ +/** + * Keyboard event object. + * + * the interface of this class is based on the DOM Level 3 keyboard event + * interface: http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-KeyboardEvent + */ +qx.Class.define("qx.html2.KeyEvent", +{ + extend : qx.html2.Event, + + statics : + { + getInstance : function(elementHash, domEvent, eventType, keyCode, charCode, keyIdentifier) + { + if (this.__instance == undefined) { + this.__instance = new qx.html2.KeyEvent(); + } + this.__instance.__initEvent(elementHash, domEvent, eventType, keyCode, charCode, keyIdentifier); + return this.__instance; + } + }, + + members : + { + __initEvent : function(elementHash, domEvent, eventType, keyCode, charCode, keyIdentifier) + { + this.base(arguments, elementHash, domEvent); + this._type = eventType; + this._keyCode = keyCode; + this._charCode = charCode; + this._keyIdentifier = keyIdentifier; + }, + + + // overridden + getType : function() { + return this._type; + }, + + + /** + * Unicode number of the pressed character. + * Only valid in "keyinput" events + */ + getCharCode : function() { + return this._charCode; + }, + + + /** + * Identifier of the pressed key. This property is modeled after the <em>KeyboardEvent.keyIdentifier</em> property + * of the W3C DOM 3 event specification (http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-KeyboardEvent-keyIdentifier). + * + * It is not valid in "keyinput" events" + * + * Printable keys are represented by a unicode string, non-printable keys have one of the following + * values: + * <br> + * <table> + * <tr><th>Backspace</th><td>The Backspace (Back) key.</td></tr> + * <tr><th>Tab</th><td>The Horizontal Tabulation (Tab) key.</td></tr> + * <tr><th>Space</th><td>The Space (Spacebar) key.</td></tr> + * <tr><th>Enter</th><td>The Enter key. Note: This key identifier is also used for the Return (Macintosh numpad) key.</td></tr> + * <tr><th>Shift</th><td>The Shift key.</td></tr> + * <tr><th>Control</th><td>The Control (Ctrl) key.</td></tr> + * <tr><th>Alt</th><td>The Alt (Menu) key.</td></tr> + * <tr><th>CapsLock</th><td>The CapsLock key</td></tr> + * <tr><th>Meta</th><td>The Meta key. (Apple Meta and Windows key)</td></tr> + * <tr><th>Escape</th><td>The Escape (Esc) key.</td></tr> + * <tr><th>Left</th><td>The Left Arrow key.</td></tr> + * <tr><th>Up</th><td>The Up Arrow key.</td></tr> + * <tr><th>Right</th><td>The Right Arrow key.</td></tr> + * <tr><th>Down</th><td>The Down Arrow key.</td></tr> + * <tr><th>PageUp</th><td>The Page Up key.</td></tr> + * <tr><th>PageDown</th><td>The Page Down (Next) key.</td></tr> + * <tr><th>End</th><td>The End key.</td></tr> + * <tr><th>Home</th><td>The Home key.</td></tr> + * <tr><th>Insert</th><td>The Insert (Ins) key. (Does not fire in Opera/Win)</td></tr> + * <tr><th>Delete</th><td>The Delete (Del) Key.</td></tr> + * <tr><th>F1</th><td>The F1 key.</td></tr> + * <tr><th>F2</th><td>The F2 key.</td></tr> + * <tr><th>F3</th><td>The F3 key.</td></tr> + * <tr><th>F4</th><td>The F4 key.</td></tr> + * <tr><th>F5</th><td>The F5 key.</td></tr> + * <tr><th>F6</th><td>The F6 key.</td></tr> + * <tr><th>F7</th><td>The F7 key.</td></tr> + * <tr><th>F8</th><td>The F8 key.</td></tr> + * <tr><th>F9</th><td>The F9 key.</td></tr> + * <tr><th>F10</th><td>The F10 key.</td></tr> + * <tr><th>F11</th><td>The F11 key.</td></tr> + * <tr><th>F12</th><td>The F12 key.</td></tr> + * <tr><th>NumLock</th><td>The Num Lock key.</td></tr> + * <tr><th>PrintScreen</th><td>The Print Screen (PrintScrn, SnapShot) key.</td></tr> + * <tr><th>Scroll</th><td>The scroll lock key</td></tr> + * <tr><th>Pause</th><td>The pause/break key</td></tr> + * <tr><th>Win</th><td>The Windows Logo key</td></tr> + * <tr><th>Apps</th><td>The Application key (Windows Context Menu)</td></tr> + * </table> + */ + getKeyIdentifier : function() { + return this._keyIdentifier; + }, + + + /** + * Returns whether the the ctrl key is pressed. + * + * @type member + * @return {Boolean} whether the the ctrl key is pressed. + */ + isCtrlPressed : function() { + return this._event.ctrlKey; + }, + + + /** + * Returns whether the the shift key is pressed. + * + * @type member + * @return {Boolean} whether the the shift key is pressed. + */ + isShiftPressed : function() { + return this._event.shiftKey; + }, + + + /** + * Returns whether the the alt key is pressed. + * + * @type member + * @return {Boolean} whether the the alt key is pressed. + */ + isAltPressed : function() { + return this._event.altKey; + }, + + + /** + * Returns whether the the meta key is pressed. + * + * @type member + * @return {Boolean} whether the the meta key is pressed. + */ + isMetaPressed : function() { + return this._event.metaKey; + }, + + + /** + * Returns whether the ctrl key or (on the Mac) the command key is pressed. + * + * @type member + * @return {Boolean} <code>true</code> if the command key is pressed on the Mac + * or the ctrl key is pressed on another system. + */ + isCtrlOrCommandPressed : function() + { + if (qx.core.Client.getInstance().runsOnMacintosh()) { + return this._event.metaKey; + } else { + return this._event.ctrlKey; + } + } + + } + +}); \ No newline at end of file Added: trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEventHandler.js =================================================================== --- trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEventHandler.js (rev 0) +++ trunk/qooxdoo/frontend/framework/source/class/qx/html2/KeyEventHandler.js 2007-07-10 15:36:50 UTC (rev 8919) @@ -0,0 +1,644 @@ +/* ************************************************************************ + + qooxdoo - the new era of web development + + http://qooxdoo.org + + Copyright: + 2004-2007 1&1 Internet AG, Germany, http://www.1and1.org + + License: + LGPL: http://www.gnu.org/licenses/lgpl.html + EPL: http://www.eclipse.org/org/documents/epl-v10.php + See the LICENSE file in the project's top-level directory for details. + + Authors: + * Sebastian Werner (wpbasti) + * Andreas Ecker (ecker) + * Fabian Jakobs (fjakobs) + +************************************************************************ */ + +/* ************************************************************************ + +************************************************************************ */ + +/** + * This class provides unified key event handler for Internet Explorer, + * Firefox, Opera and Safari + */ +qx.Class.define("qx.html2.KeyEventHandler", +{ + extend : qx.core.Target, + + + + + /* + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ + + construct : function(keyHandler) + { + this.base(arguments); + this._keyHandler = keyHandler; + }, + + + + + /* + ***************************************************************************** + MEMBERS + ***************************************************************************** + */ + + members : + { + /* + --------------------------------------------------------------------------- + EVENT-HANDLER + --------------------------------------------------------------------------- + */ + + /** + * Low level handler for "keyup" and "keydown" events + * + * @param domEvent {Event} DOM event object + * @signature function(domEvent) + */ + onKeyUpDown : qx.core.Variant.select("qx.client", + { + "mshtml" : function(domEvent) + { + domEvent = window.event || domEvent; + + var keyCode = domEvent.keyCode; + var charcode = 0; + var type = domEvent.type; + + // Ignore the down in such sequences dp dp dp + if (!(this._lastUpDownType[keyCode] == "keydown" && type == "keydown")) { + this._idealKeyHandler(keyCode, charcode, type, domEvent); + } + + // On non print-able character be sure to add a keypress event + if (type == "keydown") { + if (this._isNonPrintableKeyCode(keyCode) || + keyCode == 8 || // backspace + keyCode == 9 // tab + ) { + this._idealKeyHandler(keyCode, charcode, "keypress", domEvent); + } + } + + // Store last type + this._lastUpDownType[keyCode] = type; + }, + + "gecko" : function(domEvent) + { + var keyCode = this._keyCodeFix[domEvent.keyCode] || domEvent.keyCode; + var charCode = domEvent.charCode; + var type = domEvent.type; + + // FF repeats under windows keydown events like IE + if (qx.core.Client.getInstance().runsOnWindows()) + { + var keyIdentifier = keyCode ? this._keyCodeToIdentifier(keyCode) : this._charCodeToIdentifier(charCode); + + if (!(this._lastUpDownType[keyIdentifier] == "keypress" && type == "keydown")) { + this._idealKeyHandler(keyCode, charCode, type, domEvent); + } + + // Store last type + this._lastUpDownType[keyIdentifier] = type; + } + + // all other OSes + else + { + this._idealKeyHandler(keyCode, charCode, type, domEvent); + } + }, + + "webkit" : function(domEvent) + { + var keyCode = 0; + var charCode = 0; + var type = domEvent.type; + + // prevent Safari from sending key signals twice + // This bug is fixed in recent Webkit builds so we need a revision check + // see http://trac.mochikit.com/ticket/182 for details + if (qx.core.Client.getInstance().getVersion() < 420) + { + if (!this._lastCharCodeForType) { + this._lastCharCodeForType = {}; + } + + var isSafariSpecialKey = this._lastCharCodeForType[type] > 63000; + + if (isSafariSpecialKey) + { + this._lastCharCodeForType[type] = null; + return; + } + + this._lastCharCodeForType[type] = domEvent.charCode; + } + + if (type == "keyup" || type == "keydown") { + keyCode = this._charCode2KeyCode[domEvent.charCode] || domEvent.keyCode; + } + else + { + if (this._charCode2KeyCode[domEvent.charCode]) { + keyCode = this._charCode2KeyCode[domEvent.charCode]; + } else { + charCode = domEvent.charCode; + } + } + + this._idealKeyHandler(keyCode, charCode, type, domEvent); + }, + + "opera" : function(domEvent) { + this._idealKeyHandler(domEvent.keyCode, 0, domEvent.type, domEvent); + }, + + "default" : function() { + throw new Error("Unsupported browser for key event handler!"); + } + }), + + + /** + * Low level key press handler + * + * @param domEvent {Event} DOM event object + * @signature function(domEvent) + */ + onKeyPress : qx.core.Variant.select("qx.client", + { + "mshtml" : function(domEvent) + { + var domEvent = window.event || domEvent; + + if (this._charCode2KeyCode[domEvent.keyCode]) { + this._idealKeyHandler(this._charCode2KeyCode[domEvent.keyCode], 0, domEvent.type, domEvent); + } else { + this._idealKeyHandler(0, domEvent.keyCode, domEvent.type, domEvent); + } + }, + + "gecko" : function(domEvent) + { + var keyCode = this._keyCodeFix[domEvent.keyCode] || domEvent.keyCode; + var charCode = domEvent.charCode; + var type = domEvent.type; + + // FF repeats under windows keydown events like IE + if (qx.core.Client.getInstance().runsOnWindows()) + { + var keyIdentifier = keyCode ? this._keyCodeToIdentifier(keyCode) : this._charCodeToIdentifier(charCode); + + if (!(this._lastUpDownType[keyIdentifier] == "keypress" && type == "keydown")) { + this._idealKeyHandler(keyCode, charCode, type, domEvent); + } + + // Store last type + this._lastUpDownType[keyIdentifier] = type; + } + + // all other OSes + else + { + this._idealKeyHandler(keyCode, charCode, type, domEvent); + } + }, + + "webkit" : function(domEvent) + { + var keyCode = 0; + var charCode = 0; + var type = domEvent.type; + + // prevent Safari from sending key signals twice + // This bug is fixed in recent Webkit builds so we need a revision check + // see http://trac.mochikit.com/ticket/182 for details + if (qx.core.Client.getInstance().getVersion() < 420) + { + if (!this._lastCharCodeForType) { + this._lastCharCodeForType = {}; + } + + var isSafariSpecialKey = this._lastCharCodeForType[type] > 63000; + + if (isSafariSpecialKey) + { + this._lastCharCodeForType[type] = null; + return; + } + + this._lastCharCodeForType[type] = domEvent.charCode; + } + + if (type == "keyup" || type == "keydown") { + keyCode = this._charCode2KeyCode[domEvent.charCode] || domEvent.keyCode; + } + else + { + if (this._charCode2KeyCode[domEvent.charCode]) { + keyCode = this._charCode2KeyCode[domEvent.charCode]; + } else { + charCode = domEvent.charCode; + } + } + + this._idealKeyHandler(keyCode, charCode, type, domEvent); + }, + + "opera" : function(domEvent) + { + if (this._keyCodeToIdentifierMap[domEvent.keyCode]) { + this._idealKeyHandler(domEvent.keyCode, 0, domEvent.type, domEvent); + } else { + this._idealKeyHandler(0, domEvent.keyCode, domEvent.type, domEvent); + } + }, + + "default" : function() { + throw new Error("Unsupported browser for key event handler!"); + } + }), + + + + + + /* + --------------------------------------------------------------------------- + KEY-MAPS + --------------------------------------------------------------------------- + */ + + /** maps the charcodes of special printable keys to key identifiers */ + _specialCharCodeMap : + { + 8 : "Backspace", // The Backspace (Back) key. + 9 : "Tab", // The Horizontal Tabulation (Tab) key. + + // Note: This key identifier is also used for the + // Return (Macintosh numpad) key. + 13 : "Enter", // The Enter key. + + 27 : "Escape", // The Escape (Esc) key. + 32 : "Space" // The Space (Spacebar) key. + + }, + + /** maps the keycodes of non printable keys to key identifiers */ + _keyCodeToIdentifierMap : + { + 16 : "Shift", // The Shift key. + 17 : "Control", // The Control (Ctrl) key. + 18 : "Alt", // The Alt (Menu) key. + 20 : "CapsLock", // The CapsLock key + 224 : "Meta", // The Meta key. (Apple Meta and Windows key) + 37 : "Left", // The Left Arrow key. + 38 : "Up", // The Up Arrow key. + 39 : "Right", // The Right Arrow key. + 40 : "Down", // The Down Arrow key. + 33 : "PageUp", // The Page Up key. + 34 : "PageDown", // The Page Down (Next) key. + 35 : "End", // The End key. + 36 : "Home", // The Home key. + 45 : "Insert", // The Insert (Ins) key. (Does not fire in Opera/Win) + 46 : "Delete", // The Delete (Del) Key. + 112 : "F1", // The F1 key. + 113 : "F2", // The F2 key. + 114 : "F3", // The F3 key. + 115 : "F4", // The F4 key. + 116 : "F5", // The F5 key. + 117 : "F6", // The F6 key. + 118 : "F7", // The F7 key. + 119 : "F8", // The F8 key. + 120 : "F9", // The F9 key. + 121 : "F10", // The F10 key. + 122 : "F11", // The F11 key. + 123 : "F12", // The F12 key. + 144 : "NumLock", // The Num Lock key. + 44 : "PrintScreen", // The Print Screen (PrintScrn, SnapShot) key. + 145 : "Scroll", // The scroll lock key + 19 : "Pause", // The pause/break key + 91 : "Win", // The Windows Logo key + 93 : "Apps" // The Application key (Windows Context Menu) + }, + + /** maps the keycodes of the numpad keys to the right charcodes */ + _numpadToCharCode : + { + 96 : "0".charCodeAt(0), + 97 : "1".charCodeAt(0), + 98 : "2".charCodeAt(0), + 99 : "3".charCodeAt(0), + 100 : "4".charCodeAt(0), + 101 : "5".charCodeAt(0), + 102 : "6".charCodeAt(0), + 103 : "7".charCodeAt(0), + 104 : "8".charCodeAt(0), + 105 : "9".charCodeAt(0), + 106 : "*".charCodeAt(0), + 107 : "+".charCodeAt(0), + 109 : "-".charCodeAt(0), + 110 : ",".charCodeAt(0), + 111 : "/".charCodeAt(0) + }, + + + + + /* + --------------------------------------------------------------------------- + HELPER-METHODS + --------------------------------------------------------------------------- + */ + + _charCodeA : "A".charCodeAt(0), + _charCodeZ : "Z".charCodeAt(0), + _charCode0 : "0".charCodeAt(0), + _charCode9 : "9".charCodeAt(0), + + + /** + * Checks whether the keyCode represents a non printable key + * + * @type member + * @param keyCode {String} key code to check. + * @return {Boolean} Wether the keyCode represents a non printable key. + */ + _isNonPrintableKeyCode : function(keyCode) { + return this._keyCodeToIdentifierMap[keyCode] ? true : false; + }, + + + /** + * Check whether the keycode can be reliably detected in keyup/keydown events + * + * @type member + * @param keyCode {String} key code to check. + * @return {Boolean} Wether the keycode can be reliably detected in keyup/keydown events. + */ + _isIdentifiableKeyCode : function(keyCode) + { + // A-Z + if (keyCode >= this._charCodeA && keyCode <= this._charCodeZ) { + return true; + } + + // 0-9 + if (keyCode >= this._charCode0 && keyCode <= this._charCode9) { + return true; + } + + // Enter, Space, Tab, Backspace + if (this._specialCharCodeMap[keyCode]) { + return true; + } + + // Numpad + if (this._numpadToCharCode[keyCode]) { + return true; + } + + // non printable keys + if (this._isNonPrintableKeyCode(keyCode)) { + return true; + } + + return false; + }, + + + /** + * Checks whether a given string is a valid keyIdentifier + * + * @type member + * @param keyIdentifier {String} The key identifier. + * @return {Boolean} whether the given string is a valid keyIdentifier + */ + isValidKeyIdentifier : function(keyIdentifier) + { + if (this._identifierToKeyCodeMap[keyIdentifier]) { + return true; + } + + if (keyIdentifier.length != 1) { + return false; + } + + if (keyIdentifier >= "0" && keyIdentifier <= "9") { + return true; + } + + if (keyIdentifier >= "A" && keyIdentifier <= "Z") { + return true; + } + + switch(keyIdentifier) + { + case "+": + case "-": + case "*": + case "/": + return true; + + default: + return false; + } + }, + + + /** + * converts a keyboard code to the corresponding identifier + * + * @type member + * @param keyCode {Integer} key code + * @return {String} key identifier + */ + _keyCodeToIdentifier : function(keyCode) + { + if (this._isIdentifiableKeyCode(keyCode)) + { + var numPadKeyCode = this._numpadToCharCode[keyCode]; + + if (numPadKeyCode) { + return String.fromCharCode(numPadKeyCode); + } + + return (this._keyCodeToIdentifierMap[keyCode] || this._specialCharCodeMap[keyCode] || String.fromCharCode(keyCode)); + } + else + { + return "Unidentified"; + } + }, + + + /** + * converts a character code to the corresponding identifier + * + * @type member + * @param charCode {String} character code + * @return {String} key identifier + */ + _charCodeToIdentifier : function(charCode) { + return this._specialCharCodeMap[charCode] || String.fromCharCode(charCode).toUpperCase(); + }, + + + /** + * converts a key identifier back to a keycode + * + * @type member + * @param keyIdentifier {String} The key identifier to convert + * @return {Integer} keyboard code + */ + _identifierToKeyCode : function(keyIdentifier) { + return this._identifierToKeyCodeMap[keyIdentifier] || keyIdentifier.charCodeAt(0); + }, + + + + + /* + --------------------------------------------------------------------------- + IDEALIZED-KEY-HANDLER + --------------------------------------------------------------------------- + */ + + /** + * Key handler for an idealized browser. + * Runs after the browser specific key handlers have normalized the key events. + * + * @type member + * @param keyCode {String} keyboard code + * @param charCode {String} character code + * @param eventType {String} type of the event (keydown, keypress, keyup) + * @param domEvent {Element} DomEvent + * @return {void} + */ + _idealKeyHandler : function(keyCode, charCode, eventType, domEvent) + { + if (!keyCode && !charCode) { + return; + } + + var keyIdentifier; + + // Use: keyCode + if (keyCode) + { + keyIdentifier = this._keyCodeToIdentifier(keyCode); + this._keyHandler(domEvent, eventType, keyCode, charCode, keyIdentifier); + } + + // Use: charCode + else + { + keyIdentifier = this._charCodeToIdentifier(charCode); + this._keyHandler(domEvent, "keypress", keyCode, charCode, keyIdentifier); + this._keyHandler(domEvent, "keyinput", keyCode, charCode, keyIdentifier); + } + } + }, + + + + /* + ***************************************************************************** + DEFER + ***************************************************************************** + */ + + defer : function(statics, members, properties) + { + // construct invers of keyCodeToIdentifierMap + if (!members._identifierToKeyCodeMap) + { + members._identifierToKeyCodeMap = {}; + + for (var key in members._keyCodeToIdentifierMap) { + members._identifierToKeyCodeMap[members._keyCodeToIdentifierMap[key]] = parseInt(key); + } + + for (var key in members._specialCharCodeMap) { + members._identifierToKeyCodeMap[members._specialCharCodeMap[key]] = parseInt(key); + } + } + + if (qx.core.Variant.isSet("qx.client", "mshtml")) + { + members._lastUpDownType = {}; + members._charCode2KeyCode = { 13 : 13, 27 : 27 }; + } + else if (qx.core.Variant.isSet("qx.client", "gecko")) + { + members._lastUpDownType = {}; + members._keyCodeFix = { + 12 : members._identifierToKeyCode("NumLock") + }; + } + else if (qx.core.Variant.isSet("qx.client", "webkit")) + { + members._charCode2KeyCode = + { + // Safari/Webkit Mappings + 63289 : members._identifierToKeyCode("NumLock"), + 63276 : members._identifierToKeyCode("PageUp"), + 63277 : members._identifierToKeyCode("PageDown"), + 63275 : members._identifierToKeyCode("End"), + 63273 : members._identifierToKeyCode("Home"), + 63234 : members._identifierToKeyCode("Left"), + 63232 : members._identifierToKeyCode("Up"), + 63235 : members._identifierToKeyCode("Right"), + 63233 : members._identifierToKeyCode("Down"), + 63272 : members._identifierToKeyCode("Delete"), + 63302 : members._identifierToKeyCode("Insert"), + 63236 : members._identifierToKeyCode("F1"), + 63237 : members._identifierToKeyCode("F2"), + 63238 : members._identifierToKeyCode("F3"), + 63239 : members._identifierToKeyCode("F4"), + 63240 : members._identifierToKeyCode("F5"), + 63241 : members._identifierToKeyCode("F6"), + 63242 : members._identifierToKeyCode("F7"), + 63243 : members._identifierToKeyCode("F8"), + 63244 : members._identifierToKeyCode("F9"), + 63245 : members._identifierToKeyCode("F10"), + 63246 : members._identifierToKeyCode("F11"), + 63247 : members._identifierToKeyCode("F12"), + 63248 : members._identifierToKeyCode("PrintScreen"), + 3 : members._identifierToKeyCode("Enter"), + 12 : members._identifierToKeyCode("NumLock"), + 13 : members._identifierToKeyCode("Enter") + }; + } + }, + + + + + /* + ***************************************************************************** + DESTRUCTOR + ***************************************************************************** + */ + + destruct : function() + { + this._disposeFields("_lastUpDownType"); + } +}); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |