Follow up to bug 404290, make sure embedding clients don't crash (bug 406108). r+sr=bzbarsky a1.9=blocking1.9

This commit is contained in:
stuart.morgan@alumni.case.edu 2007-12-03 16:31:21 -08:00
parent c3053199cd
commit 38864cbc95

View File

@ -1865,12 +1865,21 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem *aDocShellItem,
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(treeOwner));
if (!treeOwnerAsWin) // we'll need this to actually size the docshell
return;
float devPixelsPerCSSPixel = 1.0;
nsCOMPtr<nsIWidget> mainWidget;
treeOwnerAsWin->GetMainWidget(getter_AddRefs(mainWidget));
nsCOMPtr<nsIDeviceContext> 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<nsIBaseWindow> shellWindow(do_QueryInterface(aDocShellItem));
if (shellWindow)
shellWindow->GetParentWidget(getter_AddRefs(mainWidget));
}
if (mainWidget) {
nsCOMPtr<nsIDeviceContext> 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);
}
}