Bug 685154 - Cleanup nsIFrame::GetParentStyleContextFrame and related code. r=roc
authorMats Palmgren <matspal@gmail.com>
Mon, 12 Sep 2011 09:08:07 -0700
changeset 77932 79890feb4abe972aae795fbb0ccb6bf8959c8b5a
parent 77931 38ff711d43699ddf0f16f287e08254e2da22b392
child 77933 d49caeac648d175aa7f3b23c0fdd3a2c13e99f33
push id340
push userclegnitto@mozilla.com
push dateTue, 08 Nov 2011 22:56:33 +0000
treeherdermozilla-beta@f745dc151615 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs685154
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 685154 - Cleanup nsIFrame::GetParentStyleContextFrame and related code. r=roc Make nsCSSFrameConstructor::ConstructTable return a null frame if creating the inner table frame fails. Simplify some code since we can now depend on the invariant that a properly created outer table frame always has a non-null inner table frame.
layout/base/nsCSSFrameConstructor.cpp
layout/mathml/nsMathMLmtableFrame.cpp
layout/tables/nsTableOuterFrame.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -1904,17 +1904,22 @@ nsCSSFrameConstructor::ConstructTable(ns
   InitAndRestoreFrame(aState, content, geometricParent, nsnull, newFrame);  
 
   // Create the inner table frame
   nsIFrame* innerFrame;
   if (kNameSpaceID_MathML == nameSpaceID)
     innerFrame = NS_NewMathMLmtableFrame(mPresShell, styleContext);
   else
     innerFrame = NS_NewTableFrame(mPresShell, styleContext);
- 
+
+  if (!innerFrame) {
+    newFrame->Destroy();
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
   InitAndRestoreFrame(aState, content, newFrame, nsnull, innerFrame);
 
   // Put the newly created frames into the right child list
   SetInitialSingleChild(newFrame, innerFrame);
 
   rv = aState.AddChild(newFrame, aFrameItems, content, styleContext,
                        aParentFrame);
   if (NS_FAILED(rv)) {
@@ -6670,20 +6675,18 @@ nsCSSFrameConstructor::ContentAppended(n
   }
 
   // Notify the parent frame passing it the list of new frames
   // Append the flowed frames to the principal child list; captions
   // need special treatment
   if (captionItems.NotEmpty()) { // append the caption to the outer table
     NS_ASSERTION(nsGkAtoms::tableFrame == frameType, "how did that happen?");
     nsIFrame* outerTable = parentFrame->GetParent();
-    if (outerTable) {
-      state.mFrameManager->AppendFrames(outerTable, nsIFrame::kCaptionList,
-                                        captionItems);
-    }
+    state.mFrameManager->AppendFrames(outerTable, nsIFrame::kCaptionList,
+                                      captionItems);
   }
 
   if (frameItems.NotEmpty()) { // append the in-flow kids
     AppendFrames(state, parentFrame, frameItems, prevSibling);
   }
 
   // Recover first-letter frames
   if (haveFirstLetterStyle) {
--- a/layout/mathml/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -453,18 +453,18 @@ nsMathMLmtableOuterFrame::AttributeChang
   // rowlines      : here 
   // rowspacing    : not yet supported 
   // columnalign   : here 
   // columnlines   : here 
   // columnspacing : not yet supported 
 
   // mtable is simple and only has one (pseudo) row-group inside our inner-table
   nsIFrame* tableFrame = mFrames.FirstChild();
-  if (!tableFrame || tableFrame->GetType() != nsGkAtoms::tableFrame)
-    return NS_OK;
+  NS_ASSERTION(tableFrame && tableFrame->GetType() == nsGkAtoms::tableFrame,
+               "should always have an inner table frame");
   nsIFrame* rgFrame = tableFrame->GetFirstPrincipalChild();
   if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
     return NS_OK;
 
   // align - just need to issue a dirty (resize) reflow command
   if (aAttribute == nsGkAtoms::align) {
     PresContext()->PresShell()->
       FrameNeedsReflow(this, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
@@ -543,18 +543,18 @@ nsMathMLmtableOuterFrame::GetRowFrameAt(
   } else {
     // aRowIndex is 1-based, so convert it to a 0-based index
     --aRowIndex;
   }
 
   // if our inner table says that the index is valid, find the row now
   if (0 <= aRowIndex && aRowIndex <= rowCount) {
     nsIFrame* tableFrame = mFrames.FirstChild();
-    if (!tableFrame || tableFrame->GetType() != nsGkAtoms::tableFrame)
-      return nsnull;
+    NS_ASSERTION(tableFrame && tableFrame->GetType() == nsGkAtoms::tableFrame,
+                 "should always have an inner table frame");
     nsIFrame* rgFrame = tableFrame->GetFirstPrincipalChild();
     if (!rgFrame || rgFrame->GetType() != nsGkAtoms::tableRowGroupFrame)
       return nsnull;
     nsTableIterator rowIter(*rgFrame);
     nsIFrame* rowFrame = rowIter.First();
     for ( ; rowFrame; rowFrame = rowIter.Next()) {
       if (aRowIndex == 0) {
         DEBUG_VERIFY_THAT_FRAME_IS(rowFrame, TABLE_ROW);
--- a/layout/tables/nsTableOuterFrame.cpp
+++ b/layout/tables/nsTableOuterFrame.cpp
@@ -239,27 +239,21 @@ nsTableOuterFrame::SetInitialChildList(C
   if (kCaptionList == aListID) {
     // the frame constructor already checked for table-caption display type
     mCaptionFrames.SetFrames(aChildList);
     mCaptionFrame = mCaptionFrames.FirstChild();
   }
   else {
     NS_ASSERTION(aListID == kPrincipalList, "wrong childlist");
     NS_ASSERTION(mFrames.IsEmpty(), "Frame leak!");
-    mInnerTableFrame = nsnull;
-    if (aChildList.NotEmpty()) {
-      if (nsGkAtoms::tableFrame == aChildList.FirstChild()->GetType()) {
-        mInnerTableFrame = (nsTableFrame*)aChildList.FirstChild();
-        mFrames.SetFrames(aChildList);
-      }
-      else {
-        NS_ERROR("expected a table frame");
-        return NS_ERROR_INVALID_ARG;
-      }
-    }
+    NS_ASSERTION(aChildList.FirstChild() &&
+                 nsGkAtoms::tableFrame == aChildList.FirstChild()->GetType(),
+                 "expected a table frame");
+    mInnerTableFrame = static_cast<nsTableFrame*>(aChildList.FirstChild());
+    mFrames.SetFrames(aChildList);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTableOuterFrame::AppendFrames(ChildListID     aListID,
                                 nsFrameList&    aFrameList)
@@ -389,52 +383,48 @@ nsTableOuterFrame::BuildDisplayListForIn
   return NS_OK;
 }
 
 void
 nsTableOuterFrame::SetSelected(PRBool        aSelected,
                                SelectionType aType)
 {
   nsFrame::SetSelected(aSelected, aType);
-  if (mInnerTableFrame) {
-    mInnerTableFrame->SetSelected(aSelected, aType);
-  }
+  mInnerTableFrame->SetSelected(aSelected, aType);
 }
 
 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
   // the table content node and creating a style context for the outer
   // frame that is a *child* of the table frame's style context,
   // matching the ::-moz-table-outer pseudo-element.  html.css has a
   // rule that causes that pseudo-element (and thus the outer table)
   // to inherit *some* style properties from the table frame.  The
   // children of the table inherit directly from the inner table, and
   // the outer table's style context is a leaf.
 
-  if (!mInnerTableFrame) {
-    return this;
-  }
   return mInnerTableFrame;
 }
 
 // INCREMENTAL REFLOW HELPER FUNCTIONS 
 
 void
 nsTableOuterFrame::InitChildReflowState(nsPresContext&    aPresContext,                     
                                         nsHTMLReflowState& aReflowState)
                                     
 {
   nsMargin collapseBorder;
   nsMargin collapsePadding(0,0,0,0);
   nsMargin* pCollapseBorder  = nsnull;
   nsMargin* pCollapsePadding = nsnull;
-  if ((aReflowState.frame == mInnerTableFrame) && (mInnerTableFrame->IsBorderCollapse())) {
+  if (aReflowState.frame == mInnerTableFrame &&
+      mInnerTableFrame->IsBorderCollapse()) {
     collapseBorder  = mInnerTableFrame->GetIncludedOuterBCBorder();
     pCollapseBorder = &collapseBorder;
     pCollapsePadding = &collapsePadding;
   }
   aReflowState.Init(&aPresContext, -1, -1, pCollapseBorder, pCollapsePadding);
 }
 
 // get the margin and padding data. nsHTMLReflowState doesn't handle the
@@ -953,22 +943,16 @@ nsTableOuterFrame::UpdateReflowMetrics(P
 NS_METHOD nsTableOuterFrame::Reflow(nsPresContext*           aPresContext,
                                     nsHTMLReflowMetrics&     aDesiredSize,
                                     const nsHTMLReflowState& aOuterRS,
                                     nsReflowStatus&          aStatus)
 {
   DO_GLOBAL_REFLOW_COUNT("nsTableOuterFrame");
   DISPLAY_REFLOW(aPresContext, this, aOuterRS, aDesiredSize, aStatus);
 
-  // We desperately need an inner table frame,
-  // if this fails fix the frame constructor
-  if (mFrames.IsEmpty() || !mInnerTableFrame) {
-    NS_ERROR("incomplete children");
-    return NS_ERROR_FAILURE;
-  }
   nsresult rv = NS_OK;
   PRUint8 captionSide = GetCaptionSide();
 
   // Initialize out parameters
   aDesiredSize.width = aDesiredSize.height = 0;
   aStatus = NS_FRAME_COMPLETE;
 
   if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
@@ -1164,50 +1148,42 @@ nsTableOuterFrame::GetType() const
 NS_IMETHODIMP 
 nsTableOuterFrame::GetCellDataAt(PRInt32 aRowIndex, PRInt32 aColIndex, 
                                  nsIDOMElement* &aCell,   //out params
                                  PRInt32& aStartRowIndex, PRInt32& aStartColIndex, 
                                  PRInt32& aRowSpan, PRInt32& aColSpan,
                                  PRInt32& aActualRowSpan, PRInt32& aActualColSpan,
                                  PRBool& aIsSelected)
 {
-  NS_ASSERTION(mInnerTableFrame, "no inner table frame yet?");
-  
   return mInnerTableFrame->GetCellDataAt(aRowIndex, aColIndex, aCell,
                                         aStartRowIndex, aStartColIndex, 
                                         aRowSpan, aColSpan, aActualRowSpan,
                                         aActualColSpan, aIsSelected);
 }
 
 NS_IMETHODIMP
 nsTableOuterFrame::GetTableSize(PRInt32& aRowCount, PRInt32& aColCount)
 {
-  NS_ASSERTION(mInnerTableFrame, "no inner table frame yet?");
-
   return mInnerTableFrame->GetTableSize(aRowCount, aColCount);
 }
 
 NS_IMETHODIMP
 nsTableOuterFrame::GetIndexByRowAndColumn(PRInt32 aRow, PRInt32 aColumn,
                                           PRInt32 *aIndex)
 {
   NS_ENSURE_ARG_POINTER(aIndex);
-
-  NS_ASSERTION(mInnerTableFrame, "no inner table frame yet?");
   return mInnerTableFrame->GetIndexByRowAndColumn(aRow, aColumn, aIndex);
 }
 
 NS_IMETHODIMP
 nsTableOuterFrame::GetRowAndColumnByIndex(PRInt32 aIndex,
                                           PRInt32 *aRow, PRInt32 *aColumn)
 {
   NS_ENSURE_ARG_POINTER(aRow);
   NS_ENSURE_ARG_POINTER(aColumn);
-
-  NS_ASSERTION(mInnerTableFrame, "no inner table frame yet?");
   return mInnerTableFrame->GetRowAndColumnByIndex(aIndex, aRow, aColumn);
 }
 
 /*---------------- end of nsITableLayout implementation ------------------*/
 
 
 nsIFrame*
 NS_NewTableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)