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);
|
|
|
|
|
2010-06-22 19:46:51 -04:00
|
|
|
lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
|
2009-03-31 03:40:29 -04:00
|
|
|
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
|
|
|
*/
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-22 21:32:31 -04:00
|
|
|
/* To work as a JS Code Module (*require namespace.jsm)
|
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm */
|
|
|
|
if (typeof window == 'undefined') {
|
|
|
|
this.EXPORTED_SYMBOLS = ['boxObject'];
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-26 11:13:11 -04:00
|
|
|
// If namespace.jsm is available, export symbols to the shared namespace.
|
|
|
|
// See: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm
|
|
|
|
try {
|
|
|
|
let ns = {};
|
|
|
|
Components.utils.import('resource://treestyletab-modules/namespace.jsm', ns);
|
|
|
|
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
window = {};
|
|
|
|
}
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|
|
|
|
|
2009-03-31 03:40:29 -04:00
|
|
|
(function() {
|
2010-06-22 19:46:51 -04:00
|
|
|
const currentRevision = 6;
|
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,
|
2010-06-22 19:46:51 -04:00
|
|
|
screenY : boxObject.screenY,
|
|
|
|
element : aNode
|
2009-04-01 04:49:26 -04:00
|
|
|
};
|
|
|
|
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,
|
2010-06-22 19:46:51 -04:00
|
|
|
screenY : 0,
|
|
|
|
element : aNode
|
2009-03-31 03:40:29 -04:00
|
|
|
};
|
|
|
|
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
|
|
|
|
2010-06-22 19:46:51 -04:00
|
|
|
'x,y,screenX,screenY,width,height,left,top,right,bottom'
|
|
|
|
.split(',')
|
|
|
|
.forEach(function(aProperty) {
|
|
|
|
if (aProperty in box)
|
|
|
|
box[aProperty] = Math.round(box[aProperty]);
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
})();
|
2010-06-22 19:46:51 -04:00
|
|
|
|
|
|
|
if (window != this) { // work as a JS Code Module
|
2010-06-22 21:32:31 -04:00
|
|
|
this.boxObject = window['piro.sakura.ne.jp'].boxObject;
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|