[Laszlo-checkins] r12785 - in openlaszlo/trunk: WEB-INF/lps/lfc/kernel/dhtml lps/components/incubator lps/components/incubator/test

max@openlaszlo.org max at openlaszlo.org
Sat Feb 7 06:53:18 PST 2009


Author: max
Date: 2009-02-07 06:53:13 -0800 (Sat, 07 Feb 2009)
New Revision: 12785

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
   openlaszlo/trunk/lps/components/incubator/scrolledittext.lzx
   openlaszlo/trunk/lps/components/incubator/test/scrolledittext-test.lzx
Log:
Change 20090206-maxcarlson-Q by maxcarlson at Bank.local on 2009-02-06 06:43:58 PST
    in /Users/maxcarlson/openlaszlo/trunk-clean
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Fix runtime setMultiline() and scrolledittext sizing in DHTML

Bugs Fixed: LPP-6580  scrolledittext doesn't work in 4.1 (partial), LPP-7726 - DHTML: setMultiline() has no effect after init time

Technical Reviewer: ptw
QA Reviewer: hminsky

Documentation: LzInputTextSprite - Refactor inputtext div initialization to separate method, call when creating an inputtext, or when the multiline state changes in setMultiline().  Update the field size metrics onkeypress.

scrolledittext - Use constraints instead of applyConstraintMethod() for maintaining height/width.

scrolledittext-test - Uncomment second scrolledittext, use default scrollbar class to test functionality.

Details: This makes scrolledittext begin working in DHTML, with some issues.  Sometimes, the scroll attribute assertion is triggered, and maxscroll doesn't seem to be tall enough.  Also, typing carriage returns into the inputtext doesn't cause it to automatically scroll down when typing into the bottom of the field like it does with native scrollbars - the scrollTop/scroll doesn't change.  I'm not sure how to fix this because AFAIK there's no way to accurately figure out the cursor pixel offset when typing and set it manually - maybe Tucker has a clue...

