Bug 1786048 - Part 2: Use layout device pixels for AppWindow primary content size. r=emilio

The getter used to return CSS pixels, while the setter expected layout
device pixels. The nsIDocShellTreeOwner documentation used to suggest that
CSS pixels are used for getters and setters of the primary content and
the root shell size. Only the getter for the primary content size
happend to match that documentation.

Differential Revision: https://phabricator.services.mozilla.com/D161944
This commit is contained in:
Matthias Camenzind
2022-11-30 19:37:16 +00:00
parent bba6a42299
commit e5c4c5d82a
3 changed files with 46 additions and 50 deletions

View File

@@ -66,22 +66,22 @@ interface nsIDocShellTreeOwner : nsISupports
void sizeShellTo(in nsIDocShellTreeItem shell, in long cx, in long cy); void sizeShellTo(in nsIDocShellTreeItem shell, in long cx, in long cy);
/* /*
Gets the size of the primary content area in CSS pixels. This should work Gets the size of the primary content area in device pixels. This should work
for both in-process and out-of-process content areas. for both in-process and out-of-process content areas.
*/ */
void getPrimaryContentSize(out long width, out long height); void getPrimaryContentSize(out long width, out long height);
/* /*
Sets the size of the primary content area in CSS pixels. This should work Sets the size of the primary content area in device pixels. This should work
for both in-process and out-of-process content areas. for both in-process and out-of-process content areas.
*/ */
void setPrimaryContentSize(in long width, in long height); void setPrimaryContentSize(in long width, in long height);
/* /*
Gets the size of the root docshell in CSS pixels. Gets the size of the root docshell in device pixels.
*/ */
void getRootShellSize(out long width, out long height); void getRootShellSize(out long width, out long height);
/* /*
Sets the size of the root docshell in CSS pixels. Sets the size of the root docshell in device pixels.
*/ */
void setRootShellSize(in long width, in long height); void setRootShellSize(in long width, in long height);

View File

@@ -2260,16 +2260,19 @@ static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
left = (LayoutDeviceCoord(devPxRect.x) / devToDesktopScale).Rounded(); left = (LayoutDeviceCoord(devPxRect.x) / devToDesktopScale).Rounded();
top = (LayoutDeviceCoord(devPxRect.y) / devToDesktopScale).Rounded(); top = (LayoutDeviceCoord(devPxRect.y) / devToDesktopScale).Rounded();
int32_t contentWidth, contentHeight; // CSS pixels. LayoutDeviceIntSize contentSize;
bool hasPrimaryContent = false; bool hasPrimaryContent = false;
aTreeOwner->GetHasPrimaryContent(&hasPrimaryContent); aTreeOwner->GetHasPrimaryContent(&hasPrimaryContent);
if (hasPrimaryContent) { if (hasPrimaryContent) {
aTreeOwner->GetPrimaryContentSize(&contentWidth, &contentHeight); aTreeOwner->GetPrimaryContentSize(&contentSize.width,
&contentSize.height);
} else { } else {
aTreeOwner->GetRootShellSize(&contentWidth, &contentHeight); aTreeOwner->GetRootShellSize(&contentSize.width, &contentSize.height);
} }
chromeWidth = width - contentWidth;
chromeHeight = height - contentHeight; CSSIntSize contentSizeCSS = RoundedToInt(contentSize / cssToDevScale);
chromeWidth = width - contentSizeCSS.width;
chromeHeight = height - contentSizeCSS.height;
} }
// Set up left/top // Set up left/top

View File

