Bug 473390 part 10. Move various XUL nsIBoxLayout stuff out of the frame constructor into frame creation functions, and make the XUL frame creation functions have the right signature to fit into the new world. r+sr=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Jan 2009 13:31:33 -0500
changeset 23947 e099a47f752e4d1411928ba758f66e3d7d1e2346
parent 23946 dc16f1b1eb7a7f65706cb4a14789c37923b0ba96
child 23948 a5381d3f2c90c616422dde223e7a72fa8915512f
push idunknown
push userunknown
push dateunknown
bugs473390
milestone1.9.2a1pre
Bug 473390 part 10. Move various XUL nsIBoxLayout stuff out of the frame constructor into frame creation functions, and make the XUL frame creation functions have the right signature to fit into the new world. r+sr=roc
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
layout/xul/base/src/grid/nsGridRowGroupFrame.cpp
layout/xul/base/src/grid/nsGridRowGroupFrame.h
layout/xul/base/src/grid/nsGridRowLeafFrame.cpp
layout/xul/base/src/grid/nsGridRowLeafFrame.h
layout/xul/base/src/nsBoxFrame.cpp
layout/xul/base/src/nsBoxFrame.h
layout/xul/base/src/nsDeckFrame.cpp
layout/xul/base/src/nsDeckFrame.h
layout/xul/base/src/nsListBoxBodyFrame.cpp
layout/xul/base/src/nsListBoxBodyFrame.h
layout/xul/base/src/nsListItemFrame.cpp
layout/xul/base/src/nsListItemFrame.h
layout/xul/base/src/nsMenuFrame.cpp
layout/xul/base/src/nsMenuFrame.h
layout/xul/base/src/nsStackFrame.cpp
layout/xul/base/src/nsStackFrame.h
layout/xul/base/src/nsXULLabelFrame.cpp
layout/xul/base/src/nsXULLabelFrame.h
layout/xul/base/src/tree/src/nsTreeColFrame.cpp
layout/xul/base/src/tree/src/nsTreeColFrame.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -279,23 +279,23 @@ NS_NewRootBoxFrame (nsIPresShell* aPresS
 
 nsIFrame*
 NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewThumbFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
-NS_NewDeckFrame (nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayoutManager = nsnull);
+NS_NewDeckFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewLeafBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
-NS_NewStackFrame (nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayoutManager = nsnull);
+NS_NewStackFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewProgressMeterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewImageBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
@@ -323,27 +323,20 @@ nsIFrame*
 NS_NewMenuBarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewTreeBodyFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 // grid
 nsresult
 NS_NewGridLayout2 ( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout );
-nsresult
-NS_NewGridRowLeafLayout ( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout );
 nsIFrame*
-NS_NewGridRowLeafFrame (nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot, nsIBoxLayout* aLayout);
-nsresult
-NS_NewGridRowGroupLayout ( nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout );
+NS_NewGridRowLeafFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 nsIFrame*
-NS_NewGridRowGroupFrame (nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot, nsIBoxLayout* aLayout);
-
-nsresult
-NS_NewListBoxLayout ( nsIPresShell* aPresShell, nsCOMPtr<nsIBoxLayout>& aNewLayout );
+NS_NewGridRowGroupFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 // end grid
 
 nsIFrame*
 NS_NewTitleBarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 nsIFrame*
 NS_NewResizerFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
@@ -5435,17 +5428,16 @@ PRBool IsXULDisplayType(const nsStyleDis
 nsresult
 nsCSSFrameConstructor::ConstructXULFrame(nsFrameConstructorState& aState,
                                          nsIContent*              aContent,
                                          nsIFrame*                aParentFrame,
                                          nsIAtom*                 aTag,
                                          PRInt32                  aNameSpaceID,
                                          nsStyleContext*          aStyleContext,
                                          nsFrameItems&            aFrameItems,
-                                         PRBool                   aXBLBaseTag,
                                          PRBool                   aHasPseudoParent,
                                          PRBool*                  aHaltProcessing)
 {
   *aHaltProcessing = PR_FALSE;
 
   PRBool    primaryFrameSet = PR_FALSE;
   nsresult  rv = NS_OK;
   PRBool    isPopup = PR_FALSE;
@@ -5536,40 +5528,39 @@ nsCSSFrameConstructor::ConstructXULFrame
       // TEXT CONSTRUCTION
       else if (aTag == nsGkAtoms::text || aTag == nsGkAtoms::label ||
                aTag == nsGkAtoms::description) {
         if ((aTag == nsGkAtoms::label || aTag == nsGkAtoms::description) && 
             (! aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::value))) {
           // XXX we should probably be calling ConstructBlock here to handle
           // things like columns etc
           if (aTag == nsGkAtoms::label) {
-            newFrame = NS_NewXULLabelFrame(mPresShell, aStyleContext,
-                                           NS_BLOCK_FLOAT_MGR |
-                                           NS_BLOCK_MARGIN_ROOT);
+            newFrame = NS_NewXULLabelFrame(mPresShell, aStyleContext);
           } else {
             newFrame = NS_NewBlockFrame(mPresShell, aStyleContext,
                                         NS_BLOCK_FLOAT_MGR |
                                         NS_BLOCK_MARGIN_ROOT);
           }
         }
         else {
           newFrame = NS_NewTextBoxFrame(mPresShell, aStyleContext);
         }
       }
       // End of TEXT CONSTRUCTION logic
 
        // Menu Construction    
       else if (aTag == nsGkAtoms::menu ||
-               aTag == nsGkAtoms::menuitem || 
                aTag == nsGkAtoms::menubutton) {
         // A derived class box frame
         // that has custom reflow to prevent menu children
         // from becoming part of the flow.
-        newFrame = NS_NewMenuFrame(mPresShell, aStyleContext,
-          (aTag != nsGkAtoms::menuitem));
+        newFrame = NS_NewMenuFrame(mPresShell, aStyleContext);
+      }
+      else if (aTag == nsGkAtoms::menuitem) {
+        newFrame = NS_NewMenuItemFrame(mPresShell, aStyleContext);
       }
       else if (aTag == nsGkAtoms::menubar) {
   #ifdef XP_MACOSX
         // On Mac OS X, we use the system menubar for any root chrome shell
         // XUL menubars.
         PRBool isRootChromeShell = PR_FALSE;
         nsCOMPtr<nsISupports> container = aState.mPresContext->GetContainer();
         if (container) {
@@ -5643,17 +5634,17 @@ nsCSSFrameConstructor::ConstructXULFrame
     // Display types for XUL start here
     // Make sure this is kept in sync with nsCSSProps::kDisplayKTable
     // First is BOX
     if (!newFrame && isXULDisplay) {
       triedFrame = PR_TRUE;
   
       if (display->mDisplay == NS_STYLE_DISPLAY_INLINE_BOX ||
                display->mDisplay == NS_STYLE_DISPLAY_BOX) {
-        newFrame = NS_NewBoxFrame(mPresShell, aStyleContext, PR_FALSE, nsnull);
+        newFrame = NS_NewBoxFrame(mPresShell, aStyleContext);
 
         // Boxes can scroll.
         mayBeScrollable = PR_TRUE;
       } // End of BOX CONSTRUCTION logic
 #ifdef MOZ_XUL
       // ------- Begin Grid ---------
       else if (display->mDisplay == NS_STYLE_DISPLAY_INLINE_GRID ||
                display->mDisplay == NS_STYLE_DISPLAY_GRID) {
@@ -5662,54 +5653,34 @@ nsCSSFrameConstructor::ConstructXULFrame
         newFrame = NS_NewBoxFrame(mPresShell, aStyleContext, PR_FALSE, layout);
 
         // Boxes can scroll.
         mayBeScrollable = PR_TRUE;
       } //------- End Grid ------
 
       // ------- Begin Rows/Columns ---------
       else if (display->mDisplay == NS_STYLE_DISPLAY_GRID_GROUP) {
-        nsCOMPtr<nsIBoxLayout> layout;
-      
         if (isXULNS && aTag == nsGkAtoms::listboxbody) {
-          NS_NewListBoxLayout(mPresShell, layout);
-          newFrame = NS_NewListBoxBodyFrame(mPresShell, aStyleContext, PR_FALSE, layout);
+          newFrame = NS_NewListBoxBodyFrame(mPresShell, aStyleContext);
         }
         else
         {
-          NS_NewGridRowGroupLayout(mPresShell, getter_AddRefs(layout));
-          newFrame = NS_NewGridRowGroupFrame(mPresShell, aStyleContext, PR_FALSE, layout);
+          newFrame = NS_NewGridRowGroupFrame(mPresShell, aStyleContext);
         }
 
         // Boxes can scroll.
-        if (display->IsScrollableOverflow()) {
-          // set the top to be the newly created scrollframe
-          BuildScrollFrame(aState, aContent, aStyleContext, newFrame,
-                           aParentFrame, topFrame, aStyleContext);
-
-          // we have a scrollframe so the parent becomes the scroll frame.
-          aParentFrame = newFrame->GetParent();
-
-          primaryFrameSet = PR_TRUE;
-
-          frameHasBeenInitialized = PR_TRUE;
-        }
+        mayBeScrollable = PR_TRUE;
       } //------- End Grid ------
 
       // ------- Begin Row/Column ---------
       else if (display->mDisplay == NS_STYLE_DISPLAY_GRID_LINE) {
-        nsCOMPtr<nsIBoxLayout> layout;
-
-
-        NS_NewGridRowLeafLayout(mPresShell, getter_AddRefs(layout));
-
         if (isXULNS && aTag == nsGkAtoms::listitem)
-          newFrame = NS_NewListItemFrame(mPresShell, aStyleContext, PR_FALSE, layout);
+          newFrame = NS_NewListItemFrame(mPresShell, aStyleContext);
         else
-          newFrame = NS_NewGridRowLeafFrame(mPresShell, aStyleContext, PR_FALSE, layout);
+          newFrame = NS_NewGridRowLeafFrame(mPresShell, aStyleContext);
 
         // Boxes can scroll.
         mayBeScrollable = PR_TRUE;
       } //------- End Grid ------
       // End of STACK CONSTRUCTION logic
        // DECK CONSTRUCTION
       else if (display->mDisplay == NS_STYLE_DISPLAY_DECK) {
         newFrame = NS_NewDeckFrame(mPresShell, aStyleContext);
@@ -7037,17 +7008,17 @@ nsCSSFrameConstructor::ConstructFrameInt
   // XUL frame. This is temporary, pending planned factoring of this
   // whole process into separate, pluggable steps.
   if (NS_SUCCEEDED(rv) &&
       (!frameItems->childList || lastChild == frameItems->lastChild)) {
     PRBool haltProcessing;
 
     rv = ConstructXULFrame(aState, aContent, adjParentFrame, aTag,
                            aNameSpaceID, styleContext,
-                           *frameItems, aXBLBaseTag, pseudoParent,
+                           *frameItems, pseudoParent,
                            &haltProcessing);
 
     if (haltProcessing) {
       return rv;
     }
   } 
 
 // MathML Mod - RBS
@@ -9876,17 +9847,17 @@ nsCSSFrameConstructor::CreateContinuingF
 
     if (newFrame) {
       newFrame->Init(content, aParentFrame, aFrame);
       nsHTMLContainerFrame::CreateViewForFrame(newFrame, PR_FALSE);
     }
   
 #ifdef MOZ_XUL
   } else if (nsGkAtoms::XULLabelFrame == frameType) {
-    newFrame = NS_NewXULLabelFrame(shell, styleContext, 0);
+    newFrame = NS_NewXULLabelFrame(shell, styleContext);
 
     if (newFrame) {
       newFrame->Init(content, aParentFrame, aFrame);
       nsHTMLContainerFrame::CreateViewForFrame(newFrame, PR_FALSE);
     }
 #endif  
   } else if (nsGkAtoms::columnSetFrame == frameType) {
     newFrame = NS_NewColumnSetFrame(shell, styleContext, 0);
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -842,17 +842,16 @@ private:
 
   nsresult ConstructXULFrame(nsFrameConstructorState& aState,
                              nsIContent*              aContent,
                              nsIFrame*                aParentFrame,
                              nsIAtom*                 aTag,
                              PRInt32                  aNameSpaceID,
                              nsStyleContext*          aStyleContext,
                              nsFrameItems&            aFrameItems,
-                             PRBool                   aXBLBaseTag,
                              PRBool                   aHasPseudoParent,
                              PRBool*                  aHaltProcessing);
 
 // SVG - rods
 #ifdef MOZ_SVG
   nsresult ConstructSVGFrame(nsFrameConstructorState& aState,
                              nsIContent*              aContent,
                              nsIFrame*                aParentFrame,
--- a/layout/xul/base/src/grid/nsGridRowGroupFrame.cpp
+++ b/layout/xul/base/src/grid/nsGridRowGroupFrame.cpp
@@ -43,28 +43,33 @@
 //
 
 #include "nsGridRowGroupFrame.h"
 #include "nsGridRowLeafLayout.h"
 #include "nsGridRow.h"
 #include "nsBoxLayoutState.h"
 #include "nsGridLayout2.h"
 
+nsresult
+NS_NewGridRowGroupLayout(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
+
 nsIFrame*
-NS_NewGridRowGroupFrame (nsIPresShell* aPresShell,
-                         nsStyleContext* aContext,
-                         PRBool aIsRoot,
-                         nsIBoxLayout* aLayoutManager)
+NS_NewGridRowGroupFrame(nsIPresShell* aPresShell,
+                        nsStyleContext* aContext)
 {
-  return
-    new (aPresShell) nsGridRowGroupFrame (aPresShell, aContext, aIsRoot, aLayoutManager);
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewGridRowGroupLayout(aPresShell, getter_AddRefs(layout));
+  if (!layout) {
+    return nsnull;
+  }
+
+  return new (aPresShell) nsGridRowGroupFrame(aPresShell, aContext, layout);
 } 
 
 
-
 /**
  * This is redefined because row groups have a funny property. If they are flexible
  * then their flex must be equal to the sum of their children's flexes.
  */
 nscoord
 nsGridRowGroupFrame::GetFlex(nsBoxLayoutState& aState)
 {
   // if we are flexible out flexibility is determined by our columns.
--- a/layout/xul/base/src/grid/nsGridRowGroupFrame.h
+++ b/layout/xul/base/src/grid/nsGridRowGroupFrame.h
@@ -53,32 +53,27 @@
  * an element that is a child of a grid and contains all the rows (or
  * all the columns).  However, multiple levels of groups are allowed, so
  * the parent or child could instead be another group.
  */
 class nsGridRowGroupFrame : public nsBoxFrame
 {
 public:
 
-  friend nsIFrame* NS_NewGridRowGroupFrame(nsIPresShell* aPresShell,
-                                           nsStyleContext* aContext,
-                                           nsIBoxLayout* aLayoutManager);
-
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const
   {
       return MakeFrameName(NS_LITERAL_STRING("nsGridRowGroup"), aResult);
   }
 #endif
 
   nsGridRowGroupFrame(nsIPresShell* aPresShell,
                       nsStyleContext* aContext,
-                      PRBool aIsRoot,
                       nsIBoxLayout* aLayoutManager):
-    nsBoxFrame(aPresShell, aContext, aIsRoot, aLayoutManager) {}
+    nsBoxFrame(aPresShell, aContext, PR_FALSE, aLayoutManager) {}
 
   virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState);
 
 }; // class nsGridRowGroupFrame
 
 
 
 #endif
--- a/layout/xul/base/src/grid/nsGridRowLeafFrame.cpp
+++ b/layout/xul/base/src/grid/nsGridRowLeafFrame.cpp
@@ -43,23 +43,31 @@
 //
 
 #include "nsGridRowLeafFrame.h"
 #include "nsGridRowLeafLayout.h"
 #include "nsGridRow.h"
 #include "nsBoxLayoutState.h"
 #include "nsGridLayout2.h"
 
+nsresult
+NS_NewGridRowLeafLayout(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
+
 nsIFrame*
 NS_NewGridRowLeafFrame(nsIPresShell* aPresShell,
-                       nsStyleContext* aContext,
-                       PRBool aIsRoot,
-                       nsIBoxLayout* aLayoutManager)
+                       nsStyleContext* aContext)
 {
-    return new (aPresShell) nsGridRowLeafFrame (aPresShell, aContext, aIsRoot, aLayoutManager);
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewGridRowLeafLayout(aPresShell, getter_AddRefs(layout));
+  if (!layout) {
+    return nsnull;
+  }
+  
+  return new (aPresShell) nsGridRowLeafFrame(aPresShell, aContext, PR_FALSE,
+                                             layout);
 } 
 
 /*
  * Our border and padding could be affected by our columns or rows.
  * Let's go check it out.
  */
 NS_IMETHODIMP
 nsGridRowLeafFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding)
--- a/layout/xul/base/src/grid/nsGridRowLeafFrame.h
+++ b/layout/xul/base/src/grid/nsGridRowLeafFrame.h
@@ -55,18 +55,17 @@
  */
 // XXXldb This needs a better name that indicates that it's for any grid
 // row.
 class nsGridRowLeafFrame : public nsBoxFrame
 {
 public:
 
   friend nsIFrame* NS_NewGridRowLeafFrame(nsIPresShell* aPresShell,
-                                          nsStyleContext* aContext,
-                                          nsIBoxLayout* aLayoutManager);
+                                          nsStyleContext* aContext);
 
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const
   {
       return MakeFrameName(NS_LITERAL_STRING("nsGridRowLeaf"), aResult);
   }
 #endif
 
--- a/layout/xul/base/src/nsBoxFrame.cpp
+++ b/layout/xul/base/src/nsBoxFrame.cpp
@@ -125,16 +125,22 @@ nsIBox* nsBoxFrame::mDebugChild = nsnull
 #endif
 
 nsIFrame*
 NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
 {
   return new (aPresShell) nsBoxFrame(aPresShell, aContext, aIsRoot, aLayoutManager);
 } // NS_NewBoxFrame
 
+nsIFrame*
+NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
+{
+  return new (aPresShell) nsBoxFrame(aPresShell, aContext);
+}
+
 nsBoxFrame::nsBoxFrame(nsIPresShell* aPresShell,
                        nsStyleContext* aContext,
                        PRBool aIsRoot,
                        nsIBoxLayout* aLayoutManager) :
   nsContainerFrame(aContext),
   mMouseThrough(unset)
 {
   mState |= NS_STATE_IS_HORIZONTAL;
--- a/layout/xul/base/src/nsBoxFrame.h
+++ b/layout/xul/base/src/nsBoxFrame.h
@@ -61,27 +61,31 @@ class nsBoxLayoutState;
 //#define NS_STATE_DEBUG_WAS_SET           0x08000000  moved to nsBox.h
 #define NS_STATE_IS_COLLAPSED            0x10000000
 #define NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK 0x20000000
 #define NS_STATE_EQUAL_SIZE              0x40000000
 //#define NS_STATE_IS_DIRECTION_NORMAL     0x80000000  moved to nsIFrame.h
 
 nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
                          nsStyleContext* aContext,
-                         PRBool aIsRoot = PR_FALSE,
-                         nsIBoxLayout* aLayoutManager = nsnull);
+                         PRBool aIsRoot,
+                         nsIBoxLayout* aLayoutManager);
+nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
+                         nsStyleContext* aContext);
 
 class nsBoxFrame : public nsContainerFrame
 {
 public:
 
   friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, 
                                   nsStyleContext* aContext,
                                   PRBool aIsRoot,
                                   nsIBoxLayout* aLayoutManager);
+  friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
+                                  nsStyleContext* aContext);
 
   // gets the rect inside our border and debug border. If you wish to paint inside a box
   // call this method to get the rect so you don't draw on the debug border or outer border.
 
   // ------ nsIBox -------------
   NS_IMETHOD SetLayoutManager(nsIBoxLayout* aLayout);
   NS_IMETHOD GetLayoutManager(nsIBoxLayout** aLayout);
   NS_IMETHOD RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIBox* aChild);
@@ -167,17 +171,17 @@ public:
   NS_IMETHOD DidReflow(nsPresContext*           aPresContext,
                        const nsHTMLReflowState*  aReflowState,
                        nsDidReflowStatus         aStatus);
 
   virtual PRBool HonorPrintBackgroundSettings();
 
   virtual ~nsBoxFrame();
   
-  nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot = nsnull, nsIBoxLayout* aLayoutManager = nsnull);
+  nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot = PR_FALSE, nsIBoxLayout* aLayoutManager = nsnull);
 
   // if aIsPopup is true, then the view is for a popup. In this case,
   // the view is added a child of the root view, and is initially hidden
   static nsresult CreateViewForFrame(nsPresContext* aPresContext,
                                      nsIFrame* aChild,
                                      nsStyleContext* aStyleContext,
                                      PRBool aForce,
                                      PRBool aIsPopup = PR_FALSE);
--- a/layout/xul/base/src/nsDeckFrame.cpp
+++ b/layout/xul/base/src/nsDeckFrame.cpp
@@ -53,34 +53,27 @@
 #include "nsIPresShell.h"
 #include "nsCSSRendering.h"
 #include "nsIViewManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsStackLayout.h"
 #include "nsDisplayList.h"
 
 nsIFrame*
-NS_NewDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayoutManager)
+NS_NewDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
-  return new (aPresShell) nsDeckFrame(aPresShell, aContext, aLayoutManager);
+  return new (aPresShell) nsDeckFrame(aPresShell, aContext);
 } // NS_NewDeckFrame
 
 
