Bug 1801032 - Keep reading lowercase screenx/y when loading XUL window positions. r=smaug

The early blank first-paint stuff[1] manually sets these attributes in
lowercase in an about:blank window, marvelous o.O

[1]: https://searchfox.org/mozilla-central/rev/650c19c96529eb28d081062c1ca274bc50ef3635/browser/components/BrowserGlue.jsm#1507-1523

Differential Revision: https://phabricator.services.mozilla.com/D162745
This commit is contained in:
Emilio Cobos Álvarez 2022-11-23 14:52:12 +00:00
parent 90a2b214cc
commit 9ebc51ed48
2 changed files with 34 additions and 23 deletions

View File

@ -1107,7 +1107,9 @@ STATIC_ATOMS = [
Atom("scoped", "scoped"),
Atom("screen", "screen"),
Atom("screenX", "screenX"),
Atom("screenx", "screenx"),
Atom("screenY", "screenY"),
Atom("screeny", "screeny"),
Atom("script", "script"),
Atom("scrollbar", "scrollbar"),
Atom("scrollbarThumb", "scrollbar-thumb"),

View File

@ -1210,6 +1210,22 @@ void AppWindow::RemoveTooltipSupport() {
listener->RemoveTooltipSupport(docShellElement);
}
static Maybe<int32_t> ReadIntAttribute(const Element& aElement,
nsAtom* aPrimary,
nsAtom* aSecondary = nullptr) {
nsAutoString attrString;
if (!aElement.GetAttr(aPrimary, attrString)) {
if (aSecondary) {
return ReadIntAttribute(aElement, aSecondary);
}
return Nothing();
}
nsresult res = NS_OK;
int32_t ret = attrString.ToInteger(&res);
return NS_SUCCEEDED(res) ? Some(ret) : Nothing();
}
// If aSpecWidth and/or aSpecHeight are > 0, we will use these CSS px sizes
// to fit to the screen when staggering windows; if they're negative,
// we use the window's current size instead.
@ -1222,8 +1238,8 @@ bool AppWindow::LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight) {
return false;
}
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
NS_ENSURE_TRUE(windowElement, false);
RefPtr<dom::Element> root = GetWindowDOMElement();
NS_ENSURE_TRUE(root, false);
const LayoutDeviceIntRect devRect = GetPositionAndSize();
@ -1246,19 +1262,23 @@ bool AppWindow::LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight) {
}
// Obtain the position information from the <xul:window> element.
nsAutoString posString;
DesktopIntPoint specPoint = curPoint;
nsresult errorCode;
windowElement->GetAttr(nsGkAtoms::screenX, posString);
int32_t temp = posString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode)) {
specPoint.x = temp;
// Also read lowercase screenx/y because the front-end sometimes sets these
// via setAttribute on HTML documents like about:blank, and stuff gets
// lowercased.
//
// TODO(emilio): We should probably rename screenX/Y to screen-x/y to
// prevent this impedance mismatch.
if (auto attr =
ReadIntAttribute(*root, nsGkAtoms::screenX, nsGkAtoms::screenx)) {
specPoint.x = *attr;
gotPosition = true;
}
windowElement->GetAttr(nsGkAtoms::screenY, posString);
temp = posString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode)) {
specPoint.y = temp;
if (auto attr =
ReadIntAttribute(*root, nsGkAtoms::screenY, nsGkAtoms::screeny)) {
specPoint.y = *attr;
gotPosition = true;
}
@ -1282,17 +1302,6 @@ bool AppWindow::LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight) {
return gotPosition;
}
static Maybe<int32_t> ReadIntAttribute(const Element& aElement, nsAtom* aAtom) {
nsAutoString attrString;
if (!aElement.GetAttr(aAtom, attrString)) {
return Nothing();
}
nsresult res = NS_OK;
int32_t ret = attrString.ToInteger(&res);
return NS_SUCCEEDED(res) ? Some(ret) : Nothing();
}
static Maybe<int32_t> ReadSize(const Element& aElement, nsAtom* aAttr,
nsAtom* aMinAttr, nsAtom* aMaxAttr) {
Maybe<int32_t> attr = ReadIntAttribute(aElement, aAttr);