From 887e2768fe7d35417e808735d4d6c12aa6521ce6 Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Wed, 11 Oct 2000 00:36:30 +0000 Subject: [PATCH] Fix for 46877, scroll position not being remembered in session history. patch is by evaughan. r=pink a=hyatt --- layout/xul/base/src/nsScrollBoxFrame.cpp | 56 +++++++++++++++++------- layout/xul/base/src/nsScrollBoxFrame.h | 5 ++- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/layout/xul/base/src/nsScrollBoxFrame.cpp b/layout/xul/base/src/nsScrollBoxFrame.cpp index c5de32ca4abd..693990816152 100644 --- a/layout/xul/base/src/nsScrollBoxFrame.cpp +++ b/layout/xul/base/src/nsScrollBoxFrame.cpp @@ -74,7 +74,8 @@ NS_NewScrollBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) return NS_OK; } -nsScrollBoxFrame::nsScrollBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell), mVerticalOverflow(PR_FALSE), mHorizontalOverflow(PR_FALSE) +nsScrollBoxFrame::nsScrollBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell), mVerticalOverflow(PR_FALSE), mHorizontalOverflow(PR_FALSE), + mRestoreRect(-1,-1,-1,-1) { } @@ -473,6 +474,39 @@ nsScrollBoxFrame::DoLayout(nsBoxLayoutState& aState) PostScrollPortEvent(shell, mHorizontalOverflow, nsScrollPortEvent::horizontal); } + + + if (mRestoreRect.y != -1) { + // if we are supposed to restore + nsIPresContext* presContext = aState.GetPresContext(); + nsIScrollableView* scrollingView; + nsIView* view; + GetView(presContext, &view); + if (NS_SUCCEEDED(view->QueryInterface(kScrollViewIID, (void**)&scrollingView))) { + + nsIView* child = nsnull; + nsRect childRect(0,0,0,0); + if (NS_SUCCEEDED(scrollingView->GetScrolledView(child)) && child) { + child->GetBounds(childRect); + } + + PRInt32 cx,cy,x,y; + scrollingView->GetScrollPosition(cx,cy); + + x = (int)(((float)childRect.width / mRestoreRect.width) * mRestoreRect.x); + y = (int)(((float)childRect.height / mRestoreRect.height) * mRestoreRect.y); + + // 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) + scrollingView->ScrollTo(x,y,0); + else // if we reached the position then stop + mRestoreRect.y = -1; + } + } + + return NS_OK; } @@ -730,23 +764,11 @@ nsScrollBoxFrame::RestoreState(nsIPresContext* aPresContext, if (NS_SUCCEEDED(res)) res = height->GetData(&h); + // don't do it now store it later and do it in layout. if (NS_SUCCEEDED(res)) { - - nsIScrollableView* scrollingView; - nsIView* view; - GetView(aPresContext, &view); - if (NS_SUCCEEDED(view->QueryInterface(kScrollViewIID, (void**)&scrollingView))) { - - nsIView* child = nsnull; - nsRect childRect(0,0,0,0); - if (NS_SUCCEEDED(scrollingView->GetScrolledView(child)) && child) { - child->GetBounds(childRect); - } - x = (int)(((float)childRect.width / w) * x); - y = (int)(((float)childRect.height / h) * y); - - scrollingView->ScrollTo(x,y,0); - } + mRestoreRect.SetRect(x,y,w,h); + } else { + mRestoreRect.SetRect(-1,-1,-1,-1); } } diff --git a/layout/xul/base/src/nsScrollBoxFrame.h b/layout/xul/base/src/nsScrollBoxFrame.h index f4f9deee5d1f..c5eca443a4e4 100644 --- a/layout/xul/base/src/nsScrollBoxFrame.h +++ b/layout/xul/base/src/nsScrollBoxFrame.h @@ -120,8 +120,9 @@ protected: private: nsresult CreateScrollingView(nsIPresContext* aPresContext); - PRBool mVerticalOverflow; - PRBool mHorizontalOverflow; + PRPackedBool mVerticalOverflow; + PRPackedBool mHorizontalOverflow; + nsRect mRestoreRect; protected: virtual PRBool NeedsClipWidget();