-nsDeckFrame::nsDeckFrame(nsIPresShell* aPresShell,
-                         nsStyleContext* aContext,
-                         nsIBoxLayout* aLayoutManager)
+nsDeckFrame::nsDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
   : nsBoxFrame(aPresShell, aContext), mIndex(0)
 {
-     // if no layout manager specified us the static sprocket layout
-  nsCOMPtr<nsIBoxLayout> layout = aLayoutManager;
-
-  if (!layout) {
-    NS_NewStackLayout(aPresShell, layout);
-  }
-
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewStackLayout(aPresShell, layout);
   SetLayoutManager(layout);
 }
 
 nsIAtom*
 nsDeckFrame::GetType() const
 {
   return nsGkAtoms::deckFrame;
 }
--- a/layout/xul/base/src/nsDeckFrame.h
+++ b/layout/xul/base/src/nsDeckFrame.h
@@ -48,18 +48,17 @@
 
 #include "nsBoxFrame.h"
 
 class nsDeckFrame : public nsBoxFrame
 {
 public:
 
   friend nsIFrame* NS_NewDeckFrame(nsIPresShell* aPresShell,
-                                   nsStyleContext* aContext,
-                                   nsIBoxLayout* aLayoutManager);
+                                   nsStyleContext* aContext);
 
   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
                               nsIAtom*        aAttribute,
                               PRInt32         aModType);
 
   NS_IMETHOD DoLayout(nsBoxLayoutState& aState);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
