diff --git a/content/treestyletab/boxObject.js b/content/treestyletab/boxObject.js index e6e8d018..135a0043 100644 --- a/content/treestyletab/boxObject.js +++ b/content/treestyletab/boxObject.js @@ -18,45 +18,6 @@ var Ci = Components.interfaces; - var getFrameOwnerFromFrame = function(aFrame) { - var parentItem = aFrame - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell) - .QueryInterface(Ci.nsIDocShellTreeNode) - .QueryInterface(Ci.nsIDocShellTreeItem) - .parent; - var isChrome = parentItem.itemType == parentItem.typeChrome; - var parentDocument = parentItem - .QueryInterface(Ci.nsIWebNavigation) - .document; - var nodes = parentDocument.evaluate( - '/descendant::*[contains(" frame FRAME iframe IFRAME browser tabbrowser ", concat(" ", local-name(), " "))]', - parentDocument, - null, - XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, - null - ); - for (let i = 0, maxi = nodes.snapshotLength; i < maxi; i++) - { - let owner = nodes.snapshotItem(i); - if (isChrome && owner.wrappedJSObject) owner = owner.wrappedJSObject; - if (owner.localName == 'tabbrowser') { - let tabs = owner.mTabContainer.childNodes; - for (let i = 0, maxi = tabs.length; i < maxi; i++) - { - let browser = tabs[i].linkedBrowser; - if (browser.contentWindow == aFrame) - return browser; - } - } - else if (owner.contentWindow == aFrame) { - return owner; - } - } - return null; - }; - window['piro.sakura.ne.jp'].boxObject = { revision : currentRevision, @@ -65,6 +26,11 @@ if ('getBoxObjectFor' in aNode.ownerDocument) return aNode.ownerDocument.getBoxObjectFor(aNode); + return this.getBoxObjectFromClientRectFor(aNode); + }, + + getBoxObjectFromClientRectFor : function(aNode) + { var box = { x : 0, y : 0, @@ -87,7 +53,7 @@ while (true) { frame = owner.ownerDocument.defaultView; - owner = getFrameOwnerFromFrame(frame); + owner = this._getFrameOwnerFromFrame(frame); if (!owner) { box.screenX += frame.screenX; box.screenY += frame.screenY; @@ -107,6 +73,46 @@ catch(e) { } return box; + }, + + _getFrameOwnerFromFrame : function(aFrame) + { + var parentItem = aFrame + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShell) + .QueryInterface(Ci.nsIDocShellTreeNode) + .QueryInterface(Ci.nsIDocShellTreeItem) + .parent; + var isChrome = parentItem.itemType == parentItem.typeChrome; + var parentDocument = parentItem + .QueryInterface(Ci.nsIWebNavigation) + .document; + var nodes = parentDocument.evaluate( + '/descendant::*[contains(" frame FRAME iframe IFRAME browser tabbrowser ", concat(" ", local-name(), " "))]', + parentDocument, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null + ); + for (let i = 0, maxi = nodes.snapshotLength; i < maxi; i++) + { + let owner = nodes.snapshotItem(i); + if (isChrome && owner.wrappedJSObject) owner = owner.wrappedJSObject; + if (owner.localName == 'tabbrowser') { + let tabs = owner.mTabContainer.childNodes; + for (let i = 0, maxi = tabs.length; i < maxi; i++) + { + let browser = tabs[i].linkedBrowser; + if (browser.contentWindow == aFrame) + return browser; + } + } + else if (owner.contentWindow == aFrame) { + return owner; + } + } + return null; } };