Bug 461921 - remove nsPIAccessible, r=marcoz, davidb
authorAlexander Surkov <surkov.alexander@gmail.com>
Thu, 18 Jun 2009 15:37:38 +0800
changeset 29320 30b481fd82f5dcb7e9bb0e84c5565a966f7821e4
parent 29319 ca8cf5405bd4b2a5845746e0792666add194839c
child 29321 6f97009ad54774ef9e6d4dacec45f26f420131b2
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcoz, davidb
bugs461921
milestone1.9.2a1pre
Bug 461921 - remove nsPIAccessible, r=marcoz, davidb
accessible/public/Makefile.in
accessible/public/nsPIAccessible.idl
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/base/nsAccUtils.cpp
accessible/src/base/nsAccUtils.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsAccessible.h
accessible/src/base/nsApplicationAccessible.cpp
accessible/src/base/nsBaseWidgetAccessible.cpp
accessible/src/base/nsBaseWidgetAccessible.h
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsDocAccessible.h
accessible/src/base/nsOuterDocAccessible.cpp
accessible/src/base/nsRootAccessible.cpp
accessible/src/base/nsTextAccessible.cpp
accessible/src/base/nsTextAccessible.h
accessible/src/html/nsHTMLImageAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/html/nsHTMLTextAccessible.cpp
accessible/src/html/nsHTMLTextAccessible.h
accessible/src/html/nsHyperTextAccessible.cpp
accessible/src/mac/nsAccessibleWrap.h
accessible/src/mac/nsAccessibleWrap.mm
accessible/src/msaa/nsAccessibleWrap.cpp
accessible/src/msaa/nsAccessibleWrap.h
accessible/src/msaa/nsHyperTextAccessibleWrap.cpp
accessible/src/msaa/nsHyperTextAccessibleWrap.h
accessible/src/xforms/nsXFormsAccessible.cpp
accessible/src/xforms/nsXFormsAccessible.h
accessible/src/xforms/nsXFormsFormControlsAccessible.cpp
accessible/src/xforms/nsXFormsFormControlsAccessible.h
accessible/src/xul/nsXULFormControlAccessible.cpp
accessible/src/xul/nsXULFormControlAccessible.h
accessible/src/xul/nsXULMenuAccessible.cpp
accessible/src/xul/nsXULMenuAccessible.h
accessible/src/xul/nsXULSelectAccessible.cpp
accessible/src/xul/nsXULSelectAccessible.h
accessible/src/xul/nsXULSliderAccessible.cpp
accessible/src/xul/nsXULSliderAccessible.h
--- a/accessible/public/Makefile.in
+++ b/accessible/public/Makefile.in
@@ -53,17 +53,16 @@ GRE_MODULE	= 1
 XPIDLSRCS = \
       nsIAccessibleTypes.idl \
       nsIAccessibilityService.idl \
       nsIAccessibleRetrieval.idl \
       nsIAccessible.idl \
       nsIAccessibleRelation.idl \
       nsIAccessibleRole.idl \
       nsIAccessibleStates.idl \
-      nsPIAccessible.idl \
       nsIAccessibleDocument.idl \
       nsPIAccessibleDocument.idl \
       nsIAccessibleProvider.idl \
       nsIAccessibleSelectable.idl \
       nsIAccessNode.idl \
       nsIAccessibleEvent.idl \
       nsIAccessibleEditableText.idl \
       nsIAccessibleHyperLink.idl \
deleted file mode 100644
--- a/accessible/public/nsPIAccessible.idl
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-/* ***** 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Original Author: Aaron Leventhal (aaronl@netscape.com)
- * 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 ***** */
-
-#include "nsISupports.idl"
-
-interface nsIAccessible;
-interface nsIAccessibleEvent;
-%{C++
-   struct nsRoleMapEntry;
-%}
-[ptr] native nsRoleMapEntryPtr(nsRoleMapEntry);
-
-[uuid(ed61e5cd-283a-42df-9599-765e0e27f4d9)]
-interface nsPIAccessible : nsISupports
-{
-  /**
-   * Set accessible parent.
-   */
-  void setParent(in nsIAccessible aAccParent);
-
-  /**
-   * Set first accessible child.
-   */
-  void setFirstChild(in nsIAccessible aAccFirstChild);
-
-  /**
-   * Set next sibling accessible.
-   */
-  void setNextSibling(in nsIAccessible aAccNextSibling);
-
-  /**
-   * Return parent accessible only if cached.
-   */
-  void getCachedParent(out nsIAccessible aAccParent);
-
-  /**
-   * Return first child accessible only if cached.
-   */
-  void getCachedFirstChild(out nsIAccessible aAccFirstChild);
-
-  /**
-   * Set the child count to -1 (unknown) and null out cached child pointers
-   */
-  void invalidateChildren();
-
-  /**
-   * Fire accessible event.
-   */
-  void fireAccessibleEvent(in nsIAccessibleEvent aAccEvent);
-
-  /**
-   * Return true if there are accessible children in anonymous content
-   */
-  readonly attribute boolean allowsAnonChildAccessibles;
-
-  /**
-   * Assert if child not in parent's cache.
-   */
-  void testChildCache(in nsIAccessible aCachedChild);
-
-  /**
-   * Returns text of accessible if accessible has text role otherwise empty
-   * string.
-   */
-  void appendTextTo(out AString aString, in unsigned long aStartOffset,
-                    in unsigned long aLength);
-                    
-  /**
-   * Set the ARIA role map entry for a new accessible.
-   * For a newly created accessible, specify which role map entry should be used.
-   * @param aRoleMapEntry The ARIA nsRoleMapEntry* for the accessible, or 
-   *                      nsnull if none.
-   */
-   void setRoleMapEntry(in nsRoleMapEntryPtr aRoleMapEntry);
-
-  /**
-   * Maps ARIA state attributes to state of accessible. Note the given state
-   * argument should hold states for accessible before you pass it into this
-   * method.
-   * @param  in/out where to fill the states into.
-   */
-   void getARIAState(out unsigned long aState);
-};
-
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -1101,17 +1101,17 @@ nsAccessibleWrap *GetAccessibleWrap(AtkO
         static_cast<nsAccessibleWrap*>(appAccWrap.get());
 
     if (tmpAppAccWrap != tmpAccWrap && !tmpAccWrap->IsValidObject())
         return nsnull;
 
     return tmpAccWrap;
 }
 
-NS_IMETHODIMP
+nsresult
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
     nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return FirePlatformEvent(aEvent);
 }
 
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -36,17 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsCoreUtils.h"
 #include "nsAccUtils.h"
 
 #include "nsIAccessibleStates.h"
 #include "nsIAccessibleTypes.h"
-#include "nsPIAccessible.h"
 
 #include "nsAccessibleEventData.h"
 #include "nsHyperTextAccessible.h"
 #include "nsHTMLTableAccessible.h"
 #include "nsAccessibilityAtoms.h"
 #include "nsAccessibleTreeWalker.h"
 #include "nsAccessible.h"
 #include "nsARIAMap.h"
@@ -340,24 +339,23 @@ nsAccUtils::HasDefinedARIAToken(nsIConte
 }
 
 nsresult
 nsAccUtils::FireAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
                          PRBool aIsAsynch)
 {
   NS_ENSURE_ARG(aAccessible);
 
-  nsCOMPtr<nsPIAccessible> pAccessible(do_QueryInterface(aAccessible));
-  NS_ASSERTION(pAccessible, "Accessible doesn't implement nsPIAccessible");
+  nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(aAccessible));
 
   nsCOMPtr<nsIAccessibleEvent> event =
     new nsAccEvent(aEventType, aAccessible, aIsAsynch);
   NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
 
-  return pAccessible->FireAccessibleEvent(event);
+  return acc->FireAccessibleEvent(event);
 }
 
 PRBool
 nsAccUtils::HasAccessibleChildren(nsIDOMNode *aNode)
 {
   if (!aNode)
     return PR_FALSE;
 
@@ -719,21 +717,31 @@ nsAccUtils::GetLiveAttrValue(PRUint32 aR
       aValue = NS_LITERAL_STRING("polite");
       break;
   }
 }
 
 already_AddRefed<nsAccessible>
 nsAccUtils::QueryAccessible(nsIAccessible *aAccessible)
 {
-  nsAccessible* accessible = nsnull;
+  nsAccessible* acc = nsnull;
   if (aAccessible)
-    CallQueryInterface(aAccessible, &accessible);
-  
-  return accessible;
+    CallQueryInterface(aAccessible, &acc);
+
+  return acc;
+}
+
+already_AddRefed<nsAccessible>
+nsAccUtils::QueryAccessible(nsIAccessNode *aAccessNode)
+{
+  nsAccessible* acc = nsnull;
+  if (aAccessNode)
+    CallQueryInterface(aAccessNode, &acc);
+
+  return acc;
 }
 
 already_AddRefed<nsHTMLTableAccessible>
 nsAccUtils::QueryAccessibleTable(nsIAccessibleTable *aAccessibleTable)
 {
   nsHTMLTableAccessible* accessible = nsnull;
   if (aAccessibleTable)
     CallQueryInterface(aAccessibleTable, &accessible);
@@ -797,20 +805,20 @@ nsAccUtils::TextLength(nsIAccessible *aA
       return NS_SUCCEEDED(rv) ? static_cast<PRInt32>(length) : -1;
     }
   }
   
   // For list bullets (or anything other accessible which would compute its own
   // text. They don't have their own frame.
   // XXX In the future, list bullets may have frame and anon content, so 
   // we should be able to remove this at that point
-  nsCOMPtr<nsPIAccessible> pAcc(do_QueryInterface(aAccessible));
-  
+  nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(aAccessible));
+
   nsAutoString text;
