[Laszlo-checkins] r14043 - openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml

bargull@openlaszlo.org bargull at openlaszlo.org
Tue Jun 2 10:34:33 PDT 2009


Author: bargull
Date: 2009-06-02 10:34:30 -0700 (Tue, 02 Jun 2009)
New Revision: 14043

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
Log:
Change 20090602-bargull-GPN by bargull at dell--p4--2-53 on 2009-06-02 15:54:52
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: DHTML: add "updateControlKeys" to LzKeyboardKernel

New Features:

Bugs Fixed: LPP-8218 - DHTML: issues with contextmenu onmenuopen, dragging (partial)

Technical Reviewer: max, ptw
QA Reviewer: hqm
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
Call "updateControlKeys()" instead of "__keyboardEvent()" for mouse-events. 
Set "cancelBubble" and "returnValue" after invoking "updateControlKeys()" to mimic old behaviour (this is actually wrong, see LPP-8200, but reduces testing effort right now). "keyCode" is set to 0 for mouse-events in IE, Opera, Safari, so you only need to test for keyCode==0 (Firefox is irrelevant in this case, because it sets keyCode to `undefined` for mouse-events). 

    

Tests:
test/lfc/legals/keyboardandmouse.lzx?lzr=dhtml still works as expected




Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js	2009-06-02 14:17:34 UTC (rev 14042)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js	2009-06-02 17:34:30 UTC (rev 14043)
@@ -10,59 +10,44 @@
   */
 
 // Receives keyboard events from the runtime
-var LzKeyboardKernel = { 
+var LzKeyboardKernel = {
     __downKeysHash: {alt: false, control: false, shift: false, meta: false}
     ,__keyCodes: {}
-    ,__keyboardEvent: function ( e ){   
+    ,__keyboardEvent: function ( e ){
         if (!e) e = window.event;
         var delta = {};
         var dirty = false;
         var k = e['keyCode'];
-        var t = e.type; 
+        var t = e.type;
         var dh = LzKeyboardKernel.__downKeysHash;
-        var kcodes = LzKeyboardKernel.__keyCodes;
-        var quirks = LzSprite.prototype.quirks;
         // TODO: really, all control characters should be skipped...
         // skip shift, ctrl, option keys to prevent duplicate sending - see LPP-4267
         if (k >= 0 && k != 16 && k != 17 && k != 18 && k != 224) {
             // TODO: add mapping to flash character codes?
             var s = String.fromCharCode(k).toLowerCase();
-            kcodes[s] = k;
+            LzKeyboardKernel.__keyCodes[s] = k;
             if (t == 'keyup') {
                 if (dh[s] != false) {
                     delta[s] = false;
                     dirty = true;
-                }    
+                }
                 dh[s] = false;
             } else if (t == 'keydown') {
                 if (dh[s] != true) {
-                    delta[s] = true;    
+                    delta[s] = true;
                     dirty = true;
-                }    
+                }
                 dh[s] = true;
-            }    
-        }    
-        var alt = e['altKey'];
-        if (dh['alt'] != alt) {
-            delta['alt'] = alt;
-            dirty = true;
-            if (quirks['alt_key_sends_control']) {
-                delta['control'] = delta['alt'];
             }
-        }    
-        var ctrl = e['ctrlKey']// || e['metaKey'];
-        if (dh['control'] != ctrl) {
-            delta['control'] = ctrl;
+        }
+
+        if (LzKeyboardKernel.__updateControlKeys(e, delta)) {
             dirty = true;
-        }    
-        var shift = e['shiftKey'];
-        if (dh['shift'] != shift) {
-            delta['shift'] = shift;
-            dirty = true;
-        }    
+        }
+
         var stuck;
         var meta = e['metaKey'];
-        if (quirks['detectstuckkeys']) {
+        if (LzSprite.prototype.quirks['detectstuckkeys']) {
             // see LPP-8210
             if (dh['meta'] != meta) {
                 // look for stuck keys
@@ -77,23 +62,26 @@
                 }
             }
         }
+        dh['meta'] = meta;
 
-        dh['alt'] = alt;
-        dh['control'] = ctrl;
-        dh['shift'] = shift;
-        dh['meta'] = meta;
-        if (dirty && LzKeyboardKernel.__scope && LzKeyboardKernel.__scope[LzKeyboardKernel.__callback]) {
-            //console.log(t, s, k, delta, e.metaKey, e.ctrlKey, dh);
-            if (stuck) {
-                //console.log('stuck key', key, keycode);
-                var keycode = kcodes[stuck];
-                var fakedelta = {}
-                fakedelta[key] = false;
-                LzKeyboardKernel.__scope[LzKeyboardKernel.__callback](fakedelta, keycode, 'onkeyup');
+        if (dirty) {
+            var scope = LzKeyboardKernel.__scope;
+            var callback = LzKeyboardKernel.__callback;
+            if (scope && scope[callback]) {
+                //console.log(t, s, k, delta, e.metaKey, e.ctrlKey, dh);
+                if (stuck) {
+                    // console.log('stuck key', key, keycode);
+                    var keycode = LzKeyboardKernel.__keyCodes[stuck];
+                    var fakedelta = {};
+                    // FIXME: [20090602 anba] 'key' seems to be a typo, should it be 'stuck'?
+                    fakedelta[key] = false;
+                    scope[callback](fakedelta, keycode, 'onkeyup');
+                }
+
+                scope[callback](delta, k, 'on' + t);
             }
-            LzKeyboardKernel.__scope[LzKeyboardKernel.__callback](delta, k, 'on' + t);
-        } 
-        
+        }
+
         // cancel bubbling
         if (k >= 0) {
             if (k == 9) {
@@ -107,11 +95,53 @@
                 e.cancelBubble = true;
                 e.returnValue = false;
                 return false;
-            }    
-        }    
+            }
+        }
         //Debug.write('downKeysHash', t, k, dh, delta);
     }
