This commit is contained in:
Olli.Pettay%helsinki.fi 2007-03-13 22:11:14 +00:00
Родитель 3e9933122b
Коммит 6ba0c9dc46
2 изменённых файлов: 50 добавлений и 32 удалений

Просмотреть файл

@ -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<nsIContent> vScroll =
mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull;
nsCOMPtr<nsIContent> 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

Просмотреть файл

@ -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