Bug 497495 (frame poisoning) part 3b: Mechanical changes to match the nsQueryFrame interface changes in part 3a.

diff --git a/layout/base/nsIPercentHeightObserver.h b/layout/base/nsIPercentHeightObserver.h
--- a/layout/base/nsIPercentHeightObserver.h
+++ b/layout/base/nsIPercentHeightObserver.h
@@ -39,25 +39,26 @@
 #define nsIPercentHeightObserver_h___
 
 #include "nsQueryFrame.h"
 
 struct nsHTMLReflowState;
 class  nsPresContext;
 
 /**
- * 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.
+ * 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
+class nsIPercentHeightObserver : public nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsIPercentHeightObserver)
+  NS_DECL_QUERYFRAME_INTERFACE(nsIPercentHeightObserver)
 
-  // Notify the observer that aReflowState has no computed height, but it has a percent height
+  // 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;
 };
 
-#endif // nsIPercentHeightObserver_h___ 
+#endif // nsIPercentHeightObserver_h___
diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -290,17 +290,17 @@ nsComboboxControlFrame::~nsComboboxContr
 
 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)
+NS_QUERYFRAME_TAIL(nsBlockFrame)
 
 NS_IMPL_QUERY_INTERFACE1(nsComboboxControlFrame, nsIRollupListener)
 
 NS_IMETHODIMP_(nsrefcnt)
 nsComboboxControlFrame::AddRef()
 {
   return 2;
 }
@@ -1052,16 +1052,18 @@ nsComboboxControlFrame::CreateAnonymousC
 
   return NS_OK;
 }
 
 // XXXbz this is a for-now hack.  Now that display:inline-block works,
 // need to revisit this.
 class nsComboboxDisplayFrame : public nsBlockFrame {
 public:
+  NS_DECL_QUERYFRAME(nsComboboxDisplayFrame)
+
   nsComboboxDisplayFrame (nsStyleContext* aContext,
                           nsComboboxControlFrame* aComboBox)
     : nsBlockFrame(aContext),
       mComboBox(aComboBox)
   {}
 
   // Need this so that line layout knows that this block's width
   // depends on the available width.
@@ -1081,16 +1083,19 @@ public:
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
 protected:
   nsComboboxControlFrame* mComboBox;
 };
 
+NS_QUERYFRAME_HEAD(nsComboboxDisplayFrame)
+NS_QUERYFRAME_TAIL(nsBlockFrame)
+
 nsIAtom*
 nsComboboxDisplayFrame::GetType() const
 {
   return nsGkAtoms::comboboxDisplayFrame;
 }
 
 NS_IMETHODIMP
 nsComboboxDisplayFrame::Reflow(nsPresContext*           aPresContext,
diff --git a/layout/forms/nsComboboxControlFrame.h b/layout/forms/nsComboboxControlFrame.h
--- a/layout/forms/nsComboboxControlFrame.h
+++ b/layout/forms/nsComboboxControlFrame.h
@@ -91,17 +91,17 @@ class nsComboboxControlFrame : public ns
 {
 public:
   friend nsIFrame* NS_NewComboboxControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
   friend class nsComboboxDisplayFrame;
 
   nsComboboxControlFrame(nsStyleContext* aContext);
   ~nsComboboxControlFrame();
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsComboboxControlFrame)
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray& aElements);
   virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
 
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp
--- a/layout/forms/nsFieldSetFrame.cpp
+++ b/layout/forms/nsFieldSetFrame.cpp
@@ -61,16 +61,17 @@
 #endif
 #include "nsIServiceManager.h"
 #include "nsDisplayList.h"
 
 class nsLegendFrame;
 
 class nsFieldSetFrame : public nsHTMLContainerFrame {
 public:
+  NS_DECL_QUERYFRAME(nsFieldSetFrame)
 
   nsFieldSetFrame(nsStyleContext* aContext);
 
   NS_IMETHOD SetInitialChildList(nsIAtom*       aListName,
                                  nsFrameList&   aChildList);
 
   NS_HIDDEN_(nscoord)
     GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
@@ -82,17 +83,17 @@ public:
                              nsSize aMargin, nsSize aBorder, nsSize aPadding,
                              PRBool aShrinkWrap);
   virtual nscoord GetBaseline() const;
 
   NS_IMETHOD Reflow(nsPresContext*           aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
-                               
+
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   void PaintBorderBackground(nsIRenderingContext& aRenderingContext,
     nsPoint aPt, const nsRect& aDirtyRect);
 
   NS_IMETHOD AppendFrames(nsIAtom*       aListName,
@@ -101,17 +102,17 @@ public:
                           nsIFrame*      aPrevFrame,
                           nsFrameList&   aFrameList);
   NS_IMETHOD RemoveFrame(nsIAtom*       aListName,
                          nsIFrame*      aOldFrame);
 
   virtual nsIAtom* GetType() const;
   virtual PRBool IsContainingBlock() const;
 
-#ifdef ACCESSIBILITY  
+#ifdef ACCESSIBILITY
   NS_IMETHOD  GetAccessible(nsIAccessible** aAccessible);
 #endif
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const {
     return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult);
   }
 #endif
@@ -122,16 +123,19 @@ protected:
   void ReParentFrameList(const nsFrameList& aFrameList);
 
   nsIFrame* mLegendFrame;
   nsIFrame* mContentFrame;
   nsRect    mLegendRect;
   nscoord   mLegendSpace;
 };
 
+NS_QUERYFRAME_HEAD(nsFieldSetFrame)
+NS_QUERYFRAME_TAIL(nsHTMLContainerFrame)
+
 nsIFrame*
 NS_NewFieldSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsFieldSetFrame(aContext);
 }
 
 nsFieldSetFrame::nsFieldSetFrame(nsStyleContext* aContext)
   : nsHTMLContainerFrame(aContext)
diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -233,17 +233,17 @@ nsFileControlFrame::CreateAnonymousConte
   SyncAttr(kNameSpaceID_None, nsGkAtoms::disabled, SYNC_BOTH);
 
   return NS_OK;
 }
 
 NS_QUERYFRAME_HEAD(nsFileControlFrame)
   NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
+NS_QUERYFRAME_TAIL(nsBlockFrame)
 
 void 
 nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
 {
 }
 
 /**
  * This is called when our browse button is clicked
diff --git a/layout/forms/nsFileControlFrame.h b/layout/forms/nsFileControlFrame.h
--- a/layout/forms/nsFileControlFrame.h
+++ b/layout/forms/nsFileControlFrame.h
@@ -58,18 +58,18 @@ public:
   NS_IMETHOD Init(nsIContent* aContent,
                   nsIFrame*   aParent,
                   nsIFrame*   aPrevInFlow);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
-  NS_DECL_QUERYFRAME
-  
+  NS_DECL_QUERYFRAME(nsFileControlFrame)
+
   // 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);
   
   NS_IMETHOD Reflow(nsPresContext*          aCX,
diff --git a/layout/forms/nsFormControlFrame.cpp b/layout/forms/nsFormControlFrame.cpp
--- a/layout/forms/nsFormControlFrame.cpp
+++ b/layout/forms/nsFormControlFrame.cpp
@@ -59,17 +59,17 @@ nsFormControlFrame::Destroy()
 {
   // Unregister the access key registered in reflow
   nsFormControlFrame::RegUnRegAccessKey(static_cast(this), PR_FALSE);
   nsLeafFrame::Destroy();
 }
 
 NS_QUERYFRAME_HEAD(nsFormControlFrame)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
+NS_QUERYFRAME_TAIL(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);
diff --git a/layout/forms/nsFormControlFrame.h b/layout/forms/nsFormControlFrame.h
--- 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_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsFormControlFrame)
 
   /** 
     * Respond to a gui event
     * @see nsIFrame::HandleEvent
     */
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
                          nsGUIEvent* aEvent,
                          nsEventStatus* aEventStatus);
diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp
--- a/layout/forms/nsGfxButtonControlFrame.cpp
+++ b/layout/forms/nsGfxButtonControlFrame.cpp
@@ -182,17 +182,17 @@ NS_IMETHODIMP nsGfxButtonControlFrame::G
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
 NS_QUERYFRAME_HEAD(nsGfxButtonControlFrame)
   NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
-NS_QUERYFRAME_TAIL_INHERITING(nsHTMLButtonControlFrame)
+NS_QUERYFRAME_TAIL(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
diff --git a/layout/forms/nsGfxButtonControlFrame.h b/layout/forms/nsGfxButtonControlFrame.h
--- a/layout/forms/nsGfxButtonControlFrame.h
+++ b/layout/forms/nsGfxButtonControlFrame.h
@@ -70,17 +70,17 @@ public:
 #endif
 
   virtual nsIAtom* GetType() const;
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsGfxButtonControlFrame)
 
   // nsIAnonymousContentCreator
   virtual nsresult CreateAnonymousContent(nsTArray& aElements);
   virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
 
   // nsIFormControlFrame
   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const; 
 
diff --git a/layout/forms/nsGfxCheckboxControlFrame.cpp b/layout/forms/nsGfxCheckboxControlFrame.cpp
--- a/layout/forms/nsGfxCheckboxControlFrame.cpp
+++ b/layout/forms/nsGfxCheckboxControlFrame.cpp
@@ -115,17 +115,17 @@ nsGfxCheckboxControlFrame::nsGfxCheckbox
 
 nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
 {
 }
 
 
 NS_QUERYFRAME_HEAD(nsGfxCheckboxControlFrame)
   NS_QUERYFRAME_ENTRY(nsICheckboxControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
+NS_QUERYFRAME_TAIL(nsFormControlFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP
 nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService
     = do_GetService("@mozilla.org/accessibilityService;1");
 
diff --git a/layout/forms/nsGfxCheckboxControlFrame.h b/layout/forms/nsGfxCheckboxControlFrame.h
--- a/layout/forms/nsGfxCheckboxControlFrame.h
+++ b/layout/forms/nsGfxCheckboxControlFrame.h
@@ -63,17 +63,17 @@ public:
 
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
 
   //nsICheckboxControlFrame methods
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsGfxCheckboxControlFrame)
 
 protected:
 
   PRBool IsChecked();
   PRBool IsIndeterminate();
 };
 
 #endif