+    ,__updateControlKeys: function (e, delta) {
+        var dh = LzKeyboardKernel.__downKeysHash;
+        var dirty = false;
+        if (delta) {
+            var send = false;
+        } else {
+            // Called with mouse-event, see LzSprite, LzMouseKernel
+            delta = {};
+            var send = true;
+        }
+        var alt = e['altKey'];
+        if (dh['alt'] != alt) {
+            delta['alt'] = alt;
+            dirty = true;
+            if (LzSprite.prototype.quirks['alt_key_sends_control']) {
+                delta['control'] = delta['alt'];
+            }
+        }
+        var ctrl = e['ctrlKey'];
+        if (dh['control'] != ctrl) {
+            delta['control'] = ctrl;
+            dirty = true;
+        }
+        var shift = e['shiftKey'];
+        if (dh['shift'] != shift) {
+            delta['shift'] = shift;
+            dirty = true;
+        }
 
+        dh['alt'] = alt;
+        dh['control'] = ctrl;
+        dh['shift'] = shift;
+
+        if (send && dirty) {
+            var scope = LzKeyboardKernel.__scope;
+            var callback = LzKeyboardKernel.__callback;
+            if (scope && scope[callback]) {
+                scope[callback](delta, 0, 'on' + e.type);
+            }
+        }
+
+        return dirty;
+    }
     ,__callback: null
     ,__scope: null
     ,__cancelKeys: true