@@ -82,19 +81,17 @@ public:
 
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const
   {
       return MakeFrameName(NS_LITERAL_STRING("Deck"), aResult);
   }
 #endif
 
-  nsDeckFrame(nsIPresShell* aPresShell,
-              nsStyleContext* aContext,
-              nsIBoxLayout* aLayout = nsnull);
+  nsDeckFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 protected:
 
   // REVIEW: Sorry, I couldn't resist devirtualizing these.
   nsIBox* GetSelectedBox();
   void IndexChanged(nsPresContext* aPresContext);
   PRInt32 GetSelectedIndex();
   void HideBox(nsPresContext* aPresContext, nsIBox* aBox);
--- a/layout/xul/base/src/nsListBoxBodyFrame.cpp
+++ b/layout/xul/base/src/nsListBoxBodyFrame.cpp
@@ -167,19 +167,18 @@ nsListScrollSmoother::Stop()
 }
 
 NS_IMPL_ISUPPORTS1(nsListScrollSmoother, nsITimerCallback)
 
 /////////////// nsListBoxBodyFrame //////////////////
 
 nsListBoxBodyFrame::nsListBoxBodyFrame(nsIPresShell* aPresShell,
                                        nsStyleContext* aContext,
-                                       PRBool aIsRoot,
                                        nsIBoxLayout* aLayoutManager)