diff --git a/layout/forms/nsGfxRadioControlFrame.cpp b/layout/forms/nsGfxRadioControlFrame.cpp
--- a/layout/forms/nsGfxRadioControlFrame.cpp
+++ b/layout/forms/nsGfxRadioControlFrame.cpp
@@ -59,17 +59,17 @@ nsGfxRadioControlFrame::nsGfxRadioContro
 }
 
 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
 {
 }
 
 NS_QUERYFRAME_HEAD(nsGfxRadioControlFrame)
   NS_QUERYFRAME_ENTRY(nsIRadioControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
+NS_QUERYFRAME_TAIL(nsFormControlFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP
 nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService
     = do_GetService("@mozilla.org/accessibilityService;1");
 
diff --git a/layout/forms/nsGfxRadioControlFrame.h b/layout/forms/nsGfxRadioControlFrame.h
--- a/layout/forms/nsGfxRadioControlFrame.h
+++ b/layout/forms/nsGfxRadioControlFrame.h
@@ -50,17 +50,17 @@ class nsIAccessible;
 class nsGfxRadioControlFrame : public nsFormControlFrame,
                                public nsIRadioControlFrame
 
 {
 public:
   nsGfxRadioControlFrame(nsStyleContext* aContext);
   ~nsGfxRadioControlFrame();
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsGfxRadioControlFrame)
   
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -100,17 +100,17 @@ nsHTMLButtonControlFrame::Init(
   if (NS_SUCCEEDED(rv)) {
     mRenderer.SetFrame(this, PresContext());
   }
   return rv;
 }
 
 NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
+NS_QUERYFRAME_TAIL(nsHTMLContainerFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     nsIContent* content = GetContent();
diff --git a/layout/forms/nsHTMLButtonControlFrame.h b/layout/forms/nsHTMLButtonControlFrame.h
--- 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_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsHTMLButtonControlFrame)
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
 
   virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
diff --git a/layout/forms/nsICheckboxControlFrame.h b/layout/forms/nsICheckboxControlFrame.h
--- a/layout/forms/nsICheckboxControlFrame.h
+++ b/layout/forms/nsICheckboxControlFrame.h
@@ -37,25 +37,25 @@
 
 #ifndef nsICheckControlFrame_h___
 #define nsICheckControlFrame_h___
 
 #include "nsQueryFrame.h"
 class nsStyleContext;
 class nsPresContext;
 
-/** 
+/**
   * nsICheckControlFrame is the common interface radio buttons.
   * @see nsFromControlFrame and its base classes for more info
   */
-class nsICheckboxControlFrame
+class nsICheckboxControlFrame : public nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsICheckboxControlFrame)
-  
+  NS_DECL_QUERYFRAME_INTERFACE(nsICheckboxControlFrame)
+
   /**
    * Called by content when checkbox "checked" changes
    */
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
 #endif
 
diff --git a/layout/forms/nsIComboboxControlFrame.h b/layout/forms/nsIComboboxControlFrame.h
--- a/layout/forms/nsIComboboxControlFrame.h
+++ b/layout/forms/nsIComboboxControlFrame.h
@@ -49,17 +49,17 @@ class nsCSSFrameConstructor;
 /** 
   * 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 nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsIComboboxControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(nsIComboboxControlFrame)
 
   /**
    * Indicates whether the list is dropped down
    */
   virtual PRBool IsDroppedDown() = 0;
 
   /**
    * Shows or hides the drop down
diff --git a/layout/forms/nsIFormControlFrame.h b/layout/forms/nsIFormControlFrame.h
--- a/layout/forms/nsIFormControlFrame.h
+++ b/layout/forms/nsIFormControlFrame.h
@@ -47,17 +47,17 @@ struct nsSize;
 /** 
   * 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 nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsIFormControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(nsIFormControlFrame)
 
   /**
    * 
    * @param aOn
    * @param aRepaint
    */
   virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE) = 0;
 