@@ -1105,48 +1105,39 @@ NS_IMETHODIMP AppWindow::ForceRoundedDimensions() {
return NS_OK; return NS_OK;
} }
int32_t availWidthCSS = 0; CSSToLayoutDeviceScale scale = UnscaledDevicePixelsPerCSSPixel();
int32_t availHeightCSS = 0;
int32_t contentWidthCSS = 0;
int32_t contentHeightCSS = 0;
int32_t windowWidthCSS = 0;
int32_t windowHeightCSS = 0;
double devicePerCSSPixels = UnscaledDevicePixelsPerCSSPixel().scale;
GetAvailScreenSize(&availWidthCSS, &availHeightCSS); CSSIntSize availSizeCSS;
GetAvailScreenSize(&availSizeCSS.width, &availSizeCSS.height);
// To get correct chrome size, we have to resize the window to a proper // To get correct chrome size, we have to resize the window to a proper
// size first. So, here, we size it to its available size. // size first. So, here, we size it to its available size.
SetSpecifiedSize(availWidthCSS, availHeightCSS); SetSpecifiedSize(availSizeCSS.width, availSizeCSS.height);
// Get the current window size for calculating chrome UI size. // Get the current window size for calculating chrome UI size.
GetSize(&windowWidthCSS, &windowHeightCSS); // device pixels CSSIntSize windowSizeCSS = RoundedToInt(GetSize() / scale);
windowWidthCSS = NSToIntRound(windowWidthCSS / devicePerCSSPixels);
windowHeightCSS = NSToIntRound(windowHeightCSS / devicePerCSSPixels);
// Get the content size for calculating chrome UI size. // Get the content size for calculating chrome UI size.
GetPrimaryContentSize(&contentWidthCSS, &contentHeightCSS); LayoutDeviceIntSize contentSizeDev;
GetPrimaryContentSize(&contentSizeDev.width, &contentSizeDev.height);
CSSIntSize contentSizeCSS = RoundedToInt(contentSizeDev / scale);
// Calculate the chrome UI size. // Calculate the chrome UI size.
int32_t chromeWidth = 0, chromeHeight = 0; CSSIntSize chromeSizeCSS = windowSizeCSS - contentSizeCSS;
chromeWidth = windowWidthCSS - contentWidthCSS;
chromeHeight = windowHeightCSS - contentHeightCSS;
int32_t targetContentWidth = 0, targetContentHeight = 0;
CSSIntSize targetSizeCSS;
// Here, we use the available screen dimensions as the input dimensions to // Here, we use the available screen dimensions as the input dimensions to
// force the window to be rounded as the maximum available content size. // force the window to be rounded as the maximum available content size.
nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting( nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
chromeWidth, chromeHeight, availWidthCSS, availHeightCSS, availWidthCSS, chromeSizeCSS.width, chromeSizeCSS.height, availSizeCSS.width,
availHeightCSS, availSizeCSS.height, availSizeCSS.width, availSizeCSS.height,
false, // aSetOuterWidth false, // aSetOuterWidth
false, // aSetOuterHeight false, // aSetOuterHeight
&targetContentWidth, &targetContentHeight); &targetSizeCSS.width, &targetSizeCSS.height);
targetContentWidth = NSToIntRound(targetContentWidth * devicePerCSSPixels); LayoutDeviceIntSize targetSizeDev = RoundedToInt(targetSizeCSS * scale);
targetContentHeight = NSToIntRound(targetContentHeight * devicePerCSSPixels);
SetPrimaryContentSize(targetContentWidth, targetContentHeight); SetPrimaryContentSize(targetSizeDev.width, targetSizeDev.height);
return NS_OK; return NS_OK;
} }
@@ -2166,8 +2157,15 @@ nsresult AppWindow::GetPrimaryRemoteTabSize(int32_t* aWidth, int32_t* aHeight) {
RefPtr<dom::Element> element = host->GetOwnerElement(); RefPtr<dom::Element> element = host->GetOwnerElement();
NS_ENSURE_STATE(element); NS_ENSURE_STATE(element);
*aWidth = element->ClientWidth(); CSSIntSize size(element->ClientWidth(), element->ClientHeight());
*aHeight = element->ClientHeight(); LayoutDeviceIntSize sizeDev =
RoundedToInt(size * UnscaledDevicePixelsPerCSSPixel());
if (aWidth) {
*aWidth = sizeDev.width;
}
if (aHeight) {
*aHeight = sizeDev.height;
}
return NS_OK; return NS_OK;
} }
@@ -2178,14 +2176,13 @@ nsresult AppWindow::GetPrimaryContentShellSize(int32_t* aWidth,
nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(mPrimaryContentShell)); nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(mPrimaryContentShell));
NS_ENSURE_STATE(shellWindow); NS_ENSURE_STATE(shellWindow);
// We want to return CSS pixels. First, we get device pixels LayoutDeviceIntSize sizeDev = shellWindow->GetSize();
// from the content area... if (aWidth) {
// And then get the device pixel scaling factor. Dividing device *aWidth = sizeDev.width;
// pixels by this scaling factor gives us CSS pixels. }
CSSIntSize size = RoundedToInt( if (aHeight) {
shellWindow->GetSize() / shellWindow->UnscaledDevicePixelsPerCSSPixel()); *aHeight = sizeDev.height;
*aWidth = size.width; }
*aHeight = size.height;
return NS_OK; return NS_OK;
} }
@@ -2193,7 +2190,8 @@ NS_IMETHODIMP
AppWindow::SetPrimaryContentSize(int32_t aWidth, int32_t aHeight) { AppWindow::SetPrimaryContentSize(int32_t aWidth, int32_t aHeight) {
if (mPrimaryBrowserParent) { if (mPrimaryBrowserParent) {
return SetPrimaryRemoteTabSize(aWidth, aHeight); return SetPrimaryRemoteTabSize(aWidth, aHeight);
} else if (mPrimaryContentShell) { }
if (mPrimaryContentShell) {
return SizeShellTo(mPrimaryContentShell, aWidth, aHeight); return SizeShellTo(mPrimaryContentShell, aWidth, aHeight);
} }
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
@@ -2202,12 +2200,7 @@ AppWindow::SetPrimaryContentSize(int32_t aWidth, int32_t aHeight) {
nsresult AppWindow::SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight) { nsresult AppWindow::SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight) {
int32_t shellWidth, shellHeight; int32_t shellWidth, shellHeight;
GetPrimaryRemoteTabSize(&shellWidth, &shellHeight); GetPrimaryRemoteTabSize(&shellWidth, &shellHeight);
SizeShellToWithLimit(aWidth, aHeight, shellWidth, shellHeight);
// FIXME: This is wrong (pre-existing), the above call acounts for zoom and
// this one doesn't.
double scale = UnscaledDevicePixelsPerCSSPixel().scale;
SizeShellToWithLimit(aWidth, aHeight, shellWidth * scale,
shellHeight * scale);
return NS_OK; return NS_OK;
} }