-  pAcc->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
+  acc->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
   return text.Length();
 }
 
 PRBool
 nsAccUtils::MustPrune(nsIAccessible *aAccessible)
 { 
   PRUint32 role = nsAccUtils::Role(aAccessible);
 
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -325,16 +325,22 @@ public:
 
   /**
    * Query nsAccessible from the given nsIAccessible.
    */
   static already_AddRefed<nsAccessible>
     QueryAccessible(nsIAccessible *aAccessible);
 
   /**
+   * Query nsAccessible from the given nsIAccessNode.
+   */
+  static already_AddRefed<nsAccessible>
+    QueryAccessible(nsIAccessNode *aAccessNode);
+
+  /**
    * Query nsHTMLTableAccessible from the given nsIAccessibleTable.
    */
   static already_AddRefed<nsHTMLTableAccessible>
     QueryAccessibleTable(nsIAccessibleTable *aAccessibleTable);
   
 #ifdef DEBUG_A11Y
   /**
    * Detect whether the given accessible object implements nsIAccessibleText,
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -453,22 +453,21 @@ nsAccessibilityService::CreateRootAccess
     *aRootAcc = new nsDocAccessibleWrap(rootNode, weakShell);
   }
   else {
     *aRootAcc = new nsRootAccessibleWrap(rootNode, weakShell);
   }
   if (!*aRootAcc)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  nsRefPtr<nsAccessNode> rootAcc = nsAccUtils::QueryAccessNode(*aRootAcc);
+  nsRefPtr<nsAccessible> rootAcc = nsAccUtils::QueryAccessible(*aRootAcc);
   rootAcc->Init();
 
   nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(rootNode);
-  nsCOMPtr<nsPIAccessible> privateAccessible(do_QueryInterface(*aRootAcc));
-  privateAccessible->SetRoleMapEntry(roleMapEntry);
+  rootAcc->SetRoleMapEntry(roleMapEntry);
 
   NS_ADDREF(*aRootAcc);
 
   return NS_OK;
 }
 
  /**
    * HTML widget creation
@@ -1261,23 +1260,21 @@ nsresult nsAccessibilityService::InitAcc
                                                 nsIAccessible **aAccessibleOut,
                                                 nsRoleMapEntry *aRoleMapEntry)
 {
   if (!aAccessibleIn) {
     return NS_ERROR_FAILURE; // No accessible to init
   }
   NS_ASSERTION(aAccessibleOut && !*aAccessibleOut, "Out param should already be cleared out");
 
-  nsRefPtr<nsAccessNode> acc = nsAccUtils::QueryAccessNode(aAccessibleIn);
+  nsRefPtr<nsAccessible> acc = nsAccUtils::QueryAccessible(aAccessibleIn);
   nsresult rv = acc->Init(); // Add to cache, etc.
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsPIAccessible> privateAccessible =
-    do_QueryInterface(aAccessibleIn);
-  privateAccessible->SetRoleMapEntry(aRoleMapEntry);
+  acc->SetRoleMapEntry(aRoleMapEntry);
   NS_ADDREF(*aAccessibleOut = aAccessibleIn);
 
   return NS_OK;
 }
 
 static PRBool HasRelatedContent(nsIContent *aContent)
 {
   nsAutoString id;
@@ -1719,20 +1716,19 @@ nsAccessibilityService::GetRelevantConte
       nsCOMPtr<nsIDOMNode> bindingNode(do_QueryInterface(bindingParent));
       if (bindingNode) {
         // Try to get an accessible by type since XBL widget can be accessible
         // only if it implements nsIAccessibleProvider interface.
         nsCOMPtr<nsIAccessible> accessible;
         rv = GetAccessibleByType(bindingNode, getter_AddRefs(accessible));
 
         if (NS_SUCCEEDED(rv)) {
-          nsCOMPtr<nsPIAccessible> paccessible(do_QueryInterface(accessible));
-          if (paccessible) {
-            PRBool allowsAnonChildren = PR_FALSE;
-            paccessible->GetAllowsAnonChildAccessibles(&allowsAnonChildren);
+          nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessible));
+          if (acc) {
+            PRBool allowsAnonChildren = acc->GetAllowsAnonChildAccessibles();
             if (!allowsAnonChildren) {
               NS_ADDREF(*aRelevantNode = bindingNode);
               return NS_OK;
             }
           }
         }
       }
     }
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -175,22 +175,16 @@ nsresult nsAccessible::QueryInterface(RE
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessible))) {
     *aInstancePtr = static_cast<nsIAccessible*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
-  if(aIID.Equals(NS_GET_IID(nsPIAccessible))) {
-    *aInstancePtr = static_cast<nsPIAccessible*>(this);
-    NS_ADDREF_THIS();
-    return NS_OK;
-  }
-
   if (aIID.Equals(NS_GET_IID(nsAccessible))) {
     *aInstancePtr = static_cast<nsAccessible*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
     nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
@@ -262,20 +256,20 @@ nsAccessible::nsAccessible(nsIDOMNode* a
 
 //-----------------------------------------------------
 // destruction
 //-----------------------------------------------------
 nsAccessible::~nsAccessible()
 {
 }
 
-NS_IMETHODIMP nsAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
+void
+nsAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
 {
   mRoleMapEntry = aRoleMapEntry;
-  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessible::GetName(nsAString& aName)
 {
   aName.Truncate();
 
   if (IsDefunct())
@@ -484,118 +478,119 @@ nsAccessible::GetKeyboardShortcut(nsAStr
     propertyKey.AssignLiteral("VK_CONTROL");
     nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
   }
 
   aAccessKey = accesskey;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::SetParent(nsIAccessible *aParent)
+void
+nsAccessible::SetParent(nsIAccessible *aParent)
 {
   if (mParent != aParent) {
     // Adopt a child -- we allow this now. the new parent
     // may be a dom node which wasn't previously accessible but now is.
     // The old parent's children now need to be invalidated, since 
     // it no longer owns the child, the new parent does
-    nsCOMPtr<nsPIAccessible> privOldParent = do_QueryInterface(mParent);
-    if (privOldParent) {
-      privOldParent->InvalidateChildren();
-    }
+    nsRefPtr<nsAccessible> oldParent = nsAccUtils::QueryAccessible(mParent);
+    if (oldParent)
+      oldParent->InvalidateChildren();
   }
 
   mParent = aParent;
-  return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::SetFirstChild(nsIAccessible *aFirstChild)
+void
+nsAccessible::SetFirstChild(nsIAccessible *aFirstChild)
 {
   mFirstChild = aFirstChild;
-
-  return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::SetNextSibling(nsIAccessible *aNextSibling)
+void
+nsAccessible::SetNextSibling(nsIAccessible *aNextSibling)
 {
   mNextSibling = aNextSibling;
-  return NS_OK;
 }
 
 nsresult
 nsAccessible::Shutdown()
 {
   mNextSibling = nsnull;
 
   // Invalidate the child count and pointers to other accessibles, also make
   // sure none of its children point to this parent
   InvalidateChildren();
   if (mParent) {
-    nsCOMPtr<nsPIAccessible> privateParent(do_QueryInterface(mParent));
-    privateParent->InvalidateChildren();
+    nsRefPtr<nsAccessible> parent(nsAccUtils::QueryAccessible(mParent));
+    parent->InvalidateChildren();
     mParent = nsnull;
   }
 
   return nsAccessNodeWrap::Shutdown();
 }
 
-NS_IMETHODIMP nsAccessible::InvalidateChildren()
+void
+nsAccessible::InvalidateChildren()
 {
   // Document has transformed, reset our invalid children and child count
 
   // Reset the sibling pointers, they will be set up again the next time
   // CacheChildren() is called.
   // Note: we don't want to start creating accessibles at this point,
   // so don't use GetNextSibling() here. (bug 387252)
-  nsAccessible* child = static_cast<nsAccessible*>(mFirstChild.get());
+  nsRefPtr<nsAccessible> child = nsAccUtils::QueryAccessible(mFirstChild);
   while (child) {
     child->mParent = nsnull;
 
     nsCOMPtr<nsIAccessible> next = child->mNextSibling;
     child->mNextSibling = nsnull;
-    child = static_cast<nsAccessible*>(next.get());
+    child = nsAccUtils::QueryAccessible(next);
   }
 
   mAccChildCount = eChildCountUninitialized;
   mFirstChild = nsnull;
-  return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::GetParent(nsIAccessible **  aParent)
+NS_IMETHODIMP
+nsAccessible::GetParent(nsIAccessible **aParent)
 {
-  nsresult rv = GetCachedParent(aParent);
-  if (NS_FAILED(rv) || *aParent) {
-    return rv;
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIAccessible> cachedParent = GetCachedParent();
+  if (cachedParent) {
+    cachedParent.swap(*aParent);
+    return NS_OK;
   }
 
   nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
   NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
 
   return docAccessible->GetAccessibleInParentChain(mDOMNode, PR_TRUE, aParent);
 }
 
-NS_IMETHODIMP nsAccessible::GetCachedParent(nsIAccessible **  aParent)
+already_AddRefed<nsIAccessible>
+nsAccessible::GetCachedParent()
 {
-  *aParent = nsnull;
-  if (!mWeakShell) {
-    // This node has been shut down
-    return NS_ERROR_FAILURE;
-  }
-  NS_IF_ADDREF(*aParent = mParent);
-  return NS_OK;
+  if (IsDefunct())
+    return nsnull;
+
+  nsCOMPtr<nsIAccessible> cachedParent = mParent;
+  return cachedParent.forget();
 }
 
-NS_IMETHODIMP nsAccessible::GetCachedFirstChild(nsIAccessible **  aFirstChild)
+already_AddRefed<nsIAccessible>
+nsAccessible::GetCachedFirstChild()
 {
-  *aFirstChild = nsnull;
-  if (!mWeakShell) {
-    // This node has been shut down
-    return NS_ERROR_FAILURE;
-  }
-  NS_IF_ADDREF(*aFirstChild = mFirstChild);
-  return NS_OK;
+  if (IsDefunct())
+    return nsnull;
+
+  nsCOMPtr<nsIAccessible> cachedFirstChild = mFirstChild;
+  return cachedFirstChild.forget();
 }
 
   /* readonly attribute nsIAccessible nextSibling; */
 NS_IMETHODIMP nsAccessible::GetNextSibling(nsIAccessible * *aNextSibling) 
 { 
   *aNextSibling = nsnull; 
   if (!mWeakShell) {
     // This node has been shut down
@@ -655,20 +650,19 @@ NS_IMETHODIMP nsAccessible::GetFirstChil
 {  
   if (gIsCacheDisabled) {
     InvalidateChildren();
   }
   PRInt32 numChildren;
   GetChildCount(&numChildren);  // Make sure we cache all of the children
 
 #ifdef DEBUG
-  nsCOMPtr<nsPIAccessible> firstChild(do_QueryInterface(mFirstChild));
+  nsRefPtr<nsAccessible> firstChild(nsAccUtils::QueryAccessible(mFirstChild));
   if (firstChild) {
-    nsCOMPtr<nsIAccessible> realParent;
-    firstChild->GetCachedParent(getter_AddRefs(realParent));
+    nsCOMPtr<nsIAccessible> realParent = firstChild->GetCachedParent();
     NS_ASSERTION(!realParent || realParent == this,
                  "Two accessibles have the same first child accessible.");
   }
 #endif
 
   NS_IF_ADDREF(*aFirstChild = mFirstChild);
 
   return NS_OK;  
@@ -747,44 +741,43 @@ void nsAccessible::CacheChildren()
   if (!mWeakShell) {
     // This node has been shut down
     mAccChildCount = eChildCountUninitialized;
     return;
   }
 
   if (mAccChildCount == eChildCountUninitialized) {
     mAccChildCount = 0;// Prevent reentry
-    PRBool allowsAnonChildren = PR_FALSE;
-    GetAllowsAnonChildAccessibles(&allowsAnonChildren);
+    PRBool allowsAnonChildren = GetAllowsAnonChildAccessibles();
     nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
     // Seed the frame hint early while we're still on a container node.
     // This is better than doing the GetPrimaryFrameFor() later on
     // a text node, because text nodes aren't in the frame map.
     walker.mState.frame = GetFrame();
 
-    nsCOMPtr<nsPIAccessible> privatePrevAccessible;
+    nsRefPtr<nsAccessible> prevAcc;
     PRInt32 childCount = 0;
     walker.GetFirstChild();
     SetFirstChild(walker.mState.accessible);
 
     while (walker.mState.accessible) {
       ++ childCount;
-      privatePrevAccessible = do_QueryInterface(walker.mState.accessible);
-      privatePrevAccessible->SetParent(this);
+      prevAcc = nsAccUtils::QueryAccessible(walker.mState.accessible);
+      prevAcc->SetParent(this);
       walker.GetNextSibling();
-      privatePrevAccessible->SetNextSibling(walker.mState.accessible);
+      prevAcc->SetNextSibling(walker.mState.accessible);
     }
     mAccChildCount = childCount;
   }
 }
 
-NS_IMETHODIMP nsAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsAccessible::GetAllowsAnonChildAccessibles()
 {
-  *aAllowsAnonChildren = PR_TRUE;
-  return NS_OK;
+  return PR_TRUE;
 }
 
 /* readonly attribute long childCount; */
 NS_IMETHODIMP nsAccessible::GetChildCount(PRInt32 *aAccChildCount) 
 {
   CacheChildren();
   *aAccChildCount = mAccChildCount;
   return NS_OK;  
@@ -821,40 +814,39 @@ NS_IMETHODIMP nsAccessible::GetIndexInPa
     nsCOMPtr<nsIAccessible> tempAccessible;
     sibling->GetNextSibling(getter_AddRefs(tempAccessible));
     sibling = tempAccessible;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAccessible::TestChildCache(nsIAccessible *aCachedChild)
+void
+nsAccessible::TestChildCache(nsIAccessible *aCachedChild)
 {
-#ifndef DEBUG_A11Y
-  return NS_OK;
-#else
+#ifdef DEBUG_A11Y
   // All cached accessible nodes should be in the parent
   // It will assert if not all the children were created
   // when they were first cached, and no invalidation
   // ever corrected parent accessible's child cache.
-  if (mAccChildCount <= 0) {
-    return NS_OK;
-  }
+  if (mAccChildCount <= 0)
+    return;
+
   nsCOMPtr<nsIAccessible> sibling = mFirstChild;
 
   while (sibling != aCachedChild) {
     NS_ASSERTION(sibling, "[TestChildCache] Never ran into the same child that we started from");
     if (!sibling)
-      return NS_ERROR_FAILURE;
+      return;
 
     nsCOMPtr<nsIAccessible> tempAccessible;
     sibling->GetNextSibling(getter_AddRefs(tempAccessible));
     sibling = tempAccessible;
   }
-  return NS_OK;
+
 #endif
 }
 
 nsresult nsAccessible::GetTranslatedString(const nsAString& aKey, nsAString& aStringOut)
 {
   nsXPIDLString xsValue;
 
   if (!gStringBundle || 
@@ -1584,17 +1576,17 @@ nsAccessible::GetXULName(nsAString& aLab
       return NS_OK;
     }
     parent = parent->GetParent();
   }
 
   return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
 }
 
-NS_IMETHODIMP
+nsresult
 nsAccessible::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   NS_ENSURE_ARG_POINTER(aEvent);
   nsCOMPtr<nsIDOMNode> eventNode;
   aEvent->GetDOMNode(getter_AddRefs(eventNode));
   NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIObserverService> obsService =
@@ -3099,17 +3091,17 @@ nsresult nsAccessible::GetLinkOffset(PRI
     }
     accessible->GetNextSibling(getter_AddRefs(nextSibling));
     accessible.swap(nextSibling);
   }
 
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP
+nsresult
 nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
 {
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible public methods
 
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -41,17 +41,16 @@
 
 #include "nsAccessNodeWrap.h"
 
 #include "nsARIAMap.h"
 #include "nsRelUtils.h"
 #include "nsTextEquivUtils.h"
 
 #include "nsIAccessible.h"
-#include "nsPIAccessible.h"
 #include "nsIAccessibleHyperLink.h"
 #include "nsIAccessibleSelectable.h"
 #include "nsIAccessibleValue.h"
 #include "nsIAccessibleRole.h"
 #include "nsIAccessibleStates.h"
 #include "nsIAccessibleEvent.h"
 
 #include "nsIDOMNodeList.h"
@@ -99,39 +98,37 @@ public:
   }
 
 private:
   nsTArray<nsString> mNames;
 };
 
 
 #define NS_ACCESSIBLE_IMPL_CID                          \
-{  /* 16917f1e-6cee-4cde-be3f-8bb5943f506c */           \
-  0x16917f1e,                                           \
-  0x6cee,                                               \
-  0x4cde,                                               \
-  { 0xbe, 0x3f, 0x8b, 0xb5, 0x94, 0x3F, 0x50, 0x6c }    \
+{  /* 53cfa871-be42-47fc-b416-0033653b3151 */           \
+  0x53cfa871,                                           \
+  0xbe42,                                               \
+  0x47fc,                                               \
+  { 0xb4, 0x16, 0x00, 0x33, 0x65, 0x3b, 0x31, 0x51 }    \
 }
 
 class nsAccessible : public nsAccessNodeWrap, 
                      public nsIAccessible, 
-                     public nsPIAccessible,
                      public nsIAccessibleHyperLink,
                      public nsIAccessibleSelectable,
                      public nsIAccessibleValue
 {
 public:
   nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
   virtual ~nsAccessible();
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsAccessible, nsAccessNode)
 
   NS_DECL_NSIACCESSIBLE
-  NS_DECL_NSPIACCESSIBLE
   NS_DECL_NSIACCESSIBLEHYPERLINK
   NS_DECL_NSIACCESSIBLESELECTABLE
   NS_DECL_NSIACCESSIBLEVALUE
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLE_IMPL_CID)
 
   //////////////////////////////////////////////////////////////////////////////
   // nsAccessNode
 
@@ -141,16 +138,25 @@ public:
   // Public methods
 
   /**
    * Returns the accessible name specified by ARIA.
    */
   nsresult GetARIAName(nsAString& aName);
 
   /**
+   * Maps ARIA state attributes to state of accessible. Note the given state
+   * argument should hold states for accessible before you pass it into this
+   * method.
+   *
+   * @param  [in/out] where to fill the states into.
+   */
+  virtual nsresult GetARIAState(PRUint32 *aState);
+
+  /**
    * Returns the accessible name provided by native markup. It doesn't take
    * into account ARIA markup used to specify the name.
    *
    * @param  aName             [out] the accessible name
    *
    * @return NS_OK_EMPTY_NAME  points empty name was specified by native markup
    *                           explicitly (see nsIAccessible::name attribute for
    *                           details)
@@ -187,16 +193,88 @@ public:
    * @param  aDeepestChild  [in] flag points if deep child should be returned
    * @param  aChild         [out] found child
    */
   virtual nsresult GetChildAtPoint(PRInt32 aX, PRInt32 aY,
                                    PRBool aDeepestChild,
                                    nsIAccessible **aChild);
 
   //////////////////////////////////////////////////////////////////////////////
+  // Initializing and cache methods
+
+  /**
+   * Set accessible parent.
+   * XXX: shouldn't be virtual, bug 496783
+   */
+  virtual void SetParent(nsIAccessible *aParent);
+
+  /**
+   * Set first accessible child.
+   */
+  void SetFirstChild(nsIAccessible *aFirstChild);
+
+  /**
+   * Set next sibling accessible.
+   */
+  void SetNextSibling(nsIAccessible *aNextSibling);
+
+  /**
+   * Set the ARIA role map entry for a new accessible.
+   * For a newly created accessible, specify which role map entry should be used.
+   *
+   * @param aRoleMapEntry The ARIA nsRoleMapEntry* for the accessible, or 
+   *                      nsnull if none.
+   */
+  virtual void SetRoleMapEntry(nsRoleMapEntry *aRoleMapEntry);
+
+  /**
+   * Set the child count to -1 (unknown) and null out cached child pointers
+   */
+  virtual void InvalidateChildren();
+
+  /**
+   * Return parent accessible only if cached.
+   */
+  already_AddRefed<nsIAccessible> GetCachedParent();
+
+  /**
+   * Return first child accessible only if cached.
+   */
+  already_AddRefed<nsIAccessible> GetCachedFirstChild();
+
+  /**
+   * Assert if child not in parent's cache.
+   */
+  void TestChildCache(nsIAccessible *aCachedChild);
+
+  //////////////////////////////////////////////////////////////////////////////
+  // Miscellaneous methods.
+
+  /**
+   * Fire accessible event.
+   */
+  virtual nsresult FireAccessibleEvent(nsIAccessibleEvent *aAccEvent);
+
+  /**
+   * Return true if there are accessible children in anonymous content
+   */
+  virtual PRBool GetAllowsAnonChildAccessibles();
+
+  /**
+   * Returns text of accessible if accessible has text role otherwise empty
+   * string.
+   *
+   * @param aText         returned text of the accessible
+   * @param aStartOffset  start offset inside of the accesible
+   * @param aLength       required lenght of text
+   */
+  virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
+                                PRUint32 aLength);
+
+  //////////////////////////////////////////////////////////////////////////////
   // Helper methods
   
   already_AddRefed<nsIAccessible> GetParent() {
     nsIAccessible *parent = nsnull;
     GetParent(&parent);
     return parent;
   }
 
--- a/accessible/src/base/nsApplicationAccessible.cpp
+++ b/accessible/src/base/nsApplicationAccessible.cpp
@@ -231,30 +231,31 @@ nsApplicationAccessible::CacheChildren()
 
   if (mAccChildCount == eChildCountUninitialized) {
     mAccChildCount = 0;// Prevent reentry
     nsCOMPtr<nsISimpleEnumerator> enumerator;
     mChildren->Enumerate(getter_AddRefs(enumerator));
 
     nsCOMPtr<nsIWeakReference> childWeakRef;
     nsCOMPtr<nsIAccessible> accessible;
-    nsCOMPtr<nsPIAccessible> previousAccessible;
+    nsRefPtr<nsAccessible> prevAcc;
     PRBool hasMoreElements;
-    while(NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreElements))
-          && hasMoreElements) {
+
+    while(NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreElements)) &&
+          hasMoreElements) {
       enumerator->GetNext(getter_AddRefs(childWeakRef));
       accessible = do_QueryReferent(childWeakRef);
       if (accessible) {
-        if (previousAccessible)
-          previousAccessible->SetNextSibling(accessible);
+        if (prevAcc)
+          prevAcc->SetNextSibling(accessible);
         else
           SetFirstChild(accessible);
 
-        previousAccessible = do_QueryInterface(accessible);
-        previousAccessible->SetParent(this);
+        prevAcc = nsAccUtils::QueryAccessible(accessible);
+        prevAcc->SetParent(this);
       }
     }
 
     PRUint32 count = 0;
     mChildren->GetLength(&count);
     mAccChildCount = static_cast<PRInt32>(count);
   }
 }