-  : nsBoxFrame(aPresShell, aContext, aIsRoot, aLayoutManager),
+  : nsBoxFrame(aPresShell, aContext, PR_FALSE, aLayoutManager),
     mRowCount(-1),
     mRowHeight(0),
     mRowHeightWasSet(PR_FALSE),
     mAvailableHeight(0),
     mStringWidth(-1),
     mTopFrame(nsnull),
     mBottomFrame(nsnull),
     mLinkupFrame(nsnull),
@@ -1492,15 +1491,22 @@ nsListBoxBodyFrame::RemoveChildFrame(nsB
                "Going to destroy a frame we didn't remove.  Prepare to crash");
   if (mLayoutManager)
     mLayoutManager->ChildrenRemoved(this, aState, aFrame);
   aFrame->Destroy();
 }
 
 // Creation Routines ///////////////////////////////////////////////////////////////////////
 
+nsresult
+NS_NewListBoxLayout ( nsIPresShell* aPresShell, nsCOMPtr<nsIBoxLayout>& aNewLayout );
+
 nsIFrame*
-NS_NewListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
-                       PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
+NS_NewListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
-  return 
-    new (aPresShell) nsListBoxBodyFrame(aPresShell, aContext, aIsRoot, aLayoutManager);
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewListBoxLayout(aPresShell, layout);
+  if (!layout) {
+    return nsnull;
+  }
+
+  return new (aPresShell) nsListBoxBodyFrame(aPresShell, aContext, layout);
 }
