From 6ba0c9dc46d6937f0482a03a39bb3cad597af301 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Tue, 13 Mar 2007 22:11:14 +0000 Subject: [PATCH] Bug 373564, r+sr=roc --- layout/generic/nsGfxScrollFrame.cpp | 73 +++++++++++++++++------------ layout/generic/nsGfxScrollFrame.h | 9 +++- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index b859a7509cf..fdfaf563669 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1737,11 +1737,11 @@ void nsGfxScrollFrameInner::InternalScrollPositionDidChange(nscoord aX, nscoord aY) { if (mVScrollbarBox) - SetCoordAttribute(mVScrollbarBox, nsGkAtoms::curpos, + SetCoordAttribute(mVScrollbarBox->GetContent(), nsGkAtoms::curpos, aY - GetScrolledRect(GetScrollPortSize()).y); if (mHScrollbarBox) - SetCoordAttribute(mHScrollbarBox, nsGkAtoms::curpos, + SetCoordAttribute(mHScrollbarBox->GetContent(), nsGkAtoms::curpos, aX - GetScrolledRect(GetScrollPortSize()).x); } @@ -2302,6 +2302,21 @@ nsXULScrollFrame::Layout(nsBoxLayoutState& aState) return NS_OK; } +void +nsGfxScrollFrameInner::FinishReflowForScrollbar(nsIContent* aContent, + nscoord aMinXY, nscoord aMaxXY, + nscoord aCurPosXY, + nscoord aPageIncrement, + nscoord aIncrement) +{ + // Scrollbars assume zero is the minimum position, so translate for them. + SetCoordAttribute(aContent, nsGkAtoms::curpos, aCurPosXY - aMinXY); + SetScrollbarEnabled(aContent, aMaxXY - aMinXY); + SetCoordAttribute(aContent, nsGkAtoms::maxpos, aMaxXY - aMinXY); + SetCoordAttribute(aContent, nsGkAtoms::pageincrement, aPageIncrement); + SetCoordAttribute(aContent, nsGkAtoms::increment, aIncrement); +} + PRBool nsGfxScrollFrameInner::ReflowFinished() { @@ -2332,28 +2347,28 @@ nsGfxScrollFrameInner::ReflowFinished() NS_ASSERTION(!mFrameInitiatedScroll, "We shouldn't be reentering here"); mFrameInitiatedScroll = PR_TRUE; - if (mVScrollbarBox) { - NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!"); - nscoord curPosX, curPosY; - scrollable->GetScrollPosition(curPosX, curPosY); - // Scrollbars assume zero is the minimum position, so translate for them. - SetCoordAttribute(mVScrollbarBox, nsGkAtoms::curpos, curPosY - minY); - SetScrollbarEnabled(mVScrollbarBox, maxY - minY); - SetCoordAttribute(mVScrollbarBox, nsGkAtoms::maxpos, maxY - minY); - SetCoordAttribute(mVScrollbarBox, nsGkAtoms::pageincrement, nscoord(scrollArea.height - fontHeight)); - SetCoordAttribute(mVScrollbarBox, nsGkAtoms::increment, fontHeight); - } + nsCOMPtr vScroll = + mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull; + nsCOMPtr hScroll = + mHScrollbarBox ? mHScrollbarBox->GetContent() : nsnull; - if (mHScrollbarBox) { - NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!"); + // Note, in some cases mOuter may get deleted while finishing reflow + // for scrollbars. + if (vScroll || hScroll) { + nsWeakFrame weakFrame(mOuter); nscoord curPosX, curPosY; scrollable->GetScrollPosition(curPosX, curPosY); - // Scrollbars assume zero is the minimum position, so translate for them. - SetCoordAttribute(mHScrollbarBox, nsGkAtoms::curpos, curPosX - minX); - SetScrollbarEnabled(mHScrollbarBox, maxX - minX); - SetCoordAttribute(mHScrollbarBox, nsGkAtoms::maxpos, maxX - minX); - SetCoordAttribute(mHScrollbarBox, nsGkAtoms::pageincrement, nscoord(float(scrollArea.width)*0.8)); - SetCoordAttribute(mHScrollbarBox, nsGkAtoms::increment, nsPresContext::CSSPixelsToAppUnits(10)); + if (vScroll) { + FinishReflowForScrollbar(vScroll, minY, maxY, curPosY, + nscoord(scrollArea.height - fontHeight), + fontHeight); + } + if (hScroll) { + FinishReflowForScrollbar(hScroll, minX, maxX, curPosX, + nscoord(float(scrollArea.width) * 0.8), + nsPresContext::CSSPixelsToAppUnits(10)); + } + NS_ENSURE_TRUE(weakFrame.IsAlive(), PR_FALSE); } mFrameInitiatedScroll = PR_FALSE; @@ -2470,19 +2485,18 @@ nsGfxScrollFrameInner::ScrollbarChanged(nsPresContext* aPresContext, nscoord aX, } void -nsGfxScrollFrameInner::SetScrollbarEnabled(nsIBox* aBox, nscoord aMaxPos) +nsGfxScrollFrameInner::SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos) { - nsIContent* content = aBox->GetContent(); if (aMaxPos) { - content->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE); + aContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE); } else { - content->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, - NS_LITERAL_STRING("true"), PR_TRUE); + aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, + NS_LITERAL_STRING("true"), PR_TRUE); } } void -nsGfxScrollFrameInner::SetCoordAttribute(nsIBox* aBox, nsIAtom* aAtom, +nsGfxScrollFrameInner::SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom, nscoord aSize) { // convert to pixels @@ -2493,11 +2507,10 @@ nsGfxScrollFrameInner::SetCoordAttribute(nsIBox* aBox, nsIAtom* aAtom, nsAutoString newValue; newValue.AppendInt(aSize); - nsIContent* content = aBox->GetContent(); - if (content->AttrValueIs(kNameSpaceID_None, aAtom, newValue, eCaseMatters)) + if (aContent->AttrValueIs(kNameSpaceID_None, aAtom, newValue, eCaseMatters)) return; - content->SetAttr(kNameSpaceID_None, aAtom, newValue, PR_TRUE); + aContent->SetAttr(kNameSpaceID_None, aAtom, newValue, PR_TRUE); } nsRect diff --git a/layout/generic/nsGfxScrollFrame.h b/layout/generic/nsGfxScrollFrame.h index dd5f5b6df3d..48df9fba2eb 100644 --- a/layout/generic/nsGfxScrollFrame.h +++ b/layout/generic/nsGfxScrollFrame.h @@ -125,8 +125,13 @@ public: nsGfxScrollFrameInner *mInner; }; - void SetScrollbarEnabled(nsIBox* aBox, nscoord aMaxPos); - void SetCoordAttribute(nsIBox* aBox, nsIAtom* aAtom, nscoord aSize); + static void FinishReflowForScrollbar(nsIContent* aContent, nscoord aMinXY, + nscoord aMaxXY, nscoord aCurPosXY, + nscoord aPageIncrement, + nscoord aIncrement); + static void SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos); + static void SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom, + nscoord aSize); nscoord GetCoordAttribute(nsIBox* aFrame, nsIAtom* atom, nscoord defaultValue); // Like ScrollPositionDidChange, but initiated by this frame rather than from the