2021-01-28 23:58:34 +03:00
|
|
|
/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["LayoutUtils"];
|
|
|
|
|
|
|
|
var LayoutUtils = {
|
|
|
|
/**
|
2022-01-05 12:13:36 +03:00
|
|
|
* For a given DOM element, returns its position in screen coordinates
|
|
|
|
* (<https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_View/Coordinate_systems#screen>).
|
2021-01-28 23:58:34 +03:00
|
|
|
*/
|
|
|
|
getElementBoundingScreenRect(aElement) {
|
|
|
|
let rect = aElement.getBoundingClientRect();
|
|
|
|
let win = aElement.ownerGlobal;
|
|
|
|
|
|
|
|
let x = rect.left;
|
|
|
|
let y = rect.top;
|
|
|
|
|
Bug 1684795 - Account for desktop zooming when opening content popups. r=tnikkel
In OOP iframes, we don't have desktop zoom value specifically in each iframe
documents, instead we have a transform matrix,
nsIWidget::WidgetToTopLevelWidgetTransform(), on each the __top__ level OOP
iframe document that the matrix includes the desktop zoom scale value along with
translations by ancestor scroll containers, ancestor CSS transforms, etc.
Note that if the document is not in OOP iframes, i.e. it's in the top level
content subtree, the transform, nsIWidget::WidgetToTopLevelWidgetTransform()
doesn't include the destktop zoom value, so for documents in the top level
content document subtree, ViewportUtils::DocumentRelativeLayoutToVisual applies
the desktop zoom value via PresShell::GetResolution().
Differential Revision: https://phabricator.services.mozilla.com/D102219
2021-02-08 00:33:39 +03:00
|
|
|
// We need to compensate for ancestor iframes in the same process
|
|
|
|
// that might shift things over.
|
2022-01-24 14:56:13 +03:00
|
|
|
let parentFrame = win.browsingContext?.embedderElement;
|
2021-01-28 23:58:34 +03:00
|
|
|
while (parentFrame) {
|
|
|
|
win = parentFrame.ownerGlobal;
|
|
|
|
let cstyle = win.getComputedStyle(parentFrame);
|
|
|
|
|
|
|
|
let framerect = parentFrame.getBoundingClientRect();
|
|
|
|
x +=
|
|
|
|
framerect.left +
|
|
|
|
parseFloat(cstyle.borderLeftWidth) +
|
|
|
|
parseFloat(cstyle.paddingLeft);
|
|
|
|
y +=
|
|
|
|
framerect.top +
|
|
|
|
parseFloat(cstyle.borderTopWidth) +
|
|
|
|
parseFloat(cstyle.paddingTop);
|
|
|
|
|
2022-01-24 14:56:13 +03:00
|
|
|
parentFrame = win.browsingContext?.embedderElement;
|
2021-01-28 23:58:34 +03:00
|
|
|
}
|
|
|
|
|
2021-08-21 03:31:13 +03:00
|
|
|
return aElement.ownerGlobal.windowUtils.toScreenRectInCSSUnits(
|
Bug 1684795 - Account for desktop zooming when opening content popups. r=tnikkel
In OOP iframes, we don't have desktop zoom value specifically in each iframe
documents, instead we have a transform matrix,
nsIWidget::WidgetToTopLevelWidgetTransform(), on each the __top__ level OOP
iframe document that the matrix includes the desktop zoom scale value along with
translations by ancestor scroll containers, ancestor CSS transforms, etc.
Note that if the document is not in OOP iframes, i.e. it's in the top level
content subtree, the transform, nsIWidget::WidgetToTopLevelWidgetTransform()
doesn't include the destktop zoom value, so for documents in the top level
content document subtree, ViewportUtils::DocumentRelativeLayoutToVisual applies
the desktop zoom value via PresShell::GetResolution().
Differential Revision: https://phabricator.services.mozilla.com/D102219
2021-02-08 00:33:39 +03:00
|
|
|
x,
|
|
|
|
y,
|
2021-01-28 23:58:34 +03:00
|
|
|
rect.width,
|
|
|
|
rect.height
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|