diff --git a/layout/forms/nsIListControlFrame.h b/layout/forms/nsIListControlFrame.h
--- a/layout/forms/nsIListControlFrame.h
+++ b/layout/forms/nsIListControlFrame.h
@@ -45,17 +45,17 @@ class nsAString;
 class nsIContent;
 
 /** 
   * nsIListControlFrame is the interface for frame-based listboxes.
   */
 class nsIListControlFrame : public nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsIListControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(nsIListControlFrame)
 
   /**
    * Sets the ComboBoxFrame
    *
    */
   virtual void SetComboboxFrame(nsIFrame* aComboboxFrame) = 0;
 
   /**
diff --git a/layout/forms/nsIRadioControlFrame.h b/layout/forms/nsIRadioControlFrame.h
--- a/layout/forms/nsIRadioControlFrame.h
+++ b/layout/forms/nsIRadioControlFrame.h
@@ -36,24 +36,24 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIRadioControlFrame_h___
 #define nsIRadioControlFrame_h___
 
 #include "nsQueryFrame.h"
 class nsStyleContext;
 
-/** 
+/**
   * nsIRadioControlFrame is the common interface radio buttons.
   * @see nsFormControlFrame and its base classes for more info
   */
-class nsIRadioControlFrame
+class nsIRadioControlFrame : public nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsIRadioControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(nsIRadioControlFrame)
 
    /**
     * Called by content when the radio button's state changes
     */
    NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
 #endif
diff --git a/layout/forms/nsISelectControlFrame.h b/layout/forms/nsISelectControlFrame.h
--- a/layout/forms/nsISelectControlFrame.h
+++ b/layout/forms/nsISelectControlFrame.h
@@ -38,23 +38,23 @@
 
 #ifndef nsISelectControlFrame_h___
 #define nsISelectControlFrame_h___
 
 #include "nsQueryFrame.h"
 
 class nsIDOMHTMLOptionElement;
 
-/** 
+/**
   * nsISelectControlFrame is the interface for combo boxes and listboxes
   */
 class nsISelectControlFrame : public nsQueryFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsISelectControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(nsISelectControlFrame)
 
   /**
    * Adds an option to the list at index
    */
 
   NS_IMETHOD AddOption(PRInt32 index) = 0;
 
   /**
diff --git a/layout/forms/nsITextControlFrame.h b/layout/forms/nsITextControlFrame.h
--- a/layout/forms/nsITextControlFrame.h
+++ b/layout/forms/nsITextControlFrame.h
@@ -43,17 +43,17 @@
 class nsIEditor;
 class nsIDocShell;
 class nsISelectionController;
 class nsFrameSelection;
 
 class nsITextControlFrame : public nsIFormControlFrame
 {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsITextControlFrame)
+  NS_DECL_QUERYFRAME_INTERFACE(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]
diff --git a/layout/forms/nsImageControlFrame.cpp b/layout/forms/nsImageControlFrame.cpp
--- a/layout/forms/nsImageControlFrame.cpp
+++ b/layout/forms/nsImageControlFrame.cpp
@@ -76,17 +76,17 @@ public:
   nsImageControlFrame(nsStyleContext* aContext);
   ~nsImageControlFrame();
 
   virtual void Destroy();
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsImageControlFrame)
 
   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
 
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
                          nsGUIEvent* aEvent,
@@ -153,17 +153,17 @@ nsImageControlFrame::Init(nsIContent*   
   
   return  mContent->SetProperty(nsGkAtoms::imageClickedPoint,
                                  new nsIntPoint(0, 0),
                                  IntPointDtorFunc);
 }
 
 NS_QUERYFRAME_HEAD(nsImageControlFrame)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper)
+NS_QUERYFRAME_TAIL(nsImageControlFrameSuper)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     if (mContent->Tag() == nsGkAtoms::button) {
diff --git a/layout/forms/nsIsIndexFrame.cpp b/layout/forms/nsIsIndexFrame.cpp
--- a/layout/forms/nsIsIndexFrame.cpp
+++ b/layout/forms/nsIsIndexFrame.cpp
@@ -232,17 +232,17 @@ nsIsIndexFrame::CreateAnonymousContent(n
     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)
+NS_QUERYFRAME_TAIL(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(nsIDOMKeyListener))) {
diff --git a/layout/forms/nsIsIndexFrame.h b/layout/forms/nsIsIndexFrame.h
--- a/layout/forms/nsIsIndexFrame.h
+++ b/layout/forms/nsIsIndexFrame.h
@@ -76,17 +76,17 @@ 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
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsIsIndexFrame)
 
   // nsISupports
   NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
 
   // nsIFormControlFrame
   virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
   
   virtual PRBool IsLeaf() const;
diff --git a/layout/forms/nsLegendFrame.cpp b/layout/forms/nsLegendFrame.cpp
--- a/layout/forms/nsLegendFrame.cpp
+++ b/layout/forms/nsLegendFrame.cpp
@@ -69,18 +69,17 @@ nsLegendFrame::GetType() const
 void
 nsLegendFrame::Destroy()
 {
   nsFormControlFrame::RegUnRegAccessKey(static_cast(this), PR_FALSE);
   nsBlockFrame::Destroy();
 }
 
 NS_QUERYFRAME_HEAD(nsLegendFrame)
-  NS_QUERYFRAME_ENTRY(nsLegendFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
+NS_QUERYFRAME_TAIL(nsBlockFrame)
 
 NS_IMETHODIMP 
 nsLegendFrame::Reflow(nsPresContext*          aPresContext,
                      nsHTMLReflowMetrics&     aDesiredSize,
                      const nsHTMLReflowState& aReflowState,
                      nsReflowStatus&          aStatus)
 {
   DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
diff --git a/layout/forms/nsLegendFrame.h b/layout/forms/nsLegendFrame.h
--- a/layout/forms/nsLegendFrame.h
+++ b/layout/forms/nsLegendFrame.h
@@ -37,22 +37,20 @@
 
 #ifndef nsLegendFrame_h___
 #define nsLegendFrame_h___
 
 #include "nsBlockFrame.h"
 
 class nsLegendFrame : public nsBlockFrame {
 public:
-  NS_DECLARE_FRAME_ACCESSOR(nsLegendFrame)
+  NS_DECL_QUERYFRAME(nsLegendFrame)
 
   nsLegendFrame(nsStyleContext* aContext) : nsBlockFrame(aContext) {}
 
-  NS_DECL_QUERYFRAME
-
   NS_IMETHOD Reflow(nsPresContext*           aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus);
 
   virtual void Destroy();
 
   virtual nsIAtom* GetType() const;
diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -386,17 +386,17 @@ nsListControlFrame::InvalidateFocus()
     containerFrame->Invalidate(invalidateArea);
   }
 }
 
 NS_QUERYFRAME_HEAD(nsListControlFrame)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
   NS_QUERYFRAME_ENTRY(nsIListControlFrame)
   NS_QUERYFRAME_ENTRY(nsISelectControlFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsHTMLScrollFrame)
+NS_QUERYFRAME_TAIL(nsHTMLScrollFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     nsCOMPtr node = do_QueryInterface(mContent);
diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -72,17 +72,17 @@ class nsListEventListener;
 class nsListControlFrame : public nsHTMLScrollFrame,
                            public nsIFormControlFrame, 
                            public nsIListControlFrame,
                            public nsISelectControlFrame
 {
 public:
   friend nsIFrame* NS_NewListControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsListControlFrame)
 
     // nsIFrame
   NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
                          nsGUIEvent* aEvent,
                          nsEventStatus* aEventStatus);
   
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsFrameList&    aChildList);
diff --git a/layout/forms/nsSelectsAreaFrame.cpp b/layout/forms/nsSelectsAreaFrame.cpp
--- a/layout/forms/nsSelectsAreaFrame.cpp
+++ b/layout/forms/nsSelectsAreaFrame.cpp
@@ -51,16 +51,19 @@ NS_NewSelectsAreaFrame(nsIPresShell* aSh
     // We need NS_BLOCK_FLOAT_MGR to ensure that the options inside the select
     // aren't expanded by right floats outside the select.
     it->SetFlags(aFlags | NS_BLOCK_FLOAT_MGR);
   }
 
   return it;
 }
 
+NS_QUERYFRAME_HEAD(nsSelectsAreaFrame)
+NS_QUERYFRAME_TAIL(nsBlockFrame)
+
 //---------------------------------------------------------
 PRBool 
 nsSelectsAreaFrame::IsOptionElement(nsIContent* aContent)
 {
   PRBool result = PR_FALSE;
  
   nsCOMPtr optElem;
   if (NS_SUCCEEDED(aContent->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement),(void**) getter_AddRefs(optElem)))) {      
diff --git a/layout/forms/nsSelectsAreaFrame.h b/layout/forms/nsSelectsAreaFrame.h
--- a/layout/forms/nsSelectsAreaFrame.h
+++ b/layout/forms/nsSelectsAreaFrame.h
@@ -38,16 +38,18 @@
 #define nsSelectsAreaFrame_h___
 
 #include "nsBlockFrame.h"
 class nsIContent;
 
 class nsSelectsAreaFrame : public nsBlockFrame
 {
 public:
+  NS_DECL_QUERYFRAME(nsSelectsAreaFrame)
+
   friend nsIFrame* NS_NewSelectsAreaFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRUint32 aFlags);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
 
   nsresult BuildDisplayListInternal(nsDisplayListBuilder*   aBuilder,
                                     const nsRect&           aDirtyRect,
diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -950,19 +950,18 @@ NS_NewTextControlFrame(nsIPresShell* aPr
 {
   return new (aPresShell) nsTextControlFrame(aPresShell, aContext);
 }
 
 NS_QUERYFRAME_HEAD(nsTextControlFrame)
   NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
   NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
   NS_QUERYFRAME_ENTRY(nsITextControlFrame)
-  if (nsIScrollableViewProvider::kFrameIID == id && IsScrollable())
-    return static_cast(this);
-NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
+  NS_QUERYFRAME_ENTRY_CONDITIONAL(nsIScrollableViewProvider, IsScrollable())
+NS_QUERYFRAME_TAIL(nsBoxFrame)
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTextControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLTextFieldAccessible(static_cast(this), aAccessible);
diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h
--- a/layout/forms/nsTextControlFrame.h
+++ b/layout/forms/nsTextControlFrame.h
@@ -161,17 +161,17 @@ public:
 
   /** handler for attribute changes to mContent */
   NS_IMETHOD AttributeChanged(PRInt32         aNameSpaceID,
                               nsIAtom*        aAttribute,
                               PRInt32         aModType);
 
   NS_IMETHOD GetText(nsString* aText);
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsTextControlFrame)
 
 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;
   /**
diff --git a/layout/generic/nsBRFrame.cpp b/layout/generic/nsBRFrame.cpp
--- a/layout/generic/nsBRFrame.cpp
+++ b/layout/generic/nsBRFrame.cpp
@@ -58,16 +58,18 @@
 #include "nsIContent.h"
 #include "nsFrameSelection.h"
 //END INCLUDES FOR SELECTION
 
 class BRFrame : public nsFrame {
 public:
   friend nsIFrame* NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
+  NS_DECL_QUERYFRAME(BRFrame)
+
   virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint);
 
   virtual PRBool PeekOffsetNoAmount(PRBool aForward, PRInt32* aOffset);
   virtual PRBool PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset);
   virtual PRBool PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsKeyboardSelect,
                                 PRInt32* aOffset, PeekWordState* aState);
 
   NS_IMETHOD Reflow(nsPresContext* aPresContext,
@@ -92,16 +94,19 @@ public:
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
 
 protected:
   BRFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
   virtual ~BRFrame();
 };
 
+NS_QUERYFRAME_HEAD(BRFrame)
+NS_QUERYFRAME_TAIL(nsFrame)
+
 nsIFrame*
 NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) BRFrame(aContext);
 }
 
 BRFrame::~BRFrame()
 {
diff --git a/layout/generic/nsBidiFrames.cpp b/layout/generic/nsBidiFrames.cpp
--- a/layout/generic/nsBidiFrames.cpp
+++ b/layout/generic/nsBidiFrames.cpp
@@ -66,9 +66,13 @@ nsDirectionalFrame::GetFrameName(nsAStri
 #endif
 
 nsIFrame*
 NS_NewDirectionalFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUnichar aChar)
 {
   return new (aPresShell) nsDirectionalFrame(aContext, aChar);
 }
 
+NS_QUERYFRAME_HEAD(nsDirectionalFrame)
+NS_QUERYFRAME_TAIL(nsFrame)
+
+
 #endif /* IBMBIDI */
