From 38864cbc95b2861b43e54748838f2cdfb7a82e85 Mon Sep 17 00:00:00 2001 From: "stuart.morgan@alumni.case.edu" Date: Mon, 3 Dec 2007 16:31:21 -0800 Subject: [PATCH] Follow up to bug 404290, make sure embedding clients don't crash (bug 406108). r+sr=bzbarsky a1.9=blocking1.9 --- .../windowwatcher/src/nsWindowWatcher.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index 52639aa6640..a3d1da29286 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -1865,12 +1865,21 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, nsCOMPtr treeOwnerAsWin(do_QueryInterface(treeOwner)); if (!treeOwnerAsWin) // we'll need this to actually size the docshell return; - + + float devPixelsPerCSSPixel = 1.0; nsCOMPtr mainWidget; treeOwnerAsWin->GetMainWidget(getter_AddRefs(mainWidget)); - nsCOMPtr ctx = mainWidget->GetDeviceContext(); - - float DevPixelsPerCSSPixel = float(ctx->AppUnitsPerCSSPixel()) / ctx->AppUnitsPerDevPixel(); + if (!mainWidget) { + // Some embedding clients don't support nsIDocShellTreeOwner's + // GetMainWidget, so try going through nsIBaseWindow's GetParentWidget + nsCOMPtr shellWindow(do_QueryInterface(aDocShellItem)); + if (shellWindow) + shellWindow->GetParentWidget(getter_AddRefs(mainWidget)); + } + if (mainWidget) { + nsCOMPtr ctx = mainWidget->GetDeviceContext(); + devPixelsPerCSSPixel = float(ctx->AppUnitsPerCSSPixel()) / ctx->AppUnitsPerDevPixel(); + } /* The current position and size will be unchanged if not specified (and they fit entirely onscreen). Also, calculate the difference @@ -1892,17 +1901,17 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, // Set up left/top if (aSizeSpec.mLeftSpecified) { - left = aSizeSpec.mLeft * DevPixelsPerCSSPixel; + left = NSToIntRound(aSizeSpec.mLeft * devPixelsPerCSSPixel); } if (aSizeSpec.mTopSpecified) { - top = aSizeSpec.mTop * DevPixelsPerCSSPixel; + top = NSToIntRound(aSizeSpec.mTop * devPixelsPerCSSPixel); } // Set up width if (aSizeSpec.mOuterWidthSpecified) { if (!aSizeSpec.mUseDefaultWidth) { - width = aSizeSpec.mOuterWidth * DevPixelsPerCSSPixel; + width = NSToIntRound(aSizeSpec.mOuterWidth * devPixelsPerCSSPixel); } // Else specified to default; just use our existing width } else if (aSizeSpec.mInnerWidthSpecified) { @@ -1910,14 +1919,14 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, if (aSizeSpec.mUseDefaultWidth) { width = width - chromeWidth; } else { - width = aSizeSpec.mInnerWidth * DevPixelsPerCSSPixel; + width = NSToIntRound(aSizeSpec.mInnerWidth * devPixelsPerCSSPixel); } } // Set up height if (aSizeSpec.mOuterHeightSpecified) { if (!aSizeSpec.mUseDefaultHeight) { - height = aSizeSpec.mOuterHeight * DevPixelsPerCSSPixel; + height = NSToIntRound(aSizeSpec.mOuterHeight * devPixelsPerCSSPixel); } // Else specified to default; just use our existing height } else if (aSizeSpec.mInnerHeightSpecified) { @@ -1925,7 +1934,7 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem, if (aSizeSpec.mUseDefaultHeight) { height = height - chromeHeight; } else { - height = aSizeSpec.mInnerHeight * DevPixelsPerCSSPixel; + height = NSToIntRound(aSizeSpec.mInnerHeight * devPixelsPerCSSPixel); } }