--- a/accessible/src/base/nsBaseWidgetAccessible.cpp
+++ b/accessible/src/base/nsBaseWidgetAccessible.cpp
@@ -81,22 +81,21 @@ NS_IMETHODIMP nsLeafAccessible::GetLastC
 
 /* long getAccChildCount (); */
 NS_IMETHODIMP nsLeafAccessible::GetChildCount(PRInt32 *_retval)
 {
   *_retval = 0;
   return NS_OK;
 }
 
-/* readonly attribute boolean allowsAnonChildAccessibles; */
-NS_IMETHODIMP
-nsLeafAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+// nsAccessible::GetAllowsAnonChildAccessibles()
+PRBool
+nsLeafAccessible::GetAllowsAnonChildAccessibles()
 {
-  *aAllowsAnonChildren = PR_FALSE;
-  return NS_OK;
+  return PR_FALSE;
 }
 
 // nsAccessible::GetChildAtPoint()
 nsresult
 nsLeafAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
                                   PRBool aDeepestChild,
                                   nsIAccessible **aChild)
 {
--- a/accessible/src/base/nsBaseWidgetAccessible.h
+++ b/accessible/src/base/nsBaseWidgetAccessible.h
@@ -62,23 +62,21 @@ public:
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessible
   NS_IMETHOD GetFirstChild(nsIAccessible **_retval);
   NS_IMETHOD GetLastChild(nsIAccessible **_retval);
   NS_IMETHOD GetChildCount(PRInt32 *_retval);
 
-  // nsPIAccessible
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
-
   // nsAccessible
   virtual nsresult GetChildAtPoint(PRInt32 aX, PRInt32 aY,
                                    PRBool aDeepestChild,
                                    nsIAccessible **aChild);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 };
 
 /**
   * A type of accessible for DOM nodes containing an href="" attribute.
   *  It knows how to report the state of the link ( traveled or not )
   *  and can activate ( click ) the link programmatically.
   */
 class nsLinkableAccessible : public nsHyperTextAccessibleWrap
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -231,34 +231,38 @@ nsDocAccessible::GetRoleInternal(PRUint3
     else if (itemType == nsIDocShellTreeItem::typeContent) {
       *aRole = nsIAccessibleRole::ROLE_DOCUMENT;
     }
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsDocAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
+void
+nsDocAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
 {
-  NS_ENSURE_STATE(mDocument);
+  NS_ASSERTION(mDocument, "No document during initialization!");
+  if (!mDocument)
+    return;
 
   mRoleMapEntry = aRoleMapEntry;
 
   // Allow use of ARIA role from outer to override
   nsIDocument *parentDoc = mDocument->GetParentDocument();
-  NS_ENSURE_TRUE(parentDoc, NS_ERROR_FAILURE);
+  NS_ASSERTION(parentDoc, "No parent document during initialization!");
+  if (!parentDoc)
+    return;
+
   nsIContent *ownerContent = parentDoc->FindContentForSubDocument(mDocument);
   nsCOMPtr<nsIDOMNode> ownerNode(do_QueryInterface(ownerContent));
   if (ownerNode) {
     nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(ownerNode);
     if (roleMapEntry)
       mRoleMapEntry = roleMapEntry; // Override
   }
-
-  return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsDocAccessible::GetDescription(nsAString& aDescription)
 {
   if (mParent)
     mParent->GetDescription(aDescription);
 
@@ -318,27 +322,27 @@ nsDocAccessible::GetStateInternal(PRUint
   }
   else if (aExtraState) {
     *aExtraState |= nsIAccessibleStates::EXT_STATE_EDITABLE;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsDocAccessible::GetARIAState(PRUint32 *aState)
 {
   // Combine with states from outer doc
   NS_ENSURE_ARG_POINTER(aState);
   nsresult rv = nsAccessible::GetARIAState(aState);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsPIAccessible> privateParentAccessible = do_QueryInterface(mParent);
-  if (privateParentAccessible)  // Allow iframe/frame etc. to have final state override via ARIA
-    return privateParentAccessible->GetARIAState(aState);
+  nsRefPtr<nsAccessible> parent = nsAccUtils::QueryAccessible(mParent);
+  if (parent)  // Allow iframe/frame etc. to have final state override via ARIA
+    return parent->GetARIAState(aState);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsDocAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
 {
   nsAccessible::GetAttributes(aAttributes);
@@ -533,24 +537,22 @@ NS_IMETHODIMP nsDocAccessible::GetCached
 {
   GetCacheEntry(mAccessNodeCache, aUniqueID, aAccessNode); // Addrefs for us
 #ifdef DEBUG_A11Y
   // All cached accessible nodes should be in the parent
   // It will assert if not all the children were created
   // when they were first cached, and no invalidation
   // ever corrected parent accessible's child cache.
   nsCOMPtr<nsIAccessible> accessible = do_QueryInterface(*aAccessNode);
-  nsCOMPtr<nsPIAccessible> privateAccessible = do_QueryInterface(accessible);
-  if (privateAccessible) {
-    nsCOMPtr<nsIAccessible> parent;
-    privateAccessible->GetCachedParent(getter_AddRefs(parent));
-    nsCOMPtr<nsPIAccessible> privateParent(do_QueryInterface(parent));
-    if (privateParent) {
-      privateParent->TestChildCache(accessible);
-    }
+  nsRefPtr<nsAccessible> acc = nsAccUtils::QueryAccessible(accessible);
+  if (acc) {
+    nsCOMPtr<nsIAccessible> parent = acc->GetCachedParent();
+    nsRefPtr<nsAccessible> parentAcc(nsAccUtils::QueryAccessible(parent));
+    if (parentAcc)
+      parentAcc->TestChildCache(accessible);
   }
 #endif
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocAccessible::CacheAccessNode(void *aUniqueID, nsIAccessNode *aAccessNode)
 {
@@ -880,21 +882,22 @@ NS_IMETHODIMP nsDocAccessible::FireDocLo
   }
   nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
   treeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
 
   if (isFinished) {
     // Need to wait until scrollable view is available
     AddScrollListener();
     nsCOMPtr<nsIAccessible> parent(nsAccessible::GetParent());
-    nsCOMPtr<nsPIAccessible> privateAccessible(do_QueryInterface(parent));
-    if (privateAccessible) {
+    nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(parent));
+    if (acc) {
       // Make the parent forget about the old document as a child
-      privateAccessible->InvalidateChildren();
+      acc->InvalidateChildren();
     }
+
     if (sameTypeRoot != treeItem) {
       // Fire show/hide events to indicate frame/iframe content is new, rather than
       // doc load event which causes screen readers to act is if entire page is reloaded
       InvalidateCacheSubtree(nsnull, nsIAccessibleEvent::EVENT_DOM_SIGNIFICANT_CHANGE);
     }
     // Fire STATE_CHANGE event for doc load finish if focus is in same doc tree
     if (gLastFocusedNode) {
       nsCOMPtr<nsIDocShellTreeItem> focusedTreeItem =
@@ -1633,20 +1636,20 @@ NS_IMETHODIMP nsDocAccessible::FlushPend
         GetAccessibleInParentChain(domNode, PR_TRUE,
                                    getter_AddRefs(containerAccessible));
         if (!containerAccessible)
           containerAccessible = this;
       }
 
       if (eventType == nsIAccessibleEvent::EVENT_ASYNCH_SHOW) {
         // For asynch show, delayed invalidatation of parent's children
-        nsCOMPtr<nsPIAccessible> privateContainerAccessible =
-          do_QueryInterface(containerAccessible);
-        if (privateContainerAccessible)
-          privateContainerAccessible->InvalidateChildren();
+        nsRefPtr<nsAccessible> containerAcc =
+          nsAccUtils::QueryAccessible(containerAccessible);
+        if (containerAcc)
+          containerAcc->InvalidateChildren();
 
         // Some show events in the subtree may have been removed to 
         // avoid firing redundant events. But, we still need to make sure any
         // accessibles parenting those shown nodes lose their child references.
         InvalidateChildrenInSubtree(domNode);
       }
 
       // Also fire text changes if the node being created could affect the text in an nsIAccessibleText parent.
@@ -1760,19 +1763,19 @@ void nsDocAccessible::FlushEventsCallbac
     accessibleDoc->FlushPendingEvents();
   }
 }
 
 void nsDocAccessible::InvalidateChildrenInSubtree(nsIDOMNode *aStartNode)
 {
   nsCOMPtr<nsIAccessNode> accessNode;
   GetCachedAccessNode(aStartNode, getter_AddRefs(accessNode));
-  nsCOMPtr<nsPIAccessible> accessible(do_QueryInterface(accessNode));
-  if (accessible)
-    accessible->InvalidateChildren();
+  nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessNode));
+  if (acc)
+    acc->InvalidateChildren();
 
   // Invalidate accessible children in the DOM subtree 
   nsCOMPtr<nsINode> node = do_QueryInterface(aStartNode);
   PRInt32 index, numChildren = node->GetChildCount();
   for (index = 0; index < numChildren; index ++) {
     nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(node->GetChildAt(index));
     if (childNode)
       InvalidateChildrenInSubtree(childNode);
@@ -1800,22 +1803,21 @@ void nsDocAccessible::RefreshNodes(nsIDO
       nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(domNode));
       if (!popup) {
         // Popup elements already fire these via DOMMenuInactive
         // handling in nsRootAccessible::HandleEvent
         nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
                                  accessible);
       }
     }
-    nsCOMPtr<nsPIAccessible> privateAccessible = do_QueryInterface(accessible);
-    NS_ASSERTION(privateAccessible, "No nsPIAccessible for nsIAccessible");
+    nsRefPtr<nsAccessible> acc = nsAccUtils::QueryAccessible(accessible);
 
-    nsCOMPtr<nsIAccessible> childAccessible;
-    // we only need to shutdown the accessibles here if one of them has been created
-    privateAccessible->GetCachedFirstChild(getter_AddRefs(childAccessible));
+    // We only need to shutdown the accessibles here if one of them has been
+    // created.
+    nsCOMPtr<nsIAccessible> childAccessible = acc->GetCachedFirstChild();
     if (childAccessible) {
       nsCOMPtr<nsIArray> children;
       // use GetChildren() to fetch children at one time, instead of using
       // GetNextSibling(), because after we shutdown the first child,
       // mNextSibling will be set null.
       accessible->GetChildren(getter_AddRefs(children));
       PRUint32 childCount =0;
       if (children)
@@ -1908,31 +1910,35 @@ NS_IMETHODIMP nsDocAccessible::Invalidat
     if (mAccessNodeCache.Count() <= 1) {
       // Still loading and no accessibles has yet been created other than this
       // doc accessible. In this case we optimize
       // by not firing SHOW/HIDE/REORDER events for every document mutation
       // caused by page load, since AT is not going to want to grab the
       // document and listen to these changes until after the page is first loaded
       // Leave early, and ensure mAccChildCount stays uninitialized instead of 0,
       // which it is if anyone asks for its children right now.
-      return InvalidateChildren();
+      InvalidateChildren();
+      return NS_OK;
     }
     nsIEventStateManager *esm = presShell->GetPresContext()->EventStateManager();
     NS_ENSURE_TRUE(esm, NS_ERROR_FAILURE);
     if (!esm->IsHandlingUserInputExternal()) {
       // Changes during page load, but not caused by user input
       // Just invalidate accessible hierarchy and return,
       // otherwise the page load time slows down way too much
       nsCOMPtr<nsIAccessible> containerAccessible;
       GetAccessibleInParentChain(childNode, PR_FALSE, getter_AddRefs(containerAccessible));
       if (!containerAccessible) {
         containerAccessible = this;
       }
-      nsCOMPtr<nsPIAccessible> privateContainer = do_QueryInterface(containerAccessible);
-      return privateContainer->InvalidateChildren();
+
+      nsRefPtr<nsAccessible> containerAcc =
+        nsAccUtils::QueryAccessible(containerAccessible);
+      containerAcc->InvalidateChildren();
+      return NS_OK;
     }     
     // else: user input, so we must fall through and for full handling,
     // e.g. fire the mutation events. Note: user input could cause DOM_CREATE
     // during page load if user typed into an input field or contentEditable area
   }
 
   // Update last change state information
   nsCOMPtr<nsIAccessNode> childAccessNode;
@@ -2017,21 +2023,21 @@ NS_IMETHODIMP nsDocAccessible::Invalidat
   // We will use this accessible to fire the accessible mutation event.
   // We're guaranteed success, because we will eventually end up at the doc accessible,
   // and there is always one of those.
 
   if (aChild && !isHiding) {
     if (!isAsynch) {
       // DOM already updated with new objects -- invalidate parent's children now
       // For asynch we must wait until layout updates before we invalidate the children
-      nsCOMPtr<nsPIAccessible> privateContainerAccessible =
-        do_QueryInterface(containerAccessible);
-      if (privateContainerAccessible) {
-        privateContainerAccessible->InvalidateChildren();
-      }
+      nsRefPtr<nsAccessible> containerAcc =
+        nsAccUtils::QueryAccessible(containerAccessible);
+      if (containerAcc)
+        containerAcc->InvalidateChildren();
+
     }
     // Fire EVENT_SHOW, EVENT_MENUPOPUP_START for newly visible content.
     // Fire after a short timer, because we want to make sure the view has been
     // updated to make this accessible content visible. If we don't wait,
     // the assistive technology may receive the event and then retrieve
     // nsIAccessibleStates::STATE_INVISIBLE for the event's accessible object.
     PRUint32 additionEvent = isAsynch ? nsIAccessibleEvent::EVENT_ASYNCH_SHOW :
                                         nsIAccessibleEvent::EVENT_DOM_CREATE;
--- a/accessible/src/base/nsDocAccessible.h
+++ b/accessible/src/base/nsDocAccessible.h
@@ -71,20 +71,18 @@ class nsDocAccessible : public nsHyperTe
   NS_DECL_NSPIACCESSIBLEDOCUMENT
   NS_DECL_NSIOBSERVER
 
   public:
     nsDocAccessible(nsIDOMNode *aNode, nsIWeakReference* aShell);
     virtual ~nsDocAccessible();
 
     // nsIAccessible
-    NS_IMETHOD SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry);
     NS_IMETHOD GetName(nsAString& aName);
     NS_IMETHOD GetDescription(nsAString& aDescription);
-    NS_IMETHOD GetARIAState(PRUint32 *aState);
     NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
     NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
     NS_IMETHOD GetParent(nsIAccessible **aParent);
     NS_IMETHOD TakeFocus(void);
 
     // ----- nsIScrollPositionListener ---------------------------
     NS_IMETHOD ScrollPositionWillChange(nsIScrollableView *aView, nscoord aX, nscoord aY);
     virtual void ViewPositionDidChange(nsIScrollableView* aScrollable) {}
@@ -98,16 +96,18 @@ class nsDocAccessible : public nsHyperTe
     // nsAccessNode
     virtual nsresult Init();
     virtual nsresult Shutdown();
     virtual nsIFrame* GetFrame();
 
     // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
+  virtual nsresult GetARIAState(PRUint32 *aState);
+  virtual void SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry);
 
     // nsIAccessibleText
     NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor);
 
     /**
       * Non-virtual method to fire a delayed event after a 0 length timeout
       *
       * @param aEvent - the nsIAccessibleEvent event type
--- a/accessible/src/base/nsOuterDocAccessible.cpp
+++ b/accessible/src/base/nsOuterDocAccessible.cpp
@@ -132,27 +132,25 @@ void nsOuterDocAccessible::CacheChildren
   if (!innerNode) {
     return;
   }
 
   nsCOMPtr<nsIAccessible> innerAccessible;
   nsCOMPtr<nsIAccessibilityService> accService = 
     do_GetService("@mozilla.org/accessibilityService;1");
   accService->GetAccessibleFor(innerNode, getter_AddRefs(innerAccessible));
-  nsCOMPtr<nsPIAccessible> privateInnerAccessible = 
-    do_QueryInterface(innerAccessible);
-  if (!privateInnerAccessible) {
+  nsRefPtr<nsAccessible> innerAcc(nsAccUtils::QueryAccessible(innerAccessible));
+  if (!innerAcc)
     return;
-  }
 
   // Success getting inner document as first child -- now we cache it.
   mAccChildCount = 1;
   SetFirstChild(innerAccessible); // weak ref
-  privateInnerAccessible->SetParent(this);
-  privateInnerAccessible->SetNextSibling(nsnull);
+  innerAcc->SetParent(this);
+  innerAcc->SetNextSibling(nsnull);
 }
 
 nsresult
 nsOuterDocAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   nsAutoString tag;
   aAttributes->GetStringProperty(NS_LITERAL_CSTRING("tag"), tag);
   if (!tag.IsEmpty()) {
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -658,18 +658,18 @@ nsresult nsRootAccessible::HandleEventWi
 
   nsCOMPtr<nsIAccessible> accessible;
   accService->GetAccessibleInShell(aTargetNode, eventShell,
                                    getter_AddRefs(accessible));
 
   if (eventType.EqualsLiteral("popuphiding"))
     return HandlePopupHidingEvent(aTargetNode, accessible);
 
-  nsCOMPtr<nsPIAccessible> privAcc(do_QueryInterface(accessible));
-  if (!privAcc)
+  nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessible));
+  if (!acc)
     return NS_OK;
 
 #ifdef MOZ_XUL
   if (isTree) {
     nsCOMPtr<nsIAccessibleTreeCache> treeAcc(do_QueryInterface(accessible));
     NS_ASSERTION(treeAcc,
                  "Accessible for xul:tree doesn't implement nsIAccessibleTreeCache interface.");
 
@@ -694,17 +694,17 @@ nsresult nsRootAccessible::HandleEventWi
     // nsXULListitemAccessible::GetStateInternal uses STATE_SELECTED in this case,
     // so we need to check nsIAccessibleStates::STATE_SELECTED also.
     PRBool isEnabled = (state & (nsIAccessibleStates::STATE_CHECKED |
                         nsIAccessibleStates::STATE_SELECTED)) != 0;
 
     nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
       new nsAccStateChangeEvent(accessible, nsIAccessibleStates::STATE_CHECKED,
                                 PR_FALSE, isEnabled);
-    privAcc->FireAccessibleEvent(accEvent);
+    acc->FireAccessibleEvent(accEvent);
 
     if (isEnabled)
       FireAccessibleFocusEvent(accessible, aTargetNode, aEvent);
 
     return NS_OK;
   }
 
   if (eventType.EqualsLiteral("CheckboxStateChange")) {
@@ -712,17 +712,17 @@ nsresult nsRootAccessible::HandleEventWi
 
     PRBool isEnabled = !!(state & nsIAccessibleStates::STATE_CHECKED);
 
     nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
       new nsAccStateChangeEvent(accessible,
                                 nsIAccessibleStates::STATE_CHECKED,
                                 PR_FALSE, isEnabled);
 
-    return privAcc->FireAccessibleEvent(accEvent);
+    return acc->FireAccessibleEvent(accEvent);
   }
 
   nsCOMPtr<nsIAccessible> treeItemAccessible;
 #ifdef MOZ_XUL
   // If it's a tree element, need the currently selected item
   if (isTree) {
     nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
       do_QueryInterface(aTargetNode);
@@ -1123,19 +1123,18 @@ nsRootAccessible::HandlePopupShownEvent(
     if (comboboxRole == nsIAccessibleRole::ROLE_COMBOBOX ||
         comboboxRole == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
       nsCOMPtr<nsIAccessibleStateChangeEvent> event =
         new nsAccStateChangeEvent(comboboxAcc,
                                   nsIAccessibleStates::STATE_EXPANDED,
                                   PR_FALSE, PR_TRUE);
       NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
 
-      nsCOMPtr<nsPIAccessible> pComboboxAcc(do_QueryInterface(comboboxAcc));
-
-      return pComboboxAcc->FireAccessibleEvent(event);
+      nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(comboboxAcc));
+      return acc->FireAccessibleEvent(event);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 nsRootAccessible::HandlePopupHidingEvent(nsIDOMNode *aNode,
@@ -1168,19 +1167,18 @@ nsRootAccessible::HandlePopupHidingEvent
   if (comboboxRole == nsIAccessibleRole::ROLE_COMBOBOX ||
       comboboxRole == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
     nsCOMPtr<nsIAccessibleStateChangeEvent> event =
       new nsAccStateChangeEvent(comboboxAcc,
                                 nsIAccessibleStates::STATE_EXPANDED,
                                 PR_FALSE, PR_FALSE);
     NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
 
-    nsCOMPtr<nsPIAccessible> pComboboxAcc(do_QueryInterface(comboboxAcc));
-
-    return pComboboxAcc->FireAccessibleEvent(event);
+    nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(comboboxAcc));
+    return acc->FireAccessibleEvent(event);
   }
 
   return NS_OK;
 }
 
 #ifdef MOZ_XUL
 nsresult
 nsRootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
--- a/accessible/src/base/nsTextAccessible.cpp
+++ b/accessible/src/base/nsTextAccessible.cpp
@@ -48,18 +48,18 @@
 nsTextAccessible::nsTextAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
 nsLinkableAccessible(aDOMNode, aShell)
 { 
 }
 
 // Make sure we don't support text or other irrelevant interfaces.
 // We have nsLinkableAccessible in our inheritance chain as a convenience in order to
 // get link actions and states on the text accessibles. Windows screen readers expect that.
-NS_IMPL_ISUPPORTS_INHERITED3(nsTextAccessible, nsAccessNode,
-                             nsAccessible, nsIAccessible, nsPIAccessible)
+NS_IMPL_ISUPPORTS_INHERITED2(nsTextAccessible, nsAccessNode,
+                             nsAccessible, nsIAccessible)
 
 /**
   * We are text
   */
 nsresult
 nsTextAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_TEXT_LEAF;
@@ -88,17 +88,17 @@ NS_IMETHODIMP nsTextAccessible::GetLastC
   * No Children
   */
 NS_IMETHODIMP nsTextAccessible::GetChildCount(PRInt32 *_retval)
 {
   *_retval = 0;
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsTextAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
 {
   nsIFrame *frame = GetFrame();
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   return frame->GetRenderedText(&aText, nsnull, nsnull, aStartOffset, aLength);
 }
 
--- a/accessible/src/base/nsTextAccessible.h
+++ b/accessible/src/base/nsTextAccessible.h
@@ -53,18 +53,17 @@ public:
 
   nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
 
   // nsIAccessible
   NS_IMETHOD GetFirstChild(nsIAccessible **_retval);
   NS_IMETHOD GetLastChild(nsIAccessible **_retval);
   NS_IMETHOD GetChildCount(PRInt32 *_retval);
 
-  // nsPIAccessible
-  NS_IMETHOD AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength);
-
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
+  virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
+                                PRUint32 aLength);
 };
 
 
 #endif
 
--- a/accessible/src/html/nsHTMLImageAccessible.cpp
+++ b/accessible/src/html/nsHTMLImageAccessible.cpp
@@ -172,31 +172,28 @@ void nsHTMLImageAccessible::CacheChildre
   if (!mapAreas)
     return;
 
   PRUint32 numMapAreas;
   mapAreas->GetLength(&numMapAreas);
   PRInt32 childCount = 0;
   
   nsCOMPtr<nsIAccessible> areaAccessible;
-  nsCOMPtr<nsPIAccessible> privatePrevAccessible;
+  nsRefPtr<nsAccessible> prevAcc;
   while (childCount < (PRInt32)numMapAreas && 
          (areaAccessible = GetAreaAccessible(mapAreas, childCount)) != nsnull) {
-    if (privatePrevAccessible) {
-      privatePrevAccessible->SetNextSibling(areaAccessible);
-    }
-    else {
+    if (prevAcc)
+      prevAcc->SetNextSibling(areaAccessible);
+    else
       SetFirstChild(areaAccessible);
-    }
 
     ++ childCount;
 
-    privatePrevAccessible = do_QueryInterface(areaAccessible);
-    NS_ASSERTION(privatePrevAccessible, "nsIAccessible impl's should always support nsPIAccessible as well");
-    privatePrevAccessible->SetParent(this);
+    prevAcc = nsAccUtils::QueryAccessible(areaAccessible);
+    prevAcc->SetParent(this);
   }
   mAccChildCount = childCount;
 }
 
 NS_IMETHODIMP
 nsHTMLImageAccessible::GetNumActions(PRUint8 *aNumActions)
 {
   NS_ENSURE_ARG_POINTER(aNumActions);
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -372,33 +372,31 @@ nsHTMLSelectListAccessible::AccessibleFo
                                                 nsIAccessible *aLastGoodAccessible,
                                                 PRInt32 *aChildCount)
 {
   nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aContent));
   NS_ASSERTION(domNode, "DOM node is null");
   // Accessibility service will initialize & cache any accessibles created
   nsCOMPtr<nsIAccessible> accessible;
   aAccService->GetAccessibleInWeakShell(domNode, mWeakShell, getter_AddRefs(accessible));
