Bug 345339, attachment 243112: Revisit nsPresState, patch by Karthik Sarma <karthik3@comcast.net>, r+sr=roc

git-svn-id: svn://10.0.0.236/trunk@214778 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
gavin%gavinsharp.com
2006-11-06 16:08:20 +00:00
parent 8c619e0101
commit b1ef96b548
6 changed files with 91 additions and 93 deletions

View File

@@ -2712,76 +2712,28 @@ nsGfxScrollFrameInner::SaveState(nsIStatefulFrame::SpecialStateID aStateID)
}
nsRect childRect = child->GetBounds();
childRect.x = x;
childRect.y = y;
nsAutoPtr<nsPresState> state;
nsresult rv = NS_NewPresState(getter_Transfers(state));
NS_ENSURE_SUCCESS(rv, nsnull);
nsCOMPtr<nsISupportsPRInt32> xoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
if (xoffset) {
rv = xoffset->SetData(x);
NS_ENSURE_SUCCESS(rv, nsnull);
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), xoffset);
}
state->SetScrollState(childRect);
nsCOMPtr<nsISupportsPRInt32> yoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
if (yoffset) {
rv = yoffset->SetData(y);
NS_ENSURE_SUCCESS(rv, nsnull);
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), yoffset);
}
nsCOMPtr<nsISupportsPRInt32> width = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
if (width) {
rv = width->SetData(childRect.width);
NS_ENSURE_SUCCESS(rv, nsnull);
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("width"), width);
}
nsCOMPtr<nsISupportsPRInt32> height = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
if (height) {
rv = height->SetData(childRect.height);
NS_ENSURE_SUCCESS(rv, nsnull);
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("height"), height);
}
return state.forget();
}
void
nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
{
nsCOMPtr<nsISupportsPRInt32> xoffset;
nsCOMPtr<nsISupportsPRInt32> yoffset;
nsCOMPtr<nsISupportsPRInt32> width;
nsCOMPtr<nsISupportsPRInt32> height;
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), getter_AddRefs(xoffset));
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), getter_AddRefs(yoffset));
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("width"), getter_AddRefs(width));
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("height"), getter_AddRefs(height));
if (xoffset && yoffset) {
PRInt32 x,y,w,h;
nsresult rv = xoffset->GetData(&x);
if (NS_SUCCEEDED(rv))
rv = yoffset->GetData(&y);
if (NS_SUCCEEDED(rv))
rv = width->GetData(&w);
if (NS_SUCCEEDED(rv))
rv = height->GetData(&h);
mLastPos.x = -1;
mLastPos.y = -1;
mRestoreRect.SetRect(-1, -1, -1, -1);
// don't do it now, store it later and do it in layout.
if (NS_SUCCEEDED(rv)) {
mRestoreRect.SetRect(x, y, w, h);
mDidHistoryRestore = PR_TRUE;
nsIScrollableView* scrollingView = GetScrollableView();
if (scrollingView) {
scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
} else {
mLastPos = nsPoint(0, 0);
}
}
mRestoreRect = aState->GetScrollState();
mLastPos.x = -1;
mLastPos.y = -1;
mDidHistoryRestore = PR_TRUE;
nsIScrollableView* scrollingView = GetScrollableView();
if (scrollingView) {
scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
} else {
mLastPos = nsPoint(0, 0);
}
}