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.
This commit is contained in:
Mats Palmgren 2011-09-12 09:08:07 -07:00
parent 8963489cac
commit 4a82c200c1
12 changed files with 75 additions and 151 deletions

View File

@ -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<nsStyleContext> 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;
}

View File

@ -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<nsStyleContext> 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

View File

@ -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<nsFrame*>(placeholder)->
GetParentStyleContextFrame(aPresContext, aProviderFrame, aIsChild);
return placeholder->GetParentStyleContextFrame();
}
//-----------------------------------------------------------------------------------
void
nsFrame::GetLastLeaf(nsPresContext* aPresContext, nsIFrame **aFrame)
{

View File

@ -268,9 +268,18 @@ public:
virtual already_AddRefed<nsAccessible> 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,

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -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() &&

View File

@ -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<nsFrame*>(mParent)->
DoGetParentStyleContextFrame(aPresContext, aProviderFrame, aIsChild);
return static_cast<nsFrame*>(GetParent())->DoGetParentStyleContextFrame();
}

View File

@ -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

View File

@ -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

View File

@ -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<nsAccessible> 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 ------------------------*/