-  nsCOMPtr<nsPIAccessible> privateAccessible(do_QueryInterface(accessible));
-  if (!privateAccessible) {
+  nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessible));
+  if (!acc)
     return nsnull;
-  }
 
   ++ *aChildCount;
-  privateAccessible->SetParent(this);
-  nsCOMPtr<nsPIAccessible> privatePrevAccessible(do_QueryInterface(aLastGoodAccessible));
-  if (privatePrevAccessible) {
-    privatePrevAccessible->SetNextSibling(accessible);
-  }
-  if (!mFirstChild) {
+  acc->SetParent(this);
+  nsRefPtr<nsAccessible> prevAcc =
+    nsAccUtils::QueryAccessible(aLastGoodAccessible);
+  if (prevAcc)
+    prevAcc->SetNextSibling(accessible);
+
+  if (!mFirstChild)
     mFirstChild = accessible;
-  }
-  nsIAccessible *returnAccessible = accessible;
-  NS_ADDREF(returnAccessible);
-  return returnAccessible;
+
+  return accessible.forget();
 }
 
 already_AddRefed<nsIAccessible>
 nsHTMLSelectListAccessible::CacheOptSiblings(nsIAccessibilityService *aAccService,
                                              nsIContent *aParentContent,
                                              nsIAccessible *aLastGoodAccessible,
                                              PRInt32 *aChildCount)
 {
@@ -426,23 +424,24 @@ nsHTMLSelectListAccessible::CacheOptSibl
         newAccessible = CacheOptSiblings(aAccService, childContent,
                                          lastGoodAccessible, aChildCount);
         if (newAccessible) {
           lastGoodAccessible = newAccessible;
         }
       }
     }
   }