--- a/layout/xul/base/src/nsListBoxBodyFrame.h
+++ b/layout/xul/base/src/nsListBoxBodyFrame.h
@@ -48,25 +48,24 @@
 #include "nsIReflowCallback.h"
 #include "nsPresContext.h"
 #include "nsBoxLayoutState.h"
 #include "nsThreadUtils.h"
 #include "nsPIBoxObject.h"
 
 class nsListScrollSmoother;
 nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
-                                 nsStyleContext* aContext,
-                                 PRBool aIsRoot = PR_FALSE,
-                                 nsIBoxLayout* aLayoutManager = nsnull);
+                                 nsStyleContext* aContext);
 
 class nsListBoxBodyFrame : public nsBoxFrame,
                            public nsIScrollbarMediator,
                            public nsIReflowCallback
 {
-  nsListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot = nsnull, nsIBoxLayout* aLayoutManager = nsnull);
+  nsListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
+                     nsIBoxLayout* aLayoutManager);
   virtual ~nsListBoxBodyFrame();
 
 public:
   NS_DECLARE_FRAME_ACCESSOR(nsListBoxBodyFrame)
 
   NS_DECL_QUERYFRAME
 
   // non-virtual nsIListBoxObject
@@ -75,19 +74,17 @@ public:
   nsresult GetIndexOfFirstVisibleRow(PRInt32 *aResult);
   nsresult EnsureIndexIsVisible(PRInt32 aRowIndex);
   nsresult ScrollToIndex(PRInt32 aRowIndex);
   nsresult ScrollByLines(PRInt32 aNumLines);
   nsresult GetItemAtIndex(PRInt32 aIndex, nsIDOMElement **aResult);
   nsresult GetIndexOfItem(nsIDOMElement *aItem, PRInt32 *aResult);
 
   friend nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
