diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index f31f3abe72f..8161882821f 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -2034,7 +2034,7 @@ FrameManager::CaptureFrameStateFor(nsIPresContext* aPresContext, nsIFrame* aFram // Get the state nsCOMPtr frameState; rv = statefulFrame->SaveState(aPresContext, getter_AddRefs(frameState)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && frameState) { // add an association between (ID, type) and (state) to the // history state storage object, aState. diff --git a/mozilla/layout/html/base/src/nsFrameManager.cpp b/mozilla/layout/html/base/src/nsFrameManager.cpp index f31f3abe72f..8161882821f 100644 --- a/mozilla/layout/html/base/src/nsFrameManager.cpp +++ b/mozilla/layout/html/base/src/nsFrameManager.cpp @@ -2034,7 +2034,7 @@ FrameManager::CaptureFrameStateFor(nsIPresContext* aPresContext, nsIFrame* aFram // Get the state nsCOMPtr frameState; rv = statefulFrame->SaveState(aPresContext, getter_AddRefs(frameState)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && frameState) { // add an association between (ID, type) and (state) to the // history state storage object, aState. diff --git a/mozilla/layout/html/base/src/nsScrollFrame.cpp b/mozilla/layout/html/base/src/nsScrollFrame.cpp index 5510e934685..0e85fcfb124 100644 --- a/mozilla/layout/html/base/src/nsScrollFrame.cpp +++ b/mozilla/layout/html/base/src/nsScrollFrame.cpp @@ -998,64 +998,70 @@ NS_IMETHODIMP nsScrollFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) { + NS_ENSURE_ARG_POINTER(aState); + nsCOMPtr 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 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 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 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 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 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 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 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 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 xoffset; nsCOMPtr yoffset; nsCOMPtr width; diff --git a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp index ce6ccc28582..bb8e3a77001 100644 --- a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp @@ -497,7 +497,7 @@ nsScrollBoxFrame::DoLayout(nsBoxLayoutState& aState) // if our position is greater than the scroll position scroll. // remember we could be incrementally loading so we may enter and // scroll many times. - if (y > cy) + if (y > cy || x > cx) scrollingView->ScrollTo(x,y,0); else // if we reached the position then stop mRestoreRect.y = -1; @@ -667,6 +667,8 @@ NS_IMETHODIMP nsScrollBoxFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) { + NS_ENSURE_ARG_POINTER(aState); + nsCOMPtr mediator; nsIFrame* first = mFrames.FirstChild(); mediator = do_QueryInterface(first); @@ -675,64 +677,69 @@ nsScrollBoxFrame::SaveState(nsIPresContext* aPresContext, return NS_OK; } + nsCOMPtr 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 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 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 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 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 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 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 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 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; } @@ -742,6 +749,8 @@ NS_IMETHODIMP nsScrollBoxFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) { + NS_ENSURE_ARG_POINTER(aState); + nsCOMPtr xoffset; nsCOMPtr yoffset; nsCOMPtr width;