Bug 62713: Only save scroll position in SH if offset from origin, only put entries in state table if state was created, cleanups, r=jst@netscape.com, sr=vidur@netscape.com

git-svn-id: svn://10.0.0.236/trunk@86291 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pollmann%netscape.com
2001-02-06 02:32:04 +00:00
parent 5f8747c230
commit c7b33ed83b
4 changed files with 112 additions and 95 deletions

View File

@@ -998,64 +998,70 @@ NS_IMETHODIMP
nsScrollFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState)
{
NS_ENSURE_ARG_POINTER(aState);
nsCOMPtr<nsIPresState> state;
nsresult res = NS_OK;
nsIView* view;
GetView(aPresContext, &view);
NS_ENSURE_TRUE(view, NS_ERROR_FAILURE);
PRInt32 x,y;
nsIScrollableView* scrollingView;
nsIView* view;
GetView(aPresContext, &view);
if (NS_SUCCEEDED(view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView))) {
scrollingView->GetScrollPosition(x,y);
}
nsIView* child = nsnull;
nsRect childRect(0,0,0,0);
if (NS_SUCCEEDED(scrollingView->GetScrolledView(child)) && child) {
child->GetBounds(childRect);
}
res = view->QueryInterface(NS_GET_IID(nsIScrollableView), (void**)&scrollingView);
NS_ENSURE_SUCCESS(res, res);
scrollingView->GetScrollPosition(x,y);
res = NS_NewPresState(aState);
nsCOMPtr<nsISupportsPRInt32> xoffset;
if (NS_SUCCEEDED(res)) {
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(xoffset));
if (NS_SUCCEEDED(res) && xoffset) {
// Don't save scroll position if we are at (0,0)
if (x || y) {
nsIView* child = nsnull;
scrollingView->GetScrolledView(child);
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
nsRect childRect(0,0,0,0);
child->GetBounds(childRect);
res = NS_NewPresState(getter_AddRefs(state));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsISupportsPRInt32> xoffset;
nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(xoffset));
if (xoffset) {
res = xoffset->SetData(x);
if (NS_SUCCEEDED(res)) {
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("x-offset"), xoffset);
}
NS_ENSURE_SUCCESS(res, res);
state->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("x-offset"), xoffset);
}
}
nsCOMPtr<nsISupportsPRInt32> yoffset;
if (NS_SUCCEEDED(res)) {
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(yoffset));
if (NS_SUCCEEDED(res) && yoffset) {
nsCOMPtr<nsISupportsPRInt32> yoffset;
nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(yoffset));
if (yoffset) {
res = yoffset->SetData(y);
if (NS_SUCCEEDED(res)) {
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("y-offset"), yoffset);
}
NS_ENSURE_SUCCESS(res, res);
state->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("y-offset"), yoffset);
}
}
nsCOMPtr<nsISupportsPRInt32> width;
if (NS_SUCCEEDED(res)) {
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(width));
if (NS_SUCCEEDED(res) && width) {
nsCOMPtr<nsISupportsPRInt32> width;
nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(width));
if (width) {
res = width->SetData(childRect.width);
if (NS_SUCCEEDED(res)) {
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("width"), width);
}
NS_ENSURE_SUCCESS(res, res);
state->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("width"), width);
}
}
nsCOMPtr<nsISupportsPRInt32> height;
if (NS_SUCCEEDED(res)) {
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(height));
if (NS_SUCCEEDED(res) && height) {
nsCOMPtr<nsISupportsPRInt32> height;
nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(height));
if (height) {
res = height->SetData(childRect.height);
if (NS_SUCCEEDED(res)) {
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("height"), height);
}
NS_ENSURE_SUCCESS(res, res);
state->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("height"), height);
}
*aState = state;
NS_ADDREF(*aState);
}
return res;
}
@@ -1065,6 +1071,8 @@ NS_IMETHODIMP
nsScrollFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
nsCOMPtr<nsISupportsPRInt32> xoffset;
nsCOMPtr<nsISupportsPRInt32> yoffset;
nsCOMPtr<nsISupportsPRInt32> width;