Bug 1442521 - Treat args of nsXULWindow::SetSpecifiedSize as client area size and convert them to outer window size for SetSize. r?smaug
MozReview-Commit-ID: 7aRoxyu9LGy
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1222,42 +1222,49 @@ nsXULWindow::LoadSizeFromXUL(int32_t& aS
}
return gotSize;
}
void
nsXULWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight)
{
+ // we cannot resize anything if there's no window
+ if (mWindow) {
+ return;
+ }
+
+ // convert specified values to outer window size with device pixels
+ double cssToDevPx = mWindow->GetDefaultScale().scale;
+ LayoutDeviceIntSize specSize = mWindow->ClientToWindowSize(
+ LayoutDeviceIntSize(NSToIntRound(aSpecWidth * cssToDevPx),
+ NSToIntRound(aSpecHeight * cssToDevPx)));
+
// constrain to screen size
int32_t screenWidth;
int32_t screenHeight;
-
if (NS_SUCCEEDED(GetAvailScreenSize(&screenWidth, &screenHeight))) {
- if (aSpecWidth > screenWidth) {
- aSpecWidth = screenWidth;
+ screenWidth = NSToIntRound(screenWidth * cssToDevPx);
+ screenHeight = NSToIntRound(screenHeight * cssToDevPx);
+ if (specSize.width > screenWidth) {
+ specSize.width = screenWidth;
}
- if (aSpecHeight > screenHeight) {
- aSpecHeight = screenHeight;
+ if (specSize.height > screenHeight) {
+ specSize.height = screenHeight;
}
}
- NS_ASSERTION(mWindow, "we expected to have a window already");
-
int32_t currWidth = 0;
int32_t currHeight = 0;
GetSize(&currWidth, &currHeight); // returns device pixels
- // convert specified values to device pixels, and resize if needed
- double cssToDevPx = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
- aSpecWidth = NSToIntRound(aSpecWidth * cssToDevPx);
- aSpecHeight = NSToIntRound(aSpecHeight * cssToDevPx);
+ // resize if needed
mIntrinsicallySized = false;
- if (aSpecWidth != currWidth || aSpecHeight != currHeight) {
- SetSize(aSpecWidth, aSpecHeight, false);
+ if (specSize.width != currWidth || specSize.height != currHeight) {
+ SetSize(specSize.width, specSize.height, false);
}
}
/* Miscellaneous persistent attributes are attributes named in the
|persist| attribute, other than size and position. Those are special
because it's important to load those before one of the misc
attributes (sizemode) and they require extra processing. */
bool nsXULWindow::LoadMiscPersistentAttributesFromXUL()