Skip to content

Commit

Permalink
Bug 386801 - nsAbsoluteContainingBlock doesn't need to store a child …
Browse files Browse the repository at this point in the history
…list name; this shaves four bytes off nsViewportFrame, nsBlockFrame, and nsPositionedInlineFrame. r+sr+a=dbaron
  • Loading branch information
jswalden committed Aug 2, 2007
1 parent 25967e3 commit 3610279
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 39 deletions.
30 changes: 22 additions & 8 deletions layout/generic/nsAbsoluteContainingBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

virtual ~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 nsIAtom* GetChildListName() const { return nsGkAtoms::absoluteList; }
#ifdef DEBUG
nsIAtom* GetChildListName() const { return mChildListName; }
#endif

nsresult FirstChild(const nsIFrame* aDelegatingFrame,
nsIAtom* aListName,
Expand Down Expand Up @@ -135,6 +147,8 @@ class nsAbsoluteContainingBlock
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);
Expand Down
14 changes: 7 additions & 7 deletions layout/generic/nsBlockFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions layout/generic/nsBlockFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class nsBlockFrame : public nsBlockFrameSuper
: nsHTMLContainerFrame(aContext)
, mMinWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
, mPrefWidth(NS_INTRINSIC_WIDTH_UNKNOWN)
, mAbsoluteContainer(nsGkAtoms::absoluteList)
{
#ifdef DEBUG
InitDebugFlags();
Expand Down
12 changes: 6 additions & 6 deletions layout/generic/nsInlineFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -1062,15 +1062,15 @@ nsIAtom*
nsPositionedInlineFrame::GetAdditionalChildListName(PRInt32 aIndex) const
{
if (0 == aIndex) {
return mAbsoluteContainer.GetChildListName();
return nsGkAtoms::absoluteList;
}
return nsnull;
}

nsIFrame*
nsPositionedInlineFrame::GetFirstChild(nsIAtom* aListName) const
{
if (mAbsoluteContainer.GetChildListName() == aListName) {
if (nsGkAtoms::absoluteList == aListName) {
nsIFrame* result = nsnull;
mAbsoluteContainer.FirstChild(this, aListName, &result);
return result;
Expand Down
5 changes: 4 additions & 1 deletion layout/generic/nsInlineFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ class nsFirstLineFrame : public nsInlineFrame {
class nsPositionedInlineFrame : public nsInlineFrame
{
public:
nsPositionedInlineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {}
nsPositionedInlineFrame(nsStyleContext* aContext)
: nsInlineFrame(aContext)
, mAbsoluteContainer(nsGkAtoms::absoluteList)
{}

virtual ~nsPositionedInlineFrame() { } // useful for debugging

Expand Down
12 changes: 6 additions & 6 deletions layout/generic/nsViewportFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 7 additions & 11 deletions layout/generic/nsViewportFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -126,7 +120,9 @@ class ViewportFrame : public nsContainerFrame {
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;
};


Expand Down

0 comments on commit 3610279

Please sign in to comment.