+
   if (lastGoodAccessible) {
-    nsCOMPtr<nsPIAccessible> privateLastAcc =
-      do_QueryInterface(lastGoodAccessible);
-    privateLastAcc->SetNextSibling(nsnull);
-    NS_ADDREF(aLastGoodAccessible = lastGoodAccessible);
+    nsRefPtr<nsAccessible> lastAcc =
+      nsAccUtils::QueryAccessible(lastGoodAccessible);
+    lastAcc->SetNextSibling(nsnull);
   }
-  return aLastGoodAccessible;
+
+  return lastGoodAccessible.forget();
 }
 
 /**
   * Cache the children and child count of a Select List Accessible. We want to count 
   *  all the <optgroup>s and <option>s as children because we want a 
   *  flat tree under the Select List.
   */
 
@@ -840,28 +839,24 @@ void nsHTMLSelectOptionAccessible::Selec
     return;
   }
 
   nsCOMPtr<nsIDOMNode> optionNode(do_QueryInterface(aPossibleOption));
   NS_ASSERTION(optionNode, "No option node for nsIContent with option tag!");
 
   nsCOMPtr<nsIAccessible> multiSelect =
     nsAccUtils::GetMultiSelectFor(optionNode);
-  nsCOMPtr<nsPIAccessible> privateMultiSelect = do_QueryInterface(multiSelect);
-  if (!privateMultiSelect) {
+  if (!multiSelect)
     return;
-  }
 
