diff --git a/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/layout/xul/base/src/nsTreeRowGroupFrame.cpp index cf99ddf93dfe..4ea7e136536f 100644 --- a/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -221,11 +221,13 @@ nsTreeRowGroupFrame::FindPreviousRowContent(PRInt32& aDelta, nsIContent* aUpward parentContent->ChildCount(index); } + /* Let me see inside the damn nsCOMptrs nsIAtom* aAtom; parentContent->GetTag(aAtom); nsString result; aAtom->ToString(result); - + */ + for (PRInt32 i = index-1; i >= 0; i--) { nsCOMPtr childContent; parentContent->ChildAt(i, *getter_AddRefs(childContent)); @@ -538,8 +540,9 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext& aPresContext) // We may just be a normal row group. if (!mIsLazy) return mFrames.FirstChild(); - - if (mTopFrame) + + // If we have a frame and no content chain (e.g., unresolved/uncreated content) + if (mTopFrame && !mContentChain) return mTopFrame; // See if we have any frame whatsoever. @@ -547,21 +550,55 @@ nsTreeRowGroupFrame::GetFirstFrameForReflow(nsIPresContext& aPresContext) mBottomFrame = mTopFrame; - if (mTopFrame) - return mTopFrame; + nsCOMPtr startContent; + if (mTopFrame) { + if (!mContentChain) + return mTopFrame; + + // We have a content chain. If the top frame is the same as our content + // chain, we can go ahead and destroy our content chain and return the + // top frame. + nsCOMPtr topContent; + mTopFrame->GetContent(getter_AddRefs(topContent)); + nsCOMPtr supports; + mContentChain->GetElementAt(0, getter_AddRefs(supports)); + nsCOMPtr chainContent = do_QueryInterface(supports); + if (chainContent.get() == topContent.get()) { + // The two content nodes are the same. Our content chain has + // been synched up, and we can now remove our element and + // pass the content chain inwards. + mContentChain->RemoveElementAt(0); + PRUint32 chainSize; + mContentChain->Count(&chainSize); + if (chainSize > 0) { + ((nsTreeRowGroupFrame*)mTopFrame)->SetContentChain(mContentChain); + } + + // The chain is dead. Long live the chain. + NS_RELEASE(mContentChain); + mContentChain = nsnull; + } + startContent = chainContent; + } // We don't have a top frame instantiated. Let's // try to make one. // If we have a content chain, use that content node to make our frame, // and prepare a sub-content chain for the new child frame that we make. - - PRInt32 childCount; - mContent->ChildCount(childCount); - nsCOMPtr childContent; - if (childCount > 0) { - mContent->ChildAt(0, *getter_AddRefs(childContent)); - mFrameConstructor->CreateTreeWidgetContent(&aPresContext, this, childContent, + // Otherwise just grab the first child. + if (!startContent) { + PRInt32 childCount; + mContent->ChildCount(childCount); + nsCOMPtr childContent; + if (childCount > 0) { + mContent->ChildAt(0, *getter_AddRefs(childContent)); + startContent = childContent; + } + } + + if (startContent) { + mFrameConstructor->CreateTreeWidgetContent(&aPresContext, this, startContent, &mTopFrame); printf("Created a frame\n"); mBottomFrame = mTopFrame; @@ -661,3 +698,10 @@ void nsTreeRowGroupFrame::OnContentAdded(nsIPresContext& aPresContext) } } } + +void nsTreeRowGroupFrame::SetContentChain(nsISupportsArray* aContentChain) +{ + NS_IF_RELEASE(mContentChain); + mContentChain = aContentChain; + NS_IF_ADDREF(mContentChain); +} \ No newline at end of file diff --git a/layout/xul/base/src/nsTreeRowGroupFrame.h b/layout/xul/base/src/nsTreeRowGroupFrame.h index a4f0b2ab7cb4..03fda7ad1393 100644 --- a/layout/xul/base/src/nsTreeRowGroupFrame.h +++ b/layout/xul/base/src/nsTreeRowGroupFrame.h @@ -87,6 +87,8 @@ protected: void LocateFrame(nsIFrame* aStartFrame, nsIFrame** aResult); + void SetContentChain(nsISupportsArray* aContentChain); + void ConstructContentChain(nsIContent* aRowContent); void FindPreviousRowContent(PRInt32& aDelta, nsIContent* aUpwardHint, nsIContent* aDownwardHint, nsIContent** aResult);