2009-12-25 13:23:18 -05:00
|
|
|
var EXPORTED_SYMBOLS = ['window'];
|
|
|
|
var window = {};
|
|
|
|
|
2009-03-31 03:40:29 -04:00
|
|
|
/*
|
2009-04-06 22:38:07 -04:00
|
|
|
"getBoxObjectFor()" compatibility library for Firefox 3.6 or later
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
// use instead of HTMLDocument.getBoxObjectFor(HTMLElement)
|
|
|
|
var boxObject = window['piro.sakura.ne.jp']
|
|
|
|
.boxObject
|
|
|
|
.getBoxObjectFor(HTMLElement);
|
|
|
|
|
2009-03-31 03:40:29 -04:00
|
|
|
lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
|
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
|
|
|
original:
|
2009-04-06 22:38:07 -04:00
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/boxObject.js
|
2009-03-31 03:40:29 -04:00
|
|
|
*/
|
|
|
|
(function() {
|
2009-11-04 20:06:37 -05:00
|
|
|
const currentRevision = 5;
|
2009-03-31 03:40:29 -04:00
|
|
|
|
|
|
|
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
|
|
|
|
|
|
|
var loadedRevision = 'boxObject' in window['piro.sakura.ne.jp'] ?
|
|
|
|
window['piro.sakura.ne.jp'].boxObject.revision :
|
|
|
|
0 ;
|
|
|
|
if (loadedRevision && loadedRevision > currentRevision) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-02 06:57:00 -04:00
|
|
|
var Cc = Components.classes;
|
2009-03-31 03:40:29 -04:00
|
|
|
var Ci = Components.interfaces;
|
|
|
|
|
|
|
|
window['piro.sakura.ne.jp'].boxObject = {
|
|
|
|
revision : currentRevision,
|
|
|
|
|
2009-04-01 04:49:26 -04:00
|
|
|
getBoxObjectFor : function(aNode, aUnify)
|
2009-03-31 03:40:29 -04:00
|
|
|
{
|
2009-04-01 04:49:26 -04:00
|
|
|
return ('getBoxObjectFor' in aNode.ownerDocument) ?
|
|
|
|
this.getBoxObjectFromBoxObjectFor(aNode, aUnify) :
|
|
|
|
this.getBoxObjectFromClientRectFor(aNode, aUnify) ;
|
|
|
|
},
|
2009-03-31 03:40:29 -04:00
|
|
|
|
2009-04-01 04:49:26 -04:00
|
|
|
getBoxObjectFromBoxObjectFor : function(aNode, aUnify)
|
|
|
|
{
|
|
|
|
var boxObject = aNode.ownerDocument.getBoxObjectFor(aNode);
|
|
|
|
var box = {
|
|
|
|
x : boxObject.x,
|
|
|
|
y : boxObject.y,
|
|
|
|
width : boxObject.width,
|
|
|
|
height : boxObject.height,
|
|
|
|
screenX : boxObject.screenX,
|
|
|
|
screenY : boxObject.screenY
|
|
|
|
};
|
|
|
|
if (!aUnify) return box;
|
|
|
|
|
|
|
|
var style = this._getComputedStyle(aNode);
|
|
|
|
box.left = box.x - this._getPropertyPixelValue(style, 'border-left-width');
|
|
|
|
box.top = box.y - this._getPropertyPixelValue(style, 'border-top-width');
|
|
|
|
if (style.getPropertyValue('position') == 'fixed') {
|
|
|
|
box.left -= frame.scrollX;
|
|
|
|
box.top -= frame.scrollY;
|
|
|
|
}
|
|
|
|
box.right = box.left + box.width;
|
|
|
|
box.bottom = box.top + box.height;
|
|
|
|
|
|
|
|
return box;
|
2009-03-31 03:44:56 -04:00
|
|
|
},
|
|
|
|
|
2009-04-01 04:49:26 -04:00
|
|
|
getBoxObjectFromClientRectFor : function(aNode, aUnify)
|
2009-03-31 03:44:56 -04:00
|
|
|
{
|
2009-03-31 03:40:29 -04:00
|
|
|
var box = {
|
|
|
|
x : 0,
|
|
|
|
y : 0,
|
|
|
|
width : 0,
|
|
|
|
height : 0,
|
|
|
|
screenX : 0,
|
|
|
|
screenY : 0
|
|
|
|
};
|
|
|
|
try {
|
2009-04-02 06:57:00 -04:00
|
|
|
var zoom = this.getZoom(aNode.ownerDocument.defaultView);
|
|
|
|
|
2009-03-31 03:40:29 -04:00
|
|
|
var rect = aNode.getBoundingClientRect();
|
2009-04-01 04:49:26 -04:00
|
|
|
if (aUnify) {
|
|
|
|
box.left = rect.left;
|
|
|
|
box.top = rect.top;
|
|
|
|
box.right = rect.right;
|
|
|
|
box.bottom = rect.bottom;
|
|
|
|
}
|
|
|
|
|
2009-03-31 11:35:08 -04:00
|
|
|
var style = this._getComputedStyle(aNode);
|
2009-03-31 03:40:29 -04:00
|
|
|
var frame = aNode.ownerDocument.defaultView;
|
2009-03-31 11:35:08 -04:00
|
|
|
|
|
|
|
// "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".
|
2009-08-10 05:46:04 -04:00
|
|
|
box.width = rect.right - rect.left;
|
|
|
|
box.height = rect.bottom - rect.top;
|
2009-03-31 03:40:29 -04:00
|
|
|
|
2009-04-02 06:57:00 -04:00
|
|
|
box.screenX = rect.left * zoom;
|
|
|
|
box.screenY = rect.top * zoom;
|
2009-03-31 11:35:08 -04:00
|
|
|
|
2009-11-04 20:06:37 -05:00
|
|
|
box.screenX += frame.mozInnerScreenX * zoom;
|
|
|
|
box.screenY += frame.mozInnerScreenY * zoom;
|
2009-03-31 03:40:29 -04:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
2009-03-31 11:35:08 -04:00
|
|
|
|
|
|
|
for (let i in box)
|
|
|
|
{
|
2009-04-01 04:49:26 -04:00
|
|
|
box[i] = Math.round(box[i]);
|
2009-03-31 11:35:08 -04:00
|
|
|
}
|
|
|
|
|
2009-03-31 03:40:29 -04:00
|
|
|
return box;
|
2009-03-31 03:44:56 -04:00
|
|
|
},
|
|
|
|
|
2009-03-31 11:35:08 -04:00
|
|
|
_getComputedStyle : function(aNode)
|
|
|
|
{
|
|
|
|
return aNode.ownerDocument.defaultView.getComputedStyle(aNode, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPropertyPixelValue : function(aStyle, aProperty)
|
|
|
|
{
|
|
|
|
return parseInt(aStyle.getPropertyValue(aProperty).replace('px', ''));
|
|
|
|
},
|
|
|
|
|
2009-04-02 06:57:00 -04:00
|
|
|
Prefs : Cc['@mozilla.org/preferences;1']
|
|
|
|
.getService(Ci.nsIPrefBranch)
|
|
|
|
.QueryInterface(Ci.nsIPrefBranch2),
|
|
|
|
|
|
|
|
getZoom : function(aFrame)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (!this.Prefs.getBoolPref('browser.zoom.full'))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var markupDocumentViewer = aFrame.top
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.contentViewer
|
|
|
|
.QueryInterface(Ci.nsIMarkupDocumentViewer);
|
|
|
|
return markupDocumentViewer.fullZoom;
|
2009-03-31 03:40:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
})();
|