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

bargull@openlaszlo.org bargull at openlaszlo.org
Wed Mar 4 12:12:47 PST 2009


Author: bargull
Date: 2009-03-04 12:12:44 -0800 (Wed, 04 Mar 2009)
New Revision: 13162

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
Log:
Change 20090304-bargull-JfK by bargull at dell--p4--2-53 on 2009-03-04 19:03:59
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: workaround for Firefox DOM-focus bug

New Features:

Bugs Fixed: LPP-7786 (It takes two clicks to get focus into an edittext/inputtext in DHTML)

Technical Reviewer: hminsky
QA Reviewer: mdemmon
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
DOM operations on a blurring element breaks the focus in Firefox. It's possible to reproduce the same bug with plain HTML and Javascript, I've attached a testcase at the bugreport. (Henry, do you've got an account for their Bugzilla to report the issue? Otherwise I need to create an account.)
To workaround that bug, I've added a new quirk "dom_breaks_focus" which is enabled for Firefox. If the quirk is enabled and DOM operations were performed (__shown property changes from 'true' to 'false'), focus() needs to be called manually on the "__focusedSprite". This is done at the end of "__textEvent()" to ensure that "onfocus" won't be send too early.
    

Tests:
testcase from bugreport



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2009-03-04 18:34:08 UTC (rev 13161)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2009-03-04 20:12:44 UTC (rev 13162)
@@ -501,10 +501,11 @@
         return;
     }
     var eventname = 'on' + evt.type;
+    var quirks = sprite.quirks;
 
     LzMouseKernel.__sendMouseMove(evt);
 
-    if (sprite.quirks.ie_mouse_events && eventname == 'onmouseleave') {
+    if (quirks.ie_mouse_events && eventname == 'onmouseleave') {
         eventname = 'onmouseout';
     }
     if (sprite.__shown != true) {
@@ -521,6 +522,7 @@
     } else if (sprite.__shown == false) {
         return;
     }
+    var nextFocus = null;
     if (eventname == 'onfocus' || eventname == 'onmousedown') {
         if (eventname == 'onfocus') {
             LzInputTextSprite.prototype.__setglobalclickable(false);
@@ -542,7 +544,17 @@
             sprite.select();
             return;
         }
+        // check if __hide() was called
+        var shown = sprite.__shown;
         sprite.__hide();
+        if (quirks.dom_breaks_focus && (shown && ! sprite.__shown)) {
+            // workaround for Firefox bug (LPP-7786):
+            // DOM operations (appendChild, removeChild) on blurring element
+            // breaks the focus in Firefox, so we need to re-focus the
+            // element later again
+            var fsprite = LzInputTextSprite.prototype.__focusedSprite;
+            nextFocus = fsprite && fsprite.__LzInputDiv;
+        }
         if (sprite._cancelblur) {
             sprite._cancelblur = false;
             return;
@@ -556,7 +568,7 @@
         if (sprite.restrict || (sprite.multiline && view.maxlength > 0)) {
             sprite.__updatefieldsize();
             var keycode = evt.keyCode;
-            var charcode = sprite.quirks.text_event_charcode ? evt.charCode : evt.keyCode;
+            var charcode = quirks.text_event_charcode ? evt.charCode : evt.keyCode;
             // only printable characters or carriage return (modifier keys must not be active)
             var validChar = (!(evt.ctrlKey || evt.altKey) && (charcode >= 32 || keycode == 13));
             //Debug.write("charCode = %s, keyCode = %s, ctrlKey = %s, altKey = %s, shiftKey = %s", charcode, keycode, evt.ctrlKey, evt.altKey, evt.shiftKey);
@@ -571,7 +583,7 @@
                     var selsize = sprite.getSelectionSize();
                     //[TODO anba 2008-01-06] use selsize==0 when LPP-5330 is fixed
                     if (selsize <= 0) {
-                    if (sprite.quirks.text_ie_carriagereturn) {
+                    if (quirks.text_ie_carriagereturn) {
                             var val = sprite.__LzInputDiv.value.replace(sprite.____crregexp, '\n');
                         } else {
                             var val = sprite.__LzInputDiv.value;
@@ -592,7 +604,7 @@
             } else {
                 // IE and Safari do not send 'onkeypress' for function-keys,
                 // but Firefox and Opera!
-                if (sprite.quirks.keypress_function_keys) {
+                if (quirks.keypress_function_keys) {
                     var ispaste = false;
                     if (evt.ctrlKey && !evt.altKey && !evt.shiftKey) {
                         var c = String.fromCharCode(charcode);
@@ -645,6 +657,11 @@
             view.inputtextevent(eventname);
         }
     }
+
+    if (nextFocus) {
+        // re-initiate focus, see above
+        nextFocus.focus();
+    }
 }
 
 LzInputTextSprite.prototype.setEnabled = function ( val ){

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js	2009-03-04 18:34:08 UTC (rev 13161)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js	2009-03-04 20:12:44 UTC (rev 13162)
@@ -368,6 +368,7 @@
     ,preload_images: true
     ,inputtext_strips_newlines: false
     ,swf8_contextmenu: true
+    ,dom_breaks_focus: false
 }
 
 LzSprite.prototype.capabilities = {
@@ -527,6 +528,8 @@
             quirks['text_event_charcode'] = false;
             quirks['textdeco_on_textdiv'] = true;
         } else if (browser.isFirefox) {
+            // DOM operations on blurring element break focus (LPP-7786)
+            quirks['dom_breaks_focus'] = true;
             if (browser.version < 2) {
                 // see http://groups.google.ca/group/netscape.public.mozilla.dom/browse_thread/thread/821271ca11a1bdbf/46c87b49c026246f?lnk=st&q=+focus+nsIAutoCompletePopup+selectedIndex&rnum=1
                 quirks['firefox_autocomplete_bug'] = true;



More information about the Laszlo-checkins mailing list