-  nsCOMPtr<nsIAccessibilityService> accService = 
-    do_GetService("@mozilla.org/accessibilityService;1");
   nsCOMPtr<nsIAccessible> optionAccessible;
-  accService->GetAccessibleFor(optionNode, getter_AddRefs(optionAccessible));
-  if (!optionAccessible) {
+  GetAccService()->GetAccessibleFor(optionNode,
+                                    getter_AddRefs(optionAccessible));
+  if (!optionAccessible)
     return;
-  }
 
   nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
                            multiSelect);
 
   PRUint32 state = nsAccUtils::State(optionAccessible);
   PRUint32 eventType;
   if (state & nsIAccessibleStates::STATE_SELECTED) {
     eventType = nsIAccessibleEvent::EVENT_SELECTION_ADD;
@@ -1245,20 +1240,20 @@ void nsHTMLComboboxTextFieldAccessible::
     nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, PR_TRUE);
     // Seed the frame hint early while we're still on a container node.
     // This is better than doing the GetPrimaryFrameFor() later on
     // a text node, because text nodes aren't in the frame map.
     walker.mState.frame = GetFrame();
 
     walker.GetFirstChild();
     SetFirstChild(walker.mState.accessible);
-    nsCOMPtr<nsPIAccessible> privateChild = 
-      do_QueryInterface(walker.mState.accessible);
-    privateChild->SetParent(this);
-    privateChild->SetNextSibling(nsnull);
+    nsRefPtr<nsAccessible> child =
+      nsAccUtils::QueryAccessible(walker.mState.accessible);
+    child->SetParent(this);
+    child->SetNextSibling(nsnull);
     mAccChildCount = 1;
   }
 }
 
 /** -----ComboboxButtonAccessible ----- */
 
 /** Constructor -- cache our parent */
 nsHTMLComboboxButtonAccessible::nsHTMLComboboxButtonAccessible(nsIAccessible* aParent, 
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -415,24 +415,28 @@ void nsHTMLTableAccessible::CacheChildre
         if (captionParentAccessible != this) {
           NS_WARNING("Should not happen: parser ensures caption is the table's child, not the tbody's");
           return;
         }
         nsCOMPtr<nsIAccessible> beforeCaptionAccessible;
         captionAccessible->GetPreviousSibling(getter_AddRefs(beforeCaptionAccessible));
         if (beforeCaptionAccessible) {
           // Move caption accessible so that it's the first child
+          nsRefPtr<nsAccessible> acc =
+            nsAccUtils::QueryAccessible(beforeCaptionAccessible);
+
           nsCOMPtr<nsIAccessible> afterCaptionAccessible;
           captionAccessible->GetNextSibling(getter_AddRefs(afterCaptionAccessible));
-          nsCOMPtr<nsPIAccessible> privateAcc = do_QueryInterface(beforeCaptionAccessible);
-          privateAcc->SetNextSibling(afterCaptionAccessible);
+          acc->SetNextSibling(afterCaptionAccessible);
+
           GetFirstChild(getter_AddRefs(afterCaptionAccessible));
           SetFirstChild(captionAccessible);
-          privateAcc = do_QueryInterface(captionAccessible);
-          privateAcc->SetNextSibling(afterCaptionAccessible);        
+
+          acc = nsAccUtils::QueryAccessible(captionAccessible);
+          acc->SetNextSibling(afterCaptionAccessible);        
         }
         // Don't check for more captions, because nsAccessibilityService ensures
         // we don't create accessibles for the other captions, since only the
         // first is actually visible
         break;
       }
     }
   }
--- a/accessible/src/html/nsHTMLTextAccessible.cpp
+++ b/accessible/src/html/nsHTMLTextAccessible.cpp
@@ -338,32 +338,31 @@ nsHTMLListBulletAccessible::GetStateInte
   nsresult rv = nsLeafAccessible::GetStateInternal(aState, aExtraState);
   NS_ENSURE_A11Y_SUCCESS(rv, rv);
 
   *aState &= ~nsIAccessibleStates::STATE_FOCUSABLE;
   *aState |= nsIAccessibleStates::STATE_READONLY;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsHTMLListBulletAccessible::SetParent(nsIAccessible *aParentAccessible)
+void
+nsHTMLListBulletAccessible::SetParent(nsIAccessible *aParent)
 {
   mParent = nsnull;
-  mWeakParent = aParentAccessible;
-  return NS_OK;
+  mWeakParent = aParent;
 }
 
 NS_IMETHODIMP
 nsHTMLListBulletAccessible::GetParent(nsIAccessible **aParentAccessible)
 {
   NS_IF_ADDREF(*aParentAccessible = mWeakParent);
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 nsHTMLListBulletAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
                                          PRUint32 aLength)
 {
   PRUint32 maxLength = mBulletText.Length() - aStartOffset;
   if (aLength > maxLength) {
     aLength = maxLength;
   }
   aText += nsDependentSubstring(mBulletText, aStartOffset, aLength);
--- a/accessible/src/html/nsHTMLTextAccessible.h
+++ b/accessible/src/html/nsHTMLTextAccessible.h
@@ -108,28 +108,27 @@ public:
   NS_IMETHOD GetUniqueID(void **aUniqueID);
 
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& aName);
 
   // Don't cache via unique ID -- bullet accessible shares the same dom node as
   // this LI accessible. Also, don't cache via mParent/SetParent(), prevent
   // circular reference since li holds onto us.
-  NS_IMETHOD SetParent(nsIAccessible *aParentAccessible);
   NS_IMETHOD GetParent(nsIAccessible **aParentAccessible);
 
   // nsAccessNode
   virtual nsresult Shutdown();
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
-
-  // nsPIAccessible
-  NS_IMETHOD AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength);
+  virtual void SetParent(nsIAccessible *aParent);
+  virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
+                                PRUint32 aLength);
 
 protected:
   // XXX: Ideally we'd get the bullet text directly from the bullet frame via
   // nsBulletFrame::GetListItemText(), but we'd need an interface for getting
   // text from contentless anonymous frames. Perhaps something like
   // nsIAnonymousFrame::GetText() ? However, in practice storing the bullet text
   // here should not be a problem if we invalidate the right parts of
   // the accessibility cache when mutation events occur.
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -226,27 +226,27 @@ void nsHyperTextAccessible::CacheChildre
     mAccChildCount = 0;  // Avoid reentry
     nsCOMPtr<nsIDOMElement> editorRoot;
     editor->GetRootElement(getter_AddRefs(editorRoot));
     nsCOMPtr<nsIDOMNode> editorRootDOMNode = do_QueryInterface(editorRoot);
     if (!editorRootDOMNode) {
       return;
     }
     nsAccessibleTreeWalker walker(mWeakShell, editorRootDOMNode, PR_TRUE);
-    nsCOMPtr<nsPIAccessible> privatePrevAccessible;
+    nsRefPtr<nsAccessible> prevAcc;
     PRInt32 childCount = 0;
     walker.GetFirstChild();
     SetFirstChild(walker.mState.accessible);
 
     while (walker.mState.accessible) {
       ++ childCount;
-      privatePrevAccessible = do_QueryInterface(walker.mState.accessible);
-      privatePrevAccessible->SetParent(this);
+      prevAcc = nsAccUtils::QueryAccessible(walker.mState.accessible);
+      prevAcc->SetParent(this);
       walker.GetNextSibling();
-      privatePrevAccessible->SetNextSibling(walker.mState.accessible);
+      prevAcc->SetNextSibling(walker.mState.accessible);
     }
     mAccChildCount = childCount;
   }
 }
 
 // Substring must be entirely within the same text node
 nsIntRect nsHyperTextAccessible::GetBoundsForString(nsIFrame *aFrame, PRUint32 aStartRenderedOffset,
                                                     PRUint32 aEndRenderedOffset)