@@ -119,7 +149,7 @@
     ,setCallback: function (scope, keyboardcallback) {
         this.__scope = scope;
         this.__callback = keyboardcallback;
-    }    
+    }
     ,setKeyboardControl: function (dhtmlKeyboardControl, force) {
         if (! force && LzKeyboardKernel.__lockFocus) {
             dhtmlKeyboardControl = true;
@@ -130,9 +160,10 @@
             //console.log('setKeyboardControl' + dhtmlKeyboardControl);
             handler = LzKeyboardKernel.__keyboardEvent;
         }
-        if ( LzInputTextSprite.prototype.__focusedSprite ) {
+        var lzinputproto = LzInputTextSprite.prototype;
+        if (lzinputproto.__focusedSprite) {
             // hide any focused inputtexts
-            LzInputTextSprite.prototype.__focusedSprite.__hideIfNotFocused();
+            lzinputproto.__hideIfNotFocused();
         }
         // can't use lz.embed.attachEventHandler because we need to cancel events selectively
         if (LzSprite.prototype.quirks.keyboardlistentotop) {

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js	2009-06-02 14:17:34 UTC (rev 14042)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzMouseKernel.js	2009-06-02 17:34:30 UTC (rev 14043)
@@ -26,20 +26,30 @@
             var targ = e.target; 
         }
         var eventname = 'on' + e.type;
-        if (window['LzKeyboardKernel'] && LzKeyboardKernel['__keyboardEvent']) LzKeyboardKernel.__keyboardEvent(e);
-        if (window['LzInputTextSprite'] && LzInputTextSprite.prototype.__lastshown != null) {
+
+        // send option/shift/ctrl key events
+        if (window['LzKeyboardKernel'] && LzKeyboardKernel['__updateControlKeys']) {
+            LzKeyboardKernel.__updateControlKeys(e);
+
+            // FIXME: [20090602 anba] this prevents text selection, see LPP-8200
+            if (LzKeyboardKernel.__cancelKeys && e.keyCode == 0) {
+                e.cancelBubble = true;
+                e.returnValue = false;
+            }
+        }
+
+        var lzinputproto = window['LzInputTextSprite'] && LzInputTextSprite.prototype;
+        if (lzinputproto && lzinputproto.__lastshown != null) {
             if (LzSprite.prototype.quirks.fix_ie_clickable) {
-                LzInputTextSprite.prototype.__lastshown.__hideIfNotFocused(eventname, targ);
+                lzinputproto.__hideIfNotFocused(eventname, targ);
             } else if (eventname != 'onmousemove') {
-                LzInputTextSprite.prototype.__lastshown.__hideIfNotFocused();
+                lzinputproto.__hideIfNotFocused();
             }
         }
+
         if (eventname == 'onmousemove') {
             LzMouseKernel.__sendMouseMove(e);
-            return;
-        }    
-
-        if (eventname == 'oncontextmenu' || (e.button == 2 && eventname == 'onmouseup') ) {
+        } else if (eventname == 'oncontextmenu' || (e.button == 2 && eventname == 'onmouseup') ) {
             if (targ) {
                 // update mouse position, required for Safari
                 LzMouseKernel.__sendMouseMove(e);
@@ -72,7 +82,7 @@
     // handles global mouseup events
     ,__mouseupEvent: function (e) {
         if (LzMouseKernel.__lastMouseDown != null) {
-            // call mouseup on the sprite that got the last mouse down  
+            // call mouseup on the sprite that got the last mouse down
             LzMouseKernel.__lastMouseDown.__globalmouseup(e);
         } else {
             LzMouseKernel.__mouseEvent(e);

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js	2009-06-02 14:17:34 UTC (rev 14042)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js	2009-06-02 17:34:30 UTC (rev 14043)
@@ -497,6 +497,7 @@
     ,dom_breaks_focus: false
     ,inputtext_anonymous_div: false
     ,clipped_scrollbar_causes_display_turd: false
+    ,detectstuckkeys: false
 }
 
 LzSprite.prototype.capabilities = {
@@ -520,7 +521,6 @@
     ,proxypolicy: false
     ,linescrolling: false
     ,disableglobalfocustrap: true
-    ,detectstuckkeys: false
 }
 
 LzSprite.prototype.__updateQuirks = function () {
@@ -1164,9 +1164,17 @@
         var eventname = e;
         e = {};
     } else {
+        var eventname = 'on' + e.type;
         // send option/shift/ctrl key events
-        var eventname = 'on' + e.type;
-        if (LzKeyboardKernel && LzKeyboardKernel['__keyboardEvent']) LzKeyboardKernel.__keyboardEvent(e);
+        if (LzKeyboardKernel && LzKeyboardKernel['__updateControlKeys']) {
+            LzKeyboardKernel.__updateControlKeys(e);
+
+            // FIXME: [20090602 anba] this prevents text selection, see LPP-8200
+            if (LzKeyboardKernel.__cancelKeys && e.keyCode == 0) {
+                e.cancelBubble = true;
+                e.returnValue = false;
+            }
+        }
     }
 
     if (this.quirks.ie_mouse_events) {



More information about the Laszlo-checkins mailing list