diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 197776af853..f70eff0e97a 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -1694,8 +1694,7 @@ MoveChildrenTo(nsFrameManager* aFrameManager, // anonymous block frame, but oddly they aren't -- need to // investigate that...) if (aNewParentSC) - aPresContext->FrameManager()->ReParentStyleContext(aFrameList, - aNewParentSC); + aPresContext->FrameManager()->ReParentStyleContext(aFrameList); #endif aFrameList = aFrameList->GetNextSibling(); @@ -3798,8 +3797,7 @@ nsCSSFrameConstructor::ConstructTableColFrame(nsFrameConstructorState& aState, aNewFrame); // if the parent frame was anonymous then reparent the style context if (aIsPseudoParent) { - aState.mFrameManager-> - ReParentStyleContext(aNewFrame, parentFrame->GetStyleContext()); + aState.mFrameManager->ReParentStyleContext(aNewFrame); } // construct additional col frames if the col frame has a span > 1 @@ -12089,14 +12087,12 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState, // Support for :first-line style static void -ReparentFrame(nsPresContext* aPresContext, +ReparentFrame(nsFrameManager* aFrameManager, nsIFrame* aNewParentFrame, - nsStyleContext* aParentStyleContext, nsIFrame* aFrame) { aFrame->SetParent(aNewParentFrame); - aPresContext->FrameManager()->ReParentStyleContext(aFrame, - aParentStyleContext); + aFrameManager->ReParentStyleContext(aFrame); } // Special routine to handle placing a list of frames into a block @@ -12162,8 +12158,10 @@ nsCSSFrameConstructor::WrapFramesInFirstLineFrame( // Give the inline frames to the lineFrame after reparenting them kid = firstInlineFrame; + NS_ASSERTION(lineFrame->GetStyleContext() == firstLineStyle, + "Bogus style context on line frame"); while (kid) { - ReparentFrame(aState.mPresContext, lineFrame, firstLineStyle, kid); + ReparentFrame(aState.mFrameManager, lineFrame, kid); kid = kid->GetNextSibling(); } lineFrame->SetInitialChildList(aState.mPresContext, nsnull, @@ -12204,7 +12202,6 @@ nsCSSFrameConstructor::AppendFirstLineFrames( return rv; } nsIFrame* lineFrame = lastBlockKid; - nsStyleContext* firstLineStyle = lineFrame->GetStyleContext(); // Find the first and last inline frame in aFrameItems nsIFrame* kid = aFrameItems.childList; @@ -12232,7 +12229,7 @@ nsCSSFrameConstructor::AppendFirstLineFrames( lastInlineFrame->SetNextSibling(nsnull); kid = firstInlineFrame; while (kid) { - ReparentFrame(aState.mPresContext, lineFrame, firstLineStyle, kid); + ReparentFrame(aState.mFrameManager, lineFrame, kid); kid = kid->GetNextSibling(); } aState.mFrameManager->AppendFrames(lineFrame, nsnull, firstInlineFrame); @@ -12274,12 +12271,10 @@ nsCSSFrameConstructor::InsertFirstLineFrames( if (firstBlockKid->GetType() == nsLayoutAtoms::lineFrame) { // We already have a first-line frame nsIFrame* lineFrame = firstBlockKid; - nsStyleContext* firstLineStyle = lineFrame->GetStyleContext(); if (isInline) { // Easy case: the new inline frame will go into the lineFrame. - ReparentFrame(aState.mPresContext, lineFrame, firstLineStyle, - newFrame); + ReparentFrame(aState.mFrameManager, lineFrame, newFrame); aState.mFrameManager->InsertFrames(lineFrame, nsnull, nsnull, newFrame); @@ -12317,7 +12312,9 @@ nsCSSFrameConstructor::InsertFirstLineFrames( // Give the inline frames to the lineFrame after // reparenting them - ReparentFrame(aPresContext, lineFrame, firstLineStyle, newFrame); + NS_ASSERTION(lineFrame->GetStyleContext() == firstLineStyle, + "Bogus style context on line frame"); + ReparentFrame(aPresContext, lineFrame, newFrame); lineFrame->SetInitialChildList(aState.mPresContext, nsnull, newFrame); } @@ -12376,8 +12373,7 @@ nsCSSFrameConstructor::InsertFirstLineFrames( else { // We got lucky: aPrevSibling was the last inline frame in // the line-frame. - ReparentFrame(aState.mPresContext, aBlockFrame, firstLineStyle, - newFrame); + ReparentFrame(aState.mFrameManager, aBlockFrame, newFrame); aState.mFrameManager->InsertFrames(aBlockFrame, nsnull, prevSiblingParent, newFrame); aFrameItems.childList = nsnull; diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index 086c5b26942..5ac5b94cb2f 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -914,82 +914,98 @@ nsFrameManager::DebugVerifyStyleTree(nsIFrame* aFrame) #endif // DEBUG nsresult -nsFrameManager::ReParentStyleContext(nsIFrame* aFrame, - nsStyleContext* aNewParentContext) +nsFrameManager::ReParentStyleContext(nsIFrame* aFrame) { - nsresult result = NS_ERROR_NULL_POINTER; - if (aFrame) { - // DO NOT verify the style tree before reparenting. The frame - // tree has already been changed, so this check would just fail. - nsStyleContext* oldContext = aFrame->GetStyleContext(); - if (oldContext) { - nsPresContext *presContext = GetPresContext(); - nsRefPtr newContext; - result = NS_OK; - newContext = mStyleSet->ReParentStyleContext(presContext, oldContext, - aNewParentContext); - if (newContext) { - if (newContext != oldContext) { - PRInt32 listIndex = 0; - nsIAtom* childList = nsnull; - nsIFrame* child; + // DO NOT verify the style tree before reparenting. The frame + // tree has already been changed, so this check would just fail. + nsStyleContext* oldContext = aFrame->GetStyleContext(); + // XXXbz can oldContext really ever be null? + if (oldContext) { + nsPresContext *presContext = GetPresContext(); + nsRefPtr newContext; + nsIFrame* providerFrame = nsnull; + PRBool providerIsChild = PR_FALSE; + nsIFrame* providerChild = nsnull; + aFrame->GetParentStyleContextFrame(presContext, &providerFrame, + &providerIsChild); + nsStyleContext* newParentContext = nsnull; + if (providerIsChild) { + ReParentStyleContext(providerFrame); + newParentContext = providerFrame->GetStyleContext(); + providerChild = providerFrame; + } else if (providerFrame) { + newParentContext = providerFrame->GetStyleContext(); + } else { + NS_NOTREACHED("Reparenting something that has no usable parent? " + "Shouldn't happen!"); + } + + newContext = mStyleSet->ReParentStyleContext(presContext, oldContext, + newParentContext); + if (newContext) { + if (newContext != oldContext) { + PRInt32 listIndex = 0; + nsIAtom* childList = nsnull; + nsIFrame* child; - aFrame->SetStyleContext(presContext, newContext); + aFrame->SetStyleContext(presContext, newContext); - do { - child = aFrame->GetFirstChild(childList); - while (child) { - if (NS_FRAME_OUT_OF_FLOW != (child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) { - // only do frames that are in flow - if (nsLayoutAtoms::placeholderFrame == child->GetType()) { - // get out of flow frame and recurse there - nsIFrame* outOfFlowFrame = - nsPlaceholderFrame::GetRealFrameForPlaceholder(child); - NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame"); + do { + child = aFrame->GetFirstChild(childList); + while (child) { + // only do frames that are in flow + if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) { + if (nsLayoutAtoms::placeholderFrame == child->GetType()) { + // get out of flow frame and recurse there + nsIFrame* outOfFlowFrame = + nsPlaceholderFrame::GetRealFrameForPlaceholder(child); + NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame"); - result = ReParentStyleContext(outOfFlowFrame, newContext); + NS_ASSERTION(outOfFlowFrame != providerChild, + "Out of flow provider?"); - // reparent placeholder's context under out of flow frame - nsStyleContext* outOfFlowContext = outOfFlowFrame->GetStyleContext(); - ReParentStyleContext(child, outOfFlowContext); - } - else { // regular frame - result = ReParentStyleContext(child, newContext); - } + ReParentStyleContext(outOfFlowFrame); + + // reparent placeholder too + ReParentStyleContext(child); } - - child = child->GetNextSibling(); - } - - childList = aFrame->GetAdditionalChildListName(listIndex++); - } while (childList); - - // do additional contexts - PRInt32 contextIndex = -1; - while (1) { - nsStyleContext* oldExtraContext = aFrame->GetAdditionalStyleContext(++contextIndex); - if (oldExtraContext) { - nsRefPtr newExtraContext; - newExtraContext = mStyleSet->ReParentStyleContext(presContext, - oldExtraContext, - newContext); - if (newExtraContext) { - aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext); + else if (child != providerChild) { + // regular frame, not reparented yet + ReParentStyleContext(child); } } - else { - result = NS_OK; // ok not to have extras (or run out) - break; + + child = child->GetNextSibling(); + } + + childList = aFrame->GetAdditionalChildListName(listIndex++); + } while (childList); + + // do additional contexts + PRInt32 contextIndex = -1; + while (1) { + nsStyleContext* oldExtraContext = + aFrame->GetAdditionalStyleContext(++contextIndex); + if (oldExtraContext) { + nsRefPtr newExtraContext; + newExtraContext = mStyleSet->ReParentStyleContext(presContext, + oldExtraContext, + newContext); + if (newExtraContext) { + aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext); } } -#ifdef DEBUG - VerifyStyleTree(GetPresContext(), aFrame, aNewParentContext); -#endif + else { + break; + } } +#ifdef DEBUG + VerifyStyleTree(GetPresContext(), aFrame, newParentContext); +#endif } } } - return result; + return NS_OK; } static nsChangeHint diff --git a/mozilla/layout/base/nsFrameManager.h b/mozilla/layout/base/nsFrameManager.h index da11a593084..1920e8b7733 100644 --- a/mozilla/layout/base/nsFrameManager.h +++ b/mozilla/layout/base/nsFrameManager.h @@ -166,13 +166,14 @@ public: NS_HIDDEN_(void) NotifyDestroyingFrame(nsIFrame* aFrame); /* - * Reparent the style contexts of this frame subtree to live under the new - * given parent style context. The StyleContextParent of aFrame should be - * changed _before_ this method is called, so that style tree verification - * can take place correctly. + * Reparent the style contexts of this frame subtree. The parent frame of + * aFrame must be changed to the new parent before this function is called; + * the new parent style context will be automatically computed based on the + * new position in the frame tree. + * + * @param aFrame the root of the subtree to reparent. Must not be null. */ - NS_HIDDEN_(nsresult) ReParentStyleContext(nsIFrame* aFrame, - nsStyleContext* aNewParentContext); + NS_HIDDEN_(nsresult) ReParentStyleContext(nsIFrame* aFrame); /* * Re-resolve the style contexts for a frame tree. Returns the top-level diff --git a/mozilla/layout/forms/nsFieldSetFrame.cpp b/mozilla/layout/forms/nsFieldSetFrame.cpp index f48e214d877..babe91fd1a4 100644 --- a/mozilla/layout/forms/nsFieldSetFrame.cpp +++ b/mozilla/layout/forms/nsFieldSetFrame.cpp @@ -708,11 +708,10 @@ nsFieldSetFrame::MaybeSetLegend(nsIFrame* aFrameList, nsIAtom* aListName) void nsFieldSetFrame::ReParentFrameList(nsIFrame* aFrameList) { - nsFrameManager* frameManager = mContentFrame->GetPresContext()->FrameManager(); - nsStyleContext* newParentContext = mContentFrame->GetStyleContext(); + nsFrameManager* frameManager = GetPresContext()->FrameManager(); for (nsIFrame* frame = aFrameList; frame; frame = frame->GetNextSibling()) { frame->SetParent(mContentFrame); - frameManager->ReParentStyleContext(frame, newParentContext); + frameManager->ReParentStyleContext(frame); } mContentFrame->AddStateBits(GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW); } diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index c90bb77138c..c70cf8387a6 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -217,7 +217,7 @@ nsHTMLButtonControlFrame::ReParentFrameList(nsFrameManager* aFrameManager, for (nsIFrame* frame = aFrameList; frame; frame = frame->GetNextSibling()) { frame->SetParent(mFrames.FirstChild()); // now reparent the contexts for the reparented frame too - aFrameManager->ReParentStyleContext(frame, newParentContext); + aFrameManager->ReParentStyleContext(frame); } // Set NS_FRAME_HAS_CHILD_WITH_VIEW on the area frame if needed, bug 276236. diff --git a/mozilla/layout/generic/nsFirstLetterFrame.cpp b/mozilla/layout/generic/nsFirstLetterFrame.cpp index 11a672dce8e..a37f8384b41 100644 --- a/mozilla/layout/generic/nsFirstLetterFrame.cpp +++ b/mozilla/layout/generic/nsFirstLetterFrame.cpp @@ -164,7 +164,8 @@ nsFirstLetterFrame::SetInitialChildList(nsPresContext* aPresContext, nsFrameManager *frameManager = aPresContext->FrameManager(); for (nsIFrame* frame = aChildList; frame; frame = frame->GetNextSibling()) { - frameManager->ReParentStyleContext(frame, mStyleContext); + NS_ASSERTION(frame->GetParent() == this, "Unexpected parent"); + frameManager->ReParentStyleContext(frame); } return NS_OK; } diff --git a/mozilla/layout/generic/nsInlineFrame.cpp b/mozilla/layout/generic/nsInlineFrame.cpp index b756d82659a..0a015dd96b7 100644 --- a/mozilla/layout/generic/nsInlineFrame.cpp +++ b/mozilla/layout/generic/nsInlineFrame.cpp @@ -884,14 +884,15 @@ NS_IMETHODIMP nsInlineFrame::GetAccessible(nsIAccessible** aAccessible) static void ReParentChildListStyle(nsPresContext* aPresContext, - nsStyleContext* aParentStyleContext, - nsFrameList& aFrameList) + nsFrameList& aFrameList, + nsIFrame* aParentFrame) { nsFrameManager *frameManager = aPresContext->FrameManager(); for (nsIFrame* kid = aFrameList.FirstChild(); kid; kid = kid->GetNextSibling()) { - frameManager->ReParentStyleContext(kid, aParentStyleContext); + NS_ASSERTION(kid->GetParent() == aParentFrame, "Bogus parentage"); + frameManager->ReParentStyleContext(kid); } } @@ -947,7 +948,8 @@ nsFirstLineFrame::PullOneFrame(nsPresContext* aPresContext, InlineReflowState& i if (frame && !mPrevInFlow) { // We are a first-line frame. Fixup the child frames // style-context that we just pulled. - aPresContext->FrameManager()->ReParentStyleContext(frame, mStyleContext); + NS_ASSERTION(frame->GetParent() == this, "Incorrect parent?"); + aPresContext->FrameManager()->ReParentStyleContext(frame); } return frame; } @@ -970,7 +972,7 @@ nsFirstLineFrame::Reflow(nsPresContext* aPresContext, nsFrameList frames(prevOverflowFrames); mFrames.InsertFrames(this, nsnull, prevOverflowFrames); - ReParentChildListStyle(aPresContext, mStyleContext, frames); + ReParentChildListStyle(aPresContext, frames, this); } } @@ -981,7 +983,7 @@ nsFirstLineFrame::Reflow(nsPresContext* aPresContext, nsFrameList frames(overflowFrames); mFrames.AppendFrames(nsnull, overflowFrames); - ReParentChildListStyle(aPresContext, mStyleContext, frames); + ReParentChildListStyle(aPresContext, frames, this); } // Set our own reflow state (additional state above and beyond @@ -1042,7 +1044,7 @@ nsFirstLineFrame::Reflow(nsPresContext* aPresContext, SetStyleContext(aPresContext, newSC); // Re-resolve all children - ReParentChildListStyle(aPresContext, mStyleContext, mFrames); + ReParentChildListStyle(aPresContext, mFrames, this); } } }