|
|
|
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]; } 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: 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 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 |
||||||||||||||||||||||||||||||||||||||||||||||||||||
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>