[Laszlo-checkins] r14287 - in openlaszlo/branches/4.2: WEB-INF/lps/lfc/kernel/swf WEB-INF/lps/lfc/kernel/swf9 WEB-INF/lps/lfc/services lps/includes/source

ptw@openlaszlo.org ptw at openlaszlo.org
Tue Jul 7 19:25:54 PDT 2009


Author: ptw
Date: 2009-07-07 19:25:49 -0700 (Tue, 07 Jul 2009)
New Revision: 14287

Modified:
   openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzKeyboardKernel.as
   openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
   openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
   openlaszlo/branches/4.2/WEB-INF/lps/lfc/services/LzKeys.lzs
   openlaszlo/branches/4.2/lps/includes/source/embednew.js
Log:
Change 20090707-ptw-J by ptw at dueling-banjos.home on 2009-07-07 20:37:28 EDT
    in /Users/ptw/OpenLaszlo/4.2
    for http://svn.openlaszlo.org/openlaszlo/branches/4.2

Summary: Part 1 of fixing stuck keys when IE loses focus

Bugs Fixed: LPP-8283 Alt tab issue when switching tasks in IE7/Win

Technical Reviewer: max (pending)
QA Reviewer: hminsky (pending)

Details:

    swf/LzSprite: Create a quirk for ActiveX which for some reason seems
    to swallow browser focus events, preventing us from using the
    solution that works for all other platforms of releasing all keys
    when the the browser window regains focus.

    swf/LzKeyboardKernel: Create a Selection listener for focus change,
    call __allKeysUp when focus moves to or from the app

    swf9/LFCApplication: For ActiveX embedding, create a Stage
    listener for ACTIVATE, call __allKeysUp when the app is activated.

    LzKeys, embednew: Add some debug info

Tests:
    Still doesn't pass the test case, but it will remove the stuck key
    if you click on an input element



Modified: openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzKeyboardKernel.as
===================================================================
--- openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzKeyboardKernel.as	2009-07-08 02:24:56 UTC (rev 14286)
+++ openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzKeyboardKernel.as	2009-07-08 02:25:49 UTC (rev 14287)
@@ -47,10 +47,32 @@
     ,__codes: {16: 'shift', 17: 'control', 18: 'alt'}
     ,__callback: null
     ,__scope: null
+    ,__listeneradded: false
     ,setCallback: function (scope, funcname) {
         this.__scope = scope;
         this.__callback = funcname;
-    }    
+        if (LzSprite.prototype.quirks.swf_swallows_focus_events) {
+          // Enable focus on sprite root so we can receive onfocus
+          // events in IE when the browser window does
+          if (this.__listeneradded == false) {
+            var listener = {
+            onSetFocus: function (o, n) {
+                if ((o == null) || (n == null)) {
+                  var how = '';
+//                   if ($debug) {
+//                     how = Debug.formatToString("focus %#w -> %#w", o, n);
+//                   }
+                  lz.Keys.__allKeysUp(how);
+//                 } else if ($debug) {
+//                   Debug.debug("focus %#w -> %#w", o, n);
+                }
+              }
+            }
+            Selection.addListener(listener);
+            this.__listeneradded = true;
+          }
+        }
+    }
     // Called by lz.embed when the browser window regains focus
     ,__allKeysUp: function () {
         var delta = {};

Modified: openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
===================================================================
--- openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzSprite.as	2009-07-08 02:24:56 UTC (rev 14286)
+++ openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf/LzSprite.as	2009-07-08 02:25:49 UTC (rev 14287)
@@ -24,7 +24,14 @@
             is = _root.attachMovie('empty', 'spriteroot', 1000);
         }
         this.__LZmovieClipRef = is;
-        
+        if (LzSprite.prototype.quirks.swf_swallows_focus_events) {
+          is.attachMovie( LzSprite.prototype.__LZclickregion, "$mcB",
+                                        LzSprite.prototype.BUTTON_DEPTH, {_width: 0, _height: 0} );
+          if (debug) {
+              is.$mcB._dbg_name = 'default focus';
+          }
+          Selection.setFocus(is.$mcB);
+        }
         this.__LZsvdepth = 1;
     } else {
         this.__LZdepth = newowner.immediateparent.sprite.__LZsvdepth++;
@@ -46,6 +53,19 @@
                               ys, this.y)
 };
 
