@@ -1007,7 +1007,56 @@ NS_IMETHODIMP nsXULWindow::EnsureAuthPrompter()
}
return mAuthPrompter ? NS_OK : NS_ERROR_FAILURE;
}
void nsXULWindow::ResizeToRoundedDimensions ()
{
nsCOMPtr<nsIBaseWindow> shellWindow (do_QueryInterface (mPrimaryContentShell ));
int32_t windowWidth, windowHeight;
int32_t availWidthCSS, availHeightCSS;
int32_t contentWidth, contentHeight;
double devicePerCSSPixels = 1.0 ;
shellWindow->GetUnscaledDevicePixelsPerCSSPixel (&devicePerCSSPixels);
GetSize (&windowWidth, &windowHeight); // device pixels
GetAvailScreenSize (&availWidthCSS, &availHeightCSS); // css pixels
int32_t availWidth = NSToIntRound(devicePerCSSPixels *
availWidthCSS); // device pixels
int32_t availHeight = NSToIntRound(devicePerCSSPixels *
availHeightCSS); // device pixels
shellWindow->GetSize (&contentWidth, &contentHeight); // device pixels
// Useful for debugging:
// printf("\nscaling factor: %f\n", devicePerCSSPixels);
// printf("window size: %d x %d\n", windowWidth, windowHeight);
// printf("avail screen size: %d x %d\n", availWidth, availHeight);
// printf("primary content shell: %d x %d\n", contentWidth, contentHeight);
int32_t chromeWidth = windowWidth - contentWidth;
int32_t chromeHeight = windowHeight - contentHeight;
int32_t availForContentWidthCSS =
NSToIntRound ((0.95 * availWidth - chromeWidth) / devicePerCSSPixels);
int32_t availForContentHeightCSS =
NSToIntRound ((0.95 * availHeight - chromeHeight) / devicePerCSSPixels);
int32_t targetContentWidth =
NSToIntRound (devicePerCSSPixels *
std::min (1000 , availForContentWidthCSS -
(availForContentWidthCSS % 200 )));
int32_t targetContentHeight =
NSToIntRound (devicePerCSSPixels *
std::min (1000 , availForContentHeightCSS -
(availForContentHeightCSS % 200 )));
SizeShellTo (mPrimaryContentShell ,
targetContentWidth, targetContentHeight);
mIgnoreXULSize = true ;
mIgnoreXULSizeMode = true ;
// Useful for debugging:
// printf("target content size: %d, %d\n",
// targetContentWidth, targetContentHeight);
// GetSize(&windowWidth, &windowHeight);
// GetAvailScreenSize(&availWidth, &availHeight);
// shellWindow->GetSize(&contentWidth, &contentHeight); // device pixels
// printf("\nwindow size: %d x %d\n", windowWidth, windowHeight);
// printf("avail screen size: %d x %d\n", availWidth, availHeight);
// printf("primary content shell: %d x %d\n", contentWidth, contentHeight);
}
void nsXULWindow::OnChromeLoaded ()
{
nsresult rv = EnsureContentTreeOwner ();
@@ -1037,6 +1086,13 @@ void nsXULWindow::OnChromeLoaded()
}
}
// If we have a content browser object, and fingerprinting resistance
// is active, then set to a rounded size.
if (mPrimaryContentShell &&
Preferences::GetBool (" privacy.resistFingerprinting" , false )) {
ResizeToRoundedDimensions ();
}
bool positionSet = !mIgnoreXULPosition ;
nsCOMPtr<nsIXULWindow> parentWindow (do_QueryReferent (mParentWindow ));
#if defined(XP_UNIX) && !defined(XP_MACOSX)
@@ -1137,6 +1193,21 @@ bool nsXULWindow::LoadPositionFromXUL()
return gotPosition;
}
bool nsXULWindow::GetAvailScreenSize (int32_t * availWidth, int32_t * availHeight)
{
nsCOMPtr<nsIDOMWindow> domWindow;
GetWindowDOMWindow (getter_AddRefs (domWindow));
if (nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface (domWindow)) {
nsCOMPtr<nsIDOMScreen> screen = window->GetScreen ();
if (screen) {
screen->GetAvailWidth (availWidth);
screen->GetAvailHeight (availHeight);
return true ;
}
}
return false ;
}
bool nsXULWindow::LoadSizeFromXUL ()
{
bool gotSize = false ;
@@ -1181,21 +1252,12 @@ bool nsXULWindow::LoadSizeFromXUL()
}
if (gotSize) {
// constrain to screen size
nsCOMPtr<nsIDOMWindow> domWindow;
GetWindowDOMWindow (getter_AddRefs (domWindow));
if (nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface (domWindow)) {
nsCOMPtr<nsIDOMScreen> screen = window->GetScreen ();
if (screen) {
int32_t screenWidth;
int32_t screenHeight;
screen->GetAvailWidth (&screenWidth);
screen->GetAvailHeight (&screenHeight);
if (specWidth > screenWidth)
specWidth = screenWidth;
if (specHeight > screenHeight)
specHeight = screenHeight;
}
int32_t screenWidth, screenHeight;
if (GetAvailScreenSize (&screenWidth, &screenHeight)) {
if (specWidth > screenWidth)
specWidth = screenWidth;
if (specHeight > screenHeight)
specHeight = screenHeight;
}
mIntrinsicallySized = false ;