-                                          nsStyleContext* aContext,
-                                          PRBool aIsRoot,
-                                          nsIBoxLayout* aLayoutManager);
+                                          nsStyleContext* aContext);
   
   // nsIFrame
   NS_IMETHOD Init(nsIContent*     aContent,
                   nsIFrame*       aParent, 
                   nsIFrame*       aPrevInFlow);
   virtual void Destroy();
 
   NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aModType);
--- a/layout/xul/base/src/nsListItemFrame.cpp
+++ b/layout/xul/base/src/nsListItemFrame.cpp
@@ -38,16 +38,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsListItemFrame.h"
 
 #include "nsCOMPtr.h"
 #include "nsINameSpaceManager.h" 
 #include "nsGkAtoms.h"
 #include "nsDisplayList.h"
+#include "nsIBoxLayout.h"
 
 nsListItemFrame::nsListItemFrame(nsIPresShell* aPresShell,
                                  nsStyleContext* aContext,
                                  PRBool aIsRoot,
                                  nsIBoxLayout* aLayoutManager)
   : nsGridRowLeafFrame(aPresShell, aContext, aIsRoot, aLayoutManager) 
 {
 }
@@ -79,14 +80,23 @@ nsListItemFrame::BuildDisplayListForChil
       return NS_OK;
   }
   
   return nsGridRowLeafFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
 }
 
 // Creation Routine ///////////////////////////////////////////////////////////////////////
 
+nsresult
+NS_NewGridRowLeafLayout(nsIPresShell* aPresShell, nsIBoxLayout** aNewLayout);
+
 nsIFrame*
-NS_NewListItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
+NS_NewListItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
-  return new (aPresShell) nsListItemFrame(aPresShell, aContext, aIsRoot, aLayoutManager);
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewGridRowLeafLayout(aPresShell, getter_AddRefs(layout));
+  if (!layout) {
+    return nsnull;
+  }
+  
+  return new (aPresShell) nsListItemFrame(aPresShell, aContext, PR_FALSE, layout);
 } // NS_NewListItemFrame
 