@@ -434,19 +434,19 @@ nsHyperTextAccessible::GetPosAndText(PRI
           aEndOffset = endOffset;
         }
         if (aText) {
           if (isPassword) {
             for (PRInt32 count = startOffset; count < substringEndOffset; count ++)
               *aText += '*'; // Show *'s only for password text
           }
           else {
-            nsCOMPtr<nsPIAccessible> pAcc(do_QueryInterface(accessible));
-            pAcc->AppendTextTo(*aText, startOffset,
-                               substringEndOffset - startOffset);
+            nsRefPtr<nsAccessible> acc(nsAccUtils::QueryAccessible(accessible));
+            acc->AppendTextTo(*aText, startOffset,
+                              substringEndOffset - startOffset);
           }
         }
         if (aBoundsRect) {    // Caller wants the bounds of the text
           aBoundsRect->UnionRect(*aBoundsRect,
                                  GetBoundsForString(primaryFrame, startOffset,
                                                     substringEndOffset));
         }
         if (!startFrame) {
--- a/accessible/src/mac/nsAccessibleWrap.h
+++ b/accessible/src/mac/nsAccessibleWrap.h
@@ -70,20 +70,20 @@ class nsAccessibleWrap : public nsAccess
     // should be instantied with.   used on runtime to determine the
     // right type for this accessible's associated native object.
     virtual objc_class* GetNativeType ();
     
     // returns a pointer to the native window for this accessible tree.
     void GetNativeWindow (void **aOutNativeWindow);
     
     virtual nsresult Shutdown ();
-    virtual nsresult InvalidateChildren ();
+    virtual void InvalidateChildren();
 
-    NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
-    
+    virtual nsresult FireAccessibleEvent(nsIAccessibleEvent *aEvent);
+
     // ignored means that the accessible might still have children, but is not displayed
     // to the user. it also has no native accessible object represented for it.
     PRBool IsIgnored();
     
     PRInt32 GetUnignoredChildCount(PRBool aDeepCount);
     
     PRBool HasPopup () {
       PRUint32 state = 0;
--- a/accessible/src/mac/nsAccessibleWrap.mm
+++ b/accessible/src/mac/nsAccessibleWrap.mm
@@ -154,17 +154,17 @@ nsAccessibleWrap::Shutdown ()
   if (mNativeWrapper) {
     delete mNativeWrapper;
     mNativeWrapper = nsnull;
   }
   
   return nsAccessible::Shutdown();
 }
 
-NS_IMETHODIMP
+nsresult
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   NS_ENSURE_ARG_POINTER(aEvent);
 
   nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -206,26 +206,26 @@ nsAccessibleWrap::FirePlatformEvent(nsIA
       break;
   }
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
-nsresult
-nsAccessibleWrap::InvalidateChildren ()
+void
+nsAccessibleWrap::InvalidateChildren()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   if (mNativeWrapper) {
     mozAccessible *object = mNativeWrapper->getNativeObject();
     [object invalidateChildren];
   }
-  return nsAccessible::InvalidateChildren();
+  nsAccessible::InvalidateChildren();
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 PRInt32
 nsAccessibleWrap::GetUnignoredChildCount(PRBool aDeepCount)
 {
   // if we're flat, we have no children.
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -1618,19 +1618,19 @@ STDMETHODIMP nsAccessibleWrap::Invoke(DI
 
 NS_IMETHODIMP nsAccessibleWrap::GetNativeInterface(void **aOutAccessible)
 {
   *aOutAccessible = static_cast<IAccessible*>(this);
   NS_ADDREF_THIS();
   return NS_OK;
 }
 
-// nsPIAccessible
+// nsAccessible
 
-NS_IMETHODIMP
+nsresult
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   NS_ENSURE_ARG(aEvent);
 
   nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return FirePlatformEvent(aEvent);
--- a/accessible/src/msaa/nsAccessibleWrap.h
+++ b/accessible/src/msaa/nsAccessibleWrap.h
@@ -285,18 +285,18 @@ class nsAccessibleWrap : public nsAccess
   STDMETHODIMP GetTypeInfoCount(UINT *p);
   STDMETHODIMP GetTypeInfo(UINT i, LCID lcid, ITypeInfo **ppti);
   STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames,
                                UINT cNames, LCID lcid, DISPID *rgDispId);
   STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid,
         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
 
-  // nsPIAccessible
-  NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
+  // nsAccessible
+  virtual nsresult FireAccessibleEvent(nsIAccessibleEvent *aEvent);
 
   // Helper methods
   static PRInt32 GetChildIDFor(nsIAccessible* aAccessible);
   static HWND GetHWNDFor(nsIAccessible *aAccessible);
   static HRESULT ConvertToIA2Attributes(nsIPersistentProperties *aAttributes,
                                         BSTR *aIA2Attributes);
 
   /**
--- a/accessible/src/msaa/nsHyperTextAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsHyperTextAccessibleWrap.cpp
@@ -43,17 +43,17 @@
 NS_IMPL_ISUPPORTS_INHERITED0(nsHyperTextAccessibleWrap,
                              nsHyperTextAccessible)
 
 IMPL_IUNKNOWN_INHERITED2(nsHyperTextAccessibleWrap,
                          nsAccessibleWrap,
                          CAccessibleHypertext,
                          CAccessibleEditableText);
 
-NS_IMETHODIMP
+nsresult
 nsHyperTextAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   PRUint32 eventType;
   aEvent->GetEventType(&eventType);
 
   if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED ||
       eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) {
     nsCOMPtr<nsIAccessible> accessible;
--- a/accessible/src/msaa/nsHyperTextAccessibleWrap.h
+++ b/accessible/src/msaa/nsHyperTextAccessibleWrap.h
@@ -55,18 +55,19 @@ public:
     nsHyperTextAccessible(aNode, aShell){}
 
   // IUnknown
   DECL_IUNKNOWN_INHERITED
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
-  // nsIAccessible
-  NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
+  // nsAccessible
+  virtual nsresult FireAccessibleEvent(nsIAccessibleEvent *aEvent);
+
 protected:
   virtual nsresult GetModifiedText(PRBool aGetInsertedText, nsAString& aText,
                                    PRUint32 *aStartOffset,
                                    PRUint32 *aEndOffset);
 };
 
 #endif
 
--- a/accessible/src/xforms/nsXFormsAccessible.cpp
+++ b/accessible/src/xforms/nsXFormsAccessible.cpp
@@ -128,28 +128,27 @@ nsXFormsAccessible::CacheSelectChildren(
 
   if (!children)
     return;
 
   PRUint32 length = 0;
   children->GetLength(&length);
 
   nsCOMPtr<nsIAccessible> accessible;
-  nsCOMPtr<nsPIAccessible> currAccessible;
-  nsCOMPtr<nsPIAccessible> prevAccessible;
+  nsRefPtr<nsAccessible> currAccessible, prevAccessible;
 
   PRUint32 childLength = 0;
   for (PRUint32 index = 0; index < length; index++) {
     nsCOMPtr<nsIDOMNode> child;
     children->Item(index, getter_AddRefs(child));
     if (!child)
       continue;
 
     accService->GetAttachedAccessibleFor(child, getter_AddRefs(accessible));
-    currAccessible = do_QueryInterface(accessible);
+    currAccessible = nsAccUtils::QueryAccessible(accessible);
     if (!currAccessible)
       continue;
 
     if (childLength == 0)
       SetFirstChild(accessible);
 
     currAccessible->SetParent(this);
     if (prevAccessible) {
@@ -242,23 +241,20 @@ nsXFormsAccessible::GetDescription(nsASt
     aDescription = description;
     return NS_OK;
   }
 
   // search the xforms:hint element
   return GetBoundChildElementValue(NS_LITERAL_STRING("hint"), aDescription);
 }
 
-NS_IMETHODIMP
-nsXFormsAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXFormsAccessible::GetAllowsAnonChildAccessibles()
 {
-  NS_ENSURE_ARG_POINTER(aAllowsAnonChildren);
-
-  *aAllowsAnonChildren = PR_FALSE;
-  return NS_OK;
+  return PR_FALSE;
 }
 
 // nsXFormsContainerAccessible
 
 nsXFormsContainerAccessible::
 nsXFormsContainerAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
   nsXFormsAccessible(aNode, aShell)
 {
@@ -266,23 +262,20 @@ nsXFormsContainerAccessible(nsIDOMNode* 
 
 nsresult
 nsXFormsContainerAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_GROUPING;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXFormsContainerAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXFormsContainerAccessible::GetAllowsAnonChildAccessibles()
 {
-  NS_ENSURE_ARG_POINTER(aAllowsAnonChildren);
-
-  *aAllowsAnonChildren = PR_TRUE;
-  return NS_OK;
+  return PR_TRUE;
 }
 
 // nsXFormsEditableAccessible
 
 nsXFormsEditableAccessible::
   nsXFormsEditableAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
   nsXFormsAccessible(aNode, aShell)
 {
--- a/accessible/src/xforms/nsXFormsAccessible.h
+++ b/accessible/src/xforms/nsXFormsAccessible.h
@@ -86,17 +86,17 @@ public:
   virtual nsresult GetNameInternal(nsAString& aName);
 
   // Returns state of xforms element taking into account state of instance node
   // that it is bound to.
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
 
   // Denies accessible nodes in anonymous content of xforms element by
   // always returning PR_FALSE value.
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 
 protected:
   // Returns value of first child xforms element by tagname that is bound to
   // instance node.
   nsresult GetBoundChildElementValue(const nsAString& aTagName,
                                      nsAString& aValue);
 
   // Cache accessible child item/choices elements. For example, the method is
@@ -122,22 +122,22 @@ protected:
  * an XForms upload element since it is constructed from textfield and
  * 'pick up file' and 'clear file' buttons.
  */
 class nsXFormsContainerAccessible : public nsXFormsAccessible
 {
 public:
   nsXFormsContainerAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
 
+  // nsAccessible
+  virtual nsresult GetRoleInternal(PRUint32 *aRole);
+
   // Allows accessible nodes in anonymous content of xforms element by
   // always returning PR_TRUE value.
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
-
-  // nsAccessible
-  virtual nsresult GetRoleInternal(PRUint32 *aRole);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 };
 
 
 /**
  * The class is base for accessible objects for XForms elements that have
  * editable area.
  */
 class nsXFormsEditableAccessible : public nsXFormsAccessible
--- a/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp
+++ b/accessible/src/xforms/nsXFormsFormControlsAccessible.cpp
@@ -581,23 +581,20 @@ nsXFormsSelectComboboxAccessible::GetSta
   else
     *aState = nsIAccessibleStates::STATE_COLLAPSED;
 
   *aState |= nsIAccessibleStates::STATE_HASPOPUP |
              nsIAccessibleStates::STATE_FOCUSABLE;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXFormsSelectComboboxAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXFormsSelectComboboxAccessible::GetAllowsAnonChildAccessibles()
 {
-  NS_ENSURE_ARG_POINTER(aAllowsAnonChildren);
-
-  *aAllowsAnonChildren = PR_TRUE;
-  return NS_OK;
+  return PR_TRUE;
 }
 
 
 // nsXFormsItemComboboxAccessible
 
 nsXFormsItemComboboxAccessible::
   nsXFormsItemComboboxAccessible(nsIDOMNode *aNode, nsIWeakReference *aShell):
   nsXFormsSelectableItemAccessible(aNode, aShell)
--- a/accessible/src/xforms/nsXFormsFormControlsAccessible.h
+++ b/accessible/src/xforms/nsXFormsFormControlsAccessible.h
@@ -276,23 +276,20 @@ public:
  * represented by combobox.
  */
 
 class nsXFormsSelectComboboxAccessible : public nsXFormsSelectableAccessible
 {
 public:
   nsXFormsSelectComboboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
 
-  // Allows accessible nodes in anonymous content of xforms element by
-  // always returning PR_TRUE value.
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
-
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 };
 
 
 /**
  * Accessible object for xforms:item element when it is represented by a
  * listitem. This occurs when the item is contained in a xforms:select with
  * minimal appearance. Such a xforms:select is represented by a combobox.
  */
--- a/accessible/src/xul/nsXULFormControlAccessible.cpp
+++ b/accessible/src/xul/nsXULFormControlAccessible.cpp
@@ -174,37 +174,37 @@ void nsXULButtonAccessible::CacheChildre
   // An XUL button accessible may have 1 child dropmarker accessible
   if (!mWeakShell) {
     mAccChildCount = eChildCountUninitialized;
     return;   // This outer doc node has been shut down
   }
   if (mAccChildCount == eChildCountUninitialized) {
     mAccChildCount = 0;  // Avoid reentry
     SetFirstChild(nsnull);
-    PRBool allowsAnonChildren = PR_FALSE;
-    GetAllowsAnonChildAccessibles(&allowsAnonChildren);
+    PRBool allowsAnonChildren = GetAllowsAnonChildAccessibles();
     nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
     walker.GetFirstChild();
     nsCOMPtr<nsIAccessible> dropMarkerAccessible;
     while (walker.mState.accessible) {
       dropMarkerAccessible = walker.mState.accessible;
       walker.GetNextSibling();
     }
 
     // If the anonymous tree walker can find accessible children, 
     // and the last one is a push button, then use it as the only accessible 
     // child -- because this is the scenario where we have a dropmarker child
 
     if (dropMarkerAccessible) {
       if (nsAccUtils::RoleInternal(dropMarkerAccessible) ==
           nsIAccessibleRole::ROLE_PUSHBUTTON) {
         SetFirstChild(dropMarkerAccessible);
-        nsCOMPtr<nsPIAccessible> privChildAcc = do_QueryInterface(dropMarkerAccessible);
-        privChildAcc->SetNextSibling(nsnull);
-        privChildAcc->SetParent(this);
+        nsRefPtr<nsAccessible> childAcc =
+          nsAccUtils::QueryAccessible(dropMarkerAccessible);
+        childAcc->SetNextSibling(nsnull);
+        childAcc->SetParent(this);
         mAccChildCount = 1;
       }
     }
   }
 }
 
 /**
   * XUL Dropmarker: can contain arbitrary HTML content
@@ -984,21 +984,20 @@ NS_IMETHODIMP nsXULTextFieldAccessible::
       element->Focus();
       return NS_OK;
     }
     return NS_ERROR_FAILURE;
   }
   return NS_ERROR_INVALID_ARG;
 }
 
-NS_IMETHODIMP
-nsXULTextFieldAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXULTextFieldAccessible::GetAllowsAnonChildAccessibles()
 {
-  *aAllowsAnonChildren = PR_FALSE;
-  return NS_OK;
+  return PR_FALSE;
 }
 
 NS_IMETHODIMP nsXULTextFieldAccessible::GetAssociatedEditor(nsIEditor **aEditor)
 {
   *aEditor = nsnull;
   nsCOMPtr<nsIDOMNode> inputField = GetInputField();
   nsCOMPtr<nsIDOMNSEditableElement> editableElt(do_QueryInterface(inputField));
   NS_ENSURE_TRUE(editableElt, NS_ERROR_FAILURE);
--- a/accessible/src/xul/nsXULFormControlAccessible.h
+++ b/accessible/src/xul/nsXULFormControlAccessible.h
@@ -194,24 +194,24 @@ public:
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessible
   NS_IMETHOD GetValue(nsAString& aValue);
   NS_IMETHOD GetNumActions(PRUint8 *_retval);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 index);
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
 
   // nsIAccessibleEditableText
   NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor);
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 
 protected:
   already_AddRefed<nsIDOMNode> GetInputField();
 };
 
 
 #endif  
 
--- a/accessible/src/xul/nsXULMenuAccessible.cpp
+++ b/accessible/src/xul/nsXULMenuAccessible.cpp
@@ -510,22 +510,21 @@ nsXULMenuitemAccessible::GetAttributesIn
 
   nsresult rv = nsAccessible::GetAttributesInternal(aAttributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAccUtils::SetAccAttrsForXULContainerItem(mDOMNode, aAttributes);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXULMenuitemAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXULMenuitemAccessible::GetAllowsAnonChildAccessibles()
 {
   // That indicates we don't walk anonymous children for menuitems
-  *aAllowsAnonChildren = PR_FALSE;
-  return NS_OK;
+  return PR_FALSE;
 }
 
 NS_IMETHODIMP nsXULMenuitemAccessible::DoAction(PRUint8 index)
 {
   if (index == eAction_Click) {   // default action
     DoCommand();
     return NS_OK;
   }
--- a/accessible/src/xul/nsXULMenuAccessible.h
+++ b/accessible/src/xul/nsXULMenuAccessible.h
@@ -89,17 +89,17 @@ public:
   virtual nsresult Init();
 
   // nsAccessible
   virtual nsresult GetNameInternal(nsAString& aName);
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 };
 
 class nsXULMenuSeparatorAccessible : public nsXULMenuitemAccessible
 {
 public:
   nsXULMenuSeparatorAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
 
   // nsIAccessible
--- a/accessible/src/xul/nsXULSelectAccessible.cpp
+++ b/accessible/src/xul/nsXULSelectAccessible.cpp
@@ -954,22 +954,21 @@ NS_IMETHODIMP nsXULListitemAccessible::G
     else
       aName.AssignLiteral("check");
 
     return NS_OK;
   }
   return NS_ERROR_INVALID_ARG;
 }
 
-NS_IMETHODIMP
-nsXULListitemAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXULListitemAccessible::GetAllowsAnonChildAccessibles()
 {
   // That indicates we should walk anonymous children for listitems
-  *aAllowsAnonChildren = PR_TRUE;
-  return NS_OK;
+  return PR_TRUE;
 }
 
 nsresult
 nsXULListitemAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);
 
   // Call base class instead of nsXULMenuAccessible because menu accessible
@@ -1101,37 +1100,36 @@ NS_IMETHODIMP nsXULComboboxAccessible::G
     accService->GetAccessibleInWeakShell(focusedOptionNode, mWeakShell, 
                                         getter_AddRefs(focusedOptionAccessible));
     NS_ENSURE_TRUE(focusedOptionAccessible, NS_ERROR_FAILURE);
     return focusedOptionAccessible->GetDescription(aDescription);
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXULComboboxAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXULComboboxAccessible::GetAllowsAnonChildAccessibles()
 {
-  if (!mDOMNode)
-    return NS_ERROR_FAILURE;
-
   nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
+  NS_ASSERTION(content, "No content during accessible tree building!");
+  if (!content)
+    return PR_FALSE;
 
   if (content->NodeInfo()->Equals(nsAccessibilityAtoms::textbox, kNameSpaceID_XUL) ||
       content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::editable,
                            nsAccessibilityAtoms::_true, eIgnoreCase)) {
     // Both the XUL <textbox type="autocomplete"> and <menulist editable="true"> widgets
     // use nsXULComboboxAccessible. We need to walk the anonymous children for these
     // so that the entry field is a child
-    *aAllowsAnonChildren = PR_TRUE;
-  } else {
-    // Argument of PR_FALSE indicates we don't walk anonymous children for
-    // menuitems
-    *aAllowsAnonChildren = PR_FALSE;
+    return PR_TRUE;
   }
-  return NS_OK;
+
+  // Argument of PR_FALSE indicates we don't walk anonymous children for
+  // menuitems
+  return PR_FALSE;
 }
 
 /** Just one action ( click ). */
 NS_IMETHODIMP nsXULComboboxAccessible::GetNumActions(PRUint8 *aNumActions)
 {
   *aNumActions = 1;
   return NS_OK;
 }
--- a/accessible/src/xul/nsXULSelectAccessible.h
+++ b/accessible/src/xul/nsXULSelectAccessible.h
@@ -136,23 +136,23 @@ public:
   
   nsXULListitemAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
   virtual ~nsXULListitemAccessible() {}
 
   // nsIAccessible
   NS_IMETHOD GetActionName(PRUint8 index, nsAString& aName);
   // Don't use XUL menuitems's description attribute
   NS_IMETHOD GetDescription(nsAString& aDesc) { return nsAccessibleWrap::GetDescription(aDesc); }
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
 
   // nsAccessible
   virtual nsresult GetNameInternal(nsAString& aName);
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 
 protected:
   already_AddRefed<nsIAccessible> GetListAccessible();
 
 private:
   PRBool mIsCheckbox;
 };
 
