Bug 396185 - Make nsIFrame derivatives and helper abstract classes use a different dynamic-cast system than nsISupports:
authorBenjamin Smedberg <benjamin@smedbergs.us>
Mon, 12 Jan 2009 14:20:59 -0500
changeset 23554 61ca5667346845391496df48802cb4a83a8f87e0
parent 23553 da0a0796090fad74500b59ffab6e8de148e5df07
child 23555 54cf0cbe42e80714ec9cca64771d5e51f7e51f86
push id4602
push userbsmedberg@mozilla.com
push dateMon, 12 Jan 2009 19:25:32 +0000
treeherdermozilla-central@54cf0cbe42e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs396185
milestone1.9.2a1pre
Bug 396185 - Make nsIFrame derivatives and helper abstract classes use a different dynamic-cast system than nsISupports: * we know all types frames may be cast to at compile time, so instead of extensible GUID IIDs, use a big enum (see nsQueryFrame::FrameIID) * eliminate all vestiges of refcounting, since frames aren't refcounted Some frames (SVG frames in particular) still implement nsISupports-derived interfaces, for example nsISVGValue. There is a FrameIID for nsISVGValue that lets you go from a frame to the XPCOM interface, but you can't query back. r+sr=roc nsITextControlFrame didn't have an IID the first time around, but this wasn't a compile error because nsITextControlFrame::kFrameIID inherited from nsIFormControlFrame::kFrameIID. I've added a static analysis pass to verify the correct behavior, since I can't figure out a way to make the compiler do it.
accessible/public/nsIAccessibilityService.idl
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessibilityService.h
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsRootAccessible.cpp
accessible/src/html/nsHTMLAreaAccessible.cpp
accessible/src/html/nsHTMLFormControlAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/html/nsHyperTextAccessible.cpp
accessible/src/msaa/nsAccessibleWrap.cpp
content/base/src/nsFrameLoader.cpp
content/base/src/nsGenericElement.cpp
content/base/src/nsObjectLoadingContent.cpp
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLObjectElement.cpp
content/html/content/src/nsHTMLSelectElement.cpp
content/html/content/src/nsHTMLTextAreaElement.cpp
content/html/document/src/nsPluginDocument.cpp
content/svg/content/src/nsISVGTextContentMetrics.h
content/svg/content/src/nsISVGValue.h
content/svg/content/src/nsSVGGraphicElement.cpp
content/svg/content/src/nsSVGPatternElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGSwitchElement.cpp
content/svg/content/src/nsSVGTSpanElement.cpp
content/svg/content/src/nsSVGTextElement.cpp
content/svg/content/src/nsSVGTextPathElement.cpp
content/svg/content/src/nsSVGTextPathElement.h
docshell/base/nsDocShell.cpp
editor/libeditor/html/nsTableEditor.cpp
embedding/components/find/src/nsFind.cpp
embedding/components/find/src/nsWebBrowserFind.cpp
layout/base/nsBidiPresUtils.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSRendering.cpp
layout/base/nsCaret.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsFrameManager.cpp
layout/base/nsIPercentHeightObserver.h
layout/base/nsLayoutDebugger.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsComboboxControlFrame.h
layout/forms/nsFileControlFrame.cpp
layout/forms/nsFileControlFrame.h
layout/forms/nsFormControlFrame.cpp
layout/forms/nsFormControlFrame.h
layout/forms/nsGfxButtonControlFrame.cpp
layout/forms/nsGfxButtonControlFrame.h
layout/forms/nsGfxCheckboxControlFrame.cpp
layout/forms/nsGfxCheckboxControlFrame.h
layout/forms/nsGfxRadioControlFrame.cpp
layout/forms/nsGfxRadioControlFrame.h
layout/forms/nsHTMLButtonControlFrame.cpp
layout/forms/nsHTMLButtonControlFrame.h
layout/forms/nsICheckboxControlFrame.h
layout/forms/nsIComboboxControlFrame.h
layout/forms/nsIFormControlFrame.h
layout/forms/nsIListControlFrame.h
layout/forms/nsIRadioControlFrame.h
layout/forms/nsISelectControlFrame.h
layout/forms/nsITextControlFrame.h
layout/forms/nsImageControlFrame.cpp
layout/forms/nsIsIndexFrame.cpp
layout/forms/nsIsIndexFrame.h
layout/forms/nsLegendFrame.cpp
layout/forms/nsLegendFrame.h
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
layout/forms/nsTextControlFrame.cpp
layout/forms/nsTextControlFrame.h
layout/generic/Makefile.in
layout/generic/nsAbsoluteContainingBlock.cpp
layout/generic/nsBRFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsBlockFrame.h
layout/generic/nsContainerFrame.cpp
layout/generic/nsFloatManager.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
layout/generic/nsFrameFrame.cpp
layout/generic/nsFrameList.cpp
layout/generic/nsFrameSetFrame.cpp
layout/generic/nsFrameSetFrame.h
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
layout/generic/nsHTMLFrame.cpp
layout/generic/nsIAnonymousContentCreator.h
layout/generic/nsICanvasFrame.h
layout/generic/nsIFrame.h
layout/generic/nsIFrameDebug.h
layout/generic/nsIFrameFrame.h
layout/generic/nsIImageFrame.h
layout/generic/nsIObjectFrame.h
layout/generic/nsIPageSequenceFrame.h
layout/generic/nsIScrollableFrame.h
layout/generic/nsIScrollableViewProvider.h
layout/generic/nsIStatefulFrame.h
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
layout/generic/nsInlineFrame.cpp
layout/generic/nsInlineFrame.h
layout/generic/nsLineBox.cpp
layout/generic/nsObjectFrame.cpp
layout/generic/nsObjectFrame.h
layout/generic/nsQueryFrame.h
layout/generic/nsSelection.cpp
layout/generic/nsSimplePageSequence.cpp
layout/generic/nsSimplePageSequence.h
layout/generic/nsVideoFrame.cpp
layout/generic/nsVideoFrame.h
layout/generic/nsViewportFrame.cpp
layout/mathml/base/src/nsIMathMLFrame.h
layout/mathml/base/src/nsMathMLContainerFrame.cpp
layout/mathml/base/src/nsMathMLContainerFrame.h
layout/mathml/base/src/nsMathMLForeignFrameWrapper.cpp
layout/mathml/base/src/nsMathMLForeignFrameWrapper.h
layout/mathml/base/src/nsMathMLFrame.cpp
layout/mathml/base/src/nsMathMLFrame.h
layout/mathml/base/src/nsMathMLmactionFrame.cpp
layout/mathml/base/src/nsMathMLmfencedFrame.cpp
layout/mathml/base/src/nsMathMLmtableFrame.cpp
layout/mathml/base/src/nsMathMLmtableFrame.h
layout/printing/nsPrintEngine.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsICSSPseudoComparator.h
layout/svg/base/src/nsISVGChildFrame.h
layout/svg/base/src/nsISVGGlyphFragmentLeaf.h
layout/svg/base/src/nsISVGGlyphFragmentNode.h
layout/svg/base/src/nsISVGSVGFrame.h
layout/svg/base/src/nsSVGClipPathFrame.cpp
layout/svg/base/src/nsSVGContainerFrame.cpp
layout/svg/base/src/nsSVGContainerFrame.h
layout/svg/base/src/nsSVGFilterFrame.cpp
layout/svg/base/src/nsSVGForeignObjectFrame.cpp
layout/svg/base/src/nsSVGForeignObjectFrame.h
layout/svg/base/src/nsSVGGlyphFrame.cpp
layout/svg/base/src/nsSVGGlyphFrame.h
layout/svg/base/src/nsSVGInnerSVGFrame.cpp
layout/svg/base/src/nsSVGIntegrationUtils.cpp
layout/svg/base/src/nsSVGMarkerFrame.cpp
layout/svg/base/src/nsSVGOuterSVGFrame.cpp
layout/svg/base/src/nsSVGOuterSVGFrame.h
layout/svg/base/src/nsSVGPathGeometryFrame.cpp
layout/svg/base/src/nsSVGPathGeometryFrame.h
layout/svg/base/src/nsSVGPatternFrame.cpp
layout/svg/base/src/nsSVGSwitchFrame.cpp
layout/svg/base/src/nsSVGTSpanFrame.cpp
layout/svg/base/src/nsSVGTSpanFrame.h
layout/svg/base/src/nsSVGTextContainerFrame.cpp
layout/svg/base/src/nsSVGTextContainerFrame.h
layout/svg/base/src/nsSVGUseFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/tables/nsITableCellLayout.h
layout/tables/nsITableLayout.h
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableCellFrame.h
layout/tables/nsTableFrame.cpp
layout/tables/nsTableFrame.h
layout/tables/nsTableOuterFrame.cpp
layout/tables/nsTableOuterFrame.h
layout/tables/nsTableRowGroupFrame.cpp
layout/tables/nsTableRowGroupFrame.h
layout/xul/base/public/nsIMenuFrame.h
layout/xul/base/public/nsIScrollbarMediator.h
layout/xul/base/src/grid/nsGrid.cpp
layout/xul/base/src/grid/nsGridRowLeafLayout.cpp
layout/xul/base/src/nsBoxObject.cpp
layout/xul/base/src/nsContainerBoxObject.cpp
layout/xul/base/src/nsDocElementBoxFrame.cpp
layout/xul/base/src/nsIRootBox.h
layout/xul/base/src/nsIScrollbarFrame.h
layout/xul/base/src/nsListBoxBodyFrame.cpp
layout/xul/base/src/nsListBoxBodyFrame.h
layout/xul/base/src/nsListBoxObject.cpp
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/nsMenuPopupFrame.cpp
layout/xul/base/src/nsPopupSetFrame.cpp
layout/xul/base/src/nsRootBoxFrame.cpp
layout/xul/base/src/nsScrollBoxObject.cpp
layout/xul/base/src/nsScrollbarButtonFrame.cpp
layout/xul/base/src/nsScrollbarFrame.cpp
layout/xul/base/src/nsScrollbarFrame.h
layout/xul/base/src/nsSliderFrame.cpp
layout/xul/base/src/nsSplitterFrame.cpp
layout/xul/base/src/nsSplitterFrame.h
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.h
layout/xul/base/src/tree/src/nsTreeBoxObject.cpp
layout/xul/base/src/tree/src/nsTreeColFrame.cpp
layout/xul/base/src/tree/src/nsTreeColFrame.h
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/windows/nsNativeThemeWin.cpp
--- a/accessible/public/nsIAccessibilityService.idl
+++ b/accessible/public/nsIAccessibilityService.idl
@@ -47,39 +47,39 @@ interface nsIContent;
 interface nsITimer;
 
 [uuid(44685af8-18be-494a-8e64-16c7d4296dd1)]
 interface nsIAccessibilityService : nsIAccessibleRetrieval
 {
   nsIAccessible createOuterDocAccessible(in nsIDOMNode aNode);
   nsIAccessible createRootAccessible(in nsIPresShell aShell, in nsIDocument aDocument);
 
-  nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame);
-  nsIAccessible createHyperTextAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLBRAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLButtonAccessible(in nsISupports aFrame);
+  nsIAccessible createHTML4ButtonAccessible(in nsIFrame aFrame);
+  nsIAccessible createHyperTextAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLBRAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLButtonAccessible(in nsIFrame aFrame);
   nsIAccessible createHTMLAccessibleByMarkup(in nsIFrame aFrame, in nsIWeakReference aWeakShell, in nsIDOMNode aDOMNode);
-  nsIAccessible createHTMLLIAccessible(in nsISupports aFrame, in nsISupports aBulletFrame, in AString aBulletText);
-  nsIAccessible createHTMLCheckboxAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLLIAccessible(in nsIFrame aFrame, in nsIFrame aBulletFrame, in AString aBulletText);
+  nsIAccessible createHTMLCheckboxAccessible(in nsIFrame aFrame);
   nsIAccessible createHTMLComboboxAccessible(in nsIDOMNode aNode, in nsIWeakReference aPresShell);
-  nsIAccessible createHTMLGenericAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLGroupboxAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLHRAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLImageAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLLabelAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLGenericAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLGroupboxAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLHRAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLImageAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLLabelAccessible(in nsIFrame aFrame);
   nsIAccessible createHTMLListboxAccessible(in nsIDOMNode aNode, in nsIWeakReference aPresShell);
   nsIAccessible createHTMLObjectFrameAccessible(in nsObjectFrame aFrame);
-  nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLRadioButtonAccessible(in nsIFrame aFrame);
   nsIAccessible createHTMLSelectOptionAccessible(in nsIDOMNode aNode, in nsIAccessible aAccParent, in nsIWeakReference aPresShell);
-  nsIAccessible createHTMLTableAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLTableCellAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLTableAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLTableCellAccessible(in nsIFrame aFrame);
   nsIAccessible createHTMLTableHeadAccessible(in nsIDOMNode aDOMNode);
-  nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
-  nsIAccessible createHTMLCaptionAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLTextAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLTextFieldAccessible(in nsIFrame aFrame);
+  nsIAccessible createHTMLCaptionAccessible(in nsIFrame aFrame);
 
   nsIAccessible getAccessible(in nsIDOMNode aNode, in nsIPresShell aPresShell,                          
                               in nsIWeakReference aWeakShell, 
                               inout nsIFrame frameHint, out boolean aIsHidden);
 
   // For gtk+ native window accessible
   nsIAccessible addNativeRootAccessible(in voidPtr aAtkAccessible);
   void removeNativeRootAccessible(in nsIAccessible aRootAccessible);
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -327,21 +327,20 @@ NS_IMETHODIMP nsAccessibilityService::On
   nsIRequest *aRequest, PRUint32 state)
 {
   NS_NOTREACHED("notification excluded in AddProgressListener(...)");
   return NS_OK;
 }
 
 
 nsresult
-nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
+nsAccessibilityService::GetInfo(nsIFrame* aFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
 {
   NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!");
-  *aRealFrame = static_cast<nsIFrame*>(aFrame);
-  nsCOMPtr<nsIContent> content = (*aRealFrame)->GetContent();
+  nsCOMPtr<nsIContent> content = aFrame->GetContent();
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
   if (!content || !node)
     return NS_ERROR_FAILURE;
   *aNode = node;
   NS_IF_ADDREF(*aNode);
 
   nsCOMPtr<nsIDocument> document = content->GetDocument();
   if (!document)
@@ -469,40 +468,38 @@ nsAccessibilityService::CreateRootAccess
 
   return NS_OK;
 }
 
  /**
    * HTML widget creation
    */
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTML4ButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTML4ButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTML4ButtonAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLButtonAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -560,63 +557,60 @@ nsAccessibilityService::CreateHTMLAccess
            tag == nsAccessibilityAtoms::q) {
     return CreateHyperTextAccessible(aFrame, aAccessible);
   }
   NS_IF_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLLIAccessible(nsISupports *aFrame, 
-                                               nsISupports *aBulletFrame,
+nsAccessibilityService::CreateHTMLLIAccessible(nsIFrame *aFrame, 
+                                               nsIFrame *aBulletFrame,
                                                const nsAString& aBulletText,
                                                nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLLIAccessible(node, weakShell, aBulletText);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHyperTextAccessible(nsISupports *aFrame, nsIAccessible **aAccessible)
+nsAccessibilityService::CreateHyperTextAccessible(nsIFrame *aFrame, nsIAccessible **aAccessible)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
   
   *aAccessible = new nsHyperTextAccessibleWrap(node, weakShell);
   NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLCheckboxAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLCheckboxAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -630,22 +624,21 @@ nsAccessibilityService::CreateHTMLCombob
   if (! *_retval)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLImageAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLImageAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = nsnull;
   nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(node));
   if (domElement) {
       *_retval = new nsHTMLImageAccessibleWrap(node, weakShell);
   }
@@ -653,28 +646,27 @@ nsAccessibilityService::CreateHTMLImageA
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLGenericAccessible(nsISupports *aFrame, nsIAccessible **aAccessible)
+nsAccessibilityService::CreateHTMLGenericAccessible(nsIFrame *aFrame, nsIAccessible **aAccessible)
 {
   return CreateHyperTextAccessible(aFrame, aAccessible);
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLGroupboxAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLGroupboxAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -702,21 +694,20 @@ nsAccessibilityService::CreateHTMLListbo
   *     the object element DOMNode
   */
 NS_IMETHODIMP
 nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame,
                                                         nsIAccessible **aAccessible)
 {
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsIFrame *frame;
-  GetInfo(static_cast<nsIFrame*>(aFrame), &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
 
   *aAccessible = nsnull;
-  if (!frame || frame->GetRect().IsEmpty()) {
+  if (aFrame->GetRect().IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
   // 1) for object elements containing either HTML or TXT documents
   nsCOMPtr<nsIDOMDocument> domDoc;
   nsCOMPtr<nsIDOMHTMLObjectElement> obj(do_QueryInterface(node));
   if (obj)
     obj->GetContentDocument(getter_AddRefs(domDoc));
   else
@@ -738,30 +729,29 @@ nsAccessibilityService::CreateHTMLObject
         return NS_OK;
       }
     }
   }
 #endif
 
   // 3) for images and imagemaps, or anything else with a child frame
   // we have the object frame, get the image frame
-  frame = aFrame->GetFirstChild(nsnull);
+  nsIFrame *frame = aFrame->GetFirstChild(nsnull);
   if (frame)
     return frame->GetAccessible(aAccessible);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLRadioButtonAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -778,22 +768,21 @@ nsAccessibilityService::CreateHTMLSelect
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLTableAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTableAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLTableAccessibleWrap(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -823,133 +812,126 @@ nsAccessibilityService::CreateHTMLTableH
   *_retval = static_cast<nsIAccessible *>(accTableHead);
   NS_IF_ADDREF(*_retval);
 
   return rv;
 #endif
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTableCellAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLTableCellAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLTextAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTextAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
   *_retval = nsnull;
 
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   // XXX Don't create ATK objects for these
   *_retval = new nsHTMLTextAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLTextFieldAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLTextFieldAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLLabelAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLLabelAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLLabelAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLHRAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLHRAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLHRAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLBRAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLBRAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLBRAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsAccessibilityService::CreateHTMLCaptionAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLCaptionAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
 {
-  nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   *_retval = new nsHTMLCaptionAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
@@ -1405,18 +1387,17 @@ NS_IMETHODIMP nsAccessibilityService::Ge
 #endif
       if (frame->GetContent() != content) {
         // Not the main content for this frame!
         // For example, this happens because <area> elements return the
         // image frame as their primary frame. The main content for the 
         // image frame is the image content.
 
         // Check if frame is an image frame, and content is <area>
-        nsIImageFrame *imageFrame;
-        CallQueryInterface(frame, &imageFrame);
+        nsIImageFrame *imageFrame = do_QueryFrame(frame);
         nsCOMPtr<nsIDOMHTMLAreaElement> areaElmt = do_QueryInterface(content);
         if (imageFrame && areaElmt) {
           nsCOMPtr<nsIAccessible> imageAcc;
           CreateHTMLImageAccessible(frame, getter_AddRefs(imageAcc));
           if (imageAcc) {
             // cache children
             PRInt32 childCount;
             imageAcc->GetChildCount(&childCount);
--- a/accessible/src/base/nsAccessibilityService.h
+++ b/accessible/src/base/nsAccessibilityService.h
@@ -84,22 +84,21 @@ public:
    */
   static nsresult GetAccessibilityService(nsIAccessibilityService** aResult);
 
 private:
   /**
    * Return presentation shell, DOM node for the given frame.
    *
    * @param aFrame - the given frame
-   * @param aRealFrame [out] - the given frame casted to nsIFrame
    * @param aShell [out] - presentation shell for DOM node associated with the
    *                 given frame
    * @param aContent [out] - DOM node associated with the given frame
    */
-  nsresult GetInfo(nsISupports *aFrame, nsIFrame **aRealFrame,
+  nsresult GetInfo(nsIFrame *aFrame,
                    nsIWeakReference **aShell,
                    nsIDOMNode **aContent);
 
   /**
    * Initialize an accessible and cache it. The method should be called for
    * every created accessible.
    *
    * @param aAccessibleIn - accessible to initialize.
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -2780,18 +2780,17 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
       // If accessible is in its own Window then we should provide NODE_CHILD_OF relation
       // so that MSAA clients can easily get to true parent instead of getting to oleacc's
       // ROLE_WINDOW accessible which will prevent us from going up further (because it is
       // system generated and has no idea about the hierarchy above it).
       nsIFrame *frame = GetFrame();
       if (frame) {
         nsIView *view = frame->GetViewExternal();
         if (view) {
-          nsIScrollableFrame *scrollFrame = nsnull;
-          CallQueryInterface(frame, &scrollFrame);
+          nsIScrollableFrame *scrollFrame = do_QueryFrame(frame);
           if (scrollFrame || view->GetWidget()) {
             return GetParent(aRelated);
           }
         }
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -326,18 +326,17 @@ nsCoreUtils::ScrollSubstringTo(nsIFrame 
   return NS_OK;
 }
 
 void
 nsCoreUtils::ScrollFrameToPoint(nsIFrame *aScrollableFrame,
                                 nsIFrame *aFrame,
                                 const nsIntPoint& aPoint)
 {
-  nsIScrollableFrame *scrollableFrame = nsnull;
-  CallQueryInterface(aScrollableFrame, &scrollableFrame);
+  nsIScrollableFrame *scrollableFrame = do_QueryFrame(aScrollableFrame);
   if (!scrollableFrame)
     return;
 
   nsPresContext *presContext = aFrame->PresContext();
 
   nsIntRect frameRect = aFrame->GetScreenRectExternal();
   PRInt32 devDeltaX = aPoint.x - frameRect.x;
   PRInt32 devDeltaY = aPoint.y - frameRect.y;
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -836,18 +836,17 @@ nsresult nsRootAccessible::HandleEventWi
       }
 #endif
       nsRefPtr<nsAccessNode> menuAccessNode =
         nsAccUtils::QueryAccessNode(accessible);
   
       nsIFrame* menuFrame = menuAccessNode->GetFrame();
       NS_ENSURE_TRUE(menuFrame, NS_ERROR_FAILURE);
 
-      nsIMenuFrame* imenuFrame;
-      CallQueryInterface(menuFrame, &imenuFrame);
+      nsIMenuFrame* imenuFrame = do_QueryFrame(menuFrame);
       if (imenuFrame)
         fireFocus = PR_TRUE;
       // QI failed for nsIMenuFrame means it's not on menu bar
       if (imenuFrame && imenuFrame->IsOnMenuBar() &&
                        !imenuFrame->IsOnActiveMenuBar()) {
         // It is a top level menuitem. Only fire a focus event when the menu bar
         // is active.
         return NS_OK;
--- a/accessible/src/html/nsHTMLAreaAccessible.cpp
+++ b/accessible/src/html/nsHTMLAreaAccessible.cpp
@@ -115,31 +115,31 @@ nsHTMLAreaAccessible::GetChildCount(PRIn
   *aCount = 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y,
                                 PRInt32 *width, PRInt32 *height)
 {
+  nsresult rv;
+
   // Essentially this uses GetRect on mAreas of nsImageMap from nsImageFrame
 
   *x = *y = *width = *height = 0;
 
   nsPresContext *presContext = GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIContent> ourContent(do_QueryInterface(mDOMNode));
   NS_ENSURE_TRUE(ourContent, NS_ERROR_FAILURE);
 
   nsIFrame *frame = GetFrame();
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
-  nsIImageFrame *imageFrame;
-  nsresult rv = frame->QueryInterface(NS_GET_IID(nsIImageFrame), (void**)&imageFrame);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsIImageFrame *imageFrame = do_QueryFrame(frame);
 
   nsCOMPtr<nsIImageMap> map;
   imageFrame->GetImageMap(presContext, getter_AddRefs(map));
   NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
 
   nsRect rect, orgRectPixels;
   rv = map->GetBoundsForAreaContent(ourContent, presContext, rect);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/accessible/src/html/nsHTMLFormControlAccessible.cpp
+++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp
@@ -287,18 +287,17 @@ nsHTMLButtonAccessible::GetNameInternal(
   nsAutoString name;
   if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value,
                         name) &&
       !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt,
                         name)) {
     // Use the button's (default) label if nothing else works
     nsIFrame* frame = GetFrame();
     if (frame) {
-      nsIFormControlFrame* fcFrame = nsnull;
-      CallQueryInterface(frame, &fcFrame);
+      nsIFormControlFrame* fcFrame = do_QueryFrame(frame);
       if (fcFrame)
         fcFrame->GetFormProperty(nsAccessibilityAtoms::defaultLabel, name);
     }
   }
 
   if (name.IsEmpty() &&
       !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::src,
                         name)) {
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -738,24 +738,22 @@ NS_IMETHODIMP nsHTMLSelectOptionAccessib
     nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
     nsCOMPtr<nsIContent> selectContent(do_QueryInterface(testSelectNode));
     nsCOMPtr<nsIDOMHTMLOptionElement> option(do_QueryInterface(mDOMNode));
 
     if (!testSelectNode || !selectContent || !presShell || !option) 
       return NS_ERROR_FAILURE;
 
     nsIFrame *selectFrame = presShell->GetPrimaryFrameFor(selectContent);
-    nsIComboboxControlFrame *comboBoxFrame = nsnull;
-    CallQueryInterface(selectFrame, &comboBoxFrame);
+    nsIComboboxControlFrame *comboBoxFrame = do_QueryFrame(selectFrame);
     if (comboBoxFrame) {
       nsIFrame *listFrame = comboBoxFrame->GetDropDown();
       if (comboBoxFrame->IsDroppedDown() && listFrame) {
         // use this list control frame to roll up the list
-        nsIListControlFrame *listControlFrame = nsnull;
-        listFrame->QueryInterface(NS_GET_IID(nsIListControlFrame), (void**)&listControlFrame);
+        nsIListControlFrame *listControlFrame = do_QueryFrame(listFrame);
         if (listControlFrame) {
           PRInt32 newIndex = 0;
           option->GetIndex(&newIndex);
           listControlFrame->ComboboxFinish(newIndex);
         }
       }
     }
     return NS_OK;
@@ -792,18 +790,17 @@ nsresult nsHTMLSelectOptionAccessible::G
   // Get options
   nsCOMPtr<nsIDOMHTMLSelectElement> selectElement(do_QueryInterface(aListNode));
   NS_ASSERTION(selectElement, "No select element where it should be");
 
   nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
   nsresult rv = selectElement->GetOptions(getter_AddRefs(options));
   
   if (NS_SUCCEEDED(rv)) {
-    nsIListControlFrame *listFrame = nsnull;
-    frame->QueryInterface(NS_GET_IID(nsIListControlFrame), (void**)&listFrame);
+    nsIListControlFrame *listFrame = do_QueryFrame(frame);
     if (listFrame) {
       // Get what's focused in listbox by asking frame for "selected item". 
       // Can't use dom interface for this, because it will always return the first selected item
       // when there is more than 1 item selected. We need the focused item, not
       // the first selected item.
       focusedOptionIndex = listFrame->GetSelectedIndex();
       if (focusedOptionIndex == -1) {
         nsCOMPtr<nsIDOMNode> nextOption;
@@ -1011,18 +1008,17 @@ void nsHTMLComboboxAccessible::CacheChil
     buttonAccessible->Init();
     mAccChildCount = 2; // Button accessible child successfully added
 #endif
 
     nsIFrame *frame = GetFrame();
     if (!frame) {
       return;
     }
-    nsIComboboxControlFrame *comboFrame = nsnull;
-    frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), (void**)&comboFrame);
+    nsIComboboxControlFrame *comboFrame = do_QueryFrame(frame);
     if (!comboFrame) {
       return;
     }
     nsIFrame *listFrame = comboFrame->GetDropDown();
     if (!listFrame) {
       return;
     }
 
@@ -1071,21 +1067,17 @@ nsresult
 nsHTMLComboboxAccessible::GetStateInternal(PRUint32 *aState,
                                            PRUint32 *aExtraState)
 {
   // Get focus status from base class
   nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
   NS_ENSURE_A11Y_SUCCESS(rv, rv);
 
   nsIFrame *frame = GetBoundsFrame();
-  nsIComboboxControlFrame *comboFrame = nsnull;
-  if (frame) {
-    frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), (void**)&comboFrame);
-  }
-
+  nsIComboboxControlFrame *comboFrame = do_QueryFrame(frame);
   if (comboFrame && comboFrame->IsDroppedDown()) {
     *aState |= nsIAccessibleStates::STATE_EXPANDED;
   }
   else {
     *aState &= ~nsIAccessibleStates::STATE_FOCUSED; // Focus is on an option
     *aState |= nsIAccessibleStates::STATE_COLLAPSED;
   }
 
@@ -1155,18 +1147,17 @@ NS_IMETHODIMP nsHTMLComboboxAccessible::
 {
   if (aIndex != nsHTMLComboboxAccessible::eAction_Click) {
     return NS_ERROR_INVALID_ARG;
   }
   nsIFrame *frame = GetFrame();
   if (!frame) {
     return NS_ERROR_FAILURE;
   }
-  nsIComboboxControlFrame *comboFrame = nsnull;
-  frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), (void**)&comboFrame);
+  nsIComboboxControlFrame *comboFrame = do_QueryFrame(frame);
   if (!comboFrame) {
     return NS_ERROR_FAILURE;
   }
   // Reverse whether it's dropped down or not
   comboFrame->ShowDropDown(!comboFrame->IsDroppedDown());
 
   return NS_OK;
 }
@@ -1181,18 +1172,17 @@ NS_IMETHODIMP nsHTMLComboboxAccessible::
 {
   if (aIndex != nsHTMLComboboxAccessible::eAction_Click) {
     return NS_ERROR_INVALID_ARG;
   }
   nsIFrame *frame = GetFrame();
   if (!frame) {
     return NS_ERROR_FAILURE;
   }
-  nsIComboboxControlFrame *comboFrame = nsnull;
-  frame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), (void**)&comboFrame);
+  nsIComboboxControlFrame *comboFrame = do_QueryFrame(frame);
   if (!comboFrame) {
     return NS_ERROR_FAILURE;
   }
   if (comboFrame->IsDroppedDown())
     aName.AssignLiteral("close"); 
   else
     aName.AssignLiteral("open"); 
 
@@ -1423,18 +1413,17 @@ nsHTMLSelectListAccessible(aDOMNode, aSh
 }
 
 nsIFrame*
 nsHTMLComboboxListAccessible::GetFrame()
 {
   nsIFrame* frame = nsHTMLSelectListAccessible::GetFrame();
 
   if (frame) {
-    nsIComboboxControlFrame* comboBox;
-    CallQueryInterface(frame, &comboBox);
+    nsIComboboxControlFrame* comboBox = do_QueryFrame(frame);
     if (comboBox) {
       return comboBox->GetDropDown();
     }
   }
 
   return nsnull;
 }
 
@@ -1449,20 +1438,17 @@ nsresult
 nsHTMLComboboxListAccessible::GetStateInternal(PRUint32 *aState,
                                                PRUint32 *aExtraState)
 {
   // Get focus status from base class
   nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
   NS_ENSURE_A11Y_SUCCESS(rv, rv);
 
   nsIFrame *boundsFrame = GetBoundsFrame();
-  nsIComboboxControlFrame* comboFrame = nsnull;
-  if (boundsFrame)
-    boundsFrame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame), (void**)&comboFrame);
-
+  nsIComboboxControlFrame* comboFrame = do_QueryFrame(boundsFrame);
   if (comboFrame && comboFrame->IsDroppedDown())
     *aState |= nsIAccessibleStates::STATE_FLOATING;
   else
     *aState |= nsIAccessibleStates::STATE_INVISIBLE;
 
   return NS_OK;
 }
 
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -90,18 +90,17 @@ nsHTMLTableCellAccessible::GetAttributes
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell();
   NS_ENSURE_STATE(shell);
   
   nsIFrame *frame = shell->GetPrimaryFrameFor(content);
   NS_ASSERTION(frame, "The frame cannot be obtaied for HTML table cell.");
   NS_ENSURE_STATE(frame);
 
-  nsITableCellLayout *cellLayout = nsnull;
-  CallQueryInterface(frame, &cellLayout);
+  nsITableCellLayout *cellLayout = do_QueryFrame(frame);
   NS_ENSURE_STATE(cellLayout);
 
   PRInt32 rowIdx = -1, cellIdx = -1;
   rv = cellLayout->GetCellIndexes(rowIdx, cellIdx);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAccessible> childAcc(this);
 
@@ -923,17 +922,21 @@ nsHTMLTableAccessible::GetTableLayout(ns
   if (!tableContent) {
     return NS_ERROR_FAILURE; // Table shut down
   }
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
 
   nsIFrame *frame = shell->GetPrimaryFrameFor(tableContent);
-  return frame ? CallQueryInterface(frame, aTableLayout) : NS_ERROR_FAILURE;
+  if (!frame)
+    return NS_ERROR_FAILURE;
+
+  *aTableLayout = do_QueryFrame(frame);
+  return (*aTableLayout) ? NS_OK : NS_NOINTERFACE;
 }
 
 nsresult
 nsHTMLTableAccessible::GetCellAt(PRInt32        aRowIndex,
                                  PRInt32        aColIndex,
                                  nsIDOMElement* &aCell)
 {
   PRInt32 startRowIndex = 0, startColIndex = 0,
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -2039,18 +2039,17 @@ nsHyperTextAccessible::ScrollSubstringTo
                                   getter_AddRefs(endNode), &endOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsPresContext *presContext = frame->PresContext();
 
   PRBool initialScrolled = PR_FALSE;
   nsIFrame *parentFrame = frame;
   while ((parentFrame = parentFrame->GetParent())) {
-    nsIScrollableFrame *scrollableFrame = nsnull;
-    CallQueryInterface(parentFrame, &scrollableFrame);
+    nsIScrollableFrame *scrollableFrame = do_QueryFrame(parentFrame);
     if (scrollableFrame) {
       if (!initialScrolled) {
         // Scroll substring to the given point. Turn the point into percents
         // relative scrollable area to use nsCoreUtils::ScrollSubstringTo.
         nsIntRect frameRect = parentFrame->GetScreenRectExternal();
         PRInt32 devOffsetX = coords.x - frameRect.x;
         PRInt32 devOffsetY = coords.y - frameRect.y;
 
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -211,18 +211,17 @@ STDMETHODIMP nsAccessibleWrap::get_accPa
           // we want the native accessible for that outer window
           hwnd = ::GetParent(hwnd);
           NS_ASSERTION(hwnd, "No window handle for window");
         }
       }
       else {
         // If a frame is a scrollable frame, then it has one window for the client area,
         // not an extra parent window for just the scrollbars
-        nsIScrollableFrame *scrollFrame = nsnull;
-        CallQueryInterface(frame, &scrollFrame);
+        nsIScrollableFrame *scrollFrame = do_QueryFrame(frame);
         if (scrollFrame) {
           hwnd = (HWND)scrollFrame->GetScrolledFrame()->GetWindow()->GetNativeData(NS_NATIVE_WINDOW);
           NS_ASSERTION(hwnd, "No window handle for window");
         }
       }
     }
 
     if (hwnd && SUCCEEDED(AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAccessible,
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -630,18 +630,17 @@ nsFrameLoader::SwapWithOtherLoader(nsFra
   nsIFrame* otherFrame = otherShell->GetPrimaryFrameFor(otherContent);
   if (!ourFrame || !otherFrame) {
     mInSwap = aOther->mInSwap = PR_FALSE;
     FirePageShowEvent(ourTreeItem, ourChromeEventHandler, PR_TRUE);
     FirePageShowEvent(otherTreeItem, otherChromeEventHandler, PR_TRUE);
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
-  nsIFrameFrame* ourFrameFrame = nsnull;
-  CallQueryInterface(ourFrame, &ourFrameFrame);
+  nsIFrameFrame* ourFrameFrame = do_QueryFrame(ourFrame);
   if (!ourFrameFrame) {
     mInSwap = aOther->mInSwap = PR_FALSE;
     FirePageShowEvent(ourTreeItem, ourChromeEventHandler, PR_TRUE);
     FirePageShowEvent(otherTreeItem, otherChromeEventHandler, PR_TRUE);
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // OK.  First begin to swap the docshells in the two nsIFrames
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -1112,22 +1112,19 @@ nsNSElementTearoff::GetScrollInfo(nsIScr
   if (aFrame) {
     *aFrame = frame;
   }
   if (!frame) {
     return;
   }
 
   // Get the scrollable frame
-  nsIScrollableFrame *scrollFrame = nsnull;
-  CallQueryInterface(frame, &scrollFrame);
-
+  nsIScrollableFrame *scrollFrame = do_QueryFrame(frame);
   if (!scrollFrame) {
-    nsIScrollableViewProvider *scrollProvider = nsnull;
-    CallQueryInterface(frame, &scrollProvider);
+    nsIScrollableViewProvider *scrollProvider = do_QueryFrame(frame);
     // menu frames implement nsIScrollableViewProvider but we don't want
     // to use it here.
     if (scrollProvider && frame->GetType() != nsGkAtoms::menuFrame) {
       *aScrollableView = scrollProvider->GetScrollableView();
       if (*aScrollableView) {
         return;
       }
     }
@@ -1146,17 +1143,17 @@ nsNSElementTearoff::GetScrollInfo(nsIScr
 
       do {
         frame = frame->GetParent();
 
         if (!frame) {
           break;
         }
 
-        CallQueryInterface(frame, &scrollFrame);
+        scrollFrame = do_QueryFrame(frame);
       } while (!scrollFrame);
     }
 
     if (!scrollFrame) {
       return;
     }
   }
 
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -556,18 +556,17 @@ nsObjectLoadingContent::OnStartRequest(n
         // Do nothing in this case: This is probably due to a display:none
         // frame. If we ever get a frame, HasNewFrame will do the right thing.
         // Abort the load though, we have no use for the data.
         mInstantiating = PR_FALSE;
         return NS_BINDING_ABORTED;
       }
 
       {
-        nsIFrame *nsiframe;
-        CallQueryInterface(frame, &nsiframe);
+        nsIFrame *nsiframe = do_QueryFrame(frame);
 
         nsWeakFrame weakFrame(nsiframe);
 
         rv = frame->Instantiate(chan, getter_AddRefs(mFinalListener));
 
         mInstantiating = PR_FALSE;
 
         if (!weakFrame.IsAlive()) {
@@ -746,18 +745,17 @@ nsObjectLoadingContent::EnsureInstantiat
     mInstantiating = PR_FALSE;
 
     frame = GetExistingFrame(eFlushContent);
     if (!frame) {
       return NS_OK;
     }
   }
 
-  nsIFrame *nsiframe;
-  CallQueryInterface(frame, &nsiframe);
+  nsIFrame *nsiframe = do_QueryFrame(frame);
   nsWeakFrame weakFrame(nsiframe);
 
   // We may have a plugin instance already; if so, do nothing
   nsresult rv = frame->GetPluginInstance(*aInstance);
   if (!*aInstance && weakFrame.IsAlive()) {
     rv = Instantiate(frame, mContentType, mURI);
     if (NS_SUCCEEDED(rv) && weakFrame.IsAlive()) {
       rv = frame->GetPluginInstance(*aInstance);
@@ -800,18 +798,17 @@ nsObjectLoadingContent::HasNewFrame(nsIO
     if (pDoc) {
       PRBool willHandleInstantiation;
       pDoc->GetWillHandleInstantiation(&willHandleInstantiation);
       if (willHandleInstantiation) {
         return NS_OK;
       }
     }
 
-    nsIFrame* frame = nsnull;
-    CallQueryInterface(aFrame, &frame);
+    nsIFrame* frame = do_QueryFrame(aFrame);
     nsCOMPtr<nsIRunnable> event =
       new nsAsyncInstantiateEvent(this, frame, mContentType, mURI);
     if (!event) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     LOG(("                 dispatching event\n"));
     nsresult rv = NS_DispatchToCurrentThread(event);
@@ -1647,18 +1644,17 @@ nsObjectLoadingContent::GetExistingFrame
     // the document, etc, since flushing might run script.
     mozFlushType flushType =
       aFlushType == eFlushLayout ? Flush_Layout : Flush_ContentAndNotify;
     doc->FlushPendingNotifications(flushType);
 
     aFlushType = eDontFlush;
   } while (1);
 
-  nsIObjectFrame* objFrame;
-  CallQueryInterface(frame, &objFrame);
+  nsIObjectFrame* objFrame = do_QueryFrame(frame);
   return objFrame;
 }
 
 void
 nsObjectLoadingContent::HandleBeingBlockedByContentPolicy(nsresult aStatus,
                                                           PRInt16 aRetval)
 {
   // Must call UnloadContent first, as it overwrites
@@ -1690,18 +1686,17 @@ nsObjectLoadingContent::TryInstantiate(c
   if (!instance) {
     // The frame has no plugin instance yet. If the frame hasn't been
     // reflown yet, do nothing as once the reflow happens we'll end up
     // instantiating the plugin with the correct size n' all (which
     // isn't known until we've done the first reflow). But if the
     // frame does have a plugin instance already, be sure to
     // re-instantiate the plugin as its source or whatnot might have
     // chanced since it was instantiated.
-    nsIFrame* iframe;
-    CallQueryInterface(frame, &iframe);
+    nsIFrame* iframe = do_QueryFrame(frame);
     if (iframe->GetStateBits() & NS_FRAME_FIRST_REFLOW) {
       LOG(("OBJLC [%p]: Frame hasn't been reflown yet\n", this));
       return NS_OK; // Not a failure to have no frame
     }
   }
 
   return Instantiate(frame, aMIMEType, aURI);
 }
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -2374,18 +2374,17 @@ nsEventStateManager::DoDefaultDragStart(
       if (content->NodeInfo()->Equals(nsGkAtoms::treechildren,
                                       kNameSpaceID_XUL)) {
         nsIDocument* doc = content->GetCurrentDoc();
         if (doc) {
           nsIPresShell* presShell = doc->GetPrimaryShell();
           if (presShell) {
             nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
             if (frame) {
-              nsTreeBodyFrame* treeBody;
-              CallQueryInterface(frame, &treeBody);
+              nsTreeBodyFrame* treeBody = do_QueryFrame(frame);
               treeBody->GetSelectionRegion(getter_AddRefs(region));
             }
           }
         }
       }
     }
 #endif
 
@@ -2530,18 +2529,17 @@ GetParentFrameToScroll(nsPresContext* aP
 
   return aFrame->GetParent();
 }
 
 static nsIScrollableView*
 GetScrollableViewForFrame(nsPresContext* aPresContext, nsIFrame* aFrame)
 {
   for (; aFrame; aFrame = GetParentFrameToScroll(aPresContext, aFrame)) {
-    nsIScrollableViewProvider* svp;
-    CallQueryInterface(aFrame, &svp);
+    nsIScrollableViewProvider* svp = do_QueryFrame(aFrame);
     if (svp) {
       nsIScrollableView* scrollView = svp->GetScrollableView();
       if (scrollView)
         return scrollView;
     }
   }
   return nsnull;
 }
@@ -2607,34 +2605,32 @@ nsEventStateManager::DoScrollText(nsPres
   // nsMouseWheelTransaction tracks the frame currently being scrolled with the
   // mousewheel. We consider the transaction ended when the mouse moves more than
   // "mousewheel.transaction.ignoremovedelay" milliseconds after the last scroll
   // operation, or any time the mouse moves out of the frame, or when more than
   // "mousewheel.transaction.timeout" milliseconds have passed after the last
   // operation, even if the mouse hasn't moved.
   nsIFrame* lastScrollFrame = nsMouseWheelTransaction::GetTargetFrame();
   if (lastScrollFrame) {
-    nsIScrollableViewProvider* svp;
-    CallQueryInterface(lastScrollFrame, &svp);
+    nsIScrollableViewProvider* svp = do_QueryFrame(lastScrollFrame);
     if (svp) {
       scrollView = svp->GetScrollableView();
       nsMouseWheelTransaction::UpdateTransaction();
     } else {
       nsMouseWheelTransaction::EndTransaction();
       lastScrollFrame = nsnull;
     }
   }
   PRBool passToParent = lastScrollFrame ? PR_FALSE : PR_TRUE;
 
   for (; scrollFrame && passToParent;
        scrollFrame = GetParentFrameToScroll(aPresContext, scrollFrame)) {
     // Check whether the frame wants to provide us with a scrollable view.
     scrollView = nsnull;
-    nsIScrollableViewProvider* svp;
-    CallQueryInterface(scrollFrame, &svp);
+    nsIScrollableViewProvider* svp = do_QueryFrame(scrollFrame);
     if (svp) {
       scrollView = svp->GetScrollableView();
     }
     if (!scrollView) {
       continue;
     }
 
     nsPresContext::ScrollbarStyles ss =
@@ -2653,18 +2649,17 @@ nsEventStateManager::DoScrollText(nsPres
       nsresult rv = scrollView->CanScroll(aScrollHorizontal,
                                           (aNumLines > 0), canScroll);
       if (NS_SUCCEEDED(rv) && canScroll) {
         passToParent = PR_FALSE;
         nsMouseWheelTransaction::BeginTransaction(scrollFrame, aEvent);
       }
 
       // Comboboxes need special care.
-      nsIComboboxControlFrame* comboBox = nsnull;
-      CallQueryInterface(scrollFrame, &comboBox);
+      nsIComboboxControlFrame* comboBox = do_QueryFrame(scrollFrame);
       if (comboBox) {
         if (comboBox->IsDroppedDown()) {
           // Don't propagate to parent when drop down menu is active.
           if (passToParent) {
             passToParent = PR_FALSE;
             scrollView = nsnull;
             nsMouseWheelTransaction::EndTransaction();
           }
@@ -3588,18 +3583,17 @@ nsEventStateManager::NotifyMouseOut(nsGU
     return;
   // Before firing mouseout, check for recursion
   if (mLastMouseOverElement == mFirstMouseOutEventElement)
     return;
 
   if (mLastMouseOverFrame) {
     // if the frame is associated with a subdocument,
     // tell the subdocument that we're moving out of it
-    nsIFrameFrame* subdocFrame;
-    CallQueryInterface(mLastMouseOverFrame.GetFrame(), &subdocFrame);
+    nsIFrameFrame* subdocFrame = do_QueryFrame(mLastMouseOverFrame.GetFrame());
     if (subdocFrame) {
       nsCOMPtr<nsIDocShell> docshell;
       subdocFrame->GetDocShell(getter_AddRefs(docshell));
       if (docshell) {
         nsCOMPtr<nsPresContext> presContext;
         docshell->GetPresContext(getter_AddRefs(presContext));
         
         if (presContext) {
@@ -5210,19 +5204,17 @@ nsEventStateManager::SendFocusBlur(nsPre
   if (aEnsureWindowHasFocus) {
     nsCOMPtr<nsIWidget> widget;
     // Plug-ins with native widget need a special handling
     nsIFrame* currentFocusFrame = nsnull;
     if (mCurrentFocus)
       currentFocusFrame = presShell->GetPrimaryFrameFor(mCurrentFocus);
     if (!currentFocusFrame)
       currentFocusFrame = mCurrentTarget;
-    nsIObjectFrame* objFrame = nsnull;
-    if (currentFocusFrame)
-      CallQueryInterface(currentFocusFrame, &objFrame);
+    nsIObjectFrame* objFrame = do_QueryFrame(currentFocusFrame);
     if (objFrame) {
       nsIView* view = currentFocusFrame->GetViewExternal();
       NS_ASSERTION(view, "Object frames must have views");
       widget = view->GetWidget();
     }
     if (!widget) {
       // This raises the window that has both content and scroll bars in it
       // instead of the child window just below it that contains only the content
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1321,28 +1321,27 @@ nsGenericHTMLElement::GetFormControlFram
 {
   if (aFlushContent) {
     // Cause a flush of content, so we get up-to-date frame
     // information
     aDocument->FlushPendingNotifications(Flush_Layout);
   }
   nsIFrame* frame = GetPrimaryFrameFor(aContent, aDocument);
   if (frame) {
-    nsIFormControlFrame* form_frame = nsnull;
-    CallQueryInterface(frame, &form_frame);
+    nsIFormControlFrame* form_frame = do_QueryFrame(frame);
     if (form_frame) {
       return form_frame;
     }
 
     // If we have generated content, the primary frame will be a
     // wrapper frame..  out real frame will be in its child list.
     for (frame = frame->GetFirstChild(nsnull);
          frame;
          frame = frame->GetNextSibling()) {
-      CallQueryInterface(frame, &form_frame);
+      form_frame = do_QueryFrame(frame);
       if (form_frame) {
         return form_frame;
       }
     }
   }
 
   return nsnull;
 }
@@ -3547,18 +3546,17 @@ nsGenericHTMLElement::GetEditor(nsIEdito
 
 nsresult
 nsGenericHTMLElement::GetEditorInternal(nsIEditor** aEditor)
 {
   *aEditor = nsnull;
 
   nsIFormControlFrame *fcFrame = GetFormControlFrame(PR_FALSE);
   if (fcFrame) {
-    nsITextControlFrame *textFrame = nsnull;
-    CallQueryInterface(fcFrame, &textFrame);
+    nsITextControlFrame *textFrame = do_QueryFrame(fcFrame);
     if (textFrame) {
       return textFrame->GetEditor(aEditor);
     }
   }
 
   return NS_OK;
 }
 
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -301,19 +301,17 @@ nsHTMLButtonElement::PreHandleEvent(nsEv
   nsresult rv = GetDisabled(&bDisabled);
   if (NS_FAILED(rv) || bDisabled) {
     return rv;
   }
 
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
 
   if (formControlFrame) {
-    nsIFrame* formFrame = nsnull;
-    CallQueryInterface(formControlFrame, &formFrame);
-
+    nsIFrame* formFrame = do_QueryFrame(formControlFrame);
     if (formFrame) {
       const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
 
       if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
           uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
         return NS_OK;
     }
   }
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -782,19 +782,17 @@ nsHTMLInputElement::GetValue(nsAString& 
   if (mType == NS_FORM_INPUT_TEXT || mType == NS_FORM_INPUT_PASSWORD) {
     // No need to flush here, if there's no frame created for this
     // input yet, there won't be a value in it (that we don't already
     // have) even if we force it to be created
     nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
 
     PRBool frameOwnsValue = PR_FALSE;
     if (formControlFrame) {
-      nsITextControlFrame* textControlFrame = nsnull;
-      CallQueryInterface(formControlFrame, &textControlFrame);
-
+      nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
       if (textControlFrame) {
         textControlFrame->OwnsValue(&frameOwnsValue);
       } else {
         // We assume if it's not a text control frame that it owns the value
         frameOwnsValue = PR_TRUE;
       }
     }
 
@@ -988,17 +986,17 @@ nsHTMLInputElement::SetValueInternal(con
     nsIFormControlFrame* formControlFrame = textControlFrame;
     if (!textControlFrame) {
       // No need to flush here, if there's no frame at this point we
       // don't need to force creation of one just to tell it about this
       // new value.
       formControlFrame = GetFormControlFrame(PR_FALSE);
 
       if (formControlFrame) {
-        CallQueryInterface(formControlFrame, &textControlFrame);
+        textControlFrame = do_QueryFrame(formControlFrame);
       }
     }
 
     // File frames always own the value (if the frame is there).
     // Text frames have a bit that says whether they own the value.
     PRBool frameOwnsValue = PR_FALSE;
     if (textControlFrame) {
       textControlFrame->OwnsValue(&frameOwnsValue);
@@ -1261,24 +1259,22 @@ nsHTMLInputElement::SetCheckedInternal(P
   //
   // Notify the frame
   //
   nsIFrame* frame = GetPrimaryFrame();
   if (frame) {
     nsPresContext *presContext = GetPresContext();
 
     if (mType == NS_FORM_INPUT_CHECKBOX) {
-      nsICheckboxControlFrame* checkboxFrame = nsnull;
-      CallQueryInterface(frame, &checkboxFrame);
+      nsICheckboxControlFrame* checkboxFrame = do_QueryFrame(frame);
       if (checkboxFrame) {
         checkboxFrame->OnChecked(presContext, aChecked);
       }
     } else if (mType == NS_FORM_INPUT_RADIO) {
-      nsIRadioControlFrame* radioFrame = nsnull;
-      CallQueryInterface(frame, &radioFrame);
+      nsIRadioControlFrame* radioFrame = do_QueryFrame(frame);
       if (radioFrame) {
         radioFrame->OnChecked(presContext, aChecked);
       }
     }
   }
 
   // Notify the document that the CSS :checked pseudoclass for this element
   // has changed state.
@@ -1595,18 +1591,17 @@ nsHTMLInputElement::PreHandleEvent(nsEve
 
   // We must cache type because mType may change during JS event (bug 2369)
   aVisitor.mItemFlags |= static_cast<PRUint8>(mType);
 
   // Fire onchange (if necessary), before we do the blur, bug 357684.
   if (aVisitor.mEvent->message == NS_BLUR_CONTENT) {
     nsIFrame* primaryFrame = GetPrimaryFrame();
     if (primaryFrame) {
-      nsITextControlFrame* textFrame = nsnull;
-      CallQueryInterface(primaryFrame, &textFrame);
+      nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame);
       if (textFrame) {
         textFrame->CheckFireOnChange();
       }
     }
   }
 
   return nsGenericHTMLElement::PreHandleEvent(aVisitor);
 }
@@ -1834,18 +1829,17 @@ nsHTMLInputElement::PostHandleEvent(nsEv
                                                     nsGkAtoms::button,
                                                     eCaseMatters);
               }
             }
 
             if (!isButton) {
               nsIFrame* primaryFrame = GetPrimaryFrame();
               if (primaryFrame) {
-                nsITextControlFrame* textFrame = nsnull;
-                CallQueryInterface(primaryFrame, &textFrame);
+                nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame);
               
                 // Fire onChange (if necessary)
                 if (textFrame) {
                   textFrame->CheckFireOnChange();
                 }
               }
 
               rv = MaybeSubmitForm(aVisitor.mPresContext);
@@ -2207,19 +2201,17 @@ nsHTMLInputElement::GetTextLength(PRInt3
 NS_IMETHODIMP
 nsHTMLInputElement::SetSelectionRange(PRInt32 aSelectionStart,
                                       PRInt32 aSelectionEnd)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -2233,19 +2225,17 @@ nsHTMLInputElement::GetSelectionStart(PR
 
 NS_IMETHODIMP
 nsHTMLInputElement::SetSelectionStart(PRInt32 aSelectionStart)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionStart(aSelectionStart);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -2260,19 +2250,17 @@ nsHTMLInputElement::GetSelectionEnd(PRIn
 
 NS_IMETHODIMP
 nsHTMLInputElement::SetSelectionEnd(PRInt32 aSelectionEnd)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionEnd(aSelectionEnd);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -2299,36 +2287,32 @@ nsHTMLInputElement::GetFiles(nsIDOMFileL
 nsresult
 nsHTMLInputElement::GetSelectionRange(PRInt32* aSelectionStart,
                                       PRInt32* aSelectionEnd)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsHTMLInputElement::GetPhonetic(nsAString& aPhonetic)
 {
   aPhonetic.Truncate(0);
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       textControlFrame->GetPhonetic(aPhonetic);
   }
 
   return NS_OK;
 }
 
 #ifdef ACCESSIBILITY
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -318,21 +318,17 @@ nsHTMLObjectElement::SubmitNamesValues(n
   if (!GetAttr(kNameSpaceID_None, nsGkAtoms::name, name)) {
     // No name, don't submit.
 
     return NS_OK;
   }
 
   nsIFrame* frame = GetPrimaryFrame();
 
-  nsIObjectFrame *objFrame = nsnull;
-  if (frame) {
-    CallQueryInterface(frame, &objFrame);
-  }
-
+  nsIObjectFrame *objFrame = do_QueryFrame(frame);
   if (!objFrame) {
     // No frame, nothing to submit.
 
     return NS_OK;
   }
 
   nsCOMPtr<nsIPluginInstance> pi;
   objFrame->GetPluginInstance(*getter_AddRefs(pi));
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -596,17 +596,17 @@ nsHTMLSelectElement::GetFirstChildOption
 nsISelectControlFrame *
 nsHTMLSelectElement::GetSelectFrame()
 {
   nsIFormControlFrame* form_control_frame = GetFormControlFrame(PR_FALSE);
 
   nsISelectControlFrame *select_frame = nsnull;
 
   if (form_control_frame) {
-    CallQueryInterface(form_control_frame, &select_frame);
+    select_frame = do_QueryFrame(form_control_frame);
   }
 
   return select_frame;
 }
 
 NS_IMETHODIMP
 nsHTMLSelectElement::Add(nsIDOMHTMLElement* aElement,
                          nsIDOMHTMLElement* aBefore)
@@ -1435,19 +1435,17 @@ nsHTMLSelectElement::PreHandleEvent(nsEv
   if (NS_FAILED(rv) || disabled) {
     return rv;
   }
 
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
   nsIFrame* formFrame = nsnull;
 
   if (formControlFrame &&
-      NS_SUCCEEDED(CallQueryInterface(formControlFrame, &formFrame)) &&
-      formFrame)
-  {
+      (formFrame = do_QueryFrame(formControlFrame))) {
     const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
 
     if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
         uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
       return NS_OK;
     }
   }
 
@@ -1697,24 +1695,22 @@ nsHTMLSelectElement::DispatchDOMEvent(co
 }
 
 void nsHTMLSelectElement::DispatchContentReset() {
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
   if (formControlFrame) {
     // Only dispatch content reset notification if this is a list control
     // frame or combo box control frame.
     if (IsCombobox()) {
-      nsIComboboxControlFrame* comboFrame = nsnull;
-      CallQueryInterface(formControlFrame, &comboFrame);
+      nsIComboboxControlFrame* comboFrame = do_QueryFrame(formControlFrame);
       if (comboFrame) {
         comboFrame->OnContentReset();
       }
     } else {
-      nsIListControlFrame* listFrame = nsnull;
-      CallQueryInterface(formControlFrame, &listFrame);
+      nsIListControlFrame* listFrame = do_QueryFrame(formControlFrame);
       if (listFrame) {
         listFrame->OnContentReset();
       }
     }
   }
 }
 
 static void
--- a/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -405,17 +405,17 @@ nsHTMLTextAreaElement::GetValueInternal(
 {
   // Get the frame.
   // No need to flush here, if there is no frame yet for this textarea
   // there won't be a value in it we don't already have even if we
   // force the frame to be created.
   nsIFrame* primaryFrame = GetPrimaryFrame();
   nsITextControlFrame* textControlFrame = nsnull;
   if (primaryFrame) {
-    CallQueryInterface(primaryFrame, &textControlFrame);
+    textControlFrame = do_QueryFrame(primaryFrame);
   }
 
   // If the frame exists and owns the value, get it from the frame.  Otherwise
   // get it from content.
   PRBool frameOwnsValue = PR_FALSE;
   if (textControlFrame) {
     textControlFrame->OwnsValue(&frameOwnsValue);
   }
@@ -448,17 +448,17 @@ nsHTMLTextAreaElement::SetValueInternal(
   nsITextControlFrame* textControlFrame = aFrame;
   nsIFormControlFrame* formControlFrame = textControlFrame;
   if (!textControlFrame) {
     // No need to flush here, if there is no frame for this yet forcing
     // creation of one will not do us any good
     formControlFrame = GetFormControlFrame(PR_FALSE);
 
     if (formControlFrame) {
-      CallQueryInterface(formControlFrame, &textControlFrame);
+      textControlFrame = do_QueryFrame(formControlFrame);
     }
   }
 
   PRBool frameOwnsValue = PR_FALSE;
   if (textControlFrame) {
     textControlFrame->OwnsValue(&frameOwnsValue);
   }
   if (frameOwnsValue) {
@@ -588,18 +588,17 @@ nsHTMLTextAreaElement::PreHandleEvent(ns
   if (NS_FAILED(rv) || disabled) {
     return rv;
   }
 
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
   nsIFrame* formFrame = nsnull;
 
   if (formControlFrame &&
-      NS_SUCCEEDED(CallQueryInterface(formControlFrame, &formFrame)) &&
-      formFrame) {
+      (formFrame = do_QueryFrame(formControlFrame))) {
     const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
 
     if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
         uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
       return NS_OK;
     }
   }
 
@@ -623,18 +622,17 @@ nsHTMLTextAreaElement::PreHandleEvent(ns
         nsMouseEvent::eMiddleButton) {
     aVisitor.mEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH;
   }
 
   // Fire onchange (if necessary), before we do the blur, bug 370521.
   if (aVisitor.mEvent->message == NS_BLUR_CONTENT) {
     nsIFrame* primaryFrame = GetPrimaryFrame();
     if (primaryFrame) {
-      nsITextControlFrame* textFrame = nsnull;
-      CallQueryInterface(primaryFrame, &textFrame);
+      nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame);
       if (textFrame) {
         textFrame->CheckFireOnChange();
       }
     }
   }
 
   return nsGenericHTMLElement::PreHandleEvent(aVisitor);
 }
@@ -725,19 +723,17 @@ nsHTMLTextAreaElement::GetSelectionStart
 
 NS_IMETHODIMP
 nsHTMLTextAreaElement::SetSelectionStart(PRInt32 aSelectionStart)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame){
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionStart(aSelectionStart);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -751,54 +747,48 @@ nsHTMLTextAreaElement::GetSelectionEnd(P
 
 NS_IMETHODIMP
 nsHTMLTextAreaElement::SetSelectionEnd(PRInt32 aSelectionEnd)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionEnd(aSelectionEnd);
   }
 
   return rv;
 }
 
 nsresult
 nsHTMLTextAreaElement::GetSelectionRange(PRInt32* aSelectionStart,
                                       PRInt32* aSelectionEnd)
 {
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsHTMLTextAreaElement::SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd)
 { 
   nsresult rv = NS_ERROR_FAILURE;
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);
 
   if (formControlFrame) {
-    nsITextControlFrame* textControlFrame = nsnull;
-    CallQueryInterface(formControlFrame, &textControlFrame);
-
+    nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
     if (textControlFrame)
       rv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd);
   }
 
   return rv;
 } 
 
 nsresult
--- a/content/html/document/src/nsPluginDocument.cpp
+++ b/content/html/document/src/nsPluginDocument.cpp
@@ -139,18 +139,17 @@ nsPluginStreamListener::SetupPlugin()
   shell->FlushPendingNotifications(Flush_Layout);
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(embed);
   if (!frame) {
     mPluginDoc->AllowNormalInstantiation();
     return NS_OK;
   }
 
-  nsIObjectFrame* objFrame;
-  CallQueryInterface(frame, &objFrame);
+  nsIObjectFrame* objFrame = do_QueryFrame(frame);
   if (!objFrame) {
     mPluginDoc->AllowNormalInstantiation();
     return NS_ERROR_UNEXPECTED;
   }
 
   nsresult rv = objFrame->Instantiate(mPluginDoc->GetType().get(),
                                       mDocument->nsIDocument::GetDocumentURI());
   if (NS_FAILED(rv)) {
@@ -337,19 +336,17 @@ nsPluginDocument::Print()
   nsIPresShell *shell = GetPrimaryShell();
   if (!shell) {
     return NS_OK;
   }
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(mPluginContent);
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
-  nsIObjectFrame* objectFrame = nsnull;
-  CallQueryInterface(frame, &objectFrame);
-
+  nsIObjectFrame* objectFrame = do_QueryFrame(frame);
   if (objectFrame) {
     nsCOMPtr<nsIPluginInstance> pi;
     objectFrame->GetPluginInstance(*getter_AddRefs(pi));
 
     if (pi) {
       nsPluginPrint npprint;
       npprint.mode = nsPluginMode_Full;
       npprint.print.fullPrint.pluginPrinted = PR_FALSE;
--- a/content/svg/content/src/nsISVGTextContentMetrics.h
+++ b/content/svg/content/src/nsISVGTextContentMetrics.h
@@ -34,38 +34,32 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_ISVGTEXTCONTENTMETRICS_H__
 #define __NS_ISVGTEXTCONTENTMETRICS_H__
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
+
 class nsIDOMSVGRect;
 class nsIDOMSVGPoint;
 
 ////////////////////////////////////////////////////////////////////////
 // nsISVGTextContentMetrics
 
-// {CBF0A774-4171-4112-BD9A-F49BEFC0CE18}
-#define NS_ISVGTEXTCONTENTMETRICS_IID \
-{ 0xcbf0a774, 0x4171, 0x4112, { 0xbd, 0x9a, 0xf4, 0x9b, 0xef, 0xc0, 0xce, 0x18 } }
-
-class nsISVGTextContentMetrics : public nsISupports
+class nsISVGTextContentMetrics
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGTEXTCONTENTMETRICS_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGTextContentMetrics)
   
   NS_IMETHOD GetNumberOfChars(PRInt32 *_retval)=0;
   NS_IMETHOD GetComputedTextLength(float *_retval)=0;
   NS_IMETHOD GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)=0;
   NS_IMETHOD GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)=0;
   NS_IMETHOD GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)=0;
   NS_IMETHOD GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)=0;
   NS_IMETHOD GetRotationOfChar(PRUint32 charnum, float *_retval)=0;
   NS_IMETHOD GetCharNumAtPosition(nsIDOMSVGPoint *point, PRInt32 *_retval)=0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGTextContentMetrics,
-                              NS_ISVGTEXTCONTENTMETRICS_IID)
-
 #endif // __NS_ISVGTEXTCONTENTMETRICS_H__
--- a/content/svg/content/src/nsISVGValue.h
+++ b/content/svg/content/src/nsISVGValue.h
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #ifndef __NS_ISVGVALUE_H__
 #define __NS_ISVGVALUE_H__
 
 #include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsString.h"
 
 class nsISVGValueObserver;
 
 ////////////////////////////////////////////////////////////////////////
 // nsISVGValue: private interface for svg values
 
 /* This interface is implemented by all value-types (e.g. coords,
@@ -67,16 +68,17 @@ class nsISVGValue : public nsISupports
 public:
   enum modificationType {
     mod_other = 0,
     mod_context,
     mod_die
   };
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGVALUE_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGValue)
 
   NS_IMETHOD SetValueString(const nsAString& aValue)=0;
   NS_IMETHOD GetValueString(nsAString& aValue)=0;
 
   NS_IMETHOD AddObserver(nsISVGValueObserver* observer)=0;
   NS_IMETHOD RemoveObserver(nsISVGValueObserver* observer)=0;
 
   NS_IMETHOD BeginBatchUpdate()=0;
--- a/content/svg/content/src/nsSVGGraphicElement.cpp
+++ b/content/svg/content/src/nsSVGGraphicElement.cpp
@@ -89,18 +89,17 @@ NS_IMETHODIMP nsSVGGraphicElement::GetBB
 {
   *_retval = nsnull;
 
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
 
   if (!frame || (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD))
     return NS_ERROR_FAILURE;
 
-  nsISVGChildFrame* svgframe;
-  CallQueryInterface(frame, &svgframe);
+  nsISVGChildFrame* svgframe = do_QueryFrame(frame);
   NS_ASSERTION(svgframe, "wrong frame type");
   if (svgframe) {
     svgframe->SetMatrixPropagation(PR_FALSE);
     svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
                                nsISVGChildFrame::TRANSFORM_CHANGED);
     nsresult rv = svgframe->GetBBox(_retval);
     svgframe->SetMatrixPropagation(PR_TRUE);
     svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
--- a/content/svg/content/src/nsSVGPatternElement.cpp
+++ b/content/svg/content/src/nsSVGPatternElement.cpp
@@ -271,18 +271,17 @@ nsSVGPatternElement::GetStringInfo()
 // nsIMutationObserver methods
 
 void
 nsSVGPatternElement::PushUpdate()
 {
   nsIFrame *frame = GetPrimaryFrame();
 
   if (frame) {
-    nsISVGValue *value = nsnull;
-    CallQueryInterface(frame, &value);
+    nsISVGValue *value = do_QueryFrame(frame);
     if (value) {
       value->BeginBatchUpdate();
       value->EndBatchUpdate();
     }
   }
 }
 
 void
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -360,18 +360,17 @@ nsSVGSVGElement::SuspendRedraw(PRUint32 
   // in a binding and svg children are inserted underneath it using
   // <children/>. If the svg children then call suspendRedraw, the
   // above function call fails although the svg:svg's frame has been
   // build. Strange...
   
   NS_ASSERTION(frame, "suspending redraw w/o frame");
 #endif
   if (frame) {
-    nsISVGSVGFrame* svgframe;
-    CallQueryInterface(frame, &svgframe);
+    nsISVGSVGFrame* svgframe = do_QueryFrame(frame);
     NS_ASSERTION(svgframe, "wrong frame type");
     if (svgframe) {
       svgframe->SuspendRedraw();
     }
   }
   
   return NS_OK;
 }
@@ -399,18 +398,17 @@ nsSVGSVGElement::UnsuspendRedrawAll()
 {
   mRedrawSuspendCount = 0;
 
   nsIFrame* frame = GetPrimaryFrame();
 #ifdef DEBUG
   NS_ASSERTION(frame, "unsuspending redraw w/o frame");
 #endif
   if (frame) {
-    nsISVGSVGFrame* svgframe;
-    CallQueryInterface(frame, &svgframe);
+    nsISVGSVGFrame* svgframe = do_QueryFrame(frame);
     NS_ASSERTION(svgframe, "wrong frame type");
     if (svgframe) {
       svgframe->UnsuspendRedraw();
     }
   }  
   return NS_OK;
 }
 
@@ -653,18 +651,17 @@ nsSVGSVGElement::GetBBox(nsIDOMSVGRect *
 {
   *_retval = nsnull;
 
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
 
   if (!frame || (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD))
     return NS_ERROR_FAILURE;
 
-  nsISVGChildFrame* svgframe;
-  CallQueryInterface(frame, &svgframe);
+  nsISVGChildFrame* svgframe = do_QueryFrame(frame);
   if (svgframe) {
     svgframe->SetMatrixPropagation(PR_FALSE);
     svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
                                nsISVGChildFrame::TRANSFORM_CHANGED);
     nsresult rv = svgframe->GetBBox(_retval);
     svgframe->SetMatrixPropagation(PR_TRUE);
     svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
                                nsISVGChildFrame::TRANSFORM_CHANGED);
@@ -1292,18 +1289,17 @@ nsSVGSVGElement::InvalidateTransformNoti
 {
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) return;
   nsIPresShell* presShell = doc->GetPrimaryShell();
   if (!presShell) return;
 
   nsIFrame* frame = presShell->GetPrimaryFrameFor(this);
   if (frame) {
-    nsISVGSVGFrame* svgframe;
-    CallQueryInterface(frame, &svgframe);
+    nsISVGSVGFrame* svgframe = do_QueryFrame(frame);
     if (svgframe) {
       svgframe->NotifyViewportChange();
     }
 #ifdef DEBUG
     else {
       // XXX we get here during nsSVGOuterSVGFrame::Init() since that
       // function is called before the presshell association between us
       // and our frame is established.
--- a/content/svg/content/src/nsSVGSwitchElement.cpp
+++ b/content/svg/content/src/nsSVGSwitchElement.cpp
@@ -92,19 +92,17 @@ nsSVGSwitchElement::MaybeInvalidate()
     if (NS_SVG_PassesConditionalProcessingTests(child)) {
 
       if (mActiveChild == child) {
         return;
       }
 
       nsIFrame *frame = GetPrimaryFrame();
       if (frame) {
-        nsISVGChildFrame* svgFrame = nsnull;
-
-        CallQueryInterface(frame, &svgFrame);
+        nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
         if (svgFrame) {
           nsSVGUtils::UpdateGraphic(svgFrame);
         }
       }
       return;
     }
   }
 }
--- a/content/svg/content/src/nsSVGTSpanElement.cpp
+++ b/content/svg/content/src/nsSVGTSpanElement.cpp
@@ -77,17 +77,17 @@ public:
   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
 protected:
   // nsSVGElement overrides
   virtual PRBool IsEventName(nsIAtom* aName);
 
-  already_AddRefed<nsISVGTextContentMetrics> GetTextContentMetrics();
+  nsISVGTextContentMetrics* GetTextContentMetrics();
 
   // nsIDOMSVGTextPositioning properties:
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mX;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mY;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdX;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdY;
 
 };
@@ -248,103 +248,103 @@ NS_IMETHODIMP nsSVGTSpanElement::GetLeng
 {
   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetLengthAdjust");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* long getNumberOfChars (); */
 NS_IMETHODIMP nsSVGTSpanElement::GetNumberOfChars(PRInt32 *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetNumberOfChars(_retval);
 
   *_retval = 0;
   return NS_OK;
 }
 
 /* float getComputedTextLength (); */
 NS_IMETHODIMP nsSVGTSpanElement::GetComputedTextLength(float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetComputedTextLength(_retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
 NS_IMETHODIMP nsSVGTSpanElement::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetSubStringLength(charnum, nchars, _retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* nsIDOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTSpanElement::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetStartPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTSpanElement::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetEndPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTSpanElement::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetExtentOfChar(charnum, _retval);
 }
 
 /* float getRotationOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTSpanElement::GetRotationOfChar(PRUint32 charnum, float *_retval)
 {
   *_retval = 0.0;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetRotationOfChar(charnum, _retval);
 }
 
 /* long getCharNumAtPosition (in nsIDOMSVGPoint point); */
 NS_IMETHODIMP nsSVGTSpanElement::GetCharNumAtPosition(nsIDOMSVGPoint *point,
                                                       PRInt32 *_retval)
 {
   // null check when implementing - this method can be used by scripts!
   if (!point)
     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetCharNumAtPosition(point, _retval);
 
   *_retval = -1;
   return NS_OK;
 }
 
@@ -380,21 +380,20 @@ PRBool
 nsSVGTSpanElement::IsEventName(nsIAtom* aName)
 {
   return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
 }
 
 //----------------------------------------------------------------------
 // implementation helpers:
 
-already_AddRefed<nsISVGTextContentMetrics>
+nsISVGTextContentMetrics*
 nsSVGTSpanElement::GetTextContentMetrics()
 {
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
 
   if (!frame) {
     return nsnull;
   }
   
-  nsISVGTextContentMetrics* metrics;
-  CallQueryInterface(frame, &metrics);
+  nsISVGTextContentMetrics* metrics = do_QueryFrame(frame);
   return metrics;
 }
--- a/content/svg/content/src/nsSVGTextElement.cpp
+++ b/content/svg/content/src/nsSVGTextElement.cpp
@@ -75,17 +75,17 @@ public:
 
   // nsIContent interface
   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
 protected:
 
-  already_AddRefed<nsISVGTextContentMetrics> GetTextContentMetrics();
+  nsISVGTextContentMetrics* GetTextContentMetrics();
   
   // nsIDOMSVGTextPositioning properties:
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mX;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mY;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdX;
   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdY;
 
 };
@@ -245,102 +245,102 @@ NS_IMETHODIMP nsSVGTextElement::GetLengt
 {
   NS_NOTYETIMPLEMENTED("nsSVGTextElement::GetLengthAdjust");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* long getNumberOfChars (); */
 NS_IMETHODIMP nsSVGTextElement::GetNumberOfChars(PRInt32 *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetNumberOfChars(_retval);
 
   *_retval = 0;
   return NS_OK;
 }
 
 /* float getComputedTextLength (); */
 NS_IMETHODIMP nsSVGTextElement::GetComputedTextLength(float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetComputedTextLength(_retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
 NS_IMETHODIMP nsSVGTextElement::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetSubStringLength(charnum, nchars, _retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* nsIDOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextElement::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetStartPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextElement::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetEndPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextElement::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetExtentOfChar(charnum, _retval);
 }
 
 /* float getRotationOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextElement::GetRotationOfChar(PRUint32 charnum, float *_retval)
 {
   *_retval = 0.0;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetRotationOfChar(charnum, _retval);
 }
 
 /* long getCharNumAtPosition (in nsIDOMSVGPoint point); */
 NS_IMETHODIMP nsSVGTextElement::GetCharNumAtPosition(nsIDOMSVGPoint *point, PRInt32 *_retval)
 {
   // null check when implementing - this method can be used by scripts!
   if (!point)
     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetCharNumAtPosition(point, _retval);
 
   *_retval = -1;
   return NS_OK;
 }
 
@@ -364,21 +364,20 @@ nsSVGTextElement::IsAttributeMapped(cons
 
   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
     nsSVGTextElementBase::IsAttributeMapped(name);
 }
 
 //----------------------------------------------------------------------
 // implementation helpers:
 
-already_AddRefed<nsISVGTextContentMetrics>
+nsISVGTextContentMetrics*
 nsSVGTextElement::GetTextContentMetrics()
 {
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
 
   if (!frame) {
     return nsnull;
   }
   
-  nsISVGTextContentMetrics* metrics;
-  CallQueryInterface(frame, &metrics);
+  nsISVGTextContentMetrics* metrics = do_QueryFrame(frame);
   return metrics;
 }
--- a/content/svg/content/src/nsSVGTextPathElement.cpp
+++ b/content/svg/content/src/nsSVGTextPathElement.cpp
@@ -150,103 +150,103 @@ NS_IMETHODIMP nsSVGTextPathElement::GetL
 {
   NS_NOTYETIMPLEMENTED("nsSVGTextPathElement::GetLengthAdjust!");
   return NS_ERROR_UNEXPECTED;
 }
 
 /* long getNumberOfChars (); */
 NS_IMETHODIMP nsSVGTextPathElement::GetNumberOfChars(PRInt32 *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetNumberOfChars(_retval);
 
   *_retval = 0;
   return NS_OK;
 }
 
 /* float getComputedTextLength (); */
 NS_IMETHODIMP nsSVGTextPathElement::GetComputedTextLength(float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetComputedTextLength(_retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
 NS_IMETHODIMP nsSVGTextPathElement::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
 {
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetSubStringLength(charnum, nchars, _retval);
 
   *_retval = 0.0;
   return NS_OK;
 }
 
 /* nsIDOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextPathElement::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetStartPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextPathElement::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetEndPositionOfChar(charnum, _retval);
 }
 
 /* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextPathElement::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
 {
   *_retval = nsnull;
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetExtentOfChar(charnum, _retval);
 }
 
 /* float getRotationOfChar (in unsigned long charnum); */
 NS_IMETHODIMP nsSVGTextPathElement::GetRotationOfChar(PRUint32 charnum, float *_retval)
 {
   *_retval = 0.0;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (!metrics) return NS_ERROR_FAILURE;
 
   return metrics->GetRotationOfChar(charnum, _retval);
 }
 
 /* long getCharNumAtPosition (in nsIDOMSVGPoint point); */
 NS_IMETHODIMP nsSVGTextPathElement::GetCharNumAtPosition(nsIDOMSVGPoint *point,
                                                          PRInt32 *_retval)
 {
   // null check when implementing - this method can be used by scripts!
   if (!point)
     return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
 
-  nsCOMPtr<nsISVGTextContentMetrics> metrics = GetTextContentMetrics();
+  nsISVGTextContentMetrics *metrics = GetTextContentMetrics();
 
   if (metrics)
     return metrics->GetCharNumAtPosition(point, _retval);
 
   *_retval = -1;
   return NS_OK;
 }
 
@@ -302,21 +302,20 @@ nsSVGElement::StringAttributesInfo
 nsSVGTextPathElement::GetStringInfo()
 {
   return StringAttributesInfo(mStringAttributes, sStringInfo,
                               NS_ARRAY_LENGTH(sStringInfo));
 }
 //----------------------------------------------------------------------
 // implementation helpers:
 
-already_AddRefed<nsISVGTextContentMetrics>
+nsISVGTextContentMetrics*
 nsSVGTextPathElement::GetTextContentMetrics()
 {
   nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
 
   if (!frame) {
     return nsnull;
   }
   
-  nsISVGTextContentMetrics* metrics;
-  CallQueryInterface(frame, &metrics);
+  nsISVGTextContentMetrics* metrics = do_QueryFrame(frame);
   return metrics;
 }
--- a/content/svg/content/src/nsSVGTextPathElement.h
+++ b/content/svg/content/src/nsSVGTextPathElement.h
@@ -77,17 +77,17 @@ public:
 protected:
 
   virtual LengthAttributesInfo GetLengthInfo();
   virtual EnumAttributesInfo GetEnumInfo();
   virtual StringAttributesInfo GetStringInfo();
 
   virtual PRBool IsEventName(nsIAtom* aName);
 
-  already_AddRefed<nsISVGTextContentMetrics> GetTextContentMetrics();
+  nsISVGTextContentMetrics* GetTextContentMetrics();
 
   enum { STARTOFFSET };
   nsSVGLength2 mLengthAttributes[1];
   static LengthInfo sLengthInfo[1];
 
   enum { METHOD, SPACING };
   nsSVGEnum mEnumAttributes[2];
   static nsSVGEnumMapping sMethodMap[];
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4340,18 +4340,17 @@ nsDocShell::GetScrollbarVisibility(PRBoo
         return NS_ERROR_FAILURE;
 
     // We should now call nsLayoutUtils::GetScrollableFrameFor,
     // but we can't because of stupid linkage!
     nsIFrame* scrollFrame =
         static_cast<nsIFrame*>(scrollView->View()->GetParent()->GetClientData());
     if (!scrollFrame)
         return NS_ERROR_FAILURE;
-    nsIScrollableFrame* scrollable = nsnull;
-    CallQueryInterface(scrollFrame, &scrollable);
+    nsIScrollableFrame* scrollable = do_QueryFrame(scrollFrame);
     if (!scrollable)
         return NS_ERROR_FAILURE;
 
     nsMargin scrollbars = scrollable->GetActualScrollbarSizes();
     if (verticalVisible)
         *verticalVisible = scrollbars.left != 0 || scrollbars.right != 0;
     if (horizontalVisible)
         *horizontalVisible = scrollbars.top != 0 || scrollbars.bottom != 0;
@@ -9259,18 +9258,18 @@ nsDocShell::SetHasFocus(PRBool aHasFocus
 
   return NS_OK;
 }
 
 // Find an nsICanvasFrame under aFrame.  Only search the principal
 // child lists.  aFrame must be non-null.
 static nsICanvasFrame* FindCanvasFrame(nsIFrame* aFrame)
 {
-    nsICanvasFrame* canvasFrame;
-    if (NS_SUCCEEDED(CallQueryInterface(aFrame, &canvasFrame))) {
+    nsICanvasFrame* canvasFrame = do_QueryFrame(aFrame);
+    if (canvasFrame) {
         return canvasFrame;
     }
 
     nsIFrame* kid = aFrame->GetFirstChild(nsnull);
     while (kid) {
         canvasFrame = FindCanvasFrame(kid);
         if (canvasFrame) {
             return canvasFrame;
@@ -9297,18 +9296,18 @@ nsDocShell::SetCanvasHasFocus(PRBool aCa
   if (!doc) return NS_ERROR_FAILURE;
 
   nsIContent *rootContent = doc->GetRootContent();
   if (rootContent) {
       nsIFrame* frame = presShell->GetPrimaryFrameFor(rootContent);
       if (frame) {
           frame = frame->GetParent();
           if (frame) {
-              nsICanvasFrame* canvasFrame;
-              if (NS_SUCCEEDED(CallQueryInterface(frame, &canvasFrame))) {
+              nsICanvasFrame* canvasFrame = do_QueryFrame(frame);
+              if (canvasFrame) {
                   return canvasFrame->SetHasFocus(aCanvasHasFocus);
               }
           }
       }
   } else {
       // Look for the frame the hard way
       nsIFrame* frame = presShell->GetRootFrame();
       if (frame) {
--- a/editor/libeditor/html/nsTableEditor.cpp
+++ b/editor/libeditor/html/nsTableEditor.cpp
@@ -2725,19 +2725,17 @@ nsHTMLEditor::GetCellIndexes(nsIDOMEleme
   if (!ps) return NS_ERROR_NOT_INITIALIZED;
 
   nsCOMPtr<nsIContent> nodeAsContent( do_QueryInterface(aCell) );
   if (!nodeAsContent) return NS_ERROR_FAILURE;
   // frames are not ref counted, so don't use an nsCOMPtr
   nsIFrame *layoutObject = ps->GetPrimaryFrameFor(nodeAsContent);
   if (!layoutObject)  return NS_ERROR_FAILURE;
 
-  nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted
-  res = layoutObject->QueryInterface(NS_GET_IID(nsITableCellLayout), (void**)(&cellLayoutObject));
-  if (NS_FAILED(res)) return res;
+  nsITableCellLayout *cellLayoutObject = do_QueryFrame(layoutObject);
   if (!cellLayoutObject)  return NS_ERROR_FAILURE;
   return cellLayoutObject->GetCellIndexes(*aRowIndex, *aColIndex);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject)
 {
   *tableLayoutObject=nsnull;
@@ -2747,18 +2745,18 @@ nsHTMLEditor::GetTableLayoutObject(nsIDO
   if (!ps) return NS_ERROR_NOT_INITIALIZED;
 
   nsCOMPtr<nsIContent> nodeAsContent( do_QueryInterface(aTable) );
   if (!nodeAsContent) return NS_ERROR_FAILURE;
   // frames are not ref counted, so don't use an nsCOMPtr
   nsIFrame *layoutObject = ps->GetPrimaryFrameFor(nodeAsContent);
   if (!layoutObject)  return NS_ERROR_FAILURE;
 
-  return layoutObject->QueryInterface(NS_GET_IID(nsITableLayout), 
-                                      (void**)(tableLayoutObject)); 
+  *tableLayoutObject = do_QueryFrame(layoutObject);
+  return *tableLayoutObject ? NS_OK : NS_NOINTERFACE;
 }
 
 //Return actual number of cells (a cell with colspan > 1 counts as just 1)
 PRBool nsHTMLEditor::GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex)
 {
   PRInt32 cellCount = 0;
   nsCOMPtr<nsIDOMElement> cell;
   PRInt32 colIndex = 0;
--- a/embedding/components/find/src/nsFind.cpp
+++ b/embedding/components/find/src/nsFind.cpp
@@ -373,18 +373,17 @@ nsFindContentIterator::SetupInnerIterato
   nsIPresShell* shell = doc ? doc->GetPrimaryShell() : nsnull;
   if (!shell)
     return;
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(aContent);
   if (!frame)
     return;
 
-  nsITextControlFrame* tcFrame = nsnull;
-  CallQueryInterface(frame, &tcFrame);
+  nsITextControlFrame* tcFrame = do_QueryFrame(frame);
   if (!tcFrame)
     return;
 
   nsCOMPtr<nsIEditor> editor;
   tcFrame->GetEditor(getter_AddRefs(editor));
   if (!editor)
     return;
 
--- a/embedding/components/find/src/nsWebBrowserFind.cpp
+++ b/embedding/components/find/src/nsWebBrowserFind.cpp
@@ -435,17 +435,17 @@ void nsWebBrowserFind::SetSelectionAndSc
   // since the match could be an anonymous textnode inside a
   // <textarea> or text <input>, we need to get the outer frame
   nsITextControlFrame *tcFrame = nsnull;
   for ( ; content; content = content->GetParent()) {
     if (!content->IsInNativeAnonymousSubtree()) {
       nsIFrame* f = presShell->GetPrimaryFrameFor(content);
       if (!f)
         return;
-      CallQueryInterface(f, &tcFrame);
+      tcFrame = do_QueryFrame(f);
       break;
     }
   }
 
   nsCOMPtr<nsISelection> selection;
 
   selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
   selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -48,18 +48,16 @@
 #include "nsFrameManager.h"
 #include "nsBidiFrames.h"
 #include "nsBidiUtils.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsHTMLContainerFrame.h"
 #include "nsInlineFrame.h"
 #include "nsPlaceholderFrame.h"
 
-static NS_DEFINE_IID(kInlineFrameCID, NS_INLINE_FRAME_CID);
-
 static const PRUnichar kSpace            = 0x0020;
 static const PRUnichar kLineSeparator    = 0x2028;
 static const PRUnichar kObjectSubstitute = 0xFFFC;
 static const PRUnichar kLRE              = 0x202A;
 static const PRUnichar kRLE              = 0x202B;
 static const PRUnichar kLRO              = 0x202D;
 static const PRUnichar kRLO              = 0x202E;
 static const PRUnichar kPDF              = 0x202C;
@@ -847,19 +845,17 @@ nsBidiPresUtils::RepositionFrame(nsIFram
     return;
 
   PRBool isLeftMost, isRightMost;
   IsLeftOrRightMost(aFrame,
                     aContinuationStates,
                     isLeftMost /* out */,
                     isRightMost /* out */);
 
-  nsIFrame* testFrame;
-  aFrame->QueryInterface(kInlineFrameCID, (void**)&testFrame);
-
+  nsInlineFrame* testFrame = do_QueryFrame(aFrame);
   if (testFrame) {
     aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET);
 
     if (isLeftMost)
       aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
     else
       aFrame->RemoveStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
 
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -4513,18 +4513,17 @@ nsCSSFrameConstructor::ConstructRootFram
       rootPseudoStyle = BeginBuildingScrollFrame( state,
                                                   aDocElement,
                                                   styleContext,
                                                   viewportFrame,
                                                   rootPseudo,
                                                   PR_TRUE,
                                                   newFrame);
 
-      nsIScrollableFrame* scrollable;
-      CallQueryInterface(newFrame, &scrollable);
+      nsIScrollableFrame* scrollable = do_QueryFrame(newFrame);
       NS_ENSURE_TRUE(scrollable, NS_ERROR_FAILURE);
 
       nsIScrollableView* scrollableView = scrollable->GetScrollableView();
       NS_ENSURE_TRUE(scrollableView, NS_ERROR_FAILURE);
 
       viewManager->SetRootScrollableView(scrollableView);
       parentFrame = newFrame;
 
@@ -4669,18 +4668,18 @@ nsCSSFrameConstructor::ConstructRadioCon
   if (NS_UNLIKELY(!*aNewFrame)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   nsRefPtr<nsStyleContext> radioStyle;
   radioStyle = mPresShell->StyleSet()->ResolvePseudoStyleFor(aContent,
                                                              nsCSSAnonBoxes::radio,
                                                              aStyleContext);
-  nsIRadioControlFrame* radio = nsnull;
-  if (*aNewFrame && NS_SUCCEEDED(CallQueryInterface(*aNewFrame, &radio))) {
+  nsIRadioControlFrame* radio = do_QueryFrame(*aNewFrame);
+  if (radio) {
     radio->SetRadioButtonFaceStyleContext(radioStyle);
   }
   return NS_OK;
 }
 
 nsresult
 nsCSSFrameConstructor::ConstructCheckboxControlFrame(nsIFrame**      aNewFrame,
                                                      nsIContent*     aContent,
@@ -4690,18 +4689,18 @@ nsCSSFrameConstructor::ConstructCheckbox
   if (NS_UNLIKELY(!*aNewFrame)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   nsRefPtr<nsStyleContext> checkboxStyle;
   checkboxStyle = mPresShell->StyleSet()->ResolvePseudoStyleFor(aContent,
                                                                 nsCSSAnonBoxes::check, 
                                                                 aStyleContext);
-  nsICheckboxControlFrame* checkbox = nsnull;
-  if (*aNewFrame && NS_SUCCEEDED(CallQueryInterface(*aNewFrame, &checkbox))) {
+  nsICheckboxControlFrame* checkbox = do_QueryFrame(*aNewFrame);
+  if (checkbox) {
     checkbox->SetCheckboxFaceStyleContext(checkboxStyle);
   }
   return NS_OK;
 }
 
 nsresult
 nsCSSFrameConstructor::ConstructButtonFrame(nsFrameConstructorState& aState,
                                             nsIContent*              aContent,
@@ -4768,18 +4767,17 @@ nsCSSFrameConstructor::ConstructButtonFr
     buttonFrame->Destroy();
     return rv;
   }
 
   PRBool isLeaf = buttonFrame->IsLeaf();
 #ifdef DEBUG
   // Make sure that we're an anonymous content creator exactly when we're a
   // leaf
-  nsIAnonymousContentCreator* creator = nsnull;
-  CallQueryInterface(buttonFrame, &creator);
+  nsIAnonymousContentCreator* creator = do_QueryFrame(buttonFrame);
   NS_ASSERTION(!creator == !isLeaf,
                "Should be creator exactly when we're a leaf");
 #endif
   
   if (!isLeaf) { 
     // Process children
     nsFrameConstructorSaveState absoluteSaveState;
     nsFrameItems                childItems;
@@ -4787,18 +4785,17 @@ nsCSSFrameConstructor::ConstructButtonFr
     if (aStyleDisplay->IsPositioned()) {
       // The area frame becomes a container for child frames that are
       // absolutely positioned
       aState.PushAbsoluteContainingBlock(blockFrame, absoluteSaveState);
     }
 
 #ifdef DEBUG
     // Make sure that anonymous child creation will have no effect in this case
-    nsIAnonymousContentCreator* creator = nsnull;
-    CallQueryInterface(blockFrame, &creator);
+    nsIAnonymousContentCreator* creator = do_QueryFrame(blockFrame);
     NS_ASSERTION(!creator, "Shouldn't be an anonymous content creator!");
 #endif
 
     rv = ProcessChildren(aState, aContent, aStyleContext, blockFrame, PR_TRUE,
                          childItems,
                          buttonFrame->GetStyleDisplay()->IsBlockOutside());
     if (NS_FAILED(rv)) return rv;
   
@@ -4874,34 +4871,32 @@ nsCSSFrameConstructor::ConstructSelectFr
                            aParentFrame);
       if (NS_FAILED(rv)) {
         return rv;
       }
       
       ///////////////////////////////////////////////////////////////////
       // Combobox - Old Native Implementation
       ///////////////////////////////////////////////////////////////////
-      nsIComboboxControlFrame* comboBox = nsnull;
-      CallQueryInterface(comboboxFrame, &comboBox);
+      nsIComboboxControlFrame* comboBox = do_QueryFrame(comboboxFrame);
       NS_ASSERTION(comboBox, "NS_NewComboboxControlFrame returned frame that "
                              "doesn't implement nsIComboboxControlFrame");
 
         // Resolve pseudo element style for the dropdown list
       nsRefPtr<nsStyleContext> listStyle;
       listStyle = mPresShell->StyleSet()->ResolvePseudoStyleFor(aContent,
                                                                 nsCSSAnonBoxes::dropDownList, 
                                                                 aStyleContext);
 
         // Create a listbox
       nsIFrame* listFrame = NS_NewListControlFrame(mPresShell, listStyle);
 
         // Notify the listbox that it is being used as a dropdown list.
-      nsIListControlFrame * listControlFrame;
-      rv = CallQueryInterface(listFrame, &listControlFrame);
-      if (NS_SUCCEEDED(rv)) {
+      nsIListControlFrame * listControlFrame = do_QueryFrame(listFrame);
+      if (listControlFrame) {
         listControlFrame->SetComboboxFrame(comboboxFrame);
       }
          // Notify combobox that it should use the listbox as it's popup
       comboBox->SetDropDown(listFrame);
 
       NS_ASSERTION(!listStyle->GetStyleDisplay()->IsPositioned(),
                    "Ended up with positioned dropdown list somehow.");
       NS_ASSERTION(!listStyle->GetStyleDisplay()->IsFloating(),
@@ -5111,23 +5106,22 @@ nsCSSFrameConstructor::ConstructFieldSet
     // XXXbz this is probably wrong, and once arbitrary frames can be absolute
     // containing blocks we should fix this..
     aState.PushAbsoluteContainingBlock(blockFrame, absoluteSaveState);
   }
 
   ProcessChildren(aState, aContent, aStyleContext, blockFrame, PR_TRUE,
                   childItems, PR_TRUE);
 
-  static NS_DEFINE_IID(kLegendFrameCID, NS_LEGEND_FRAME_CID);
   nsIFrame * child      = childItems.childList;
   nsIFrame * previous   = nsnull;
-  nsIFrame* legendFrame = nsnull;
+  nsLegendFrame* legendFrame = nsnull;
   while (nsnull != child) {
-    nsresult result = child->QueryInterface(kLegendFrameCID, (void**)&legendFrame);
-    if (NS_SUCCEEDED(result) && legendFrame) {
+    legendFrame = do_QueryFrame(child);
+    if (legendFrame) {
       // We want the legend to be the first frame in the fieldset child list.
       // That way the EventStateManager will do the right thing when tabbing
       // from a selection point within the legend (bug 236071), which is
       // used for implementing legend access keys (bug 81481).
       // GetAdjustedParentFrame() below depends on this frame order.
       if (nsnull != previous) {
         previous->SetNextSibling(legendFrame->GetNextSibling());
       } else {
@@ -5184,18 +5178,17 @@ nsCSSFrameConstructor::ConstructTextFram
     ProcessPseudoFrames(aState, aFrameItems);
 
   nsIFrame* newFrame = nsnull;
 
 #ifdef MOZ_SVG
   if (aParentFrame->IsFrameOfType(nsIFrame::eSVG)) {
     nsIFrame *ancestorFrame = SVG_GetFirstNonAAncestorFrame(aParentFrame);
     if (ancestorFrame) {
-      nsISVGTextContentMetrics* metrics;
-      CallQueryInterface(ancestorFrame, &metrics);
+      nsISVGTextContentMetrics* metrics = do_QueryFrame(ancestorFrame);
       if (!metrics) {
         return NS_OK;
       }
       newFrame = NS_NewSVGGlyphFrame(mPresShell, aContent,
                                      ancestorFrame, aStyleContext);
     }
   }
   else
@@ -5575,18 +5568,17 @@ nsCSSFrameConstructor::CreateAnonymousFr
 // after the node has been constructed and initialized create any
 // anonymous content a node needs.
 nsresult
 nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState& aState,
                                              nsIContent*              aParent,
                                              nsIFrame*                aParentFrame,
                                              nsFrameItems&            aChildItems)
 {
-  nsIAnonymousContentCreator* creator = nsnull;
-  CallQueryInterface(aParentFrame, &creator);
+  nsIAnonymousContentCreator* creator = do_QueryFrame(aParentFrame);
   if (!creator)
     return NS_OK;
 
   nsresult rv;
 
   nsAutoTArray<nsIContent*, 4> newAnonymousItems;
   rv = creator->CreateAnonymousContent(newAnonymousItems);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -6989,28 +6981,26 @@ nsCSSFrameConstructor::ConstructSVGFrame
     newFrame = NS_NewSVGForeignObjectFrame(mPresShell, aContent, aStyleContext);
   }
   else if (aTag == nsGkAtoms::a) {
     newFrame = NS_NewSVGAFrame(mPresShell, aContent, aStyleContext);
   }
   else if (aTag == nsGkAtoms::text) {
     nsIFrame *ancestorFrame = SVG_GetFirstNonAAncestorFrame(aParentFrame);
     if (ancestorFrame) {
-      nsISVGTextContentMetrics* metrics;
-      CallQueryInterface(ancestorFrame, &metrics);
+      nsISVGTextContentMetrics* metrics = do_QueryFrame(ancestorFrame);
       // Text cannot be nested
       if (!metrics)
         newFrame = NS_NewSVGTextFrame(mPresShell, aContent, aStyleContext);
     }
   }
   else if (aTag == nsGkAtoms::tspan) {
     nsIFrame *ancestorFrame = SVG_GetFirstNonAAncestorFrame(aParentFrame);
     if (ancestorFrame) {
-      nsISVGTextContentMetrics* metrics;
-      CallQueryInterface(ancestorFrame, &metrics);
+      nsISVGTextContentMetrics* metrics = do_QueryFrame(ancestorFrame);
       if (metrics)
         newFrame = NS_NewSVGTSpanFrame(mPresShell, aContent,
                                        ancestorFrame, aStyleContext);
     }
   }
   else if (aTag == nsGkAtoms::linearGradient) {
     newFrame = NS_NewSVGLinearGradientFrame(mPresShell, aContent, aStyleContext);
   }
@@ -8495,18 +8485,17 @@ nsCSSFrameConstructor::ContentAppended(n
 
   // Recover first-letter frames
   if (haveFirstLetterStyle) {
     RecoverLetterFrames(containingBlock);
   }
 
 #ifdef DEBUG
   if (gReallyNoisyContentUpdates) {
-    nsIFrameDebug* fdbg = nsnull;
-    CallQueryInterface(parentFrame, &fdbg);
+    nsIFrameDebug* fdbg = do_QueryFrame(parentFrame);
     if (fdbg) {
       printf("nsCSSFrameConstructor::ContentAppended: resulting frame model:\n");
       fdbg->List(stdout, 0);
     }
   }
 #endif
 
   return NS_OK;
@@ -8643,18 +8632,17 @@ nsCSSFrameConstructor::ContentInserted(n
           // empty, so we can simply append).
           NS_ASSERTION(mDocElementContainingBlock->GetFirstChild(nsnull) == nsnull,
                        "Unexpected child of document element containing block");
           mDocElementContainingBlock->AppendFrames(nsnull, docElementFrame);
         }
         InvalidateCanvasIfNeeded(docElementFrame);
 #ifdef DEBUG
         if (gReallyNoisyContentUpdates) {
-          nsIFrameDebug* fdbg = nsnull;
-          CallQueryInterface(docElementFrame, &fdbg);
+          nsIFrameDebug* fdbg = do_QueryFrame(docElementFrame);
           if (fdbg) {
             printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
             fdbg->List(stdout, 0);
           }
         }
 #endif
       }
     }
@@ -8936,18 +8924,17 @@ nsCSSFrameConstructor::ContentInserted(n
   if (haveFirstLetterStyle) {
     // Recover the letter frames for the containing block when
     // it has first-letter style.
     RecoverLetterFrames(state.mFloatedItems.containingBlock);
   }
 
 #ifdef DEBUG
   if (gReallyNoisyContentUpdates && parentFrame) {
-    nsIFrameDebug* fdbg = nsnull;
-    CallQueryInterface(parentFrame, &fdbg);
+    nsIFrameDebug* fdbg = do_QueryFrame(parentFrame);
     if (fdbg) {
       printf("nsCSSFrameConstructor::ContentInserted: resulting frame model:\n");
       fdbg->List(stdout, 0);
     }
   }
 #endif
 
   return NS_OK;
@@ -9315,18 +9302,17 @@ nsCSSFrameConstructor::ContentRemoved(ns
     }
 
 #ifdef DEBUG
     if (gReallyNoisyContentUpdates) {
       printf("nsCSSFrameConstructor::ContentRemoved: childFrame=");
       nsFrame::ListTag(stdout, childFrame);
       printf("\n");
 
-      nsIFrameDebug* fdbg = nsnull;
-      CallQueryInterface(parentFrame, &fdbg);
+      nsIFrameDebug* fdbg = do_QueryFrame(parentFrame);
       if (fdbg)
         fdbg->List(stdout, 0);
     }
 #endif
 
     // Walk the frame subtree deleting any out-of-flow frames, and
     // remove the mapping from content objects to frames
     ::DeletingFrameSubtree(frameManager, childFrame);
@@ -9380,18 +9366,17 @@ nsCSSFrameConstructor::ContentRemoved(ns
       nsFrameConstructorState state(mPresShell, mFixedContainingBlock,
                                     GetAbsoluteContainingBlock(parentFrame),
                                     containingBlock);
       RecoverLetterFrames(containingBlock);
     }
 
 #ifdef DEBUG
     if (gReallyNoisyContentUpdates && parentFrame) {
-      nsIFrameDebug* fdbg = nsnull;
-      CallQueryInterface(parentFrame, &fdbg);
+      nsIFrameDebug* fdbg = do_QueryFrame(parentFrame);
       if (fdbg) {
         printf("nsCSSFrameConstructor::ContentRemoved: resulting frame model:\n");
         fdbg->List(stdout, 0);
       }
     }
 #endif
   }
 
@@ -12532,26 +12517,25 @@ nsCSSFrameConstructor::ConstructInline(n
     MarkIBSpecialPrevSibling(inlineFrame, blockFrame);
   }
 
   #ifdef DEBUG
   if (gNoisyInlineConstruction) {
     nsIFrameDebug*  frameDebug;
 
     printf("nsCSSFrameConstructor::ConstructInline:\n");
-    if (NS_SUCCEEDED(CallQueryInterface(aNewFrame, &frameDebug))) {
+    if ( (frameDebug = do_QueryFrame(aNewFrame)) ) {
       printf("  ==> leading inline frame:\n");
       frameDebug->List(stdout, 2);
     }
-    if (NS_SUCCEEDED(CallQueryInterface(blockFrame, &frameDebug))) {
+    if ( (frameDebug = do_QueryFrame(blockFrame)) ) {
       printf("  ==> block frame:\n");
       frameDebug->List(stdout, 2);
     }
-    if (inlineFrame &&
-        NS_SUCCEEDED(CallQueryInterface(inlineFrame, &frameDebug))) {
+    if ( (frameDebug = do_QueryFrame(inlineFrame)) ) {
       printf("  ==> trailing inline frame:\n");
       frameDebug->List(stdout, 2);
     }
   }
 #endif
 
   return rv;
 }
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -235,24 +235,23 @@ protected:
     }
 
     mFrame = aFrame;
 
     mBidiEnabled = aFrame->PresContext()->BidiEnabled();
     if (mBidiEnabled) {
       // Find the containing block frame
       nsIFrame* frame = aFrame;
-      nsresult rv = NS_ERROR_FAILURE;
-      while (frame &&
-             frame->IsFrameOfType(nsIFrame::eLineParticipant) &&
-             NS_FAILED(rv)) {
+      do {
         frame = frame->GetParent();
-        rv = frame->QueryInterface(kBlockFrameCID, (void**)&mBlockFrame);
+        mBlockFrame = do_QueryFrame(frame);
       }
-      NS_ASSERTION(NS_SUCCEEDED(rv) && mBlockFrame, "Cannot find containing block.");
+      while (frame && frame->IsFrameOfType(nsIFrame::eLineParticipant));
+
+      NS_ASSERTION(mBlockFrame, "Cannot find containing block.");
 
       mLineContinuationPoint = mContinuationPoint;
     }
   }
   
   PRBool AreOnSameLine(nsIFrame* aFrame1, nsIFrame* aFrame2) {
     // Assumes that aFrame1 and aFrame2 are both decsendants of mBlockFrame.
     PRBool isValid1, isValid2;
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -1179,18 +1179,17 @@ nsresult nsCaret::UpdateCaretRects(nsIFr
 
   // Clamp our position to be within our scroll frame. If we don't, then it
   // clips us, and we don't appear at all. See bug 335560.
   nsIFrame *scrollFrame =
     nsLayoutUtils::GetClosestFrameOfType(aFrame, nsGkAtoms::scrollFrame);
   if (scrollFrame)
   {
     // First, use the scrollFrame to get at the scrollable view that we're in.
-    nsIScrollableFrame *scrollable;
-    CallQueryInterface(scrollFrame, &scrollable);
+    nsIScrollableFrame *scrollable = do_QueryFrame(scrollFrame);
     nsIScrollableView *scrollView = scrollable->GetScrollableView();
     nsIView *view;
     scrollView->GetScrolledView(view);
 
     // Compute the caret's coordinates in the enclosing view's coordinate
     // space. To do so, we need to correct for both the original frame's
     // offset from the scrollframe, and the scrollable view's offset from the
     // scrolled frame's view.
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3732,18 +3732,18 @@ DocumentViewerImpl::PrintPreviewNavigate
   } else { // If we get here we are doing "GoTo"
     if (aPageNum < 0 || aPageNum > pageCount) {
       return NS_OK;
     }
   }
 
   if (fndPageFrame && scrollableView) {
     nscoord deadSpaceGapTwips = 0;
-    nsIPageSequenceFrame * sqf;
-    if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) {
+    nsIPageSequenceFrame * sqf = do_QueryFrame(seqFrame);
+    if (sqf) {
       sqf->GetDeadSpaceValue(&deadSpaceGapTwips);
     }
 
     // To compute deadSpaceGap, use the same presContext as was used
     // to layout the seqFrame. (That presContext may have different
     // TwipsToAppUnits conversion from this->mPresContext)
     nscoord deadSpaceGap = 
       seqFrame->PresContext()->TwipsToAppUnits(deadSpaceGapTwips);
--- a/layout/base/nsFrameManager.cpp
+++ b/layout/base/nsFrameManager.cpp
@@ -729,19 +729,18 @@ nsFrameManager::NotifyDestroyingFrame(ns
 
 #ifdef NS_DEBUG
 static void
 DumpContext(nsIFrame* aFrame, nsStyleContext* aContext)
 {
   if (aFrame) {
     fputs("frame: ", stdout);
     nsAutoString  name;
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+    nsIFrameDebug *frameDebug = do_QueryFrame(aFrame);
+    if (frameDebug) {
       frameDebug->GetFrameName(name);
       fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout);
     }
     fprintf(stdout, " (%p)", static_cast<void*>(aFrame));
   }
   if (aContext) {
     fprintf(stdout, " style: %p ", static_cast<void*>(aContext));
 
@@ -1580,19 +1579,17 @@ nsFrameManager::CaptureFrameStateFor(nsI
                                      nsIStatefulFrame::SpecialStateID aID)
 {
   if (!aFrame || !aState) {
     NS_WARNING("null frame, or state");
     return;
   }
 
   // Only capture state for stateful frames
-  nsIStatefulFrame* statefulFrame;
-  CallQueryInterface(aFrame, &statefulFrame);
-
+  nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
   if (!statefulFrame) {
     return;
   }
 
   // Capture the state, exit early if we get null (nothing to save)
   nsAutoPtr<nsPresState> frameState;
   nsresult rv = statefulFrame->SaveState(aID, getter_Transfers(frameState));
   if (!frameState) {
@@ -1647,18 +1644,17 @@ nsFrameManager::RestoreFrameStateFor(nsI
                                      nsIStatefulFrame::SpecialStateID aID)
 {
   if (!aFrame || !aState) {
     NS_WARNING("null frame or state");
     return;
   }
 
   // Only restore state for stateful frames
-  nsIStatefulFrame* statefulFrame;
-  CallQueryInterface(aFrame, &statefulFrame);
+  nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
   if (!statefulFrame) {
     return;
   }
 
   // Generate the hash key the state was stored under
   // Exit early if we get empty key
   nsIContent* content = aFrame->GetContent();
   // If we don't have content, we can't generate a hash
--- a/layout/base/nsIPercentHeightObserver.h
+++ b/layout/base/nsIPercentHeightObserver.h
@@ -33,36 +33,31 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIPercentHeightObserver_h___
 #define nsIPercentHeightObserver_h___
 
+#include "nsQueryFrame.h"
+
 struct nsHTMLReflowState;
 class  nsPresContext;
 
-// IID for the nsIPercentHeightObserver interface 
-#define NS_IPERCENTHEIGHTOBSERVER_IID \
- { 0x9cdc174b, 0x4f39, 0x41ad, {0xbc, 0x16, 0x5a, 0xc5, 0xa8, 0x64, 0x14, 0xa1}}
-
 /**
  * This interface is supported by frames that need to provide computed height
  * values to children during reflow which would otherwise not happen. Currently only
  * table cells support this.
  */
-class nsIPercentHeightObserver : public nsISupports
+class nsIPercentHeightObserver
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPERCENTHEIGHTOBSERVER_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIPercentHeightObserver)
 
   // Notify the observer that aReflowState has no computed height, but it has a percent height
   virtual void NotifyPercentHeight(const nsHTMLReflowState& aReflowState) = 0;
 
   // Ask the observer if it should observe aReflowState.frame
   virtual PRBool NeedsToObserve(const nsHTMLReflowState& aReflowState) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIPercentHeightObserver,
-                              NS_IPERCENTHEIGHTOBSERVER_IID)
-
 #endif // nsIPercentHeightObserver_h___ 
--- a/layout/base/nsLayoutDebugger.cpp
+++ b/layout/base/nsLayoutDebugger.cpp
@@ -154,20 +154,17 @@ static void
 PrintDisplayListTo(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList,
                    PRInt32 aIndent, FILE* aOutput)
 {
   for (nsDisplayItem* i = aList.GetBottom(); i != nsnull; i = i->GetAbove()) {
     for (PRInt32 j = 0; j < aIndent; ++j) {
       fputc(' ', aOutput);
     }
     nsIFrame* f = i->GetUnderlyingFrame();
-    nsIFrameDebug* fDebug = nsnull;
-    if (f) {
-      CallQueryInterface(f, &fDebug);
-    }
+    nsIFrameDebug* fDebug = do_QueryFrame(f);
     nsAutoString fName;
     if (fDebug) {
       fDebug->GetFrameName(fName);
     }
     nsRect rect = i->GetBounds(aBuilder);
     switch (i->GetType()) {
       case nsDisplayItem::TYPE_CLIP: {
         nsDisplayClip* c = static_cast<nsDisplayClip*>(i);
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -541,32 +541,27 @@ nsLayoutUtils::FindSiblingViewFor(nsIVie
 //static
 nsIScrollableFrame*
 nsLayoutUtils::GetScrollableFrameFor(nsIFrame *aScrolledFrame)
 {
   nsIFrame *frame = aScrolledFrame->GetParent();
   if (!frame) {
     return nsnull;
   }
-  nsIScrollableFrame *sf;
-  CallQueryInterface(frame, &sf);
+  nsIScrollableFrame *sf = do_QueryFrame(frame);
   return sf;
 }
 
 //static
 nsIScrollableFrame*
 nsLayoutUtils::GetScrollableFrameFor(nsIScrollableView *aScrollableView)
 {
   nsIFrame *frame = GetFrameFor(aScrollableView->View()->GetParent());
-  if (frame) {
-    nsIScrollableFrame *sf;
-    CallQueryInterface(frame, &sf);
-    return sf;
-  }
-  return nsnull;
+  nsIScrollableFrame *sf = do_QueryFrame(frame);
+  return sf;
 }
 
 //static
 nsPresContext::ScrollbarStyles
 nsLayoutUtils::ScrollbarStylesOfView(nsIScrollableView *aScrollableView)
 {
   nsIScrollableFrame *sf = GetScrollableFrameFor(aScrollableView);
   return sf ? sf->GetScrollbarStyles() :
@@ -1529,20 +1524,18 @@ nsLayoutUtils::FindChildContainingDescen
   }
 
   return result;
 }
 
 nsBlockFrame*
 nsLayoutUtils::GetAsBlock(nsIFrame* aFrame)
 {
-  nsBlockFrame* block;
-  if (NS_SUCCEEDED(aFrame->QueryInterface(kBlockFrameCID, (void**)&block)))
-    return block;
-  return nsnull;
+  nsBlockFrame* block = do_QueryFrame(aFrame);
+  return block;
 }
 
 nsBlockFrame*
 nsLayoutUtils::FindNearestBlockAncestor(nsIFrame* aFrame)
 {
   nsIFrame* nextAncestor;
   for (nextAncestor = aFrame->GetParent(); nextAncestor;
        nextAncestor = nextAncestor->GetParent()) {
@@ -1677,18 +1670,17 @@ nsLayoutUtils::IsViewportScrollbarFrame(
   if (!aFrame)
     return PR_FALSE;
 
   nsIFrame* rootScrollFrame =
     aFrame->PresContext()->PresShell()->GetRootScrollFrame();
   if (!rootScrollFrame)
     return PR_FALSE;
 
-  nsIScrollableFrame* rootScrollableFrame = nsnull;
-  CallQueryInterface(rootScrollFrame, &rootScrollableFrame);
+  nsIScrollableFrame* rootScrollableFrame = do_QueryFrame(rootScrollFrame);
   NS_ASSERTION(rootScrollableFrame, "The root scorollable frame is null");
 
   if (!IsProperAncestorFrame(rootScrollFrame, aFrame))
     return PR_FALSE;
 
   nsIFrame* rootScrolledFrame = rootScrollableFrame->GetScrolledFrame();
   return !(rootScrolledFrame == aFrame ||
            IsProperAncestorFrame(rootScrolledFrame, aFrame));
@@ -2521,19 +2513,18 @@ nsLayoutUtils::GetFirstLineBaseline(cons
     nsIAtom* fType = aFrame->GetType();
     if (fType == nsGkAtoms::tableOuterFrame) {
       *aResult = aFrame->GetBaseline();
       return PR_TRUE;
     }
 
     // For first-line baselines, we have to consider scroll frames.
     if (fType == nsGkAtoms::scrollFrame) {
-      nsIScrollableFrame *sFrame;
-      if (NS_FAILED(CallQueryInterface(const_cast<nsIFrame*>
-                                                 (aFrame), &sFrame)) || !sFrame) {
+      nsIScrollableFrame *sFrame = do_QueryFrame(const_cast<nsIFrame*>(aFrame));
+      if (!sFrame) {
         NS_NOTREACHED("not scroll frame");
       }
       nscoord kidBaseline;
       if (GetFirstLineBaseline(sFrame->GetScrolledFrame(), &kidBaseline)) {
         // Consider only the border and padding that contributes to the
         // kid's position, not the scrolling, so we get the initial
         // position.
         *aResult = kidBaseline + aFrame->GetUsedBorderAndPadding().top;
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -2925,36 +2925,33 @@ nsIPresShell::GetRootScrollFrame() const
 }
 
 nsIScrollableFrame*
 nsIPresShell::GetRootScrollFrameAsScrollable() const
 {
   nsIFrame* frame = GetRootScrollFrame();
   if (!frame)
     return nsnull;
-  nsIScrollableFrame* scrollableFrame = nsnull;
-  CallQueryInterface(frame, &scrollableFrame);
+  nsIScrollableFrame* scrollableFrame = do_QueryFrame(frame);
   NS_ASSERTION(scrollableFrame,
                "All scroll frames must implement nsIScrollableFrame");
   return scrollableFrame;
 }
 
 NS_IMETHODIMP
 PresShell::GetPageSequenceFrame(nsIPageSequenceFrame** aResult) const
 {
   NS_PRECONDITION(nsnull != aResult, "null ptr");
   if (nsnull == aResult) {
     return NS_ERROR_NULL_POINTER;
   }
 
   *aResult = nsnull;
   nsIFrame* frame = mFrameConstructor->GetPageSequenceFrame();
-  if (frame) {
-    CallQueryInterface(frame, aResult);
-  }
+  *aResult = do_QueryFrame(frame);
   return *aResult ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsIFrame*
 PresShell::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt)
 {
   return nsLayoutUtils::GetFrameForPoint(aFrame, aPt);
 }
@@ -2998,18 +2995,17 @@ PresShell::RestoreRootScrollPosition()
   // we're scrolling to our restored position.  Entering reflow for the
   // scrollable frame will cause it to reenter ScrollToRestoredPosition(), and
   // it'll get all confused.
   nsAutoScriptBlocker scriptBlocker;
 
   if (historyState) {
     nsIFrame* scrollFrame = GetRootScrollFrame();
     if (scrollFrame) {
-      nsIScrollableFrame* scrollableFrame;
-      CallQueryInterface(scrollFrame, &scrollableFrame);
+      nsIScrollableFrame* scrollableFrame = do_QueryFrame(scrollFrame);
       if (scrollableFrame) {
         FrameManager()->RestoreFrameStateFor(scrollFrame, historyState,
                                              nsIStatefulFrame::eDocumentScrollState);
         scrollableFrame->ScrollToRestoredPosition();
       }
     }
   }
 }
@@ -3217,18 +3213,17 @@ PresShell::GetViewToScroll(nsLayoutUtils
       nsCOMPtr<nsIDOMNode> focusedNode;
       domSelection->GetFocusNode(getter_AddRefs(focusedNode));
       focusedContent = do_QueryInterface(focusedNode);
     }
   }
   if (focusedContent) {
     nsIFrame* startFrame = GetPrimaryFrameFor(focusedContent);
     if (startFrame) {
-      nsIScrollableViewProvider* svp;
-      CallQueryInterface(startFrame, &svp);
+      nsIScrollableViewProvider* svp = do_QueryFrame(startFrame);
       // If this very frame provides a scroll view, start there instead of frame's
       // closest view, because the scroll view may be inside a child frame.
       // For example, this happens in the case of overflow:scroll.
       // In that case we still use GetNearestScrollingView() because
       // we need a scrolling view that matches aDirection.
       nsIScrollableView* sv;
       nsIView* startView = svp && (sv = svp->GetScrollableView()) ? sv->View() : startFrame->GetClosestView();
       NS_ASSERTION(startView, "No view to start searching for scrollable view from");
@@ -5990,19 +5985,17 @@ PresShell::RemoveOverrideStyleSheet(nsIS
   return mStyleSet->RemoveStyleSheet(nsStyleSet::eOverrideSheet, aSheet);
 }
 
 static void
 StopPluginInstance(PresShell *aShell, nsIContent *aContent)
 {
   nsIFrame *frame = aShell->FrameManager()->GetPrimaryFrameFor(aContent, -1);
 
-  nsIObjectFrame *objectFrame = nsnull;
-  if (frame)
-    CallQueryInterface(frame, &objectFrame);
+  nsIObjectFrame *objectFrame = do_QueryFrame(frame);
   if (!objectFrame)
     return;
 
   objectFrame->StopPlugin();
 }
 
 #ifdef MOZ_MEDIA
 static void
@@ -6276,20 +6269,19 @@ PresShell::DoReflow(nsIFrame* target)
   }
 }
 
 #ifdef DEBUG
 void
 PresShell::DoVerifyReflow()
 {
   if (nsIFrameDebug::GetVerifyTreeEnable()) {
-    nsIFrameDebug*  frameDebug;
     nsIFrame* rootFrame = FrameManager()->GetRootFrame();
-    if (NS_SUCCEEDED(rootFrame->QueryInterface(NS_GET_IID(nsIFrameDebug),
-                                               (void**)&frameDebug))) {
+    nsIFrameDebug *frameDebug = do_QueryFrame(rootFrame);
+    if (frameDebug) {
       frameDebug->VerifyTree();
     }
   }
   if (GetVerifyReflowEnable()) {
     // First synchronously render what we have so far so that we can
     // see it.
     nsIView* rootView;
     mViewManager->GetRootView(rootView);
@@ -6421,18 +6413,17 @@ PresShell::ClearReflowEventStatus()
 // Return value says whether to walk children.
 typedef PRBool (* frameWalkerFn)(nsIFrame *aFrame, void *aClosure);
    
 static PRBool
 ReResolveMenusAndTrees(nsIFrame *aFrame, void *aClosure)
 {
   // Trees have a special style cache that needs to be flushed when
   // the theme changes.
-  nsTreeBodyFrame *treeBody = nsnull;
-  CallQueryInterface(aFrame, &treeBody);
+  nsTreeBodyFrame *treeBody = do_QueryFrame(aFrame);
   if (treeBody)
     treeBody->ClearStyleAndImageCaches();
 
   // We deliberately don't re-resolve style on a menu's popup
   // sub-content, since doing so slows menus to a crawl.  That means we
   // have to special-case them on a skin switch, and ensure that the
   // popup frames just get destroyed completely.
   if (aFrame && aFrame->GetType() == nsGkAtoms::menuFrame)
@@ -6596,37 +6587,33 @@ static NS_DEFINE_CID(kViewManagerCID, NS
 static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID);
 
 static void
 LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg)
 {
   printf("verifyreflow: ");
   nsAutoString name;
   if (nsnull != k1) {
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(k1->QueryInterface(NS_GET_IID(nsIFrameDebug),
-                                        (void**)&frameDebug))) {
+    nsIFrameDebug *frameDebug = do_QueryFrame(k1);
+    if (frameDebug) {
      frameDebug->GetFrameName(name);
     }
   }
   else {
     name.Assign(NS_LITERAL_STRING("(null)"));
   }
   fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout);
 
   fprintf(stdout, " %p ", (void*)k1);
 
   printf(" != ");
 
   if (nsnull != k2) {
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(k2->QueryInterface(NS_GET_IID(nsIFrameDebug),
-                                        (void**)&frameDebug))) {
+    nsIFrameDebug *frameDebug = do_QueryFrame(k2);
+    if (frameDebug) {
       frameDebug->GetFrameName(name);
     }
   }
   else {
     name.Assign(NS_LITERAL_STRING("(null)"));
   }
   fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout);
 
@@ -6636,31 +6623,29 @@ LogVerifyMessage(nsIFrame* k1, nsIFrame*
 }
 
 static void
 LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg,
                  const nsRect& r1, const nsRect& r2)
 {
   printf("VerifyReflow Error:\n");
   nsAutoString name;
-  nsIFrameDebug*  frameDebug;
-
-  if (NS_SUCCEEDED(k1->QueryInterface(NS_GET_IID(nsIFrameDebug),
-                                      (void**)&frameDebug))) {
+  nsIFrameDebug *frameDebug = do_QueryFrame(k1);
+  if (frameDebug) {
     fprintf(stdout, "  ");
     frameDebug->GetFrameName(name);
     fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout);
     fprintf(stdout, " %p ", (void*)k1);
   }
   printf("{%d, %d, %d, %d}", r1.x, r1.y, r1.width, r1.height);
 
   printf(" != \n");
 
-  if (NS_SUCCEEDED(k2->QueryInterface(NS_GET_IID(nsIFrameDebug),
-                                      (void**)&frameDebug))) {
+  frameDebug = do_QueryFrame(k2);
+  if (frameDebug) {
     fprintf(stdout, "  ");
     frameDebug->GetFrameName(name);
     fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout);
     fprintf(stdout, " %p ", (void*)k2);
   }
   printf("{%d, %d, %d, %d}\n", r2.x, r2.y, r2.width, r2.height);
 
   printf("  %s\n", aMsg);
@@ -7008,23 +6993,23 @@ PresShell::VerifyIncrementalReflow()
 
   // Now that the document has been reflowed, use its frame tree to
   // compare against our frame tree.
   nsIFrame* root1 = FrameManager()->GetRootFrame();
   nsIFrame* root2 = sh->FrameManager()->GetRootFrame();
   PRBool ok = CompareTrees(mPresContext, root1, cx, root2);
   if (!ok && (VERIFY_REFLOW_NOISY & gVerifyReflowFlags)) {
     printf("Verify reflow failed, primary tree:\n");
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(CallQueryInterface(root1, &frameDebug))) {
+    nsIFrameDebug*  frameDebug = do_QueryFrame(root1);
+    if (frameDebug) {
       frameDebug->List(stdout, 0);
     }
     printf("Verification tree:\n");
-    if (NS_SUCCEEDED(CallQueryInterface(root2, &frameDebug))) {
+    frameDebug = do_QueryFrame(root2);
+    if (frameDebug) {
       frameDebug->List(stdout, 0);
     }
   }
 
 #ifdef DEBUG_Eli
   // Sample code for dumping page to png
   // XXX Needs to be made more flexible
   if (!ok) {
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -282,46 +282,38 @@ nsComboboxControlFrame::nsComboboxContro
 
 //--------------------------------------------------------------
 nsComboboxControlFrame::~nsComboboxControlFrame()
 {
   REFLOW_COUNTER_DUMP("nsCCF");
 }
 
 //--------------------------------------------------------------
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsComboboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
+
+NS_QUERYFRAME_HEAD(nsComboboxControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIComboboxControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
+  NS_QUERYFRAME_ENTRY(nsIScrollableViewProvider)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
 
-  if (aIID.Equals(NS_GET_IID(nsIComboboxControlFrame))) {
-    *aInstancePtr = static_cast<nsIComboboxControlFrame*>(this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {                                         
-    *aInstancePtr = static_cast<nsIAnonymousContentCreator*>(this);
-    return NS_OK;   
-  } else if (aIID.Equals(NS_GET_IID(nsISelectControlFrame))) {
-    *aInstancePtr = static_cast<nsISelectControlFrame*>(this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
-    *aInstancePtr = static_cast<nsIStatefulFrame*>(this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIRollupListener))) {
-    *aInstancePtr = static_cast<nsIRollupListener*>(this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider))) {
-    *aInstancePtr = static_cast<nsIScrollableViewProvider*>(this);
-    return NS_OK;
-  } 
-  
-  return nsBlockFrame::QueryInterface(aIID, aInstancePtr);
+NS_IMPL_QUERY_INTERFACE1(nsComboboxControlFrame, nsIRollupListener)
+
+NS_IMETHODIMP_(nsrefcnt)
+nsComboboxControlFrame::AddRef()
+{
+  return 2;
+}
+
+NS_IMETHODIMP_(nsrefcnt)
+nsComboboxControlFrame::Release()
+{
+  return 1;
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
@@ -420,18 +412,17 @@ nsComboboxControlFrame::ShowList(nsPresC
   }
 
   // XXXbz so why do we need to flush here, exactly?
   shell->GetDocument()->FlushPendingNotifications(Flush_Layout);
   if (!weakFrame.IsAlive()) {
     return PR_FALSE;
   }
 
-  nsIFrame* listFrame;
-  CallQueryInterface(mListControlFrame, &listFrame);
+  nsIFrame* listFrame = do_QueryFrame(mListControlFrame);
   if (listFrame) {
     nsIView* view = listFrame->GetView();
     NS_ASSERTION(view, "nsComboboxControlFrame view is null");
     if (view) {
       nsIWidget* widget = view->GetWidget();
       if (widget)
         widget->CaptureRollupEvents(this, mDroppedDown, mDroppedDown);
     }
@@ -565,18 +556,17 @@ static void printSize(char * aDesc, nsco
 nscoord
 nsComboboxControlFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
                                           nsLayoutUtils::IntrinsicWidthType aType)
 {
   // get the scrollbar width, we'll use this later
   nscoord scrollbarWidth = 0;
   nsPresContext* presContext = PresContext();
   if (mListControlFrame) {
-    nsIScrollableFrame* scrollable;
-    CallQueryInterface(mListControlFrame, &scrollable);
+    nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
     NS_ASSERTION(scrollable, "List must be a scrollable frame");
     scrollbarWidth =
       scrollable->GetDesiredScrollbarSizes(presContext, aRenderingContext).LeftRight();
   }
 
   nscoord displayWidth = 0;
   if (NS_LIKELY(mDisplayFrame)) {
     displayWidth = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
@@ -671,18 +661,17 @@ nsComboboxControlFrame::Reflow(nsPresCon
   // Get the width of the vertical scrollbar.  That will be the width of the
   // dropdown button.
   nscoord buttonWidth;
   const nsStyleDisplay *disp = GetStyleDisplay();
   if (IsThemed(disp) && !aPresContext->GetTheme()->ThemeNeedsComboboxDropmarker()) {
     buttonWidth = 0;
   }
   else {
-    nsIScrollableFrame* scrollable;
-    CallQueryInterface(mListControlFrame, &scrollable);
+    nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
     NS_ASSERTION(scrollable, "List must be a scrollable frame");
     buttonWidth =
       scrollable->GetDesiredScrollbarSizes(PresContext(), 
                                            aReflowState.rendContext).LeftRight();
     if (buttonWidth > aReflowState.ComputedWidth()) {
       buttonWidth = 0;
     }
   }
@@ -769,18 +758,17 @@ nsComboboxControlFrame::ShowDropDown(PRB
     ShowList(PresContext(), aDoDropDown); // might destroy us
   }
 }
 
 void
 nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame)
 {
   mDropdownFrame = aDropDownFrame;
- 
-  CallQueryInterface(mDropdownFrame, &mListControlFrame);
+  mListControlFrame = do_QueryFrame(mDropdownFrame);
 }
 
 nsIFrame*
 nsComboboxControlFrame::GetDropDown() 
 {
   return mDropdownFrame;
 }
 
@@ -873,25 +861,21 @@ nsComboboxControlFrame::GetIndexOfDispla
 }
 
 //----------------------------------------------------------------------
 // nsISelectControlFrame
 //----------------------------------------------------------------------
 NS_IMETHODIMP
 nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone)
 {
-  nsISelectControlFrame* listFrame = nsnull;
-  nsresult rv = NS_ERROR_FAILURE;
-  if (mDropdownFrame != nsnull) {
-    rv = CallQueryInterface(mDropdownFrame, &listFrame);
-    if (listFrame) {
-      rv = listFrame->DoneAddingChildren(aIsDone);
-    }
-  }
-  return rv;
+  nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
+  if (!listFrame)
+    return NS_ERROR_FAILURE;
+
+  return listFrame->DoneAddingChildren(aIsDone);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::AddOption(nsPresContext* aPresContext, PRInt32 aIndex)
 {
   if (aIndex <= mDisplayedIndex) {
     ++mDisplayedIndex;
   }
@@ -919,34 +903,31 @@ nsComboboxControlFrame::RemoveOption(nsP
 
   nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
   return lcf->RemoveOption(aPresContext, aIndex);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::GetOptionSelected(PRInt32 aIndex, PRBool* aValue)
 {
-  nsISelectControlFrame* listFrame = nsnull;
   NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
 
-  CallQueryInterface(mDropdownFrame, &listFrame);
+  nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
   NS_ASSERTION(listFrame, "No list frame!");
 
   return listFrame->GetOptionSelected(aIndex, aValue);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::OnSetSelectedIndex(PRInt32 aOldIndex, PRInt32 aNewIndex)
 {
   RedisplayText(aNewIndex);
+  NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
   
-  nsISelectControlFrame* listFrame = nsnull;
-  NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
-
-  CallQueryInterface(mDropdownFrame, &listFrame);
+  nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
   NS_ASSERTION(listFrame, "No list frame!");
 
   return listFrame->OnSetSelectedIndex(aOldIndex, aNewIndex);
 }
 
 // End nsISelectControlFrame
 //----------------------------------------------------------------------
 
@@ -972,39 +953,33 @@ nsComboboxControlFrame::HandleEvent(nsPr
     
   return NS_OK;
 }
 
 
 nsresult
 nsComboboxControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
 {
-  nsIFormControlFrame* fcFrame = nsnull;
-  nsresult result = CallQueryInterface(mDropdownFrame, &fcFrame);
-  if (NS_FAILED(result)) {
-    return result;
+  nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
+  if (!fcFrame) {
+    return NS_NOINTERFACE;
   }
-  if (fcFrame) {
-    return fcFrame->SetFormProperty(aName, aValue);
-  }
-  return NS_OK;
+
+  return fcFrame->SetFormProperty(aName, aValue);
 }
 
 nsresult 
 nsComboboxControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
 {
-  nsIFormControlFrame* fcFrame = nsnull;
-  nsresult result = CallQueryInterface(mDropdownFrame, &fcFrame);
-  if(NS_FAILED(result)) {
-    return result;
+  nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
+  if (!fcFrame) {
+    return NS_ERROR_FAILURE;
   }
-  if (fcFrame) {
-    return fcFrame->GetFormProperty(aName, aValue);
-  }
-  return NS_OK;
+
+  return fcFrame->GetFormProperty(aName, aValue);
 }
 
 nsIFrame*
 nsComboboxControlFrame::GetContentInsertionFrame() {
   return mInRedisplayText ? mDisplayFrame : mDropdownFrame->GetContentInsertionFrame();
 }
 
 nsresult
@@ -1224,18 +1199,18 @@ nsComboboxControlFrame::Destroy()
 {
   // Revoke any pending RedisplayTextEvent
   mRedisplayTextEvent.Revoke();
 
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
 
   if (mDroppedDown) {
     // Get parent view
-    nsIFrame * listFrame;
-    if (NS_OK == mListControlFrame->QueryInterface(NS_GET_IID(nsIFrame), (void **)&listFrame)) {
+    nsIFrame * listFrame = do_QueryFrame(mListControlFrame);
+    if (listFrame) {
       nsIView* view = listFrame->GetView();
       NS_ASSERTION(view, "nsComboboxControlFrame view is null");
       if (view) {
         nsIWidget* widget = view->GetWidget();
         if (widget)
           widget->CaptureRollupEvents(this, PR_FALSE, PR_TRUE);
       }
     }
@@ -1441,36 +1416,34 @@ void nsComboboxControlFrame::PaintFocus(
 //----------------------------------------------------------------------
   //nsIScrollableViewProvider
 //----------------------------------------------------------------------
 nsIScrollableView* nsComboboxControlFrame::GetScrollableView()
 {
   if (!mDropdownFrame)
     return nsnull;
 
-  nsIScrollableFrame* scrollable = nsnull;
-  nsresult rv = CallQueryInterface(mDropdownFrame, &scrollable);
-  if (NS_FAILED(rv))
+  nsIScrollableFrame* scrollable = do_QueryFrame(mDropdownFrame);
+  if (!scrollable)
     return nsnull;
 
   return scrollable->GetScrollableView();
 }
 
 //---------------------------------------------------------
 // gets the content (an option) by index and then set it as
 // being selected or not selected
 //---------------------------------------------------------
 NS_IMETHODIMP
 nsComboboxControlFrame::OnOptionSelected(nsPresContext* aPresContext,
                                          PRInt32 aIndex,
                                          PRBool aSelected)
 {
   if (mDroppedDown) {
-    nsCOMPtr<nsISelectControlFrame> selectFrame
-                                     = do_QueryInterface(mListControlFrame);
+    nsISelectControlFrame *selectFrame = do_QueryFrame(mListControlFrame);
     if (selectFrame) {
       selectFrame->OnOptionSelected(aPresContext, aIndex, aSelected);
     }
   } else {
     if (aSelected) {
       RedisplayText(aIndex);
     } else {
       RedisplaySelectedText();
@@ -1512,32 +1485,29 @@ nsComboboxControlFrame::OnContentReset()
 //--------------------------------------------------------
 NS_IMETHODIMP
 nsComboboxControlFrame::SaveState(SpecialStateID aStateID,
                                   nsPresState** aState)
 {
   if (!mListControlFrame)
     return NS_ERROR_FAILURE;
 
-  nsIStatefulFrame* stateful;
-  CallQueryInterface(mListControlFrame, &stateful);
+  nsIStatefulFrame* stateful = do_QueryFrame(mListControlFrame);
   return stateful->SaveState(aStateID, aState);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::RestoreState(nsPresState* aState)
 {
   if (!mListControlFrame)
     return NS_ERROR_FAILURE;
 
-  nsIStatefulFrame* stateful;
-  nsresult rv = CallQueryInterface(mListControlFrame, &stateful);
-  NS_ASSERTION(NS_SUCCEEDED(rv), "Must implement nsIStatefulFrame");
-  rv = stateful->RestoreState(aState);
-  return rv;
+  nsIStatefulFrame* stateful = do_QueryFrame(mListControlFrame);
+  NS_ASSERTION(stateful, "Must implement nsIStatefulFrame");
+  return stateful->RestoreState(aState);
 }
 
 
 //
 // Camino uses a native widget for the combobox
 // popup, which affects drawing and event
 // handling here and in nsListControlFrame.
 // 
--- a/layout/forms/nsComboboxControlFrame.h
+++ b/layout/forms/nsComboboxControlFrame.h
@@ -91,18 +91,18 @@ class nsComboboxControlFrame : public ns
 {
 public:
   friend nsIFrame* NS_NewComboboxControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
   friend class nsComboboxDisplayFrame;
 
   nsComboboxControlFrame(nsStyleContext* aContext);
   ~nsComboboxControlFrame();
 
-  // nsISupports
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
+  NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
   virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
 
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
@@ -287,15 +287,11 @@ protected:
 
   // static class data member for Bug 32920
   // only one control can be focused at a time
   static nsComboboxControlFrame * mFocused;
 
 #ifdef DO_REFLOW_COUNTER
   PRInt32 mReflowId;
 #endif
-
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
-  NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
 };
 
 #endif
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -223,33 +223,20 @@ nsFileControlFrame::CreateAnonymousConte
                                       systemGroup);
 
   SyncAttr(kNameSpaceID_None, nsGkAtoms::size,     SYNC_TEXT);
   SyncAttr(kNameSpaceID_None, nsGkAtoms::disabled, SYNC_BOTH);
 
   return NS_OK;
 }
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
-    *aInstancePtr = static_cast<nsIAnonymousContentCreator*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsBlockFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsFileControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
 
 void 
 nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
 {
   // Fix for Bug 6133 
   if (mTextFrame) {
     nsIContent* content = mTextFrame->GetContent();
     if (content) {
--- a/layout/forms/nsFileControlFrame.h
+++ b/layout/forms/nsFileControlFrame.h
@@ -58,17 +58,17 @@ public:
   NS_IMETHOD Init(nsIContent* aContent,
                   nsIFrame*   aParent,
                   nsIFrame*   aPrevInFlow);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
   
   // nsIFormControlFrame
   virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const;
   virtual void SetFocus(PRBool aOn, PRBool aRepaint);
 
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
   
@@ -178,16 +178,13 @@ private:
    * Copy an attribute from file content to text and button content.
    * @param aNameSpaceID namespace of attr
    * @param aAttribute attribute atom
    * @param aWhichControls which controls to apply to (SYNC_TEXT or SYNC_FILE
    *        or SYNC_BOTH)
    */
   void SyncAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
                 PRInt32 aWhichControls);
-
-  NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
-  NS_IMETHOD_(nsrefcnt) Release() { return 1; }
 };
 
 #endif
 
 
--- a/layout/forms/nsFormControlFrame.cpp
+++ b/layout/forms/nsFormControlFrame.cpp
@@ -57,29 +57,19 @@ nsFormControlFrame::~nsFormControlFrame(
 void
 nsFormControlFrame::Destroy()
 {
   // Unregister the access key registered in reflow
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
   nsLeafFrame::Destroy();
 }
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsFormControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsLeafFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsFormControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
 
 nscoord
 nsFormControlFrame::GetIntrinsicWidth()
 {
   // Provide a reasonable default for sites that use an "auto" height.
   // Note that if you change this, you should change the values in forms.css
   // as well.  This is the 13px default width minus the 2px default border.
   return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
--- a/layout/forms/nsFormControlFrame.h
+++ b/layout/forms/nsFormControlFrame.h
@@ -59,17 +59,17 @@ public:
   nsFormControlFrame(nsStyleContext*);
 
   virtual PRBool IsFrameOfType(PRUint32 aFlags) const
   {
     return nsLeafFrame::IsFrameOfType(aFlags &
       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
   }
 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   /** 
     * Respond to a gui event
     * @see nsIFrame::HandleEvent
     */
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
                          nsGUIEvent* aEvent,
                          nsEventStatus* aEventStatus);
@@ -119,17 +119,12 @@ protected:
 //   
    /**
     * Get the state of the checked attribute.
     * @param aState set to PR_TRUE if the checked attribute is set,
     * PR_FALSE if the checked attribute has been removed
     */
 
   void GetCurrentCheckState(PRBool* aState);
-
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
-  NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
-
 };
 
 #endif
 
--- a/layout/forms/nsGfxButtonControlFrame.cpp
+++ b/layout/forms/nsGfxButtonControlFrame.cpp
@@ -181,29 +181,19 @@ NS_IMETHODIMP nsGfxButtonControlFrame::G
   if (accService) {
     return accService->CreateHTMLButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
-    *aInstancePtr = static_cast<nsIAnonymousContentCreator*>(this);
-    return NS_OK;
-  }
-
-  return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsGfxButtonControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLButtonControlFrame)
 
 // Initially we hardcoded the default strings here.
 // Next, we used html.css to store the default label for various types
 // of buttons. (nsGfxButtonControlFrame::DoNavQuirksReflow rev 1.20)
 // However, since html.css is not internationalized, we now grab the default
 // label from a string bundle as is done for all other UI strings.
 // See bug 16999 for further details.
 nsresult
--- a/layout/forms/nsGfxButtonControlFrame.h
+++ b/layout/forms/nsGfxButtonControlFrame.h
@@ -69,18 +69,18 @@ public:
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
 
   virtual nsIAtom* GetType() const;
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
 
+  NS_DECL_QUERYFRAME
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
   virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
 
   // nsIFormControlFrame
   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const; 
 
@@ -96,18 +96,15 @@ public:
 protected:
   nsresult GetDefaultLabel(nsXPIDLString& aLabel);
 
   nsresult GetLabel(nsXPIDLString& aLabel);
 
   PRBool IsFileBrowseButton(PRInt32 type); // Browse button of file input
 
 private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
-  NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
-
   nsSize mSuggestedSize;
   nsCOMPtr<nsIContent> mTextContent;
 };
 
 
 #endif
 
--- a/layout/forms/nsGfxCheckboxControlFrame.cpp
+++ b/layout/forms/nsGfxCheckboxControlFrame.cpp
@@ -88,32 +88,19 @@ nsGfxCheckboxControlFrame::nsGfxCheckbox
 {
 }
 
 nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
 {
 }
 
 
-//----------------------------------------------------------------------
-// nsISupports
-//----------------------------------------------------------------------
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
-    *aInstancePtr = static_cast<nsICheckboxControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsGfxCheckboxControlFrame)
+  NS_QUERYFRAME_ENTRY(nsICheckboxControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLCheckboxAccessible(static_cast<nsIFrame*>(this), aAccessible);
--- a/layout/forms/nsGfxCheckboxControlFrame.h
+++ b/layout/forms/nsGfxCheckboxControlFrame.h
@@ -73,30 +73,25 @@ public:
   //nsICheckboxControlFrame methods
   NS_IMETHOD SetCheckboxFaceStyleContext(nsStyleContext *aCheckboxFaceStyleContext);
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
   virtual nsStyleContext* GetAdditionalStyleContext(PRInt32 aIndex) const;
   virtual void SetAdditionalStyleContext(PRInt32 aIndex,
                                          nsStyleContext* aStyleContext);
 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   void PaintCheckBox(nsIRenderingContext& aRenderingContext,
                      nsPoint aPt, const nsRect& aDirtyRect);
 
   void PaintCheckBoxFromStyle(nsIRenderingContext& aRenderingContext,
                               nsPoint aPt, const nsRect& aDirtyRect);
 
 protected:
 
   PRBool GetCheckboxState();
 
   nsRefPtr<nsStyleContext> mCheckButtonFaceStyle;
-
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
-  NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
- 
 };
 
 #endif
 
--- a/layout/forms/nsGfxRadioControlFrame.cpp
+++ b/layout/forms/nsGfxRadioControlFrame.cpp
@@ -56,29 +56,19 @@ nsGfxRadioControlFrame::nsGfxRadioContro
   nsFormControlFrame(aContext)
 {
 }
 
 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
 {
 }
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIRadioControlFrame))) {
-    *aInstancePtr = static_cast<nsIRadioControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsGfxRadioControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIRadioControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLRadioButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
--- a/layout/forms/nsGfxRadioControlFrame.h
+++ b/layout/forms/nsGfxRadioControlFrame.h
@@ -55,18 +55,19 @@ class nsGfxRadioControlFrame : public ns
 
 {
 private:
 
 public:
   nsGfxRadioControlFrame(nsStyleContext* aContext);
   ~nsGfxRadioControlFrame();
 
-   //nsIRadioControlFrame methods
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
+  
+  //nsIRadioControlFrame methods
   NS_IMETHOD SetRadioButtonFaceStyleContext(nsStyleContext *aRadioButtonFaceStyleContext);
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
   virtual nsStyleContext* GetAdditionalStyleContext(PRInt32 aIndex) const;
   virtual void SetAdditionalStyleContext(PRInt32 aIndex,
@@ -76,16 +77,12 @@ public:
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   void PaintRadioButtonFromStyle(nsIRenderingContext& aRenderingContext, nsPoint aPt,
                                  const nsRect& aDirtyRect);
 
 protected:
   nsRefPtr<nsStyleContext> mRadioButtonFaceStyle;
-
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; }
-  NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; }
 };
 
 #endif
 
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -100,41 +100,19 @@ nsHTMLButtonControlFrame::Init(
 {
   nsresult  rv = nsHTMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
   if (NS_SUCCEEDED(rv)) {
     mRenderer.SetFrame(this, PresContext());
   }
   return rv;
 }
 
-nsrefcnt nsHTMLButtonControlFrame::AddRef(void)
-{
-  NS_WARNING("not supported");
-  return 1;
-}
-
-nsrefcnt nsHTMLButtonControlFrame::Release(void)
-{
-  NS_WARNING("not supported");
-  return 1;
-}
-
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsHTMLButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     nsIContent* content = GetContent();
--- a/layout/forms/nsHTMLButtonControlFrame.h
+++ b/layout/forms/nsHTMLButtonControlFrame.h
@@ -60,17 +60,17 @@ class nsHTMLButtonControlFrame : public 
 {
 public:
   nsHTMLButtonControlFrame(nsStyleContext* aContext);
   ~nsHTMLButtonControlFrame();
 
 
   virtual void Destroy();
 
-  NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
 
   virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
@@ -137,19 +137,16 @@ protected:
   virtual PRBool IsSubmit(PRInt32 type);
   void ReflowButtonContents(nsPresContext* aPresContext,
                             nsHTMLReflowMetrics& aDesiredSize,
                             const nsHTMLReflowState& aReflowState,
                             nsIFrame* aFirstKid,
                             nsMargin aFocusPadding,
                             nsReflowStatus& aStatus);
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
-
   PRIntn GetSkipSides() const;
   nsButtonFrameRenderer mRenderer;
 };
 
 #endif
 
 
 
--- a/layout/forms/nsICheckboxControlFrame.h
+++ b/layout/forms/nsICheckboxControlFrame.h
@@ -33,44 +33,35 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsICheckControlFrame_h___
 #define nsICheckControlFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 class nsStyleContext;
 class nsPresContext;
 
-// IID for the nsICheckControlFrame class
-// {401347ED-0101-11d4-9706-0060B0FB9956}
-#define NS_ICHECKBOXCONTROLFRAME_IID    \
-{ 0x401347ed, 0x101, 0x11d4,  \
-  { 0x97, 0x6, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
-
 /** 
   * nsICheckControlFrame is the common interface radio buttons.
   * @see nsFromControlFrame and its base classes for more info
   */
-class nsICheckboxControlFrame : public nsISupports {
-
+class nsICheckboxControlFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICHECKBOXCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsICheckboxControlFrame)
 
   /**
    * Sets the Pseudo Style Contexts for the Check button
    */
   NS_IMETHOD SetCheckboxFaceStyleContext(
                  nsStyleContext* aCheckboxFaceStyleContext) = 0;
   
   /**
    * Called by content when checkbox "checked" changes
    */
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICheckboxControlFrame,
-                              NS_ICHECKBOXCONTROLFRAME_IID)
-
 #endif
 
--- a/layout/forms/nsIComboboxControlFrame.h
+++ b/layout/forms/nsIComboboxControlFrame.h
@@ -33,40 +33,34 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIComboboxControlFrame_h___
 #define nsIComboboxControlFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsFont.h"
 
 class nsPresContext;
 class nsString;
 class nsIContent;
 class nsVoidArray;
 class nsCSSFrameConstructor;
 
-
-// IID for the nsIComboboxControlFrame class
-#define NS_ICOMBOBOXCONTROLFRAME_IID    \
-  { 0x23f75e9c, 0x6850, 0x11da, \
-      { 0x95, 0x2c, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f } }
-
 /** 
   * nsIComboboxControlFrame is the common interface for frames of form controls. It
   * provides a uniform way of creating widgets, resizing, and painting.
   * @see nsLeafFrame and its base classes for more info
   */
-class nsIComboboxControlFrame : public nsISupports {
-
+class nsIComboboxControlFrame : public nsQueryFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICOMBOBOXCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIComboboxControlFrame)
 
   /**
    * Indicates whether the list is dropped down
    */
   virtual PRBool IsDroppedDown() = 0;
 
   /**
    * Shows or hides the drop down
@@ -122,13 +116,10 @@ public:
    * selection or not. This method is used to get the current index in the combobox to
    * compare it to the current index in the dropdown to see if the combox has been updated
    * and that way it knows whether to "cancel" the current selection residing in the 
    * dropdown. Or whether to leave the selection alone.
    */
   virtual PRInt32 GetIndexOfDisplayArea() = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIComboboxControlFrame,
-                              NS_ICOMBOBOXCONTROLFRAME_IID)
-
 #endif
 
--- a/layout/forms/nsIFormControlFrame.h
+++ b/layout/forms/nsIFormControlFrame.h
@@ -33,36 +33,31 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIFormControlFrame_h___
 #define nsIFormControlFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 class nsAString;
 class nsIContent;
 class nsIAtom;
 struct nsSize;
 
-// IID for the nsIFormControlFrame class
-#define NS_IFORMCONTROLFRAME_IID    \
-  { 0x189e1565, 0x44f, 0x11da, \
-      { 0x94, 0xfc, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f } }
-
 /** 
   * nsIFormControlFrame is the common interface for frames of form controls. It
   * provides a uniform way of creating widgets, resizing, and painting.
   * @see nsLeafFrame and its base classes for more info
   */
-class nsIFormControlFrame : public nsISupports {
-
+class nsIFormControlFrame : public nsQueryFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFORMCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIFormControlFrame)
 
   /**
    * 
    * @param aOn
    * @param aRepaint
    */
   virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE) = 0;
 
@@ -81,12 +76,10 @@ public:
    * @param aName name of the property to get.
    * @param aValue Value to set.
    * @returns NS_OK if the property name is valid, otherwise an error code.
    */
 
   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIFormControlFrame, NS_IFORMCONTROLFRAME_IID)
-
 #endif
 
--- a/layout/forms/nsIListControlFrame.h
+++ b/layout/forms/nsIListControlFrame.h
@@ -33,34 +33,29 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIListControlFrame_h___
 #define nsIListControlFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsFont.h"
 class nsPresContext;
 class nsAString;
 class nsIContent;
 
-// IID for the nsIListControlFrame class
-#define NS_ILISTCONTROLFRAME_IID    \
-{ 0x4de9ab73, 0x31b5, 0x4d92, \
- { 0xb7, 0xe4, 0x73, 0xb4, 0x4d, 0xcb, 0xfc, 0xda } }
-
 /** 
   * nsIListControlFrame is the interface for frame-based listboxes.
   */
-class nsIListControlFrame : public nsISupports {
-
+class nsIListControlFrame : public nsQueryFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILISTCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIListControlFrame)
 
   /**
    * Sets the ComboBoxFrame
    *
    */
   virtual void SetComboboxFrame(nsIFrame* aComboboxFrame) = 0;
 
   /**
@@ -121,12 +116,10 @@ public:
   virtual void ComboboxFinish(PRInt32 aIndex) = 0;
 
   /**
    * Notification that the content has been reset
    */
   virtual void OnContentReset() = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIListControlFrame, NS_ILISTCONTROLFRAME_IID)
-
 #endif
 
--- a/layout/forms/nsIRadioControlFrame.h
+++ b/layout/forms/nsIRadioControlFrame.h
@@ -33,43 +33,34 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIRadioControlFrame_h___
 #define nsIRadioControlFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 class nsStyleContext;
 
-// IID for the nsIRadioControlFrame class
-// {06450E00-24D9-11d3-966B-00105A1B1B76}
-#define NS_IRADIOCONTROLFRAME_IID    \
-{ 0x6450e00, 0x24d9, 0x11d3,  \
-  { 0x96, 0x6b, 0x0, 0x10, 0x5a, 0x1b, 0x1b, 0x76 } }
-
-
 /** 
   * nsIRadioControlFrame is the common interface radio buttons.
   * @see nsFormControlFrame and its base classes for more info
   */
-class nsIRadioControlFrame : public nsISupports {
-
+class nsIRadioControlFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IRADIOCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIRadioControlFrame)
 
   /**
    * Sets the Pseudo Style Contexts for the Radio button
    */
 
    NS_IMETHOD SetRadioButtonFaceStyleContext(nsStyleContext *aRadioButtonFaceStyleContext) = 0;
 
    /**
     * Called by content when the radio button's state changes
     */
    NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIRadioControlFrame, NS_IRADIOCONTROLFRAME_IID)
-
 #endif
 
--- a/layout/forms/nsISelectControlFrame.h
+++ b/layout/forms/nsISelectControlFrame.h
@@ -34,33 +34,27 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsISelectControlFrame_h___
 #define nsISelectControlFrame_h___
 
-#include "nsISupports.h"
-
-// IID for the nsISelectControlFrame class
-// f8a1b329-d0d8-4bd5-a9ab-08c3c0f2f166
-#define NS_ISELECTCONTROLFRAME_IID \
-{ 0xf8a1b329, 0xd0d8, 0x4bd5, \
- { 0xa9, 0xab, 0x08, 0xc3, 0xc0, 0xf2, 0xf1, 0x66 } }
+#include "nsQueryFrame.h"
 
 class nsIDOMHTMLOptionElement;
 
 /** 
   * nsISelectControlFrame is the interface for combo boxes and listboxes
   */
-class nsISelectControlFrame : public nsISupports {
-
+class nsISelectControlFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISELECTCONTROLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISelectControlFrame)
 
   /**
    * Adds an option to the list at index
    */
 
   NS_IMETHOD AddOption(nsPresContext* aPresContext, PRInt32 index) = 0;
 
   /**
@@ -89,12 +83,9 @@ public:
 
   /**
    * Notify the frame when selectedIndex was changed
    */
   NS_IMETHOD OnSetSelectedIndex(PRInt32 aOldIndex, PRInt32 aNewIndex) = 0;
 
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISelectControlFrame,
-                              NS_ISELECTCONTROLFRAME_IID)
-
 #endif
--- a/layout/forms/nsITextControlFrame.h
+++ b/layout/forms/nsITextControlFrame.h
@@ -40,25 +40,20 @@
  
 #include "nsIFormControlFrame.h"
 
 class nsIEditor;
 class nsIDocShell;
 class nsISelectionController;
 class nsFrameSelection;
 
-#define NS_IGFXTEXTCONTROLFRAME2_IID \
-{/* 0c3b64da-4431-11da-94fd-00e08161165f*/ \
-0xc3b64da, 0x4431, 0x11da, \
-{ 0x94, 0xfd, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f } }
-
 class nsITextControlFrame : public nsIFormControlFrame
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGFXTEXTCONTROLFRAME2_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsITextControlFrame)
 
   NS_IMETHOD    GetEditor(nsIEditor **aEditor) = 0;
 
   /**
    * Tell whether the frame currently owns the value or the content does (for
    * edge cases where the frame has just been created or is just going away).
    *
    * @param aOwnsValue whether the frame owns the value [out]
@@ -89,12 +84,9 @@ public:
   NS_IMETHOD    GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0;
 
   virtual nsISelectionController* GetOwnedSelectionController() = 0;
   virtual nsFrameSelection* GetOwnedFrameSelection() = 0;
 
   virtual nsresult GetPhonetic(nsAString& aPhonetic) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsITextControlFrame,
-                              NS_IGFXTEXTCONTROLFRAME2_IID)
-
 #endif
--- a/layout/forms/nsImageControlFrame.cpp
+++ b/layout/forms/nsImageControlFrame.cpp
@@ -76,17 +76,18 @@ class nsImageControlFrame : public nsIma
 public:
   nsImageControlFrame(nsStyleContext* aContext);
   ~nsImageControlFrame();
 
   virtual void Destroy();
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+
+  NS_DECL_QUERYFRAME
 
   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
 
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
                          nsGUIEvent* aEvent,
@@ -105,20 +106,16 @@ public:
 #endif
 
   NS_IMETHOD GetCursor(const nsPoint&    aPoint,
                        nsIFrame::Cursor& aCursor);
   // nsIFormContromFrame
   virtual void SetFocus(PRBool aOn, PRBool aRepaint);
   virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const; 
-
-protected:
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
 };
 
 
 nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext):
   nsImageControlFrameSuper(aContext)
 {
 }
 
@@ -155,29 +152,19 @@ nsImageControlFrame::Init(nsIContent*   
     return NS_OK;
   }
   
   return  mContent->SetProperty(nsGkAtoms::imageClickedPoint,
                                  new nsIntPoint(0, 0),
                                  IntPointDtorFunc);
 }
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  } 
-
-  return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsImageControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     if (mContent->Tag() == nsGkAtoms::button) {
@@ -187,28 +174,16 @@ NS_IMETHODIMP nsImageControlFrame::GetAc
       return accService->CreateHTMLButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
-nsrefcnt nsImageControlFrame::AddRef(void)
-{
-  NS_WARNING("not supported");
-  return 1;
-}
-
-nsrefcnt nsImageControlFrame::Release(void)
-{
-  NS_WARNING("not supported");
-  return 1;
-}
-
 nsIAtom*
 nsImageControlFrame::GetType() const
 {
   return nsGkAtoms::imageControlFrame; 
 }
 
 NS_METHOD
 nsImageControlFrame::Reflow(nsPresContext*         aPresContext,
--- a/layout/forms/nsIsIndexFrame.cpp
+++ b/layout/forms/nsIsIndexFrame.cpp
@@ -142,17 +142,18 @@ nsIsIndexFrame::UpdatePromptLabel(PRBool
 nsresult
 nsIsIndexFrame::GetInputFrame(nsIFormControlFrame** oFrame)
 {
   nsIPresShell *presShell = PresContext()->GetPresShell();
   if (!mInputContent) NS_WARNING("null content - cannot restore state");
   if (presShell && mInputContent) {
     nsIFrame *frame = presShell->GetPrimaryFrameFor(mInputContent);
     if (frame) {
-      return CallQueryInterface(frame, oFrame);
+      *oFrame = do_QueryFrame(frame);
+      return *oFrame ? NS_OK : NS_NOINTERFACE;
     }
   }
   return NS_OK;
 }
 
 void
 nsIsIndexFrame::GetInputValue(nsString& oString)
 {
@@ -228,40 +229,37 @@ nsIsIndexFrame::CreateAnonymousContent(n
   // Create an hr
   NS_NewHTMLElement(getter_AddRefs(mPostHr), hrInfo, PR_FALSE);
   if (!mPostHr || !aElements.AppendElement(mPostHr))
     return NS_ERROR_OUT_OF_MEMORY;
 
   return NS_OK;
 }
 
+NS_QUERYFRAME_HEAD(nsIsIndexFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
+
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsIsIndexFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
   NS_PRECONDITION(aInstancePtr, "null out param");
 
-  if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
-    *aInstancePtr = static_cast<nsIAnonymousContentCreator*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
-    *aInstancePtr = static_cast<nsIStatefulFrame*>(this);
-    return NS_OK;
-  }
   if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) {
     *aInstancePtr = static_cast<nsIDOMKeyListener*>(this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIDOMEventListener))) {
     *aInstancePtr = static_cast<nsIDOMEventListener*>(this);
     return NS_OK;
   }
 
-  return nsBlockFrame::QueryInterface(aIID, aInstancePtr);
+  return NS_NOINTERFACE;
 }
 
 nscoord
 nsIsIndexFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
 {
   nscoord result;
   DISPLAY_MIN_WIDTH(this, result);
 
--- a/layout/forms/nsIsIndexFrame.h
+++ b/layout/forms/nsIsIndexFrame.h
@@ -76,19 +76,22 @@ public:
   /**
    * Processes a key typed event
    * @param aKeyEvent @see nsIDOMEvent.h 
    * @returns whether the event was consumed or ignored. @see nsresult
    *
    */
   NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent); // we only care when a key is pressed
 
-  // nsIFormControlFrame
+  NS_DECL_QUERYFRAME
+
+  // nsISupports
   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
 
+  // nsIFormControlFrame
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
   
   virtual PRBool IsLeaf() const;
 
 #ifdef NS_DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
--- a/layout/forms/nsLegendFrame.cpp
+++ b/layout/forms/nsLegendFrame.cpp
@@ -47,18 +47,16 @@
 #include "nsIAtom.h"
 #include "nsGenericHTMLElement.h"
 #include "nsHTMLParts.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsFont.h"
 #include "nsFormControlFrame.h"
 
-static NS_DEFINE_IID(kLegendFrameCID, NS_LEGEND_FRAME_CID);
- 
 nsIFrame*
 NS_NewLegendFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   nsIFrame* f = new (aPresShell) nsLegendFrame(aContext);
   if (f) {
     f->AddStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
   }
   return f;
@@ -72,29 +70,19 @@ nsLegendFrame::GetType() const
 
 void
 nsLegendFrame::Destroy()
 {
   nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
   nsBlockFrame::Destroy();
 }
 
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsLegendFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(kLegendFrameCID)) {
-    *aInstancePtr = this;
-    return NS_OK;
-  }
-
-  return nsBlockFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsLegendFrame)
+  NS_QUERYFRAME_ENTRY(nsLegendFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
 
 NS_IMETHODIMP 
 nsLegendFrame::Reflow(nsPresContext*          aPresContext,
                      nsHTMLReflowMetrics&     aDesiredSize,
                      const nsHTMLReflowState& aReflowState,
                      nsReflowStatus&          aStatus)
 {
   DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
--- a/layout/forms/nsLegendFrame.h
+++ b/layout/forms/nsLegendFrame.h
@@ -44,24 +44,23 @@
 
 class  nsIContent;
 class  nsIFrame;
 class  nsPresContext;
 struct nsHTMLReflowMetrics;
 class  nsIRenderingContext;
 struct nsRect;
 
-#define NS_LEGEND_FRAME_CID \
-{ 0x73805d40, 0x5a24, 0x11d2, { 0x80, 0x46, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } }
-
 class nsLegendFrame : public nsBlockFrame {
 public:
+  NS_DECLARE_FRAME_ACCESSOR(nsLegendFrame)
+
   nsLegendFrame(nsStyleContext* aContext) : nsBlockFrame(aContext) {}
 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
 
   virtual void Destroy();
 
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -381,38 +381,21 @@ nsListControlFrame::InvalidateFocus()
     // The origin of the scrollport is the origin of containerFrame.
     nsRect invalidateArea = containerFrame->GetOverflowRect();
     nsRect emptyFallbackArea(0, 0, GetScrollPortSize().width, CalcFallbackRowHeight());
     invalidateArea.UnionRect(invalidateArea, emptyFallbackArea);
     containerFrame->Invalidate(invalidateArea);
   }
 }
 
-//---------------------------------------------------------
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsIListControlFrame))) {
-    *aInstancePtr = static_cast<nsIListControlFrame*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsISelectControlFrame))) {
-    *aInstancePtr = static_cast<nsISelectControlFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsHTMLScrollFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsListControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIListControlFrame)
+  NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLScrollFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
@@ -1361,17 +1344,17 @@ void nsListControlFrame::ComboboxFocusSe
 {
   gLastKeyTime = 0;
 }
 
 void
 nsListControlFrame::SetComboboxFrame(nsIFrame* aComboboxFrame)
 {
   if (nsnull != aComboboxFrame) {
-    aComboboxFrame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame),(void**) &mComboboxFrame); 
+    mComboboxFrame = do_QueryFrame(aComboboxFrame);
   }
 }
 
 void
 nsListControlFrame::GetOptionText(PRInt32 aIndex, nsAString & aStr)
 {
   aStr.SetLength(0);
   nsCOMPtr<nsIDOMHTMLOptionsCollection> options = GetOptions(mContent);
@@ -2196,18 +2179,17 @@ nsListControlFrame::MouseDown(nsIDOMEven
     if (mComboboxFrame) {
       if (!IgnoreMouseEventForSelection(aMouseEvent)) {
         return NS_OK;
       }
 
       if (!nsComboboxControlFrame::ToolkitHasNativePopup())
       {
         PRBool isDroppedDown = mComboboxFrame->IsDroppedDown();
-        nsIFrame* comboFrame;
-        CallQueryInterface(mComboboxFrame, &comboFrame);
+        nsIFrame* comboFrame = do_QueryFrame(mComboboxFrame);
         nsWeakFrame weakFrame(comboFrame);
         mComboboxFrame->ShowDropDown(!isDroppedDown);
         if (!weakFrame.IsAlive())
           return NS_OK;
         if (isDroppedDown) {
           CaptureMouseEvents(PR_FALSE);
         }
       }
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -75,18 +75,17 @@ class nsListEventListener;
 class nsListControlFrame : public nsHTMLScrollFrame,
                            public nsIFormControlFrame, 
                            public nsIListControlFrame,
                            public nsISelectControlFrame
 {
 public:
   friend nsIFrame* NS_NewListControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-   // nsISupports
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
     // nsIFrame
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
                          nsGUIEvent* aEvent,
                          nsEventStatus* aEventStatus);
   
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsIFrame*       aChildList);
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -999,44 +999,23 @@ nsTextInputSelectionImpl::CheckVisibilit
 }
 
 nsIFrame*
 NS_NewTextControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsTextControlFrame(aPresShell, aContext);
 }
 
-NS_IMPL_ADDREF_INHERITED(nsTextControlFrame, nsBoxFrame)
-NS_IMPL_RELEASE_INHERITED(nsTextControlFrame, nsBoxFrame)
- 
-
-NS_IMETHODIMP
-nsTextControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = static_cast<nsIFormControlFrame*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
-    *aInstancePtr = static_cast<nsIAnonymousContentCreator*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsITextControlFrame))) {
-    *aInstancePtr = static_cast<nsITextControlFrame*>(this);
-    return NS_OK;
-  }
-  if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider)) && IsScrollable()) {
-    *aInstancePtr = static_cast<nsIScrollableViewProvider*>(this);
-    return NS_OK;
-  }
-
-  return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsTextControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsITextControlFrame)
+  if (nsIScrollableViewProvider::kFrameIID == id && IsScrollable())
+    return static_cast<nsIScrollableViewProvider*>(this);
+NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTextControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLTextFieldAccessible(static_cast<nsIFrame*>(this), aAccessible);
@@ -1389,18 +1368,17 @@ nsTextControlFrame::CalcIntrinsicSize(ns
   // Set the height equal to total number of rows (times the height of each
   // line, of course)
   aIntrinsicSize.height = lineHeight * GetRows();
 
   // Add in the size of the scrollbars for textarea
   if (IsTextArea()) {
     nsIFrame* first = GetFirstChild(nsnull);
 
-    nsIScrollableFrame *scrollableFrame;
-    CallQueryInterface(first, &scrollableFrame);
+    nsIScrollableFrame *scrollableFrame = do_QueryFrame(first);
     NS_ASSERTION(scrollableFrame, "Child must be scrollable");
 
     nsMargin scrollbarSizes =
       scrollableFrame->GetDesiredScrollbarSizes(PresContext(), aRenderingContext);
 
     aIntrinsicSize.width  += scrollbarSizes.LeftRight();
     
     aIntrinsicSize.height += scrollbarSizes.TopBottom();;
@@ -2813,18 +2791,17 @@ nsTextControlFrame::SetInitialChildList(
   //look for scroll view below this frame go along first child list
   nsIFrame* first = GetFirstChild(nsnull);
 
   // Mark the scroll frame as being a reflow root. This will allow
   // incremental reflows to be initiated at the scroll frame, rather
   // than descending from the root frame of the frame hierarchy.
   first->AddStateBits(NS_FRAME_REFLOW_ROOT);
 
-  nsIScrollableFrame *scrollableFrame = nsnull;
-  CallQueryInterface(first, &scrollableFrame);
+  nsIScrollableFrame *scrollableFrame = do_QueryFrame(first);
   NS_ASSERTION(scrollableFrame, "Child must be scrollable");
 
   // we must turn off scrollbars for singleline text controls
   // XXX FIXME this should be removed,
   // nsGfxScrollFrameInner::CreateAnonymousContent handles this
   if (IsSingleLineTextControl()) 
   {
     if (scrollableFrame)
@@ -2859,20 +2836,17 @@ nsTextControlFrame::SetInitialChildList(
   }
 
   return rv;
 }
 
 nsIScrollableView* nsTextControlFrame::GetScrollableView()
 {
   nsIFrame* first = GetFirstChild(nsnull);
-  nsIScrollableFrame* scrollableFrame = nsnull;
-  if (first) {
-    CallQueryInterface(first, &scrollableFrame);
-  }
+  nsIScrollableFrame* scrollableFrame = do_QueryFrame(first);
   return scrollableFrame ? scrollableFrame->GetScrollableView() : nsnull;
 }
 
 PRBool
 nsTextControlFrame::IsScrollable() const
 {
   return !IsSingleLineTextControl();
 }
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -163,17 +163,17 @@ public:
 
   /** handler for attribute changes to mContent */
   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
                               nsIAtom*        aAttribute,
                               PRInt32         aModType);
 
   NS_IMETHOD GetText(nsString* aText);
 
-  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_QUERYFRAME
 
 public: //for methods who access nsTextControlFrame directly
   /**
    * Find out whether this is a single line text control.  (text or password)
    * @return whether this is a single line text control
    */
   PRBool IsSingleLineTextControl() const;
   /**
--- a/layout/generic/Makefile.in
+++ b/layout/generic/Makefile.in
@@ -78,16 +78,17 @@ REQUIRES	= xpcom \
 		  cairo \
 		  $(NULL)
 
 ifdef ACCESSIBILITY
 REQUIRES	+= accessibility
 endif
 
 EXPORTS		= \
+		nsQueryFrame.h \
 		nsFrameList.h \
 		nsHTMLParts.h \
 		nsHTMLReflowMetrics.h \
 		nsHTMLReflowState.h \
 		nsIAnonymousContentCreator.h \
 		nsICanvasFrame.h \
 		nsIFrame.h \
 		nsIFrameDebug.h \
--- a/layout/generic/nsAbsoluteContainingBlock.cpp
+++ b/layout/generic/nsAbsoluteContainingBlock.cpp
@@ -364,18 +364,18 @@ nsAbsoluteContainingBlock::ReflowAbsolut
                                                nsReflowStatus&          aStatus,
                                                nsRect*                  aChildBounds)
 {
 #ifdef DEBUG
   if (nsBlockFrame::gNoisyReflow) {
     nsFrame::IndentBy(stdout,nsBlockFrame::gNoiseIndent);
     printf("abs pos ");
     if (nsnull != aKidFrame) {
-      nsIFrameDebug*  frameDebug;
-      if (NS_SUCCEEDED(CallQueryInterface(aKidFrame, &frameDebug))) {
+      nsIFrameDebug *frameDebug = do_QueryFrame(aKidFrame);
+      if (frameDebug) {
         nsAutoString name;
         frameDebug->GetFrameName(name);
         printf("%s ", NS_LossyConvertUTF16toASCII(name).get());
       }
     }
 
     char width[16];
     char height[16];
@@ -508,18 +508,18 @@ nsAbsoluteContainingBlock::ReflowAbsolut
   }
   aKidFrame->DidReflow(aPresContext, &kidReflowState, NS_FRAME_REFLOW_FINISHED);
 
 #ifdef DEBUG
   if (nsBlockFrame::gNoisyReflow) {
     nsFrame::IndentBy(stdout,nsBlockFrame::gNoiseIndent - 1);
     printf("abs pos ");
     if (nsnull != aKidFrame) {
-      nsIFrameDebug*  frameDebug;
-      if (NS_SUCCEEDED(CallQueryInterface(aKidFrame, &frameDebug))) {
+      nsIFrameDebug *frameDebug = do_QueryFrame(aKidFrame);
+      if (frameDebug) {
         nsAutoString name;
         frameDebug->GetFrameName(name);
         printf("%s ", NS_LossyConvertUTF16toASCII(name).get());
       }
     }
     printf("%p rect=%d,%d,%d,%d", aKidFrame, rect.x, rect.y, rect.width, rect.height);
     printf("\n");
   }
--- a/layout/generic/nsBRFrame.cpp
+++ b/layout/generic/nsBRFrame.cpp
@@ -276,12 +276,12 @@ NS_IMETHODIMP BRFrame::GetAccessible(nsI
   nsIContent *parent = mContent->GetParent();
   if (parent &&
       parent->IsRootOfNativeAnonymousSubtree() &&
       parent->GetChildCount() == 1) {
     // This <br> is the only node in a text control, therefore it is the hacky
     // "bogus node" used when there is no text in the control
     return NS_ERROR_FAILURE;
   }
-  return accService->CreateHTMLBRAccessible(static_cast<nsIFrame*>(this), aAccessible);
+  return accService->CreateHTMLBRAccessible(this, aAccessible);
 }
 #endif
 
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -261,18 +261,16 @@ RecordReflowStatus(PRBool aChildIsBlock,
     record[index] = newS;
     printf("record(%d): %02x %02x\n", index, record[0], record[1]);
   }
 }
 #endif
 
 //----------------------------------------------------------------------
 
-const nsIID kBlockFrameCID = NS_BLOCK_FRAME_CID;
-
 nsIFrame*
 NS_NewBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags)
 {
   nsBlockFrame* it = new (aPresShell) nsBlockFrame(aContext);
   if (it) {
     it->SetFlags(aFlags);
   }
   return it;
@@ -325,27 +323,19 @@ nsBlockFrame::GetLineIterator()
   nsresult rv = it->Init(mLines, visibility->mDirection == NS_STYLE_DIRECTION_RTL);
   if (NS_FAILED(rv)) {
     delete it;
     return nsnull;
   }
   return it;
 }
 
-NS_IMETHODIMP
-nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(kBlockFrameCID)) {
-    *aInstancePtr = static_cast<void*>(static_cast<nsBlockFrame*>(this));
-    return NS_OK;
-  }
-  return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsBlockFrame)
+  NS_QUERYFRAME_ENTRY(nsBlockFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrameSuper)
 
 nsSplittableType
 nsBlockFrame::GetSplittableType() const
 {
   return NS_FRAME_SPLITTABLE_NON_RECTANGULAR;
 }
 
 #ifdef DEBUG
@@ -444,19 +434,18 @@ nsBlockFrame::List(FILE* out, PRInt32 aI
       IndentBy(out, aIndent);
       nsAutoString tmp;
       if (nsnull != listName) {
         listName->ToString(tmp);
         fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
       }
       fputs("<\n", out);
       while (kid) {
-        nsIFrameDebug*  frameDebug;
-
-        if (NS_SUCCEEDED(CallQueryInterface(kid, &frameDebug))) {
+        nsIFrameDebug *frameDebug = do_QueryFrame(kid);
+        if (frameDebug) {
           frameDebug->List(out, aIndent + 1);
         }
         kid = kid->GetNextSibling();
       }
       IndentBy(out, aIndent);
       fputs(">\n", out);
     }
   }
@@ -827,18 +816,17 @@ CalculateContainingBlockSizeForAbsolutes
     while (aLastRS->parentReflowState &&
            aLastRS->parentReflowState->frame->GetContent() == frame->GetContent()) {
       lastButOneRS = aLastRS;
       aLastRS = aLastRS->parentReflowState;
     }
     if (aLastRS != &aReflowState) {
       // Scrollbars need to be specifically excluded, if present, because they are outside the
       // padding-edge. We need better APIs for getting the various boxes from a frame.
-      nsIScrollableFrame* scrollFrame;
-      CallQueryInterface(aLastRS->frame, &scrollFrame);
+      nsIScrollableFrame* scrollFrame = do_QueryFrame(aLastRS->frame);
       nsMargin scrollbars(0,0,0,0);
       if (scrollFrame) {
         scrollbars =
           scrollFrame->GetDesiredScrollbarSizes(aLastRS->frame->PresContext(),
                                                 aLastRS->rendContext);
         if (!lastButOneRS->mFlags.mAssumingHScrollbar) {
           scrollbars.top = scrollbars.bottom = 0;
         }
--- a/layout/generic/nsBlockFrame.h
+++ b/layout/generic/nsBlockFrame.h
@@ -122,49 +122,46 @@ class nsIntervalSet;
 
 // Set on any block that has descendant frames in the normal
 // flow with 'clear' set to something other than 'none'
 // (including <BR CLEAR="..."> frames)
 #define NS_BLOCK_HAS_CLEAR_CHILDREN         0x10000000
 
 #define nsBlockFrameSuper nsHTMLContainerFrame
 
-#define NS_BLOCK_FRAME_CID \
- { 0xa6cf90df, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
-
-extern const nsIID kBlockFrameCID;
-
 /*
  * Base class for block and inline frames.
  * The block frame has an additional named child list:
  * - "Absolute-list" which contains the absolutely positioned frames
  *
  * @see nsGkAtoms::absoluteList
  */ 
 class nsBlockFrame : public nsBlockFrameSuper
 {
 public:
+  NS_DECLARE_FRAME_ACCESSOR(nsBlockFrame)
+
   typedef nsLineList::iterator                  line_iterator;
   typedef nsLineList::const_iterator            const_line_iterator;
   typedef nsLineList::reverse_iterator          reverse_line_iterator;
   typedef nsLineList::const_reverse_iterator    const_reverse_line_iterator;
 
   line_iterator begin_lines() { return mLines.begin(); }
   line_iterator end_lines() { return mLines.end(); }
   const_line_iterator begin_lines() const { return mLines.begin(); }
   const_line_iterator end_lines() const { return mLines.end(); }
   reverse_line_iterator rbegin_lines() { return mLines.rbegin(); }
   reverse_line_iterator rend_lines() { return mLines.rend(); }
   const_reverse_line_iterator rbegin_lines() const { return mLines.rbegin(); }
   const_reverse_line_iterator rend_lines() const { return mLines.rend(); }
 
   friend nsIFrame* NS_NewBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
 
-  // nsISupports
-  NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  // nsQueryFrame
+  NS_DECL_QUERYFRAME
 
   // nsIFrame
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsIFrame*       aChildList);
   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -1638,18 +1638,18 @@ nsContainerFrame::List(FILE* out, PRInt3
         fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
       }
       fputs("<\n", out);
       while (nsnull != kid) {
         // Verify the child frame's parent frame pointer is correct
         NS_ASSERTION(kid->GetParent() == (nsIFrame*)this, "bad parent frame pointer");
 
         // Have the child frame list
-        nsIFrameDebug*  frameDebug;
-        if (NS_SUCCEEDED(kid->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+        nsIFrameDebug *frameDebug = do_QueryFrame(kid);
+        if (frameDebug) {
           frameDebug->List(out, aIndent + 1);
         }
         kid = kid->GetNextSibling();
       }
       IndentBy(out, aIndent);
       fputs(">\n", out);
     }
     listName = GetAdditionalChildListName(listIndex++);
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -367,17 +367,16 @@ nsFloatManager::List(FILE* out) const
 
   for (PRUint32 i = 0; i < mFloats.Length(); ++i) {
     const FloatInfo &fi = mFloats[i];
     printf("Float %u: frame=%p rect={%d,%d,%d,%d} ymost={l:%d, r:%d}\n",
            i, static_cast<void*>(fi.mFrame),
            fi.mRect.x, fi.mRect.y, fi.mRect.width, fi.mRect.height,
            fi.mLeftYMost, fi.mRightYMost);
   }
-
   return NS_OK;
 }
 #endif
 
 nscoord
 nsFloatManager::ClearFloats(nscoord aY, PRUint8 aBreakType) const
 {
   if (!HasAnyFloats()) {
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -268,20 +268,18 @@ nsIFrameDebug::RootFrameList(nsPresConte
 {
   if((nsnull == aPresContext) || (nsnull == out))
     return;
 
   nsIPresShell *shell = aPresContext->GetPresShell();
   if (nsnull != shell) {
     nsIFrame* frame = shell->FrameManager()->GetRootFrame();
     if(nsnull != frame) {
-      nsIFrameDebug* debugFrame;
-      nsresult rv;
-      rv = frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&debugFrame);
-      if(NS_SUCCEEDED(rv))
+      nsIFrameDebug* debugFrame = do_QueryFrame(frame);
+      if (debugFrame)
         debugFrame->List(out, aIndent);
     }
   }
 }
 #endif
 // end nsIFrameDebug
 
 void
@@ -361,52 +359,22 @@ nsFrame::~nsFrame()
 {
   MOZ_COUNT_DTOR(nsFrame);
 
   NS_IF_RELEASE(mContent);
   if (mStyleContext)
     mStyleContext->Release();
 }
 
-/////////////////////////////////////////////////////////////////////////////
-// nsISupports
-
-NS_IMETHODIMP
-nsFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
+NS_QUERYFRAME_HEAD(nsFrame)
+  NS_QUERYFRAME_ENTRY(nsIFrame)
 #ifdef DEBUG
-  if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
-    *aInstancePtr = static_cast<nsIFrameDebug*>(this);
-    return NS_OK;
-  }
+  NS_QUERYFRAME_ENTRY(nsIFrameDebug)
 #endif
-
-  if (aIID.Equals(NS_GET_IID(nsIFrame)) ||
-      aIID.Equals(NS_GET_IID(nsISupports))) {
-    *aInstancePtr = static_cast<nsIFrame*>(this);
-    return NS_OK;
-  }
-
-  *aInstancePtr = nsnull;
-  return NS_ERROR_NO_INTERFACE;
-}
-
-nsrefcnt nsFrame::AddRef(void)
-{
-  NS_WARNING("not supported for frames");
-  return 1;
-}
-
-nsrefcnt nsFrame::Release(void)
-{
-  NS_WARNING("not supported for frames");
-  return 1;
-}
+NS_QUERYFRAME_TAIL
 
 /////////////////////////////////////////////////////////////////////////////
 // nsIFrame
 
 NS_IMETHODIMP
 nsFrame::Init(nsIContent*      aContent,
               nsIFrame*        aParent,
               nsIFrame*        aPrevInFlow)
@@ -1720,33 +1688,31 @@ nsFrame::GetDataForTableSelection(const 
   //PRBool selectColumn = PR_FALSE;
   //PRBool selectRow = PR_FALSE;
   
   result = NS_OK;
 
   while (frame && NS_SUCCEEDED(result))
   {
     // Check for a table cell by querying to a known CellFrame interface
-    nsITableCellLayout *cellElement;
-    result = (frame)->QueryInterface(NS_GET_IID(nsITableCellLayout), (void **)&cellElement);
-    if (NS_SUCCEEDED(result) && cellElement)
+    nsITableCellLayout *cellElement = do_QueryFrame(frame);
+    if (cellElement)
     {
       foundCell = PR_TRUE;
       //TODO: If we want to use proximity to top or left border
       //      for row and column selection, this is the place to do it
       break;
     }
     else
     {
       // If not a cell, check for table
       // This will happen when starting frame is the table or child of a table,
       //  such as a row (we were inbetween cells or in table border)
-      nsITableLayout *tableElement;
-      result = (frame)->QueryInterface(NS_GET_IID(nsITableLayout), (void **)&tableElement);
-      if (NS_SUCCEEDED(result) && tableElement)
+      nsITableLayout *tableElement = do_QueryFrame(frame);
+      if (tableElement)
       {
         foundTable = PR_TRUE;
         //TODO: How can we select row when along left table edge
         //  or select column when along top edge?
         break;
       } else {
         frame = frame->GetParent();
         result = NS_OK;
@@ -4288,18 +4254,18 @@ nsFrame::IsSelfEmpty()
 NS_IMETHODIMP
 nsFrame::GetSelectionController(nsPresContext *aPresContext, nsISelectionController **aSelCon)
 {
   if (!aPresContext || !aSelCon)
     return NS_ERROR_INVALID_ARG;
 
   nsIFrame *frame = this;
   while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) {
-    nsITextControlFrame *tcf;
-    if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsITextControlFrame),(void**)&tcf))) {
+    nsITextControlFrame *tcf = do_QueryFrame(frame);
+    if (tcf) {
       NS_IF_ADDREF(*aSelCon = tcf->GetOwnedSelectionController());
       return NS_OK;
     }
     frame = frame->GetParent();
   }
 
   return CallQueryInterface(aPresContext->GetPresShell(), aSelCon);
 }
@@ -4313,18 +4279,18 @@ nsIFrame::GetFrameSelection()
   return fs;
 }
 
 const nsFrameSelection*
 nsIFrame::GetConstFrameSelection()
 {
   nsIFrame *frame = this;
   while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) {
-    nsITextControlFrame *tcf;
-    if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsITextControlFrame),(void**)&tcf))) {
+    nsITextControlFrame *tcf = do_QueryFrame(frame);
+    if (tcf) {
       return tcf->GetOwnedFrameSelection();
     }
     frame = frame->GetParent();
   }
 
   return PresContext()->PresShell()->ConstFrameSelection();
 }
 
@@ -4402,19 +4368,18 @@ nsFrame::DumpBaseRegressionData(nsPresCo
         fputs(NS_LossyConvertUTF16toASCII(listName).get(), out);
         fprintf(out, "\">\n");
       }
       else {
         fprintf(out, "<child-list>\n");
       }
       aIndent++;
       while (kid) {
-        nsIFrameDebug*  frameDebug;
-
-        if (NS_SUCCEEDED(kid->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+        nsIFrameDebug* frameDebug = do_QueryFrame(kid);
+        if (kid) {
           frameDebug->DumpRegressionData(aPresContext, out, aIndent, aIncludeStyleData);
         }
         kid = kid->GetNextSibling();
       }
       aIndent--;
       IndentBy(out, aIndent);
       fprintf(out, "</child-list>\n");
     }
@@ -4813,19 +4778,18 @@ FindBlockFrameOrBR(nsIFrame* aFrame, nsD
   result.mContent =  nsnull;
   result.mOffset = 0;
 
   if (aFrame->IsGeneratedContentFrame())
     return result;
 
   // 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))
+  nsIFormControlFrame* fcf = do_QueryFrame(aFrame);
+  if (fcf)
     return result;
   
   // Check the frame itself
   // 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 ((nsLayoutUtils::GetAsBlock(aFrame) && !(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL)) ||
       aFrame->GetType() == nsGkAtoms::brFrame) {
@@ -6081,17 +6045,17 @@ nsIFrame::IsFocusable(PRInt32 *aTabIndex
           !mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
         // Elements with scrollable view are focusable with script & tabbable
         // Otherwise you couldn't scroll them with keyboard, which is
         // an accessibility issue (e.g. Section 508 rules)
         // However, we don't make them to be focusable with the mouse,
         // because the extra focus outlines are considered unnecessarily ugly.
         // When clicked on, the selection position within the element 
         // will be enough to make them keyboard scrollable.
-        nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(this);
+        nsIScrollableFrame *scrollFrame = do_QueryFrame(this);
         if (scrollFrame) {
           nsMargin margin = scrollFrame->GetActualScrollbarSizes();
           if (margin.top || margin.right || margin.bottom || margin.left) {
             // Scroll bars will be used for overflow
             isFocusable = PR_TRUE;
             tabIndex = 0;
           }
         }
@@ -7367,18 +7331,18 @@ void DR_State::DisplayFrameTypeInfo(nsIF
 { 
   DR_FrameTypeInfo* frameTypeInfo = GetFrameTypeInfo(aFrame->GetType());
   if (frameTypeInfo) {
     for (PRInt32 i = 0; i < aIndent; i++) {
       printf(" ");
     }
     if(!strcmp(frameTypeInfo->mNameAbbrev, "unknown")) {
       nsAutoString  name;
-      nsIFrameDebug*  frameDebug;
-      if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+      nsIFrameDebug* frameDebug = do_QueryFrame(aFrame);
+      if (frameDebug) {
        frameDebug->GetFrameName(name);
        printf("%s %p ", NS_LossyConvertUTF16toASCII(name).get(), (void*)aFrame);
       }
       else {
         printf("%s %p ", frameTypeInfo->mNameAbbrev, (void*)aFrame);
       }
     }
     else {
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -151,18 +151,18 @@ public:
   virtual PRBool ComputesOwnOverflowArea() { return PR_TRUE; }
 
 private:
   // The normal operator new is disallowed on nsFrames.
   void* operator new(size_t sz) CPP_THROW_NEW { return nsnull; }
 
 public:
 
-  // nsISupports
-  NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  // nsQueryFrame
+  NS_DECL_QUERYFRAME
 
   // nsIFrame
   NS_IMETHOD  Init(nsIContent*      aContent,
                    nsIFrame*        aParent,
                    nsIFrame*        asPrevInFlow);
   NS_IMETHOD  SetInitialChildList(nsIAtom*        aListName,
                                   nsIFrame*       aChildList);
   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
@@ -437,19 +437,18 @@ public:
   static PRInt32 ContentIndexInContainer(const nsIFrame* aFrame);
 
   void ListTag(FILE* out) const {
     ListTag(out, (nsIFrame*)this);
   }
 
   static void ListTag(FILE* out, nsIFrame* aFrame) {
     nsAutoString tmp;
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(aFrame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+    nsIFrameDebug*  frameDebug = do_QueryFrame(aFrame);
+    if (frameDebug) {
       frameDebug->GetFrameName(tmp);
     }
     fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
     fprintf(out, "@%p", static_cast<void*>(aFrame));
   }
 
   static void IndentBy(FILE* out, PRInt32 aIndent) {
     while (--aIndent >= 0) fputs("  ", out);
@@ -617,20 +616,16 @@ private:
                      nscoord aY,
                      nscoord aWidth,
                      nscoord aHeight,
                      PRBool aMoveFrame = PR_TRUE);
 
   NS_IMETHODIMP RefreshSizeCache(nsBoxLayoutState& aState);
 
   virtual nsILineIterator* GetLineIterator();
-
-protected:
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
 };
 
 // Start Display Reflow Debugging
 #ifdef DEBUG
 
   struct DR_cookie {
     DR_cookie(nsPresContext*          aPresContext,
               nsIFrame*                aFrame, 
--- a/layout/generic/nsFrameFrame.cpp
+++ b/layout/generic/nsFrameFrame.cpp
@@ -115,20 +115,17 @@ class nsSubDocumentFrame : public nsLeaf
 {
 public:
   nsSubDocumentFrame(nsStyleContext* aContext);
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
-  // nsISupports
-  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-  NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; }
-  NS_IMETHOD_(nsrefcnt) Release(void) { return 1; }
+  NS_DECL_QUERYFRAME
 
   virtual nsIAtom* GetType() const;
 
   virtual PRBool IsFrameOfType(PRUint32 aFlags) const
   {
     // nsLeafFrame is already eReplacedContainsBlock, but that's somewhat bogus
     return nsLeafFrame::IsFrameOfType(aFlags &
       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
@@ -237,30 +234,19 @@ NS_IMETHODIMP nsSubDocumentFrame::GetAcc
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(mContent);
     return accService->CreateOuterDocAccessible(node, aAccessible);
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
-//--------------------------------------------------------------
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-nsSubDocumentFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIFrameFrame))) {
-    *aInstancePtr = static_cast<nsIFrameFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsLeafFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsSubDocumentFrame)
+  NS_QUERYFRAME_ENTRY(nsIFrameFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
 
 NS_IMETHODIMP
 nsSubDocumentFrame::Init(nsIContent*     aContent,
                          nsIFrame*       aParent,
                          nsIFrame*       aPrevInFlow)
 {
   // determine if we are a <frame> or <iframe>
   if (aContent) {
@@ -651,20 +637,17 @@ nsSubDocumentFrame::AttributeChanged(PRI
     // Note that we're not doing content type checks, but that's ok -- if
     // they'd fail we will just end up with a null framesetFrame.
     if (mContent->GetParent()->Tag() == nsGkAtoms::frameset) {
       nsIFrame* parentFrame = GetParent();
 
       if (parentFrame) {
         // There is no interface for nsHTMLFramesetFrame so QI'ing to
         // concrete class, yay!
-        nsHTMLFramesetFrame* framesetFrame = nsnull;
-        parentFrame->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame),
-                                    (void **)&framesetFrame);
-
+        nsHTMLFramesetFrame* framesetFrame = do_QueryFrame(parentFrame);
         if (framesetFrame) {
           framesetFrame->RecalculateBorderResize();
         }
       }
     }
   }
   else if (aAttribute == nsGkAtoms::type) {
     if (!mFrameLoader) 
--- a/layout/generic/nsFrameList.cpp
+++ b/layout/generic/nsFrameList.cpp
@@ -409,18 +409,18 @@ nsFrameList::VerifyParent(nsIFrame* aPar
 
 #ifdef NS_DEBUG
 void
 nsFrameList::List(FILE* out) const
 {
   fputs("<\n", out);
   for (nsIFrame* frame = mFirstChild; frame;
        frame = frame->GetNextSibling()) {
-    nsIFrameDebug*  frameDebug;
-    if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+    nsIFrameDebug *frameDebug = do_QueryFrame(frame);
+    if (frameDebug) {
       frameDebug->List(out, 1);
     }
   }
   fputs(">\n", out);
 }
 #endif
 
 #ifdef IBMBIDI
--- a/layout/generic/nsFrameSetFrame.cpp
+++ b/layout/generic/nsFrameSetFrame.cpp
@@ -248,28 +248,19 @@ nsHTMLFramesetFrame::~nsHTMLFramesetFram
   delete[] mChildTypes;
   delete[] mChildFrameborder;
   delete[] mChildBorderColors;
 
   nsContentUtils::UnregisterPrefCallback(kFrameResizePref,
                                          FrameResizePrefCallback, this);
 }
 
-NS_IMETHODIMP
-nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) {
-    *aInstancePtr = (void*)this;
-    return NS_OK;
-  } 
-
-  return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsHTMLFramesetFrame)
+  NS_QUERYFRAME_ENTRY(nsHTMLFramesetFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 // static
 int
 nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure)
 {
   nsHTMLFramesetFrame *frame =
     reinterpret_cast<nsHTMLFramesetFrame *>(aClosure);
 
@@ -306,19 +297,17 @@ nsHTMLFramesetFrame::Init(nsIContent*   
                           nsIFrame*        aPrevInFlow)
 {
   nsHTMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
   // find the highest ancestor that is a frameset
   nsresult rv = NS_OK;
   nsIFrame* parentFrame = GetParent();
   mTopLevelFrameset = (nsHTMLFramesetFrame*)this;
   while (parentFrame) {
-    nsHTMLFramesetFrame* frameset = nsnull;
-    CallQueryInterface(parentFrame, &frameset);
-    
+    nsHTMLFramesetFrame* frameset = do_QueryFrame(parentFrame);
     if (frameset) {
       mTopLevelFrameset = frameset;
       parentFrame = parentFrame->GetParent();
     } else {
       break;
     }
   }
 
@@ -1304,18 +1293,17 @@ nsHTMLFramesetFrame::IsLeaf() const
 {
   // We handle constructing our kids manually
   return PR_TRUE;
 }
 
 PRBool 
 nsHTMLFramesetFrame::ChildIsFrameset(nsIFrame* aChild) 
 {
-  nsIFrame* childFrame = nsnull;
-  aChild->QueryInterface(NS_GET_IID(nsHTMLFramesetFrame), (void**)&childFrame);
+  nsHTMLFramesetFrame* childFrame = do_QueryFrame(aChild);
   if (childFrame) {
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
 
 PRBool 
--- a/layout/generic/nsFrameSetFrame.h
+++ b/layout/generic/nsFrameSetFrame.h
@@ -54,20 +54,16 @@ class  nsIRenderingContext;
 struct nsRect;
 struct nsHTMLReflowState;
 struct nsSize;
 class  nsIAtom;
 class  nsHTMLFramesetBorderFrame;
 class  nsGUIEvent;
 class  nsHTMLFramesetFrame;
 
-#define NS_IFRAMESETFRAME_IID \
-{ 0xf47deac0, 0x4200, 0x11d2, \
-  { 0x80, 0x3c, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } }
-
 #define NO_COLOR 0xFFFFFFFA
 
 struct nsBorderColor 
 {
   nscolor mLeft;
   nscolor mRight;
   nscolor mTop;
   nscolor mBottom;
@@ -103,24 +99,23 @@ struct nsFramesetDrag {
 };
 
 /*******************************************************************************
  * nsHTMLFramesetFrame
  ******************************************************************************/
 class nsHTMLFramesetFrame : public nsHTMLContainerFrame
 {
 public:
-  // Woohoo, concrete class with an IID!
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFRAMESETFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsHTMLFramesetFrame)
 
   nsHTMLFramesetFrame(nsStyleContext* aContext);
 
   virtual ~nsHTMLFramesetFrame();
 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
 
   static PRBool  gDragInProgress;
 
   void GetSizeOfChild(nsIFrame* aChild, nsSize& aSize);
@@ -267,11 +262,9 @@ protected:
 
   PRInt32*         mChildTypes; // frameset/frame distinction of children  
   nsFrameborder*   mChildFrameborder; // the frameborder attr of children 
   nsBorderColor*   mChildBorderColors;
   
   PRBool mForceFrameResizability;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsHTMLFramesetFrame, NS_IFRAMESETFRAME_IID)
-
 #endif
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -873,28 +873,16 @@ nsHTMLScrollFrame::Reflow(nsPresContext*
   }
 
   aStatus = NS_FRAME_COMPLETE;
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
   mInner.PostOverflowEvent();
   return rv;
 }
 
-NS_IMETHODIMP_(nsrefcnt) 
-nsHTMLScrollFrame::AddRef(void)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsHTMLScrollFrame::Release(void)
-{
-    return NS_OK;
-}
-
 #ifdef NS_DEBUG
 NS_IMETHODIMP
 nsHTMLScrollFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("HTMLScroll"), aResult);
 }
 #endif
 
@@ -918,25 +906,25 @@ NS_IMETHODIMP nsHTMLScrollFrame::GetAcce
 
 void
 nsHTMLScrollFrame::CurPosAttributeChanged(nsIContent* aChild,
                                           PRInt32 aModType)
 {
   mInner.CurPosAttributeChanged(aChild);
 }
 
-NS_INTERFACE_MAP_BEGIN(nsHTMLScrollFrame)
-  NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
-#ifdef NS_DEBUG
-  NS_INTERFACE_MAP_ENTRY(nsIFrameDebug)
+NS_QUERYFRAME_HEAD(nsHTMLScrollFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
+  NS_QUERYFRAME_ENTRY(nsIScrollableViewProvider)
+  NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
+#ifdef DEBUG
+  NS_QUERYFRAME_ENTRY(nsIFrameDebug)
 #endif
-  NS_INTERFACE_MAP_ENTRY(nsIScrollableFrame)
-  NS_INTERFACE_MAP_ENTRY(nsIScrollableViewProvider)
-  NS_INTERFACE_MAP_ENTRY(nsIStatefulFrame)
-NS_INTERFACE_MAP_END_INHERITING(nsHTMLContainerFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 //----------nsXULScrollFrame-------------------------------------------
 
 nsIFrame*
 NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot)
 {
   return new (aPresShell) nsXULScrollFrame(aPresShell, aContext, aIsRoot);
 }
@@ -1237,28 +1225,16 @@ nsXULScrollFrame::GetMinWidth(nsIRenderi
     else
       mMaxElementWidth = aDesiredSize.mMaxElementWidth;
 #endif
   }
   return 0;
 }
 #endif
 
-NS_IMETHODIMP_(nsrefcnt) 
-nsXULScrollFrame::AddRef(void)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsXULScrollFrame::Release(void)
-{
-    return NS_OK;
-}
-
 #ifdef NS_DEBUG
 NS_IMETHODIMP
 nsXULScrollFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("XULScroll"), aResult);
 }
 #endif
 
@@ -1273,28 +1249,26 @@ nsXULScrollFrame::DoLayout(nsBoxLayoutSt
   PRUint32 flags = aState.LayoutFlags();
   nsresult rv = Layout(aState);
   aState.SetLayoutFlags(flags);
 
   nsBox::DoLayout(aState);
   return rv;
 }
 
-NS_INTERFACE_MAP_BEGIN(nsXULScrollFrame)
-  NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
-#ifdef NS_DEBUG
-  NS_INTERFACE_MAP_ENTRY(nsIFrameDebug)
+NS_QUERYFRAME_HEAD(nsXULScrollFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+  NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
+  NS_QUERYFRAME_ENTRY(nsIScrollableViewProvider)
+  NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
+#ifdef DEBUG
+  NS_QUERYFRAME_ENTRY(nsIFrameDebug)
 #endif
-  NS_INTERFACE_MAP_ENTRY(nsIScrollableFrame)
-  NS_INTERFACE_MAP_ENTRY(nsIScrollableViewProvider)
-  NS_INTERFACE_MAP_ENTRY(nsIStatefulFrame)
-NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
-
-
-
+NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
+ 
 //-------------------- Inner ----------------------
 
 nsGfxScrollFrameInner::nsGfxScrollFrameInner(nsContainerFrame* aOuter,
                                              PRBool aIsRoot,
                                              PRBool aIsXUL)
   : mScrollableView(nsnull),
     mHScrollbarBox(nsnull),
     mVScrollbarBox(nsnull),
@@ -1323,26 +1297,16 @@ nsGfxScrollFrameInner::nsGfxScrollFrameI
     mMayHaveDirtyFixedChildren(PR_FALSE)
 {
 }
 
 nsGfxScrollFrameInner::~nsGfxScrollFrameInner()
 {
 }
 
-NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrameInner::AddRef(void)
-{
-  return 2;
-}
-
-NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrameInner::Release(void)
-{
-  return 1;
-}
-
 NS_IMPL_QUERY_INTERFACE1(nsGfxScrollFrameInner, nsIScrollPositionListener)
 
 nsresult
 nsGfxScrollFrameInner::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                         const nsRect&           aDirtyRect,
                                         const nsDisplayListSet& aLists)
 {
   nsresult rv = mOuter->DisplayBorderBackgroundOutline(aBuilder, aLists);
@@ -1407,26 +1371,25 @@ nsGfxScrollFrameInner::NeedsClipWidget()
   for (nsIFrame* parentFrame = mOuter; parentFrame;
        parentFrame = nsLayoutUtils::GetCrossDocParentFrame(parentFrame)) {
     
     /* See if we have a transform... we should have no widget if that's the case. */
     if (parentFrame->GetStyleDisplay()->HasTransform())
       return PR_FALSE;
 
     /* If we're a form element, we don't need a widget. */
-    nsIFormControlFrame* fcFrame;
-    if ((NS_SUCCEEDED(parentFrame->QueryInterface(NS_GET_IID(nsIFormControlFrame), (void**)&fcFrame)))) {
+    nsIFormControlFrame* fcFrame = do_QueryFrame(parentFrame);
+    if (fcFrame) {
       return PR_FALSE;
     }
   }
 
   // Scrollports that don't ever show associated scrollbars don't get
   // widgets, because they will seldom actually be scrolled.
-  nsIScrollableFrame *scrollableFrame;
-  CallQueryInterface(mOuter, &scrollableFrame);
+  nsIScrollableFrame *scrollableFrame = do_QueryFrame(mOuter);
   ScrollbarStyles scrollbars = scrollableFrame->GetScrollbarStyles();
   if ((scrollbars.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN
        || scrollbars.mHorizontal == NS_STYLE_OVERFLOW_VISIBLE)
       && (scrollbars.mVertical == NS_STYLE_OVERFLOW_HIDDEN
           || scrollbars.mVertical == NS_STYLE_OVERFLOW_VISIBLE)) {
     return PR_FALSE;
   }
  
@@ -1682,18 +1645,17 @@ nsGfxScrollFrameInner::CreateAnonymousCo
     // allow scrollbars if this is the child of the viewport, because
     // we must be the scrollbars for the print preview window
     if (!(mIsRoot && presContext->HasPaginatedScrolling())) {
       mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
       return NS_OK;
     }
   }
 
-  nsIScrollableFrame *scrollable;
-  CallQueryInterface(mOuter, &scrollable);
+  nsIScrollableFrame *scrollable = do_QueryFrame(mOuter);
 
   // At this stage in frame construction, the document element and/or
   // BODY overflow styles have not yet been propagated to the
   // viewport. So GetScrollbarStylesFromFrame called here will only
   // take into account the scrollbar preferences set on the docshell.
   // Thus if no scrollbar preferences are set on the docshell, we will
   // always create scrollbars, which means later dynamic changes to
   // propagated overflow styles will show or hide scrollbars on the
@@ -1708,18 +1670,17 @@ nsGfxScrollFrameInner::CreateAnonymousCo
   PRBool canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
   PRBool canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
   if (!canHaveHorizontal && !canHaveVertical) {
     // Nothing to do.
     return NS_OK;
   }
 
   // The anonymous <div> used by <inputs> never gets scrollbars.
-  nsITextControlFrame* textFrame = nsnull;
-  CallQueryInterface(parent, &textFrame);
+  nsITextControlFrame* textFrame = do_QueryFrame(parent);
   if (textFrame) {
     // Make sure we are not a text area.
     nsCOMPtr<nsIDOMHTMLTextAreaElement> textAreaElement(do_QueryInterface(parent->GetContent()));
     if (!textAreaElement) {
       mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
       return NS_OK;
     }
   }
@@ -2709,24 +2670,23 @@ nsGfxScrollFrameInner::GetActualScrollba
 }
 
 void
 nsGfxScrollFrameInner::SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisible)
 {
   if (!aScrollbar)
     return;
 
-  nsIScrollbarFrame* scrollbar;
-  CallQueryInterface(aScrollbar, &scrollbar);
+  nsIScrollbarFrame* scrollbar = do_QueryFrame(aScrollbar);
   if (scrollbar) {
     // See if we have a mediator.
     nsIScrollbarMediator* mediator = scrollbar->GetScrollbarMediator();
     if (mediator) {
       // Inform the mediator of the visibility change.
-      mediator->VisibilityChanged(scrollbar, aVisible);
+      mediator->VisibilityChanged(aVisible);
     }
   }
 }
 
 PRInt32
 nsGfxScrollFrameInner::GetCoordAttribute(nsIBox* aBox, nsIAtom* atom, PRInt32 defaultValue)
 {
   if (aBox) {
@@ -2814,18 +2774,17 @@ nsPresState*
 nsGfxScrollFrameInner::SaveState(nsIStatefulFrame::SpecialStateID aStateID)
 {
   // Don't save "normal" state for the root scrollframe; that's
   // handled via the eDocumentScrollState state id
   if (mIsRoot && aStateID == nsIStatefulFrame::eNoID) {
     return nsnull;
   }
 
-  nsIScrollbarMediator* mediator;
-  CallQueryInterface(GetScrolledFrame(), &mediator);
+  nsIScrollbarMediator* mediator = do_QueryFrame(GetScrolledFrame());
   if (mediator) {
     // child handles its own scroll state, so don't bother saving state here
     return nsnull;
   }
 
   nsIScrollableView* scrollingView = GetScrollableView();
   PRInt32 x,y;
   scrollingView->GetScrollPosition(x,y);
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -61,18 +61,18 @@ class nsIDocument;
 class nsIScrollFrameInternal;
 class nsPresState;
 struct ScrollReflowState;
 
 class nsGfxScrollFrameInner : public nsIScrollPositionListener,
                               public nsIReflowCallback {
 public:
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
+  NS_IMETHOD_(nsrefcnt) AddRef(void) { return 2; }
+  NS_IMETHOD_(nsrefcnt) Release(void) { return 1; }
 
   nsGfxScrollFrameInner(nsContainerFrame* aOuter, PRBool aIsRoot,
                         PRBool aIsXUL);
   ~nsGfxScrollFrameInner();
 
   typedef nsIScrollableFrame::ScrollbarStyles ScrollbarStyles;
   ScrollbarStyles GetScrollbarStylesFromFrame() const;
 
@@ -243,17 +243,17 @@ public:
  */
 class nsHTMLScrollFrame : public nsHTMLContainerFrame,
                           public nsIScrollableFrame,
                           public nsIAnonymousContentCreator,
                           public nsIStatefulFrame {
 public:
   friend nsIFrame* NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot);
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_QUERYFRAME
 
   // Called to set the child frames. We typically have three: the scroll area,
   // the vertical scrollbar, and the horizontal scrollbar.
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsIFrame*       aChildList);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
@@ -428,16 +428,18 @@ private:
  * Scroll frames don't support incremental changes, i.e. you can't replace
  * or remove the scrolled frame
  */
 class nsXULScrollFrame : public nsBoxFrame,
                          public nsIScrollableFrame,
                          public nsIAnonymousContentCreator,
                          public nsIStatefulFrame {
 public:
+  NS_DECL_QUERYFRAME
+
   friend nsIFrame* NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot);
 
   // Called to set the child frames. We typically have three: the scroll area,
   // the vertical scrollbar, and the horizontal scrollbar.
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsIFrame*       aChildList);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
@@ -488,19 +490,16 @@ public:
   { nsPoint pt = aChild->GetPosition();
     if (aChild == mInner.GetScrolledFrame()) pt += GetScrollPosition();
     return pt;
   }
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
 
-  // nsIBox methods
-  NS_DECL_ISUPPORTS
-
   virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
   virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
   virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState);
   virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState);
 
   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
   NS_IMETHOD GetPadding(nsMargin& aPadding);
 
--- a/layout/generic/nsHTMLFrame.cpp
+++ b/layout/generic/nsHTMLFrame.cpp
@@ -82,17 +82,19 @@
 class CanvasFrame : public nsHTMLContainerFrame, 
                     public nsIScrollPositionListener, 
                     public nsICanvasFrame {
 public:
   CanvasFrame(nsStyleContext* aContext)
   : nsHTMLContainerFrame(aContext), mDoPaintFocus(PR_FALSE),
     mAbsoluteContainer(nsGkAtoms::absoluteList) {}
 
-   // nsISupports
+  NS_DECL_QUERYFRAME
+
+  // nsISupports (nsIScrollPositionListener)
   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
 
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   virtual void Destroy();
 
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
@@ -183,34 +185,21 @@ private:
 //----------------------------------------------------------------------
 
 nsIFrame*
 NS_NewCanvasFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell)CanvasFrame(aContext);
 }
 
-//--------------------------------------------------------------
-// Frames are not refcounted, no need to AddRef
-NS_IMETHODIMP
-CanvasFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
+NS_IMPL_QUERY_INTERFACE1(CanvasFrame, nsIScrollPositionListener)
 
-  if (aIID.Equals(NS_GET_IID(nsIScrollPositionListener))) {
-    *aInstancePtr = static_cast<nsIScrollPositionListener*>(this);
-    return NS_OK;
-  } 
-  if (aIID.Equals(NS_GET_IID(nsICanvasFrame))) {
-    *aInstancePtr = static_cast<nsICanvasFrame*>(this);
-    return NS_OK;
-  } 
-
-  return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(CanvasFrame)
+  NS_QUERYFRAME_ENTRY(nsICanvasFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 NS_IMETHODIMP
 CanvasFrame::Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow)
 {
   nsresult rv = nsHTMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
 
@@ -402,18 +391,17 @@ CanvasFrame::GetFirstChild(nsIAtom* aLis
 
   return nsHTMLContainerFrame::GetFirstChild(aListName);
 }
 
 nsRect CanvasFrame::CanvasArea() const
 {
   nsRect result(GetOverflowRect());
 
-  nsIScrollableFrame *scrollableFrame;
-  CallQueryInterface(GetParent(), &scrollableFrame);
+  nsIScrollableFrame *scrollableFrame = do_QueryFrame(GetParent());
   if (scrollableFrame) {
     nsIScrollableView* scrollableView = scrollableFrame->GetScrollableView();
     nsRect vcr = scrollableView->View()->GetBounds();
     result.UnionRect(result, nsRect(nsPoint(0, 0), vcr.Size()));
   }
   return result;
 }
 
@@ -544,19 +532,17 @@ CanvasFrame::BuildDisplayList(nsDisplayL
       nsDisplayCanvasFocus(this));
 }
 
 void
 CanvasFrame::PaintFocus(nsIRenderingContext& aRenderingContext, nsPoint aPt)
 {
   nsRect focusRect(aPt, GetSize());
 
-  nsIScrollableFrame *scrollableFrame;
-  CallQueryInterface(GetParent(), &scrollableFrame);
-
+  nsIScrollableFrame *scrollableFrame = do_QueryFrame(GetParent());
   if (scrollableFrame) {
     nsIScrollableView* scrollableView = scrollableFrame->GetScrollableView();
     nsRect vcr = scrollableView->View()->GetBounds();
     focusRect.width = vcr.width;
     focusRect.height = vcr.height;
     nscoord x,y;
     scrollableView->GetScrollPosition(x, y);
     focusRect.x += x;
--- a/layout/generic/nsIAnonymousContentCreator.h
+++ b/layout/generic/nsIAnonymousContentCreator.h
@@ -38,39 +38,34 @@
 /*
  * interface for rendering objects that manually create subtrees of
  * anonymous content
  */
 
 #ifndef nsIAnonymousContentCreator_h___
 #define nsIAnonymousContentCreator_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsIContent.h"
 
 class nsPresContext;
 class nsIFrame;
 template <class T> class nsTArray;
 
-// {7568a516-3831-4db4-88a7-a42578acc136}
-#define NS_IANONYMOUS_CONTENT_CREATOR_IID \
-{ 0x7568a516, 0x3831, 0x4db4, \
-  { 0x88, 0xa7, 0xa4, 0x25, 0x78, 0xac, 0xc1, 0x36 } }
-
-
 /**
  * Any source for anonymous content can implement this interface to provide it.
  * HTML frames like nsFileControlFrame currently use this as well as XUL frames
  * like nsScrollbarFrame and nsSliderFrame.
  *
  * @see nsCSSFrameConstructor
  */
-class nsIAnonymousContentCreator : public nsISupports {
+class nsIAnonymousContentCreator
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IANONYMOUS_CONTENT_CREATOR_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIAnonymousContentCreator)
 
   /**
    * Creates "native" anonymous content and adds the created content to
    * the aElements array. None of the returned elements can be nsnull.
    *
    * @note The returned elements are owned by this object. This object is
    *       responsible for calling UnbindFromTree on the elements it returned
    *       from CreateAnonymousContent when appropriate (i.e. before releasing
@@ -88,13 +83,10 @@ public:
 
   /**
    * This gets called after the frames for the anonymous content have been
    * created and added to the frame tree. By default it does nothing.
    */
   virtual void PostCreateFrames() {}
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIAnonymousContentCreator,
-                              NS_IANONYMOUS_CONTENT_CREATOR_IID)
-
 #endif
 
--- a/layout/generic/nsICanvasFrame.h
+++ b/layout/generic/nsICanvasFrame.h
@@ -35,30 +35,24 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* interface to rendering object that lives inside the document scrollbars */
 
 #ifndef nsICanvasFrame_h__
 #define nsICanvasFrame_h__
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 
-// IID for the nsICanvasFrame interface
-#define NS_ICANVASFRAME_IID       \
-{ 0x9df7db77, 0x49a2, 0x11d5, {0x97, 0x92, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56} }
-
-class nsICanvasFrame : public nsISupports
+class nsICanvasFrame
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsICanvasFrame)
 
   /** SetHasFocus tells the CanvasFrame to draw with focus ring
    *  @param aHasFocus PR_TRUE to show focus ring, PR_FALSE to hide it
    */
   NS_IMETHOD SetHasFocus(PRBool aHasFocus) = 0;
 
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasFrame, NS_ICANVASFRAME_IID)
-
 #endif  // nsICanvasFrame_h__
 
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -42,17 +42,17 @@
 #define nsIFrame_h___
 
 /* nsIFrame is in the process of being deCOMtaminated, i.e., this file is eventually
    going to be eliminated, and all callers will use nsFrame instead.  At the moment
    we're midway through this process, so you will see inlined functions and member
    variables in this file.  -dwh */
 
 #include <stdio.h>
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsEvent.h"
 #include "nsStyleStruct.h"
 #include "nsStyleContext.h"
 #include "nsIContent.h"
 #include "nsHTMLReflowMetrics.h"
 #include "gfxMatrix.h"
 
 /**
@@ -459,20 +459,20 @@ typedef PRBool nsDidReflowStatus;
  *
  * nsIFrame is a private Gecko interface. If you are not Gecko then you
  * should not use it. If you're not in layout, then you won't be able to
  * link to many of the functions defined here. Too bad.
  *
  * If you're not in layout but you must call functions in here, at least
  * restrict yourself to calling virtual methods, which won't hurt you as badly.
  */
-class nsIFrame : public nsISupports
+class nsIFrame : public nsQueryFrame
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIFrame)
 
   nsPresContext* PresContext() const {
     return GetStyleContext()->GetRuleNode()->GetPresContext();
   }
 
   /**
    * Called to initialize the frame. This is called immediately after creating
    * the frame.
@@ -2343,19 +2343,16 @@ protected:
    * @param  aPos See description in nsFrameSelection.h. The following fields are
    *              used by this method: 
    *              Input: mDirection
    *              Output: mResultContent, mContentOffset
    */
    nsresult PeekOffsetParagraph(nsPeekOffsetStruct *aPos);
 
 private:
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
-
   nsRect* GetOverflowAreaProperty(PRBool aCreateIfNecessary = PR_FALSE);
 };
 
 //----------------------------------------------------------------------
 
 /**
  * nsWeakFrame can be used to keep a reference to a nsIFrame in a safe way.
  * Whenever an nsIFrame object is deleted, the nsWeakFrames pointing
@@ -2420,12 +2417,9 @@ public:
   }
 private:
   void Init(nsIFrame* aFrame);
 
   nsWeakFrame*  mPrev;
   nsIFrame*     mFrame;
 };
 
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIFrame, NS_IFRAME_IID)
-
 #endif /* nsIFrame_h___ */
--- a/layout/generic/nsIFrameDebug.h
+++ b/layout/generic/nsIFrameDebug.h
@@ -35,33 +35,27 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* debugging interface for all rendering objects */
 
 #ifndef nsIFrameDebug_h___
 #define nsIFrameDebug_h___
 
-#include "nsISupports.h"
 #include "nsIFrame.h"
 
 class nsPresContext;
 struct PRLogModuleInfo;
 
-// IID for the nsIFrameDebug interface {a6cf9069-15b3-11d2-932e-00805f8add32}
-#define NS_IFRAMEDEBUG_IID         \
-{ 0xa6cf9069, 0x15b3, 0x11d2, \
-  {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
- 
 /**
  * Debug related functions
  */
-class nsIFrameDebug : public nsISupports {
+class nsIFrameDebug {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFRAMEDEBUG_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIFrameDebug)
   
   NS_IMETHOD  List(FILE* out, PRInt32 aIndent) const = 0;
   /**
    * lists the frames beginning from the root frame
    * - calls root frame's List(...)
    */
   static void RootFrameList(nsPresContext* aPresContext, FILE* out, PRInt32 aIndent);
 
@@ -129,17 +123,11 @@ public:
   static void ShowFrameBorders(PRBool aEnable);
   static PRBool GetShowFrameBorders();
 
   // Show frame border of event target
   static void ShowEventTargetFrameBorder(PRBool aEnable);
   static PRBool GetShowEventTargetFrameBorder();
   
   static void PrintDisplayList(nsDisplayListBuilder* aBuilder, const nsDisplayList& aList);
-
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIFrameDebug, NS_IFRAMEDEBUG_IID)
-
 #endif /* nsIFrameDebug_h___ */
--- a/layout/generic/nsIFrameFrame.h
+++ b/layout/generic/nsIFrameFrame.h
@@ -40,31 +40,25 @@
  * document, such as <frame>, <iframe>, and some <object>s
  */
 
 #ifndef nsIFrameFrame_h___
 #define nsIFrameFrame_h___
 
 class nsIDocShell;
 
-#define NS_IFRAMEFRAME_IID \
-{ 0x22e34108, 0xc24b, 0x40ea, { \
-  0xb9, 0x79, 0x50, 0x18, 0x38, 0x8d, 0xd5, 0x88 } }
-
-class nsIFrameFrame : public nsISupports
+class nsIFrameFrame
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFRAMEFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIFrameFrame)
 
   NS_IMETHOD GetDocShell(nsIDocShell **aDocShell) = 0;
 
   /**
    * Only allowed to fail if the other frame is not the same type as
    * this one or if one of the frames has no docshell.  Don't call
    * EndSwapDocShells() unless BeginSwapDocShells() succeeds.
    */
   NS_IMETHOD BeginSwapDocShells(nsIFrame* aOther) = 0;
   virtual void EndSwapDocShells(nsIFrame* aOther) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIFrameFrame, NS_IFRAMEFRAME_IID)
-
 #endif
--- a/layout/generic/nsIImageFrame.h
+++ b/layout/generic/nsIImageFrame.h
@@ -38,30 +38,24 @@
 /*
  * interface for rendering objects for replaced elements with bitmap
  * image data
  */
 
 #ifndef nsIImageFrame_h___
 #define nsIImageFrame_h___
 
-#include "nsISupports.h"
 struct nsSize;
 class imgIRequest;
 class nsPresContext;
 class nsIImageMap;
 
-// {B261A0D5-E696-11d4-9885-00C04FA0CF4B}
-#define NS_IIMAGEFRAME_IID \
-{ 0xb261a0d5, 0xe696, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
-
-class nsIImageFrame : public nsISupports {
+class nsIImageFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIMAGEFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIImageFrame)
 
   NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize) = 0;
 
   NS_IMETHOD GetImageMap(nsPresContext *aPresContext, nsIImageMap **aImageMap) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIImageFrame, NS_IIMAGEFRAME_IID)
-
 #endif /* nsIImageFrame_h___ */
--- a/layout/generic/nsIObjectFrame.h
+++ b/layout/generic/nsIObjectFrame.h
@@ -42,23 +42,20 @@
 
 #ifndef nsIObjectFrame_h___
 #define nsIObjectFrame_h___
 
 #include "nsIFrame.h"
 
 class nsIPluginInstance;
 
-// {3e2df1fe-a898-4e2e-8763-4ca904fa338e}
-#define NS_IOBJECTFRAME_IID \
-{ 0x3e2df1fe, 0xa898, 0x4e2e, { 0x87, 0x63, 0x4c, 0xa9, 0x4, 0xfa, 0x33, 0x8e } }
-
-class nsIObjectFrame : public nsISupports {
+class nsIObjectFrame : public nsQueryFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IOBJECTFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIObjectFrame)
 
   NS_IMETHOD GetPluginInstance(nsIPluginInstance*& aPluginInstance) = 0;
 
   /**
    * Instantiate a plugin for a channel, returning a stream listener for the
    * data.
    *
    * @note Calling this method can delete the frame, so don't assume
@@ -89,11 +86,9 @@ public:
   /**
    * Stops and unloads the plugin. Makes the frame ready to receive another
    * Instantiate() call. It is safe to call this method even when no plugin
    * is currently active in this frame.
    */
   virtual void StopPlugin() = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIObjectFrame, NS_IOBJECTFRAME_IID)
-
 #endif /* nsIObjectFrame_h___ */
--- a/layout/generic/nsIPageSequenceFrame.h
+++ b/layout/generic/nsIPageSequenceFrame.h
@@ -32,37 +32,31 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsIPageSequenceFrame_h___
 #define nsIPageSequenceFrame_h___
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsRect.h"
 
 class nsPresContext;
 class nsIPrintSettings;
 
-// IID for the nsIPageSequenceFrame interface 
-// a6cf90d2-15b3-11d2-932e-00805f8add32
-#define NS_IPAGESEQUENCEFRAME_IID \
- { 0xa6cf90d2, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
-
-//----------------------------------------------------------------------
-
 /**
  * Interface for accessing special capabilities of the page sequence frame.
  *
  * Today all that exists are member functions for printing.
  */
-class nsIPageSequenceFrame : public nsISupports {
+class nsIPageSequenceFrame : public nsQueryFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPAGESEQUENCEFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIPageSequenceFrame)
 
   /**
    * Print the set of pages.
    *
    * @param   aPrintOptions options for printing
    * @param   aStatusCallback interface that the client provides to receive
    *            progress notifications. Can be NULL
    * @return  NS_OK if successful
@@ -87,19 +81,13 @@ public:
 
   NS_IMETHOD SetTotalNumPages(PRInt32 aTotal) = 0;
 
   // Gets the dead space (the gray area) around the Print Preview Page
   NS_IMETHOD GetDeadSpaceValue(nscoord* aValue) = 0;
 
   // For Shrink To Fit
   NS_IMETHOD GetSTFPercent(float& aSTFPercent) = 0;
-  
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
-  NS_IMETHOD_(nsrefcnt) Release(void) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIPageSequenceFrame, NS_IPAGESEQUENCEFRAME_IID)
-
 #endif /* nsIPageSequenceFrame_h___ */
 
 
--- a/layout/generic/nsIScrollableFrame.h
+++ b/layout/generic/nsIScrollableFrame.h
@@ -47,25 +47,20 @@
 #include "nsCoord.h"
 #include "nsIViewManager.h"
 #include "nsIScrollableViewProvider.h"
 #include "nsPresContext.h"
 #include "nsIFrame.h" // to get nsIBox, which is a typedef
 
 class nsBoxLayoutState;
 
-// IID for the nsIScrollableFrame interface
-#define NS_ISCROLLABLE_FRAME_IID    \
-{ 0xf285c180, 0x8492, 0x48d5, \
-{ 0xb1, 0xb5, 0x03, 0x28, 0x21, 0xc9, 0x72, 0x02 } }
-
 class nsIScrollableFrame : public nsIScrollableViewProvider {
 public:
 
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCROLLABLE_FRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIScrollableFrame)
 
   /**
    * Get the frame that we are scrolling within the scrollable frame.
    * @result child frame
    */
   virtual nsIFrame* GetScrolledFrame() const = 0;
 
   typedef nsPresContext::ScrollbarStyles ScrollbarStyles;
@@ -121,11 +116,9 @@ public:
    * position that was restored from the history. This must be called
    * at least once after state has been restored. It is called by the
    * scrolled frame itself during reflow, but sometimes state can be
    * restored after reflows are done...
    */
   virtual void ScrollToRestoredPosition() = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIScrollableFrame, NS_ISCROLLABLE_FRAME_IID)
-
 #endif
--- a/layout/generic/nsIScrollableViewProvider.h
+++ b/layout/generic/nsIScrollableViewProvider.h
@@ -34,27 +34,21 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _nsIScrollableViewProvider_h
 #define _nsIScrollableViewProvider_h
 
-#include "nsISupports.h"
-
-#define NS_ISCROLLABLEVIEWPROVIDER_IID \
-{0xdafcbf5f, 0x701f, 0x4697, \
-{0xa5, 0x13, 0x81, 0xd8, 0x0e, 0x01, 0x41, 0x2c}}
+#include "nsQueryFrame.h"
 
 class nsIScrollableView;
 
-class nsIScrollableViewProvider : public nsISupports {
+class nsIScrollableViewProvider : public nsQueryFrame
+{
  public: 
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCROLLABLEVIEWPROVIDER_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIScrollableViewProvider)
 
   virtual nsIScrollableView* GetScrollableView() = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIScrollableViewProvider,
-                              NS_ISCROLLABLEVIEWPROVIDER_IID)
-
 #endif /* _nsIScrollableViewProvider_h */
--- a/layout/generic/nsIStatefulFrame.h
+++ b/layout/generic/nsIStatefulFrame.h
@@ -1,39 +1,34 @@
 /*
  * interface for rendering objects whose state is saved in
  * session-history (back-forward navigation)
  */
 
 #ifndef _nsIStatefulFrame_h
 #define _nsIStatefulFrame_h
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 
 class nsPresContext;
 class nsPresState;
 
-#define NS_ISTATEFULFRAME_IID \
-{ 0x25c232cf, 0x40ba, 0x4394, \
- { 0x84, 0xe4, 0x73, 0xa2, 0xf7, 0x4d, 0x8b, 0x64 } }
-
-class nsIStatefulFrame : public nsISupports {
+class nsIStatefulFrame
+{
  public: 
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTATEFULFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIStatefulFrame)
 
   // If you create a special type stateful frame (e.g. scroll) that needs
   // to be captured outside of the standard pass through the frames, you'll need
   // a special ID by which to refer to that type.
   enum SpecialStateID {eNoID=0, eDocumentScrollState};
 
   // Save the state for this frame.  Some implementations may choose to return
   // different states depending on the value of aStateID.  If this method
   // succeeds, the caller is responsible for deleting the resulting state when
   // done with it.
   NS_IMETHOD SaveState(SpecialStateID aStateID, nsPresState** aState) = 0;
 
   // Restore the state for this frame from aState
   NS_IMETHOD RestoreState(nsPresState* aState) = 0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIStatefulFrame, NS_ISTATEFULFRAME_IID)
-
 #endif /* _nsIStatefulFrame_h */
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -181,28 +181,19 @@ nsImageFrame::nsImageFrame(nsStyleContex
   // We assume our size is not constrained and we haven't gotten an
   // initial reflow yet, so don't touch those flags.
 }
 
 nsImageFrame::~nsImageFrame()
 {
 }
 
-NS_IMETHODIMP
-nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIImageFrame))) {
-    *aInstancePtr = static_cast<nsIImageFrame*>(this);
-    return NS_OK;
-  }
-
-  return ImageFrameSuper::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsImageFrame)
+  NS_QUERYFRAME_ENTRY(nsIImageFrame)
+NS_QUERYFRAME_TAIL_INHERITING(ImageFrameSuper)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLImageAccessible(static_cast<nsIFrame*>(this), aAccessible);
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -91,18 +91,17 @@ private:
 #define IMAGE_GOTINITIALREFLOW      0x00200000
 
 #define ImageFrameSuper nsSplittableFrame
 
 class nsImageFrame : public ImageFrameSuper, public nsIImageFrame {
 public:
   nsImageFrame(nsStyleContext* aContext);
 
-  // nsISupports 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   virtual void Destroy();
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
--- a/layout/generic/nsInlineFrame.cpp
+++ b/layout/generic/nsInlineFrame.cpp
@@ -57,41 +57,29 @@
 #endif
 #include "nsDisplayList.h"
 
 #ifdef DEBUG
 #undef NOISY_PUSHING
 #endif
 
 
-NS_DEFINE_IID(kInlineFrameCID, NS_INLINE_FRAME_CID);
-
-
 //////////////////////////////////////////////////////////////////////
 
 // Basic nsInlineFrame methods
 
 nsIFrame*
 NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsInlineFrame(aContext);
 }
 
-NS_IMETHODIMP
-nsInlineFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(kInlineFrameCID)) {
-    *aInstancePtr = this;
-    return NS_OK;
-  }
-
-  return nsInlineFrameSuper::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsInlineFrame)
+  NS_QUERYFRAME_ENTRY(nsInlineFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsInlineFrameSuper)
 
 #ifdef DEBUG
 NS_IMETHODIMP
 nsInlineFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("Inline"), aResult);
 }
 #endif
--- a/layout/generic/nsInlineFrame.h
+++ b/layout/generic/nsInlineFrame.h
@@ -41,19 +41,16 @@
 #define nsInlineFrame_h___
 
 #include "nsHTMLContainerFrame.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "nsLineLayout.h"
 
 class nsAnonymousBlockFrame;
 
-#define NS_INLINE_FRAME_CID \
- { 0x88b298af, 0x8b0e, 0x4592,{0x9e, 0xc6, 0xea, 0x4c, 0x4b, 0x3f, 0xf7, 0xa4}}
-
 #define nsInlineFrameSuper nsHTMLContainerFrame
 
 // NS_INLINE_FRAME_HARD_TEXT_OFFSETS is used for access keys, where what
 // would normally be 1 text frame is split into 3 sets of an inline parent 
 // and text child (the pre access key text, the underlined key text, and
 // the post access key text). The offsets of the 3 text frame children
 // are set in nsCSSFrameConstructor
 
@@ -74,20 +71,20 @@ class nsAnonymousBlockFrame;
  * Inline frame class.
  *
  * This class manages a list of child frames that are inline frames. Working with
  * nsLineLayout, the class will reflow and place inline frames on a line.
  */
 class nsInlineFrame : public nsInlineFrameSuper
 {
 public:
-  friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
+  NS_DECLARE_FRAME_ACCESSOR(nsInlineFrame)
+  NS_DECL_QUERYFRAME
 
-  // nsISupports overrides
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
   // nsIFrame overrides
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
 #ifdef ACCESSIBILITY
   NS_IMETHODIMP GetAccessible(nsIAccessible** aAccessible);
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -140,19 +140,18 @@ ListFloats(FILE* out, PRInt32 aIndent, c
   nsFloatCache* fc = aFloats.Head();
   while (fc) {
     nsFrame::IndentBy(out, aIndent);
     nsPlaceholderFrame* ph = fc->mPlaceholder;
     if (ph) {
       fprintf(out, "placeholder@%p ", static_cast<void*>(ph));
       nsIFrame* frame = ph->GetOutOfFlowFrame();
       if (frame) {
-        nsIFrameDebug*  frameDebug;
-
-        if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+        nsIFrameDebug* frameDebug = do_QueryFrame(frame);
+        if (frameDebug) {
           frameDebug->GetFrameName(frameName);
           fputs(NS_LossyConvertUTF16toASCII(frameName).get(), out);
         }
       }
       fprintf(out, " region={%d,%d,%d,%d}",
               fc->mRegion.x, fc->mRegion.y,
               fc->mRegion.width, fc->mRegion.height);
 
@@ -220,19 +219,18 @@ nsLineBox::List(FILE* out, PRInt32 aInde
             mData->mCombinedArea.x, mData->mCombinedArea.y,
             mData->mCombinedArea.width, mData->mCombinedArea.height);
   }
   fprintf(out, "<\n");
 
   nsIFrame* frame = mFirstChild;
   PRInt32 n = GetChildCount();
   while (--n >= 0) {
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
+    nsIFrameDebug* frameDebug = do_QueryFrame(frame);
+    if (frameDebug) {
       frameDebug->List(out, aIndent + 1);
     }
     frame = frame->GetNextSibling();
   }
 
   for (i = aIndent; --i >= 0; ) fputs("  ", out);
   if (HasFloats()) {
     fputs("> floats <\n", out);
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -576,40 +576,19 @@ nsObjectFrame::nsObjectFrame(nsStyleCont
 }
 
 nsObjectFrame::~nsObjectFrame()
 {
   PR_LOG(nsObjectFrameLM, PR_LOG_DEBUG,
          ("nsObjectFrame %p deleted\n", this));
 }
 
-NS_IMETHODIMP
-nsObjectFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIObjectFrame))) {
-    *aInstancePtr = static_cast<nsIObjectFrame*>(this);
-    return NS_OK;
-  }
-
-  return nsObjectFrameSuper::QueryInterface(aIID, aInstancePtr);
-}
-
-NS_IMETHODIMP_(nsrefcnt) nsObjectFrame::AddRef(void)
-{
-  NS_WARNING("not supported for frames");
-  return 1;
-}
-
-NS_IMETHODIMP_(nsrefcnt) nsObjectFrame::Release(void)
-{
-  NS_WARNING("not supported for frames");
-  return 1;
-}
+NS_QUERYFRAME_HEAD(nsObjectFrame)
+  NS_QUERYFRAME_ENTRY(nsIObjectFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsObjectFrameSuper)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsObjectFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLObjectFrameAccessible(this, aAccessible);
@@ -1188,18 +1167,17 @@ nsObjectFrame::PrintPlugin(nsIRenderingC
   // then the shell can give us the screen frame for this content node
   nsIFrame* frame = shell->GetPrimaryFrameFor(mContent);
   if (!frame)
     return;
 
   nsPresContext* presContext = PresContext();
   // make sure this is REALLY an nsIObjectFrame
   // we may need to go through the children to get it
-  nsIObjectFrame* objectFrame = nsnull;
-  CallQueryInterface(frame,&objectFrame);
+  nsIObjectFrame* objectFrame = do_QueryFrame(frame);
   if (!objectFrame)
     objectFrame = GetNextObjectFrame(presContext,frame);
   if (!objectFrame)
     return;
 
   // finally we can get our plugin instance
   nsCOMPtr<nsIPluginInstance> pi;
   if (NS_FAILED(objectFrame->GetPluginInstance(*getter_AddRefs(pi))) || !pi)
@@ -2152,18 +2130,17 @@ nsObjectFrame::NotifyContentObjectWrappe
 
 // static
 nsIObjectFrame *
 nsObjectFrame::GetNextObjectFrame(nsPresContext* aPresContext, nsIFrame* aRoot)
 {
   nsIFrame* child = aRoot->GetFirstChild(nsnull);
 
   while (child) {
-    nsIObjectFrame* outFrame = nsnull;
-    CallQueryInterface(child, &outFrame);
+    nsIObjectFrame* outFrame = do_QueryFrame(child);
     if (outFrame) {
       nsCOMPtr<nsIPluginInstance> pi;
       outFrame->GetPluginInstance(*getter_AddRefs(pi));  // make sure we have a REAL plugin
       if (pi)
         return outFrame;
     }
 
     outFrame = GetNextObjectFrame(aPresContext, child);
--- a/layout/generic/nsObjectFrame.h
+++ b/layout/generic/nsObjectFrame.h
@@ -57,18 +57,17 @@ class nsIPluginInstance;
 class nsPresContext;
 
 #define nsObjectFrameSuper nsFrame
 
 class nsObjectFrame : public nsObjectFrameSuper, public nsIObjectFrame {
 public:
   friend nsIFrame* NS_NewObjectFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  // nsISupports 
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   NS_IMETHOD Init(nsIContent* aContent,
                   nsIFrame* aParent,
                   nsIFrame* aPrevInFlow);
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
   virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
   NS_IMETHOD Reflow(nsPresContext* aPresContext,
                     nsHTMLReflowMetrics& aDesiredSize,
@@ -135,20 +134,16 @@ public:
   //local methods
   nsresult CreateWidget(nscoord aWidth, nscoord aHeight, PRBool aViewOnly);
 
   // for a given aRoot, this walks the frame tree looking for the next outFrame
   static nsIObjectFrame* GetNextObjectFrame(nsPresContext* aPresContext,
                                             nsIFrame* aRoot);
 
 protected:
-  // nsISupports
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
-
   nsObjectFrame(nsStyleContext* aContext);
   virtual ~nsObjectFrame();
 
   // NOTE:  This frame class does not inherit from |nsLeafFrame|, so
   // this is not a virtual method implementation.
   void GetDesiredSize(nsPresContext* aPresContext,
                       const nsHTMLReflowState& aReflowState,
                       nsHTMLReflowMetrics& aDesiredSize);
new file mode 100644
--- /dev/null
+++ b/layout/generic/nsQueryFrame.h
@@ -0,0 +1,268 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla layout engine.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation <http://www.mozilla.org/>.
+ *
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsQueryFrame_h
+#define nsQueryFrame_h
+
+#include "nscore.h"
+
+#define NS_DECLARE_FRAME_ACCESSOR(classname) \
+  static const nsQueryFrame::FrameIID kFrameIID = nsQueryFrame::classname##_id;
+
+#define NS_DECL_QUERYFRAME \
+  virtual void* QueryFrame(FrameIID id);
+
+#define NS_QUERYFRAME_HEAD(class) \
+  void* class::QueryFrame(FrameIID id) {
+
+#define NS_QUERYFRAME_ENTRY(class) \
+  if (class::kFrameIID == id) \
+    return static_cast<class*>(this);
+
+#define NS_QUERYFRAME_TAIL_INHERITING(class) \
+  return class::QueryFrame(id); }
+
+#define NS_QUERYFRAME_TAIL return nsnull; }
+
+class nsQueryFrame
+{
+public:
+  enum FrameIID {
+    BRFrame_id,
+    CanvasFrame_id,
+    nsAreaFrame_id,
+    nsAutoRepeatBoxFrame_id,
+    nsBCTableCellFrame_id,
+    nsBlockFrame_id,
+    nsBox_id,
+    nsBoxFrame_id,
+    nsBulletFrame_id,
+    nsButtonBoxFrame_id,
+    nsColumnSetFrame_id,
+    nsComboboxControlFrame_id,
+    nsComboboxDisplayFrame_id,
+    nsContainerFrame_id,
+    nsContinuingTextFrame_id,
+    nsDeckFrame_id,
+    nsDirectionalFrame_id,
+    nsDocElementBoxFrame_id,
+    nsFieldSetFrame_id,
+    nsFileControlFrame_id,
+    nsFirstLetterFrame_id,
+    nsFirstLineFrame_id,
+    nsFormControlFrame_id,
+    nsFrame_id,
+    nsGfxButtonControlFrame_id,
+    nsGfxCheckboxControlFrame_id,
+    nsGfxRadioControlFrame_id,
+    nsGridRowGroupFrame_id,
+    nsGridRowLeafFrame_id,
+    nsGroupBoxFrame_id,
+    nsHTMLButtonControlFrame_id,
+    nsHTMLCanvasFrame_id,
+    nsHTMLContainerFrame_id,
+    nsHTMLFramesetBlankFrame_id,
+    nsHTMLFramesetBorderFrame_id,
+    nsHTMLFramesetFrame_id,
+    nsHTMLScrollFrame_id,
+    nsIAnonymousContentCreator_id,
+    nsICSSPseudoComparator_id,
+    nsICanvasFrame_id,
+    nsICheckboxControlFrame_id,
+    nsIComboboxControlFrame_id,
+    nsIFormControlFrame_id,
+    nsIFrame_id,
+    nsIFrameDebug_id,
+    nsIFrameFrame_id,
+    nsIImageFrame_id,
+    nsIListControlFrame_id,
+    nsIMathMLFrame_id,
+    nsIMenuFrame_id,
+    nsIObjectFrame_id,
+    nsIPageSequenceFrame_id,
+    nsIPercentHeightObserver_id,
+    nsIRadioControlFrame_id,
+    nsIRootBox_id,
+    nsISVGChildFrame_id,
+    nsISVGGlyphFragmentLeaf_id,
+    nsISVGGlyphFragmentNode_id,
+    nsISVGSVGFrame_id,
+    nsISVGTextContentMetrics_id,
+    nsISVGValue_id,
+    nsIScrollableFrame_id,
+    nsIScrollableViewProvider_id,
+    nsIScrollbarFrame_id,
+    nsIScrollbarMediator_id,
+    nsIScrollPositionListener_id,
+    nsISelectControlFrame_id,
+    nsIStatefulFrame_id,
+    nsITableCellLayout_id,
+    nsITableLayout_id,
+    nsITextControlFrame_id,
+    nsITreeBoxObject_id,
+    nsImageBoxFrame_id,
+    nsImageControlFrame_id,
+    nsImageFrame_id,
+    nsInlineFrame_id,
+    nsIsIndexFrame_id,
+    nsLeafBoxFrame_id,
+    nsLeafFrame_id,
+    nsLegendFrame_id,
+    nsListBoxBodyFrame_id,
+    nsListControlFrame_id,
+    nsListItemFrame_id,
+    nsMathMLContainerFrame_id,
+    nsMathMLForeignFrameWrapper_id,
+    nsMathMLFrame_id,
+    nsMathMLmactionFrame_id,
+    nsMathMLmathBlockFrame_id,
+    nsMathMLmathInlineFrame_id,
+    nsMathMLmfencedFrame_id,
+    nsMathMLmfracFrame_id,
+    nsMathMLmmultiscriptsFrame_id,
+    nsMathMLmoFrame_id,
+    nsMathMLmoverFrame_id,
+    nsMathMLmpaddedFrame_id,
+    nsMathMLmphantomFrame_id,
+    nsMathMLmrootFrame_id,
+    nsMathMLmrowFrame_id,
+    nsMathMLmspaceFrame_id,
+    nsMathMLmsqrtFrame_id,
+    nsMathMLmstyleFrame_id,
+    nsMathMLmsubFrame_id,
+    nsMathMLmsubsupFrame_id,
+    nsMathMLmsupFrame_id,
+    nsMathMLmtableFrame_id,
+    nsMathMLmtableOuterFrame_id,
+    nsMathMLmtdFrame_id,
+    nsMathMLmtdInnerFrame_id,
+    nsMathMLmtrFrame_id,
+    nsMathMLmunderFrame_id,
+    nsMathMLmunderoverFrame_id,
+    nsMathMLTokenFrame_id,
+    nsMenuBarFrame_id,
+    nsMenuFrame_id,
+    nsMenuPopupFrame_id,
+    nsObjectFrame_id,
+    nsPageBreakFrame_id,
+    nsPageContentFrame_id,
+    nsPageFrame_id,
+    nsPlaceholderFrame_id,
+    nsPopupSetFrame_id,
+    nsPositionedInlineFrame_id,
+    nsProgressMeterFrame_id,
+    nsResizerFrame_id,
+    nsRootBoxFrame_id,
+    nsScrollbarButtonFrame_id,
+    nsScrollbarFrame_id,
+    nsSelectsAreaFrame_id,
+    nsSimplePageSequenceFrame_id,
+    nsSliderFrame_id,
+    nsSplittableFrame_id,
+    nsSplitterFrame_id,
+    nsStackFrame_id,
+    nsSubDocumentFrame_id,
+    nsSVGAFrame_id,
+    nsSVGClipPathFrame_id,
+    nsSVGContainerFrame_id,
+    nsSVGDisplayContainerFrame_id,
+    nsSVGFilterFrame_id,
+    nsSVGForeignObjectFrame_id,
+    nsSVGGenericContainerFrame_id,
+    nsSVGGeometryFrame_id,
+    nsSVGGFrame_id,
+    nsSVGGlyphFrame_id,
+    nsSVGGradientFrame_id,
+    nsSVGImageFrame_id,
+    nsSVGInnerSVGFrame_id,
+    nsSVGLeafFrame_id,
+    nsSVGLinearGradientFrame_id,
+    nsSVGMarkerFrame_id,
+    nsSVGMaskFrame_id,
+    nsSVGOuterSVGFrame_id,
+    nsSVGPaintServerFrame_id,
+    nsSVGPathGeometryFrame_id,
+    nsSVGPatternFrame_id,
+    nsSVGRadialGradientFrame_id,
+    nsSVGStopFrame_id,
+    nsSVGSwitchFrame_id,
+    nsSVGTextContainerFrame_id,
+    nsSVGTextFrame_id,
+    nsSVGTextPathFrame_id,
+    nsSVGTSpanFrame_id,
+    nsSVGUseFrame_id,
+    nsTableCaptionFrame_id,
+    nsTableCellFrame_id,
+    nsTableColFrame_id,
+    nsTableColGroupFrame_id,
+    nsTableFrame_id,
+    nsTableOuterFrame_id,
+    nsTableRowFrame_id,
+    nsTableRowGroupFrame_id,
+    nsTextBoxFrame_id,
+    nsTextControlFrame_id,
+    nsTextFrame_id,
+    nsTitleBarFrame_id,
+    nsTreeBodyFrame_id,
+    nsTreeColFrame_id,
+    nsVideoFrame_id,
+    nsXULScrollFrame_id,
+    SpacerFrame_id,
+    ViewportFrame_id
+  };
+
+  virtual void* QueryFrame(FrameIID id) = 0;
+};
+
+class do_QueryFrame
+{
+public:
+  do_QueryFrame(nsQueryFrame *s) : mRawPtr(s) { }
+
+  template<class Dest>
+  operator Dest*() {
+    if (!mRawPtr)
+      return nsnull;
+
+    return reinterpret_cast<Dest*>(mRawPtr->QueryFrame(Dest::kFrameIID));
+  }
+
+private:
+  nsQueryFrame *mRawPtr;
+};
+
+#endif // nsQueryFrame_h
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -2428,34 +2428,30 @@ nsITableCellLayout*
 nsFrameSelection::GetCellLayout(nsIContent *aCellContent) const
 {
   NS_ENSURE_TRUE(mShell, nsnull);
   // Get frame for cell
   nsIFrame *cellFrame = mShell->GetPrimaryFrameFor(aCellContent);
   if (!cellFrame)
     return nsnull;
 
-  nsITableCellLayout *cellLayoutObject = nsnull;
-  CallQueryInterface(cellFrame, &cellLayoutObject);
-
+  nsITableCellLayout *cellLayoutObject = do_QueryFrame(cellFrame);
   return cellLayoutObject;
 }
 
 nsITableLayout* 
 nsFrameSelection::GetTableLayout(nsIContent *aTableContent) const
 {
   NS_ENSURE_TRUE(mShell, nsnull);
   // Get frame for table
   nsIFrame *tableFrame = mShell->GetPrimaryFrameFor(aTableContent);
   if (!tableFrame)
     return nsnull;
 
-  nsITableLayout *tableLayoutObject = nsnull;
-  CallQueryInterface(tableFrame, &tableLayoutObject);
-
+  nsITableLayout *tableLayoutObject = do_QueryFrame(tableFrame);
   return tableLayoutObject;
 }
 
 nsresult
 nsFrameSelection::ClearNormalSelection()
 {
   PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
   return mDomSelections[index]->RemoveAllRanges();
@@ -4591,18 +4587,17 @@ nsTypedSelection::selectFrames(nsPresCon
     // First select frame of content passed in
     frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(aContent);
     if (frame)
     {
       //NOTE: eSpreadDown is now IGNORED. Selected state is set only for given frame
       frame->SetSelected(aPresContext, nsnull, aFlags, eSpreadDown, mType);
       if (mFrameSelection->GetTableCellSelection())
       {
-        nsITableCellLayout *tcl = nsnull;
-        CallQueryInterface(frame, &tcl);
+        nsITableCellLayout *tcl = do_QueryFrame(frame);
         if (tcl)
         {
           return NS_OK;
         }
       }
     }
     // Now iterated through the child frames and set them
     while (!aInnerIter->IsDone())
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -132,27 +132,19 @@ nsSimplePageSequenceFrame::nsSimplePageS
   SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
 }
 
 nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
 {
   if (mPageData) delete mPageData;
 }
 
-NS_IMETHODIMP
-nsSimplePageSequenceFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  NS_PRECONDITION(aInstancePtr, "null out param");
-
-  if (aIID.Equals(NS_GET_IID(nsIPageSequenceFrame))) {
-    *aInstancePtr = static_cast<nsIPageSequenceFrame*>(this);
-    return NS_OK;
-  }
-  return nsContainerFrame::QueryInterface(aIID, aInstancePtr);
-}
+NS_QUERYFRAME_HEAD(nsSimplePageSequenceFrame)
+  NS_QUERYFRAME_ENTRY(nsIPageSequenceFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
 
 //----------------------------------------------------------------------
 
 // Creates a continuing page frame
 nsresult
 nsSimplePageSequenceFrame::CreateContinuingPageFrame(nsPresContext* aPresContext,
                                                      nsIFrame*       aPageFrame,
                                                      nsIFrame**      aContinuingPage)
--- a/layout/generic/nsSimplePageSequence.h
+++ b/layout/generic/nsSimplePageSequence.h
@@ -79,18 +79,17 @@ public:
 };
 
 // Simple page sequence frame class. Used when we're in paginated mode
 class nsSimplePageSequenceFrame : public nsContainerFrame,
                                   public nsIPageSequenceFrame {
 public:
   friend nsIFrame* NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  // nsISupports
-  NS_IMETHOD  QueryInterface(const nsIID& aIID, void** aInstancePtr);
+  NS_DECL_QUERYFRAME
 
   // nsIFrame
   NS_IMETHOD  Reflow(nsPresContext*      aPresContext,
                      nsHTMLReflowMetrics& aDesiredSize,
                      const nsHTMLReflowState& aMaxSize,
                      nsReflowStatus&      aStatus);
 
   NS_IMETHOD  BuildDisplayList(nsDisplayListBuilder*   aBuilder,
@@ -144,19 +143,16 @@ protected:
                                      nsIFrame**      aContinuingFrame);
 
   void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, PRBool aPageNumOnly);
 
   // SharedPageData Helper methods
   void SetDateTimeStr(PRUnichar * aDateTimeStr);
   void SetPageNumberFormat(PRUnichar * aFormatStr, PRBool aForPageNumOnly);
 
-  NS_IMETHOD_(nsrefcnt) AddRef(void) {return nsContainerFrame::AddRef();}
-  NS_IMETHOD_(nsrefcnt) Release(void) {return nsContainerFrame::Release();}
-
   nsMargin mMargin;
   PRBool   mIsPrintingSelection;
 
   // Asynch Printing
   PRInt32      mPageNum;
   PRInt32      mTotalPages;
   nsIFrame *   mCurrentPageFrame;
   PRPackedBool mDoingPageRange;
--- a/layout/generic/nsVideoFrame.cpp
+++ b/layout/generic/nsVideoFrame.cpp
@@ -66,34 +66,22 @@ nsVideoFrame::nsVideoFrame(nsStyleContex
   nsContainerFrame(aContext)
 {
 }
 
 nsVideoFrame::~nsVideoFrame()
 {
 }
 
-NS_INTERFACE_MAP_BEGIN(nsVideoFrame)
-  NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
-#ifdef NS_DEBUG
-  NS_INTERFACE_MAP_ENTRY(nsIFrameDebug)
+NS_QUERYFRAME_HEAD(nsVideoFrame)
+  NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
+#ifdef DEBUG
+  NS_QUERYFRAME_ENTRY(nsIFrameDebug)
 #endif
-NS_INTERFACE_MAP_END_INHERITING(nsContainerFrame)
-
-NS_IMETHODIMP_(nsrefcnt) 
-nsVideoFrame::AddRef(void)
-{
-  return NS_OK;
-}
-
-NS_IMETHODIMP_(nsrefcnt)
-nsVideoFrame::Release(void)
-{
-    return NS_OK;
-}
+NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
 
 nsresult
 nsVideoFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
 {
   // Set up "videocontrols" XUL element which will be XBL-bound to the
   // actual controls.
   nsPresContext* presContext = PresContext();
   nsNodeInfoManager *nodeInfoManager =
--- a/layout/generic/nsVideoFrame.h
+++ b/layout/generic/nsVideoFrame.h
@@ -52,17 +52,17 @@
 
 nsIFrame* NS_NewVideoFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 class nsVideoFrame : public nsContainerFrame, public nsIAnonymousContentCreator
 {
 public:
   nsVideoFrame(nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_QUERYFRAME
   
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   void PaintVideo(nsIRenderingContext& aRenderingContext,
                    const nsRect& aDirtyRect, nsPoint aPt);
                               
--- a/layout/generic/nsViewportFrame.cpp
+++ b/layout/generic/nsViewportFrame.cpp
@@ -219,17 +219,17 @@ nsPoint
 ViewportFrame::AdjustReflowStateForScrollbars(nsHTMLReflowState* aReflowState) const
 {
   // Calculate how much room is available for fixed frames. That means
   // determining if the viewport is scrollable and whether the vertical and/or
   // horizontal scrollbars are visible
 
   // Get our prinicpal child frame and see if we're scrollable
   nsIFrame* kidFrame = mFrames.FirstChild();
-  nsCOMPtr<nsIScrollableFrame> scrollingFrame(do_QueryInterface(kidFrame));
+  nsIScrollableFrame *scrollingFrame = do_QueryFrame(kidFrame);
 
   if (scrollingFrame) {
     nsMargin scrollbars = scrollingFrame->GetActualScrollbarSizes();
     aReflowState->SetComputedWidth(aReflowState->ComputedWidth() -
                                    scrollbars.LeftRight());
     aReflowState->availableWidth -= scrollbars.LeftRight();
     aReflowState->SetComputedHeight(aReflowState->ComputedHeight() -
                                     scrollbars.TopBottom());
--- a/layout/mathml/base/src/nsIMathMLFrame.h
+++ b/layout/mathml/base/src/nsIMathMLFrame.h
@@ -41,41 +41,35 @@
 
 #include "nsIRenderingContext.h"
 #include "nsIFrame.h"
 
 struct nsPresentationData;
 struct nsEmbellishData;
 struct nsHTMLReflowMetrics;
 
-// a781ed45-4338-43cb-9739-a7a8f8418ff3
-#define NS_IMATHMLFRAME_IID \
-{ 0xa781ed45, 0x4338, 0x43cb, \
-  { 0x97, 0x39, 0xa7, 0xa8, 0xf8, 0x41, 0x8f, 0xf3 } }
-
-static NS_DEFINE_IID(kIMathMLFrameIID, NS_IMATHMLFRAME_IID);
-
 // For MathML, this 'type' will be used to determine the spacing between frames
 // Subclasses can return a 'type' that will give them a particular spacing
 enum eMathMLFrameType {
   eMathMLFrameType_UNKNOWN = -1,
   eMathMLFrameType_Ordinary,
   eMathMLFrameType_OperatorOrdinary,
   eMathMLFrameType_OperatorInvisible,
   eMathMLFrameType_OperatorUserDefined,
   eMathMLFrameType_Inner,
   eMathMLFrameType_ItalicIdentifier,
   eMathMLFrameType_UprightIdentifier,
   eMathMLFrameType_COUNT
 };
 
 // Abstract base class that provides additional methods for MathML frames
-class nsIMathMLFrame : public nsISupports {
+class nsIMathMLFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMATHMLFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsIMathMLFrame)
 
  /* SUPPORT FOR PRECISE POSITIONING */
  /*====================================================================*/
  
  /* Metrics that _exactly_ enclose the text of the frame.
   * The frame *must* have *already* being reflowed, before you can call
   * the GetBoundingMetrics() method.
   * Note that for a frame with nested children, the bounding metrics
@@ -304,19 +298,16 @@ struct nsPresentationData {
 
   nsPresentationData() {
     flags = 0;
     baseFrame = nsnull;
     mstyle = nsnull;
   }
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIMathMLFrame, NS_IMATHMLFRAME_IID)
-
-
 // ==========================================================================
 // Bits used for the presentation flags -- these bits are set
 // in their relevant situation as they become available
 
 // This bit is set if the frame is in the *context* of displaystyle=true.
 // Note: This doesn't mean that the frame has displaystyle=true as attribute,
 // the displaystyle attribute is only allowed on <mstyle> and <mtable>.
 // The bit merely tells the context of the frame. In the context of 
--- a/layout/mathml/base/src/nsMathMLContainerFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLContainerFrame.cpp
@@ -60,28 +60,23 @@
 #include "nsMathMLParts.h"
 #include "nsMathMLContainerFrame.h"
 #include "nsAutoPtr.h"
 #include "nsStyleSet.h"
 #include "nsDisplayList.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsIReflowCallback.h"
 
-NS_DEFINE_CID(kInlineFrameCID, NS_INLINE_FRAME_CID);
-
 //
 // nsMathMLContainerFrame implementation
 //
 
-// nsISupports
-// =============================================================================
-
-NS_IMPL_ADDREF_INHERITED(nsMathMLContainerFrame, nsMathMLFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLContainerFrame, nsMathMLFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLContainerFrame, nsHTMLContainerFrame, nsMathMLFrame)
+NS_QUERYFRAME_HEAD(nsMathMLContainerFrame)
+  NS_QUERYFRAME_ENTRY(nsMathMLFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
 
 // =============================================================================
 
 // error handlers
 // provide a feedback to the user when a frame with bad markup can not be rendered
 nsresult
 nsMathMLContainerFrame::ReflowError(nsIRenderingContext& aRenderingContext,
                                     nsHTMLReflowMetrics& aDesiredSize)
@@ -210,18 +205,17 @@ nsMathMLContainerFrame::GetReflowAndBoun
   NS_ASSERTION(metrics, "Didn't SaveReflowAndBoundingMetricsFor frame!");
   if (metrics) {
     aReflowMetrics = *metrics;
     aBoundingMetrics = metrics->mBoundingMetrics;
   }
 
   if (aMathMLFrameType) {
     if (!IsForeignChild(aFrame)) {
-      nsIMathMLFrame* mathMLFrame;
-      CallQueryInterface(aFrame, &mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
       if (mathMLFrame) {
         *aMathMLFrameType = mathMLFrame->GetMathMLFrameType();
         return;
       }
     }
     *aMathMLFrameType = eMathMLFrameType_UNKNOWN;
   }
 
@@ -262,31 +256,29 @@ nsMathMLContainerFrame::GetPreferredStre
                  NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags),
                  "invalid call to GetPreferredStretchSize");
     PRBool firstTime = PR_TRUE;
     nsBoundingMetrics bm, bmChild;
     // XXXrbs need overloaded FirstChild() and clean integration of <maction> throughout
     nsIFrame* childFrame = GetFirstChild(nsnull);
     while (childFrame) {
       // initializations in case this child happens not to be a MathML frame
-      nsIMathMLFrame* mathMLFrame;
-      childFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
       if (mathMLFrame) {
         nsEmbellishData embellishData;
         nsPresentationData presentationData;
         mathMLFrame->GetEmbellishData(embellishData);
         mathMLFrame->GetPresentationData(presentationData);
         if (NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags) &&
             embellishData.direction == aStretchDirection &&
             presentationData.baseFrame) {
           // embellishements are not included, only consider the inner first child itself
           // XXXkt Does that mean the core descendent frame should be used
           // instead of the base child?
-          nsIMathMLFrame* mathMLchildFrame;
-          presentationData.baseFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLchildFrame);
+          nsIMathMLFrame* mathMLchildFrame = do_QueryFrame(presentationData.baseFrame);
           if (mathMLchildFrame) {
             mathMLFrame = mathMLchildFrame;
           }
         }
         mathMLFrame->GetBoundingMetrics(bmChild);
       }
       else {
         nsHTMLReflowMetrics unused;
@@ -354,18 +346,17 @@ nsMathMLContainerFrame::Stretch(nsIRende
       NS_WARNING("it is wrong to fire stretch on a erroneous frame");
       return NS_OK;
     }
 
     // Pass the stretch to the base child ...
 
     nsIFrame* baseFrame = mPresentationData.baseFrame;
     if (baseFrame) {
-      nsIMathMLFrame* mathMLFrame;
-      baseFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(baseFrame);
       NS_ASSERTION(mathMLFrame, "Something is wrong somewhere");
       if (mathMLFrame) {
         PRBool stretchAll =
           NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
           NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
 
         // And the trick is that the child's rect.x is still holding the descent,
         // and rect.y is still holding the ascent ...
@@ -414,17 +405,17 @@ nsMathMLContainerFrame::Stretch(nsIRende
               NS_STRETCH_DIRECTION_VERTICAL : NS_STRETCH_DIRECTION_HORIZONTAL;
 
           GetPreferredStretchSize(aRenderingContext, STRETCH_CONSIDER_EMBELLISHMENTS,
                                   stretchDir, containerSize);
 
           nsIFrame* childFrame = mFrames.FirstChild();
           while (childFrame) {
             if (childFrame != mPresentationData.baseFrame) {
-              childFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+              mathMLFrame = do_QueryFrame(childFrame);
               if (mathMLFrame) {
                 // retrieve the metrics that was stored at the previous pass
                 GetReflowAndBoundingMetricsFor(childFrame, 
                   childSize, childSize.mBoundingMetrics);
                 // do the stretching...
                 mathMLFrame->Stretch(aRenderingContext, stretchDir,
                                      containerSize, childSize);
                 // store the updated metrics
@@ -529,18 +520,17 @@ nsMathMLContainerFrame::FinalizeReflow(n
     return rv;
   }
 
   PRBool parentWillFireStretch = PR_FALSE;
   if (!placeOrigin) {
     // This means the rect.x and rect.y of our children were not set!!
     // Don't go without checking to see if our parent will later fire a Stretch() command
     // targeted at us. The Stretch() will cause the rect.x and rect.y to clear...
-    nsIMathMLFrame* mathMLFrame;
-    mParent->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+    nsIMathMLFrame* mathMLFrame = do_QueryFrame(mParent);
     if (mathMLFrame) {
       nsEmbellishData embellishData;
       nsPresentationData presentationData;
       mathMLFrame->GetEmbellishData(embellishData);
       mathMLFrame->GetPresentationData(presentationData);
       if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(presentationData.flags) ||
           NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(presentationData.flags) ||
           (NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags)
@@ -612,18 +602,17 @@ nsMathMLContainerFrame::FinalizeReflow(n
 // a subtree that may contain non-mathml container frames
 /* static */ void
 nsMathMLContainerFrame::PropagatePresentationDataFor(nsIFrame*       aFrame,
                                                      PRUint32        aFlagsValues,
                                                      PRUint32        aFlagsToUpdate)
 {
   if (!aFrame || !aFlagsToUpdate)
     return;
-  nsIMathMLFrame* mathMLFrame;
-  aFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+  nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
   if (mathMLFrame) {
     // update
     mathMLFrame->UpdatePresentationData(aFlagsValues,
                                         aFlagsToUpdate);
     // propagate using the base method to make sure that the control
     // is passed on to MathML frames that may be overloading the method
     mathMLFrame->UpdatePresentationDataFromChildAt(0, -1,
       aFlagsValues, aFlagsToUpdate);
@@ -706,26 +695,24 @@ nsMathMLContainerFrame::BuildDisplayList
 nsMathMLContainerFrame::RebuildAutomaticDataForChildren(nsIFrame* aParentFrame)
 {
   // 1. As we descend the tree, make each child frame inherit data from
   // the parent
   // 2. As we ascend the tree, transmit any specific change that we want
   // down the subtrees
   nsIFrame* childFrame = aParentFrame->GetFirstChild(nsnull);
   while (childFrame) {
-    nsIMathMLFrame* childMathMLFrame;
-    childFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&childMathMLFrame);
+    nsIMathMLFrame* childMathMLFrame = do_QueryFrame(childFrame);
     if (childMathMLFrame) {
       childMathMLFrame->InheritAutomaticData(aParentFrame);
     }
     RebuildAutomaticDataForChildren(childFrame);
     childFrame = childFrame->GetNextSibling();
   }
-  nsIMathMLFrame* mathMLFrame;
-  aParentFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+  nsIMathMLFrame* mathMLFrame = do_QueryFrame(aParentFrame);
   if (mathMLFrame) {
     mathMLFrame->TransmitAutomaticData();
   }
 }
 
 /* static */ nsresult
 nsMathMLContainerFrame::ReLayoutChildren(nsIFrame* aParentFrame,
                                          nsFrameState aBits)
@@ -736,18 +723,17 @@ nsMathMLContainerFrame::ReLayoutChildren
   // walk-up to the first frame that is a MathML frame, stop if we reach <math>
   nsIFrame* frame = aParentFrame;
   while (1) {
      nsIFrame* parent = frame->GetParent();
      if (!parent || !parent->GetContent())
        break;
 
     // stop if it is a MathML frame
-    nsIMathMLFrame* mathMLFrame;
-    frame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+    nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
     if (mathMLFrame)
       break;
 
     // stop if we reach the root <math> tag
     nsIContent* content = frame->GetContent();
     NS_ASSERTION(content, "dangling frame without a content node");
     if (!content)
       break;
@@ -905,18 +891,17 @@ nsMathMLContainerFrame::ReflowChild(nsIF
   // from a generated content such as :before { content: open-quote } or 
   // :after { content: close-quote }. Unfortunately, the other frames out-there
   // may expect their own invariants that are not met when we mix things.
   // Hence we do not claim their support, but we will nevertheless attempt to keep
   // them in the flow, if we can get their desired size. We observed that most
   // frames may be reflowed generically, but nsInlineFrames need extra care.
 
 #ifdef DEBUG
-  nsInlineFrame* inlineFrame;
-  aChildFrame->QueryInterface(kInlineFrameCID, (void**)&inlineFrame);
+  nsInlineFrame* inlineFrame = do_QueryFrame(aChildFrame);
   NS_ASSERTION(!inlineFrame, "Inline frames should be wrapped in blocks");
 #endif
   
   nsresult rv = nsHTMLContainerFrame::
          ReflowChild(aChildFrame, aPresContext, aDesiredSize, aReflowState,
                      0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
 
   if (NS_FAILED(rv))
@@ -1002,18 +987,17 @@ nsMathMLContainerFrame::Reflow(nsPresCon
     // include them in the caculations of the size of stretchy elements
     nsBoundingMetrics containerSize;
     GetPreferredStretchSize(*aReflowState.rendContext, 0, stretchDir,
                             containerSize);
 
     // fire the stretch on each child
     childFrame = mFrames.FirstChild();
     while (childFrame) {
-      nsIMathMLFrame* mathMLFrame;
-      childFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
       if (mathMLFrame) {
         // retrieve the metrics that was stored at the previous pass
         nsHTMLReflowMetrics childDesiredSize;
         GetReflowAndBoundingMetricsFor(childFrame,
           childDesiredSize, childDesiredSize.mBoundingMetrics);
 
         mathMLFrame->Stretch(*aReflowState.rendContext, stretchDir,
                              containerSize, childDesiredSize);
--- a/layout/mathml/base/src/nsMathMLContainerFrame.h
+++ b/layout/mathml/base/src/nsMathMLContainerFrame.h
@@ -66,17 +66,17 @@
 #define STRETCH_CONSIDER_EMBELLISHMENTS 0x00000002 // size calculations include embellishments
 
 class nsMathMLContainerFrame : public nsHTMLContainerFrame,
                                public nsMathMLFrame {
   friend class nsMathMLmfencedFrame;
 public:
   nsMathMLContainerFrame(nsStyleContext* aContext) : nsHTMLContainerFrame(aContext) {}
 
-  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_QUERYFRAME
 
   // --------------------------------------------------------------------------
   // Overloaded nsMathMLFrame methods -- see documentation in nsIMathMLFrame.h
 
   NS_IMETHOD
   Stretch(nsIRenderingContext& aRenderingContext,
           nsStretchDirection   aStretchDirection,
           nsBoundingMetrics&   aContainerSize,
--- a/layout/mathml/base/src/nsMathMLForeignFrameWrapper.cpp
+++ b/layout/mathml/base/src/nsMathMLForeignFrameWrapper.cpp
@@ -49,19 +49,19 @@
 #include "nsPresContext.h"
 #include "nsStyleContext.h"
 #include "nsStyleConsts.h"
 #include "nsIRenderingContext.h"
 #include "nsIFontMetrics.h"
 
 #include "nsMathMLForeignFrameWrapper.h"
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLForeignFrameWrapper, nsMathMLFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLForeignFrameWrapper, nsMathMLFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLForeignFrameWrapper, nsBlockFrame, nsMathMLFrame)
+NS_QUERYFRAME_HEAD(nsMathMLForeignFrameWrapper)
+  NS_QUERYFRAME_ENTRY(nsMathMLFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
 
 nsIFrame*
 NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLForeignFrameWrapper(aContext);
 }
 
 NS_IMETHODIMP
--- a/layout/mathml/base/src/nsMathMLForeignFrameWrapper.h
+++ b/layout/mathml/base/src/nsMathMLForeignFrameWrapper.h
@@ -47,17 +47,17 @@
 #include "nsCOMPtr.h"
 #include "nsMathMLContainerFrame.h"
 
 class nsMathMLForeignFrameWrapper : public nsBlockFrame,
                                     public nsMathMLFrame {
 public:
   friend nsIFrame* NS_NewMathMLForeignFrameWrapper(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_QUERYFRAME
 
   // Overloaded nsIMathMLFrame methods
 
   NS_IMETHOD
   UpdatePresentationDataFromChildAt(PRInt32         aFirstIndex,
                                     PRInt32         aLastIndex,
                                     PRUint32        aFlagsValues,
                                     PRUint32        aFlagsToUpdate)
--- a/layout/mathml/base/src/nsMathMLFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLFrame.cpp
@@ -55,21 +55,16 @@
 #include "nsIURI.h"
 #include "nsContentCID.h"
 #include "nsAutoPtr.h"
 #include "nsStyleSet.h"
 #include "nsStyleUtil.h"
 #include "nsDisplayList.h"
 #include "nsAttrName.h"
 
-static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID);
-
-
-NS_IMPL_QUERY_INTERFACE1(nsMathMLFrame, nsIMathMLFrame)
-
 eMathMLFrameType
 nsMathMLFrame::GetMathMLFrameType()
 {
   // see if it is an embellished operator (mapped to 'Op' in TeX)
   if (mEmbellishData.coreFrame)
     return GetMathMLFrameTypeFor(mEmbellishData.coreFrame);
 
   // if it has a prescribed base, fetch the type from there
@@ -187,18 +182,17 @@ nsMathMLFrame::GetEmbellishDataFrom(nsIF
   // initialize OUT params
   aEmbellishData.flags = 0;
   aEmbellishData.coreFrame = nsnull;
   aEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
   aEmbellishData.leftSpace = 0;
   aEmbellishData.rightSpace = 0;
 
   if (aFrame && aFrame->IsFrameOfType(nsIFrame::eMathML)) {
-    nsIMathMLFrame* mathMLFrame;
-    CallQueryInterface(aFrame, &mathMLFrame);
+    nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
     if (mathMLFrame) {
       mathMLFrame->GetEmbellishData(aEmbellishData);
     }
   }
 }
 
 // helper to get the presentation data of a frame, by possibly walking up
 // the frame hierarchy if we happen to be surrounded by non-MathML frames.
@@ -210,18 +204,17 @@ nsMathMLFrame::GetPresentationDataFrom(n
   // initialize OUT params
   aPresentationData.flags = 0;
   aPresentationData.baseFrame = nsnull;
   aPresentationData.mstyle = nsnull;
 
   nsIFrame* frame = aFrame;
   while (frame) {
     if (frame->IsFrameOfType(nsIFrame::eMathML)) {
-      nsIMathMLFrame* mathMLFrame;
-      CallQueryInterface(frame, &mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
       if (mathMLFrame) {
         mathMLFrame->GetPresentationData(aPresentationData);
         break;
       }
     }
     // stop if the caller doesn't want to lookup beyond the frame
     if (!aClimbTree) {
       break;
@@ -265,18 +258,17 @@ nsMathMLFrame::GetAttribute(nsIContent* 
   }
 
   nsIFrame* mstyleParent = aMathMLmstyleFrame->GetParent();
 
   nsPresentationData mstyleParentData;
   mstyleParentData.mstyle = nsnull;
 
   if (mstyleParent) {
-    nsIMathMLFrame* mathMLFrame;
-    CallQueryInterface(mstyleParent, &mathMLFrame);
+    nsIMathMLFrame* mathMLFrame = do_QueryFrame(mstyleParent);
     if (mathMLFrame) {
       mathMLFrame->GetPresentationData(mstyleParentData);
     }
   }
 
   // recurse all the way up into the <mstyle> hierarchy
   return GetAttribute(aMathMLmstyleFrame->GetContent(),
                       mstyleParentData.mstyle, aAttributeAtom, aValue);
--- a/layout/mathml/base/src/nsMathMLFrame.h
+++ b/layout/mathml/base/src/nsMathMLFrame.h
@@ -52,30 +52,16 @@
 #include "nsMathMLElement.h"
 
 class nsMathMLChar;
 
 // Concrete base class with default methods that derived MathML frames can override
 class nsMathMLFrame : public nsIMathMLFrame {
 public:
 
-  // nsISupports ------
-
-  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-
-  NS_IMETHOD_(nsrefcnt) AddRef() {
-    // not meaningfull for frames
-    return 1;
-  }
-
-  NS_IMETHOD_(nsrefcnt) Release() {
-    // not meaningfull for frames
-    return 1;
-  }
-
   // nsIMathMLFrame ---
 
   NS_IMETHOD
   GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
     aBoundingMetrics = mBoundingMetrics;
     return NS_OK;
   }
 
@@ -224,18 +210,17 @@ public:
   ParseNamedSpaceValue(nsIFrame*   aMathMLmstyleFrame,
                        nsString&   aString,
                        nsCSSValue& aCSSValue);
 
   static eMathMLFrameType
   GetMathMLFrameTypeFor(nsIFrame* aFrame)
   {
     if (aFrame->IsFrameOfType(nsIFrame::eMathML)) {
-      nsIMathMLFrame* mathMLFrame;
-      CallQueryInterface(aFrame, &mathMLFrame);
+      nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
       if (mathMLFrame)
         return mathMLFrame->GetMathMLFrameType();
     }
     return eMathMLFrameType_UNKNOWN;
   }
 
   // estimate of the italic correction
   static void
--- a/layout/mathml/base/src/nsMathMLmactionFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLmactionFrame.cpp
@@ -69,22 +69,31 @@
 //
 
 #define NS_MATHML_ACTION_TYPE_NONE         0
 #define NS_MATHML_ACTION_TYPE_TOGGLE       1
 #define NS_MATHML_ACTION_TYPE_STATUSLINE   2
 #define NS_MATHML_ACTION_TYPE_TOOLTIP      3 // unsupported
 #define NS_MATHML_ACTION_TYPE_RESTYLE      4
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLmactionFrame, nsMathMLContainerFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmactionFrame, nsMathMLContainerFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED2(nsMathMLmactionFrame,
-                                   nsMathMLContainerFrame,
-                                   nsIDOMMouseListener,
-                                   nsIDOMEventListener)
+NS_IMETHODIMP_(nsrefcnt)
+nsMathMLmactionFrame::AddRef()
+{
+  return 2;
+}
+
+NS_IMETHODIMP_(nsrefcnt)
+nsMathMLmactionFrame::Release()
+{
+  return 1;
+}
+
+NS_IMPL_QUERY_INTERFACE2(nsMathMLmactionFrame,
+                         nsIDOMMouseListener,
+                         nsIDOMEventListener)
 
 nsIFrame*
 NS_NewMathMLmactionFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmactionFrame(aContext);
 }
 
 nsMathMLmactionFrame::~nsMathMLmactionFrame()
--- a/layout/mathml/base/src/nsMathMLmfencedFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLmfencedFrame.cpp
@@ -346,18 +346,17 @@ nsMathMLmfencedFrame::doReflow(nsPresCon
   }
   else {
     // case when the call is made for mfenced
     aForFrame->GetPreferredStretchSize(*aReflowState.rendContext,
                                        0, /* i.e., without embellishments */
                                        stretchDir, containerSize);
     childFrame = firstChild;
     while (childFrame) {
-      nsIMathMLFrame* mathmlChild;
-      childFrame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathmlChild);
+      nsIMathMLFrame* mathmlChild = do_QueryFrame(childFrame);
       if (mathmlChild) {
         nsHTMLReflowMetrics childDesiredSize;
         // retrieve the metrics that was stored at the previous pass
         GetReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
                                          childDesiredSize.mBoundingMetrics);
 
         mathmlChild->Stretch(*aReflowState.rendContext, 
                              stretchDir, containerSize, childDesiredSize);
--- a/layout/mathml/base/src/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLmtableFrame.cpp
@@ -344,19 +344,19 @@ ListMathMLTree(nsIFrame* atLeast)
   CallQueryInterface(f, &fdbg);
   fdbg->List(stdout, 0);
 }
 #endif
 
 // --------
 // implementation of nsMathMLmtableOuterFrame
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLmtableOuterFrame, nsMathMLFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmtableOuterFrame, nsMathMLFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLmtableOuterFrame, nsTableOuterFrame, nsMathMLFrame)
+NS_QUERYFRAME_HEAD(nsMathMLmtableOuterFrame)
+  NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsTableOuterFrame)
 
 nsIFrame*
 NS_NewMathMLmtableOuterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmtableOuterFrame(aContext);
 }
 
 nsMathMLmtableOuterFrame::~nsMathMLmtableOuterFrame()
@@ -642,23 +642,16 @@ nsMathMLmtableOuterFrame::Reflow(nsPresC
   mBoundingMetrics.rightBearing = aDesiredSize.width;
 
   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
 
   return rv;
 }
 
-// --------
-// implementation of nsMathMLmtableFrame
-
-NS_IMPL_ADDREF_INHERITED(nsMathMLmtableFrame, nsTableFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmtableFrame, nsTableFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED0(nsMathMLmtableFrame, nsTableFrame)
-
 nsIFrame*
 NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmtableFrame(aContext);
 }
 
 nsMathMLmtableFrame::~nsMathMLmtableFrame()
 {
@@ -683,20 +676,16 @@ nsMathMLmtableFrame::RestyleTable()
   // Explicitly request a re-resolve and reflow in our subtree to pick up any changes
   PresContext()->PresShell()->FrameConstructor()->
     PostRestyleEvent(mContent, eReStyle_Self, nsChangeHint_ReflowFrame);
 }
 
 // --------
 // implementation of nsMathMLmtrFrame
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLmtrFrame, nsTableRowFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmtrFrame, nsTableRowFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED0(nsMathMLmtrFrame, nsTableRowFrame)
-
 nsIFrame*
 NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmtrFrame(aContext);
 }
 
 nsMathMLmtrFrame::~nsMathMLmtrFrame()
 {
@@ -744,20 +733,16 @@ nsMathMLmtrFrame::AttributeChanged(PRInt
     PostRestyleEvent(mContent, eReStyle_Self, nsChangeHint_ReflowFrame);
 
   return NS_OK;
 }
 
 // --------
 // implementation of nsMathMLmtdFrame
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLmtdFrame, nsTableCellFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmtdFrame, nsTableCellFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED0(nsMathMLmtdFrame, nsTableCellFrame)
-
 nsIFrame*
 NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmtdFrame(aContext);
 }
 
 nsMathMLmtdFrame::~nsMathMLmtdFrame()
 {
@@ -830,19 +815,19 @@ nsMathMLmtdFrame::AttributeChanged(PRInt
   }
 
   return NS_OK;
 }
 
 // --------
 // implementation of nsMathMLmtdInnerFrame
 
-NS_IMPL_ADDREF_INHERITED(nsMathMLmtdInnerFrame, nsMathMLFrame)
-NS_IMPL_RELEASE_INHERITED(nsMathMLmtdInnerFrame, nsMathMLFrame)
-NS_IMPL_QUERY_INTERFACE_INHERITED1(nsMathMLmtdInnerFrame, nsBlockFrame, nsMathMLFrame)
+NS_QUERYFRAME_HEAD(nsMathMLmtdInnerFrame)
+  NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
 
 nsIFrame*
 NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsMathMLmtdInnerFrame(aContext);
 }
 
 nsMathMLmtdInnerFrame::~nsMathMLmtdInnerFrame()
--- a/layout/mathml/base/src/nsMathMLmtableFrame.h
+++ b/layout/mathml/base/src/nsMathMLmtableFrame.h
@@ -47,17 +47,17 @@
 //
 
 class nsMathMLmtableOuterFrame : public nsTableOuterFrame,
                                  public nsMathMLFrame
 {
 public:
   friend nsIFrame* NS_NewMathMLmtableOuterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_QUERYFRAME
 
   // Overloaded nsIMathMLFrame methods
 
   NS_IMETHOD
   InheritAutomaticData(nsIFrame* aParent);
 
   NS_IMETHOD
   UpdatePresentationData(PRUint32 aFlagsValues,
@@ -102,18 +102,16 @@ protected:
 
 // --------------
 
 class nsMathMLmtableFrame : public nsTableFrame
 {
 public:
   friend nsIFrame* NS_NewMathMLmtableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
-
   // Overloaded nsTableFrame methods
 
   NS_IMETHOD
   SetInitialChildList(nsIAtom*  aListName,
                       nsIFrame* aChildList);
 
   NS_IMETHOD
   AppendFrames(nsIAtom*  aListName,
@@ -161,18 +159,16 @@ protected:
 
 // --------------
 
 class nsMathMLmtrFrame : public nsTableRowFrame
 {
 public:
   friend nsIFrame* NS_NewMathMLmtrFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
-
   // overloaded nsTableRowFrame methods
 
   NS_IMETHOD
   AttributeChanged(PRInt32  aNameSpaceID,
                    nsIAtom* aAttribute,
                    PRInt32  aModType);
 
   NS_IMETHOD
@@ -226,18 +222,16 @@ protected:
 
 // --------------
 
 class nsMathMLmtdFrame : public nsTableCellFrame
 {
 public:
   friend nsIFrame* NS_NewMathMLmtdFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
-
   // overloaded nsTableCellFrame methods
 
   NS_IMETHOD
   AttributeChanged(PRInt32  aNameSpaceID,
                    nsIAtom* aAttribute,
                    PRInt32  aModType);
 
   virtual PRInt32 GetRowSpan();
@@ -255,17 +249,17 @@ protected:
 
 // --------------
 
 class nsMathMLmtdInnerFrame : public nsBlockFrame,
                               public nsMathMLFrame {
 public:
   friend nsIFrame* NS_NewMathMLmtdInnerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_QUERYFRAME
 
   // Overloaded nsIMathMLFrame methods
 
   NS_IMETHOD
   UpdatePresentationDataFromChildAt(PRInt32         aFirstIndex,
                                     PRInt32         aLastIndex,
                                     PRUint32        aFlagsValues,
                                     PRUint32        aFlagsToUpdate)
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -356,17 +356,17 @@ nsPrintEngine::GetSeqFrameAndCountPagesI
                                                 PRInt32&      aCount)
 {
   NS_ENSURE_ARG_POINTER(aPO);
 
   // Finds the SimplePageSequencer frame
   nsIPageSequenceFrame* seqFrame = nsnull;
   aPO->mPresShell->GetPageSequenceFrame(&seqFrame);
   if (seqFrame) {
-    CallQueryInterface(seqFrame, &aSeqFrame);
+    aSeqFrame = do_QueryFrame(seqFrame);
   } else {
     aSeqFrame = nsnull;
   }
   if (aSeqFrame == nsnull) return NS_ERROR_FAILURE;
 
   // first count the total number of pages
   aCount = 0;
   nsIFrame* pageFrame = aSeqFrame->GetFirstChild(nsnull);
@@ -2059,18 +2059,18 @@ nsPrintEngine::CalcNumPrintablePages(PRI
   // and printable pages
   PRInt32 i;
   for (i=0; i<mPrt->mPrintDocList->Count(); i++) {
     nsPrintObject* po = (nsPrintObject*)mPrt->mPrintDocList->ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     if (po->mPresContext && po->mPresContext->IsRootPaginatedDocument()) {
       nsIPageSequenceFrame* pageSequence;
       po->mPresShell->GetPageSequenceFrame(&pageSequence);
-      nsIFrame * seqFrame;
-      if (NS_SUCCEEDED(CallQueryInterface(pageSequence, &seqFrame))) {
+      nsIFrame * seqFrame = do_QueryFrame(pageSequence);
+      if (seqFrame) {
         nsIFrame* frame = seqFrame->GetFirstChild(nsnull);
         while (frame) {
           aNumPages++;
           frame = frame->GetNextSibling();
         }
       }
     }
   }
@@ -2143,20 +2143,19 @@ nsPrintEngine::DoPrint(nsPrintObject * a
 
     // We are done preparing for printing, so we can turn this off
     mPrt->mPreparingForPrint = PR_FALSE;
 
     // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging
     if (nsnull != mPrt->mDebugFilePtr) {
 #ifdef NS_DEBUG
       // output the regression test
-      nsIFrameDebug* fdbg;
       nsIFrame* root = poPresShell->FrameManager()->GetRootFrame();
-
-      if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) {
+      nsIFrameDebug* fdbg = do_QueryFrame(root);
+      if (fdbg) {
         fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRUE);
       }
       fclose(mPrt->mDebugFilePtr);
       SetIsPrinting(PR_FALSE);
 #endif
     } else {
 #ifdef EXTENDED_DEBUG_PRINTING
       nsIFrame* rootFrame = poPresShell->FrameManager()->GetRootFrame();
@@ -2244,18 +2243,18 @@ nsPrintEngine::DoPrint(nsPrintObject * a
                 pageHeight -= totalMargin.top + totalMargin.bottom;
                 PRInt32 totalPages = NSToIntCeil(float(selectionHgt) * aPO->mZoomRatio / float(pageHeight));
                 pageSequence->SetTotalNumPages(totalPages);
               }
             }
           }
         }
 
-        nsIFrame * seqFrame;
-        if (NS_FAILED(CallQueryInterface(pageSequence, &seqFrame))) {
+        nsIFrame * seqFrame = do_QueryFrame(pageSequence);
+        if (!seqFrame) {
           SetIsPrinting(PR_FALSE);
           return NS_ERROR_FAILURE;
         }
 
         mPageSeqFrame = pageSequence;
         mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr);
 
         // Schedule Page to Print
@@ -2500,18 +2499,18 @@ nsPrintEngine::GetPageRangeForSelection(
 {
   NS_ASSERTION(aPresShell, "Pointer is null!");
   NS_ASSERTION(aPresContext, "Pointer is null!");
   NS_ASSERTION(aSelection, "Pointer is null!");
   NS_ASSERTION(aPageSeqFrame, "Pointer is null!");
   NS_ASSERTION(aStartFrame, "Pointer is null!");
   NS_ASSERTION(aEndFrame, "Pointer is null!");
 
-  nsIFrame * seqFrame;
-  if (NS_FAILED(CallQueryInterface(aPageSeqFrame, &seqFrame))) {
+  nsIFrame * seqFrame = do_QueryFrame(aPageSeqFrame);
+  if (!seqFrame) {
     return NS_ERROR_FAILURE;
   }
 
   nsIFrame * startFrame = nsnull;
   nsIFrame * endFrame   = nsnull;
 
   // start out with the sequence frame and search the entire frame tree
   // capturing the starting and ending child frames of the selection
@@ -3291,19 +3290,18 @@ static void RootFrameList(nsPresContext*
 {
   if (!aPresContext || !out)
     return;
 
   nsIPresShell *shell = aPresContext->GetPresShell();
   if (shell) {
     nsIFrame* frame = shell->FrameManager()->GetRootFrame();
     if (frame) {
-      nsIFrameDebug* debugFrame;
-      nsresult rv = CallQueryInterface(frame, &debugFrame);
-      if (NS_SUCCEEDED(rv))
+      nsIFrameDebug* debugFrame = do_QueryFrame(frame);
+      if (debugFrame)
         debugFrame->List(aPresContext, out, aIndent);
     }
   }
 }
 
 /** ---------------------------------------------------
  *  Dumps Frames for Printing
  */
@@ -3319,19 +3317,19 @@ static void DumpFrames(FILE*            
   NS_ASSERTION(aFrame, "Pointer is null!");
 
   nsIFrame* child = aFrame->GetFirstChild(nsnull);
   while (child != nsnull) {
     for (PRInt32 i=0;i<aLevel;i++) {
      fprintf(out, "  ");
     }
     nsAutoString tmp;
-    nsIFrameDebug*  frameDebug;
-
-    if (NS_SUCCEEDED(CallQueryInterface(child, &frameDebug))) {
+
+    nsIFrameDebug* frameDebug = do_QueryFrame(child);
+    if (frameDebug) {
       frameDebug->GetFrameName(tmp);
     }
     fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
     PRBool isSelected;
     if (NS_SUCCEEDED(child->IsVisibleForPainting(aPresContext, *aRendContext, PR_TRUE, &isSelected))) {
       fprintf(out, " %p %s", child, isSelected?"VIS":"UVS");
       nsRect rect = child->GetRect();
       fprintf(out, "[%d,%d,%d,%d] ", rect.x, rect.y, rect.width, rect.height);
@@ -3456,18 +3454,18 @@ static void DumpPrintObjectsList(nsVoidA
   PRInt32 cnt = aDocList->Count();
   for (PRInt32 i=0;i<cnt;i++) {
     nsPrintObject* po = (nsPrintObject*)aDocList->ElementAt(i);
     NS_ASSERTION(po, "nsPrintObject can't be null!");
     nsIFrame* rootFrame = nsnull;
     if (po->mPresShell) {
       rootFrame = po->mPresShell->FrameManager()->GetRootFrame();
       while (rootFrame != nsnull) {
-        nsIPageSequenceFrame * sqf = nsnull;
-        if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf))) {
+        nsIPageSequenceFrame * sqf = do_QueryFrame(rootFrame);
+        if (sqf) {
           break;
         }
         rootFrame = rootFrame->GetFirstChild(nsnull);
       }
     }
 
     PR_PL(("%s %d %d %d %p %p %p %p %p   %d   %d,%d,%d,%d\n", types[po->mFrameType],
             po->IsPrintable(), po->mPrintAsIs, po->mHasBeenPrinted, po, po->mDocShell.get(), po->mSeqFrame,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -3073,18 +3073,17 @@ nsComputedDOMStyle::GetAbsoluteOffset(PR
     if (container->GetType() == nsGkAtoms::viewportFrame) {
       // For absolutely positioned frames scrollbars are taken into
       // account by virtue of getting a containing block that does
       // _not_ include the scrollbars.  For fixed positioned frames,
       // the containing block is the viewport, which _does_ include
       // scrollbars.  We have to do some extra work.
       // the first child in the default frame list is what we want
       nsIFrame* scrollingChild = container->GetFirstChild(nsnull);
-      nsCOMPtr<nsIScrollableFrame> scrollFrame =
-        do_QueryInterface(scrollingChild);
+      nsIScrollableFrame *scrollFrame = do_QueryFrame(scrollingChild);
       if (scrollFrame) {
         scrollbarSizes = scrollFrame->GetActualScrollbarSizes();
       }
     }
 
     nscoord offset = 0;
     switch (aSide) {
       case NS_SIDE_TOP:
--- a/layout/style/nsICSSPseudoComparator.h
+++ b/layout/style/nsICSSPseudoComparator.h
@@ -35,26 +35,22 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* internal interface for implementing complex pseudo-classes */
 
 #ifndef nsICSSPseudoComparator_h___
 #define nsICSSPseudoComparator_h___
 
-// {4B122120-0F2D-4e88-AFE9-84A9AE2404E5}
-#define NS_ICSS_PSEUDO_COMPARATOR_IID     \
-{ 0x4b122120, 0xf2d, 0x4e88, { 0xaf, 0xe9, 0x84, 0xa9, 0xae, 0x24, 0x4, 0xe5 } }
+#include "nsQueryFrame.h"
 
 class nsIAtom;
 struct nsCSSSelector;
 
-class nsICSSPseudoComparator: public nsISupports {
+class nsICSSPseudoComparator
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_PSEUDO_COMPARATOR_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsICSSPseudoComparator)
 
   NS_IMETHOD  PseudoMatches(nsIAtom* aTag, nsCSSSelector* aSelector, PRBool* aResult)=0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSPseudoComparator,
-                              NS_ICSS_PSEUDO_COMPARATOR_IID)
-
 #endif /* nsICSSPseudoComparator_h___ */
--- a/layout/svg/base/src/nsISVGChildFrame.h
+++ b/layout/svg/base/src/nsISVGChildFrame.h
@@ -35,34 +35,30 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_ISVGCHILDFRAME_H__
 #define __NS_ISVGCHILDFRAME_H__
 
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 #include "nsCOMPtr.h"
 #include "nsRect.h"
 
 class gfxContext;
 class nsPresContext;
 class nsIDOMSVGRect;
 class nsIDOMSVGMatrix;
 class nsSVGRenderState;
 
-#define NS_ISVGCHILDFRAME_IID \
-{ 0xfc3ee9b2, 0xaf40, 0x416d, \
-  { 0xa8, 0x51, 0xb4, 0x68, 0xa4, 0xe4, 0x8b, 0xcd } }
-
-class nsISVGChildFrame : public nsISupports {
+class nsISVGChildFrame : public nsQueryFrame
+{
 public:
-
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGCHILDFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGChildFrame)
 
   // Paint this frame - aDirtyRect is the area being redrawn, in frame
   // offset pixel coordinates
   NS_IMETHOD PaintSVG(nsSVGRenderState* aContext,
                       const nsIntRect *aDirtyRect)=0;
 
   // Check if this frame or children contain the given point,
   // specified in app units relative to the origin of the outer
@@ -106,12 +102,10 @@ public:
 
   // Are we a container frame?
   NS_IMETHOD_(PRBool) IsDisplayContainer()=0;
 
   // Does this frame have an current covered region in mRect (aka GetRect())?
   NS_IMETHOD_(PRBool) HasValidCoveredRect()=0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGChildFrame, NS_ISVGCHILDFRAME_IID)
-
 #endif // __NS_ISVGCHILDFRAME_H__
 
--- a/layout/svg/base/src/nsISVGGlyphFragmentLeaf.h
+++ b/layout/svg/base/src/nsISVGGlyphFragmentLeaf.h
@@ -41,27 +41,20 @@
 
 #include "nsISVGGlyphFragmentNode.h"
 #include "nsIDOMSVGLengthList.h"
 
 class nsIDOMSVGPoint;
 class nsIDOMSVGRect;
 class nsSVGTextPathFrame;
 
-
-// {ec9a9965-3ff2-4bb5-b0e2-dd8830e9f41a}
-#define NS_ISVGGLYPHFRAGMENTLEAF_IID \
-  { 0xec9a9965, 0x3ff2, 0x4bb5, \
-    { 0xb0, 0xe2, 0xdd, 0x88, 0x30, 0xe9, 0xf4, 0x1a } }
-
 class nsISVGGlyphFragmentLeaf : public nsISVGGlyphFragmentNode
 {
 public:
-
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGGLYPHFRAGMENTLEAF_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGGlyphFragmentLeaf)
 
   NS_IMETHOD GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)=0;
   NS_IMETHOD GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)=0;
   NS_IMETHOD GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)=0;
   NS_IMETHOD GetRotationOfChar(PRUint32 charnum, float *_retval)=0;
 
   enum { BASELINE_ALPHABETIC = 0U };
   enum { BASELINE_HANGING = 1U };
@@ -84,12 +77,9 @@ public:
   NS_IMETHOD_(already_AddRefed<nsIDOMSVGLengthList>) GetX()=0;
   NS_IMETHOD_(already_AddRefed<nsIDOMSVGLengthList>) GetY()=0;
   NS_IMETHOD_(already_AddRefed<nsIDOMSVGLengthList>) GetDx()=0;
   NS_IMETHOD_(already_AddRefed<nsIDOMSVGLengthList>) GetDy()=0;
   NS_IMETHOD_(PRUint16) GetTextAnchor()=0;
   NS_IMETHOD_(PRBool) IsAbsolutelyPositioned()=0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGGlyphFragmentLeaf,
-                              NS_ISVGGLYPHFRAGMENTLEAF_IID)
-
 #endif // __NS_ISVGGLYPHFRAGMENTLEAF_H__
--- a/layout/svg/base/src/nsISVGGlyphFragmentNode.h
+++ b/layout/svg/base/src/nsISVGGlyphFragmentNode.h
@@ -35,40 +35,33 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #ifndef __NS_ISVGGLYPHFRAGMENTNODE_H__
 #define __NS_ISVGGLYPHFRAGMENTNODE_H__
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 
 class nsISVGGlyphFragmentLeaf;
 class nsIDOMSVGPoint;
 
 #define PRESERVE_WHITESPACE       0x00
 #define COMPRESS_WHITESPACE       0x01
 #define TRIM_LEADING_WHITESPACE   0x02
 #define TRIM_TRAILING_WHITESPACE  0x04
 
-#define NS_ISVGGLYPHFRAGMENTNODE_IID \
-{ 0x1297716a, 0xd68d, 0x4c9d, { 0x8e, 0xf8, 0x9e, 0x01, 0x1d, 0x78, 0x21, 0xd0 } }
-
-class nsISVGGlyphFragmentNode : public nsISupports
+class nsISVGGlyphFragmentNode : public nsQueryFrame
 {
 public:
-  
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGGLYPHFRAGMENTNODE_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGGlyphFragmentNode)
 
   NS_IMETHOD_(PRUint32) GetNumberOfChars()=0;
   NS_IMETHOD_(float) GetComputedTextLength()=0;
   NS_IMETHOD_(float) GetSubStringLength(PRUint32 charnum, PRUint32 fragmentChars)=0;
   NS_IMETHOD_(PRInt32) GetCharNumAtPosition(nsIDOMSVGPoint *point)=0;
   NS_IMETHOD_(nsISVGGlyphFragmentLeaf *) GetFirstGlyphFragment()=0;
   NS_IMETHOD_(nsISVGGlyphFragmentLeaf *) GetNextGlyphFragment()=0;
   NS_IMETHOD_(void) SetWhitespaceHandling(PRUint8 aWhitespaceHandling)=0;
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGGlyphFragmentNode,
-                              NS_ISVGGLYPHFRAGMENTNODE_IID)
-
 #endif // __NS_ISVGGLYPHFRAGMENTNODE_H__
--- a/layout/svg/base/src/nsISVGSVGFrame.h
+++ b/layout/svg/base/src/nsISVGSVGFrame.h
@@ -34,26 +34,21 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __NS_ISVGSVGFRAME_H__
 #define __NS_ISVGSVGFRAME_H__
 
-#include "nsISupports.h"
+#include "nsQueryFrame.h"
 
-// {C38FDFC3-7030-47CB-BA69-D7C5F45E657C}
-#define NS_ISVGSVGFRAME_IID \
-{ 0xc38fdfc3, 0x7030, 0x47cb, { 0xba, 0x69, 0xd7, 0xc5, 0xf4, 0x5e, 0x65, 0x7c } }
-
-class nsISVGSVGFrame : public nsISupports {
+class nsISVGSVGFrame
+{
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGSVGFRAME_IID)
+  NS_DECLARE_FRAME_ACCESSOR(nsISVGSVGFrame)
 
   NS_IMETHOD SuspendRedraw()=0;        
   NS_IMETHOD UnsuspendRedraw()=0;      
   NS_IMETHOD NotifyViewportChange()=0; 
 };
 
-NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGSVGFrame, NS_ISVGSVGFRAME_IID)
-
 #endif // __NS_ISVGSVGFRAME_H__
--- a/layout/svg/base/src/nsSVGClipPathFrame.cpp
+++ b/layout/svg/base/src/nsSVGClipPathFrame.cpp
@@ -79,18 +79,17 @@ nsSVGClipPathFrame::ClipPaint(nsSVGRende
   PRBool isTrivial = IsTrivial();
 
   nsAutoSVGRenderMode mode(aContext,
                            isTrivial ? nsSVGRenderState::CLIP
                                      : nsSVGRenderState::CLIP_MASK);
 
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame = nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       // The CTM of each frame referencing us can be different.
       SVGFrame->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION | 
                                  nsISVGChildFrame::TRANSFORM_CHANGED);
       SVGFrame->PaintSVG(aContext, nsnull);
     }
   }
 
@@ -116,18 +115,17 @@ nsSVGClipPathFrame::ClipHitTest(nsIFrame
   }
   AutoClipPathReferencer clipRef(this);
 
   mClipParent = aParent,
   mClipParentMatrix = aMatrix;
 
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame = nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       // Notify the child frame that we may be working with a
       // different transform, so it can update its covered region
       // (used to shortcut hit testing).
       SVGFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
 
       if (SVGFrame->GetFrameForPoint(aPoint))
         return PR_TRUE;
@@ -138,19 +136,17 @@ nsSVGClipPathFrame::ClipHitTest(nsIFrame
 
 PRBool
 nsSVGClipPathFrame::IsTrivial()
 {
   PRBool foundChild = PR_FALSE;
 
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame *svgChild = nsnull;
-    CallQueryInterface(kid, &svgChild);
-
+    nsISVGChildFrame *svgChild = do_QueryFrame(kid);
     if (svgChild) {
       // We consider a non-trivial clipPath to be one containing
       // either more than one svg child and/or a svg container
       if (foundChild || svgChild->IsDisplayContainer())
         return PR_FALSE;
       foundChild = PR_TRUE;
     }
   }
--- a/layout/svg/base/src/nsSVGContainerFrame.cpp
+++ b/layout/svg/base/src/nsSVGContainerFrame.cpp
@@ -33,22 +33,19 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsSVGContainerFrame.h"
 #include "nsSVGUtils.h"
 #include "nsSVGOuterSVGFrame.h"
 
-//----------------------------------------------------------------------
-// nsISupports methods
-
-NS_INTERFACE_MAP_BEGIN(nsSVGDisplayContainerFrame)
-  NS_INTERFACE_MAP_ENTRY(nsISVGChildFrame)
-NS_INTERFACE_MAP_END_INHERITING(nsSVGContainerFrame)
+NS_QUERYFRAME_HEAD(nsSVGDisplayContainerFrame)
+  NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsSVGContainerFrame)
 
 nsIFrame*
 NS_NewSVGContainerFrame(nsIPresShell* aPresShell,
                         nsIContent* aContent,
                         nsStyleContext* aContext)
 {
   return new (aPresShell) nsSVGContainerFrame(aContext);
 }
@@ -125,18 +122,17 @@ nsSVGDisplayContainerFrame::InsertFrames
   // its initial reflow (our NS_FRAME_FIRST_REFLOW bit is clear) - bug 399863.
   if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
     nsIFrame* end = nsnull;
     if (lastNewFrame)
       end = lastNewFrame->GetNextSibling();
 
     for (nsIFrame* kid = aFrameList; kid != end;
          kid = kid->GetNextSibling()) {
-      nsISVGChildFrame* SVGFrame = nsnull;
-      CallQueryInterface(kid, &SVGFrame);
+      nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
       if (SVGFrame) {
         SVGFrame->InitialUpdate(); 
       }
     }
   }
 
   return NS_OK;
 }
@@ -187,36 +183,34 @@ nsSVGDisplayContainerFrame::GetCoveredRe
   return nsSVGUtils::GetCoveredRegion(mFrames);
 }
 
 NS_IMETHODIMP
 nsSVGDisplayContainerFrame::UpdateCoveredRegion()
 {
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame = nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       SVGFrame->UpdateCoveredRegion();
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSVGDisplayContainerFrame::InitialUpdate()
 {
   NS_ASSERTION(GetStateBits() & NS_FRAME_FIRST_REFLOW,
                "Yikes! We've been called already! Hopefully we weren't called "
                "before our nsSVGOuterSVGFrame's initial Reflow()!!!");
 
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame = nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       SVGFrame->InitialUpdate();
     }
   }
 
   NS_ASSERTION(!(mState & NS_FRAME_IN_REFLOW),
                "We don't actually participate in reflow");
   
@@ -236,32 +230,30 @@ nsSVGDisplayContainerFrame::NotifySVGCha
   nsSVGUtils::NotifyChildrenOfSVGChange(this, aFlags);
 }
 
 NS_IMETHODIMP
 nsSVGDisplayContainerFrame::NotifyRedrawSuspended()
 {
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame=nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       SVGFrame->NotifyRedrawSuspended();
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSVGDisplayContainerFrame::NotifyRedrawUnsuspended()
 {
   for (nsIFrame* kid = mFrames.FirstChild(); kid;
        kid = kid->GetNextSibling()) {
-    nsISVGChildFrame* SVGFrame = nsnull;
-    CallQueryInterface(kid, &SVGFrame);
+    nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
     if (SVGFrame) {
       SVGFrame->NotifyRedrawUnsuspended();
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/svg/base/src/nsSVGContainerFrame.h
+++ b/layout/svg/base/src/nsSVGContainerFrame.h
@@ -79,23 +79,18 @@ public:
 class nsSVGDisplayContainerFrame : public nsSVGContainerFrame,
                                    public nsISVGChildFrame
 {
 protected:
   nsSVGDisplayContainerFrame(nsStyleContext* aContext) :
     nsSVGContainerFrame(aContext) {}
 
 public:
-  // nsISupports interface:
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
-  NS_IMETHOD_(nsrefcnt) Release() { return 1; }
+  NS_DECL_QUERYFRAME
 
-public:
   // nsIFrame:
   NS_IMETHOD InsertFrames(nsIAtom*        aListName,
                           nsIFrame*       aPrevFrame,
                           nsIFrame*       aFrameList);
   NS_IMETHOD RemoveFrame(nsIAtom*        aListName,
                          nsIFrame*       aOldFrame);
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
--- a/layout/svg/base/src/nsSVGFilterFrame.cpp
+++ b/layout/svg/base/src/nsSVGFilterFrame.cpp
@@ -105,17 +105,17 @@ nsAutoFilterInstance::nsAutoFilterInstan
                                            nsSVGFilterFrame *aFilterFrame,
                                            nsSVGFilterPaintCallback *aPaint,
                                            const nsIntRect *aDirtyOutputRect,
                                            const nsIntRect *aDirtyInputRect,
                                            const nsIntRect *aOverrideSourceBBox)
 {
   nsCOMPtr<nsIDOMSVGMatrix> ctm = nsSVGUtils::GetCanvasTM(aTarget);
 
-  CallQueryInterface(aTarget, &mTarget);
+  mTarget = do_QueryFrame(aTarget);
   if (mTarget) {
     mTarget->SetMatrixPropagation(PR_FALSE);
     mTarget->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
                               nsISVGChildFrame::TRANSFORM_CHANGED);
   }
 
   nsSVGFilterElement *filter = static_cast<nsSVGFilterElement*>(
           aFilterFrame->GetContent());
--- a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
+++ b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
@@ -76,24 +76,21 @@ nsSVGForeignObjectFrame::nsSVGForeignObj
   : nsSVGForeignObjectFrameBase(aContext),
     mInReflow(PR_FALSE)
 {
   AddStateBits(NS_FRAME_REFLOW_ROOT |
                NS_FRAME_MAY_BE_TRANSFORMED_OR_HAVE_RENDERING_OBSERVERS);
 }
 
 //----------------------------------------------------------------------
-// nsISupports methods
+// nsIFrame methods
 
-NS_INTERFACE_MAP_BEGIN(nsSVGForeignObjectFrame)
-  NS_INTERFACE_MAP_ENTRY(nsISVGChildFrame)
-NS_INTERFACE_MAP_END_INHERITING(nsSVGForeignObjectFrameBase)
-
-//----------------------------------------------------------------------
-// nsIFrame methods
+NS_QUERYFRAME_HEAD(nsSVGForeignObjectFrame)
+  NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
+NS_QUERYFRAME_TAIL_INHERITING(nsSVGForeignObjectFrameBase)
 
 NS_IMETHODIMP
 nsSVGForeignObjectFrame::Init(nsIContent* aContent,
                               nsIFrame*   aParent,
                               nsIFrame*   aPrevInFlow)
 {
   nsresult rv = nsSVGForeignObjectFrameBase::Init(aContent, aParent, aPrevInFlow);
   AddStateBits(NS_STATE_SVG_PROPAGATE_TRANSFORM | 
--- a/layout/svg/base/src/nsSVGForeignObjectFrame.h
+++ b/layout/svg/base/src/nsSVGForeignObjectFrame.h
@@ -52,23 +52,19 @@ typedef nsContainerFrame nsSVGForeignObj
 class nsSVGForeignObjectFrame : public nsSVGForeignObjectFrameBase,
                                 public nsISVGChildFrame
 {
   friend nsIFrame*
   NS_NewSVGForeignObjectFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
 protected:
   nsSVGForeignObjectFrame(nsStyleContext* aContext);
   
-  // nsISupports interface:
-  NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
-private:
-  NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
-  NS_IMETHOD_(nsrefcnt) Release() { return 1; }
+public:
+  NS_DECL_QUERYFRAME
 
-public:
   // nsIFrame:  
   NS_IMETHOD  Init(nsIContent* aContent,
                    nsIFrame*   aParent,
                    nsIFrame*   aPrevInFlow);
   virtual void Destroy();
   NS_IMETHOD  AttributeChanged(PRInt32         aNameSpaceID,
                                nsIAtom*        aAttribute,
                                PRInt32         aModType);
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -182,34 +182,33 @@ private:
 
 //----------------------------------------------------------------------
 // Implementation
 
 nsIFrame*
 NS_NewSVGGlyphFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame* parentFrame, nsStyleContext* aContext)
 {
   NS_ASSERTION(parentFrame, "null parent");
-  nsISVGTextContentMetrics *metrics;
-  CallQueryInterface(parentFrame, &metrics);
+  nsISVGTextContentMetrics *metrics = do_QueryFrame(parentFrame);
   NS_ASSERTION(metrics, "trying to construct an SVGGlyphFrame for an invalid container");
   
   NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
                "trying to construct an SVGGlyphFrame for wrong content element");
 
   return new (aPresShell) nsSVGGlyphFrame(aContext);
 }
 
 //----------------------------------------------------------------------
-// nsISupports