Bug 409331. Instead of QIing to nsBlockFrame in various places, call an nsLayoutUtils method to do it. r+sr=roc
authorKaruna (karunasagark@gmail.com)
Mon, 14 Jul 2008 10:10:23 +1200
changeset 15909 140ebc8ba14616ab4d32d69c211d2bd7bcf8629a
parent 15908 befb0a142cd5c0339a45066a8f2eec5be68fe48f
child 15910 78fef1c4adbfa208879468b6fa9127994677b3bf
push id596
push userrocallahan@mozilla.com
push dateSun, 13 Jul 2008 22:10:34 +0000
treeherdermozilla-central@140ebc8ba146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs409331
milestone1.9.1a1pre
Bug 409331. Instead of QIing to nsBlockFrame in various places, call an nsLayoutUtils method to do it. r+sr=roc
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCaret.cpp
layout/base/nsLayoutUtils.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsBlockReflowContext.cpp
layout/generic/nsBlockReflowState.cpp
layout/generic/nsFrame.cpp
layout/generic/nsHTMLReflowState.cpp
layout/generic/nsInlineFrame.cpp
layout/generic/nsTextFrameThebes.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -11142,24 +11142,18 @@ nsCSSFrameConstructor::ShouldHaveFirstLe
                                        nsCSSPseudoElements::firstLetter,
                                        mPresShell->GetPresContext());
 }
 
 PRBool
 nsCSSFrameConstructor::HasFirstLetterStyle(nsIFrame* aBlockFrame)
 {
   NS_PRECONDITION(aBlockFrame, "Need a frame");
-  
-#ifdef DEBUG
-  nsBlockFrame* block;
-  NS_ASSERTION(NS_SUCCEEDED(aBlockFrame->QueryInterface(kBlockFrameCID,
-                                                        (void**)&block)) &&
-               block,
+  NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame),
                "Not a block frame?");