@@ -178,25 +178,25 @@ public:
 class nsXULComboboxAccessible : public nsAccessibleWrap
 {
 public:
   enum { eAction_Click = 0 };
 
   nsXULComboboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
   virtual ~nsXULComboboxAccessible() {}
 
-  /* ----- nsIAccessible ----- */
+  // nsIAccessible
   NS_IMETHOD GetValue(nsAString& _retval);
   NS_IMETHOD GetDescription(nsAString& aDescription);
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
   NS_IMETHOD DoAction(PRUint8 index);
   NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
   NS_IMETHOD GetActionName(PRUint8 index, nsAString& aName);
 
   // nsAccessNode
   virtual nsresult Init();
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 };
 
 #endif
--- a/accessible/src/xul/nsXULSliderAccessible.cpp
+++ b/accessible/src/xul/nsXULSliderAccessible.cpp
@@ -183,25 +183,21 @@ nsXULSliderAccessible::SetCurrentValue(d
 
   // ARIA redefined current value.
   if (rv != NS_OK_NO_ARIA_VALUE)
     return rv;
 
   return SetSliderAttr(nsAccessibilityAtoms::curpos, aValue);
 }
 
-// nsPIAccessible
-NS_IMETHODIMP
-nsXULSliderAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
+PRBool
+nsXULSliderAccessible::GetAllowsAnonChildAccessibles()
 {
-  NS_ENSURE_ARG_POINTER(aAllowsAnonChildren);
-
   // Do not allow anonymous xul:slider be accessible.
-  *aAllowsAnonChildren = PR_FALSE;
-  return NS_OK;
+  return PR_FALSE;
 }
 
 // Utils
 
 already_AddRefed<nsIContent>
 nsXULSliderAccessible::GetSliderNode()
 {
   if (!mDOMNode)
--- a/accessible/src/xul/nsXULSliderAccessible.h
+++ b/accessible/src/xul/nsXULSliderAccessible.h
@@ -58,19 +58,17 @@ public:
   NS_IMETHOD DoAction(PRUint8 aIndex);
 
   // nsIAccessibleValue
   NS_DECL_NSIACCESSIBLEVALUE
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
-
-  // nsPIAccessible
-  NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren);
+  virtual PRBool GetAllowsAnonChildAccessibles();
 
 protected:
   already_AddRefed<nsIContent> GetSliderNode();
 
   nsresult GetSliderAttr(nsIAtom *aName, nsAString& aValue);
   nsresult SetSliderAttr(nsIAtom *aName, const nsAString& aValue);
 
   nsresult GetSliderAttr(nsIAtom *aName, double *aValue);