History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: LPP-5220
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: -- --
Assignee: Max Carlson
Reporter: André Bargull
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenLaszlo

"span" and "div" (as text) break text-size cache

Created: 08/Dec/07 03:24 PM   Updated: 03/Jan/08 06:40 PM
Component/s: Kernel - DHTML
Affects Version/s: RingDing (4.1)
Fix Version/s: RingDing (4.1)

Time Tracking:
Not Specified

Severity: Minor
Fixed in Change#: 7,721
Runtime: N/A
Fix in hand: False


 Description  « Hide
"span" resp. "div" is used as a key for the textsizecache to identify the style-span/-div. That way, we cannot use "span"/"div" as a string.

testcase: see "LPP-5176.tar" at LPP-5176.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Max Carlson - 01/Jan/08 08:56 PM
I'm not sure why, but if I change the testcase to use any other string, e.g. 'bar' it still blows up. After looking at the textsizecache code, I can't see why 'div/span' would be treated like any other string - can you elaborate with some line numbers? Thanks!

Here's the testcase I used (based on LPP-5176):

<canvas width="500" height="500" debug="true" layout="axis:y; spacing:10" >
 
    <text id="myCounter" fontsize="14">
   <attribute name="my_count" value="0" />
   <attribute name="mydel" value="$once{new LzDelegate(this, 'updateCount')}" />
   <method name="updateCount">
   var sCount = "" + (++my_count);
  
   try {
   this.setText( sCount );
   } catch (e) {
   Debug.warn(e);
   Debug.debug(this.sprite._sizecache.counter);
  
   return;
   }
  
LzTimer.addTimer( this.mydel, 1 );
   </method>
    </text>
 
    <button text="count" onclick="myCounter.updateCount()" />
    
    <button text="kill timer" onclick="myCounter.mydel = null" />
    
    <button text="'span' is bad" onclick="myCounter.setText('bar')" />

</canvas>

André Bargull - 02/Jan/08 09:28 AM
Sure Max, here you go:

LzTextSprite.prototype.getTextSize = function (string, ignorewidth) {
    [...]
    var _textsizecache = this._sizecache[style];//get cache for current style
    if (! _textsizecache[string]) {//check whether we already computed width/height for the current text, note we're using "_textsizecache" everywhere!
    [...]
        if (this.quirks['text_measurement_use_insertadjacenthtml']) {
            [...]
            var tagname = 'span';
            var mdiv = _textsizecache[tagname];//oops, saving the HTML-span in the "_textsizecache"-object!
            if (mdiv == null) {
            [...]
        } else {
            var tagname = this.multiline ? 'div' : 'span';
            var mdiv = _textsizecache[tagname];//same "oops" as above
            if (mdiv == null) {
            [...]
        }
        [...]
        _textsizecache[string] = size;//now we may overwrite the HTML-span/div with the size-object...
        this._sizecache.counter++;
    }
    return _textsizecache[string];
}

Max Carlson - 03/Jan/08 06:40 PM
Author: max
Date: 2008-01-03 18:32:28 -0800 (Thu, 03 Jan 2008)
New Revision: 7721

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
Log:
Change 20080103-maxcarlson-c by maxcarlson@Roboto.lan on 2008-01-03 00:14:38 PST
    in /Users/maxcarlson/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Fix issue with 'div' and 'span' clobbering text size caches

New Features:

Bugs Fixed: LPP-5220 - "span" and "div" (as text) break text-size cache

Technical Reviewer: a.bargull@intensis.de
QA Reviewer: promanik
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details: Clear contents of lzTextSizeCache div when cache size overflows. Store measuring div/span as 'lzdiv~~~' + span/div instead of 'span/div'
    

Tests: See LPP-5220.



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js 2008-01-03 20:09:35 UTC (rev 7720)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/dhtml/LzTextSprite.js 2008-01-04 02:32:28 UTC (rev 7721)
@@ -1,7 +1,7 @@
 /**
   * LzTextSprite.js
   *
- * @copyright Copyright 2007 Laszlo Systems, Inc. All Rights Reserved.
+ * @copyright Copyright 2007-2008 Laszlo Systems, Inc. All Rights Reserved.
   * Use is subject to license terms.
   *
   * @topic Kernel
@@ -267,15 +267,18 @@
         this._styledirty = false;
     }
 
+ var root = document.getElementById('lzTextSizeCache');
+
     // Empty the cache when full, but do not reset the counter because
     // IE holds onto the object.
     if (this._sizecache.counter > 0 && this._sizecache.counter % this.__sizecacheupperbound == 0) {
         this._sizecache = {counter: this._sizecache.counter};
+ if (root) {
+ root.innerHTML = '';
+ }
     }
     if (this._sizecache[style] == null) this._sizecache[style] = {};
 
- var root = document.getElementById('lzTextSizeCache');
-
     if (! root) {
         root = document.createElement('div');
         Lz.__setAttr(root, 'id', 'lzTextSizeCache');
@@ -292,7 +295,7 @@
                 string = string.replace(this.inner_html_strips_newlines_re, '<br />');
             }
             var tagname = 'span';
- var mdiv = _textsizecache[tagname];
+ var mdiv = _textsizecache['lzdiv~~~' + tagname];
             if (mdiv == null) {
                 var html = '<' + tagname + ' id="testSpan' + this._sizecache.counter + '"';
                 html += ' style="' + style + '">';
@@ -301,7 +304,7 @@
                 root.insertAdjacentHTML('beforeEnd', html);
 
                 mdiv = document.all['testSpan' + this._sizecache.counter];
- _textsizecache[tagname] = mdiv;
+ _textsizecache['lzdiv~~~' + tagname] = mdiv;
             }
         } else {
             if (this.__LzInputDiv == null) {
@@ -310,16 +313,16 @@
                 }
             }
             var tagname = this.multiline ? 'div' : 'span';
- var mdiv = _textsizecache[tagname];
+ var mdiv = _textsizecache['lzdiv~~~' + tagname];
             if (mdiv == null) {
                 mdiv = document.createElement(tagname);
                 Lz.__setAttr(mdiv, 'style', style);
                 root.appendChild(mdiv);
- _textsizecache[tagname] = mdiv;
+ _textsizecache['lzdiv~~~' + tagname] = mdiv;
             }
         }
         if (this.quirks.ie_leak_prevention) {
- LzTextSprite.prototype._sizedomcache[tagname + style] = mdiv;
+ LzTextSprite.prototype._sizedomcache['lzdiv~~~' + tagname + style] = mdiv;
         }
 
         mdiv.innerHTML = string;


_______________________________________________
Laszlo-checkins mailing list
Laszlo-checkins@openlaszlo.org
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins