From 9ebc51ed4807a19ed63ab9ea1c39d9ab71572d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Nov 2022 14:52:12 +0000 Subject: [PATCH] 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 --- xpcom/ds/StaticAtoms.py | 2 ++ xpfe/appshell/AppWindow.cpp | 55 +++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/xpcom/ds/StaticAtoms.py b/xpcom/ds/StaticAtoms.py index f6f44dad05e2..ec3bab7b7ff4 100644 --- a/xpcom/ds/StaticAtoms.py +++ b/xpcom/ds/StaticAtoms.py @@ -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"), diff --git a/xpfe/appshell/AppWindow.cpp b/xpfe/appshell/AppWindow.cpp index 55a57be7d41d..0c085c26cde4 100644 --- a/xpfe/appshell/AppWindow.cpp +++ b/xpfe/appshell/AppWindow.cpp @@ -1210,6 +1210,22 @@ void AppWindow::RemoveTooltipSupport() { listener->RemoveTooltipSupport(docShellElement); } +static Maybe 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 windowElement = GetWindowDOMElement(); - NS_ENSURE_TRUE(windowElement, false); + RefPtr 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 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 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 ReadSize(const Element& aElement, nsAtom* aAttr, nsAtom* aMinAttr, nsAtom* aMaxAttr) { Maybe attr = ReadIntAttribute(aElement, aAttr);