Split nsTableOuterFrame::OuterReflowChild. b=363248,386704 r+sr=roc a=blocking1.9+
authordbaron@dbaron.org
Tue, 26 Feb 2008 18:01:33 -0800
changeset 12308 cb136f670ea866f08ccd8a9a4c56a0b8640f0108
parent 12307 f0977ebba5afa433465fdc5364fe89221bf69751
child 12309 e56591cd45442e3cea5c37986dc90addd45ec359
push idunknown
push userunknown
push dateunknown
reviewersblocking1.9
bugs363248, 386704
milestone1.9b4pre
Split nsTableOuterFrame::OuterReflowChild. b=363248,386704 r+sr=roc a=blocking1.9+
layout/tables/nsTableOuterFrame.cpp
layout/tables/nsTableOuterFrame.h
--- a/layout/tables/nsTableOuterFrame.cpp
+++ b/layout/tables/nsTableOuterFrame.cpp
@@ -1089,29 +1089,23 @@ nsTableOuterFrame::IsNested(const nsHTML
     if (nsGkAtoms::tableFrame == rs->frame->GetType()) {
       return PR_TRUE;
     }
     rs = rs->parentReflowState;
   }
   return PR_FALSE;
 }
 
-nsresult
-nsTableOuterFrame::OuterReflowChild(nsPresContext*             aPresContext,
-                                    nsIFrame*                  aChildFrame,
-                                    const nsHTMLReflowState&   aOuterRS,
-                                    void*                      aChildRSSpace,
-                                    nsHTMLReflowMetrics&       aMetrics,
-                                    nscoord                    aAvailWidth, 
-                                    nsSize&                    aDesiredSize,
-                                    nsMargin&                  aMargin,
-                                    nsReflowStatus&            aStatus)
+void
+nsTableOuterFrame::OuterBeginReflowChild(nsPresContext*           aPresContext,
+                                         nsIFrame*                aChildFrame,
+                                         const nsHTMLReflowState& aOuterRS,
+                                         void*                    aChildRSSpace,
+                                         nscoord                  aAvailWidth)
 { 
-  aMargin = nsMargin(0,0,0,0);
-
   // work around pixel rounding errors, round down to ensure we don't exceed the avail height in
   nscoord availHeight = aOuterRS.availableHeight;
   if (NS_UNCONSTRAINEDSIZE != availHeight) {
     if (mCaptionFrame == aChildFrame) {
       availHeight = NS_UNCONSTRAINEDSIZE;
     } else {
       nsMargin margin;
       GetMargin(aPresContext, aOuterRS, aChildFrame, aOuterRS.availableWidth,
@@ -1135,34 +1129,31 @@ nsTableOuterFrame::OuterReflowChild(nsPr
 
   // see if we need to reset top of page due to a caption
   if (mCaptionFrame) {
     PRUint8 captionSide = GetCaptionSide();
     if (((NS_SIDE_BOTTOM == captionSide) && (mCaptionFrame == aChildFrame)) || 
         ((NS_SIDE_TOP == captionSide) && (mInnerTableFrame == aChildFrame))) {
       childRS.mFlags.mIsTopOfPage = PR_FALSE;
     }
-    if ((mCaptionFrame == aChildFrame) && (NS_SIDE_LEFT  != captionSide) 
-                                       && (NS_SIDE_RIGHT != captionSide)) {
-      aAvailWidth = aOuterRS.availableWidth;
-    }
   }
+}
+
+nsresult
+nsTableOuterFrame::OuterDoReflowChild(nsPresContext*             aPresContext,
+                                      nsIFrame*                  aChildFrame,
+                                      const nsHTMLReflowState&   aChildRS,
+                                      nsHTMLReflowMetrics&       aMetrics,
+                                      nsReflowStatus&            aStatus)
+{ 
 
   // use the current position as a best guess for placement
   nsPoint childPt = aChildFrame->GetPosition();
-  nsresult rv = ReflowChild(aChildFrame, aPresContext, aMetrics, childRS,
-                            childPt.x, childPt.y, NS_FRAME_NO_MOVE_FRAME, aStatus);
-  if (NS_FAILED(rv)) return rv;
-  
-  aMargin = childRS.mComputedMargin;
-
-  aDesiredSize.width  = aMetrics.width;
-  aDesiredSize.height = aMetrics.height;
-
-  return rv;
+  return ReflowChild(aChildFrame, aPresContext, aMetrics, aChildRS,
+                     childPt.x, childPt.y, NS_FRAME_NO_MOVE_FRAME, aStatus);
 }
 
 void 
 nsTableOuterFrame::UpdateReflowMetrics(PRUint8              aCaptionSide,
                                        nsHTMLReflowMetrics& aMet,
                                        const nsMargin&      aInnerMargin,
                                        const nsMargin&      aCaptionMargin)
 {
@@ -1217,23 +1208,28 @@ NS_METHOD nsTableOuterFrame::Reflow(nsPr
   // side captions small.
   nsHTMLReflowMetrics captionMet;
   nsSize captionSize;
   nsMargin captionMargin;
   // Use longs to get more-aligned space.
   #define LONGS_IN_HTMLRS \
     ((sizeof(nsHTMLReflowState) + sizeof(long) - 1) / sizeof(long))
   long captionRSSpace[LONGS_IN_HTMLRS];
+  nsHTMLReflowState *captionRS =
+    static_cast<nsHTMLReflowState*>((void*)captionRSSpace);
   if (reflowCaption) {
     nsReflowStatus capStatus; // don't let the caption cause incomplete
-    rv = OuterReflowChild(aPresContext, mCaptionFrame, aOuterRS,
-                          captionRSSpace, captionMet,
-                          aOuterRS.ComputedWidth(), captionSize,
-                          captionMargin, capStatus);
+    OuterBeginReflowChild(aPresContext, mCaptionFrame, aOuterRS,
+                          captionRSSpace, aOuterRS.ComputedWidth());
+    rv = OuterDoReflowChild(aPresContext, mCaptionFrame, *captionRS,
+                            captionMet, capStatus);
     if (NS_FAILED(rv)) return rv;
+    captionSize.width = captionMet.width;
+    captionSize.height = captionMet.height;
+    captionMargin = captionRS->mComputedMargin;
   } else if (mCaptionFrame) {
     captionSize = mCaptionFrame->GetSize();
     GetMargin(aPresContext, aOuterRS, mCaptionFrame, aOuterRS.ComputedWidth(),
               captionMargin);
   } else {
     captionSize.SizeTo(0,0);
     captionMargin.SizeTo(0,0,0,0);
   }
@@ -1245,21 +1241,27 @@ NS_METHOD nsTableOuterFrame::Reflow(nsPr
     innerAvailWidth -= captionMet.width + captionMargin.LeftRight();
 
   // Then, now that we know how much to reduce the width of the inner
   // table to account for side captions, reflow the inner table.
   nsHTMLReflowMetrics innerMet;
   nsSize innerSize;
   nsMargin innerMargin;
   long innerRSSpace[LONGS_IN_HTMLRS];
+  nsHTMLReflowState *innerRS =
+    static_cast<nsHTMLReflowState*>((void*) innerRSSpace);
   if (reflowInner) {
-    rv = OuterReflowChild(aPresContext, mInnerTableFrame, aOuterRS,
-                          innerRSSpace, innerMet, innerAvailWidth,
-                          innerSize, innerMargin, aStatus);
+    OuterBeginReflowChild(aPresContext, mInnerTableFrame, aOuterRS,
+                          innerRSSpace, innerAvailWidth);
+    rv = OuterDoReflowChild(aPresContext, mInnerTableFrame, *innerRS,
+                            innerMet, aStatus);
     if (NS_FAILED(rv)) return rv;
+    innerSize.width = innerMet.width;
+    innerSize.height = innerMet.height;
+    innerMargin = innerRS->mComputedMargin;
   } else {
     innerSize = mInnerTableFrame->GetSize();
     GetMargin(aPresContext, aOuterRS, mInnerTableFrame,
               aOuterRS.ComputedWidth(), innerMargin);
   }
 
   nsSize   containSize = GetContainingBlockSize(aOuterRS);
 
@@ -1269,18 +1271,16 @@ NS_METHOD nsTableOuterFrame::Reflow(nsPr
   // XXX Need to recompute inner table's auto margins for the case of side
   // captions.  (Caption's are broken too, but that should be fixed earlier.)
 
   if (mCaptionFrame) {
     nsPoint captionOrigin;
     GetCaptionOrigin(captionSide, containSize, innerSize, 
                      innerMargin, captionSize, captionMargin, captionOrigin);
     if (reflowCaption) {
-      nsHTMLReflowState *captionRS =
-        static_cast<nsHTMLReflowState*>((void*)captionRSSpace);
       FinishReflowChild(mCaptionFrame, aPresContext, captionRS, captionMet,
                         captionOrigin.x, captionOrigin.y, 0);
       captionRS->~nsHTMLReflowState();
     } else if (mCaptionFrame->GetPosition() != captionOrigin) {
       // Invalidate both the old and new rects
       mCaptionFrame->Invalidate(mCaptionFrame->GetOverflowRect());
       mCaptionFrame->SetPosition(captionOrigin);
       nsTableFrame::RePositionViews(mCaptionFrame);
@@ -1289,18 +1289,16 @@ NS_METHOD nsTableOuterFrame::Reflow(nsPr
   }
   // XXX If the height is constrained then we need to check whether
   // everything still fits...
 
   nsPoint innerOrigin;
   GetInnerOrigin(captionSide, containSize, captionSize, 
                  captionMargin, innerSize, innerMargin, innerOrigin);
   if (reflowInner) {
-    nsHTMLReflowState *innerRS =
-      static_cast<nsHTMLReflowState*>((void*) innerRSSpace);
     FinishReflowChild(mInnerTableFrame, aPresContext, innerRS, innerMet,
                       innerOrigin.x, innerOrigin.y, 0);
     innerRS->~nsHTMLReflowState();
   } else if (mInnerTableFrame->GetPosition() != innerOrigin) {
     // Invalidate both the old and new rects
     mInnerTableFrame->Invalidate(mInnerTableFrame->GetOverflowRect());
     mInnerTableFrame->SetPosition(innerOrigin);
     nsTableFrame::RePositionViews(mInnerTableFrame);
--- a/layout/tables/nsTableOuterFrame.h
+++ b/layout/tables/nsTableOuterFrame.h
@@ -229,42 +229,44 @@ protected:
                       nscoord&        aHeight);
 
   void BalanceLeftRightCaption(PRUint8         aCaptionSide,
                                const nsMargin& aInnerMargin, 
                                const nsMargin& aCaptionMargin,
                                nscoord&        aInnerWidth,
                                nscoord&        aCaptionWidth);
 
-  NS_IMETHOD GetCaptionOrigin(PRUint32         aCaptionSide,
+  nsresult   GetCaptionOrigin(PRUint32         aCaptionSide,
                               const nsSize&    aContainBlockSize,
                               const nsSize&    aInnerSize, 
                               const nsMargin&  aInnerMargin,
                               const nsSize&    aCaptionSize,
                               nsMargin&        aCaptionMargin,
                               nsPoint&         aOrigin);
 
-  NS_IMETHOD GetInnerOrigin(PRUint32         aCaptionSide,
+  nsresult   GetInnerOrigin(PRUint32         aCaptionSide,
                             const nsSize&    aContainBlockSize,
                             const nsSize&    aCaptionSize, 
                             const nsMargin&  aCaptionMargin,
                             const nsSize&    aInnerSize,
                             nsMargin&        aInnerMargin,
                             nsPoint&         aOrigin);
   
   // reflow the child (caption or innertable frame)
-  NS_IMETHOD OuterReflowChild(nsPresContext*            aPresContext,
-                              nsIFrame*                 aChildFrame,
-                              const nsHTMLReflowState&  aOuterRS,
-                              void*                     aChildRSSpace,
-                              nsHTMLReflowMetrics&      aMetrics,
-                              nscoord                   aAvailWidth,
-                              nsSize&                   aDesiredSize,
-                              nsMargin&                 aMargin,
-                              nsReflowStatus&           aStatus);
+  void OuterBeginReflowChild(nsPresContext*           aPresContext,
+                             nsIFrame*                aChildFrame,
+                             const nsHTMLReflowState& aOuterRS,
+                             void*                    aChildRSSpace,
+                             nscoord                  aAvailWidth);
+
+  nsresult OuterDoReflowChild(nsPresContext*           aPresContext,
+                              nsIFrame*                aChildFrame,
+                              const nsHTMLReflowState& aChildRS,
+                              nsHTMLReflowMetrics&     aMetrics,
+                              nsReflowStatus&          aStatus);
 
   // Set the reflow metrics
   void UpdateReflowMetrics(PRUint8              aCaptionSide,
                            nsHTMLReflowMetrics& aMet,
                            const nsMargin&      aInnerMargin,
                            const nsMargin&      aCaptionMargin);
 
   void InvalidateDamage(PRUint8         aCaptionSide,