From 2887b8531ef5090a7209b28627e8d924658c74ee Mon Sep 17 00:00:00 2001 From: piro Date: Tue, 31 Mar 2009 15:35:08 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= 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@3978 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/boxObject.js | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/content/treestyletab/boxObject.js b/content/treestyletab/boxObject.js index 135a0043..981f4f80 100644 --- a/content/treestyletab/boxObject.js +++ b/content/treestyletab/boxObject.js @@ -41,12 +41,22 @@ }; try { var rect = aNode.getBoundingClientRect(); + var style = this._getComputedStyle(aNode); var frame = aNode.ownerDocument.defaultView; - box.x = rect.left + frame.scrollX; - box.y = rect.top + frame.scrollY; + + // "x" and "y" are offset positions of the "padding-box" from the document top-left edge. + box.x = rect.left + this._getPropertyPixelValue(style, 'border-left-width'); + box.y = rect.top + this._getPropertyPixelValue(style, 'border-top-width'); + if (style.getPropertyValue('position') != 'fixed') { + box.x += frame.scrollX; + box.y += frame.scrollY; + } + + // "width" and "height" are sizes of the "border-box". box.width = rect.right-rect.left; box.height = rect.bottom-rect.top; + // "screenX" and "screenY" are absolute positions of the "border-box". box.screenX = rect.left; box.screenY = rect.top; var owner = aNode; @@ -54,6 +64,11 @@ { frame = owner.ownerDocument.defaultView; owner = this._getFrameOwnerFromFrame(frame); + + let style = this._getComputedStyle(owner); + box.screenX += this._getPropertyPixelValue(style, 'border-left-width'); + box.screenY += this._getPropertyPixelValue(style, 'border-top-width'); + if (!owner) { box.screenX += frame.screenX; box.screenY += frame.screenY; @@ -65,6 +80,7 @@ box.screenY += ownerBox.screenY; break; } + let ownerRect = owner.getBoundingClientRect(); box.screenX += ownerRect.left; box.screenY += ownerRect.top; @@ -72,9 +88,25 @@ } catch(e) { } + + for (let i in box) + { + box[i] = parseInt(box[i]); + } + return box; }, + _getComputedStyle : function(aNode) + { + return aNode.ownerDocument.defaultView.getComputedStyle(aNode, null); + }, + + _getPropertyPixelValue : function(aStyle, aProperty) + { + return parseInt(aStyle.getPropertyValue(aProperty).replace('px', '')); + }, + _getFrameOwnerFromFrame : function(aFrame) { var parentItem = aFrame