From 4a82c200c1d34d6aaf79d825de58c247814de48b Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Mon, 12 Sep 2011 09:08:07 -0700 Subject: [PATCH] Bug 685154 - Cleanup nsIFrame::GetParentStyleContextFrame and related code. r=roc Make nsIFrame::GetParentStyleContextFrame return the frame directly instead of indirectly through an out parameter. Remove the unused nsPresContext parameter. --- layout/base/nsCSSFrameConstructor.cpp | 15 ++---- layout/base/nsFrameManager.cpp | 25 ++++------ layout/generic/nsFrame.cpp | 69 ++++++++------------------ layout/generic/nsFrame.h | 24 ++++----- layout/generic/nsIFrame.h | 16 ++---- layout/generic/nsPlaceholderFrame.cpp | 11 ++-- layout/generic/nsPlaceholderFrame.h | 5 +- layout/tables/nsTableColGroupFrame.cpp | 5 +- layout/tables/nsTableFrame.cpp | 13 ++--- layout/tables/nsTableFrame.h | 4 +- layout/tables/nsTableOuterFrame.cpp | 30 ++++------- layout/tables/nsTableOuterFrame.h | 9 ++-- 12 files changed, 75 insertions(+), 151 deletions(-) diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 90ae7202e94..8d0cb90c81f 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -2479,9 +2479,9 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle // Figure out which frame has the main style for the document element, // assigning it to mRootElementStyleFrame. // Backgrounds should be propagated from that frame to the viewport. - PRBool isChild; - contentFrame->GetParentStyleContextFrame(state.mPresContext, - &mRootElementStyleFrame, &isChild); + mRootElementStyleFrame = contentFrame->GetParentStyleContextFrame(); + bool isChild = mRootElementStyleFrame && + mRootElementStyleFrame->GetParent() == contentFrame; if (!isChild) { mRootElementStyleFrame = mRootElementFrame; } @@ -5788,13 +5788,8 @@ nsCSSFrameConstructor::IsValidSibling(nsIFrame* aSibling, // if we haven't already, construct a style context to find the display type of aContent if (UNSET_DISPLAY == aDisplay) { nsRefPtr styleContext; - nsIFrame* styleParent; - PRBool providerIsChild; - if (NS_FAILED(aSibling-> - GetParentStyleContextFrame(aSibling->PresContext(), - &styleParent, - &providerIsChild)) || - !styleParent) { + nsIFrame* styleParent = aSibling->GetParentStyleContextFrame(); + if (!styleParent) { NS_NOTREACHED("Shouldn't happen"); return PR_FALSE; } diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index f749c186d11..c99b27b1450 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -268,7 +268,7 @@ nsFrameManager::Destroy() // Placeholder frame functions nsPlaceholderFrame* -nsFrameManager::GetPlaceholderFrameFor(nsIFrame* aFrame) +nsFrameManager::GetPlaceholderFrameFor(nsIFrame* aFrame) { NS_PRECONDITION(aFrame, "null param unexpected"); @@ -587,10 +587,7 @@ VerifyContextParent(nsPresContext* aPresContext, nsIFrame* aFrame, // as the parent context instead of asking the frame // get the parent context from the frame (indirectly) - nsIFrame* providerFrame = nsnull; - PRBool providerIsChild; - aFrame->GetParentStyleContextFrame(aPresContext, - &providerFrame, &providerIsChild); + nsIFrame* providerFrame = aFrame->GetParentStyleContextFrame(); if (providerFrame) aParentContext = providerFrame->GetStyleContext(); // aParentContext could still be null @@ -808,13 +805,11 @@ nsFrameManager::ReparentStyleContext(nsIFrame* aFrame) // XXXbz can oldContext really ever be null? if (oldContext) { nsRefPtr newContext; - nsIFrame* providerFrame = nsnull; - PRBool providerIsChild = PR_FALSE; - nsIFrame* providerChild = nsnull; - aFrame->GetParentStyleContextFrame(GetPresContext(), &providerFrame, - &providerIsChild); + nsIFrame* providerFrame = aFrame->GetParentStyleContextFrame(); + bool isChild = providerFrame && providerFrame->GetParent() == aFrame; nsStyleContext* newParentContext = nsnull; - if (providerIsChild) { + nsIFrame* providerChild = nsnull; + if (isChild) { ReparentStyleContext(providerFrame); newParentContext = providerFrame->GetStyleContext(); providerChild = providerFrame; @@ -1107,11 +1102,9 @@ nsFrameManager::ReResolveStyleContext(nsPresContext *aPresContext, nsIFrame* resolvedChild = nsnull; // Get the frame providing the parent style context. If it is a // child, then resolve the provider first. - nsIFrame* providerFrame = nsnull; - PRBool providerIsChild = PR_FALSE; - aFrame->GetParentStyleContextFrame(aPresContext, - &providerFrame, &providerIsChild); - if (!providerIsChild) { + nsIFrame* providerFrame = aFrame->GetParentStyleContextFrame(); + bool isChild = providerFrame && providerFrame->GetParent() == aFrame; + if (!isChild) { if (providerFrame) parentContext = providerFrame->GetStyleContext(); else diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 7a4744a30be..cdf7758dd1c 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -6520,15 +6520,6 @@ nsFrame::ConsiderChildOverflow(nsOverflowAreas& aOverflowAreas, } } -NS_IMETHODIMP -nsFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) -{ - return DoGetParentStyleContextFrame(aPresContext, aProviderFrame, aIsChild); -} - - /** * This function takes a "special" frame and _if_ that frame is an anonymous * block created by an ib split it returns the block's preceding inline. This @@ -6575,26 +6566,22 @@ GetIBSpecialSiblingForAnonymousBlock(nsIFrame* aFrame) * Also skip anonymous scrolled-content parents; inherit directly from the * outer scroll frame. */ -static nsresult -GetCorrectedParent(nsPresContext* aPresContext, nsIFrame* aFrame, - nsIFrame** aSpecialParent) +static nsIFrame* +GetCorrectedParent(const nsIFrame* aFrame) { nsIFrame *parent = aFrame->GetParent(); if (!parent) { - *aSpecialParent = nsnull; - } else { - nsIAtom* pseudo = aFrame->GetStyleContext()->GetPseudo(); - // Outer tables are always anon boxes; if we're in here for an outer - // table, that actually means its the _inner_ table that wants to - // know its parent. So get the pseudo of the inner in that case. - if (pseudo == nsCSSAnonBoxes::tableOuter) { - pseudo = aFrame->GetFirstPrincipalChild() - ->GetStyleContext()->GetPseudo(); - } - *aSpecialParent = nsFrame::CorrectStyleParentFrame(parent, pseudo); + return nsnull; } - return NS_OK; + // Outer tables are always anon boxes; if we're in here for an outer + // table, that actually means its the _inner_ table that wants to + // know its parent. So get the pseudo of the inner in that case. + nsIAtom* pseudo = aFrame->GetStyleContext()->GetPseudo(); + if (pseudo == nsCSSAnonBoxes::tableOuter) { + pseudo = aFrame->GetFirstPrincipalChild()->GetStyleContext()->GetPseudo(); + } + return nsFrame::CorrectStyleParentFrame(parent, pseudo); } /* static */ @@ -6659,17 +6646,13 @@ nsFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent, return nsnull; } -nsresult -nsFrame::DoGetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) +nsIFrame* +nsFrame::DoGetParentStyleContextFrame() { - *aIsChild = PR_FALSE; - *aProviderFrame = nsnull; if (mContent && !mContent->GetParent() && !GetStyleContext()->GetPseudo()) { // we're a frame for the root. We have no style context parent. - return NS_OK; + return nsnull; } if (!(mState & NS_FRAME_OUT_OF_FLOW)) { @@ -6679,17 +6662,16 @@ nsFrame::DoGetParentStyleContextFrame(nsPresContext* aPresContext, * inline. We can get to it using GetIBSpecialSiblingForAnonymousBlock. */ if (mState & NS_FRAME_IS_SPECIAL) { - *aProviderFrame = GetIBSpecialSiblingForAnonymousBlock(this); - - if (*aProviderFrame) { - return NS_OK; + nsIFrame* specialSibling = GetIBSpecialSiblingForAnonymousBlock(this); + if (specialSibling) { + return specialSibling; } } // If this frame is one of the blocks that split an inline, we must // return the "special" inline parent, i.e., the parent that this // frame would have if we didn't mangle the frame structure. - return GetCorrectedParent(aPresContext, this, aProviderFrame); + return GetCorrectedParent(this); } // For out-of-flow frames, we must resolve underneath the @@ -6701,22 +6683,15 @@ nsFrame::DoGetParentStyleContextFrame(nsPresContext* aPresContext, // have placeholders. Use their first-in-flow's placeholder. oofFrame = oofFrame->GetFirstInFlow(); } - nsIFrame *placeholder = - aPresContext->FrameManager()->GetPlaceholderFrameFor(oofFrame); + nsIFrame* placeholder = oofFrame->PresContext()->FrameManager()-> + GetPlaceholderFrameFor(oofFrame); if (!placeholder) { NS_NOTREACHED("no placeholder frame for out-of-flow frame"); - GetCorrectedParent(aPresContext, this, aProviderFrame); - return NS_ERROR_FAILURE; + return GetCorrectedParent(this); } - return static_cast(placeholder)-> - GetParentStyleContextFrame(aPresContext, aProviderFrame, aIsChild); + return placeholder->GetParentStyleContextFrame(); } -//----------------------------------------------------------------------------------- - - - - void nsFrame::GetLastLeaf(nsPresContext* aPresContext, nsIFrame **aFrame) { diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index 27d516022f1..5e15177187d 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -268,9 +268,18 @@ public: virtual already_AddRefed CreateAccessible(); #endif - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); + virtual nsIFrame* GetParentStyleContextFrame() { + return DoGetParentStyleContextFrame(); + } + + /** + * Do the work for getting the parent style context frame so that + * other frame's |GetParentStyleContextFrame| methods can call this + * method on *another* frame. (This function handles out-of-flow + * frames by using the frame manager's placeholder map and it also + * handles block-within-inline and generated content wrappers.) + */ + nsIFrame* DoGetParentStyleContextFrame(); virtual PRBool IsEmpty(); virtual PRBool IsSelfEmpty(); @@ -399,15 +408,6 @@ public: nsHTMLReflowMetrics& aMetrics, nsReflowStatus& aStatus); - // Do the work for getting the parent style context frame so that - // other frame's |GetParentStyleContextFrame| methods can call this - // method on *another* frame. (This function handles out-of-flow - // frames by using the frame manager's placeholder map and it also - // handles block-within-inline and generated content wrappers.) - nsresult DoGetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); - // Incorporate the child overflow areas into aOverflowAreas. // If the child does not have a overflow, use the child area. void ConsiderChildOverflow(nsOverflowAreas& aOverflowAreas, diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index bbb7b98c222..557d2bbda90 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -2396,19 +2396,11 @@ public: * this frame returns a child frame, then the child frame must be sure * to return a grandparent or higher! * - * @param aPresContext: PresContext - * @param aProviderFrame: The frame whose style context should be the - * parent of this frame's style context. Null - * is permitted, and means that this frame's - * style context should be the root of the - * style context tree. - * @param aIsChild: True if |aProviderFrame| is set to a child - * of this frame; false if it is an ancestor or - * null. + * @return The frame whose style context should be the parent of this frame's + * style context. Null is permitted, and means that this frame's + * style context should be the root of the style context tree. */ - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) = 0; + virtual nsIFrame* GetParentStyleContextFrame() = 0; /** * Determines whether a frame is visible for painting; diff --git a/layout/generic/nsPlaceholderFrame.cpp b/layout/generic/nsPlaceholderFrame.cpp index 9b5a1f9c691..7c3789775f8 100644 --- a/layout/generic/nsPlaceholderFrame.cpp +++ b/layout/generic/nsPlaceholderFrame.cpp @@ -191,20 +191,15 @@ nsPlaceholderFrame::CanContinueTextRun() const return mOutOfFlowFrame->CanContinueTextRun(); } -NS_IMETHODIMP -nsPlaceholderFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) +nsIFrame* +nsPlaceholderFrame::GetParentStyleContextFrame() { NS_PRECONDITION(GetParent(), "How can we not have a parent here?"); - *aIsChild = PR_FALSE; // Lie about our pseudo so we can step out of all anon boxes and // pseudo-elements. The other option would be to reimplement the // {ib} split gunk here. - *aProviderFrame = - CorrectStyleParentFrame(GetParent(), nsGkAtoms::placeholderFrame); - return NS_OK; + return CorrectStyleParentFrame(GetParent(), nsGkAtoms::placeholderFrame); } diff --git a/layout/generic/nsPlaceholderFrame.h b/layout/generic/nsPlaceholderFrame.h index a76fd70a1f0..f6a30f2252a 100644 --- a/layout/generic/nsPlaceholderFrame.h +++ b/layout/generic/nsPlaceholderFrame.h @@ -174,9 +174,8 @@ public: } #endif - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); + virtual nsIFrame* GetParentStyleContextFrame(); + /** * @return the out-of-flow for aFrame if aFrame is a placeholder; otherwise * aFrame diff --git a/layout/tables/nsTableColGroupFrame.cpp b/layout/tables/nsTableColGroupFrame.cpp index bb452858eda..04962c4e3a6 100644 --- a/layout/tables/nsTableColGroupFrame.cpp +++ b/layout/tables/nsTableColGroupFrame.cpp @@ -336,10 +336,7 @@ nsTableColGroupFrame::RemoveFrame(ChildListID aListID, nsTableColFrame* nextCol; while (col && col->GetColType() == eColAnonymousCol) { #ifdef DEBUG - nsIFrame* providerFrame; - PRBool isChild; - colFrame->GetParentStyleContextFrame(PresContext(), &providerFrame, - &isChild); + nsIFrame* providerFrame = colFrame->GetParentStyleContextFrame(); if (colFrame->GetStyleContext()->GetParent() == providerFrame->GetStyleContext()) { NS_ASSERTION(col->GetStyleContext() == colFrame->GetStyleContext() && diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 3a6fee2d6e2..0d020cc01ad 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -161,10 +161,8 @@ struct BCPropertyData BCPixelSize mRightCellBorderWidth; }; -NS_IMETHODIMP -nsTableFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) +nsIFrame* +nsTableFrame::GetParentStyleContextFrame() { // Since our parent, the table outer frame, returned this frame, we // must return whatever our parent would normally have returned. @@ -172,13 +170,10 @@ nsTableFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, NS_PRECONDITION(mParent, "table constructed without outer table"); if (!mContent->GetParent() && !GetStyleContext()->GetPseudo()) { // We're the root. We have no style context parent. - *aIsChild = PR_FALSE; - *aProviderFrame = nsnull; - return NS_OK; + return nsnull; } - return static_cast(mParent)-> - DoGetParentStyleContextFrame(aPresContext, aProviderFrame, aIsChild); + return static_cast(GetParent())->DoGetParentStyleContextFrame(); } diff --git a/layout/tables/nsTableFrame.h b/layout/tables/nsTableFrame.h index 35f93035508..8e9b4202e7d 100644 --- a/layout/tables/nsTableFrame.h +++ b/layout/tables/nsTableFrame.h @@ -349,9 +349,7 @@ public: nsFrameList& GetColGroups(); - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); + virtual nsIFrame* GetParentStyleContextFrame(); /** * Get the "type" of the frame diff --git a/layout/tables/nsTableOuterFrame.cpp b/layout/tables/nsTableOuterFrame.cpp index 3df79d2d839..b62d4649903 100644 --- a/layout/tables/nsTableOuterFrame.cpp +++ b/layout/tables/nsTableOuterFrame.cpp @@ -117,10 +117,8 @@ nsTableCaptionFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext, return result; } -NS_IMETHODIMP -nsTableCaptionFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) +nsIFrame* +nsTableCaptionFrame::GetParentStyleContextFrame() { NS_PRECONDITION(mContent->GetParent(), "How could we not have a parent here?"); @@ -131,17 +129,13 @@ nsTableCaptionFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, if (outerFrame && outerFrame->GetType() == nsGkAtoms::tableOuterFrame) { nsIFrame* innerFrame = outerFrame->GetFirstPrincipalChild(); if (innerFrame) { - *aProviderFrame = - nsFrame::CorrectStyleParentFrame(innerFrame, - GetStyleContext()->GetPseudo()); - *aIsChild = PR_FALSE; - return NS_OK; + return nsFrame::CorrectStyleParentFrame(innerFrame, + GetStyleContext()->GetPseudo()); } } NS_NOTREACHED("Where is our inner table frame?"); - return nsBlockFrame::GetParentStyleContextFrame(aPresContext, aProviderFrame, - aIsChild); + return nsBlockFrame::GetParentStyleContextFrame(); } #ifdef ACCESSIBILITY @@ -405,10 +399,8 @@ nsTableOuterFrame::SetSelected(PRBool aSelected, } } -NS_IMETHODIMP -nsTableOuterFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild) +nsIFrame* +nsTableOuterFrame::GetParentStyleContextFrame() { // The table outer frame and the (inner) table frame split the style // data by giving the table frame the style context associated with @@ -421,13 +413,9 @@ nsTableOuterFrame::GetParentStyleContextFrame(nsPresContext* aPresContext, // the outer table's style context is a leaf. if (!mInnerTableFrame) { - *aProviderFrame = this; - *aIsChild = PR_FALSE; - return NS_ERROR_FAILURE; + return this; } - *aProviderFrame = mInnerTableFrame; - *aIsChild = PR_TRUE; - return NS_OK; + return mInnerTableFrame; } // INCREMENTAL REFLOW HELPER FUNCTIONS diff --git a/layout/tables/nsTableOuterFrame.h b/layout/tables/nsTableOuterFrame.h index ecba6304100..b8351b06aff 100644 --- a/layout/tables/nsTableOuterFrame.h +++ b/layout/tables/nsTableOuterFrame.h @@ -59,9 +59,8 @@ public: nsSize aMargin, nsSize aBorder, nsSize aPadding, PRBool aShrinkWrap); - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); + virtual nsIFrame* GetParentStyleContextFrame(); + #ifdef ACCESSIBILITY virtual already_AddRefed CreateAccessible(); #endif @@ -169,9 +168,7 @@ public: void SetSelected(PRBool aSelected, SelectionType aType); - NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext, - nsIFrame** aProviderFrame, - PRBool* aIsChild); + virtual nsIFrame* GetParentStyleContextFrame(); /*---------------- nsITableLayout methods ------------------------*/