+LzSprite.prototype.quirks = {
+    swf_swallows_focus_events: false
+}
+
+LzSprite.prototype.__updateQuirks = function () {
+    var quirks = this.quirks;
+    if (System.capabilities.os.indexOf('Win') == 0) {
+        quirks.swf_swallows_focus_events = true;
+    }
+}
+
+LzSprite.prototype.__updateQuirks();
+
 LzSprite.prototype.capabilities = {
     rotation: true
     // Avoid scaling canvas to percentage values - SWF already scales the viewport size, so take window size literally to avoid scaling twice

Modified: openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
===================================================================
--- openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as	2009-07-08 02:24:56 UTC (rev 14286)
+++ openlaszlo/branches/4.2/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as	2009-07-08 02:25:49 UTC (rev 14287)
@@ -65,7 +65,11 @@
 
         stage.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
         stage.addEventListener(KeyboardEvent.KEY_UP,reportKeyUp);
+
         if (Capabilities.playerType == "ActiveX") {
+            // Workaround for ActiveX control swallowing browser focus events
+            stage.addEventListener(Event.ACTIVATE,allKeysUp);
+
             // workaround for flash player bug FP-1355
             LFCApplication.textfieldTabEnabled = true;
             stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, preventFocusChange);
@@ -125,6 +129,10 @@
         LzKeyboardKernel.__keyboardEvent(event, 'onkeydown');
     }
 
+    function allKeysUp(event:Event):void {
+        lz.Keys.__allKeysUp('flash activate');
+    }
+
     function preventFocusChange(event:FocusEvent):void {
         if (event.keyCode == 9) {
             event.preventDefault();

Modified: openlaszlo/branches/4.2/WEB-INF/lps/lfc/services/LzKeys.lzs
===================================================================
--- openlaszlo/branches/4.2/WEB-INF/lps/lfc/services/LzKeys.lzs	2009-07-08 02:24:56 UTC (rev 14286)
+++ openlaszlo/branches/4.2/WEB-INF/lps/lfc/services/LzKeys.lzs	2009-07-08 02:25:49 UTC (rev 14287)
@@ -142,7 +142,10 @@
      * Trampoline so we can call from lz.embed
      * @access private
      */
-    function __allKeysUp ():void {
+    function __allKeysUp (how='unknown'):void {
+//       if ($debug) {
+//         Debug.debug("[%6.2f] __allKeysUp: %s", (new Date).getTime() % 1000000, how);
+//       }
       LzKeyboardKernel.__allKeysUp();
     }
 

Modified: openlaszlo/branches/4.2/lps/includes/source/embednew.js
===================================================================
--- openlaszlo/branches/4.2/lps/includes/source/embednew.js	2009-07-08 02:24:56 UTC (rev 14286)
+++ openlaszlo/branches/4.2/lps/includes/source/embednew.js	2009-07-08 02:25:49 UTC (rev 14287)
@@ -644,18 +644,18 @@
         if (d != null) this.callMethod("lz.Keys.__mousewheelEvent(" + d + ")"); 
     }
     ,/** @access private */
-    _gotFocus: function() {
-        lz.embed._broadcastMethod('_sendAllKeysUp');
+    _gotFocus: function(how='unknown') {
+        lz.embed._broadcastMethod('_sendAllKeysUp', how);
     }
     ,/** @access private */
-    _sendAllKeysUpSWF: function () {
-        this.callMethod("lz.Keys.__allKeysUp()");
+    _sendAllKeysUpSWF: function (how='unknown') {
+        this.callMethod("lz.Keys.__allKeysUp(" + how + ")");
     }
     ,/** @access private */
-    _sendAllKeysUpDHTML: function () {
+    _sendAllKeysUpDHTML: function (how='unknown') {
         // How to deal with multiple DHTML apps on a page?
-        if (LzKeyboardKernel && LzKeyboardKernel['__allKeysUp']) {
-            LzKeyboardKernel.__allKeysUp();
+        if (lz['Keys'] && lz.Keys['__allKeysUp']) {
+            lz.Keys.__allKeysUp(how);
         }
     }
     ,/** @access private */
@@ -783,9 +783,11 @@
 lz.embed.attachEventHandler(window, 'beforeunload', lz.embed, '_cleanupHandlers');
 
 // Notice that you got focus
-lz.embed.attachEventHandler(window, 'focus', lz.embed, '_gotFocus');
 if (lz.embed.browser.isIE) {
-  lz.embed.attachEventHandler(window, 'activate', lz.embed, '_gotFocus');
+  // attachEventHandler does not work for IE?
+  document.onfocusin = function () { lz.embed._gotFocus('document focusin'); }
+} else {
+  lz.embed.attachEventHandler(window, 'focus', lz.embed, '_gotFocus');
 }
 
 // for backward compatibility



More information about the Laszlo-checkins mailing list