fix for #18196 - fix off-by-one errors with trees that have headers - EnsureRowIsVisible and IsValidRow expect zero-based rows, not row-index based rows

r=hyatt
This commit is contained in:
alecf%netscape.com 1999-11-16 19:07:34 +00:00
parent 97044a6c33
commit 362d7a861c
2 changed files with 38 additions and 7 deletions

View File

@ -1409,7 +1409,8 @@ nsTreeRowGroupFrame::IndexOfCell(nsIPresContext& aPresContext,
// To determine the column index, just ask what our indexOf is. // To determine the column index, just ask what our indexOf is.
row->IndexOf(aCellContent, aColIndex); row->IndexOf(aCellContent, aColIndex);
} }
// returns the 0-based index of the content node, within the content tree
void void
nsTreeRowGroupFrame::IndexOfRow(nsIPresContext& aPresContext, nsTreeRowGroupFrame::IndexOfRow(nsIPresContext& aPresContext,
nsIContent* aRowContent, PRInt32& aRowIndex) nsIContent* aRowContent, PRInt32& aRowIndex)
@ -1443,6 +1444,11 @@ nsTreeRowGroupFrame::IndexOfRow(nsIPresContext& aPresContext,
PRBool PRBool
nsTreeRowGroupFrame::IsValidRow(PRInt32 aRowIndex) nsTreeRowGroupFrame::IsValidRow(PRInt32 aRowIndex)
{ {
// adjust for zero-based mRowCount
nsTableRowFrame* firstRow=nsnull;
GetFirstRow(&firstRow);
aRowIndex -= firstRow->GetRowIndex();
if (aRowIndex >= 0 && aRowIndex < mRowCount) if (aRowIndex >= 0 && aRowIndex < mRowCount)
return PR_TRUE; return PR_TRUE;
return PR_FALSE; return PR_FALSE;
@ -1454,9 +1460,14 @@ nsTreeRowGroupFrame::EnsureRowIsVisible(PRInt32 aRowIndex)
// if no scrollbar, then it must be visible // if no scrollbar, then it must be visible
if (!mScrollbar) return; if (!mScrollbar) return;
// adjust row index for zero-based scrollbar
nsTableRowFrame* firstRow=nsnull;
GetFirstRow(&firstRow);
aRowIndex -= firstRow->GetRowIndex();
PRInt32 rows; PRInt32 rows;
GetRowCount(rows); GetRowCount(rows);
PRInt32 bottomIndex = mCurrentIndex +rows - 1; PRInt32 bottomIndex = mCurrentIndex + rows - 1;
// if row is visible, ignore // if row is visible, ignore
if (mCurrentIndex <= aRowIndex && aRowIndex <= bottomIndex) if (mCurrentIndex <= aRowIndex && aRowIndex <= bottomIndex)
@ -1473,7 +1484,7 @@ nsTreeRowGroupFrame::EnsureRowIsVisible(PRInt32 aRowIndex)
PRInt32 scrollTo = mCurrentIndex; PRInt32 scrollTo = mCurrentIndex;
if (aRowIndex < mCurrentIndex) { if (aRowIndex < mCurrentIndex) {
// row is above us, scroll up from mCurrentIndex // row is above us, scroll up from mCurrentIndex
// scroll such that mCurrentIndex = aRowIndex // scroll such that the top row is aRowIndex
#ifdef DEBUG_tree #ifdef DEBUG_tree
printf("row is above, scroll to %d\n", aRowIndex); printf("row is above, scroll to %d\n", aRowIndex);
#endif #endif
@ -1481,7 +1492,7 @@ nsTreeRowGroupFrame::EnsureRowIsVisible(PRInt32 aRowIndex)
} else { } else {
// aRowIndex > bottomIndex here // aRowIndex > bottomIndex here
// row is below us, so scroll down from bottomIndex // row is below us, so scroll down from bottomIndex
// scroll such that mCurrentIndex = (aRowIndex - aRowCount) // scroll such that the top row is "rows" above aRowIndex
NS_ASSERTION(aRowIndex - rows >=0, "scrolling to negative row?!"); NS_ASSERTION(aRowIndex - rows >=0, "scrolling to negative row?!");
scrollTo=aRowIndex - rows + 1; scrollTo=aRowIndex - rows + 1;
#ifdef DEBUG_tree #ifdef DEBUG_tree
@ -1502,10 +1513,7 @@ nsTreeRowGroupFrame::EnsureRowIsVisible(PRInt32 aRowIndex)
value=""; value="";
#endif #endif
// scrollTo++; // off by one?
value.Append(scrollTo); value.Append(scrollTo);
//rv = scrollbarContent->GetAttribute(kNamespaceID_None, nsXULAtoms::curpos,
// value, PR_TRUE);
scrollbarContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::curpos, scrollbarContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::curpos,
value, PR_TRUE); value, PR_TRUE);
} }
@ -1677,6 +1685,28 @@ nsTreeRowGroupFrame::GetInsertionIndex(nsIFrame *aFrame, PRInt32 aCurrentIndex,
return index; return index;
} }
void
nsTreeRowGroupFrame::GetFirstRow(nsTableRowFrame **aRowFrame)
{
nsIFrame* child = mFrames.FirstChild();
while (child) {
if (IsTableRowFrame(child)) {
*aRowFrame = (nsTableRowFrame*)child;
return;
}
if (IsTableRowGroupFrame(child)) {
((nsTreeRowGroupFrame*)child)->GetFirstRow(aRowFrame);
if (*aRowFrame) return;
}
child->GetNextSibling(&child);
}
return;
}
// //
// pinkerton // pinkerton
// code copied from the toolbar to bootstrap tree d&d. I hope to god // code copied from the toolbar to bootstrap tree d&d. I hope to god

View File

@ -150,6 +150,7 @@ protected:
void PostAppendRow(nsIFrame* aRowFrame, nsIPresContext& aPresContext); void PostAppendRow(nsIFrame* aRowFrame, nsIPresContext& aPresContext);
void GetFirstRow(nsTableRowFrame **aRowFrame);
public: public:
// Helpers that allow access to info. The tree is the primary consumer of this // Helpers that allow access to info. The tree is the primary consumer of this