diff --git a/layout/generic/nsBidiFrames.h b/layout/generic/nsBidiFrames.h
--- a/layout/generic/nsBidiFrames.h
+++ b/layout/generic/nsBidiFrames.h
@@ -47,16 +47,18 @@
 class nsDirectionalFrame : public nsFrame
 {
 protected:
   virtual ~nsDirectionalFrame();
 
 public:
   nsDirectionalFrame(nsStyleContext* aContext, PRUnichar aChar);
 
+  NS_DECL_QUERYFRAME(nsDirectionalFrame)
+
   /**
    * Get the "type" of the frame
    *
    * @see nsGkAtoms::directionalFrame
    */
   virtual nsIAtom* GetType() const;
 
   PRUnichar GetChar() const { return mChar; }
diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -324,18 +324,17 @@ nsBlockFrame::GetLineIterator()
   if (NS_FAILED(rv)) {
     delete it;
     return nsnull;
   }
   return it;
 }
 
 NS_QUERYFRAME_HEAD(nsBlockFrame)
-  NS_QUERYFRAME_ENTRY(nsBlockFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrameSuper)
+NS_QUERYFRAME_TAIL(nsBlockFrameSuper)
 
 nsSplittableType
 nsBlockFrame::GetSplittableType() const
 {
   return NS_FRAME_SPLITTABLE_NON_RECTANGULAR;
 }
 
 #ifdef DEBUG
diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h
--- a/layout/generic/nsBlockFrame.h
+++ b/layout/generic/nsBlockFrame.h
@@ -133,22 +133,20 @@ class nsIntervalSet;
 #define nsBlockFrameSuper nsHTMLContainerFrame
 
 /*
  * 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(); }
@@ -156,17 +154,17 @@ public:
   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);
 
   // nsQueryFrame
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsBlockFrame)
 
   // nsIFrame
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsFrameList&    aChildList);
   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -79,16 +79,18 @@ public:
   NS_IMETHOD FrameChanged(imgIContainer *aContainer, nsIntRect *dirtyRect);
 
   void SetFrame(nsBulletFrame *frame) { mFrame = frame; }
 
 private:
   nsBulletFrame *mFrame;
 };
 
+NS_QUERYFRAME_HEAD(nsBulletFrame)
+NS_QUERYFRAME_TAIL(nsFrame)
 
 nsBulletFrame::~nsBulletFrame()
 {
 }
 
 void
 nsBulletFrame::Destroy()
 {
diff --git a/layout/generic/nsBulletFrame.h b/layout/generic/nsBulletFrame.h
--- a/layout/generic/nsBulletFrame.h
+++ b/layout/generic/nsBulletFrame.h
@@ -50,16 +50,18 @@
  * A simple class that manages the layout and rendering of html bullets.
  * This class also supports the CSS list-style properties.
  */
 class nsBulletFrame : public nsFrame {
 public:
   nsBulletFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
   virtual ~nsBulletFrame();
 
+  NS_DECL_QUERYFRAME(nsBulletFrame)
+
   // nsIFrame
   virtual void Destroy();
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
                               const nsDisplayListSet& aLists);
   virtual nsIAtom* GetType() const;
   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
 #ifdef NS_DEBUG
diff --git a/layout/generic/nsColumnSetFrame.cpp b/layout/generic/nsColumnSetFrame.cpp
--- a/layout/generic/nsColumnSetFrame.cpp
+++ b/layout/generic/nsColumnSetFrame.cpp
@@ -49,26 +49,28 @@
 #include "nsStyleConsts.h"
 #include "nsCOMPtr.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
 #include "nsCSSRendering.h"
 
 class nsColumnSetFrame : public nsHTMLContainerFrame {
 public:
+  NS_DECL_QUERYFRAME(nsColumnSetFrame)
+
   nsColumnSetFrame(nsStyleContext* aContext);
 
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsFrameList&    aChildList);
 
   NS_IMETHOD Reflow(nsPresContext* aPresContext,
                     nsHTMLReflowMetrics& aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus& aStatus);
-                               
+
   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
                            nsFrameList&    aFrameList);
   NS_IMETHOD  InsertFrames(nsIAtom*        aListName,
                            nsIFrame*       aPrevFrame,
                            nsFrameList&    aFrameList);
   NS_IMETHOD  RemoveFrame(nsIAtom*        aListName,
                           nsIFrame*       aOldFrame);
 
@@ -167,16 +169,19 @@ protected:
                         const nsHTMLReflowState& aReflowState,
                         nsReflowStatus& aStatus,
                         const ReflowConfig& aConfig,
                         PRBool aLastColumnUnbounded,
                         nsCollapsingMargin* aCarriedOutBottomMargin,
                         ColumnBalanceData& aColData);
 };
 
+NS_QUERYFRAME_HEAD(nsColumnSetFrame)
+NS_QUERYFRAME_TAIL(nsHTMLContainerFrame)
+
 /**
  * Tracking issues:
  *
  * XXX cursor movement around the top and bottom of colums seems to make the editor
  * lose the caret.
  *
  * XXX should we support CSS columns applied to table elements?
  */
diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -79,16 +79,19 @@
 #else
 #undef NOISY
 #endif
 
 nsContainerFrame::~nsContainerFrame()
 {
 }
 
