ルート要素の属性値を変更する時に他の属性が壊れてしまうバグに対処

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7185 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-09-13 09:47:04 +00:00
parent 441222fc2e
commit 6d4f956d6e
3 changed files with 65 additions and 11 deletions

View File

@ -12,7 +12,7 @@
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/stopRendering.js
*/
(function() {
const currentRevision = 7;
const currentRevision = 8;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -146,7 +146,7 @@
init : function()
{
if (this.useCanvas) {
this.initCanvas();
window.addEventListener('DOMContentLoaded', this, true);
}
else {
this._popups = [];
@ -160,6 +160,11 @@
destroy : function()
{
if (this.useCanvas) {
try {
window.removeEventListener('DOMContentLoaded', this, true);
}
catch(e) {
}
this.destroyCanvas();
}
else {
@ -179,7 +184,7 @@
.getService(Ci.nsIXULAppInfo);
const comparator = Cc['@mozilla.org/xpcom/version-comparator;1']
.getService(Ci.nsIVersionComparator);
return comparator.compare(XULAppInfo.version, '3.6.9999') > 0;
return comparator.compare(XULAppInfo.version, '4.0b1') > 0;
})(),
DRAW_WINDOW_FLAGS : Ci.nsIDOMCanvasRenderingContext2D.DRAWWINDOW_DRAW_VIEW |
@ -314,12 +319,26 @@
destroyCanvas : function()
{
if (!this.canvas)
return;
document.documentElement.removeChild(this.box);
document.removeChild(this.stylePI);
this.box = null;
this.canvas = null;
this.style = null;
this.stylePI = null;
},
handleEvent : function(aEvent)
{
switch (aEvent.type)
{
case 'DOMContentLoaded':
window.removeEventListener('DOMContentLoaded', this, true);
this.initCanvas();
return;
}
}
};

View File

@ -127,14 +127,18 @@ var TreeStyleTabService = {
maxTabbarWidth : function TSTService_maxTabbarWidth(aWidth, aTabBrowser)
{
aTabBrowser = aTabBrowser || this.browser;
var max = Math.max(window.outerWidth, parseInt(document.documentElement.getAttribute('width') || 0));
var windowWidth = window.outerWidth;
var rootWidth = parseInt(document.documentElement.getAttribute('width') || 0);
var max = Math.max(windowWidth, rootWidth);
return Math.max(0, Math.min(aWidth, max * this.MAX_TABBAR_SIZE_RATIO));
},
maxTabbarHeight : function TSTService_maxTabbarHeight(aHeight, aTabBrowser)
{
aTabBrowser = aTabBrowser || this.browser;
var max = Math.max(window.outerHeight, parseInt(document.documentElement.getAttribute('height') || 0));
var windowHeight = window.outerHeight;
var rootHeight = parseInt(document.documentElement.getAttribute('height') || 0);
var max = Math.max(windowHeight, rootHeight);
return Math.max(0, Math.min(aHeight, max * this.MAX_TABBAR_SIZE_RATIO));
},

View File

@ -765,9 +765,10 @@ var TreeStyleTabUtils = {
if (!strip) return;
if (aValue) {
strip.setAttribute(aAttr, aValue);
strip.ownerDocument.defaultView.setTimeout(function() {
strip.ownerDocument.documentElement.setAttribute(aAttr, aValue);
}, 10);
strip.ownerDocument.defaultView.setTimeout(function(aSelf) {
// setting an attribute to a root element sometimes breaks others...
aSelf.safeSetAttribute(strip.ownerDocument.documentElement, aAttr, aValue);
}, 10, this);
if (this._tabStripPlaceHolder)
this._tabStripPlaceHolder.setAttribute(aAttr, aValue);
if (strip.tabsToolbarInnerBox)
@ -775,9 +776,9 @@ var TreeStyleTabUtils = {
}
else {
strip.removeAttribute(aAttr);
strip.ownerDocument.defaultView.setTimeout(function() {
strip.ownerDocument.documentElement.removeAttribute(aAttr);
}, 10);
strip.ownerDocument.defaultView.setTimeout(function(aSelf) {
aSelf.safeSetAttribute(strip.ownerDocument.documentElement, aAttr);
}, 10, this);
if (this._tabStripPlaceHolder)
this._tabStripPlaceHolder.removeAttribute(aAttr);
if (strip.tabsToolbarInnerBox)
@ -790,6 +791,36 @@ var TreeStyleTabUtils = {
this.setTabStripAttribute(aAttr, null);
},
safeSetAttribute : function TSTUtils_safeSetAttribute(aElem, aAttr, aValue)
{
var old = {};
Array.slice(aElem.attributes).forEach(function(aAttr) {
old[aAttr.name] = aAttr.value;
});
if (aValue)
aElem.setAttribute(aAttr, aValue);
else
aElem.removeAttribute(aAttr);
for (var i in old)
{
if (old[i] != aElem.getAttribute(i)) {
dump('TSTUtils_safeSetAttribute restores '+aElem+'.'+i+
', from '+aElem.getAttribute(i)+' to '+old[i]+'\n');
aElem.setAttribute(i, old[i]);
}
}
// verification
for (var i in old)
{
if (old[i] != aElem.getAttribute(i)) {
dump('TSTUtils_safeSetAttribute failed to restore '+aElem+'.'+i+
', from '+aElem.getAttribute(i)+' to '+old[i]+'\n');
}
}
},
getTabFromChild : function TSTUtils_getTabFromChild(aTab)
{
return this.evaluateXPath(