Bug 862054 - Move translateToTopLevelWindow to Util. r=bbondy

This commit is contained in:
Jim Mathies 2013-04-23 08:51:02 -05:00
Родитель 28ae28e917
Коммит ce05f3ebe2
2 изменённых файлов: 25 добавлений и 26 удалений

Просмотреть файл

@ -315,6 +315,30 @@ let Util = {
* Screen and layout utilities
*/
/*
* translateToTopLevelWindow - Given an element potentially within
* a subframe, calculate the offsets up to the top level browser.
*/
translateToTopLevelWindow: function translateToTopLevelWindow(aElement) {
let offsetX = 0;
let offsetY = 0;
let element = aElement;
while (element &&
element.ownerDocument &&
element.ownerDocument.defaultView != content) {
element = element.ownerDocument.defaultView.frameElement;
let rect = element.getBoundingClientRect();
offsetX += rect.left;
offsetY += rect.top;
}
let win = null;
if (element == aElement)
win = content;
else
win = element.contentDocument.defaultView;
return { targetWindow: win, offsetX: offsetX, offsetY: offsetY };
},
get displayDPI() {
delete this.displayDPI;
return this.displayDPI = this.getWindowUtils(window).displayDPI;

Просмотреть файл

@ -159,31 +159,6 @@ var ContextMenuHandler = {
* Utility routines
*/
/*
* _translateToTopLevelWindow - Given a potential coordinate set within
* a subframe, translate up to the parent window which is what front
* end code expect.
*/
_translateToTopLevelWindow: function _translateToTopLevelWindow(aPopupNode) {
let offsetX = 0;
let offsetY = 0;
let element = aPopupNode;
while (element &&
element.ownerDocument &&
element.ownerDocument.defaultView != content) {
element = element.ownerDocument.defaultView.frameElement;
let rect = element.getBoundingClientRect();
offsetX += rect.left;
offsetY += rect.top;
}
let win = null;
if (element == aPopupNode)
win = content;
else
win = element.contentDocument.defaultView;
return { targetWindow: win, offsetX: offsetX, offsetY: offsetY };
},
/*
* _processPopupNode - Generate and send a Content:ContextMenu message
* to browser detailing the underlying content types at this.popupNode.
@ -197,7 +172,7 @@ var ContextMenuHandler = {
let { targetWindow: targetWindow,
offsetX: offsetX,
offsetY: offsetY } =
this._translateToTopLevelWindow(aPopupNode);
Util.translateToTopLevelWindow(aPopupNode);
let popupNode = this.popupNode = aPopupNode;
let imageUrl = "";