+NS_QUERYFRAME_HEAD(nsContainerFrame)
+NS_QUERYFRAME_TAIL(nsSplittableFrame)
+
 NS_IMETHODIMP
 nsContainerFrame::Init(nsIContent* aContent,
                        nsIFrame*   aParent,
                        nsIFrame*   aPrevInFlow)
 {
   nsresult rv = nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
   if (aPrevInFlow) {
     // Make sure we copy bits from our prev-in-flow that will affect
diff --git a/layout/generic/nsContainerFrame.h b/layout/generic/nsContainerFrame.h
--- a/layout/generic/nsContainerFrame.h
+++ b/layout/generic/nsContainerFrame.h
@@ -68,16 +68,18 @@
 class nsOverflowContinuationTracker;
 
 /**
  * Implementation of a container frame.
  */
 class nsContainerFrame : public nsSplittableFrame
 {
 public:
+  NS_DECL_QUERYFRAME(nsContainerFrame)
+
   // nsIFrame overrides
   NS_IMETHOD Init(nsIContent* aContent,
                   nsIFrame*   aParent,
                   nsIFrame*   aPrevInFlow);
   NS_IMETHOD SetInitialChildList(nsIAtom*     aListName,
                                  nsFrameList& aChildList);
   NS_IMETHOD AppendFrames(nsIAtom*  aListName,
                           nsFrameList& aFrameList);
diff --git a/layout/generic/nsFirstLetterFrame.cpp b/layout/generic/nsFirstLetterFrame.cpp
--- a/layout/generic/nsFirstLetterFrame.cpp
+++ b/layout/generic/nsFirstLetterFrame.cpp
@@ -49,16 +49,19 @@
 #include "nsFrameManager.h"
 
 nsIFrame*
 NS_NewFirstLetterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsFirstLetterFrame(aContext);
 }
 
+NS_QUERYFRAME_HEAD(nsFirstLetterFrame)
+NS_QUERYFRAME_TAIL(nsHTMLContainerFrame)
+
 #ifdef NS_DEBUG
 NS_IMETHODIMP
 nsFirstLetterFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("Letter"), aResult);
 }
 #endif
 
diff --git a/layout/generic/nsFirstLetterFrame.h b/layout/generic/nsFirstLetterFrame.h
--- a/layout/generic/nsFirstLetterFrame.h
+++ b/layout/generic/nsFirstLetterFrame.h
@@ -41,16 +41,18 @@
 /* rendering object for CSS :first-letter pseudo-element */
 
 #include "nsHTMLContainerFrame.h"
 
 #define nsFirstLetterFrameSuper nsHTMLContainerFrame
 
 class nsFirstLetterFrame : public nsFirstLetterFrameSuper {
 public:
+  NS_DECL_QUERYFRAME(nsFirstLetterFrame)
+
   nsFirstLetterFrame(nsStyleContext* aContext) : nsHTMLContainerFrame(aContext) {}
 
   NS_IMETHOD Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow);
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsFrameList&    aChildList);
 #ifdef NS_DEBUG
diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -282,24 +282,16 @@ nsWeakFrame::Init(nsIFrame* aFrame)
 }
 
 nsIFrame*
 NS_NewEmptyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsFrame(aContext);
 }
 
-// Overloaded new operator. Relies on an arena (which comes from the
-// presShell) to perform the allocation.
-void*
-nsFrame::operator new(size_t sz, nsIPresShell* aPresShell) CPP_THROW_NEW
-{
-  return aPresShell->AllocateFrame(sz, 0 /* dummy */);
-}
-
 // Overridden to prevent the global delete from being called, since the memory
 // came out of an nsIArena instead of the global delete operator's heap.
 void
 nsFrame::operator delete(void* aPtr, size_t sz)
 {
   // Don't let the memory be freed, since it will be recycled
   // instead. Don't call the global operator delete.
 
@@ -326,17 +318,17 @@ nsFrame::~nsFrame()
 
   NS_IF_RELEASE(mContent);
   if (mStyleContext)
     mStyleContext->Release();
 }
 
 NS_QUERYFRAME_HEAD(nsFrame)
   NS_QUERYFRAME_ENTRY(nsIFrame)
-NS_QUERYFRAME_TAIL
+NS_QUERYFRAME_TAIL_INHERITANCE_ROOT
 
 /////////////////////////////////////////////////////////////////////////////
 // nsIFrame
 
 NS_IMETHODIMP
 nsFrame::Init(nsIContent*      aContent,
               nsIFrame*        aParent,
               nsIFrame*        aPrevInFlow)
diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp
--- a/layout/generic/nsFrameFrame.cpp
+++ b/layout/generic/nsFrameFrame.cpp
@@ -114,17 +114,17 @@ class nsSubDocumentFrame : public nsLeaf
 {
 public:
   nsSubDocumentFrame(nsStyleContext* aContext);
 
 #ifdef DEBUG
   NS_IMETHOD GetFrameName(nsAString& aResult) const;
 #endif
 
-  NS_DECL_QUERYFRAME
+  NS_DECL_QUERYFRAME(nsSubDocumentFrame)
 
   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));
@@ -235,17 +235,17 @@ NS_IMETHODIMP nsSubDocumentFrame::GetAcc
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
 NS_QUERYFRAME_HEAD(nsSubDocumentFrame)
   NS_QUERYFRAME_ENTRY(nsIFrameFrame)
-NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
+NS_QUERYFRAME_TAIL(nsLeafFrame)
 
 NS_IMETHODIMP
 nsSubDocumentFrame::Init(nsIContent*     aContent,
                          nsIFrame*       aParent,
                          nsIFrame*       aPrevInFlow)
 {
   // determine if we are a  or