Tests: scrolledittext-test runs as before in swf8/9, and now (almost) works in DHTML.



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2009-02-07 14:51:36 UTC (rev 12784)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzInputTextSprite.js	2009-02-07 14:53:13 UTC (rev 12785)
@@ -44,34 +44,18 @@
 LzInputTextSprite.prototype.__createInputText = function(t) {
     if (this.__LzInputDiv) return;
     //Debug.write('Multiline', this, this.multiline, this.owner.multiline);
-    if (this.owner && this.owner.password) {
-        this.__LzInputDiv = document.createElement('input');
-        lz.embed.__setAttr(this.__LzInputDiv, 'type', 'password');
-    } else if (this.owner && this.owner.multiline) {
-        this.__LzInputDiv = document.createElement('textarea');
-    } else {    
-        this.__LzInputDiv = document.createElement('input');
-        lz.embed.__setAttr(this.__LzInputDiv, 'type', 'text');
-    }
-    if (this.quirks.firefox_autocomplete_bug) {
-        lz.embed.__setAttr(this.__LzInputDiv, 'autocomplete', 'off');
-    }
-    this.__LzInputDiv.owner = this;
-    if (this.quirks.emulate_flash_font_metrics) {
-        if (this.owner && this.owner.multiline) {
-            this.__LzInputDiv.className = 'lzswfinputtextmultiline';
-        } else {
-            this.____hpadding = 1;
-            this.__LzInputDiv.className = 'lzswfinputtext';
-        }    
-    } else {    
-        this.__LzInputDiv.className = 'lzinputtext';
-    }    
+    var type = '';
     if (this.owner) {
-        lz.embed.__setAttr(this.__LzInputDiv, 'name', this.owner.name);
+        if (this.owner.password) {
+            type = 'password'
+        } else if (this.owner.multiline) {
+            type = 'multiline'
+        }
     }
+    this.__createInputDiv(type);
     if (t == null) t = '';
     lz.embed.__setAttr(this.__LzInputDiv, 'value', t);
+
     if (this.quirks.fix_clickable) {
         if (this.quirks.fix_ie_clickable) {
             this.__LZinputclickdiv = document.createElement('img');
@@ -93,15 +77,75 @@
     }    
     this.__LZdiv.appendChild(this.__LzInputDiv);
 
-    if (this.quirks['inputtext_size_includes_margin']) {
-        this.____hpadding = 0;
-    }
-
-    this.scrolldiv = this.__LzInputDiv;
     //Debug.write(this.__LzInputDiv.style);
     this.__setTextEvents(true);
 }
 
+LzInputTextSprite.prototype.__createInputDiv = function(type) {
+    if (type === 'password') {
+        this.__LzInputDiv = document.createElement('input');
+        lz.embed.__setAttr(this.__LzInputDiv, 'type', 'password');
+    } else if (type === 'multiline') {
+        this.__LzInputDiv = document.createElement('textarea');
+    } else {    
+        this.__LzInputDiv = document.createElement('input');
+        lz.embed.__setAttr(this.__LzInputDiv, 'type', 'text');
+    }
+    if (this.quirks.firefox_autocomplete_bug) {
+        lz.embed.__setAttr(this.__LzInputDiv, 'autocomplete', 'off');
+    }
+    this.__LzInputDiv.owner = this;
+    if (this.quirks.emulate_flash_font_metrics) {
+        if (this.owner && this.owner.multiline) {
+            // Should reflect CSS defaults in LzSprite.js
+            this.____hpadding = 2;
+            this.__LzInputDiv.className = 'lzswfinputtextmultiline';
+        } else {
+            this.____hpadding = 1;
+            this.__LzInputDiv.className = 'lzswfinputtext';
+        }    
+        if (this.quirks['inputtext_size_includes_margin']) {
+            this.____hpadding = 0;
+        }
+    } else {    
+        this.__LzInputDiv.className = 'lzinputtext';
+    }    
+    if (this.owner) {
+        lz.embed.__setAttr(this.__LzInputDiv, 'name', this.owner.name);
+    }
+    this.scrolldiv = this.__LzInputDiv;
+}
+
+LzInputTextSprite.prototype.setMultiline = function(ml) {
+    var oldval = this.multiline;
+    this.multiline = ml == true;
+    if (oldval != null && this.multiline != oldval) {
+        // cache original values
+        var style = this.__LzInputDiv.style;
+        var scrollleft = this.__LzInputDiv.scrollLeft;
+        var scrolltop = this.__LzInputDiv.scrollTop;
+
+        // destroy old element
+        this.__setTextEvents(false);
+        this.__discardElement(this.__LzInputDiv);
+
+        this.__createInputDiv(ml ? 'multiline' : '');
+
+        // must set before appending
+        lz.embed.__setAttr(this.__LzInputDiv, 'style', style);
+        this.__LZdiv.appendChild(this.__LzInputDiv);
+        this.__LzInputDiv.style.overflow = ml ? 'hidden' : 'visible';
+        this.__LzInputDiv.scrollLeft = scrollleft;
+        this.__LzInputDiv.scrollTop = scrolltop;
+
+        // restore text events
+        this.__setTextEvents(true);
+
+        // restore text content
+        this.setText(this.text, true);
+    }
+}
+
 // called from the scope of __LZinputclickdiv
 LzInputTextSprite.prototype.__handlemouse = function(e) {
     if (this.owner.selectable != true) return;
@@ -494,6 +538,7 @@
 
     if (eventname == 'onkeypress') {
         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;
             // only printable characters or carriage return (modifier keys must not be active)

Modified: openlaszlo/trunk/lps/components/incubator/scrolledittext.lzx
===================================================================
--- openlaszlo/trunk/lps/components/incubator/scrolledittext.lzx	2009-02-07 14:51:36 UTC (rev 12784)
+++ openlaszlo/trunk/lps/components/incubator/scrolledittext.lzx	2009-02-07 14:53:13 UTC (rev 12785)
@@ -14,8 +14,11 @@
               height="${parent.height-parent.border*2}" 
               x="${parent.border}" y="${parent.border}"/>
 
-        <_newinternalinputtext name="inp" x="${parent.border}" 
-            y="${parent.border}">
+        <_newinternalinputtext name="inp" 
+            x="${parent.border}" 
+            y="${parent.border}" 
+            height="${parent.height - parent.border * 2}" 
+            width="${parent.width - parent.vscrollwidth - parent.border*2}">
             <!-- Supplied by lztext now
                 attribute name="lineheight"
                        value="${this.getTextHeight()/this.getMaxScroll()}"/-->
@@ -37,19 +40,6 @@
                 }
             </setter>
             
-            <method name="_constainWidth" args="IGNORE_THIS_ARG">
-                this.setAttribute("width", parent.width - parent.vscrollwidth - parent.border*2 );
-            </method>
-            
-            <method name="_constainHeight" args="IGNORE_THIS_ARG">
-                this.setAttribute("height", parent.height - parent.border*2 );
-            </method>
-            
-            <handler name="oninit">
-                this.applyConstraintMethod('_constainWidth', [parent, "width", parent, "vscrollwidth", parent, "border"]);
-                this.applyConstraintMethod('_constainHeight', [parent, "height", parent, "border"]);
-            </handler>
-            
             <handler name="onscroll" args="IGNORE_THIS_ARG">
                 this.setAttribute('pos', -this.lineheight * (this.scroll - 1));
             </handler>

Modified: openlaszlo/trunk/lps/components/incubator/test/scrolledittext-test.lzx
===================================================================
--- openlaszlo/trunk/lps/components/incubator/test/scrolledittext-test.lzx	2009-02-07 14:51:36 UTC (rev 12784)
+++ openlaszlo/trunk/lps/components/incubator/test/scrolledittext-test.lzx	2009-02-07 14:53:13 UTC (rev 12785)
@@ -36,8 +36,7 @@
         </button>
     </view>
 
-        <!--scrolledittext x="20" y="20" width="300" height="200" vscrollbarclassname="newvscrollbar">this is the fun scrolledittext</scrolledittext-->
-
+    <scrolledittext x="20" y="20" width="300" height="200">this is the fun scrolledittext with a default scrollbar</scrolledittext>
 </canvas>
 <!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
 * Copyright 2006-2007, 2009 Laszlo Systems, Inc. All Rights Reserved.               *



More information about the Laszlo-checkins mailing list