Bug 424375. window.outerWidth/outerHeight should be in CSS pixels, not device pixels. r+sr=jst

This commit is contained in:
roc+%cs.cmu.edu 2008-04-01 22:20:45 +00:00
Родитель e95c296421
Коммит 7e28413a9b
2 изменённых файлов: 74 добавлений и 55 удалений

Просмотреть файл

@ -3185,11 +3185,9 @@ nsGlobalWindow::SetInnerHeight(PRInt32 aInnerHeight)
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::GetOuterWidth(PRInt32* aOuterWidth)
nsresult
nsGlobalWindow::GetOuterSize(nsIntSize* aSizeCSSPixels)
{
FORWARD_TO_OUTER(GetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
@ -3199,18 +3197,56 @@ nsGlobalWindow::GetOuterWidth(PRInt32* aOuterWidth)
if (rootWindow) {
rootWindow->FlushPendingNotifications(Flush_Layout);
}
PRInt32 notused;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(aOuterWidth, &notused),
nsIntSize sizeDevPixels;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(&sizeDevPixels.width,
&sizeDevPixels.height),
NS_ERROR_FAILURE);
nsCOMPtr<nsPresContext> presContext;
mDocShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext) {
// XXX If we don't have a prescontext it's not really clear what we
// should do... For now let's assume a 1:1 ratio.
*aSizeCSSPixels = sizeDevPixels;
return NS_OK;
}
*aSizeCSSPixels = nsIntSize(
nsPresContext::AppUnitsToIntCSSPixels(presContext->DevPixelsToAppUnits(sizeDevPixels.width)),
nsPresContext::AppUnitsToIntCSSPixels(presContext->DevPixelsToAppUnits(sizeDevPixels.height)));
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::SetOuterWidth(PRInt32 aOuterWidth)
nsGlobalWindow::GetOuterWidth(PRInt32* aOuterWidth)
{
FORWARD_TO_OUTER(SetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED);
FORWARD_TO_OUTER(GetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED);
nsIntSize sizeCSSPixels;
nsresult rv = GetOuterSize(&sizeCSSPixels);
NS_ENSURE_SUCCESS(rv, rv);
*aOuterWidth = sizeCSSPixels.width;
return NS_OK;
}
NS_IMETHODIMP
nsGlobalWindow::GetOuterHeight(PRInt32* aOuterHeight)
{
FORWARD_TO_OUTER(GetOuterHeight, (aOuterHeight), NS_ERROR_NOT_INITIALIZED);
nsIntSize sizeCSSPixels;
nsresult rv = GetOuterSize(&sizeCSSPixels);
NS_ENSURE_SUCCESS(rv, rv);
*aOuterHeight = sizeCSSPixels.height;
return NS_OK;
}
nsresult
nsGlobalWindow::SetOuterSize(PRInt32 aLengthCSSPixels, PRBool aIsWidth)
{
/*
* If caller is not chrome and the user has not explicitly exempted the site,
* prevent setting window.outerWidth by exiting early
@ -3224,38 +3260,40 @@ nsGlobalWindow::SetOuterWidth(PRInt32 aOuterWidth)
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(CheckSecurityWidthAndHeight(&aOuterWidth, nsnull),
nsCOMPtr<nsPresContext> presContext;
mDocShell->GetPresContext(getter_AddRefs(presContext));
PRInt32 lengthDevPixels;
if (presContext) {
lengthDevPixels =
presContext->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(aLengthCSSPixels));
} else {
// XXX If we don't have a prescontext it's not really clear what we
// should do... For now let's assume a 1:1 ratio.
lengthDevPixels = aLengthCSSPixels;
}
NS_ENSURE_SUCCESS(CheckSecurityWidthAndHeight(
aIsWidth ? &lengthDevPixels : nsnull,
aIsWidth ? nsnull : &lengthDevPixels),
NS_ERROR_FAILURE);
PRInt32 notused, height;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(&notused, &height), NS_ERROR_FAILURE);
PRInt32 width, height;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(&width, &height), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(treeOwnerAsWin->SetSize(aOuterWidth, height, PR_TRUE),
NS_ERROR_FAILURE);
return NS_OK;
if (aIsWidth) {
width = lengthDevPixels;
} else {
height = lengthDevPixels;
}
return treeOwnerAsWin->SetSize(width, height, PR_TRUE);
}
NS_IMETHODIMP
nsGlobalWindow::GetOuterHeight(PRInt32* aOuterHeight)
nsGlobalWindow::SetOuterWidth(PRInt32 aOuterWidth)
{
FORWARD_TO_OUTER(GetOuterHeight, (aOuterHeight), NS_ERROR_NOT_INITIALIZED);
FORWARD_TO_OUTER(SetOuterWidth, (aOuterWidth), NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
nsGlobalWindow* rootWindow =
static_cast<nsGlobalWindow *>(GetPrivateRoot());
if (rootWindow) {
rootWindow->FlushPendingNotifications(Flush_Layout);
}
PRInt32 notused;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(&notused, aOuterHeight),
NS_ERROR_FAILURE);
return NS_OK;
return SetOuterSize(aOuterWidth, PR_TRUE);
}
NS_IMETHODIMP
@ -3263,29 +3301,7 @@ nsGlobalWindow::SetOuterHeight(PRInt32 aOuterHeight)
{
FORWARD_TO_OUTER(SetOuterHeight, (aOuterHeight), NS_ERROR_NOT_INITIALIZED);
/*
* If caller is not chrome and the user has not explicitly exempted the site,
* prevent setting window.outerHeight by exiting early
*/
if (!CanMoveResizeWindows()) {
return NS_OK;
}
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(CheckSecurityWidthAndHeight(nsnull, &aOuterHeight),
NS_ERROR_FAILURE);
PRInt32 width, notused;
NS_ENSURE_SUCCESS(treeOwnerAsWin->GetSize(&width, &notused), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(treeOwnerAsWin->SetSize(width, aOuterHeight, PR_TRUE),
NS_ERROR_FAILURE);
return NS_OK;
return SetOuterSize(aOuterHeight, PR_FALSE);
}
NS_IMETHODIMP

Просмотреть файл

@ -585,6 +585,9 @@ protected:
nsresult GetScrollXY(PRInt32* aScrollX, PRInt32* aScrollY,
PRBool aDoFlush);
nsresult GetScrollMaxXY(PRInt32* aScrollMaxX, PRInt32* aScrollMaxY);
nsresult GetOuterSize(nsIntSize* aSizeCSSPixels);
nsresult SetOuterSize(PRInt32 aLengthCSSPixels, PRBool aIsWidth);
PRBool IsFrame()
{