From 6e8b27bc7b576c019c85f8d82215d01b748d495f Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 24 Mar 2009 13:55:32 +1300 Subject: [PATCH] Bug 482687. Remember the appunits-per-devpixel ratio and use it if the window is gone, instead of crashing. r+sr=roc --- xpfe/appshell/src/nsXULWindow.cpp | 21 +++++++++++++++++---- xpfe/appshell/src/nsXULWindow.h | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index 15af06a3eae..60915a8ca65 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -146,7 +146,9 @@ nsXULWindow::nsXULWindow() mBlurSuppressionLevel(0), mPersistentAttributesDirty(0), mPersistentAttributesMask(0), - mChromeFlags(nsIWebBrowserChrome::CHROME_ALL) + mChromeFlags(nsIWebBrowserChrome::CHROME_ALL), + // best guess till we have a widget + mAppPerDev(nsPresContext::AppUnitsPerCSSPixel()) { } @@ -1053,7 +1055,7 @@ PRBool nsXULWindow::LoadPositionFromXUL() PRInt32 specX = currX; PRInt32 specY = currY; nsAutoString posString; - PRInt32 appPerDev = mWindow->GetDeviceContext()->AppUnitsPerDevPixel(); + PRInt32 appPerDev = AppUnitsPerDevPixel(); rv = windowElement->GetAttribute(NS_LITERAL_STRING("screenX"), posString); if (NS_SUCCEEDED(rv)) { @@ -1120,7 +1122,7 @@ PRBool nsXULWindow::LoadSizeFromXUL() PRInt32 specWidth = currWidth; PRInt32 specHeight = currHeight; nsAutoString sizeString; - PRInt32 appPerDev = mWindow->GetDeviceContext()->AppUnitsPerDevPixel(); + PRInt32 appPerDev = AppUnitsPerDevPixel(); rv = windowElement->GetAttribute(NS_LITERAL_STRING("width"), sizeString); if (NS_SUCCEEDED(rv)) { @@ -1463,7 +1465,7 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() nsAutoString sizeString; nsAutoString windowElementId; nsCOMPtr ownerXULDoc; - PRInt32 appPerDev = mWindow->GetDeviceContext()->AppUnitsPerDevPixel(); + PRInt32 appPerDev = AppUnitsPerDevPixel(); { // fetch docShellElement's ID and XUL owner document nsCOMPtr ownerDoc; @@ -2130,6 +2132,17 @@ NS_IMETHODIMP nsXULWindow::SetXULBrowserWindow(nsIXULBrowserWindow * aXULBrowser // nsXULWindow: Accessors //***************************************************************************** +PRInt32 nsXULWindow::AppUnitsPerDevPixel() +{ + if (mWindow && mWindow->GetDeviceContext()) { + mAppPerDev = mWindow->GetDeviceContext()->AppUnitsPerDevPixel(); + } else { + NS_ERROR("nsXULWindow::AppUnitsPerDevPixel called with no window " + "or no dev context"); + } + return mAppPerDev; +} + //***************************************************************************** //*** nsContentShellInfo: Object Management //***************************************************************************** diff --git a/xpfe/appshell/src/nsXULWindow.h b/xpfe/appshell/src/nsXULWindow.h index 1c5100897f0..d16b25c33d3 100644 --- a/xpfe/appshell/src/nsXULWindow.h +++ b/xpfe/appshell/src/nsXULWindow.h @@ -150,6 +150,7 @@ protected: void SetContentScrollbarVisibility(PRBool aVisible); PRBool GetContentScrollbarVisibility(); void PersistentAttributesDirty(PRUint32 aDirtyFlags); + PRInt32 AppUnitsPerDevPixel(); nsChromeTreeOwner* mChromeTreeOwner; nsContentTreeOwner* mContentTreeOwner; @@ -177,6 +178,8 @@ protected: PRUint32 mPersistentAttributesDirty; // persistentAttributes PRUint32 mPersistentAttributesMask; PRUint32 mChromeFlags; + PRUint32 mAppPerDev; // sometimes needed when we can't get + // it from the widget nsString mTitle; nsCOMArray mTargetableShells; // targetable shells only