Bug 481932 - use do_QueryFrame instead of IS_TABLE_CELL + cast; r+sr=roc
authorArpad Borsos <arpad.borsos@googlemail.com>
Tue, 24 Mar 2009 23:10:06 +0100
changeset 26583 931671e83e44f7bd1cb1df28b533a87014c03d58
parent 26582 f35e586819512327f0963e36f24b112da27ab2ef
child 26584 c352ad4174bb820bbdd71811b4ff3948d12eb768
push idunknown
push userunknown
push dateunknown
bugs481932
milestone1.9.2a1pre
Bug 481932 - use do_QueryFrame instead of IS_TABLE_CELL + cast; r+sr=roc
layout/tables/nsCellMap.cpp
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableCellFrame.h
layout/tables/nsTableFrame.cpp
layout/tables/nsTableRowFrame.cpp
layout/tables/nsTableRowFrame.h
layout/tables/nsTableRowGroupFrame.cpp
--- a/layout/tables/nsCellMap.cpp
+++ b/layout/tables/nsCellMap.cpp
@@ -1614,27 +1614,27 @@ void nsCellMap::CollapseZeroColSpan(nsTa
   }
 }
 
 PRBool nsCellMap::CellsSpanOut(nsTArray<nsTableRowFrame*>& aRows) const
 { 
   PRInt32 numNewRows = aRows.Length();
   for (PRInt32 rowX = 0; rowX < numNewRows; rowX++) {
     nsIFrame* rowFrame = (nsIFrame *) aRows.ElementAt(rowX);
-    nsIFrame* cellFrame = rowFrame->GetFirstChild(nsnull);
-    while (cellFrame) {
-      if (IS_TABLE_CELL(cellFrame->GetType())) {
+    nsIFrame* childFrame = rowFrame->GetFirstChild(nsnull);
+    while (childFrame) {
+      nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+      if (cellFrame) {
         PRBool zeroSpan;
-        PRInt32 rowSpan = GetRowSpanForNewCell((nsTableCellFrame*) cellFrame,
-                                               rowX, zeroSpan);
+        PRInt32 rowSpan = GetRowSpanForNewCell(cellFrame, rowX, zeroSpan);
         if (rowX + rowSpan > numNewRows) {
           return PR_TRUE;
         }
       }
-      cellFrame = cellFrame->GetNextSibling();
+      childFrame = childFrame->GetNextSibling();
     }
   }
   return PR_FALSE;
 }
     
 // return PR_TRUE if any cells have rows spans into or out of the region 
 // defined by the row and col indices or any cells have colspans into the region
 PRBool nsCellMap::CellsSpanInOrOut(PRInt32 aStartRowIndex,
@@ -1791,18 +1791,19 @@ nsCellMap::ExpandWithRows(nsTableCellMap
 
   PRInt32 newRowIndex = 0;
   for (PRInt32 rowX = startRowIndex; rowX <= endRowIndex; rowX++) {
     nsTableRowFrame* rFrame = aRowFrames.ElementAt(newRowIndex);
     // append cells 
     nsIFrame* cFrame = rFrame->GetFirstChild(nsnull);
     PRInt32 colIndex = 0;
     while (cFrame) {
-      if (IS_TABLE_CELL(cFrame->GetType())) {
-        AppendCell(aMap, (nsTableCellFrame *)cFrame, rowX, PR_FALSE, aDamageArea, &colIndex);
+      nsTableCellFrame *cellFrame = do_QueryFrame(cFrame);
+      if (cellFrame) {
+        AppendCell(aMap, cellFrame, rowX, PR_FALSE, aDamageArea, &colIndex);
       }
       cFrame = cFrame->GetNextSibling();
     }
     newRowIndex++;
   }
 
   SetDamageArea(0, startRowIndex, aMap.GetColCount(), 1 + endRowIndex - startRowIndex, aDamageArea); 
 }
@@ -2252,18 +2253,19 @@ nsCellMap::RebuildConsideringRows(nsTabl
   rowX = aStartRowIndex;
   if (aRowsToInsert) {
     // add in the new cells and create rows if necessary
     PRInt32 numNewRows = aRowsToInsert->Length();
     for (PRInt32 newRowX = 0; newRowX < numNewRows; newRowX++) {
       nsTableRowFrame* rFrame = aRowsToInsert->ElementAt(newRowX);
       nsIFrame* cFrame = rFrame->GetFirstChild(nsnull);
       while (cFrame) {
-        if (IS_TABLE_CELL(cFrame->GetType())) {
-          AppendCell(aMap, (nsTableCellFrame *)cFrame, rowX, PR_FALSE, aDamageArea);
+        nsTableCellFrame *cellFrame = do_QueryFrame(cFrame);
+        if (cellFrame) {
+          AppendCell(aMap, cellFrame, rowX, PR_FALSE, aDamageArea);
         }
         cFrame = cFrame->GetNextSibling();
       }
       rowX++;
     }
     copyStartRowIndex = aStartRowIndex;
   }
   else {
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -82,18 +82,19 @@ nsTableCellFrame::~nsTableCellFrame()
 {
 }
 
 nsTableCellFrame*  
 nsTableCellFrame::GetNextCell() const
 {
   nsIFrame* childFrame = GetNextSibling();
   while (childFrame) {
-    if (IS_TABLE_CELL(childFrame->GetType())) {
-      return (nsTableCellFrame*)childFrame;
+    nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+    if (cellFrame) {
+      return cellFrame;
     }
     childFrame = childFrame->GetNextSibling();
   }
   return nsnull;
 }
 
 NS_IMETHODIMP
 nsTableCellFrame::Init(nsIContent*      aContent,
@@ -1017,16 +1018,17 @@ NS_METHOD nsTableCellFrame::Reflow(nsPre
 
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
   return NS_OK;
 }
 
 /* ----- global methods ----- */
 
 NS_QUERYFRAME_HEAD(nsTableCellFrame)
+  NS_QUERYFRAME_ENTRY(nsTableCellFrame)
   NS_QUERYFRAME_ENTRY(nsITableCellLayout)
   NS_QUERYFRAME_ENTRY(nsIPercentHeightObserver)
 NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTableCellFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
--- a/layout/tables/nsTableCellFrame.h
+++ b/layout/tables/nsTableCellFrame.h
@@ -68,16 +68,17 @@ class nsTableFrame;
  * @author  sclark
  */
 class nsTableCellFrame : public nsHTMLContainerFrame, 
                          public nsITableCellLayout, 
                          public nsIPercentHeightObserver
 {
 public:
 
+  NS_DECLARE_FRAME_ACCESSOR(nsTableCellFrame)
   NS_DECL_QUERYFRAME
 
   // default constructor supplied by the compiler
 
   nsTableCellFrame(nsStyleContext* aContext);
   ~nsTableCellFrame();
 
   NS_IMETHOD Init(nsIContent*      aContent,
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -385,23 +385,23 @@ nsTableFrame::IsContainingBlock() const
 {
   return PR_TRUE;
 }
 
 void nsTableFrame::AttributeChangedFor(nsIFrame*       aFrame,
                                        nsIContent*     aContent, 
                                        nsIAtom*        aAttribute)
 {
-  if (IS_TABLE_CELL(aFrame->GetType())) {
+  nsTableCellFrame *cellFrame = do_QueryFrame(aFrame);
+  if (cellFrame) {
     if ((nsGkAtoms::rowspan == aAttribute) || 
         (nsGkAtoms::colspan == aAttribute)) {
       nsTableCellMap* cellMap = GetCellMap();
       if (cellMap) {
         // for now just remove the cell from the map and reinsert it
-        nsTableCellFrame* cellFrame = (nsTableCellFrame*)aFrame;
         PRInt32 rowIndex, colIndex;
         cellFrame->GetRowIndex(rowIndex);
         cellFrame->GetColIndex(colIndex);
         RemoveCell(cellFrame, rowIndex);
         nsAutoTArray<nsTableCellFrame*, 1> cells;
         cells.AppendElement(cellFrame);
         InsertCells(cells, rowIndex, colIndex - 1);
 
@@ -1047,18 +1047,18 @@ void nsTableFrame::RemoveRows(nsTableRow
                               PRBool           aConsiderSpans)
 {
 #ifdef TBD_OPTIMIZATION
   // decide if we need to rebalance. we have to do this here because the row group 
   // cannot do it when it gets the dirty reflow corresponding to the frame being destroyed
   PRBool stopTelling = PR_FALSE;
   for (nsIFrame* kidFrame = aFirstFrame.FirstChild(); (kidFrame && !stopAsking);
        kidFrame = kidFrame->GetNextSibling()) {
-    if (IS_TABLE_CELL(kidFrame->GetType())) {
-      nsTableCellFrame* cellFrame = (nsTableCellFrame*)kidFrame;
+    nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
+    if (cellFrame) {
       stopTelling = tableFrame->CellChangedWidth(*cellFrame, cellFrame->GetPass1MaxElementWidth(), 
                                                  cellFrame->GetMaximumWidth(), PR_TRUE);
     }
   }
   // XXX need to consider what happens if there are cells that have rowspans 
   // into the deleted row. Need to consider moving rows if a rebalance doesn't happen
 #endif
 
@@ -1126,18 +1126,19 @@ nsTableFrame::CollectRows(nsIFrame*     
                           nsTArray<nsTableRowFrame*>& aCollection)
 {
   if (!aFrame) return 0;
   PRInt32 numRows = 0;
   nsTableRowGroupFrame* rgFrame = GetRowGroupFrame(aFrame);
   if (rgFrame) {
     nsIFrame* childFrame = rgFrame->GetFirstChild(nsnull);
     while (childFrame) {
-      if (nsGkAtoms::tableRowFrame == childFrame->GetType()) {
-        aCollection.AppendElement(static_cast<nsTableRowFrame*>(childFrame));
+      nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+      if (rowFrame) {
+        aCollection.AppendElement(rowFrame);
         numRows++;
       }
       else {
         numRows += CollectRows(childFrame, aCollection);
       }
       childFrame = childFrame->GetNextSibling();
     }
   }
@@ -1595,18 +1596,18 @@ nsTableFrame::ProcessRowInserted(nscoord
   OrderRowGroups(rowGroups);
   // find the row group containing the inserted row
   for (PRUint32 rgX = 0; rgX < rowGroups.Length(); rgX++) {
     nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
     NS_ASSERTION(rgFrame, "Must have rgFrame here");
     nsIFrame* childFrame = rgFrame->GetFirstChild(nsnull);
     // find the row that was inserted first
     while (childFrame) {
-      if (nsGkAtoms::tableRowFrame == childFrame->GetType()) {
-        nsTableRowFrame* rowFrame = (nsTableRowFrame*)childFrame;
+      nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+      if (rowFrame) {
         if (rowFrame->IsFirstInserted()) {
           rowFrame->SetFirstInserted(PR_FALSE);
           // damage the table from the 1st row inserted to the end of the table
           nscoord damageY = rgFrame->GetPosition().y + rowFrame->GetPosition().y;
           nsRect damageRect(0, damageY, GetSize().width, aNewHeight - damageY);
 
           Invalidate(damageRect);
           // XXXbz didn't we do this up front?  Why do we need to do it again?
@@ -3751,35 +3752,37 @@ nsTableFrame::GetFrameAtOrBefore(nsIFram
 }
 
 #ifdef DEBUG
 void 
 nsTableFrame::DumpRowGroup(nsIFrame* aKidFrame)
 {
   nsTableRowGroupFrame* rgFrame = GetRowGroupFrame(aKidFrame);
   if (rgFrame) {
-    nsIFrame* rowFrame = rgFrame->GetFirstChild(nsnull);
-    while (rowFrame) {
-      if (nsGkAtoms::tableRowFrame == rowFrame->GetType()) {
-        printf("row(%d)=%p ", ((nsTableRowFrame*)rowFrame)->GetRowIndex(), rowFrame);
-        nsIFrame* cellFrame = rowFrame->GetFirstChild(nsnull);
-        while (cellFrame) {
-          if (IS_TABLE_CELL(cellFrame->GetType())) {
+    nsIFrame* cFrame = rgFrame->GetFirstChild(nsnull);
+    while (cFrame) {
+      nsTableRowFrame *rowFrame = do_QueryFrame(cFrame);
+      if (rowFrame) {
+        printf("row(%d)=%p ", rowFrame->GetRowIndex(), rowFrame);
+        nsIFrame* childFrame = cFrame->GetFirstChild(nsnull);
+        while (childFrame) {
+          nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+          if (cellFrame) {
             PRInt32 colIndex;
-            ((nsTableCellFrame*)cellFrame)->GetColIndex(colIndex);
-            printf("cell(%d)=%p ", colIndex, cellFrame);
+            cellFrame->GetColIndex(colIndex);
+            printf("cell(%d)=%p ", colIndex, childFrame);
           }
-          cellFrame = cellFrame->GetNextSibling();
+          childFrame = childFrame->GetNextSibling();
         }
         printf("\n");
       }
       else {
         DumpRowGroup(rowFrame);
       }
-      rowFrame = rowFrame->GetNextSibling();
+      cFrame = cFrame->GetNextSibling();
     }
   }
 }
 
 void 
 nsTableFrame::Dump(PRBool          aDumpRows,
                    PRBool          aDumpCols, 
                    PRBool          aDumpCellMap)
--- a/layout/tables/nsTableRowFrame.cpp
+++ b/layout/tables/nsTableRowFrame.cpp
@@ -138,16 +138,20 @@ nsTableRowFrame::SetPctHeight(float  aPc
     if (height > 0.0f) {
       SetHasPctHeight(PR_TRUE);
     }
   }
 }
 
 /* ----------- nsTableRowFrame ---------- */
 
+NS_QUERYFRAME_HEAD(nsTableRowFrame)
+  NS_QUERYFRAME_ENTRY(nsTableRowFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
+
 nsTableRowFrame::nsTableRowFrame(nsStyleContext* aContext)
   : nsHTMLContainerFrame(aContext)
 {
   mBits.mRowIndex = mBits.mFirstInserted = 0;
   ResetHeight(0);
 }
 
 nsTableRowFrame::~nsTableRowFrame()
@@ -201,19 +205,20 @@ nsTableRowFrame::AppendFrames(nsIAtom*  
 
   // Append the frames
   mFrames.AppendFrames(nsnull, aFrameList);
 
   // Add the new cell frames to the table
   nsTableFrame *tableFrame =  nsTableFrame::GetTableFrame(this);
   for (nsIFrame* childFrame = aFrameList; childFrame;
        childFrame = childFrame->GetNextSibling()) {
-    if (IS_TABLE_CELL(childFrame->GetType())) {
+    nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+    if (cellFrame) {
       // Add the cell to the cell map
-      tableFrame->AppendCell((nsTableCellFrame&)*childFrame, GetRowIndex());
+      tableFrame->AppendCell(*cellFrame, GetRowIndex());
     }
   }
 
   PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange,
                                                NS_FRAME_HAS_DIRTY_CHILDREN);
   tableFrame->SetGeometryDirty();
 
   return NS_OK;
@@ -233,18 +238,19 @@ nsTableRowFrame::InsertFrames(nsIAtom*  
   nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
   
   // gather the new frames (only those which are cells) into an array
   nsIAtom* cellFrameType = (tableFrame->IsBorderCollapse()) ? nsGkAtoms::bcTableCellFrame : nsGkAtoms::tableCellFrame;
   nsTableCellFrame* prevCellFrame = (nsTableCellFrame *)nsTableFrame::GetFrameAtOrBefore(this, aPrevFrame, cellFrameType);
   nsTArray<nsTableCellFrame*> cellChildren;
   for (nsIFrame* childFrame = aFrameList; childFrame;
        childFrame = childFrame->GetNextSibling()) {
-    if (IS_TABLE_CELL(childFrame->GetType())) {
-      cellChildren.AppendElement(static_cast<nsTableCellFrame*>(childFrame));
+    nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+    if (cellFrame) {
+      cellChildren.AppendElement(cellFrame);
     }
   }
   // insert the cells into the cell map
   PRInt32 colIndex = -1;
   if (prevCellFrame) {
     prevCellFrame->GetColIndex(colIndex);
   }
   tableFrame->InsertCells(cellChildren, GetRowIndex(), colIndex);
@@ -262,18 +268,18 @@ nsTableRowFrame::InsertFrames(nsIAtom*  
 NS_IMETHODIMP
 nsTableRowFrame::RemoveFrame(nsIAtom*        aListName,
                              nsIFrame*       aOldFrame)
 {
   NS_ASSERTION(!aListName, "unexpected child list");
 
   nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
   if (tableFrame) {
-    if (IS_TABLE_CELL(aOldFrame->GetType())) {
-      nsTableCellFrame* cellFrame = (nsTableCellFrame*)aOldFrame;
+    nsTableCellFrame *cellFrame = do_QueryFrame(aOldFrame);
+    if (cellFrame) {
       PRInt32 colIndex;
       cellFrame->GetColIndex(colIndex);
       // remove the cell from the cell map
       tableFrame->RemoveCell(cellFrame, GetRowIndex());
 
       // Remove the frame and destroy it
       mFrames.DestroyFrame(aOldFrame);
 
@@ -329,18 +335,19 @@ GetHeightOfRowsSpannedBelowFirst(nsTable
   return height;
 }
 
 nsTableCellFrame*  
 nsTableRowFrame::GetFirstCell() 
 {
   nsIFrame* childFrame = mFrames.FirstChild();
   while (childFrame) {
-    if (IS_TABLE_CELL(childFrame->GetType())) {
-      return (nsTableCellFrame*)childFrame;
+    nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+    if (cellFrame) {
+      return cellFrame;
     }
     childFrame = childFrame->GetNextSibling();
   }
   return nsnull;
 }
 
 /**
  * Post-reflow hook. This is where the table row does its post-processing
@@ -358,18 +365,18 @@ nsTableRowFrame::DidResize()
   
   nsHTMLReflowMetrics desiredSize;
   desiredSize.width = mRect.width;
   desiredSize.height = mRect.height;
   desiredSize.mOverflowArea = nsRect(0, 0, desiredSize.width,
                                      desiredSize.height);
 
   while (childFrame) {
-    if (IS_TABLE_CELL(childFrame->GetType())) {
-      nsTableCellFrame* cellFrame = (nsTableCellFrame*)childFrame;
+    nsTableCellFrame *cellFrame = do_QueryFrame(childFrame);
+    if (cellFrame) {
       nscoord cellHeight = mRect.height + GetHeightOfRowsSpannedBelowFirst(*cellFrame, *tableFrame);
 
       // resize the cell's height
       nsRect cellRect = cellFrame->GetRect();
       nsRect cellOverflowRect = cellFrame->GetOverflowRect();
       if (cellRect.height != cellHeight)
       {
         cellFrame->SetSize(nsSize(cellRect.width, cellHeight));
@@ -530,30 +537,31 @@ nsTableRowFrame::CalcHeight(const nsHTML
     SetFixedHeight(position->mHeight.GetCoordValue());
   }
   else if (eStyleUnit_Percent == position->mHeight.GetUnit()) {
     SetPctHeight(position->mHeight.GetPercentValue());
   }
 
   for (nsIFrame* kidFrame = mFrames.FirstChild(); kidFrame;
        kidFrame = kidFrame->GetNextSibling()) {
-    if (IS_TABLE_CELL(kidFrame->GetType())) {
-      nscoord availWidth = ((nsTableCellFrame *)kidFrame)->GetPriorAvailWidth();
-      nsSize desSize = ((nsTableCellFrame *)kidFrame)->GetDesiredSize();
+    nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
+    if (cellFrame) {
+      nscoord availWidth = cellFrame->GetPriorAvailWidth();
+      nsSize desSize = cellFrame->GetDesiredSize();
       if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) && !GetPrevInFlow()) {
         CalculateCellActualSize(kidFrame, desSize.width, desSize.height, availWidth);
       }
       // height may have changed, adjust descent to absorb any excess difference
       nscoord ascent;
        if (!kidFrame->GetFirstChild(nsnull)->GetFirstChild(nsnull))
          ascent = desSize.height;
        else
-         ascent = ((nsTableCellFrame *)kidFrame)->GetCellBaseline();
+         ascent = cellFrame->GetCellBaseline();
       nscoord descent = desSize.height - ascent;
-      UpdateHeight(desSize.height, ascent, descent, tableFrame, (nsTableCellFrame*)kidFrame);
+      UpdateHeight(desSize.height, ascent, descent, tableFrame, cellFrame);
     }
   }
   return GetHeight();
 }
 
 /**
  * We need a custom display item for table row backgrounds. This is only used
  * when the table row is the root of a stacking context (e.g., has 'opacity').
@@ -803,35 +811,33 @@ nsTableRowFrame::ReflowChildren(nsPresCo
   PRInt32 prevColIndex  = firstPrevColIndex;
   nscoord x = 0; // running total of children x offset
 
   // This computes the max of all cell heights
   nscoord cellMaxHeight = 0;
 
   // Reflow each of our existing cell frames
   for (nsIFrame* kidFrame = iter.First(); kidFrame; kidFrame = iter.Next()) {
-    nsIAtom* frameType = kidFrame->GetType();
-    if (!IS_TABLE_CELL(frameType)) {
+    nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
+    if (!cellFrame) {
       // XXXldb nsCSSFrameConstructor needs to enforce this!
       NS_NOTREACHED("yikes, a non-row child");
 
       // it's an unknown frame type, give it a generic reflow and ignore the results
       nsTableCellReflowState kidReflowState(aPresContext, aReflowState,
                                             kidFrame, nsSize(0,0), PR_FALSE);
       InitChildReflowState(*aPresContext, nsSize(0,0), PR_FALSE, kidReflowState);
       nsHTMLReflowMetrics desiredSize;
       nsReflowStatus  status;
       ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowState, 0, 0, 0, status);
       kidFrame->DidReflow(aPresContext, nsnull, NS_FRAME_REFLOW_FINISHED);
 
       continue;
     }
 
-    nsTableCellFrame* cellFrame = static_cast<nsTableCellFrame*>(kidFrame);
-
     // See if we should only reflow the dirty child frames
     PRBool doReflowChild = PR_TRUE;
     if (!aReflowState.ShouldReflowAllKids() &&
         !aTableFrame.IsGeometryDirty() &&
         !NS_SUBTREE_DIRTY(kidFrame)) {
       if (!aReflowState.mFlags.mSpecialHeightReflow)
         doReflowChild = PR_FALSE;
     }
@@ -1188,19 +1194,18 @@ nsTableRowFrame::CollapseRowIfNecessary(
     nscoord x = 0; // running total of children x offset
 
     PRInt32 colIncrement = iter.IsLeftToRight() ? 1 : -1;
 
     //nscoord x = cellSpacingX;
 
     nsIFrame* kidFrame = iter.First();
     while (kidFrame) {
-      nsIAtom* frameType = kidFrame->GetType();
-      if (IS_TABLE_CELL(frameType)) {
-        nsTableCellFrame* cellFrame = (nsTableCellFrame*)kidFrame;
+      nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
+      if (cellFrame) {
         PRInt32 cellColIndex;
         cellFrame->GetColIndex(cellColIndex);
         PRInt32 cellColSpan = tableFrame->GetEffectiveColSpan(*cellFrame);
 
         // If the adjacent cell is in a prior row (because of a rowspan) add in
         // the space
         if ((iter.IsLeftToRight() && (prevColIndex != (cellColIndex - 1))) ||
             (!iter.IsLeftToRight() &&
@@ -1319,18 +1324,18 @@ nsTableRowFrame::InsertCellFrame(nsTable
 void 
 nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame,
                                  PRInt32           aColIndex)
 {
   // Find the cell frame where col index < aColIndex
   nsTableCellFrame* priorCell = nsnull;
   for (nsIFrame* child = mFrames.FirstChild(); child;
        child = child->GetNextSibling()) {
-    if (!IS_TABLE_CELL(child->GetType())) {
-      nsTableCellFrame* cellFrame = (nsTableCellFrame*)child;
+    nsTableCellFrame *cellFrame = do_QueryFrame(child);
+    if (cellFrame) {
       PRInt32 colIndex;
       cellFrame->GetColIndex(colIndex);
       if (colIndex < aColIndex) {
         priorCell = cellFrame;
       }
       else break;
     }
   }
@@ -1350,19 +1355,20 @@ nsTableRowFrame::GetType() const
   return nsGkAtoms::tableRowFrame;
 }
 
 nsTableRowFrame*  
 nsTableRowFrame::GetNextRow() const
 {
   nsIFrame* childFrame = GetNextSibling();
   while (childFrame) {
-    if (nsGkAtoms::tableRowFrame == childFrame->GetType()) {
+    nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+    if (rowFrame) {
 	  NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW == childFrame->GetStyleDisplay()->mDisplay, "wrong display type on rowframe");
-      return (nsTableRowFrame*)childFrame;
+      return rowFrame;
     }
     childFrame = childFrame->GetNextSibling();
   }
   return nsnull;
 }
 
 void 
 nsTableRowFrame::SetUnpaginatedHeight(nsPresContext* aPresContext,
@@ -1410,22 +1416,21 @@ void nsTableRowFrame::SetContinuousBCBor
  * this row has any cells that have non-auto-height.  (Row-spanning
  * cells are ignored.)
  */
 void nsTableRowFrame::InitHasCellWithStyleHeight(nsTableFrame* aTableFrame)
 {
   nsTableIterator iter(*this);
 
   for (nsIFrame* kidFrame = iter.First(); kidFrame; kidFrame = iter.Next()) {
-    nsIAtom* frameType = kidFrame->GetType();
-    if (!IS_TABLE_CELL(frameType)) {
+    nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
+    if (!cellFrame) {
       NS_NOTREACHED("Table row has a non-cell child.");
       continue;
     }
-    nsTableCellFrame* cellFrame = static_cast<nsTableCellFrame*>(kidFrame);
     // Ignore row-spanning cells
     if (aTableFrame->GetEffectiveRowSpan(*cellFrame) == 1 &&
         cellFrame->GetStylePosition()->mHeight.GetUnit() != eStyleUnit_Auto) {
       AddStateBits(NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT);
       return;
     }
   }
   RemoveStateBits(NS_ROW_HAS_CELL_WITH_STYLE_HEIGHT);
--- a/layout/tables/nsTableRowFrame.h
+++ b/layout/tables/nsTableRowFrame.h
@@ -62,16 +62,20 @@ struct nsTableCellReflowState;
  * 
  * @see nsTableFrame
  * @see nsTableRowGroupFrame
  * @see nsTableCellFrame
  */
 class nsTableRowFrame : public nsHTMLContainerFrame
 {
 public:
+
+  NS_DECLARE_FRAME_ACCESSOR(nsTableRowFrame)
+  NS_DECL_QUERYFRAME
+
   virtual ~nsTableRowFrame();
 
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   /** @see nsIFrame::DidSetStyleContext */
   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
   
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -320,18 +320,18 @@ nsTableRowGroupFrame::InitChildReflowSta
                                            PRBool             aBorderCollapse,
                                            nsHTMLReflowState& aReflowState)                                    
 {
   nsMargin collapseBorder;
   nsMargin padding(0,0,0,0);
   nsMargin* pCollapseBorder = nsnull;
   if (aBorderCollapse) {
     if (aReflowState.frame) {
-      if (nsGkAtoms::tableRowFrame == aReflowState.frame->GetType()) {
-        nsTableRowFrame* rowFrame = (nsTableRowFrame*)aReflowState.frame;
+      nsTableRowFrame *rowFrame = do_QueryFrame(aReflowState.frame);
+      if (rowFrame) {
         pCollapseBorder = rowFrame->GetBCBorderWidth(collapseBorder);
       }
     }
   }
   aReflowState.Init(&aPresContext, -1, -1, pCollapseBorder, &padding);
 }
 
 static void
@@ -373,17 +373,18 @@ nsTableRowGroupFrame::ReflowChildren(nsP
   PRBool haveRow = PR_FALSE;
   PRBool reflowAllKids = aReflowState.reflowState.ShouldReflowAllKids() ||
                          tableFrame->IsGeometryDirty();
   PRBool needToCalcRowHeights = reflowAllKids;
 
   nsIFrame *prevKidFrame = nsnull;
   for (nsIFrame* kidFrame = GetFirstFrame(); kidFrame;
        prevKidFrame = kidFrame, kidFrame = kidFrame->GetNextSibling()) {
-    if (kidFrame->GetType() != nsGkAtoms::tableRowFrame) {
+    nsTableRowFrame *rowFrame = do_QueryFrame(kidFrame);
+    if (!rowFrame) {
       // XXXldb nsCSSFrameConstructor needs to enforce this!
       NS_NOTREACHED("yikes, a non-row child");
       continue;
     }
 
     haveRow = PR_TRUE;
 
     // Reflow the row frame
@@ -428,17 +429,17 @@ nsTableRowGroupFrame::ReflowChildren(nsP
       // Place the child
       PlaceChild(aPresContext, aReflowState, kidFrame, desiredSize,
                  oldKidRect, oldKidOverflowRect);
       aReflowState.y += cellSpacingY;
 
       if (!reflowAllKids) {
         if (IsSimpleRowFrame(aReflowState.tableFrame, kidFrame)) {
           // Inform the row of its new height.
-          ((nsTableRowFrame*)kidFrame)->DidResize();
+          rowFrame->DidResize();
           // the overflow area may have changed inflate the overflow area
           const nsStylePosition *stylePos = GetStylePosition();
           nsStyleUnit unit = stylePos->mHeight.GetUnit();
           if (aReflowState.tableFrame->IsAutoHeight() &&
               unit != eStyleUnit_Coord) {
             // Because other cells in the row may need to be aligned
             // differently, repaint the entire row
             nsRect kidRect(0, aReflowState.y,
@@ -456,17 +457,17 @@ nsTableRowGroupFrame::ReflowChildren(nsP
           else if (oldKidRect.height != desiredSize.height)
             needToCalcRowHeights = PR_TRUE;
         } else {
           needToCalcRowHeights = PR_TRUE;
         }
       }
 
       if (isPaginated && aPageBreakBeforeEnd && !*aPageBreakBeforeEnd) {
-        nsTableRowFrame* nextRow = ((nsTableRowFrame*)kidFrame)->GetNextRow();
+        nsTableRowFrame* nextRow = rowFrame->GetNextRow();
         if (nextRow) {
           *aPageBreakBeforeEnd = nsTableFrame::PageBreakAfter(*kidFrame, nextRow);
         }
       }
     } else {
       SlideChild(aReflowState, kidFrame);
 
       // Adjust the running y-offset so we know where the next row should be placed
@@ -507,18 +508,19 @@ nsTableRowGroupFrame::ReflowChildren(nsP
   return rv;
 }
 
 nsTableRowFrame*  
 nsTableRowGroupFrame::GetFirstRow() 
 {
   for (nsIFrame* childFrame = GetFirstFrame(); childFrame;
        childFrame = childFrame->GetNextSibling()) {
-    if (nsGkAtoms::tableRowFrame == childFrame->GetType()) {
-      return (nsTableRowFrame*)childFrame;
+    nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+    if (rowFrame) {
+      return rowFrame;
     }
   }
   return nsnull;
 }
 
 
 struct RowInfo {
   RowInfo() { height = pctHeight = hasStyleHeight = hasPctHeight = isSpecial = 0; }
@@ -1388,23 +1390,24 @@ nsTableRowGroupFrame::AppendFrames(nsIAt
                                    nsIFrame*       aFrameList)
 {
   NS_ASSERTION(!aListName, "unexpected child list");
 
   ClearRowCursor();
 
   // collect the new row frames in an array
   nsAutoTArray<nsTableRowFrame*, 8> rows;
-  for (nsIFrame* rowFrame = aFrameList; rowFrame;
-       rowFrame = rowFrame->GetNextSibling()) {
-    if (nsGkAtoms::tableRowFrame == rowFrame->GetType()) {
+  for (nsIFrame* childFrame = aFrameList; childFrame;
+       childFrame = childFrame->GetNextSibling()) {
+    nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+    if (rowFrame) {
       NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW ==
-                     rowFrame->GetStyleDisplay()->mDisplay,
+                     childFrame->GetStyleDisplay()->mDisplay,
                    "wrong display type on rowframe");      
-      rows.AppendElement(static_cast<nsTableRowFrame*>(rowFrame));
+      rows.AppendElement(rowFrame);
     }
   }
 
   PRInt32 rowIndex = GetRowCount();
   // Append the frames to the sibling chain
   mFrames.AppendFrames(nsnull, aFrameList);
 
   if (rows.Length() > 0) {
@@ -1434,25 +1437,26 @@ nsTableRowGroupFrame::InsertFrames(nsIAt
 
   nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
   if (!tableFrame)
     return NS_ERROR_NULL_POINTER;
 
   // collect the new row frames in an array
   nsTArray<nsTableRowFrame*> rows;
   PRBool gotFirstRow = PR_FALSE;
-  for (nsIFrame* rowFrame = aFrameList; rowFrame;
-       rowFrame = rowFrame->GetNextSibling()) {
-    if (nsGkAtoms::tableRowFrame == rowFrame->GetType()) {
+  for (nsIFrame* childFrame = aFrameList; childFrame;
+       childFrame = childFrame->GetNextSibling()) {
+    nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
+    if (rowFrame) {
       NS_ASSERTION(NS_STYLE_DISPLAY_TABLE_ROW ==
-                     rowFrame->GetStyleDisplay()->mDisplay,
+                     childFrame->GetStyleDisplay()->mDisplay,
                    "wrong display type on rowframe");      
-      rows.AppendElement(static_cast<nsTableRowFrame*>(rowFrame));
+      rows.AppendElement(rowFrame);
       if (!gotFirstRow) {
-        ((nsTableRowFrame*)rowFrame)->SetFirstInserted(PR_TRUE);
+        rowFrame->SetFirstInserted(PR_TRUE);
         gotFirstRow = PR_TRUE;
         tableFrame->SetRowInserted(PR_TRUE);
       }
     }
   }
 
   PRInt32 startRowIndex = GetStartRowIndex();
   // Insert the frames in the sibling chain
@@ -1477,19 +1481,20 @@ nsTableRowGroupFrame::RemoveFrame(nsIAto
                                   nsIFrame*       aOldFrame)
 {
   NS_ASSERTION(!aListName, "unexpected child list");
 
   ClearRowCursor();
 
   nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
   if (tableFrame) {
-    if (nsGkAtoms::tableRowFrame == aOldFrame->GetType()) {
+    nsTableRowFrame *rowFrame = do_QueryFrame(aOldFrame);
+    if (rowFrame) {
       // remove the rows from the table (and flag a rebalance)
-      tableFrame->RemoveRows((nsTableRowFrame &)*aOldFrame, 1, PR_TRUE);
+      tableFrame->RemoveRows(*rowFrame, 1, PR_TRUE);
 
       PresContext()->PresShell()->
         FrameNeedsReflow(this, nsIPresShell::eTreeChange,
                          NS_FRAME_HAS_DIRTY_CHILDREN);
       tableFrame->SetGeometryDirty();
     }
   }
   mFrames.DestroyFrame(aOldFrame);
@@ -1541,18 +1546,19 @@ nsTableRowGroupFrame::GetHeightBasis(con
   return result;
 }
 
 PRBool
 nsTableRowGroupFrame::IsSimpleRowFrame(nsTableFrame* aTableFrame,
                                        nsIFrame*     aFrame)
 {
   // Make sure it's a row frame and not a row group frame
-  if (aFrame->GetType() == nsGkAtoms::tableRowFrame) {
-    PRInt32 rowIndex = ((nsTableRowFrame*)aFrame)->GetRowIndex();
+  nsTableRowFrame *rowFrame = do_QueryFrame(aFrame);
+  if (rowFrame) {
+    PRInt32 rowIndex = rowFrame->GetRowIndex();
     
     // It's a simple row frame if there are no cells that span into or
     // across the row
     PRInt32 numEffCols = aTableFrame->GetEffectiveColCount();
     if (!aTableFrame->RowIsSpannedInto(rowIndex, numEffCols) &&
         !aTableFrame->RowHasSpanningCells(rowIndex, numEffCols)) {
       return PR_TRUE;
     }
@@ -1680,20 +1686,19 @@ nsTableRowGroupFrame::GetLine(PRInt32   
   return NS_ERROR_FAILURE;
 }
   
 PRInt32
 nsTableRowGroupFrame::FindLineContaining(nsIFrame* aFrame)
 {
   NS_ENSURE_ARG_POINTER(aFrame);
   
-  NS_ASSERTION((aFrame->GetType() == nsGkAtoms::tableRowFrame),
-               "RowGroup contains a frame that is not a row");
+  nsTableRowFrame *rowFrame = do_QueryFrame(aFrame);
+  NS_ASSERTION(rowFrame, "RowGroup contains a frame that is not a row");
 
-  nsTableRowFrame* rowFrame = (nsTableRowFrame*)aFrame;
   return rowFrame->GetRowIndex() - GetStartRowIndex();
 }
 
 PRInt32
 nsTableRowGroupFrame::FindLineAt(nscoord  aY)
 {
   NS_NOTREACHED("Not implemented");
   return NS_ERROR_NOT_IMPLEMENTED;