-#endif
 
   return (aBlockFrame->GetStateBits() & NS_BLOCK_HAS_FIRST_LETTER_STYLE) != 0;
 }
 
 PRBool
 nsCSSFrameConstructor::ShouldHaveFirstLineStyle(nsIContent* aContent,
                                                 nsStyleContext* aStyleContext)
 {
@@ -11740,26 +11734,18 @@ nsresult
 nsCSSFrameConstructor::CreateLetterFrame(nsFrameConstructorState& aState,
                                          nsIFrame* aBlockFrame,
                                          nsIContent* aTextContent,
                                          nsIFrame* aParentFrame,
                                          nsFrameItems& aResult)
 {
   NS_PRECONDITION(aTextContent->IsNodeOfType(nsINode::eTEXT),
                   "aTextContent isn't text");
-
-#ifdef DEBUG
-  {
-    nsBlockFrame* block;
-    NS_ASSERTION(NS_SUCCEEDED(aBlockFrame->QueryInterface(kBlockFrameCID,
-                                                          (void**)&block)) &&
-                 block,
+  NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlockFrame),
                  "Not a block frame?");
-  }
-#endif
 
   // Get style context for the first-letter-frame
   nsStyleContext* parentStyleContext =
     nsFrame::CorrectStyleParentFrame(aParentFrame,
                                      nsCSSPseudoElements::firstLetter)->
       GetStyleContext();
   // Use content from containing block so that we can actually
   // find a matching style rule.
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -698,18 +698,18 @@ CheckForTrailingTextFrameRecursive(nsIFr
 }
 
 static nsLineBox*
 FindContainingLine(nsIFrame* aFrame)
 {
   while (aFrame && aFrame->IsFrameOfType(nsIFrame::eLineParticipant))
   {
     nsIFrame* parent = aFrame->GetParent();
-    nsBlockFrame* blockParent;
-    if (NS_SUCCEEDED(parent->QueryInterface(kBlockFrameCID, (void**)&blockParent)))
+    nsBlockFrame* blockParent = nsLayoutUtils::GetAsBlock(parent);
+    if (blockParent)
     {
       PRBool isValid;
       nsBlockInFlowLineIterator iter(blockParent, aFrame, &isValid);
       return isValid ? iter.GetLine().get() : nsnull;
     }
     aFrame = parent;
   }
   return nsnull;
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2325,19 +2325,18 @@ nsLayoutUtils::GetStringWidth(const nsIF
   nscoord width;
   aContext->GetWidth(aString, aLength, width);
   return width;
 }
 
 /* static */ PRBool
 nsLayoutUtils::GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
 {
-  const nsBlockFrame* block;
-  if (NS_FAILED(const_cast<nsIFrame*>(aFrame)->
-                  QueryInterface(kBlockFrameCID, (void**)&block))) {
+  const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
+  if (!block) {
     // For the first-line baseline we also have to check for a table, and if
     // so, use the baseline of its first row.
     nsIAtom* fType = aFrame->GetType();
     if (fType == nsGkAtoms::tableOuterFrame) {
       *aResult = aFrame->GetBaseline();
       return PR_TRUE;
     }
 
@@ -2383,19 +2382,18 @@ nsLayoutUtils::GetFirstLineBaseline(cons
     }
   }
   return PR_FALSE;
 }
 
 /* static */ PRBool
 nsLayoutUtils::GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
 {
-  const nsBlockFrame* block;
-  if (NS_FAILED(const_cast<nsIFrame*>(aFrame)->
-                  QueryInterface(kBlockFrameCID, (void**)&block)))
+  const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
+  if (!block)
     // No baseline.  (We intentionally don't descend into scroll frames.)
     return PR_FALSE;
 
   for (nsBlockFrame::const_reverse_line_iterator line = block->rbegin_lines(),
                                              line_end = block->rend_lines();
        line != line_end; ++line) {
     if (line->IsBlock()) {
       nsIFrame *kid = line->mFirstChild;
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -977,18 +977,17 @@ nsBlockFrame::Reflow(nsPresContext*     
     NS_ASSERTION(aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE,
                  "Somehow we failed to fit all content, even though we have unlimited space!");
     if (NS_FRAME_IS_FULLY_COMPLETE(state.mReflowStatus)) {
       // find the nearest block ancestor that uses the same space manager
       for (const nsHTMLReflowState* ancestorRS = aReflowState.parentReflowState; 
            ancestorRS; 
            ancestorRS = ancestorRS->parentReflowState) {
         nsIFrame* ancestor = ancestorRS->frame;
-        nsIAtom* fType = ancestor->GetType();
-        if ((nsGkAtoms::blockFrame == fType || nsGkAtoms::areaFrame == fType) &&
+        if (nsLayoutUtils::GetAsBlock(ancestor) &&
             aReflowState.mSpaceManager == ancestorRS->mSpaceManager) {
           // Put the continued floats in ancestor since it uses the same space manager
           nsFrameList* ancestorPlace =
             ((nsBlockFrame*)ancestor)->GetOverflowPlaceholders();
           // The ancestor should have this list, since it's being reflowed. But maybe
           // it isn't because of reflow roots or something.
           if (ancestorPlace) {
             for (nsIFrame* f = state.mOverflowPlaceholders.FirstChild();
@@ -4954,54 +4953,52 @@ nsBlockFrame::RemoveFloat(nsIFrame* aFlo
 
 static void MarkAllDescendantLinesDirty(nsBlockFrame* aBlock)
 {
   nsLineList::iterator line = aBlock->begin_lines();
   nsLineList::iterator endLine = aBlock->end_lines();
   while (line != endLine) {
     if (line->IsBlock()) {
       nsIFrame* f = line->mFirstChild;
-      void* bf;
-      if (NS_SUCCEEDED(f->QueryInterface(kBlockFrameCID, &bf))) {
-        MarkAllDescendantLinesDirty(static_cast<nsBlockFrame*>(f));
+      nsBlockFrame* bf = nsLayoutUtils::GetAsBlock(f);
+      if (bf) {
+        MarkAllDescendantLinesDirty(bf);
       }
     }
     line->MarkDirty();
     ++line;
   }
 }
 
 static void MarkSameSpaceManagerLinesDirty(nsBlockFrame* aBlock)
 {
   nsBlockFrame* blockWithSpaceMgr = aBlock;
   while (!(blockWithSpaceMgr->GetStateBits() & NS_BLOCK_SPACE_MGR)) {
-    void* bf;
-    if (NS_FAILED(blockWithSpaceMgr->GetParent()->
-                  QueryInterface(kBlockFrameCID, &bf))) {
+    nsBlockFrame* bf = nsLayoutUtils::GetAsBlock(blockWithSpaceMgr->GetParent());
+    if (!bf) {
       break;
     }
-    blockWithSpaceMgr = static_cast<nsBlockFrame*>(blockWithSpaceMgr->GetParent());
+    blockWithSpaceMgr = bf;
   }
     
   // Mark every line at and below the line where the float was
   // dirty, and mark their lines dirty too. We could probably do
   // something more efficient --- e.g., just dirty the lines that intersect
   // the float vertically.
   MarkAllDescendantLinesDirty(blockWithSpaceMgr);
 }
 
 /**
  * Returns PR_TRUE if aFrame is a block that has one or more float children.
  */
 static PRBool BlockHasAnyFloats(nsIFrame* aFrame)
 {
-  void* bf;
-  if (NS_FAILED(aFrame->QueryInterface(kBlockFrameCID, &bf)))
+  nsBlockFrame* block = nsLayoutUtils::GetAsBlock(aFrame);
+  if (!block)
     return PR_FALSE;
-  nsBlockFrame* block = static_cast<nsBlockFrame*>(aFrame);
   if (block->GetFirstChild(nsGkAtoms::floatList))
     return PR_TRUE;
     
   nsLineList::iterator line = block->begin_lines();
   nsLineList::iterator endLine = block->end_lines();
   while (line != endLine) {
     if (line->IsBlock() && BlockHasAnyFloats(line->mFirstChild))
       return PR_TRUE;
@@ -5257,19 +5254,18 @@ nsBlockInFlowLineIterator::FindValidLine
 }
 
 static nsresult RemoveBlockChild(nsIFrame* aFrame, PRBool aDestroyFrames,
                                  PRBool aRemoveOnlyFluidContinuations)
 {
   if (!aFrame)
     return NS_OK;
 
-  nsBlockFrame* nextBlock = static_cast<nsBlockFrame*>(aFrame->GetParent());
-  NS_ASSERTION(nextBlock->GetType() == nsGkAtoms::blockFrame ||
-               nextBlock->GetType() == nsGkAtoms::areaFrame,
+  nsBlockFrame* nextBlock = nsLayoutUtils::GetAsBlock(aFrame->GetParent());
+  NS_ASSERTION(nextBlock,
                "Our child's continuation's parent is not a block?");
   return nextBlock->DoRemoveFrame(aFrame, aDestroyFrames,
                                   aRemoveOnlyFluidContinuations);
 }
 
 // This function removes aDeletedFrame and all its continuations.  It
 // is optimized for deleting a whole series of frames. The easy
 // implementation would invoke itself recursively on
@@ -6556,19 +6552,18 @@ nsBlockFrame::RenumberListsFor(nsPresCon
 
   // If the frame is a list-item and the frame implements our
   // block frame API then get its bullet and set the list item
   // ordinal.
   const nsStyleDisplay* display = kid->GetStyleDisplay();
   if (NS_STYLE_DISPLAY_LIST_ITEM == display->mDisplay) {
     // Make certain that the frame is a block frame in case
     // something foreign has crept in.
-    nsBlockFrame* listItem;
-    nsresult rv = kid->QueryInterface(kBlockFrameCID, (void**)&listItem);
-    if (NS_SUCCEEDED(rv)) {
+    nsBlockFrame* listItem = nsLayoutUtils::GetAsBlock(kid);
+    if (listItem) {
       if (nsnull != listItem->mBullet) {
         PRBool changed;
         *aOrdinal = listItem->mBullet->SetListItemOrdinal(*aOrdinal,
                                                           &changed);
         if (changed) {
           kidRenumberedABullet = PR_TRUE;
 
           // Invalidate the bullet content area since it may look different now
@@ -6590,19 +6585,18 @@ nsBlockFrame::RenumberListsFor(nsPresCon
     if (FrameStartsCounterScope(kid)) {
       // Don't bother recursing into a block frame that is a new
       // counter scope. Any list-items in there will be handled by
       // it.
     }
     else {
       // If the display=block element is a block frame then go ahead
       // and recurse into it, as it might have child list-items.
-      nsBlockFrame* kidBlock;
-      nsresult rv = kid->QueryInterface(kBlockFrameCID, (void**) &kidBlock);
-      if (NS_SUCCEEDED(rv)) {
+      nsBlockFrame* kidBlock = nsLayoutUtils::GetAsBlock(kid);
+      if (kidBlock) {
         kidRenumberedABullet = RenumberListsInBlock(aPresContext, kidBlock, aOrdinal, aDepth + 1);
       }
     }
   }
   return kidRenumberedABullet;
 }
 
 void
@@ -6760,38 +6754,30 @@ nsBlockFrame::CheckFloats(nsBlockReflowS
   }
 }
 
 /* static */
 PRBool
 nsBlockFrame::BlockIsMarginRoot(nsIFrame* aBlock)
 {
   NS_PRECONDITION(aBlock, "Must have a frame");
-#ifdef DEBUG
-  nsBlockFrame* blockFrame;
-  aBlock->QueryInterface(kBlockFrameCID, (void**)&blockFrame);
-  NS_ASSERTION(blockFrame, "aBlock must be a block");
-#endif
+  NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlock), "aBlock must be a block");
 
   nsIFrame* parent = aBlock->GetParent();
   return (aBlock->GetStateBits() & NS_BLOCK_MARGIN_ROOT) ||
     (parent && !parent->IsFloatContainingBlock() &&
      parent->GetType() != nsGkAtoms::columnSetFrame);
 }
 
 /* static */
 PRBool
 nsBlockFrame::BlockNeedsSpaceManager(nsIFrame* aBlock)
 {
   NS_PRECONDITION(aBlock, "Must have a frame");
-#ifdef DEBUG
-  nsBlockFrame* blockFrame;
-  aBlock->QueryInterface(kBlockFrameCID, (void**)&blockFrame);
-  NS_ASSERTION(blockFrame, "aBlock must be a block");
-#endif
+  NS_ASSERTION(nsLayoutUtils::GetAsBlock(aBlock), "aBlock must be a block");
 
   nsIFrame* parent = aBlock->GetParent();
   return (aBlock->GetStateBits() & NS_BLOCK_SPACE_MGR) ||
     (parent && !parent->IsFloatContainingBlock());
 }
 
 /* static */
 PRBool
@@ -6909,17 +6895,17 @@ nsBlockFrame::WidthToClearPastFloats(nsB
 }
  
 /* static */
 nsBlockFrame*
 nsBlockFrame::GetNearestAncestorBlock(nsIFrame* aCandidate)
 {
   nsBlockFrame* block = nsnull;
   while(aCandidate) {
-    aCandidate->QueryInterface(kBlockFrameCID, (void**)&block);
+    block = nsLayoutUtils::GetAsBlock(aCandidate);
     if (block) { 
       // yay, candidate is a block!
       return block;
     }
     // Not a block. Check its parent next.
     aCandidate = aCandidate->GetParent();
   }
   NS_NOTREACHED("Fell off frame tree looking for ancestor block!");
--- a/layout/generic/nsBlockReflowContext.cpp
+++ b/layout/generic/nsBlockReflowContext.cpp
@@ -102,21 +102,20 @@ nsBlockReflowContext::ComputeCollapsedTo
   PRBool dirtiedLine = PR_FALSE;
   PRBool setBlockIsEmpty = PR_FALSE;
 
   // Calculate the frame's generational top-margin from its child
   // blocks. Note that if the frame has a non-zero top-border or
   // top-padding then this step is skipped because it will be a margin
   // root.  It is also skipped if the frame is a margin root for other
   // reasons.
-  void* bf;
   nsIFrame* frame = DescendIntoBlockLevelFrame(aRS.frame);
   nsPresContext* prescontext = frame->PresContext();
   if (0 == aRS.mComputedBorderPadding.top &&
-      NS_SUCCEEDED(frame->QueryInterface(kBlockFrameCID, &bf)) &&
+      nsLayoutUtils::GetAsBlock(frame) &&
       !nsBlockFrame::BlockIsMarginRoot(frame)) {
     // iterate not just through the lines of 'block' but also its
     // overflow lines and the normal and overflow lines of its next in
     // flows. Note that this will traverse some frames more than once:
     // for example, if A contains B and A->nextinflow contains
     // B->nextinflow, we'll traverse B->nextinflow twice. But this is
     // OK because our traversal is idempotent.
     for (nsBlockFrame* block = static_cast<nsBlockFrame*>(frame);
--- a/layout/generic/nsBlockReflowState.cpp
+++ b/layout/generic/nsBlockReflowState.cpp
@@ -439,18 +439,17 @@ nsBlockReflowState::RecoverFloats(nsLine
                aDeltaY, fc->mRegion.x, fc->mRegion.y,
                fc->mRegion.width, fc->mRegion.height);
       }
 #endif
       mSpaceManager->AddRectRegion(floatFrame, fc->mRegion);
       fc = fc->Next();
     }
   } else if (aLine->IsBlock()) {
-    nsBlockFrame *kid = nsnull;
-    aLine->mFirstChild->QueryInterface(kBlockFrameCID, (void**)&kid);
+    nsBlockFrame *kid = nsLayoutUtils::GetAsBlock(aLine->mFirstChild);
     // don't recover any state inside a block that has its own space
     // manager (we don't currently have any blocks like this, though,
     // thanks to our use of extra frames for 'overflow')
     if (kid && !nsBlockFrame::BlockNeedsSpaceManager(kid)) {
       nscoord tx = kid->mRect.x, ty = kid->mRect.y;
 
       // If the element is relatively positioned, then adjust x and y
       // accordingly so that we consider relatively positioned frames
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2524,20 +2524,18 @@ static FrameTarget GetSelectionClosestFr
 // This method is for the special handling we do for block frames; they're
 // special because they represent paragraphs and because they are organized
 // into lines, which have bounds that are not stored elsewhere in the
 // frame tree.  Returns a null FrameTarget for frames which are not
 // blocks or blocks with no lines.
 static FrameTarget GetSelectionClosestFrameForBlock(nsIFrame* aFrame,
                                                     nsPoint aPoint)
 {
-  nsresult rv;
-  nsBlockFrame* bf; // used only for QI
-  rv = aFrame->QueryInterface(kBlockFrameCID, (void**)&bf);
-  if (NS_FAILED(rv))
+  nsBlockFrame* bf = nsLayoutUtils::GetAsBlock(aFrame); // used only for QI
+  if (!bf)
     return FrameTarget::Null();
 
   // This code searches for the correct line
   nsBlockFrame::line_iterator firstLine = bf->begin_lines();
   nsBlockFrame::line_iterator end = bf->end_lines();
   if (firstLine == end)
     return FrameTarget::Null();
   nsBlockFrame::line_iterator curLine = firstLine;
@@ -4618,22 +4616,20 @@ FindBlockFrameOrBR(nsIFrame* aFrame, nsD
   // Treat form controls as inline leaves
   // XXX we really need a way to determine whether a frame is inline-level
   nsIFormControlFrame* fcf; // used only for QI
   nsresult rv = aFrame->QueryInterface(NS_GET_IID(nsIFormControlFrame), (void**)&fcf);
   if (NS_SUCCEEDED(rv))
     return result;
   
   // Check the frame itself
-  nsBlockFrame* bf; // used only for QI
-  rv = aFrame->QueryInterface(kBlockFrameCID, (void**)&bf);
   // Fall through "special" block frames because their mContent is the content
   // of the inline frames they were created from. The first/last child of
   // such frames is the real block frame we're looking for.
-  if (NS_SUCCEEDED(rv) && !(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL) ||
+  if (nsLayoutUtils::GetAsBlock(aFrame) && !(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL) ||
       aFrame->GetType() == nsGkAtoms::brFrame) {
     nsIContent* content = aFrame->GetContent();
     result.mContent = content->GetParent();
     // In some cases (bug 310589, bug 370174) we end up here with a null content.
     // This probably shouldn't ever happen, but since it sometimes does, we want
     // to avoid crashing here.
     NS_ASSERTION(result.mContent, "Unexpected orphan content");
     if (result.mContent)
@@ -4669,17 +4665,16 @@ FindBlockFrameOrBR(nsIFrame* aFrame, nsD
   }
   return result;
 }
 
 nsresult
 nsIFrame::PeekOffsetParagraph(nsPeekOffsetStruct *aPos)
 {
   nsIFrame* frame = this;
-  nsBlockFrame* bf;  // used only for QI
   nsContentAndOffset blockFrameOrBR;
   blockFrameOrBR.mContent = nsnull;
   PRBool reachedBlockAncestor = PR_FALSE;
 
   // Go through containing frames until reaching a block frame.
   // In each step, search the previous (or next) siblings for the closest
   // "stop frame" (a block frame or a BRFrame).
   // If found, set it to be the selection boundray and abort.
@@ -4699,17 +4694,17 @@ nsIFrame::PeekOffsetParagraph(nsPeekOffs
         sibling = siblings.GetPrevSiblingFor(sibling);
       }
       if (blockFrameOrBR.mContent) {
         aPos->mResultContent = blockFrameOrBR.mContent;
         aPos->mContentOffset = blockFrameOrBR.mOffset;
         break;
       }
       frame = parent;
-      reachedBlockAncestor = NS_SUCCEEDED(frame->QueryInterface(kBlockFrameCID, (void**)&bf));
+      reachedBlockAncestor = (nsLayoutUtils::GetAsBlock(frame) != nsnull);
     }
     if (reachedBlockAncestor) { // no "stop frame" found
       aPos->mResultContent = frame->GetContent();
       aPos->mContentOffset = 0;
     }
   } else { // eDirNext
     while (!reachedBlockAncestor) {
       nsIFrame* parent = frame->GetParent();
@@ -4724,17 +4719,17 @@ nsIFrame::PeekOffsetParagraph(nsPeekOffs
         sibling = sibling->GetNextSibling();
       }
       if (blockFrameOrBR.mContent) {
         aPos->mResultContent = blockFrameOrBR.mContent;
         aPos->mContentOffset = blockFrameOrBR.mOffset;
         break;
       }
       frame = parent;
-      reachedBlockAncestor = NS_SUCCEEDED(frame->QueryInterface(kBlockFrameCID, (void**)&bf));
+      reachedBlockAncestor = (nsLayoutUtils::GetAsBlock(frame) != nsnull);
     }
     if (reachedBlockAncestor) { // no "stop frame" found
       aPos->mResultContent = frame->GetContent();
       if (aPos->mResultContent)
         aPos->mContentOffset = aPos->mResultContent->GetChildCount();
     }
   }
   return NS_OK;
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -949,19 +949,18 @@ nsHTMLReflowState::CalculateHypothetical
 
   // Get the placeholder x-offset and y-offset in the coordinate
   // space of the block frame that contains it
   // XXXbz the placeholder is not fully reflown yet if our containing block is
   // relatively positioned...
   nsPoint placeholderOffset = aPlaceholderFrame->GetOffsetTo(aContainingBlock);
 
   // First, determine the hypothetical box's mTop
-  nsBlockFrame* blockFrame;
-  if (NS_SUCCEEDED(aContainingBlock->QueryInterface(kBlockFrameCID,
-                                  reinterpret_cast<void**>(&blockFrame)))) {
+  nsBlockFrame* blockFrame = nsLayoutUtils::GetAsBlock(aContainingBlock);
+  if (blockFrame) {
     PRBool isValid;
     nsBlockInFlowLineIterator iter(blockFrame, aPlaceholderFrame, &isValid);
     NS_ASSERTION(isValid, "Can't find placeholder!");
     NS_ASSERTION(iter.GetContainer() == blockFrame, "Found placeholder in wrong block!");
     nsBlockFrame::line_iterator lineBox = iter.GetLine();
 
     // How we determine the hypothetical box depends on whether the element
     // would have been inline-level or block-level
--- a/layout/generic/nsInlineFrame.cpp
+++ b/layout/generic/nsInlineFrame.cpp
@@ -253,22 +253,20 @@ nsInlineFrame::ReparentFloatsForInlineCh
     ancestor = ancestor->GetParent();
     if (!ancestor)
       return;
   } while (!ancestor->IsFloatContainingBlock());
 
   if (ancestor == aOurLineContainer)
     return;
 
-  nsBlockFrame* ourBlock;
-  nsresult rv = aOurLineContainer->QueryInterface(kBlockFrameCID, (void**)&ourBlock);
-  NS_ASSERTION(NS_SUCCEEDED(rv), "Not a block, but broke vertically?");
-  nsBlockFrame* frameBlock;
-  rv = ancestor->QueryInterface(kBlockFrameCID, (void**)&frameBlock);
-  NS_ASSERTION(NS_SUCCEEDED(rv), "ancestor not a block");
+  nsBlockFrame* ourBlock = nsLayoutUtils::GetAsBlock(aOurLineContainer);
+  NS_ASSERTION(ourBlock, "Not a block, but broke vertically?");
+  nsBlockFrame* frameBlock = nsLayoutUtils::GetAsBlock(ancestor);
+  NS_ASSERTION(frameBlock, "ancestor not a block");
 
   nsFrameList blockChildren(ancestor->GetFirstChild(nsnull));
   PRBool isOverflow = !blockChildren.ContainsFrame(ancestorBlockChild);
 
   while (PR_TRUE) {
     ourBlock->ReparentFloats(aFrame, frameBlock, isOverflow, PR_FALSE);
 
     if (!aReparentSiblings)
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -850,18 +850,17 @@ BuildTextRuns(gfxContext* aContext, nsTe
     aLineContainer = FindLineContainer(aForFrame);
   } else {
     NS_ASSERTION(!aForFrame || aLineContainer == FindLineContainer(aForFrame), "Wrong line container hint");
   }
 
   nsPresContext* presContext = aLineContainer->PresContext();
   BuildTextRunsScanner scanner(presContext, aContext, aLineContainer);
 
-  nsBlockFrame* block = nsnull;
-  aLineContainer->QueryInterface(kBlockFrameCID, (void**)&block);
+  nsBlockFrame* block = nsLayoutUtils::GetAsBlock(aLineContainer);
 
   if (!block) {
     NS_ASSERTION(!aLineContainer->GetPrevInFlow() && !aLineContainer->GetNextInFlow(),
                  "Breakable non-block line containers not supported");
     // Just loop through all the children of the linecontainer ... it's really
     // just one line
     scanner.SetAtStartOfLine();
     scanner.SetCommonAncestorWithLastFrame(nsnull);