From 6d4f956d6e95aed18a30cd9dc1818f9273314cc6 Mon Sep 17 00:00:00 2001 From: piro Date: Mon, 13 Sep 2010 09:47:04 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=88=E8=A6=81=E7=B4=A0?= =?UTF-8?q?=E3=81=AE=E5=B1=9E=E6=80=A7=E5=80=A4=E3=82=92=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=99=E3=82=8B=E6=99=82=E3=81=AB=E4=BB=96=E3=81=AE=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E3=81=8C=E5=A3=8A=E3=82=8C=E3=81=A6=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=86=E3=83=90=E3=82=B0=E3=81=AB=E5=AF=BE=E5=87=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7185 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/res/stopRendering.js | 25 +++++++++++-- content/treestyletab/treestyletab.js | 8 +++-- modules/utils.js | 43 +++++++++++++++++++---- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/content/treestyletab/res/stopRendering.js b/content/treestyletab/res/stopRendering.js index 0fe0e0e6..a7a9eb22 100644 --- a/content/treestyletab/res/stopRendering.js +++ b/content/treestyletab/res/stopRendering.js @@ -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; + } } }; diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index c181b348..7ba8474f 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -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)); }, diff --git a/modules/utils.js b/modules/utils.js index 33849613..7b7afd0b 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -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(