From bf1a45072997ee3d08e68313155c396e250fd4aa Mon Sep 17 00:00:00 2001 From: "jwalden@mit.edu" Date: Thu, 2 Aug 2007 15:44:36 -0700 Subject: [PATCH] Bug 386801 - nsAbsoluteContainingBlock doesn't need to store a child list name; this shaves four bytes off nsViewportFrame, nsBlockFrame, and nsPositionedInlineFrame. r+sr+a=dbaron --- layout/generic/nsAbsoluteContainingBlock.h | 30 ++++++++++++++++------ layout/generic/nsBlockFrame.cpp | 14 +++++----- layout/generic/nsBlockFrame.h | 1 + layout/generic/nsInlineFrame.cpp | 12 ++++----- layout/generic/nsInlineFrame.h | 5 +++- layout/generic/nsViewportFrame.cpp | 12 ++++----- layout/generic/nsViewportFrame.h | 18 +++++-------- 7 files changed, 53 insertions(+), 39 deletions(-) diff --git a/layout/generic/nsAbsoluteContainingBlock.h b/layout/generic/nsAbsoluteContainingBlock.h index a9bb05451390..87e435294e86 100644 --- a/layout/generic/nsAbsoluteContainingBlock.h +++ b/layout/generic/nsAbsoluteContainingBlock.h @@ -52,24 +52,36 @@ class nsIFrame; class nsPresContext; /** - * This class contains the logic for being an absolute containing block. + * This class contains the logic for being an absolute containing block. This + * class is used within viewport frames (for frames representing content with + * fixed position) and blocks (for frames representing absolutely positioned + * content), since each set of frames is absolutely positioned with respect to + * its parent. * * There is no principal child list, just a named child list which contains - * the absolutely positioned frames + * the absolutely positioned frames. * * All functions include as the first argument the frame that is delegating - * the request + * the request. * - * @see nsGkAtoms::absoluteList + * @see nsGkAtoms::absoluteList and nsGkAtoms::fixedList */ class nsAbsoluteContainingBlock { public: - nsAbsoluteContainingBlock() { } // useful for debugging + nsAbsoluteContainingBlock(nsIAtom* aChildListName) +#ifdef DEBUG + : mChildListName(aChildListName) +#endif + { + NS_ASSERTION(mChildListName == nsGkAtoms::absoluteList || + mChildListName == nsGkAtoms::fixedList, + "should either represent position:fixed or absolute content"); + } - virtual ~nsAbsoluteContainingBlock() { } // useful for debugging - - virtual nsIAtom* GetChildListName() const { return nsGkAtoms::absoluteList; } +#ifdef DEBUG + nsIAtom* GetChildListName() const { return mChildListName; } +#endif nsresult FirstChild(const nsIFrame* aDelegatingFrame, nsIAtom* aListName, @@ -135,6 +147,8 @@ protected: nsFrameList mAbsoluteFrames; // additional named child list #ifdef DEBUG + nsIAtom* const mChildListName; // nsGkAtoms::fixedList or nsGkAtoms::absoluteList + // helper routine for debug printout void PrettyUC(nscoord aSize, char* aBuf); diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 814ae039c2fc..981f90b84947 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -517,7 +517,7 @@ nsBlockFrame::GetBaseline() const nsIFrame* nsBlockFrame::GetFirstChild(nsIAtom* aListName) const { - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { nsIFrame* result = nsnull; mAbsoluteContainer.FirstChild(this, aListName, &result); return result; @@ -561,7 +561,7 @@ nsBlockFrame::GetAdditionalChildListName(PRInt32 aIndex) const case NS_BLOCK_FRAME_OVERFLOW_OOF_LIST_INDEX: return nsGkAtoms::overflowOutOfFlowList; case NS_BLOCK_FRAME_ABSOLUTE_LIST_INDEX: - return mAbsoluteContainer.GetChildListName(); + return nsGkAtoms::absoluteList; default: return nsnull; } @@ -4639,7 +4639,7 @@ nsBlockFrame::AppendFrames(nsIAtom* aListName, return NS_OK; } if (aListName) { - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { return mAbsoluteContainer.AppendFrames(this, aListName, aFrameList); } else if (nsGkAtoms::floatList == aListName) { @@ -4688,7 +4688,7 @@ nsBlockFrame::InsertFrames(nsIAtom* aListName, "inserting after sibling frame with different parent"); if (aListName) { - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { return mAbsoluteContainer.InsertFrames(this, aListName, aPrevFrame, aFrameList); } @@ -4981,7 +4981,7 @@ nsBlockFrame::RemoveFrame(nsIAtom* aListName, MarkSameSpaceManagerLinesDirty(this); } } - else if (mAbsoluteContainer.GetChildListName() == aListName) { + else if (nsGkAtoms::absoluteList == aListName) { return mAbsoluteContainer.RemoveFrame(this, aListName, aOldFrame); } else if (nsGkAtoms::floatList == aListName) { @@ -5024,7 +5024,7 @@ nsBlockFrame::DoRemoveOutOfFlowFrame(nsIFrame* aFrame) // Remove aFrame from the appropriate list. if (display->IsAbsolutelyPositioned()) { block->mAbsoluteContainer.RemoveFrame(block, - block->mAbsoluteContainer.GetChildListName(), + nsGkAtoms::absoluteList, aFrame); aFrame->Destroy(); } @@ -6096,7 +6096,7 @@ nsBlockFrame::SetInitialChildList(nsIAtom* aListName, { nsresult rv = NS_OK; - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { mAbsoluteContainer.SetInitialChildList(this, aListName, aChildList); } else if (nsGkAtoms::floatList == aListName) { diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h index 28d3bcd91f66..50af89bce249 100644 --- a/layout/generic/nsBlockFrame.h +++ b/layout/generic/nsBlockFrame.h @@ -289,6 +289,7 @@ protected: : nsHTMLContainerFrame(aContext) , mMinWidth(NS_INTRINSIC_WIDTH_UNKNOWN) , mPrefWidth(NS_INTRINSIC_WIDTH_UNKNOWN) + , mAbsoluteContainer(nsGkAtoms::absoluteList) { #ifdef DEBUG InitDebugFlags(); diff --git a/layout/generic/nsInlineFrame.cpp b/layout/generic/nsInlineFrame.cpp index ad45e899c772..24afa010e0d2 100644 --- a/layout/generic/nsInlineFrame.cpp +++ b/layout/generic/nsInlineFrame.cpp @@ -993,7 +993,7 @@ nsPositionedInlineFrame::SetInitialChildList(nsIAtom* aListName, { nsresult rv; - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { rv = mAbsoluteContainer.SetInitialChildList(this, aListName, aChildList); } else { rv = nsInlineFrame::SetInitialChildList(aListName, aChildList); @@ -1008,7 +1008,7 @@ nsPositionedInlineFrame::AppendFrames(nsIAtom* aListName, { nsresult rv; - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { rv = mAbsoluteContainer.AppendFrames(this, aListName, aFrameList); } else { rv = nsInlineFrame::AppendFrames(aListName, aFrameList); @@ -1024,7 +1024,7 @@ nsPositionedInlineFrame::InsertFrames(nsIAtom* aListName, { nsresult rv; - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { rv = mAbsoluteContainer.InsertFrames(this, aListName, aPrevFrame, aFrameList); } else { @@ -1040,7 +1040,7 @@ nsPositionedInlineFrame::RemoveFrame(nsIAtom* aListName, { nsresult rv; - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { rv = mAbsoluteContainer.RemoveFrame(this, aListName, aOldFrame); } else { rv = nsInlineFrame::RemoveFrame(aListName, aOldFrame); @@ -1062,7 +1062,7 @@ nsIAtom* nsPositionedInlineFrame::GetAdditionalChildListName(PRInt32 aIndex) const { if (0 == aIndex) { - return mAbsoluteContainer.GetChildListName(); + return nsGkAtoms::absoluteList; } return nsnull; } @@ -1070,7 +1070,7 @@ nsPositionedInlineFrame::GetAdditionalChildListName(PRInt32 aIndex) const nsIFrame* nsPositionedInlineFrame::GetFirstChild(nsIAtom* aListName) const { - if (mAbsoluteContainer.GetChildListName() == aListName) { + if (nsGkAtoms::absoluteList == aListName) { nsIFrame* result = nsnull; mAbsoluteContainer.FirstChild(this, aListName, &result); return result; diff --git a/layout/generic/nsInlineFrame.h b/layout/generic/nsInlineFrame.h index 0b8f5c87908d..752e4c7979ce 100644 --- a/layout/generic/nsInlineFrame.h +++ b/layout/generic/nsInlineFrame.h @@ -245,7 +245,10 @@ protected: class nsPositionedInlineFrame : public nsInlineFrame { public: - nsPositionedInlineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {} + nsPositionedInlineFrame(nsStyleContext* aContext) + : nsInlineFrame(aContext) + , mAbsoluteContainer(nsGkAtoms::absoluteList) + {} virtual ~nsPositionedInlineFrame() { } // useful for debugging diff --git a/layout/generic/nsViewportFrame.cpp b/layout/generic/nsViewportFrame.cpp index ced43f06b0fa..27a4133ab83a 100644 --- a/layout/generic/nsViewportFrame.cpp +++ b/layout/generic/nsViewportFrame.cpp @@ -78,7 +78,7 @@ ViewportFrame::SetInitialChildList(nsIAtom* aListName, #ifdef NS_DEBUG nsFrame::VerifyDirtyBitSet(aChildList); #endif - if (mFixedContainer.GetChildListName() == aListName) { + if (nsGkAtoms::fixedList == aListName) { rv = mFixedContainer.SetInitialChildList(this, aListName, aChildList); } else { @@ -115,7 +115,7 @@ ViewportFrame::AppendFrames(nsIAtom* aListName, { nsresult rv = NS_OK; - if (mFixedContainer.GetChildListName() == aListName) { + if (nsGkAtoms::fixedList == aListName) { rv = mFixedContainer.AppendFrames(this, aListName, aFrameList); } else { @@ -134,7 +134,7 @@ ViewportFrame::InsertFrames(nsIAtom* aListName, { nsresult rv = NS_OK; - if (mFixedContainer.GetChildListName() == aListName) { + if (nsGkAtoms::fixedList == aListName) { rv = mFixedContainer.InsertFrames(this, aListName, aPrevFrame, aFrameList); } else { @@ -152,7 +152,7 @@ ViewportFrame::RemoveFrame(nsIAtom* aListName, { nsresult rv = NS_OK; - if (mFixedContainer.GetChildListName() == aListName) { + if (nsGkAtoms::fixedList == aListName) { rv = mFixedContainer.RemoveFrame(this, aListName, aOldFrame); } else { @@ -170,7 +170,7 @@ ViewportFrame::GetAdditionalChildListName(PRInt32 aIndex) const NS_PRECONDITION(aIndex >= 0, "illegal index"); if (0 == aIndex) { - return mFixedContainer.GetChildListName(); + return nsGkAtoms::fixedList; } return nsnull; @@ -179,7 +179,7 @@ ViewportFrame::GetAdditionalChildListName(PRInt32 aIndex) const nsIFrame* ViewportFrame::GetFirstChild(nsIAtom* aListName) const { - if (mFixedContainer.GetChildListName() == aListName) { + if (nsGkAtoms::fixedList == aListName) { nsIFrame* result = nsnull; mFixedContainer.FirstChild(this, aListName, &result); return result; diff --git a/layout/generic/nsViewportFrame.h b/layout/generic/nsViewportFrame.h index 3547e0806e83..fc5e89e72a46 100644 --- a/layout/generic/nsViewportFrame.h +++ b/layout/generic/nsViewportFrame.h @@ -49,15 +49,6 @@ #include "nsIPresShell.h" #include "nsAbsoluteContainingBlock.h" -class nsFixedContainingBlock : public nsAbsoluteContainingBlock { -public: - nsFixedContainingBlock() { } // useful for debugging - - virtual ~nsFixedContainingBlock() { } // useful for debugging - - virtual nsIAtom* GetChildListName() const { return nsGkAtoms::fixedList; } -}; - /** * ViewportFrame is the parent of a single child - the doc root frame or a scroll frame * containing the doc root frame. ViewportFrame stores this child in its primary child @@ -68,7 +59,10 @@ class ViewportFrame : public nsContainerFrame { public: typedef nsContainerFrame Super; - ViewportFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {} + ViewportFrame(nsStyleContext* aContext) + : nsContainerFrame(aContext) + , mFixedContainer(nsGkAtoms::fixedList) + {} virtual ~ViewportFrame() { } // useful for debugging virtual void Destroy(); @@ -126,7 +120,9 @@ protected: nsPoint AdjustReflowStateForScrollbars(nsHTMLReflowState* aReflowState) const; protected: - nsFixedContainingBlock mFixedContainer; + // position: fixed content is really content which is absolutely positioned with + // respect to the viewport. + nsAbsoluteContainingBlock mFixedContainer; };