--- a/layout/xul/base/src/nsListItemFrame.h
+++ b/layout/xul/base/src/nsListItemFrame.h
@@ -36,27 +36,23 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsBoxFrame.h"
 #include "nsGridRowLeafFrame.h"
 
 nsIFrame* NS_NewListItemFrame(nsIPresShell* aPresShell,
-                              nsStyleContext *aContext,
-                              PRBool aIsRoot = PR_FALSE,
-                              nsIBoxLayout* aLayoutManager = nsnull);
+                              nsStyleContext *aContext);
 
 class nsListItemFrame : public nsGridRowLeafFrame
 {
 public:
   friend nsIFrame* NS_NewListItemFrame(nsIPresShell* aPresShell,
-                                       nsStyleContext *aContext,
-                                       PRBool aIsRoot,
-                                       nsIBoxLayout* aLayoutManager);
+                                       nsStyleContext *aContext);
 
   // overridden so that children of listitems don't handle mouse events,
   // unless allowevents="true" is specified on the listitem
   NS_IMETHOD BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
                                          const nsRect&           aDirtyRect,
                                          const nsDisplayListSet& aLists);
 
   // nsIBox
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -148,31 +148,42 @@ public:
 
 private:
   nsCOMPtr<nsIContent> mMenu;
   nsCOMPtr<nsPresContext> mPresContext;
   PRBool mIsActivate;
 };
 
 //
-// NS_NewMenuFrame
+// NS_NewMenuFrame and NS_NewMenuItemFrame
 //
-// Wrapper for creating a new menu popup container
+// Wrappers for creating a new menu popup container
 //
 nsIFrame*
-NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags)
+NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   nsMenuFrame* it = new (aPresShell) nsMenuFrame (aPresShell, aContext);
   
-  if ((it != nsnull) && aFlags)
+  if (it)
     it->SetIsMenu(PR_TRUE);
 
   return it;
 }
 
+nsIFrame*
+NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
+{
+  nsMenuFrame* it = new (aPresShell) nsMenuFrame (aPresShell, aContext);
+
+  if (it)
+    it->SetIsMenu(PR_FALSE);
+
+  return it;
+}
+
 NS_QUERYFRAME_HEAD(nsMenuFrame)
   NS_QUERYFRAME_ENTRY(nsIMenuFrame)
   NS_QUERYFRAME_ENTRY(nsIScrollableViewProvider)
 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
 
 //
 // nsMenuFrame cntr
 //
--- a/layout/xul/base/src/nsMenuFrame.h
+++ b/layout/xul/base/src/nsMenuFrame.h
@@ -54,17 +54,18 @@
 #include "nsIMenuFrame.h"
 #include "nsXULPopupManager.h"
 #include "nsITimer.h"
 #include "nsISupportsArray.h"
 #include "nsIDOMText.h"
 #include "nsIContent.h"
 #include "nsIScrollableViewProvider.h"
 
-nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
+nsIFrame* NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
+nsIFrame* NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 class nsMenuBarFrame;
 class nsIScrollableView;
 
 #define NS_STATE_ACCELTEXT_IS_DERIVED  NS_STATE_BOX_CHILD_RESERVED
 
 // the type of menuitem
 enum nsMenuType {
--- a/layout/xul/base/src/nsStackFrame.cpp
+++ b/layout/xul/base/src/nsStackFrame.cpp
@@ -50,31 +50,26 @@
 #include "nsHTMLParts.h"
 #include "nsIPresShell.h"
 #include "nsCSSRendering.h"
 #include "nsBoxLayoutState.h"
 #include "nsStackLayout.h"
 #include "nsDisplayList.h"
 
 nsIFrame*
-NS_NewStackFrame (nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayoutManager)
+NS_NewStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
-  return new (aPresShell) nsStackFrame(aPresShell, aContext, aLayoutManager);
+  return new (aPresShell) nsStackFrame(aPresShell, aContext);
 } // NS_NewStackFrame
 
-nsStackFrame::nsStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayoutManager):
+nsStackFrame::nsStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext):
   nsBoxFrame(aPresShell, aContext)
 {
-    // if no layout manager specified us the stack layout
-  nsCOMPtr<nsIBoxLayout> layout = aLayoutManager;
-
-  if (layout == nsnull) {
-    NS_NewStackLayout(aPresShell, layout);
-  }
-
+  nsCOMPtr<nsIBoxLayout> layout;
+  NS_NewStackLayout(aPresShell, layout);
   SetLayoutManager(layout);
 }
 
 // REVIEW: The old code put everything in the background layer. To be more
 // consistent with the way other frames work, I'm putting everything in the
 // Content() (i.e., foreground) layer (see nsFrame::BuildDisplayListForChild,
 // the case for stacking context but non-positioned, non-floating frames).
 // This could easily be changed back by hacking nsBoxFrame::BuildDisplayListInternal
--- a/layout/xul/base/src/nsStackFrame.h
+++ b/layout/xul/base/src/nsStackFrame.h
@@ -47,29 +47,30 @@
 #define nsStackFrame_h___
 
 #include "nsBoxFrame.h"
 
 class nsStackFrame : public nsBoxFrame
 {
 public:
 
-  friend nsIFrame* NS_NewStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayout = nsnull);
+  friend nsIFrame* NS_NewStackFrame(nsIPresShell* aPresShell,
+                                    nsStyleContext* aContext);
 
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const
   {
     return MakeFrameName(NS_LITERAL_STRING("Stack"), aResult);
   }
 #endif
 
   NS_IMETHOD BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
                                          const nsRect&           aDirtyRect,
                                          const nsDisplayListSet& aLists);
 
 protected:
