Skip to content

Commit

Permalink
Bug 630919, add collect and invalidate phases for tree ranges, r=enn+…
Browse files Browse the repository at this point in the history
…neil, a=jst

--HG--
extra : rebase_source : 0a714e7f3829f9641340e47a83f386ab7a0d0905
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Mar 1, 2011
1 parent 5db80a9 commit f39d329
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions layout/xul/base/src/tree/src/nsTreeSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,40 @@ struct nsTreeRange
return total;
}

static void CollectRanges(nsTreeRange* aRange, nsTArray<PRInt32>& aRanges)
{
nsTreeRange* cur = aRange;
while (cur) {
aRanges.AppendElement(cur->mMin);
aRanges.AppendElement(cur->mMax);
cur = cur->mNext;
}
}

static void InvalidateRanges(nsITreeBoxObject* aTree,
nsTArray<PRInt32>& aRanges)
{
if (aTree) {
nsCOMPtr<nsITreeBoxObject> tree = aTree;
for (PRUint32 i = 0; i < aRanges.Length(); i += 2) {
aTree->InvalidateRange(aRanges[i], aRanges[i + 1]);
}
}
}

void Invalidate() {
if (mSelection->mTree)
mSelection->mTree->InvalidateRange(mMin, mMax);
if (mNext)
mNext->Invalidate();
nsTArray<PRInt32> ranges;
CollectRanges(this, ranges);
InvalidateRanges(mSelection->mTree, ranges);

}

void RemoveAllBut(PRInt32 aIndex) {
if (aIndex >= mMin && aIndex <= mMax) {

// Invalidate everything in this list.
mSelection->mFirstRange->Invalidate();
nsTArray<PRInt32> ranges;
CollectRanges(mSelection->mFirstRange, ranges);

mMin = aIndex;
mMax = aIndex;
Expand All @@ -239,6 +261,7 @@ struct nsTreeRange
delete mSelection->mFirstRange;
mSelection->mFirstRange = this;
}
InvalidateRanges(mSelection->mTree, ranges);
}
else if (mNext)
mNext->RemoveAllBut(aIndex);
Expand Down Expand Up @@ -453,6 +476,7 @@ NS_IMETHODIMP nsTreeSelection::RangedSelect(PRInt32 aStartIndex, PRInt32 aEndInd
if (mFirstRange) {
mFirstRange->Invalidate();
delete mFirstRange;
mFirstRange = nsnull;
}
}

Expand Down

0 comments on commit f39d329

Please sign in to comment.