Skip to content
Permalink
Browse files
Bug 19459: Size new windows to 1000x1000 or nearest 200x200
  • Loading branch information
arthuredelstein committed Oct 23, 2016
1 parent 08136fa commit 4813a689619b51f08b9b1c0e25efb1591f9d9e87
Showing with 80 additions and 16 deletions.
  1. +78 −16 xpfe/appshell/nsXULWindow.cpp
  2. +2 −0 xpfe/appshell/nsXULWindow.h
@@ -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;
@@ -89,6 +89,7 @@ friend class nsContentTreeOwner;
NS_IMETHOD EnsurePrompter();
NS_IMETHOD EnsureAuthPrompter();

void ResizeToRoundedDimensions();
void OnChromeLoaded();
void StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
int32_t aSpecWidth, int32_t aSpecHeight);
@@ -120,6 +121,7 @@ friend class nsContentTreeOwner;
void SetContentScrollbarVisibility(bool aVisible);
bool GetContentScrollbarVisibility();
void PersistentAttributesDirty(uint32_t aDirtyFlags);
bool GetAvailScreenSize(int32_t* availWidth, int32_t* availHeight);

nsChromeTreeOwner* mChromeTreeOwner;
nsContentTreeOwner* mContentTreeOwner;

0 comments on commit 4813a68

Please sign in to comment.