-  nsStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, nsIBoxLayout* aLayout = nsnull);
+  nsStackFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 }; // class nsStackFrame
 
 
 
 #endif
 
--- a/layout/xul/base/src/nsXULLabelFrame.cpp
+++ b/layout/xul/base/src/nsXULLabelFrame.cpp
@@ -38,22 +38,22 @@
 /* derived class of nsBlockFrame used for xul:label elements */
 
 #include "nsXULLabelFrame.h"
 #include "nsHTMLParts.h"
 #include "nsINameSpaceManager.h"
 #include "nsIEventStateManager.h"
 
 nsIFrame*
-NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags)
+NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
   
-  if (it != nsnull)
-    it->SetFlags(aFlags);
+  if (it)
+    it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
 
   return it;
 }
 
 // If you make changes to this function, check its counterparts 
 // in nsBoxFrame and nsTextBoxFrame
 nsresult
 nsXULLabelFrame::RegUnregAccessKey(PRBool aDoReg)
--- a/layout/xul/base/src/nsXULLabelFrame.h
+++ b/layout/xul/base/src/nsXULLabelFrame.h
@@ -44,17 +44,18 @@
 
 #ifndef MOZ_XUL
 #error "This file should not be included"
 #endif
 
 class nsXULLabelFrame : public nsBlockFrame
 {
 public:
-  friend nsIFrame* NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext *aContext, PRUint32 aFlags);
+  friend nsIFrame* NS_NewXULLabelFrame(nsIPresShell* aPresShell,
+                                       nsStyleContext *aContext);
   
   // nsIFrame
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
 
   virtual void Destroy();
 
@@ -75,11 +76,11 @@ public:
 
 protected:
   nsXULLabelFrame(nsStyleContext *aContext) : nsBlockFrame(aContext) {}
 
   nsresult RegUnregAccessKey(PRBool aDoReg);
 };
 
 nsIFrame*
-NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
+NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 #endif /* !defined(nsXULLabelFrame_h_) */
--- a/layout/xul/base/src/tree/src/nsTreeColFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeColFrame.cpp
@@ -54,20 +54,19 @@
 #include "nsTreeBodyFrame.h"
 
 //
 // NS_NewTreeColFrame
 //
 // Creates a new col frame
 //
 nsIFrame*
-NS_NewTreeColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
-                   PRBool aIsRoot, nsIBoxLayout* aLayoutManager)
+NS_NewTreeColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
-  return new (aPresShell) nsTreeColFrame(aPresShell, aContext, aIsRoot, aLayoutManager);
+  return new (aPresShell) nsTreeColFrame(aPresShell, aContext);
 } // NS_NewTreeColFrame
 
 // Destructor
 nsTreeColFrame::~nsTreeColFrame()
 {
 }
 
 NS_IMETHODIMP
--- a/layout/xul/base/src/tree/src/nsTreeColFrame.h
+++ b/layout/xul/base/src/tree/src/nsTreeColFrame.h
@@ -36,28 +36,24 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsBoxFrame.h"
 
 class nsITreeBoxObject;
 
 nsIFrame* NS_NewTreeColFrame(nsIPresShell* aPresShell, 
-                             nsStyleContext* aContext,
-                             PRBool aIsRoot = PR_FALSE,
-                             nsIBoxLayout* aLayoutManager = nsnull);
+                             nsStyleContext* aContext);
 
 class nsTreeColFrame : public nsBoxFrame
 {
 public:
   nsTreeColFrame(nsIPresShell* aPresShell,
-                 nsStyleContext* aContext,
-                 PRBool aIsRoot = nsnull,
-                 nsIBoxLayout* aLayoutManager = nsnull):
-    nsBoxFrame(aPresShell, aContext, aIsRoot, aLayoutManager) {}
+                 nsStyleContext* aContext):
+    nsBoxFrame(aPresShell, aContext) {}
 
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
 
   virtual void Destroy();
 
   NS_IMETHOD BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
@@ -66,19 +62,18 @@ public:
 
   NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
                               nsIAtom* aAttribute,
                               PRInt32 aModType);
 
   virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
                          PRBool aRemoveOverflowArea = PR_FALSE);
 
-  friend nsIFrame* NS_NewTreeColFrame(nsIPresShell* aPresShell, 
-                                      PRBool aIsRoot,
-                                      nsIBoxLayout* aLayoutManager);
+  friend nsIFrame* NS_NewTreeColFrame(nsIPresShell* aPresShell,
+                                      nsStyleContext* aContext);
 
 protected:
   virtual ~nsTreeColFrame();
 
   /**
    * @return the tree box object of the tree this column belongs to, or nsnull.
    */
   nsITreeBoxObject* GetTreeBoxObject();