Bug 541618 - nsINode should be used instead nsIDOMNode by nsAccessNode, r=marcoz, davidb
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 11 Jun 2010 17:23:18 +0900
changeset 43504 117fe7a234ccc906a47189687c8da54d3bd9a071
parent 43503 5df144c4cfdf3818bfd653d00c0c1597d4b7f763
child 43505 431eab8cf6ab75207b201583b6e9552939f54d1d
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
bugs541618
milestone1.9.3a6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 541618 - nsINode should be used instead nsIDOMNode by nsAccessNode, r=marcoz, davidb
accessible/src/atk/nsAccessNodeWrap.cpp
accessible/src/atk/nsAccessNodeWrap.h
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsAccessibleWrap.h
accessible/src/atk/nsDocAccessibleWrap.cpp
accessible/src/atk/nsDocAccessibleWrap.h
accessible/src/atk/nsMaiInterfaceComponent.cpp
accessible/src/atk/nsRootAccessibleWrap.cpp
accessible/src/base/nsARIAGridAccessible.cpp
accessible/src/base/nsARIAGridAccessible.h
accessible/src/base/nsAccDocManager.cpp
accessible/src/base/nsAccEvent.cpp
accessible/src/base/nsAccEvent.h
accessible/src/base/nsAccTreeWalker.cpp
accessible/src/base/nsAccUtils.cpp
accessible/src/base/nsAccUtils.h
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessNode.h
accessible/src/base/nsAccessibilityAtomList.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessibilityService.h
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsAccessible.h
accessible/src/base/nsApplicationAccessible.cpp
accessible/src/base/nsApplicationAccessible.h
accessible/src/base/nsBaseWidgetAccessible.cpp
accessible/src/base/nsBaseWidgetAccessible.h
accessible/src/base/nsCaretAccessible.cpp
accessible/src/base/nsCaretAccessible.h
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsDocAccessible.h
accessible/src/base/nsEventShell.cpp
accessible/src/base/nsEventShell.h
accessible/src/base/nsFormControlAccessible.cpp
accessible/src/base/nsFormControlAccessible.h
accessible/src/base/nsOuterDocAccessible.cpp
accessible/src/base/nsOuterDocAccessible.h
accessible/src/base/nsRootAccessible.cpp
accessible/src/base/nsRootAccessible.h
accessible/src/base/nsTextAccessible.cpp
accessible/src/base/nsTextAccessible.h
accessible/src/base/nsTextAttrs.cpp
accessible/src/base/nsTextAttrs.h
accessible/src/base/nsTextEquivUtils.cpp
accessible/src/base/nsTextEquivUtils.h
accessible/src/html/nsHTMLFormControlAccessible.cpp
accessible/src/html/nsHTMLFormControlAccessible.h
accessible/src/html/nsHTMLImageAccessible.cpp
accessible/src/html/nsHTMLImageAccessible.h
accessible/src/html/nsHTMLImageMapAccessible.cpp
accessible/src/html/nsHTMLImageMapAccessible.h
accessible/src/html/nsHTMLLinkAccessible.cpp
accessible/src/html/nsHTMLLinkAccessible.h
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.h
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.h
accessible/src/html/nsHTMLTextAccessible.cpp
accessible/src/html/nsHTMLTextAccessible.h
accessible/src/html/nsHyperTextAccessible.cpp
accessible/src/html/nsHyperTextAccessible.h
accessible/src/mac/nsAccessNodeWrap.h
accessible/src/mac/nsAccessNodeWrap.mm
accessible/src/mac/nsAccessibleWrap.h
accessible/src/mac/nsAccessibleWrap.mm
accessible/src/mac/nsDocAccessibleWrap.h
accessible/src/mac/nsDocAccessibleWrap.mm
accessible/src/mac/nsRootAccessibleWrap.h
accessible/src/mac/nsRootAccessibleWrap.mm
accessible/src/msaa/nsARIAGridAccessibleWrap.h
accessible/src/msaa/nsAccessNodeWrap.cpp
accessible/src/msaa/nsAccessNodeWrap.h
accessible/src/msaa/nsAccessibleWrap.cpp
accessible/src/msaa/nsAccessibleWrap.h
accessible/src/msaa/nsDocAccessibleWrap.cpp
accessible/src/msaa/nsDocAccessibleWrap.h
accessible/src/msaa/nsHTMLImageAccessibleWrap.h
accessible/src/msaa/nsHTMLTableAccessibleWrap.h
accessible/src/msaa/nsHTMLWin32ObjectAccessible.cpp
accessible/src/msaa/nsHTMLWin32ObjectAccessible.h
accessible/src/msaa/nsHyperTextAccessibleWrap.h
accessible/src/msaa/nsRootAccessibleWrap.cpp
accessible/src/msaa/nsRootAccessibleWrap.h
accessible/src/msaa/nsTextAccessibleWrap.cpp
accessible/src/msaa/nsTextAccessibleWrap.h
accessible/src/msaa/nsXULListboxAccessibleWrap.cpp
accessible/src/msaa/nsXULListboxAccessibleWrap.h
accessible/src/msaa/nsXULMenuAccessibleWrap.cpp
accessible/src/msaa/nsXULMenuAccessibleWrap.h
accessible/src/msaa/nsXULTreeGridAccessibleWrap.cpp
accessible/src/msaa/nsXULTreeGridAccessibleWrap.h
accessible/src/other/nsAccessNodeWrap.cpp
accessible/src/other/nsAccessNodeWrap.h
accessible/src/other/nsAccessibleWrap.cpp
accessible/src/other/nsAccessibleWrap.h
accessible/src/other/nsRootAccessibleWrap.cpp
accessible/src/other/nsRootAccessibleWrap.h
accessible/src/xforms/nsXFormsAccessible.cpp
accessible/src/xforms/nsXFormsAccessible.h
accessible/src/xforms/nsXFormsFormControlsAccessible.cpp
accessible/src/xforms/nsXFormsFormControlsAccessible.h
accessible/src/xforms/nsXFormsWidgetsAccessible.cpp
accessible/src/xforms/nsXFormsWidgetsAccessible.h
accessible/src/xul/nsXULAlertAccessible.cpp
accessible/src/xul/nsXULAlertAccessible.h
accessible/src/xul/nsXULColorPickerAccessible.cpp
accessible/src/xul/nsXULColorPickerAccessible.h
accessible/src/xul/nsXULComboboxAccessible.cpp
accessible/src/xul/nsXULComboboxAccessible.h
accessible/src/xul/nsXULFormControlAccessible.cpp
accessible/src/xul/nsXULFormControlAccessible.h
accessible/src/xul/nsXULListboxAccessible.cpp
accessible/src/xul/nsXULListboxAccessible.h
accessible/src/xul/nsXULMenuAccessible.cpp
accessible/src/xul/nsXULMenuAccessible.h
accessible/src/xul/nsXULSliderAccessible.cpp
accessible/src/xul/nsXULSliderAccessible.h
accessible/src/xul/nsXULTabAccessible.cpp
accessible/src/xul/nsXULTabAccessible.h
accessible/src/xul/nsXULTextAccessible.cpp
accessible/src/xul/nsXULTextAccessible.h
accessible/src/xul/nsXULTreeAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.h
accessible/src/xul/nsXULTreeGridAccessible.cpp
accessible/src/xul/nsXULTreeGridAccessible.h
--- a/accessible/src/atk/nsAccessNodeWrap.cpp
+++ b/accessible/src/atk/nsAccessNodeWrap.cpp
@@ -39,26 +39,27 @@
 #include "nsAccessNodeWrap.h"
 #include "nsApplicationAccessibleWrap.h"
 
 /* For documentation of the accessibility architecture, 
  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
  */
 
 
-/*
- * Class nsAccessNodeWrap
- */
+////////////////////////////////////////////////////////////////////////////////
+// nsAccessNodeWrap
+////////////////////////////////////////////////////////////////////////////////
 
 //-----------------------------------------------------
 // construction 
 //-----------------------------------------------------
 
-nsAccessNodeWrap::nsAccessNodeWrap(nsIDOMNode *aNode, nsIWeakReference* aShell): 
-  nsAccessNode(aNode, aShell)
+nsAccessNodeWrap::
+    nsAccessNodeWrap(nsIContent *aContent, nsIWeakReference *aShell) :
+    nsAccessNode(aContent, aShell)
 {
 }
 
 //-----------------------------------------------------
 // destruction
 //-----------------------------------------------------
 nsAccessNodeWrap::~nsAccessNodeWrap()
 {
--- a/accessible/src/atk/nsAccessNodeWrap.h
+++ b/accessible/src/atk/nsAccessNodeWrap.h
@@ -43,16 +43,16 @@
 #ifndef _nsAccessNodeWrap_H_
 #define _nsAccessNodeWrap_H_
 
 #include "nsAccessNode.h"
 
 class nsAccessNodeWrap :  public nsAccessNode
 {
 public: // construction, destruction
-    nsAccessNodeWrap(nsIDOMNode *aNode, nsIWeakReference* aShell);
+    nsAccessNodeWrap(nsIContent *aContent, nsIWeakReference *aShell);
     virtual ~nsAccessNodeWrap();
 
     static void InitAccessibility();
     static void ShutdownAccessibility();
 };
 
 #endif
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -265,20 +265,19 @@ mai_atk_object_get_type(void)
     return type;
 }
 
 #ifdef MAI_LOGGING
 PRInt32 nsAccessibleWrap::mAccWrapCreated = 0;
 PRInt32 nsAccessibleWrap::mAccWrapDeleted = 0;
 #endif
 
-nsAccessibleWrap::nsAccessibleWrap(nsIDOMNode* aNode,
-                                   nsIWeakReference *aShell)
-    : nsAccessible(aNode, aShell),
-      mAtkObject(nsnull)
+nsAccessibleWrap::
+    nsAccessibleWrap(nsIContent *aContent, nsIWeakReference *aShell) :
+    nsAccessible(aContent, aShell), mAtkObject(nsnull)
 {
 #ifdef MAI_LOGGING
     ++mAccWrapCreated;
 #endif
     MAI_LOG_DEBUG(("==nsAccessibleWrap creating: this=%p,total=%d left=%d\n",
                    (void*)this, mAccWrapCreated,
                   (mAccWrapCreated-mAccWrapDeleted)));
 }
@@ -557,17 +556,17 @@ GetUniqueMaiAtkTypeName(PRUint16 interfa
     MAI_LOG_DEBUG(("MaiWidget::LastedTypeName=%s\n", name));
 
     return name;
 }
 
 PRBool nsAccessibleWrap::IsValidObject()
 {
     // to ensure we are not shut down
-    return (mDOMNode != nsnull);
+    return !IsDefunct();
 }
 
 /* static functions for ATK callbacks */
 void
 classInitCB(AtkObjectClass *aClass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS(aClass);
 
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -80,17 +80,17 @@ class MaiHyperlink;
 
 /**
  * nsAccessibleWrap, and its descendents in atk directory provide the
  * implementation of AtkObject.
  */
 class nsAccessibleWrap: public nsAccessible
 {
 public:
-    nsAccessibleWrap(nsIDOMNode*, nsIWeakReference *aShell);
+    nsAccessibleWrap(nsIContent *aContent, nsIWeakReference *aShell);
     virtual ~nsAccessibleWrap();
     void ShutdownAtkObject();
 
     // nsAccessNode
     virtual nsresult Shutdown();
 
 #ifdef MAI_LOGGING
     virtual void DumpnsAccessibleWrapInfo(int aDepth) {}
--- a/accessible/src/atk/nsDocAccessibleWrap.cpp
+++ b/accessible/src/atk/nsDocAccessibleWrap.cpp
@@ -38,20 +38,23 @@
  * 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 "nsMai.h"
 #include "nsDocAccessibleWrap.h"
 
-//----- nsDocAccessibleWrap -----
+////////////////////////////////////////////////////////////////////////////////
+// nsDocAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
 
-nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode,
-                                         nsIWeakReference *aShell): 
-  nsDocAccessible(aDOMNode, aShell), mActivated(PR_FALSE)
+nsDocAccessibleWrap::
+    nsDocAccessibleWrap(nsIDocument *aDocument, nsIContent *aRootContent,
+                        nsIWeakReference *aShell) :
+    nsDocAccessible(aDocument, aRootContent, aShell), mActivated(PR_FALSE)
 {
 }
 
 nsDocAccessibleWrap::~nsDocAccessibleWrap()
 {
 }
 
--- a/accessible/src/atk/nsDocAccessibleWrap.h
+++ b/accessible/src/atk/nsDocAccessibleWrap.h
@@ -46,15 +46,16 @@
 #ifndef _nsDocAccessibleWrap_H_
 #define _nsDocAccessibleWrap_H_
 
 #include "nsDocAccessible.h"
 
 class nsDocAccessibleWrap: public nsDocAccessible
 {
 public:
-  nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell);
+  nsDocAccessibleWrap(nsIDocument *aDocument, nsIContent *aRootContent,
+                      nsIWeakReference *aShell);
   virtual ~nsDocAccessibleWrap();
 
   PRBool mActivated;
 };
 
 #endif
--- a/accessible/src/atk/nsMaiInterfaceComponent.cpp
+++ b/accessible/src/atk/nsMaiInterfaceComponent.cpp
@@ -73,19 +73,18 @@ refAccessibleAtPointCB(AtkComponent *aCo
                        AtkCoordType aCoordType)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
     if (!accWrap || nsAccUtils::MustPrune(accWrap))
         return nsnull;
 
     // nsIAccessible getChildAtPoint (x,y) is in screen pixels.
     if (aCoordType == ATK_XY_WINDOW) {
-        nsCOMPtr<nsIDOMNode> domNode;
-        accWrap->GetDOMNode(getter_AddRefs(domNode));
-        nsIntPoint winCoords = nsCoreUtils::GetScreenCoordsForWindow(domNode);
+        nsIntPoint winCoords =
+          nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
         aAccX += winCoords.x;
         aAccY += winCoords.y;
     }
 
     nsCOMPtr<nsIAccessible> pointAcc;
     accWrap->GetChildAtPoint(aAccX, aAccY, getter_AddRefs(pointAcc));
     if (!pointAcc) {
         return nsnull;
@@ -114,19 +113,18 @@ getExtentsCB(AtkComponent *aComponent,
 
     PRInt32 nsAccX, nsAccY, nsAccWidth, nsAccHeight;
     // Returned in screen coordinates
     nsresult rv = accWrap->GetBounds(&nsAccX, &nsAccY,
                                      &nsAccWidth, &nsAccHeight);
     if (NS_FAILED(rv))
         return;
     if (aCoordType == ATK_XY_WINDOW) {
-        nsCOMPtr<nsIDOMNode> domNode;
-        accWrap->GetDOMNode(getter_AddRefs(domNode));
-        nsIntPoint winCoords = nsCoreUtils::GetScreenCoordsForWindow(domNode);
+        nsIntPoint winCoords =
+          nsCoreUtils::GetScreenCoordsForWindow(accWrap->GetNode());
         nsAccX -= winCoords.x;
         nsAccY -= winCoords.y;
     }
 
     *aAccX = nsAccX;
     *aAccY = nsAccY;
     *aAccWidth = nsAccWidth;
     *aAccHeight = nsAccHeight;
--- a/accessible/src/atk/nsRootAccessibleWrap.cpp
+++ b/accessible/src/atk/nsRootAccessibleWrap.cpp
@@ -38,17 +38,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMai.h"
 #include "nsRootAccessibleWrap.h"
 
 nsNativeRootAccessibleWrap::nsNativeRootAccessibleWrap(AtkObject *aAccessible):
-    nsRootAccessible(nsnull, nsnull)
+    nsRootAccessible(nsnull, nsnull, nsnull)
 {
     g_object_ref(aAccessible);
     mAtkObject = aAccessible;
 }
 
 nsNativeRootAccessibleWrap::~nsNativeRootAccessibleWrap()
 {
     g_object_unref(mAtkObject);
--- a/accessible/src/base/nsARIAGridAccessible.cpp
+++ b/accessible/src/base/nsARIAGridAccessible.cpp
@@ -46,19 +46,19 @@
 ////////////////////////////////////////////////////////////////////////////////
 // nsARIAGridAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor
 
-nsARIAGridAccessible::nsARIAGridAccessible(nsIDOMNode* aDomNode,
-                                           nsIWeakReference* aShell) :
-  nsAccessibleWrap(aDomNode, aShell)
+nsARIAGridAccessible::
+  nsARIAGridAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsAccessibleWrap(aContent, aShell)
 {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsARIAGridAccessible,
                              nsAccessible,
@@ -751,17 +751,17 @@ nsARIAGridAccessible::GetCellInRowAt(nsA
 
   return cell;
 }
 
 nsresult
 nsARIAGridAccessible::SetARIASelected(nsAccessible *aAccessible,
                                       PRBool aIsSelected, PRBool aNotify)
 {
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aAccessible->GetDOMNode()));
+  nsIContent *content = aAccessible->GetContent();
   NS_ENSURE_STATE(content);
 
   nsresult rv = NS_OK;
   if (aIsSelected)
     rv = content->SetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected,
                           NS_LITERAL_STRING("true"), aNotify);
   else
     rv = content->UnsetAttr(kNameSpaceID_None,
@@ -892,19 +892,19 @@ nsARIAGridAccessible::GetSelectedColumns
 ////////////////////////////////////////////////////////////////////////////////
 // nsARIAGridCellAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor
 
-nsARIAGridCellAccessible::nsARIAGridCellAccessible(nsIDOMNode* aDomNode,
-                                                   nsIWeakReference* aShell) :
-  nsHyperTextAccessibleWrap(aDomNode, aShell)
+nsARIAGridCellAccessible::
+  nsARIAGridCellAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsHyperTextAccessibleWrap(aContent, aShell)
 {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsARIAGridCellAccessible,
                              nsHyperTextAccessible,
--- a/accessible/src/base/nsARIAGridAccessible.h
+++ b/accessible/src/base/nsARIAGridAccessible.h
@@ -45,17 +45,17 @@
 
 /**
  * Accessible for ARIA grid and treegrid.
  */
 class nsARIAGridAccessible : public nsAccessibleWrap,
                              public nsIAccessibleTable
 {
 public:
-  nsARIAGridAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
+  nsARIAGridAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessibleTable
   NS_DECL_NSIACCESSIBLETABLE
 
 protected:
@@ -105,17 +105,17 @@ protected:
 
 /**
  * Accessible for ARIA gridcell and rowheader/columnheader.
  */
 class nsARIAGridCellAccessible : public nsHyperTextAccessibleWrap,
                                  public nsIAccessibleTableCell
 {
 public:
-  nsARIAGridCellAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
+  nsARIAGridCellAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessibleTableCell
   NS_DECL_NSIACCESSIBLETABLECELL
 
   // nsAccessible
--- a/accessible/src/base/nsAccDocManager.cpp
+++ b/accessible/src/base/nsAccDocManager.cpp
@@ -197,18 +197,16 @@ nsAccDocManager::OnStateChange(nsIWebPro
     mDocAccessibleCache.GetWeak(static_cast<void*>(document));
   if (!docAcc)
     return NS_OK;
 
   nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(DOMWindow));
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webNav));
   NS_ENSURE_STATE(docShell);
 
-  nsCOMPtr<nsIDOMNode> DOMNode = do_QueryInterface(document);
-
   // Fire reload and state busy events on existing document accessible while
   // event from user input flag can be calculated properly and accessible
   // is alive. When new document gets loaded then this one is destroyed.
   PRUint32 loadType;
   docShell->GetLoadType(&loadType);
   if (loadType == LOAD_RELOAD_NORMAL ||
       loadType == LOAD_RELOAD_BYPASS_CACHE ||
       loadType == LOAD_RELOAD_BYPASS_PROXY ||
@@ -218,17 +216,17 @@ nsAccDocManager::OnStateChange(nsIWebPro
     nsRefPtr<nsAccEvent> reloadEvent =
       new nsAccEvent(nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD, docAcc);
     nsEventShell::FireEvent(reloadEvent);
   }
 
   // Fire state busy change event. Use delayed event since we don't care
   // actually if event isn't delivered when the document goes away like a shot.
   nsRefPtr<nsAccEvent> stateEvent =
-    new nsAccStateChangeEvent(DOMNode, nsIAccessibleStates::STATE_BUSY,
+    new nsAccStateChangeEvent(document, nsIAccessibleStates::STATE_BUSY,
                               PR_FALSE, PR_TRUE);
   docAcc->FireDelayedAccessibleEvent(stateEvent);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccDocManager::OnProgressChange(nsIWebProgress *aWebProgress,
@@ -352,25 +350,24 @@ nsAccDocManager::HandleDOMDocumentLoad(n
     if (!nsCoreUtils::IsRootDocument(aDocument)) {
       docAcc->InvalidateCacheSubtree(nsnull,
                                      nsIAccessibilityService::NODE_SIGNIFICANT_CHANGE);
     }
     return;
   }
 
   // Fire complete/load stopped if the load event type is given.
-  nsCOMPtr<nsIDOMNode> DOMNode = do_QueryInterface(aDocument);
   if (aLoadEventType) {
-    nsRefPtr<nsAccEvent> loadEvent = new nsAccEvent(aLoadEventType, DOMNode);
+    nsRefPtr<nsAccEvent> loadEvent = new nsAccEvent(aLoadEventType, aDocument);
     docAcc->FireDelayedAccessibleEvent(loadEvent);
   }
 
   // Fire busy state change event.
   nsRefPtr<nsAccEvent> stateEvent =
-    new nsAccStateChangeEvent(DOMNode, nsIAccessibleStates::STATE_BUSY,
+    new nsAccStateChangeEvent(aDocument, nsIAccessibleStates::STATE_BUSY,
                               PR_FALSE, PR_FALSE);
   docAcc->FireDelayedAccessibleEvent(stateEvent);
 }
 
 PRBool
 nsAccDocManager::IsEventTargetDocument(nsIDocument *aDocument) const
 {
   nsCOMPtr<nsISupports> container = aDocument->GetContainer();
@@ -448,52 +445,51 @@ nsAccDocManager::CreateDocOrRootAccessib
 
   // Ignore documents without presshell.
   nsIPresShell *presShell = aDocument->GetPrimaryShell();
   if (!presShell)
     return nsnull;
 
   // Do not create document accessible until role content is loaded, otherwise
   // we get accessible document with wrong role.
-  nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(aDocument));
-  if (!nsCoreUtils::GetRoleContent(DOMNode))
-    return NS_OK;
+  nsIContent *rootElm = nsCoreUtils::GetRoleContent(aDocument);
+  if (!rootElm)
+    return nsnull;
 
   PRBool isRootDoc = nsCoreUtils::IsRootDocument(aDocument);
 
   // Ensure the document container node is accessible, otherwise do not create
   // document accessible.
   nsAccessible *outerDocAcc = nsnull;
   if (!isRootDoc) {
     nsIDocument* parentDoc = aDocument->GetParentDocument();
     if (!parentDoc)
       return nsnull;
 
     nsIContent* ownerContent = parentDoc->FindContentForSubDocument(aDocument);
-    nsCOMPtr<nsIDOMNode> ownerNode(do_QueryInterface(ownerContent));
-    if (!ownerNode)
+    if (!ownerContent)
       return nsnull;
 
     // XXXaaronl: ideally we would traverse the presshell chain. Since there's
     // no easy way to do that, we cheat and use the document hierarchy.
     // GetAccessible() is bad because it doesn't support our concept of multiple
     // presshells per doc. It should be changed to use
     // GetAccessibleInWeakShell().
-    outerDocAcc = GetAccService()->GetAccessible(ownerNode);
+    outerDocAcc = GetAccService()->GetAccessible(ownerContent);
     if (!outerDocAcc)
       return nsnull;
   }
 
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
 
   // We only create root accessibles for the true root, otherwise create a
   // doc accessible.
   nsDocAccessible *docAcc = isRootDoc ?
-    new nsRootAccessibleWrap(DOMNode, weakShell) :
-    new nsDocAccessibleWrap(DOMNode, weakShell);
+    new nsRootAccessibleWrap(aDocument, rootElm, weakShell) :
+    new nsDocAccessibleWrap(aDocument, rootElm, weakShell);
 
   if (!docAcc)
     return nsnull;
 
   // Cache and addref document accessible.
   if (!mDocAccessibleCache.Put(static_cast<void*>(aDocument), docAcc)) {
     delete docAcc;
     return nsnull;
@@ -504,17 +500,17 @@ nsAccDocManager::CreateDocOrRootAccessib
   if (outerDocAcc) {
     // Root document accessible doesn't have associated outerdoc accessible, it
     // adds itself to application accessible instead.
     NS_LOG_ACCDOCCREATE("append document to outerdoc", aDocument)
     outerDocAcc->AppendChild(docAcc);
   }
 
   if (!GetAccService()->InitAccessible(docAcc,
-                                       nsAccUtils::GetRoleMapEntry(DOMNode))) {
+                                       nsAccUtils::GetRoleMapEntry(aDocument))) {
     mDocAccessibleCache.Remove(static_cast<void*>(aDocument));
     return nsnull;
   }
 
   NS_LOG_ACCDOCCREATE("document created", aDocument)
 
   AddListeners(aDocument, isRootDoc);
   return docAcc;
--- a/accessible/src/base/nsAccEvent.cpp
+++ b/accessible/src/base/nsAccEvent.cpp
@@ -83,21 +83,21 @@ nsAccEvent::nsAccEvent(PRUint32 aEventTy
                        PRBool aIsAsync, EIsFromUserInput aIsFromUserInput,
                        EEventRule aEventRule) :
   mEventType(aEventType), mEventRule(aEventRule), mIsAsync(aIsAsync),
   mAccessible(aAccessible)
 {
   CaptureIsFromUserInput(aIsFromUserInput);
 }
 
-nsAccEvent::nsAccEvent(PRUint32 aEventType, nsIDOMNode *aDOMNode,
+nsAccEvent::nsAccEvent(PRUint32 aEventType, nsINode *aNode,
                        PRBool aIsAsync, EIsFromUserInput aIsFromUserInput,
                        EEventRule aEventRule) :
   mEventType(aEventType), mEventRule(aEventRule), mIsAsync(aIsAsync),
-  mNode(do_QueryInterface(aDOMNode))
+  mNode(aNode)
 {
   CaptureIsFromUserInput(aIsFromUserInput);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccEvent: nsIAccessibleEvent
 
 NS_IMETHODIMP
@@ -123,17 +123,17 @@ nsAccEvent::GetEventType(PRUint32 *aEven
 
 NS_IMETHODIMP
 nsAccEvent::GetAccessible(nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
   if (!mAccessible)
-    mAccessible = GetAccessibleByNode();
+    mAccessible = GetAccessibleForNode();
 
   NS_IF_ADDREF(*aAccessible = mAccessible);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccEvent::GetDOMNode(nsIDOMNode **aDOMNode)
 {
@@ -160,24 +160,19 @@ nsAccEvent::GetAccessibleDocument(nsIAcc
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccEvent: public methods
 
 nsINode*
 nsAccEvent::GetNode()
 {
   if (!mNode) {
-    nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(mAccessible));
-    if (!accessNode)
-      return nsnull;
-
-    nsCOMPtr<nsIDOMNode> DOMNode;
-    accessNode->GetDOMNode(getter_AddRefs(DOMNode));
-
-    mNode = do_QueryInterface(DOMNode);
+    nsRefPtr<nsAccessNode> accessNode(do_QueryObject(mAccessible));
+    if (accessNode)
+      mNode = accessNode->GetNode();
   }
 
   return mNode;
 }
 
 nsDocAccessible*
 nsAccEvent::GetDocAccessible()
 {
@@ -186,26 +181,23 @@ nsAccEvent::GetDocAccessible()
     return GetAccService()->GetDocAccessible(node->GetOwnerDoc());
 
   return nsnull;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccEvent: protected methods
 
-already_AddRefed<nsIAccessible>
-nsAccEvent::GetAccessibleByNode()
+nsAccessible *
+nsAccEvent::GetAccessibleForNode() const
 {
   if (!mNode)
     return nsnull;
 
-  nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mNode));
-
-  nsCOMPtr<nsIAccessible> accessible;
-  GetAccService()->GetAccessibleFor(DOMNode, getter_AddRefs(accessible));
+  nsAccessible *accessible = GetAccService()->GetAccessible(mNode);
 
 #ifdef MOZ_XUL
   // hack for xul tree table. We need a better way for firing delayed event
   // against xul tree table. see bug 386821.
   // There will be problem if some day we want to fire delayed event against
   // the xul tree itself or an unselected treeitem.
   nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
   if (content && content->NodeInfo()->Equals(nsAccessibilityAtoms::tree,
@@ -215,30 +207,29 @@ nsAccEvent::GetAccessibleByNode()
       do_QueryInterface(mNode);
 
     if (multiSelect) {
       PRInt32 treeIndex = -1;
       multiSelect->GetCurrentIndex(&treeIndex);
       if (treeIndex >= 0) {
         nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(accessible);
         if (treeAcc)
-          accessible = treeAcc->GetTreeItemAccessible(treeIndex);
+          return treeAcc->GetTreeItemAccessible(treeIndex);
       }
     }
   }
 #endif
 
-  return accessible.forget();
+  return accessible;
 }
 
 void
 nsAccEvent::CaptureIsFromUserInput(EIsFromUserInput aIsFromUserInput)
 {
-  nsCOMPtr<nsIDOMNode> targetNode;
-  GetDOMNode(getter_AddRefs(targetNode));
+  nsINode *targetNode = GetNode();
 
 #ifdef DEBUG
   if (!targetNode) {
     // XXX: remove this hack during reorganization of 506907. Meanwhile we
     // want to get rid an assertion for application accessible events which
     // don't have DOM node (see bug 506206).
     nsApplicationAccessible *applicationAcc =
       nsAccessNode::GetApplicationAccessible();
@@ -277,17 +268,17 @@ nsAccEvent::CaptureIsFromUserInput(EIsFr
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsAccReorderEvent, nsAccEvent,
                              nsAccReorderEvent)
 
 nsAccReorderEvent::nsAccReorderEvent(nsIAccessible *aAccTarget,
                                      PRBool aIsAsynch,
                                      PRBool aIsUnconditional,
-                                     nsIDOMNode *aReasonNode) :
+                                     nsINode *aReasonNode) :
   nsAccEvent(::nsIAccessibleEvent::EVENT_REORDER, aAccTarget,
              aIsAsynch, eAutoDetect, nsAccEvent::eCoalesceFromSameSubtree),
   mUnconditionalEvent(aIsUnconditional), mReasonNode(aReasonNode)
 {
 }
 
 PRBool
 nsAccReorderEvent::IsUnconditionalEvent()
@@ -296,19 +287,17 @@ nsAccReorderEvent::IsUnconditionalEvent(
 }
 
 PRBool
 nsAccReorderEvent::HasAccessibleInReasonSubtree()
 {
   if (!mReasonNode)
     return PR_FALSE;
 
-  nsCOMPtr<nsIAccessible> accessible;
-  GetAccService()->GetAccessibleFor(mReasonNode, getter_AddRefs(accessible));
-
+  nsAccessible *accessible = GetAccService()->GetAccessible(mReasonNode);
   return accessible || nsAccUtils::HasAccessibleChildren(mReasonNode);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccStateChangeEvent
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsAccStateChangeEvent, nsAccEvent,
@@ -324,34 +313,32 @@ nsAccStateChangeEvent::
                         EIsFromUserInput aIsFromUserInput):
   nsAccEvent(nsIAccessibleEvent::EVENT_STATE_CHANGE, aAccessible, aIsAsynch,
              aIsFromUserInput, eAllowDupes),
   mState(aState), mIsExtraState(aIsExtraState), mIsEnabled(aIsEnabled)
 {
 }
 
 nsAccStateChangeEvent::
-  nsAccStateChangeEvent(nsIDOMNode *aNode,
-                        PRUint32 aState, PRBool aIsExtraState,
+  nsAccStateChangeEvent(nsINode *aNode, PRUint32 aState, PRBool aIsExtraState,
                         PRBool aIsEnabled):
   nsAccEvent(::nsIAccessibleEvent::EVENT_STATE_CHANGE, aNode),
   mState(aState), mIsExtraState(aIsExtraState), mIsEnabled(aIsEnabled)
 {
 }
 
 nsAccStateChangeEvent::
-  nsAccStateChangeEvent(nsIDOMNode *aNode,
-                        PRUint32 aState, PRBool aIsExtraState):
+  nsAccStateChangeEvent(nsINode *aNode, PRUint32 aState, PRBool aIsExtraState) :
   nsAccEvent(::nsIAccessibleEvent::EVENT_STATE_CHANGE, aNode),
   mState(aState), mIsExtraState(aIsExtraState)
 {
-  // Use GetAccessibleByNode() because we do not want to store an accessible
+  // Use GetAccessibleForNode() because we do not want to store an accessible
   // since it leads to problems with delayed events in the case when
   // an accessible gets reorder event before delayed event is processed.
-  nsCOMPtr<nsIAccessible> accessible(GetAccessibleByNode());
+  nsAccessible *accessible = GetAccessibleForNode();
   if (accessible) {
     PRUint32 state = 0, extraState = 0;
     accessible->GetState(&state, mIsExtraState ? &extraState : nsnull);
     mIsEnabled = ((mIsExtraState ? extraState : state) & mState) != 0;
   } else {
     mIsEnabled = PR_FALSE;
   }
 }
@@ -442,17 +429,17 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsAccCaretM
 nsAccCaretMoveEvent::
   nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset) :
   nsAccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aAccessible, PR_TRUE), // Currently always asynch
   mCaretOffset(aCaretOffset)
 {
 }
 
 nsAccCaretMoveEvent::
-  nsAccCaretMoveEvent(nsIDOMNode *aNode) :
+  nsAccCaretMoveEvent(nsINode *aNode) :
   nsAccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aNode, PR_TRUE), // Currently always asynch
   mCaretOffset(-1)
 {
 }
 
 NS_IMETHODIMP
 nsAccCaretMoveEvent::GetCaretOffset(PRInt32* aCaretOffset)
 {
--- a/accessible/src/base/nsAccEvent.h
+++ b/accessible/src/base/nsAccEvent.h
@@ -46,16 +46,17 @@
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsString.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsINode.h"
 #include "nsIDOMNode.h"
 
+class nsAccessible;
 class nsDocAccessible;
 
 // Constants used to point whether the event is from user input.
 enum EIsFromUserInput
 {
   // eNoUserInput: event is not from user input
   eNoUserInput = 0,
   // eFromUserInput: event is from user input
@@ -103,18 +104,17 @@ public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCEVENT_IMPL_CID)
 
   // Initialize with an nsIAccessible
   nsAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
              PRBool aIsAsynch = PR_FALSE,
              EIsFromUserInput aIsFromUserInput = eAutoDetect,
              EEventRule aEventRule = eRemoveDupes);
   // Initialize with an nsIDOMNode
-  nsAccEvent(PRUint32 aEventType, nsIDOMNode *aDOMNode,
-             PRBool aIsAsynch = PR_FALSE,
+  nsAccEvent(PRUint32 aEventType, nsINode *aNode, PRBool aIsAsynch = PR_FALSE,
              EIsFromUserInput aIsFromUserInput = eAutoDetect,
              EEventRule aEventRule = eRemoveDupes);
   virtual ~nsAccEvent() {}
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsAccEvent)
 
   NS_DECL_NSIACCESSIBLEEVENT
@@ -128,17 +128,17 @@ public:
 
   nsINode* GetNode();
   nsDocAccessible* GetDocAccessible();
 
 protected:
   /**
    * Get an accessible from event target node.
    */
-  already_AddRefed<nsIAccessible> GetAccessibleByNode();
+  nsAccessible *GetAccessibleForNode() const;
 
   /**
    * Determine whether the event is from user input by event state manager if
    * it's not pointed explicetly.
    */
   void CaptureIsFromUserInput(EIsFromUserInput aIsFromUserInput);
 
   PRBool mIsFromUserInput;
@@ -163,17 +163,17 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsAccEvent
   { 0x86, 0x8c, 0x39, 0x12, 0xb1, 0x5b, 0x76, 0x7a }    \
 }
 
 class nsAccReorderEvent : public nsAccEvent
 {
 public:
 
   nsAccReorderEvent(nsIAccessible *aAccTarget, PRBool aIsAsynch,
-                    PRBool aIsUnconditional, nsIDOMNode *aReasonNode);
+                    PRBool aIsUnconditional, nsINode *aReasonNode);
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCREORDEREVENT_IMPL_CID)
 
   NS_DECL_ISUPPORTS_INHERITED
 
   /**
    * Return true if event is unconditional, i.e. must be fired.
    */
@@ -181,37 +181,35 @@ public:
 
   /**
    * Return true if changed DOM node has accessible in its tree.
    */
   PRBool HasAccessibleInReasonSubtree();
 
 private:
   PRBool mUnconditionalEvent;
-  nsCOMPtr<nsIDOMNode> mReasonNode;
+  nsCOMPtr<nsINode> mReasonNode;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsAccReorderEvent, NS_ACCREORDEREVENT_IMPL_CID)
 
 
 class nsAccStateChangeEvent: public nsAccEvent,
                              public nsIAccessibleStateChangeEvent
 {
 public:
   nsAccStateChangeEvent(nsIAccessible *aAccessible,
                         PRUint32 aState, PRBool aIsExtraState,
                         PRBool aIsEnabled, PRBool aIsAsynch = PR_FALSE,
                         EIsFromUserInput aIsFromUserInput = eAutoDetect);
 
-  nsAccStateChangeEvent(nsIDOMNode *aNode,
-                        PRUint32 aState, PRBool aIsExtraState,
+  nsAccStateChangeEvent(nsINode *aNode, PRUint32 aState, PRBool aIsExtraState,
                         PRBool aIsEnabled);
 
-  nsAccStateChangeEvent(nsIDOMNode *aNode,
-                        PRUint32 aState, PRBool aIsExtraState);
+  nsAccStateChangeEvent(nsINode *aNode, PRUint32 aState, PRBool aIsExtraState);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLESTATECHANGEEVENT
 
 private:
   PRUint32 mState;
   PRBool mIsExtraState;
   PRBool mIsEnabled;
@@ -236,17 +234,17 @@ private:
   nsString mModifiedText;
 };
 
 class nsAccCaretMoveEvent: public nsAccEvent,
                            public nsIAccessibleCaretMoveEvent
 {
 public:
   nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset);
-  nsAccCaretMoveEvent(nsIDOMNode *aNode);
+  nsAccCaretMoveEvent(nsINode *aNode);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLECARETMOVEEVENT
 
 private:
   PRInt32 mCaretOffset;
 };
 
--- a/accessible/src/base/nsAccTreeWalker.cpp
+++ b/accessible/src/base/nsAccTreeWalker.cpp
@@ -107,19 +107,18 @@ nsAccTreeWalker::GetNextChildInternal(PR
   if (mState->childList)
     mState->childList->GetLength(&length);
 
   while (mState->childIdx < length) {
     nsIContent* childNode = mState->childList->GetNodeAt(mState->childIdx);
     mState->childIdx++;
 
     PRBool isHidden = PR_FALSE;
-    nsCOMPtr<nsIDOMNode> childDOMNode(do_QueryInterface(childNode));
     nsRefPtr<nsAccessible> accessible =
-      GetAccService()->GetAccessible(childDOMNode, presShell, mWeakShell,
+      GetAccService()->GetAccessible(childNode, presShell, mWeakShell,
                                      &isHidden);
 
     if (accessible)
       return accessible.forget();
 
     // Walk down into subtree to find accessibles.
     if (!isHidden) {
       if (!PushState(childNode))
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -136,21 +136,21 @@ nsAccUtils::GetARIAOrDefaultLevel(nsIAcc
 
   if (level != 0)
     return level;
 
   return GetDefaultLevel(acc);
 }
 
 void
-nsAccUtils::GetPositionAndSizeForXULSelectControlItem(nsIDOMNode *aNode,
+nsAccUtils::GetPositionAndSizeForXULSelectControlItem(nsIContent *aContent,
                                                       PRInt32 *aPosInSet,
                                                       PRInt32 *aSetSize)
 {
-  nsCOMPtr<nsIDOMXULSelectControlItemElement> item(do_QueryInterface(aNode));
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> item(do_QueryInterface(aContent));
   if (!item)
     return;
 
   nsCOMPtr<nsIDOMXULSelectControlElement> control;
   item->GetControl(getter_AddRefs(control));
   if (!control)
     return;
 
@@ -177,21 +177,21 @@ nsAccUtils::GetPositionAndSizeForXULSele
         (*aPosInSet)--;
     }
   }
 
   (*aPosInSet)++; // group position is 1-index based.
 }
 
 void
-nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIDOMNode *aNode,
+nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIContent *aContent,
                                                   PRInt32 *aPosInSet,
                                                   PRInt32 *aSetSize)
 {
-  nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aNode));
+  nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
   if (!item)
     return;
 
   nsCOMPtr<nsIDOMXULContainerElement> container;
   item->GetParentContainer(getter_AddRefs(container));
   if (!container)
     return;
 
@@ -241,19 +241,19 @@ nsAccUtils::GetPositionAndSizeForXULCont
       PRUint32 itemState = State(itemAcc);
       if (!(itemState & nsIAccessibleStates::STATE_INVISIBLE))
         (*aSetSize)++;
     }
   }
 }
 
 PRInt32
-nsAccUtils::GetLevelForXULContainerItem(nsIDOMNode *aNode)
+nsAccUtils::GetLevelForXULContainerItem(nsIContent *aContent)
 {
-  nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aNode));
+  nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
   if (!item)
     return 0;
 
   nsCOMPtr<nsIDOMXULContainerElement> container;
   item->GetParentContainer(getter_AddRefs(container));
   if (!container)
     return 0;
 
@@ -282,18 +282,17 @@ nsAccUtils::SetLiveContainerAttributes(n
     // container-relevant attribute
     if (relevant.IsEmpty() &&
         nsAccUtils::HasDefinedARIAToken(ancestor, nsAccessibilityAtoms::aria_relevant) &&
         ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_relevant, relevant))
       SetAccAttr(aAttributes, nsAccessibilityAtoms::containerRelevant, relevant);
 
     // container-live, and container-live-role attributes
     if (live.IsEmpty()) {
-      nsCOMPtr<nsIDOMNode> node(do_QueryInterface(ancestor));
-      nsRoleMapEntry *role = GetRoleMapEntry(node);
+      nsRoleMapEntry *role = GetRoleMapEntry(ancestor);
       if (nsAccUtils::HasDefinedARIAToken(ancestor,
                                           nsAccessibilityAtoms::aria_live)) {
         ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_live,
                           live);
       } else if (role) {
         GetLiveAttrValue(role->liveAttRule, live);
       }
       if (!live.IsEmpty()) {
@@ -338,56 +337,44 @@ nsAccUtils::HasDefinedARIAToken(nsIConte
       aContent->AttrValueIs(kNameSpaceID_None, aAtom,
                             nsAccessibilityAtoms::_undefined, eCaseMatters)) {
         return PR_FALSE;
   }
   return PR_TRUE;
 }
 
 PRBool
-nsAccUtils::HasAccessibleChildren(nsIDOMNode *aNode)
+nsAccUtils::HasAccessibleChildren(nsINode *aNode)
 {
   if (!aNode)
     return PR_FALSE;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
-  if (!content)
-    return PR_FALSE;
-
   nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
   if (!presShell)
     return PR_FALSE;
 
-  nsIFrame *frame = content->GetPrimaryFrame();
-  if (!frame)
-    return PR_FALSE;
-
+  nsIContent *content = nsCoreUtils::GetRoleContent(aNode);
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
   nsAccTreeWalker walker(weakShell, content, PR_FALSE);
   nsRefPtr<nsAccessible> accessible = walker.GetNextChild();
   return accessible ? PR_TRUE : PR_FALSE;
 }
 
-already_AddRefed<nsIAccessible>
-nsAccUtils::GetAncestorWithRole(nsIAccessible *aDescendant, PRUint32 aRole)
+nsAccessible *
+nsAccUtils::GetAncestorWithRole(nsAccessible *aDescendant, PRUint32 aRole)
 {
-  nsCOMPtr<nsIAccessible> parentAccessible = aDescendant, testRoleAccessible;
-  while (NS_SUCCEEDED(parentAccessible->GetParent(getter_AddRefs(testRoleAccessible))) &&
-         testRoleAccessible) {
-    PRUint32 testRole = nsAccUtils::Role(testRoleAccessible);
-    if (testRole == aRole) {
-      nsIAccessible *returnAccessible = testRoleAccessible;
-      NS_ADDREF(returnAccessible);
-      return returnAccessible;
-    }
-    nsCOMPtr<nsIAccessibleDocument> docAccessible = do_QueryInterface(testRoleAccessible);
-    if (docAccessible) {
+  nsAccessible *document = aDescendant->GetDocAccessible();
+  nsAccessible *parent = aDescendant;
+  while ((parent = parent->GetParent())) {
+    PRUint32 testRole = nsAccUtils::Role(parent);
+    if (testRole == aRole)
+      return parent;
+
+    if (parent == document)
       break;
-    }
-    parentAccessible.swap(testRoleAccessible);
   }
   return nsnull;
 }
 
 void
 nsAccUtils::GetARIATreeItemParent(nsIAccessible *aStartTreeItem,
                                   nsIContent *aStartContent,
                                   nsIAccessible **aTreeItemParentResult)
@@ -482,52 +469,47 @@ nsAccUtils::GetARIATreeItemParent(nsIAcc
     role = nsAccUtils::Role(prevAccessible);
   }
   if (role == nsIAccessibleRole::ROLE_OUTLINEITEM) {
     // Previous sibling of parent group is a tree item -- this is the conceptual tree item parent
     NS_ADDREF(*aTreeItemParentResult = prevAccessible);
   }
 }
 
-already_AddRefed<nsIAccessible>
-nsAccUtils::GetSelectableContainer(nsIAccessible *aAccessible, PRUint32 aState)
+nsAccessible *
+nsAccUtils::GetSelectableContainer(nsAccessible *aAccessible, PRUint32 aState)
 {
   if (!aAccessible)
     return nsnull;
 
   if (!(aState & nsIAccessibleStates::STATE_SELECTABLE))
     return nsnull;
 
   nsCOMPtr<nsIAccessibleSelectable> container;
-  nsCOMPtr<nsIAccessible> parent, accessible(aAccessible);
+  nsAccessible *parent = aAccessible;
   while (!container) {
-    accessible->GetParent(getter_AddRefs(parent));
-
+    parent = parent->GetParent();
     if (!parent || Role(parent) == nsIAccessibleRole::ROLE_PANE)
       return nsnull;
 
-    container = do_QueryInterface(parent);
-    parent.swap(accessible);
+    container = do_QueryObject(parent);
   }
 
-  return accessible.forget();
+  return parent;
 }
 
-already_AddRefed<nsIAccessible>
-nsAccUtils::GetMultiSelectableContainer(nsIDOMNode *aNode)
+nsAccessible *
+nsAccUtils::GetMultiSelectableContainer(nsINode *aNode)
 {
-  nsCOMPtr<nsIAccessible> accessible;
-  GetAccService()->GetAccessibleFor(aNode, getter_AddRefs(accessible));
-
-  nsCOMPtr<nsIAccessible> container =
-    GetSelectableContainer(accessible, State(accessible));
+  nsAccessible *accessible = GetAccService()->GetAccessible(aNode);
+  nsAccessible *container = GetSelectableContainer(accessible,
+                                                   State(accessible));
 
   if (State(container) & nsIAccessibleStates::STATE_MULTISELECTABLE)
-    return container.forget();
-
+    return container;
   return nsnull;
 }
 
 PRBool
 nsAccUtils::IsARIASelected(nsIAccessible *aAccessible)
 {
   nsRefPtr<nsAccessible> acc = do_QueryObject(aAccessible);
   nsCOMPtr<nsIDOMNode> node;
@@ -542,17 +524,17 @@ nsAccUtils::IsARIASelected(nsIAccessible
       return PR_TRUE;
   }
 
   return PR_FALSE;
 }
 
 already_AddRefed<nsIAccessibleText>
 nsAccUtils::GetTextAccessibleFromSelection(nsISelection *aSelection,
-                                           nsIDOMNode **aNode)
+                                           nsINode **aNode)
 {
   // Get accessible from selection's focus DOM point (the DOM point where
   // selection is ended).
 
   nsCOMPtr<nsIDOMNode> focusDOMNode;
   aSelection->GetFocusNode(getter_AddRefs(focusDOMNode));
   if (!focusDOMNode)
     return nsnull;
@@ -563,51 +545,43 @@ nsAccUtils::GetTextAccessibleFromSelecti
   nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDOMNode));
   nsCOMPtr<nsINode> resultNode =
     nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
 
   // Get text accessible containing the result node.
   while (resultNode) {
     // Make sure to get the correct starting node for selection events inside
     // XBL content trees.
-    nsCOMPtr<nsIDOMNode> resultDOMNode(do_QueryInterface(resultNode));
-    nsCOMPtr<nsIDOMNode> relevantDOMNode;
-    GetAccService()->GetRelevantContentNodeFor(resultDOMNode,
-                                               getter_AddRefs(relevantDOMNode));
-    if (relevantDOMNode) {
-      resultNode = do_QueryInterface(relevantDOMNode);
-      resultDOMNode.swap(relevantDOMNode);
-    }
-
-    if (!resultNode || !resultNode->IsNodeOfType(nsINode::eTEXT)) {
-      nsAccessible *accessible = GetAccService()->GetAccessible(resultDOMNode);
+    resultNode = GetAccService()->GetRelevantContentNodeFor(resultNode);
+    if (!resultNode->IsNodeOfType(nsINode::eTEXT)) {
+      nsAccessible *accessible = GetAccService()->GetAccessible(resultNode);
       if (accessible) {
         nsIAccessibleText *textAcc = nsnull;
         CallQueryInterface(accessible, &textAcc);
         if (textAcc) {
           if (aNode)
-            resultDOMNode.forget(aNode);
+            NS_ADDREF(*aNode = resultNode);
 
           return textAcc;
         }
       }
     }
 
-    resultNode = resultNode->GetParent();
+    resultNode = resultNode->GetNodeParent();
   }
 
   NS_NOTREACHED("No nsIAccessibleText for selection change event!");
 
   return nsnull;
 }
 
 nsresult
 nsAccUtils::ConvertToScreenCoords(PRInt32 aX, PRInt32 aY,
                                   PRUint32 aCoordinateType,
-                                  nsIAccessNode *aAccessNode,
+                                  nsAccessNode *aAccessNode,
                                   nsIntPoint *aCoords)
 {
   NS_ENSURE_ARG_POINTER(aCoords);
 
   aCoords->MoveTo(aX, aY);
 
   switch (aCoordinateType) {
     case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
@@ -632,17 +606,17 @@ nsAccUtils::ConvertToScreenCoords(PRInt3
   }
 
   return NS_OK;
 }
 
 nsresult
 nsAccUtils::ConvertScreenCoordsTo(PRInt32 *aX, PRInt32 *aY,
                                   PRUint32 aCoordinateType,
-                                  nsIAccessNode *aAccessNode)
+                                  nsAccessNode *aAccessNode)
 {
   switch (aCoordinateType) {
     case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
       break;
 
     case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
     {
       NS_ENSURE_ARG(aAccessNode);
@@ -664,35 +638,28 @@ nsAccUtils::ConvertScreenCoordsTo(PRInt3
     default:
       return NS_ERROR_INVALID_ARG;
   }
 
   return NS_OK;
 }
 
 nsIntPoint
-nsAccUtils::GetScreenCoordsForWindow(nsIAccessNode *aAccessNode)
+nsAccUtils::GetScreenCoordsForWindow(nsAccessNode *aAccessNode)
 {
-  nsCOMPtr<nsIDOMNode> DOMNode;
-  aAccessNode->GetDOMNode(getter_AddRefs(DOMNode));
-  if (DOMNode)
-    return nsCoreUtils::GetScreenCoordsForWindow(DOMNode);
-
-  return nsIntPoint(0, 0);
+  return nsCoreUtils::GetScreenCoordsForWindow(aAccessNode->GetNode());
 }
 
 nsIntPoint
-nsAccUtils::GetScreenCoordsForParent(nsIAccessNode *aAccessNode)
+nsAccUtils::GetScreenCoordsForParent(nsAccessNode *aAccessNode)
 {
   nsRefPtr<nsAccessNode> parent;
-  nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(aAccessNode));
+  nsRefPtr<nsAccessible> accessible(do_QueryObject(aAccessNode));
   if (accessible) {
-    nsCOMPtr<nsIAccessible> parentAccessible;
-    accessible->GetParent(getter_AddRefs(parentAccessible));
-    parent = do_QueryObject(parentAccessible);
+    parent = do_QueryObject(accessible->GetParent());
   } else {
     nsCOMPtr<nsIAccessNode> parentAccessNode;
     aAccessNode->GetParentNode(getter_AddRefs(parentAccessNode));
     parent = do_QueryObject(parentAccessNode);
   }
 
   if (!parent)
     return nsIntPoint(0, 0);
@@ -701,17 +668,17 @@ nsAccUtils::GetScreenCoordsForParent(nsI
   if (!parentFrame)
     return nsIntPoint(0, 0);
 
   nsIntRect parentRect = parentFrame->GetScreenRectExternal();
   return nsIntPoint(parentRect.x, parentRect.y);
 }
 
 nsRoleMapEntry*
-nsAccUtils::GetRoleMapEntry(nsIDOMNode *aNode)
+nsAccUtils::GetRoleMapEntry(nsINode *aNode)
 {
   nsIContent *content = nsCoreUtils::GetRoleContent(aNode);
   nsAutoString roleString;
   if (!content ||
       !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, roleString) ||
       roleString.IsEmpty()) {
     // We treat role="" as if the role attribute is absent (per aria spec:8.1.1)
     return nsnull;
@@ -870,21 +837,19 @@ nsAccUtils::MustPrune(nsIAccessible *aAc
     role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
     role == nsIAccessibleRole::ROLE_GRAPHIC ||
     role == nsIAccessibleRole::ROLE_SLIDER ||
     role == nsIAccessibleRole::ROLE_PROGRESSBAR ||
     role == nsIAccessibleRole::ROLE_SEPARATOR;
 }
 
 PRBool
-nsAccUtils::IsNodeRelevant(nsIDOMNode *aNode)
+nsAccUtils::IsNodeRelevant(nsINode *aNode)
 {
-  nsCOMPtr<nsIDOMNode> relevantNode;
-  GetAccService()->GetRelevantContentNodeFor(aNode, getter_AddRefs(relevantNode));
-  return aNode == relevantNode;
+  return aNode == GetAccService()->GetRelevantContentNodeFor(aNode);
 }
 
 nsresult
 nsAccUtils::GetHeaderCellsFor(nsIAccessibleTable *aTable,
                               nsIAccessibleTableCell *aCell,
                               PRInt32 aRowOrColHeaderCells, nsIArray **aCells)
 {
   nsresult rv = NS_OK;
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -107,32 +107,32 @@ public:
    * given accessible.
    */
   static PRInt32 GetARIAOrDefaultLevel(nsIAccessible *aAcc);
 
   /**
    * Compute position in group (posinset) and group size (setsize) for
    * nsIDOMXULSelectControlItemElement node.
    */
-  static void GetPositionAndSizeForXULSelectControlItem(nsIDOMNode *aNode,
+  static void GetPositionAndSizeForXULSelectControlItem(nsIContent *aContent,
                                                         PRInt32 *aPosInSet,
                                                         PRInt32 *aSetSize);
 
   /**
    * Compute group position and group size (posinset and setsize) for
    * nsIDOMXULContainerItemElement node.
    */
-  static void GetPositionAndSizeForXULContainerItem(nsIDOMNode *aNode,
+  static void GetPositionAndSizeForXULContainerItem(nsIContent *aContent,
                                                     PRInt32 *aPosInSet,
                                                     PRInt32 *aSetSize);
 
   /**
    * Compute group level for nsIDOMXULContainerItemElement node.
    */
-  static PRInt32 GetLevelForXULContainerItem(nsIDOMNode *aNode);
+  static PRInt32 GetLevelForXULContainerItem(nsIContent *aContent);
 
   /**
    * Set container-foo live region attributes for the given node.
    *
    * @param aAttributes    where to store the attributes
    * @param aStartContent  node to start from
    * @param aTopContent    node to end at
    */
@@ -157,17 +157,17 @@ public:
     nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(aWeakShell));
     return presShell ?
       GetAccService()->GetDocAccessible(presShell->GetDocument()) : nsnull;
   }
 
   /**
    * Return document accessible for the given DOM node.
    */
-  static nsDocAccessible *GetDocAccessibleFor(nsIDOMNode *aNode)
+  static nsDocAccessible *GetDocAccessibleFor(nsINode *aNode)
   {
     nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
     return presShell ?
       GetAccService()->GetDocAccessible(presShell->GetDocument()) : nsnull;
   }
 
   /**
    * Return document accessible for the given docshell.
@@ -179,26 +179,28 @@ public:
     docShell->GetPresShell(getter_AddRefs(presShell));
     return presShell ?
       GetAccService()->GetDocAccessible(presShell->GetDocument()) : nsnull;
   }
 
   /**
    * Return true if the given DOM node contains accessible children.
    */
-  static PRBool HasAccessibleChildren(nsIDOMNode *aNode);
+  static PRBool HasAccessibleChildren(nsINode *aNode);
 
   /**
-    * If an ancestor in this document exists with the given role, return it
-    * @param aDescendant Descendant to start search with
-    * @param aRole Role to find matching ancestor for
-    * @return The ancestor accessible with the given role, or nsnull if no match is found
+    * Return ancestor in this document with the given role if it exists.
+    *
+    * @param  aDescendant  [in] descendant to start search with
+    * @param  aRole        [in] role to find matching ancestor for
+    * @return               the ancestor accessible with the given role, or
+    *                       nsnull if no match is found
     */
-   static already_AddRefed<nsIAccessible>
-     GetAncestorWithRole(nsIAccessible *aDescendant, PRUint32 aRole);
+   static nsAccessible * GetAncestorWithRole(nsAccessible *aDescendant,
+                                             PRUint32 aRole);
 
    /**
      * For an ARIA tree item , get the accessible that represents its conceptual parent.
      * This method will use the correct method for the given way the tree is constructed.
      * The conceptual parent is what the user sees as the parent, not the DOM or accessible parent.
      * @param aStartTreeItem  The tree item to get the parent for
      * @param aStartTreeItemContent  The content node for the tree item
      * @param The tree item's parent, or null if none
@@ -209,24 +211,23 @@ public:
                            nsIAccessible **aTreeItemParent);
 
   /**
    * Return single or multi selectable container for the given item.
    *
    * @param  aAccessible  [in] the item accessible
    * @param  aState       [in] the state of the item accessible
    */
-  static already_AddRefed<nsIAccessible>
-    GetSelectableContainer(nsIAccessible *aAccessible, PRUint32 aState);
+  static nsAccessible *GetSelectableContainer(nsAccessible *aAccessible,
+                                              PRUint32 aState);
 
   /**
    * Return multi selectable container for the given item.
    */
-  static already_AddRefed<nsIAccessible>
-    GetMultiSelectableContainer(nsIDOMNode *aNode);
+  static nsAccessible *GetMultiSelectableContainer(nsINode *aNode);
 
   /**
    * Return true if the DOM node of given accessible has aria-selected="true"
    * attribute.
    */
   static PRBool IsARIASelected(nsIAccessible *aAccessible);
 
   /**
@@ -234,70 +235,72 @@ public:
    * Used for normal and misspelling selection changes processing.
    *
    * @param aSelection  [in] the given selection
    * @param aNode       [out, optional] the DOM node of text accessible
    * @return            text accessible
    */
   static already_AddRefed<nsIAccessibleText>
     GetTextAccessibleFromSelection(nsISelection *aSelection,
-                                   nsIDOMNode **aNode = nsnull);
+                                   nsINode **aNode = nsnull);
 
   /**
    * Converts the given coordinates to coordinates relative screen.
    *
    * @param aX               [in] the given x coord
    * @param aY               [in] the given y coord
    * @param aCoordinateType  [in] specifies coordinates origin (refer to
    *                         nsIAccessibleCoordinateType)
    * @param aAccessNode      [in] the accessible if coordinates are given
    *                         relative it.
    * @param aCoords          [out] converted coordinates
    */
   static nsresult ConvertToScreenCoords(PRInt32 aX, PRInt32 aY,
                                         PRUint32 aCoordinateType,
-                                        nsIAccessNode *aAccessNode,
+                                        nsAccessNode *aAccessNode,
                                         nsIntPoint *aCoords);
 
   /**
    * Converts the given coordinates relative screen to another coordinate
    * system.
    *
    * @param aX               [in, out] the given x coord
    * @param aY               [in, out] the given y coord
    * @param aCoordinateType  [in] specifies coordinates origin (refer to
    *                         nsIAccessibleCoordinateType)
    * @param aAccessNode      [in] the accessible if coordinates are given
    *                         relative it
    */
   static nsresult ConvertScreenCoordsTo(PRInt32 *aX, PRInt32 *aY,
                                         PRUint32 aCoordinateType,
-                                        nsIAccessNode *aAccessNode);
+                                        nsAccessNode *aAccessNode);
 
   /**
    * Returns coordinates relative screen for the top level window.
    *
    * @param aAccessNode  the accessible hosted in the window
    */
-  static nsIntPoint GetScreenCoordsForWindow(nsIAccessNode *aAccessNode);
+  static nsIntPoint GetScreenCoordsForWindow(nsAccessNode *aAccessNode);
 
   /**
    * Returns coordinates relative screen for the parent of the given accessible.
    *
    * @param aAccessNode  the accessible
    */
-  static nsIntPoint GetScreenCoordsForParent(nsIAccessNode *aAccessNode);
+  static nsIntPoint GetScreenCoordsForParent(nsAccessNode *aAccessNode);
 
   /**
    * Get the role map entry for a given DOM node. This will use the first
    * ARIA role if the role attribute provides a space delimited list of roles.
-   * @param aNode  The DOM node to get the role map entry for
-   * @return       A pointer to the role map entry for the ARIA role, or nsnull if none
+   *
+   * @param aNode  [in] the DOM node to get the role map entry for
+   * @return        a pointer to the role map entry for the ARIA role, or nsnull
+   *                if none
    */
-  static nsRoleMapEntry* GetRoleMapEntry(nsIDOMNode *aNode);
+  static nsRoleMapEntry *GetRoleMapEntry(nsINode *aNode);
 
   /**
    * Return the role of the given accessible.
    */
   static PRUint32 Role(nsIAccessible *aAcc)
   {
     PRUint32 role = nsIAccessibleRole::ROLE_NOTHING;
     if (aAcc)
@@ -405,17 +408,17 @@ public:
    * to platform accessibility APIs, should the children be pruned off?
    */
   static PRBool MustPrune(nsIAccessible *aAccessible);
 
   /**
    * Return true if the given node can be accessible and attached to
    * the document's accessible tree.
    */
-  static PRBool IsNodeRelevant(nsIDOMNode *aNode);
+  static PRBool IsNodeRelevant(nsINode *aNode);
 
   /**
    * Search hint enum constants. Used by GetHeaderCellsFor() method.
    */
   enum {
     // search for row header cells, left direction
     eRowHeaderCells,
     // search for column header cells, top direction
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -75,17 +75,17 @@
 #include "mozilla/Services.h"
 
 /* For documentation of the accessibility architecture, 
  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
  */
 
 nsIStringBundle *nsAccessNode::gStringBundle = 0;
 nsIStringBundle *nsAccessNode::gKeyStringBundle = 0;
-nsIDOMNode *nsAccessNode::gLastFocusedNode = 0;
+nsINode *nsAccessNode::gLastFocusedNode = nsnull;
 
 PRBool nsAccessNode::gIsCacheDisabled = PR_FALSE;
 PRBool nsAccessNode::gIsFormFillEnabled = PR_FALSE;
 
 nsApplicationAccessible *nsAccessNode::gApplicationAccessible = nsnull;
 
 /*
  * Class nsAccessNode
@@ -104,18 +104,19 @@ NS_INTERFACE_MAP_END
  
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsAccessNode, nsIAccessNode)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_FULL(nsAccessNode, nsIAccessNode,
                                       LastRelease())
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessNode construction/desctruction
 
-nsAccessNode::nsAccessNode(nsIDOMNode *aNode, nsIWeakReference* aShell): 
-  mDOMNode(aNode), mWeakShell(aShell)
+nsAccessNode::
+  nsAccessNode(nsIContent *aContent, nsIWeakReference *aShell) :
+  mContent(aContent), mWeakShell(aShell)
 {
 #ifdef DEBUG_A11Y
   mIsInitialized = PR_FALSE;
 #endif
 }
 
 nsAccessNode::~nsAccessNode()
 {
@@ -163,46 +164,45 @@ nsAccessNode::Init()
   GetUniqueID(&uniqueID);
 
   if (!docAcc->CacheAccessNode(uniqueID, this))
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Make sure an ancestor in real content is cached
   // so that nsDocAccessible::RefreshNodes() can find the anonymous subtree to release when
   // the root node goes away
-  nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
-  if (content && content->IsInAnonymousSubtree()) {
+  if (mContent && mContent->IsInAnonymousSubtree()) {
     // Specific examples of where this is used: <input type="file"> and <xul:findbar>
-    nsAccessible *parent = GetAccService()->GetContainerAccessible(mDOMNode,
+    nsAccessible *parent = GetAccService()->GetContainerAccessible(mContent,
                                                                    PR_TRUE);
     if (parent)
       parent->EnsureChildren();
   }
 
 #ifdef DEBUG_A11Y
   mIsInitialized = PR_TRUE;
 #endif
 
   return NS_OK;
 }
 
 
 nsresult
 nsAccessNode::Shutdown()
 {
-  mDOMNode = nsnull;
+  mContent = nsnull;
   mWeakShell = nsnull;
 
   return NS_OK;
 }
 
 // nsIAccessNode
 NS_IMETHODIMP nsAccessNode::GetUniqueID(void **aUniqueID)
 {
-  *aUniqueID = static_cast<void*>(mDOMNode);
+  *aUniqueID = static_cast<void*>(GetNode());
   return NS_OK;
 }
 
 // nsIAccessNode
 NS_IMETHODIMP nsAccessNode::GetOwnerWindow(void **aWindow)
 {
   *aWindow = nsnull;
   nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
@@ -295,17 +295,17 @@ void nsAccessNode::ShutdownXPAccessibili
   }
 
   NotifyA11yInitOrShutdown(PR_FALSE);
 }
 
 PRBool
 nsAccessNode::IsDefunct()
 {
-  if (!mDOMNode)
+  if (!mContent)
     return PR_TRUE;
 
   // Call GetPresShell() since the accessible may be shut down in it.
   nsCOMPtr<nsIPresShell> presShell(GetPresShell());
   return !presShell;
 }
 
 already_AddRefed<nsIPresShell> nsAccessNode::GetPresShell()
@@ -333,18 +333,18 @@ nsPresContext* nsAccessNode::GetPresCont
     return nsnull;
   }
   return presShell->GetPresContext();
 }
 
 already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
 {
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
-    nsCoreUtils::GetDocShellTreeItemFor(mDOMNode);
-  NS_ASSERTION(docShellTreeItem, "No docshell tree item for mDOMNode");
+    nsCoreUtils::GetDocShellTreeItemFor(mContent);
+  NS_ASSERTION(docShellTreeItem, "No docshell tree item for mContent");
   if (!docShellTreeItem) {
     return nsnull;
   }
   nsCOMPtr<nsIDocShellTreeItem> root;
   docShellTreeItem->GetRootTreeItem(getter_AddRefs(root));
   NS_ASSERTION(root, "No root content tree item");
   if (!root) {
     return nsnull;
@@ -353,18 +353,17 @@ already_AddRefed<nsRootAccessible> nsAcc
   nsDocAccessible *docAcc = nsAccUtils::GetDocAccessibleFor(root);
   nsRefPtr<nsRootAccessible> rootAcc = do_QueryObject(docAcc);
   return rootAcc.forget();
 }
 
 nsIFrame*
 nsAccessNode::GetFrame()
 {
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  return content ? content->GetPrimaryFrame() : nsnull;
+  return mContent ? mContent->GetPrimaryFrame() : nsnull;
 }
 
 #ifdef DEBUG
 PRBool
 nsAccessNode::IsInCache()
 {
   nsDocAccessible *docAccessible = nsAccUtils::GetDocAccessibleFor(mWeakShell);
   if (!docAccessible)
@@ -376,35 +375,38 @@ nsAccessNode::IsInCache()
   return docAccessible->GetCachedAccessNode(uniqueID) ? PR_TRUE : PR_FALSE;
 }
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessNode
 
 NS_IMETHODIMP
-nsAccessNode::GetDOMNode(nsIDOMNode **aNode)
+nsAccessNode::GetDOMNode(nsIDOMNode **aDOMNode)
 {
-  NS_IF_ADDREF(*aNode = mDOMNode);
+  NS_ENSURE_ARG_POINTER(aDOMNode);
+  *aDOMNode = nsnull;
+
+  nsINode *node = GetNode();
+  if (node)
+    CallQueryInterface(node, aDOMNode);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetNumChildren(PRInt32 *aNumChildren)
 {
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-
-  if (!content) {
-    *aNumChildren = 0;
+  NS_ENSURE_ARG_POINTER(aNumChildren);
+  *aNumChildren = 0;
 
-    return NS_ERROR_NULL_POINTER;
-  }
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  *aNumChildren = content->GetChildCount();
-
+  *aNumChildren = GetNode()->GetChildCount();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetDocument(nsIAccessibleDocument **aDocument)
 {
   NS_ENSURE_ARG_POINTER(aDocument);
 
@@ -422,17 +424,17 @@ nsAccessNode::GetRootDocument(nsIAccessi
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetInnerHTML(nsAString& aInnerHTML)
 {
   aInnerHTML.Truncate();
 
-  nsCOMPtr<nsIDOMNSHTMLElement> domNSElement(do_QueryInterface(mDOMNode));
+  nsCOMPtr<nsIDOMNSHTMLElement> domNSElement(do_QueryInterface(mContent));
   NS_ENSURE_TRUE(domNSElement, NS_ERROR_NULL_POINTER);
 
   return domNSElement->GetInnerHTML(aInnerHTML);
 }
 
 NS_IMETHODIMP
 nsAccessNode::ScrollTo(PRUint32 aScrollType)
 {
@@ -468,180 +470,211 @@ nsAccessNode::ScrollToPoint(PRUint32 aCo
   nsIFrame *parentFrame = frame;
   while ((parentFrame = parentFrame->GetParent()))
     nsCoreUtils::ScrollFrameToPoint(parentFrame, frame, coords);
 
   return NS_OK;
 }
 
 // nsAccessNode protected
-nsresult
-nsAccessNode::MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode)
+nsAccessNode *
+nsAccessNode::MakeAccessNode(nsINode *aNode)
 {
-  *aAccessNode = nsnull;
-  
-  nsCOMPtr<nsIAccessNode> accessNode =
-    GetAccService()->GetCachedAccessNode(aNode, mWeakShell);
+  nsAccessNode *accessNode = GetAccService()->GetCachedAccessNode(aNode,
+                                                                  mWeakShell);
 
   if (!accessNode)
     accessNode = GetAccService()->GetAccessibleInWeakShell(aNode, mWeakShell);
 
-  if (accessNode) {
-    NS_ADDREF(*aAccessNode = accessNode);
-    return NS_OK;
+  if (accessNode)
+    return accessNode;
+
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
+  if (!content)
+    return nsnull;
+
+  nsAccessNode *newAccessNode = new nsAccessNode(content, mWeakShell);
+  if (!newAccessNode)
+    return nsnull;
+
+  // Initialize and cache it.
+  if (NS_FAILED(newAccessNode->Init())) {
+    newAccessNode->Shutdown();
+    delete newAccessNode;
+    return nsnull;
   }
 
-  nsAccessNode *newAccessNode = new nsAccessNode(aNode, mWeakShell);
-  if (!newAccessNode) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  NS_ADDREF(*aAccessNode = newAccessNode);
-  newAccessNode->Init();
-
-  return NS_OK;
+  return newAccessNode;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetFirstChildNode(nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
-  NS_ENSURE_TRUE(mDOMNode, NS_ERROR_NULL_POINTER);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  mDOMNode->GetFirstChild(getter_AddRefs(domNode));
+  nsIContent* childNode = GetNode()->GetChildAt(0);
+  if (childNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(childNode));
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetLastChildNode(nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
-  NS_ENSURE_TRUE(mDOMNode, NS_ERROR_NULL_POINTER);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  mDOMNode->GetLastChild(getter_AddRefs(domNode));
+  PRUint32 childCount = GetNode()->GetChildCount();
+  nsIContent* childNode = GetNode()->GetChildAt(childCount - 1);
+  if (childNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(childNode));
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetParentNode(nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
-  NS_ENSURE_TRUE(mDOMNode, NS_ERROR_NULL_POINTER);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  mDOMNode->GetParentNode(getter_AddRefs(domNode));
+  nsINode* parentNode = GetNode()->GetNodeParent();
+  if (parentNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(parentNode));
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetPreviousSiblingNode(nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
-  NS_ENSURE_TRUE(mDOMNode, NS_ERROR_NULL_POINTER);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  mDOMNode->GetPreviousSibling(getter_AddRefs(domNode));
+  nsINode* parentNode = GetNode()->GetNodeParent();
+  PRInt32 indexOf = parentNode->IndexOf(GetNode());
+  if (indexOf == -1)
+    return NS_OK;
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  nsIContent *siblingNode = parentNode->GetChildAt(indexOf - 1);
+  if (siblingNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(siblingNode));
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetNextSiblingNode(nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
-  NS_ENSURE_TRUE(mDOMNode, NS_ERROR_NULL_POINTER);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  mDOMNode->GetNextSibling(getter_AddRefs(domNode));
+  nsINode* parentNode = GetNode()->GetNodeParent();
+  PRInt32 indexOf = parentNode->IndexOf(GetNode());
+  if (indexOf == -1)
+    return NS_OK;
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  nsIContent *siblingNode = parentNode->GetChildAt(indexOf + 1);
+  if (siblingNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(siblingNode));
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetChildNodeAt(PRInt32 aChildNum, nsIAccessNode **aAccessNode)
 {
   NS_ENSURE_ARG_POINTER(aAccessNode);
   *aAccessNode = nsnull;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode =
-    do_QueryInterface(content->GetChildAt(aChildNum));
+  nsIContent* childNode = GetNode()->GetChildAt(aChildNum);
+  if (childNode)
+    NS_IF_ADDREF(*aAccessNode = MakeAccessNode(childNode));
 
-  return domNode ? MakeAccessNode(domNode, aAccessNode) : NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetComputedStyleValue(const nsAString& aPseudoElt,
                                     const nsAString& aPropertyName,
                                     nsAString& aValue)
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
-  nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
-                                           getter_AddRefs(styleDecl));
+  nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl =
+    nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mContent);
   NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
 
   return styleDecl->GetPropertyValue(aPropertyName, aValue);
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetComputedStyleCSSValue(const nsAString& aPseudoElt,
                                        const nsAString& aPropertyName,
                                        nsIDOMCSSPrimitiveValue **aCSSValue)
 {
   NS_ENSURE_ARG_POINTER(aCSSValue);
   *aCSSValue = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
-  nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
-                                           getter_AddRefs(styleDecl));
+  nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl =
+    nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mContent);
   NS_ENSURE_STATE(styleDecl);
 
   nsCOMPtr<nsIDOMCSSValue> cssValue;
   styleDecl->GetPropertyCSSValue(aPropertyName, getter_AddRefs(cssValue));
   NS_ENSURE_TRUE(cssValue, NS_ERROR_FAILURE);
 
   return CallQueryInterface(cssValue, aCSSValue);
 }
 
 // nsAccessNode public
-already_AddRefed<nsIDOMNode> nsAccessNode::GetCurrentFocus()
+already_AddRefed<nsINode>
+nsAccessNode::GetCurrentFocus()
 {
-  nsIPresShell *shell = nsCoreUtils::GetPresShellFor(mDOMNode);
+  // XXX: consider to use nsFocusManager directly, it allows us to avoid
+  // unnecessary query interface calls.
+  nsCOMPtr<nsIPresShell> shell = GetPresShell();
   NS_ENSURE_TRUE(shell, nsnull);
-  nsCOMPtr<nsIDocument> doc = shell->GetDocument();
+  nsIDocument *doc = shell->GetDocument();
   NS_ENSURE_TRUE(doc, nsnull);
 
   nsIDOMWindow* win = doc->GetWindow();
 
   nsCOMPtr<nsIDOMWindow> focusedWindow;
   nsCOMPtr<nsIDOMElement> focusedElement;
   nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
   if (fm)
     fm->GetFocusedElementForWindow(win, PR_TRUE, getter_AddRefs(focusedWindow),
                                    getter_AddRefs(focusedElement));
 
-  nsIDOMNode *focusedNode = nsnull;
+  nsINode *focusedNode = nsnull;
   if (focusedElement) {
     CallQueryInterface(focusedElement, &focusedNode);
   }
   else if (focusedWindow) {
     nsCOMPtr<nsIDOMDocument> doc;
     focusedWindow->GetDocument(getter_AddRefs(doc));
     if (doc)
       CallQueryInterface(doc, &focusedNode);
@@ -649,44 +682,24 @@ already_AddRefed<nsIDOMNode> nsAccessNod
 
   return focusedNode;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetLanguage(nsAString& aLanguage)
 {
   aLanguage.Truncate();
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (!content) {
-    // For documents make sure we look for lang attribute on
-    // document element
-    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mDOMNode));
-    if (domDoc) {
-      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDOMNode));
-      if (htmlDoc) {
-        // Make sure we look for lang attribute on HTML <body>
-        nsCOMPtr<nsIDOMHTMLElement> bodyElement;
-        htmlDoc->GetBody(getter_AddRefs(bodyElement));
-        content = do_QueryInterface(bodyElement);
-      }
-      if (!content) {
-        nsCOMPtr<nsIDOMElement> docElement;
-        domDoc->GetDocumentElement(getter_AddRefs(docElement));
-        content = do_QueryInterface(docElement);
-      }
-    }
-    if (!content) {
-      return NS_ERROR_FAILURE;
-    }
-  }
 
-  nsCoreUtils::GetLanguageFor(content, nsnull, aLanguage);
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCoreUtils::GetLanguageFor(mContent, nsnull, aLanguage);
 
   if (aLanguage.IsEmpty()) { // Nothing found, so use document's language
-    nsIDocument *doc = content->GetOwnerDoc();
+    nsIDocument *doc = mContent->GetOwnerDoc();
     if (doc) {
       doc->GetHeaderData(nsAccessibilityAtoms::headerContentLanguage, aLanguage);
     }
   }
  
   return NS_OK;
 }
 
--- a/accessible/src/base/nsAccessNode.h
+++ b/accessible/src/base/nsAccessNode.h
@@ -77,19 +77,20 @@ typedef nsRefPtrHashtable<nsVoidPtrHashK
   0x2b07e3d7,                                           \
   0x00b3,                                               \
   0x4379,                                               \
   { 0xaa, 0x0b, 0xea, 0x22, 0xe2, 0xc8, 0xff, 0xda }    \
 }
 
 class nsAccessNode: public nsIAccessNode
 {
-  public: // construction, destruction
-    nsAccessNode(nsIDOMNode *, nsIWeakReference* aShell);
-    virtual ~nsAccessNode();
+public:
+
+  nsAccessNode(nsIContent *aContent, nsIWeakReference *aShell);
+  virtual ~nsAccessNode();
 
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAccessNode, nsIAccessNode)
 
     NS_DECL_NSIACCESSNODE
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSNODE_IMPL_CID)
 
     static void InitXPAccessibility();
@@ -105,19 +106,28 @@ class nsAccessNode: public nsIAccessNode
    */
   nsDocAccessible* GetDocAccessible() const;
 
   /**
    * Return the root document accessible for this accessnode.
    */
   already_AddRefed<nsRootAccessible> GetRootAccessible();
 
-    static nsIDOMNode *gLastFocusedNode;
+  /**
+   * Reference to a node of focused accessible.
+   */
+  static nsINode *gLastFocusedNode;
 
-    already_AddRefed<nsIDOMNode> GetCurrentFocus();
+  /**
+   * Return focused node within accessible window.
+   *
+   * XXX: it shouldn't break us if we return focused node not depending on
+   * window so that we can turn this method into util method.
+   */
+  already_AddRefed<nsINode> GetCurrentFocus();
 
     /**
      * Returns true when the accessible is defunct.
      */
     virtual PRBool IsDefunct();
 
     /**
      * Initialize the access node object, add it to the cache.
@@ -132,17 +142,41 @@ class nsAccessNode: public nsIAccessNode
     /**
      * Return frame for the given access node object.
      */
     virtual nsIFrame* GetFrame();
 
   /**
    * Return DOM node associated with this accessible.
    */
-  nsIDOMNode *GetDOMNode() const { return mDOMNode; }
+  already_AddRefed<nsIDOMNode> GetDOMNode() const
+  {
+    nsIDOMNode *DOMNode = nsnull;
+    if (GetNode())
+      CallQueryInterface(GetNode(), &DOMNode);
+    return DOMNode;
+  }
+
+  /**
+   * Return DOM node associated with the accessible.
+   */
+  virtual nsINode* GetNode() const { return mContent; }
+  nsIContent* GetContent() const { return mContent; }
+
+  /**
+   * Return node type information of DOM node associated with the accessible.
+   */
+  PRBool IsContent() const
+  {
+    return GetNode() && GetNode()->IsNodeOfType(nsINode::eCONTENT);
+  }
+  PRBool IsDocument() const
+  {
+    return GetNode() && GetNode()->IsNodeOfType(nsINode::eDOCUMENT);
+  }
 
   /**
    * Return the corresponding press shell for this accessible.
    */
   already_AddRefed<nsIPresShell> GetPresShell();
 
   /**
    * Return true if the accessible still has presentation shell. Light-weight
@@ -153,24 +187,27 @@ class nsAccessNode: public nsIAccessNode
 #ifdef DEBUG
   /**
    * Return true if the access node is cached.
    */
   PRBool IsInCache();
 #endif
 
 protected:
-    nsresult MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode);
+  /**
+   * Return the access node for the given DOM node.
+   */
+  nsAccessNode *MakeAccessNode(nsINode *aNode);
 
     nsPresContext* GetPresContext();
 
     void LastRelease();
 
-    nsCOMPtr<nsIDOMNode> mDOMNode;
-    nsCOMPtr<nsIWeakReference> mWeakShell;
+  nsCOMPtr<nsIContent> mContent;
+  nsCOMPtr<nsIWeakReference> mWeakShell;
 
 #ifdef DEBUG_A11Y
     PRBool mIsInitialized;
 #endif
 
     /**
      * Notify global nsIObserver's that a11y is getting init'd or shutdown
      */
--- a/accessible/src/base/nsAccessibilityAtomList.h
+++ b/accessible/src/base/nsAccessibilityAtomList.h
@@ -52,24 +52,28 @@
   The first argument to ACCESSIBILITY_ATOM is the C++ identifier of the atom
   The second argument is the string value of the atom
 
  ******/
 
 
   // Alphabetical list of generic atoms
 ACCESSIBILITY_ATOM(button, "button")
+ACCESSIBILITY_ATOM(checkbox, "checkbox")
 ACCESSIBILITY_ATOM(col, "col")
 ACCESSIBILITY_ATOM(_empty, "")
 ACCESSIBILITY_ATOM(_false, "false")
 ACCESSIBILITY_ATOM(image, "image")
 ACCESSIBILITY_ATOM(menu, "menu")
 ACCESSIBILITY_ATOM(menuButton, "menu-button")
 ACCESSIBILITY_ATOM(menugenerated, "menugenerated")
+ACCESSIBILITY_ATOM(multiple, "multiple")
+ACCESSIBILITY_ATOM(open, "open")
 ACCESSIBILITY_ATOM(password, "password")
+ACCESSIBILITY_ATOM(radio, "radio")
 ACCESSIBILITY_ATOM(reset, "reset")
 ACCESSIBILITY_ATOM(row, "row")
 ACCESSIBILITY_ATOM(submit, "submit")
 ACCESSIBILITY_ATOM(_true, "true")
 ACCESSIBILITY_ATOM(_undefined, "undefined")
 
   // Header info
 ACCESSIBILITY_ATOM(headerContentLanguage, "content-language")
@@ -117,16 +121,17 @@ ACCESSIBILITY_ATOM(h6, "h6")
 ACCESSIBILITY_ATOM(item, "item") // XForms
 ACCESSIBILITY_ATOM(itemset, "itemset") // XForms
 ACCESSIBILITY_ATOM(img, "img")
 ACCESSIBILITY_ATOM(input, "input")
 ACCESSIBILITY_ATOM(label, "label")
 ACCESSIBILITY_ATOM(legend, "legend")
 ACCESSIBILITY_ATOM(li, "li")
 ACCESSIBILITY_ATOM(link, "link")
+ACCESSIBILITY_ATOM(listcell, "listcell") // XUL
 ACCESSIBILITY_ATOM(listcols, "listcols") // XUL
 ACCESSIBILITY_ATOM(listcol, "listcol") // XUL
 ACCESSIBILITY_ATOM(listhead, "listhead") // XUL
 ACCESSIBILITY_ATOM(listheader, "listheader") // XUL
 ACCESSIBILITY_ATOM(map, "map")
 ACCESSIBILITY_ATOM(math, "math")
 ACCESSIBILITY_ATOM(menupopup, "menupopup")     // XUL
 ACCESSIBILITY_ATOM(object, "object")
@@ -156,44 +161,48 @@ ACCESSIBILITY_ATOM(tr, "tr")
 ACCESSIBILITY_ATOM(tree, "tree")
 ACCESSIBILITY_ATOM(ul, "ul")
 
   // Alphabetical list of attributes (DOM)
 ACCESSIBILITY_ATOM(acceltext, "acceltext")
 ACCESSIBILITY_ATOM(accesskey, "accesskey")
 ACCESSIBILITY_ATOM(alt, "alt")
 ACCESSIBILITY_ATOM(anonid, "anonid") // Used for ID's in XBL
+ACCESSIBILITY_ATOM(checked, "checked")
 ACCESSIBILITY_ATOM(contenteditable, "contenteditable")
 ACCESSIBILITY_ATOM(control, "control")
 ACCESSIBILITY_ATOM(disabled, "disabled")
 ACCESSIBILITY_ATOM(_class, "class")
 ACCESSIBILITY_ATOM(cycles, "cycles") // used for XUL cycler attribute
 ACCESSIBILITY_ATOM(curpos, "curpos") // XUL
 ACCESSIBILITY_ATOM(data, "data")
 ACCESSIBILITY_ATOM(_default, "default") // XUL button
 ACCESSIBILITY_ATOM(draggable, "draggable")
 ACCESSIBILITY_ATOM(droppable, "droppable")   // XUL combo box
 ACCESSIBILITY_ATOM(editable, "editable")
 ACCESSIBILITY_ATOM(_for, "for")
 ACCESSIBILITY_ATOM(headers, "headers")   // HTML table
 ACCESSIBILITY_ATOM(hidden, "hidden")   // XUL tree columns
+ACCESSIBILITY_ATOM(hover, "hover") // XUL color picker
 ACCESSIBILITY_ATOM(href, "href") // XUL, XLink
 ACCESSIBILITY_ATOM(increment, "increment") // XUL
 ACCESSIBILITY_ATOM(lang, "lang")
 ACCESSIBILITY_ATOM(linkedPanel, "linkedpanel") // XUL
 ACCESSIBILITY_ATOM(longDesc, "longdesc")
 ACCESSIBILITY_ATOM(max, "max") // XUL
 ACCESSIBILITY_ATOM(maxpos, "maxpos") // XUL
 ACCESSIBILITY_ATOM(minpos, "minpos") // XUL
+ACCESSIBILITY_ATOM(_moz_menuactive, "_moz-menuactive") // XUL
 ACCESSIBILITY_ATOM(multiline, "multiline") // XUL
 ACCESSIBILITY_ATOM(name, "name")
 ACCESSIBILITY_ATOM(onclick, "onclick")
 ACCESSIBILITY_ATOM(popup, "popup")
 ACCESSIBILITY_ATOM(readonly, "readonly")
 ACCESSIBILITY_ATOM(scope, "scope") // HTML table
+ACCESSIBILITY_ATOM(seltype, "seltype") // XUL listbox
 ACCESSIBILITY_ATOM(simple, "simple") // XLink
 ACCESSIBILITY_ATOM(src, "src")
 ACCESSIBILITY_ATOM(selected, "selected")
 ACCESSIBILITY_ATOM(summary, "summary")
 ACCESSIBILITY_ATOM(tabindex, "tabindex")
 ACCESSIBILITY_ATOM(title, "title")
 ACCESSIBILITY_ATOM(toolbarname, "toolbarname")
 ACCESSIBILITY_ATOM(tooltiptext, "tooltiptext")
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -59,32 +59,25 @@
 #include "nsIDOMDocument.h"
 #include "nsIDOMHTMLAreaElement.h"
 #include "nsIDOMHTMLLegendElement.h"
 #include "nsIDOMHTMLObjectElement.h"
 #include "nsIDOMHTMLOptGroupElement.h"
 #include "nsIDOMHTMLOptionElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIHTMLDocument.h"
-#include "nsIDocShell.h"
-#include "nsIFrame.h"
 #include "nsIImageFrame.h"
 #include "nsILink.h"
-#include "nsINameSpaceManager.h"
 #include "nsIObserverService.h"
 #include "nsIPluginInstance.h"
-#include "nsIPresShell.h"
 #include "nsISupportsUtils.h"
 #include "nsObjectFrame.h"
 #include "nsOuterDocAccessible.h"
 #include "nsRootAccessibleWrap.h"
 #include "nsTextFragment.h"
-#include "nsServiceManagerUtils.h"
-#include "nsUnicharUtils.h"
-#include "nsNetError.h"
 #include "mozilla/Services.h"
 
 #ifdef MOZ_XUL
 #include "nsXULAlertAccessible.h"
 #include "nsXULColorPickerAccessible.h"
 #include "nsXULComboboxAccessible.h"
 #include "nsXULFormControlAccessible.h"
 #include "nsXULListboxAccessibleWrap.h"
@@ -150,31 +143,30 @@ nsAccessibilityService::Observe(nsISuppo
 // nsIAccessibilityService
 void
 nsAccessibilityService::NotifyOfAnchorJumpTo(nsIContent *aTarget)
 {
   nsIDocument *document = aTarget->GetCurrentDoc();
   if (!document)
     return;
 
-  nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(aTarget));
-
+  nsINode *targetNode = aTarget;
   nsAccessible *targetAcc = GetAccessible(targetNode);
 
   // Getting the targetAcc above will have ensured accessible doc creation.
   // XXX Bug 561683
   nsDocAccessible *docAccessible = GetDocAccessible(document);
   if (!docAccessible)
     return;
 
   // If the jump target is not accessible then fire an event for nearest
   // accessible in parent chain.
   if (!targetAcc) {
     targetAcc = GetContainerAccessible(targetNode, PR_TRUE);
-    targetNode = targetAcc->GetDOMNode();
+    targetNode = targetAcc->GetNode();
   }
 
   NS_ASSERTION(targetNode,
       "No accessible in parent chain!? Expect at least a document accessible.");
   if (!targetNode)
     return;
 
   // XXX note in rare cases the node could go away before we flush the queue,
@@ -190,282 +182,267 @@ nsAccessibilityService::FireAccessibleEv
                                             nsIAccessible *aTarget)
 {
   nsEventShell::FireEvent(aEvent, aTarget);
   return NS_OK;
 }
 
 // nsAccessibilityService private
 nsresult
-nsAccessibilityService::GetInfo(nsIFrame* aFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
+nsAccessibilityService::GetInfo(nsIFrame *aFrame, nsIWeakReference **aShell,
+                                nsIContent **aContent)
 {
   NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!");
   if (!aFrame) {
     return NS_ERROR_FAILURE;
   }
-  nsCOMPtr<nsIContent> content = aFrame->GetContent();
-  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
-  if (!content || !node)
+  nsIContent* content = aFrame->GetContent();
+  if (!content)
     return NS_ERROR_FAILURE;
 
-  *aNode = node;
-  NS_IF_ADDREF(*aNode);
-
-  nsCOMPtr<nsIDocument> document = content->GetDocument();
+  nsIDocument* document = content->GetOwnerDoc();
   if (!document)
     return NS_ERROR_FAILURE;
 
   NS_ASSERTION(document->GetPrimaryShell(),"Error no shells!");
 
   // do_GetWR only works into a |nsCOMPtr| :-(
   nsCOMPtr<nsIWeakReference> weakShell =
     do_GetWeakReference(document->GetPrimaryShell());
-  NS_IF_ADDREF(*aShell = weakShell);
 
-  return NS_OK;
-}
-
-// nsAccessibilityService public
-nsresult
-nsAccessibilityService::GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **aWeakShell)
-{
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aNode->GetOwnerDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
-  if (!doc)
-    return NS_ERROR_INVALID_ARG;
-
-  // ---- Get the pres shell ----
-  nsIPresShell *shell = doc->GetPrimaryShell();
-  if (!shell)
-    return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIWeakReference> weakRef(do_GetWeakReference(shell));
-  
-  *aWeakShell = weakRef;
-  NS_IF_ADDREF(*aWeakShell);
+  weakShell.forget(aShell);
+  NS_IF_ADDREF(*aContent = content);
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessibilityService
 
 nsresult
 nsAccessibilityService::CreateOuterDocAccessible(nsIDOMNode* aDOMNode, 
                                                  nsIAccessible **aOuterDocAccessible)
 {
   NS_ENSURE_ARG_POINTER(aDOMNode);
   
   *aOuterDocAccessible = nsnull;
 
-  nsCOMPtr<nsIWeakReference> outerWeakShell;
-  GetShellFromNode(aDOMNode, getter_AddRefs(outerWeakShell));
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  nsCOMPtr<nsIWeakReference> outerWeakShell =
+    nsCoreUtils::GetWeakShellFor(content);
   NS_ENSURE_TRUE(outerWeakShell, NS_ERROR_FAILURE);
 
   nsOuterDocAccessible *outerDocAccessible =
-    new nsOuterDocAccessible(aDOMNode, outerWeakShell);
+    new nsOuterDocAccessible(content, outerWeakShell);
   NS_ENSURE_TRUE(outerDocAccessible, NS_ERROR_FAILURE);
 
   NS_ADDREF(*aOuterDocAccessible = outerDocAccessible);
 
   return NS_OK;
 }
 
  /**
    * HTML widget creation
    */
 nsresult
-nsAccessibilityService::CreateHTML4ButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTML4ButtonAccessible(nsIFrame *aFrame,
+                                                    nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTML4ButtonAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTML4ButtonAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLButtonAccessible(nsIFrame *aFrame,
+                                                   nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLButtonAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLButtonAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 // nsAccessibilityService private
 already_AddRefed<nsAccessible>
 nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame *aFrame,
                                                      nsIWeakReference *aWeakShell,
-                                                     nsIDOMNode *aNode)
+                                                     nsINode *aNode)
 {
   // This method assumes we're in an HTML namespace.
   nsRefPtr<nsAccessible> accessible;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
   nsIAtom *tag = content->Tag();
   if (tag == nsAccessibilityAtoms::legend) {
-    accessible = new nsHTMLLegendAccessible(aNode, aWeakShell);
+    accessible = new nsHTMLLegendAccessible(content, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::option) {
-    accessible = new nsHTMLSelectOptionAccessible(aNode, aWeakShell);
+    accessible = new nsHTMLSelectOptionAccessible(content, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::optgroup) {
-    accessible = new nsHTMLSelectOptGroupAccessible(aNode, aWeakShell);
+    accessible = new nsHTMLSelectOptGroupAccessible(content, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::ul || tag == nsAccessibilityAtoms::ol ||
            tag == nsAccessibilityAtoms::dl) {
-    accessible = new nsHTMLListAccessible(aNode, aWeakShell);
+    accessible = new nsHTMLListAccessible(content, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::a) {
 
     // Only some roles truly enjoy life as nsHTMLLinkAccessibles, for details
     // see closed bug 494807.
     nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aNode);
     if (roleMapEntry && roleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING
         && roleMapEntry->role != nsIAccessibleRole::ROLE_LINK) {
 
-      accessible = new nsHyperTextAccessibleWrap(aNode, aWeakShell);
+      accessible = new nsHyperTextAccessibleWrap(content, aWeakShell);
     } else {
-      accessible = new nsHTMLLinkAccessible(aNode, aWeakShell);
+      accessible = new nsHTMLLinkAccessible(content, aWeakShell);
     }
   }
   else if (tag == nsAccessibilityAtoms::dt ||
            (tag == nsAccessibilityAtoms::li && 
             aFrame->GetType() != nsAccessibilityAtoms::blockFrame)) {
     // Normally for li, it is created by the list item frame (in nsBlockFrame)
     // which knows about the bullet frame; however, in this case the list item
     // must have been styled using display: foo
-    accessible = new nsHTMLLIAccessible(aNode, aWeakShell, EmptyString());
+    accessible = new nsHTMLLIAccessible(content, aWeakShell, EmptyString());
   }
   else if (tag == nsAccessibilityAtoms::abbr ||
            tag == nsAccessibilityAtoms::acronym ||
            tag == nsAccessibilityAtoms::blockquote ||
            tag == nsAccessibilityAtoms::dd ||
            tag == nsAccessibilityAtoms::form ||
            tag == nsAccessibilityAtoms::h1 ||
            tag == nsAccessibilityAtoms::h2 ||
            tag == nsAccessibilityAtoms::h3 ||
            tag == nsAccessibilityAtoms::h4 ||
            tag == nsAccessibilityAtoms::h5 ||
            tag == nsAccessibilityAtoms::h6 ||
            tag == nsAccessibilityAtoms::q) {
 
-    accessible = new nsHyperTextAccessibleWrap(aNode, aWeakShell);
+    accessible = new nsHyperTextAccessibleWrap(content, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::tr) {
-    accessible = new nsEnumRoleAccessible(aNode, aWeakShell,
-                                            nsIAccessibleRole::ROLE_ROW);
+    accessible = new nsEnumRoleAccessible(content, aWeakShell,
+                                          nsIAccessibleRole::ROLE_ROW);
   }
   else if (nsCoreUtils::IsHTMLTableHeader(content)) {
-    accessible = new nsHTMLTableHeaderCellAccessibleWrap(aNode, aWeakShell);
+    accessible = new nsHTMLTableHeaderCellAccessibleWrap(content, aWeakShell);
   }
 
   return accessible.forget();
 }
 
 nsresult
 nsAccessibilityService::CreateHTMLLIAccessible(nsIFrame *aFrame, 
                                                nsIFrame *aBulletFrame,
                                                const nsAString& aBulletText,
-                                               nsIAccessible **_retval)
+                                               nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLLIAccessible(node, weakShell, aBulletText);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLLIAccessible(content, weakShell, aBulletText);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
-  return NS_OK;
-}
-
-nsresult
-nsAccessibilityService::CreateHyperTextAccessible(nsIFrame *aFrame, nsIAccessible **aAccessible)
-{
-  nsCOMPtr<nsIDOMNode> node;
-  nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
-  if (NS_FAILED(rv))
-    return rv;
-
-  nsCOMPtr<nsIContent> content(do_QueryInterface(node));
-  NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
-  
-  *aAccessible = new nsHyperTextAccessibleWrap(node, weakShell);
-  NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY);
-
   NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHyperTextAccessible(nsIFrame *aFrame,
+                                                  nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLCheckboxAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHyperTextAccessibleWrap(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLComboboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aPresShell, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIFrame *aFrame,
+                                                     nsIAccessible **aAccessible)
 {
-  *_retval = new nsHTMLComboboxAccessible(aDOMNode, aPresShell);
-  if (! *_retval)
+  nsCOMPtr<nsIContent> content;
+  nsCOMPtr<nsIWeakReference> weakShell;
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
+  if (NS_FAILED(rv))
+    return rv;
+
+  *aAccessible = new nsHTMLCheckboxAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
+  return NS_OK;
+}
+
+nsresult
+nsAccessibilityService::CreateHTMLComboboxAccessible(nsIDOMNode *aDOMNode,
+                                                     nsIWeakReference *aPresShell,
+                                                     nsIAccessible **aAccessible)
+{
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  *aAccessible = new nsHTMLComboboxAccessible(content, aPresShell);
+  if (!*aAccessible)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
 nsAccessibilityService::CreateHTMLImageAccessible(nsIFrame *aFrame,
                                                   nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  nsCOMPtr<nsIContent> content = do_QueryInterface(node);
-  NS_ENSURE_STATE(content);
-
   nsCOMPtr<nsIHTMLDocument> htmlDoc =
     do_QueryInterface(content->GetCurrentDoc());
 
   nsCOMPtr<nsIDOMHTMLMapElement> mapElm;
   if (htmlDoc) {
     nsAutoString mapElmName;
     content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::usemap,
                      mapElmName);
@@ -473,75 +450,80 @@ nsAccessibilityService::CreateHTMLImageA
     if (!mapElmName.IsEmpty()) {
       if (mapElmName.CharAt(0) == '#')
         mapElmName.Cut(0,1);
       mapElm = htmlDoc->GetImageMap(mapElmName);
     }
   }
 
   if (mapElm)
-    *aAccessible = new nsHTMLImageMapAccessible(node, weakShell, mapElm);
+    *aAccessible = new nsHTMLImageMapAccessible(content, weakShell, mapElm);
   else
-    *aAccessible = new nsHTMLImageAccessibleWrap(node, weakShell);
+    *aAccessible = new nsHTMLImageAccessibleWrap(content, weakShell);
 
   if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
 nsAccessibilityService::CreateHTMLGenericAccessible(nsIFrame *aFrame, nsIAccessible **aAccessible)
 {
   return CreateHyperTextAccessible(aFrame, aAccessible);
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIFrame *aFrame,
+                                                     nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLGroupboxAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLGroupboxAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLListboxAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aPresShell, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLListboxAccessible(nsIDOMNode* aDOMNode,
+                                                    nsIWeakReference *aPresShell,
+                                                    nsIAccessible **aAccessible)
 {
-  *_retval = new nsHTMLSelectListAccessible(aDOMNode, aPresShell);
-  if (! *_retval) 
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  *aAccessible = new nsHTMLSelectListAccessible(content, aPresShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
 nsAccessibilityService::CreateHTMLMediaAccessible(nsIFrame *aFrame,
                                                   nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG_POINTER(aAccessible);
   *aAccessible = nsnull;
 
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
   nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
-                        getter_AddRefs(node));
+                        getter_AddRefs(content));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  *aAccessible = new nsEnumRoleAccessible(node, weakShell,
+  *aAccessible = new nsEnumRoleAccessible(content, weakShell,
                                           nsIAccessibleRole::ROLE_GROUPING);
   NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 /**
@@ -552,45 +534,48 @@ nsAccessibilityService::CreateHTMLMediaA
   *     have to go to the plugin to get the accessible content
   *  3) An image or imagemap, where the image frame points back to 
   *     the object element DOMNode
   */
 nsresult
 nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame,
                                                         nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  NS_ENSURE_ARG_POINTER(aAccessible);
+  *aAccessible = nsnull;
+
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(content));
 
-  *aAccessible = nsnull;
   if (aFrame->GetRect().IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
   // 1) for object elements containing either HTML or TXT documents
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  nsCOMPtr<nsIDOMHTMLObjectElement> obj(do_QueryInterface(node));
-  if (obj)
+  nsCOMPtr<nsIDOMHTMLObjectElement> obj(do_QueryInterface(content));
+  if (obj) {
+    nsCOMPtr<nsIDOMDocument> domDoc;
     obj->GetContentDocument(getter_AddRefs(domDoc));
-  else
-    domDoc = do_QueryInterface(node);
-  if (domDoc)
-    return CreateOuterDocAccessible(node, aAccessible);
+    if (domDoc) {
+      nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(content));
+      return CreateOuterDocAccessible(DOMNode, aAccessible);
+    }
+  }
 
 #ifdef XP_WIN
   // 2) for plugins
   nsCOMPtr<nsIPluginInstance> pluginInstance ;
   aFrame->GetPluginInstance(*getter_AddRefs(pluginInstance));
   if (pluginInstance) {
     // Note: pluginPort will be null if windowless.
     HWND pluginPort = nsnull;
     aFrame->GetPluginPort(&pluginPort);
 
     *aAccessible =
-      new nsHTMLWin32ObjectOwnerAccessible(node, weakShell, pluginPort);
+      new nsHTMLWin32ObjectOwnerAccessible(content, weakShell, pluginPort);
     NS_ENSURE_TRUE(*aAccessible, NS_ERROR_OUT_OF_MEMORY);
 
     NS_ADDREF(*aAccessible);
     return NS_OK;
   }
 #endif
 
   // 3) for images and imagemaps, or anything else with a child frame
@@ -598,189 +583,210 @@ nsAccessibilityService::CreateHTMLObject
   nsIFrame *frame = aFrame->GetFirstChild(nsnull);
   if (frame)
     return frame->GetAccessible(aAccessible);
 
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIFrame *aFrame,
+                                                        nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLRadioButtonAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLRadioButtonAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLSelectOptionAccessible(nsIDOMNode* aDOMNode, 
+nsAccessibilityService::CreateHTMLSelectOptionAccessible(nsIDOMNode *aDOMNode,
                                                          nsIAccessible *aParent, 
-                                                         nsIWeakReference* aPresShell, 
-                                                         nsIAccessible **_retval)
+                                                         nsIWeakReference *aPresShell,
+                                                         nsIAccessible **aAccessible)
 {
-  *_retval = new nsHTMLSelectOptionAccessible(aDOMNode, aPresShell);
-  if (! *_retval) 
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  *aAccessible = new nsHTMLSelectOptionAccessible(content, aPresShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLTableAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTableAccessible(nsIFrame *aFrame,
+                                                  nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLTableAccessibleWrap(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLTableAccessibleWrap(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
 nsAccessibilityService::CreateHTMLTableCellAccessible(nsIFrame *aFrame,
                                                       nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  NS_ENSURE_ARG_POINTER(aAccessible);
+  *aAccessible = nsnull;
+
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *aAccessible = new nsHTMLTableCellAccessibleWrap(node, weakShell);
-  if (!*aAccessible) 
+  *aAccessible = new nsHTMLTableCellAccessibleWrap(content, weakShell);
+  if (!*aAccessible)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*aAccessible);
+  return NS_OK;
+}
+
+nsresult
+nsAccessibilityService::CreateHTMLTextAccessible(nsIFrame *aFrame,
+                                                 nsIAccessible **aAccessible)
+{
+  *aAccessible = nsnull;
+
+  nsCOMPtr<nsIContent> content;
+  nsCOMPtr<nsIWeakReference> weakShell;
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
+  if (NS_FAILED(rv))
+    return rv;
+
+  // XXX Don't create ATK objects for these
+  *aAccessible = new nsHTMLTextAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLTextAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIFrame *aFrame,
+                                                      nsIAccessible **aAccessible)
 {
-  *_retval = nsnull;
-
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  // XXX Don't create ATK objects for these
-  *_retval = new nsHTMLTextAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLTextFieldAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLLabelAccessible(nsIFrame *aFrame,
+                                                  nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLTextFieldAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLLabelAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLLabelAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLHRAccessible(nsIFrame *aFrame,
+                                               nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLLabelAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLHRAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLHRAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLBRAccessible(nsIFrame *aFrame,
+                                               nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLHRAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLBRAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 nsresult
-nsAccessibilityService::CreateHTMLBRAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
+nsAccessibilityService::CreateHTMLCaptionAccessible(nsIFrame *aFrame,
+                                                    nsIAccessible **aAccessible)
 {
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell),
+                        getter_AddRefs(content));
   if (NS_FAILED(rv))
     return rv;
 
-  *_retval = new nsHTMLBRAccessible(node, weakShell);
-  if (! *_retval) 
+  *aAccessible = new nsHTMLCaptionAccessible(content, weakShell);
+  if (!*aAccessible)
     return NS_ERROR_OUT_OF_MEMORY;
 
-  NS_ADDREF(*_retval);
-  return NS_OK;
-}
-
-nsresult
-nsAccessibilityService::CreateHTMLCaptionAccessible(nsIFrame *aFrame, nsIAccessible **_retval)
-{
-  nsCOMPtr<nsIDOMNode> node;
-  nsCOMPtr<nsIWeakReference> weakShell;
-  nsresult rv = GetInfo(aFrame, getter_AddRefs(weakShell), getter_AddRefs(node));
-  if (NS_FAILED(rv))
-    return rv;
-
-  *_retval = new nsHTMLCaptionAccessible(node, weakShell);
-  if (! *_retval) 
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  NS_ADDREF(*_retval);
+  NS_ADDREF(*aAccessible);
   return NS_OK;
 }
 
 // nsAccessibilityService public
 nsAccessNode*
-nsAccessibilityService::GetCachedAccessNode(nsIDOMNode *aNode, 
+nsAccessibilityService::GetCachedAccessNode(nsINode *aNode,
                                             nsIWeakReference *aWeakShell)
 {
   nsDocAccessible *docAccessible = nsAccUtils::GetDocAccessibleFor(aWeakShell);
   return docAccessible ?
     docAccessible->GetCachedAccessNode(static_cast<void*>(aNode)) : nsnull;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -791,16 +797,52 @@ nsAccessibilityService::GetApplicationAc
 {
   NS_ENSURE_ARG_POINTER(aAccessibleApplication);
 
   NS_IF_ADDREF(*aAccessibleApplication = nsAccessNode::GetApplicationAccessible());
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode,
+                                         nsIAccessible **aAccessible)
+{
+  NS_ENSURE_ARG_POINTER(aAccessible);
+
+  nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
+  NS_IF_ADDREF(*aAccessible = GetAccessible(node));
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAccessibilityService::GetAttachedAccessibleFor(nsIDOMNode *aDOMNode,
+                                                 nsIAccessible **aAccessible)
+{
+  NS_ENSURE_ARG(aDOMNode);
+  NS_ENSURE_ARG_POINTER(aAccessible);
+
+  nsCOMPtr<nsINode> node(do_QueryInterface(aDOMNode));
+  NS_IF_ADDREF(*aAccessible = GetAttachedAccessibleFor(node));
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsAccessibilityService::GetRelevantContentNodeFor(nsIDOMNode *aNode,
+                                                  nsIDOMNode **aRelevantNode)
+{
+  NS_ENSURE_ARG(aNode);
+  NS_ENSURE_ARG_POINTER(aRelevantNode);
+
+  nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
+  nsINode *relevantNode = GetRelevantContentNodeFor(node);
+  CallQueryInterface(relevantNode, aRelevantNode);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsAccessibilityService::GetStringRole(PRUint32 aRole, nsAString& aString)
 {
   if ( aRole >= NS_ARRAY_LENGTH(kRoleNames)) {
     aString.AssignLiteral("unknown");
     return NS_OK;
   }
 
   CopyUTF8toUTF16(kRoleNames[aRole], aString);
@@ -949,141 +991,111 @@ nsAccessibilityService::GetStringRelatio
     aString.AssignLiteral("unknown");
     return NS_OK;
   }
 
   CopyUTF8toUTF16(kRelationTypeNames[aRelationType], aString);
   return NS_OK;
 }
 
-
-/**
-  * GetAccessibleFor - get an nsIAccessible from a DOM node
-  */
-
-NS_IMETHODIMP
-nsAccessibilityService::GetAccessibleFor(nsIDOMNode *aNode,
-                                         nsIAccessible **aAccessible)
-{
-  NS_ENSURE_ARG_POINTER(aAccessible);
-
-  NS_IF_ADDREF(*aAccessible = GetAccessible(aNode));
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAccessibilityService::GetAttachedAccessibleFor(nsIDOMNode *aNode,
-                                                 nsIAccessible **aAccessible)
-{
-  NS_ENSURE_ARG(aNode);
-  NS_ENSURE_ARG_POINTER(aAccessible);
-
-  *aAccessible = nsnull;
-
-  nsCOMPtr<nsIDOMNode> relevantNode;
-  nsresult rv = GetRelevantContentNodeFor(aNode, getter_AddRefs(relevantNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (relevantNode != aNode)
-    return NS_OK;
-
-  return GetAccessibleFor(aNode, aAccessible);
-}
-
+// nsIAccesibilityService
 nsAccessible*
 nsAccessibilityService::GetAccessibleInShell(nsIDOMNode *aNode, 
                                              nsIPresShell *aPresShell) 
 {
   if (!aNode || !aPresShell)
     return nsnull;
 
+  nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(aPresShell));
   nsRefPtr<nsAccessible> accessible =
-    GetAccessible(aNode, aPresShell, weakShell);
+    GetAccessible(node, aPresShell, weakShell);
   return accessible;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessibilityService public
 
 nsAccessible *
-nsAccessibilityService::GetAccessible(nsIDOMNode *aNode)
+nsAccessibilityService::GetAccessible(nsINode *aNode)
 {
   if (!aNode)
     return nsnull;
 
   nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
   if (!presShell)
     return nsnull;
 
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
   nsRefPtr<nsAccessible> accessible = GetAccessible(aNode, presShell,
                                                     weakShell);
   return accessible;
 }
 
 nsAccessible *
-nsAccessibilityService::GetAccessibleInWeakShell(nsIDOMNode *aNode, 
+nsAccessibilityService::GetAccessibleInWeakShell(nsINode *aNode,
                                                  nsIWeakReference *aWeakShell) 
 {
   if (!aNode || !aWeakShell)
     return nsnull;
 
   nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(aWeakShell));
   nsRefPtr<nsAccessible> accessible = GetAccessible(aNode, presShell,
                                                     aWeakShell);
   return accessible;
 }
 
 nsAccessible *
-nsAccessibilityService::GetContainerAccessible(nsIDOMNode *aNode,
+nsAccessibilityService::GetContainerAccessible(nsINode *aNode,
                                                PRBool aCanCreate)
 {
   if (!aNode)
     return nsnull;
 
-  nsCOMPtr<nsINode> currNode(do_QueryInterface(aNode));
-  nsIDocument *document = currNode->GetCurrentDoc();
+  nsIDocument *document = aNode->GetCurrentDoc();
   if (!document)
     return nsnull;
 
   nsIPresShell *presShell = document->GetPrimaryShell();
   if (!presShell)
     return nsnull;
 
+  nsINode *currNode = aNode;
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
 
   nsAccessible *accessible = nsnull;
   while (!accessible && (currNode = currNode->GetNodeParent())) {
-    nsCOMPtr<nsIDOMNode> currDOMNode(do_QueryInterface(currNode));
-
-    nsCOMPtr<nsIDOMNode> relevantDOMNode;
-    GetAccService()->GetRelevantContentNodeFor(currDOMNode,
-                                               getter_AddRefs(relevantDOMNode));
-    if (relevantDOMNode) {
-      currNode = do_QueryInterface(relevantDOMNode);
-      currDOMNode.swap(relevantDOMNode);
-    }
+    currNode = GetAccService()->GetRelevantContentNodeFor(currNode);
 
     if (aCanCreate) {
-      accessible =
-        GetAccService()->GetAccessibleInWeakShell(currDOMNode, weakShell);
+      accessible = GetAccService()->GetAccessibleInWeakShell(currNode,
+                                                             weakShell);
 
     } else {
       // Only return cached accessible, don't create anything.
       nsRefPtr<nsAccessible> cachedAcc =
-        do_QueryObject(GetCachedAccessNode(currDOMNode, weakShell));
+        do_QueryObject(GetCachedAccessNode(currNode, weakShell));
 
       accessible = cachedAcc;
     }
   }
 
   return accessible;
 }
 
+nsAccessible *
+nsAccessibilityService::GetAttachedAccessibleFor(nsINode *aNode)
+{
+  nsINode *relevantNode = GetRelevantContentNodeFor(aNode);
+  if (relevantNode != aNode)
+    return nsnull;
+
+  return GetAccessible(relevantNode);
+}
+
 PRBool
 nsAccessibilityService::InitAccessible(nsAccessible *aAccessible,
                                        nsRoleMapEntry *aRoleMapEntry)
 {
   if (!aAccessible)
     return PR_FALSE;
 
   nsresult rv = aAccessible->Init(); // Add to cache, etc.
@@ -1125,84 +1137,67 @@ static PRBool HasRelatedContent(nsIConte
       return PR_TRUE;
     }
   }
 
   return PR_FALSE;
 }
 
 already_AddRefed<nsAccessible>
-nsAccessibilityService::GetAccessible(nsIDOMNode *aNode,
+nsAccessibilityService::GetAccessible(nsINode *aNode,
                                       nsIPresShell *aPresShell,
                                       nsIWeakReference *aWeakShell,
                                       PRBool *aIsHidden)
 {
   if (!aPresShell || !aWeakShell || gIsShutdown)
     return nsnull;
 
   NS_ASSERTION(aNode, "GetAccessible() called with no node.");
 
   if (aIsHidden)
     *aIsHidden = PR_FALSE;
 
-#ifdef DEBUG_A11Y
-  // Please leave this in for now, it's a convenient debugging method
-  nsAutoString name;
-  aNode->GetLocalName(name);
-  if (name.LowerCaseEqualsLiteral("h1")) 
-    printf("## aaronl debugging tag name\n");
-
-  nsAutoString attrib;
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aNode));
-  if (element) {
-    element->GetAttribute(NS_LITERAL_STRING("type"), attrib);
-    if (attrib.EqualsLiteral("statusbarpanel"))
-      printf("## aaronl debugging attribute\n");
-  }
-#endif
-
   // Check to see if we already have an accessible for this node in the cache.
   nsAccessNode* cachedAccessNode = GetCachedAccessNode(aNode, aWeakShell);
   if (cachedAccessNode) {
     // XXX: the cache might contain the access node for the DOM node that is not
     // accessible because of wrong cache update. In this case try to create new
     // accessible.
     nsRefPtr<nsAccessible> cachedAccessible = do_QueryObject(cachedAccessNode);
 
     if (cachedAccessible)
       return cachedAccessible.forget();
   }
 
   // No cache entry, so we must create the accessible.
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
-  if (!content) {
+  if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
     // If it's document node then ask accessible document loader for
     // document accessible, otherwise return null.
     nsCOMPtr<nsIDocument> document(do_QueryInterface(aNode));
-    if (document) {
-      nsAccessible *accessible = GetDocAccessible(document);
-      NS_IF_ADDREF(accessible);
-      return accessible;
-    }
-
-    return nsnull;
+    nsAccessible *accessible = GetDocAccessible(document);
+    NS_IF_ADDREF(accessible);
+    return accessible;
   }
 
   // We have a content node.
-  if (!content->IsInDoc()) {
+  if (!aNode->IsInDoc()) {
     NS_WARNING("Creating accessible for node with no document");
     return nsnull;
   }
 
-  if (content->GetOwnerDoc() != aPresShell->GetDocument()) {
+  if (aNode->GetOwnerDoc() != aPresShell->GetDocument()) {
     NS_ERROR("Creating accessible for wrong pres shell");
     return nsnull;
   }
 
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
+  if (!content)
+    return nsnull;
+
   // Frames can be deallocated when we flush layout, or when we call into code
   // that can flush layout, either directly, or via DOM manipulation, or some
   // CSS styles like :hover. We use the weak frame checks to avoid calling
   // methods on a dead frame pointer.
   nsWeakFrame weakFrame = content->GetPrimaryFrame();
 
   // Check frame to see if it is hidden.
   if (!weakFrame.GetFrame() ||
@@ -1266,17 +1261,17 @@ nsAccessibilityService::GetAccessible(ns
     content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::name, name);
     if (!name.IsEmpty()) {
       if (aIsHidden)
         *aIsHidden = PR_TRUE;
 
       return nsnull;
     }
 
-    newAcc = new nsHyperTextAccessibleWrap(aNode, aWeakShell);
+    newAcc = new nsHyperTextAccessibleWrap(content, aWeakShell);
     if (InitAccessible(newAcc, nsAccUtils::GetRoleMapEntry(aNode)))
       return newAcc.forget();
     return nsnull;
   }
 
   nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aNode);
   if (roleMapEntry && !nsCRT::strcmp(roleMapEntry->roleString, "presentation") &&
       !content->IsFocusable()) { // For presentation only
@@ -1303,19 +1298,18 @@ nsAccessibilityService::GetAccessible(ns
       // accessibles
       nsIContent *tableContent = content;
       while ((tableContent = tableContent->GetParent()) != nsnull) {
         nsIFrame *tableFrame = tableContent->GetPrimaryFrame();
         if (!tableFrame)
           continue;
 
         if (tableFrame->GetType() == nsAccessibilityAtoms::tableOuterFrame) {
-          nsCOMPtr<nsIDOMNode> tableNode(do_QueryInterface(tableContent));
           nsAccessible *tableAccessible =
-            GetAccessibleInWeakShell(tableNode, aWeakShell);
+            GetAccessibleInWeakShell(tableContent, aWeakShell);
 
           if (tableAccessible) {
             if (!roleMapEntry) {
               PRUint32 role = nsAccUtils::Role(tableAccessible);
               if (role != nsIAccessibleRole::ROLE_TABLE &&
                   role != nsIAccessibleRole::ROLE_TREE_TABLE) {
                 // No ARIA role and not in table: override role. For example,
                 // <table role="label"><td>content</td></table>
@@ -1323,17 +1317,17 @@ nsAccessibilityService::GetAccessible(ns
               }
             }
 
             break;
           }
 
 #ifdef DEBUG
           nsRoleMapEntry *tableRoleMapEntry =
-            nsAccUtils::GetRoleMapEntry(tableNode);
+            nsAccUtils::GetRoleMapEntry(tableContent);
           NS_ASSERTION(tableRoleMapEntry &&
                        !nsCRT::strcmp(tableRoleMapEntry->roleString, "presentation"),
                        "No accessible for parent table and it didn't have role of presentation");
 #endif
 
           if (!roleMapEntry && !content->IsFocusable()) {
             // Table-related descendants of presentation table are also
             // presentation if they aren't focusable and have not explicit ARIA
@@ -1362,22 +1356,22 @@ nsAccessibilityService::GetAccessible(ns
     if (roleMapEntry) {
       // Create ARIA grid/treegrid accessibles if node is not of a child or
       // valid child of HTML table and is not a HTML table.
       if ((!partOfHTMLTable || !tryTagNameOrFrame) &&
           frameType != nsAccessibilityAtoms::tableOuterFrame) {
 
         if (roleMapEntry->role == nsIAccessibleRole::ROLE_TABLE ||
             roleMapEntry->role == nsIAccessibleRole::ROLE_TREE_TABLE) {
-          newAcc = new nsARIAGridAccessibleWrap(aNode, aWeakShell);
+          newAcc = new nsARIAGridAccessibleWrap(content, aWeakShell);
 
         } else if (roleMapEntry->role == nsIAccessibleRole::ROLE_GRID_CELL ||
             roleMapEntry->role == nsIAccessibleRole::ROLE_ROWHEADER ||
             roleMapEntry->role == nsIAccessibleRole::ROLE_COLUMNHEADER) {
-          newAcc = new nsARIAGridCellAccessibleWrap(aNode, aWeakShell);
+          newAcc = new nsARIAGridCellAccessibleWrap(content, aWeakShell);
         }
       }
     }
 
     if (!newAcc && tryTagNameOrFrame) {
       // Prefer to use markup (mostly tag name, perhaps attributes) to
       // decide if and what kind of accessible to create.
       // The method creates accessibles for table related content too therefore
@@ -1413,35 +1407,35 @@ nsAccessibilityService::GetAccessible(ns
         newAcc = do_QueryObject(newAccessible);
       }
     }
   }
 
   if (!newAcc) {
     // Elements may implement nsIAccessibleProvider via XBL. This allows them to
     // say what kind of accessible to create.
-    newAcc = CreateAccessibleByType(aNode, aWeakShell);
+    newAcc = CreateAccessibleByType(content, aWeakShell);
   }
 
   if (!newAcc) {
     // Create generic accessibles for SVG and MathML nodes.
     if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
         content->Tag() == nsAccessibilityAtoms::svg) {
-      newAcc = new nsEnumRoleAccessible(aNode, aWeakShell,
+      newAcc = new nsEnumRoleAccessible(content, aWeakShell,
                                         nsIAccessibleRole::ROLE_DIAGRAM);
     }
     else if (content->GetNameSpaceID() == kNameSpaceID_MathML &&
              content->Tag() == nsAccessibilityAtoms::math) {
-      newAcc = new nsEnumRoleAccessible(aNode, aWeakShell,
+      newAcc = new nsEnumRoleAccessible(content, aWeakShell,
                                         nsIAccessibleRole::ROLE_EQUATION);
     }
   }
 
   if (!newAcc) {
-    newAcc = CreateAccessibleForDeckChild(weakFrame.GetFrame(), aNode,
+    newAcc = CreateAccessibleForDeckChild(weakFrame.GetFrame(), content,
                                           aWeakShell);
   }
 
   // If no accessible, see if we need to create a generic accessible because
   // of some property that makes this object interesting
   // We don't do this for <body>, <html>, <window>, <dialog> etc. which 
   // correspond to the doc accessible and will be created in any case
   if (!newAcc && content->Tag() != nsAccessibilityAtoms::body && content->GetParent() && 
@@ -1449,21 +1443,21 @@ nsAccessibilityService::GetAccessible(ns
        (isHTML && nsCoreUtils::HasClickListener(content)) ||
        HasUniversalAriaProperty(content) || roleMapEntry ||
        HasRelatedContent(content) || nsCoreUtils::IsXLink(content))) {
     // This content is focusable or has an interesting dynamic content accessibility property.
     // If it's interesting we need it in the accessibility hierarchy so that events or
     // other accessibles can point to it, or so that it can hold a state, etc.
     if (isHTML) {
       // Interesting HTML container which may have selectable text and/or embedded objects
-      newAcc = new nsHyperTextAccessibleWrap(aNode, aWeakShell);
+      newAcc = new nsHyperTextAccessibleWrap(content, aWeakShell);
     }
     else {  // XUL, SVG, MathML etc.
       // Interesting generic non-HTML container
-      newAcc = new nsAccessibleWrap(aNode, aWeakShell);
+      newAcc = new nsAccessibleWrap(content, aWeakShell);
     }
   }
 
   if (InitAccessible(newAcc, roleMapEntry))
     return newAcc.forget();
   return nsnull;
 }
 
@@ -1534,20 +1528,18 @@ nsAccessibilityService::HasUniversalAria
          nsAccUtils::HasDefinedARIAToken(aContent, nsAccessibilityAtoms::aria_invalid) ||
          aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label) ||
          aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby) ||
          nsAccUtils::HasDefinedARIAToken(aContent, nsAccessibilityAtoms::aria_live) ||
          nsAccUtils::HasDefinedARIAToken(aContent, nsAccessibilityAtoms::aria_owns) ||
          nsAccUtils::HasDefinedARIAToken(aContent, nsAccessibilityAtoms::aria_relevant);
 }
 
-// nsIAccessibleRetrieval
-NS_IMETHODIMP
-nsAccessibilityService::GetRelevantContentNodeFor(nsIDOMNode *aNode,
-                                                  nsIDOMNode **aRelevantNode)
+nsINode *
+nsAccessibilityService::GetRelevantContentNodeFor(nsINode *aNode)
 {
   // The method returns node that is relevant for attached accessible check.
   // Sometimes element that is XBL widget hasn't accessible children in
   // anonymous content. This method check whether given node can be accessible
   // by looking through all nested bindings that given node is anonymous for. If
   // there is XBL widget that deniedes to be accessible for given node then the
   // method returns that XBL widget otherwise it returns given node.
 
@@ -1558,80 +1550,75 @@ nsAccessibilityService::GetRelevantConte
   // 2. xul:texbox has html:input in anonymous content. When given node is
   // html:input elmement then we return xul:textbox since xul:textbox doesn't
   // allow accessible nodes in anonymous content.
   // 3. xforms:input that is hosted in xul document contains xul:textbox
   // element. When given node is html:input or xul:textbox then we return
   // xforms:input element since xforms:input hasn't accessible anonymous
   // children.
 
-  NS_ENSURE_ARG(aNode);
-  NS_ENSURE_ARG_POINTER(aRelevantNode);
+  if (!aNode)
+    return nsnull;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
   if (content) {
     // Build stack of binding parents so we can walk it in reverse.
     nsIContent *bindingParent;
     nsCOMArray<nsIContent> bindingsStack;
 
     for (bindingParent = content->GetBindingParent(); bindingParent != nsnull &&
          bindingParent != bindingParent->GetBindingParent();
          bindingParent = bindingParent->GetBindingParent()) {
       bindingsStack.AppendObject(bindingParent);
     }
 
     PRInt32 bindingsCount = bindingsStack.Count();
     for (PRInt32 index = bindingsCount - 1; index >= 0 ; index--) {
       bindingParent = bindingsStack[index];
-      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<nsIWeakReference> weakShell;
-        GetShellFromNode(bindingNode, getter_AddRefs(weakShell));
+
+      // Try to get an accessible by type since XBL widget can be accessible
+      // only if it implements nsIAccessibleProvider interface.
+      nsCOMPtr<nsIWeakReference> weakShell =
+        nsCoreUtils::GetWeakShellFor(bindingParent);
 
-        // XXX: it's a hack we should try the cache before, otherwise to cache
-        // the accessible.
-        nsRefPtr<nsAccessible> accessible =
-          CreateAccessibleByType(bindingNode, weakShell);
+      // XXX: it's a hack we should try the cache before, otherwise to cache
+      // the accessible.
+      nsRefPtr<nsAccessible> accessible =
+        CreateAccessibleByType(bindingParent, weakShell);
 
-        if (accessible) {
-          if (!accessible->GetAllowsAnonChildAccessibles()) {
-            NS_ADDREF(*aRelevantNode = bindingNode);
-            return NS_OK;
-          }
-        }
+      if (accessible) {
+        if (!accessible->GetAllowsAnonChildAccessibles())
+          return bindingParent;
       }
     }
   }
 
-  NS_ADDREF(*aRelevantNode = aNode);
-  return NS_OK;
+  return aNode;
 }
 
 already_AddRefed<nsAccessible>
 nsAccessibilityService::GetAreaAccessible(nsIFrame *aImageFrame,
-                                          nsIDOMNode *aAreaNode,
+                                          nsINode *aAreaNode,
                                           nsIWeakReference *aWeakShell)
 {
   // Check if frame is an image frame, and content is <area>.
   nsIImageFrame *imageFrame = do_QueryFrame(aImageFrame);
   if (!imageFrame)
     return nsnull;
 
   nsCOMPtr<nsIDOMHTMLAreaElement> areaElmt = do_QueryInterface(aAreaNode);
   if (!areaElmt)
     return nsnull;
 
   // Try to get image map accessible from the global cache or create it
   // if failed.
   nsRefPtr<nsAccessible> imageAcc;
 
-  nsCOMPtr<nsIDOMNode> imageNode(do_QueryInterface(aImageFrame->GetContent()));
-  nsAccessNode *cachedImgAcc = GetCachedAccessNode(imageNode, aWeakShell);
+  nsAccessNode *cachedImgAcc = GetCachedAccessNode(aImageFrame->GetContent(),
+                                                   aWeakShell);
   if (cachedImgAcc)
     imageAcc = do_QueryObject(cachedImgAcc);
 
   if (!imageAcc) {
     nsCOMPtr<nsIAccessible> imageAccessible;
     CreateHTMLImageAccessible(aImageFrame,
                               getter_AddRefs(imageAccessible));
 
@@ -1648,247 +1635,238 @@ nsAccessibilityService::GetAreaAccessibl
   if (!cachedAreaAcc)
     return nsnull;
 
   nsRefPtr<nsAccessible> areaAcc = do_QueryObject(cachedAreaAcc);
   return areaAcc.forget();
 }
 
 already_AddRefed<nsAccessible>
-nsAccessibilityService::CreateAccessibleByType(nsIDOMNode *aNode,
+nsAccessibilityService::CreateAccessibleByType(nsIContent *aContent,
                                                nsIWeakReference *aWeakShell)
 {
-  nsCOMPtr<nsIAccessibleProvider> accessibleProvider(do_QueryInterface(aNode));
+  nsCOMPtr<nsIAccessibleProvider> accessibleProvider(do_QueryInterface(aContent));
   if (!accessibleProvider)
     return nsnull;
 
   PRInt32 type;
   nsresult rv = accessibleProvider->GetAccessibleType(&type);
   if (NS_FAILED(rv))
     return nsnull;
 
   nsRefPtr<nsAccessible> accessible;
   if (type == nsIAccessibleProvider::OuterDoc) {
-    accessible = new nsOuterDocAccessible(aNode, aWeakShell);
+    accessible = new nsOuterDocAccessible(aContent, aWeakShell);
     return accessible.forget();
   }
 
   switch (type)
   {
 #ifdef MOZ_XUL
     case nsIAccessibleProvider::NoAccessible:
       return nsnull;
 
     // XUL controls
     case nsIAccessibleProvider::XULAlert:
-      accessible = new nsXULAlertAccessible(aNode, aWeakShell);
+      accessible = new nsXULAlertAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULButton:
-      accessible = new nsXULButtonAccessible(aNode, aWeakShell);
+      accessible = new nsXULButtonAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULCheckbox:
-      accessible = new nsXULCheckboxAccessible(aNode, aWeakShell);
+      accessible = new nsXULCheckboxAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULColorPicker:
-      accessible = new nsXULColorPickerAccessible(aNode, aWeakShell);
+      accessible = new nsXULColorPickerAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULColorPickerTile:
-      accessible = new nsXULColorPickerTileAccessible(aNode, aWeakShell);
+      accessible = new nsXULColorPickerTileAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULCombobox:
-      accessible = new nsXULComboboxAccessible(aNode, aWeakShell);
+      accessible = new nsXULComboboxAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULDropmarker:
-      accessible = new nsXULDropmarkerAccessible(aNode, aWeakShell);
+      accessible = new nsXULDropmarkerAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULGroupbox:
-      accessible = new nsXULGroupboxAccessible(aNode, aWeakShell);
+      accessible = new nsXULGroupboxAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULImage:
     {
-      // Don't include nameless images in accessible tree
-      nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aNode));
-      if (!elt)
+      // Don't include nameless images in accessible tree.
+      if (!aContent->HasAttr(kNameSpaceID_None,
+                             nsAccessibilityAtoms::tooltiptext))
         return nsnull;
 
-      PRBool hasTextEquivalent;
-      // Prefer value over tooltiptext
-      elt->HasAttribute(NS_LITERAL_STRING("tooltiptext"), &hasTextEquivalent);
-      if (!hasTextEquivalent)
-        return nsnull;
-
-      accessible = new nsHTMLImageAccessibleWrap(aNode, aWeakShell);
+      accessible = new nsHTMLImageAccessibleWrap(aContent, aWeakShell);
       break;
     }
     case nsIAccessibleProvider::XULLink:
-      accessible = new nsXULLinkAccessible(aNode, aWeakShell);
+      accessible = new nsXULLinkAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULListbox:
-      accessible = new nsXULListboxAccessibleWrap(aNode, aWeakShell);
+      accessible = new nsXULListboxAccessibleWrap(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULListCell:
-      accessible = new nsXULListCellAccessibleWrap(aNode, aWeakShell);
+      accessible = new nsXULListCellAccessibleWrap(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULListHead:
-      accessible = new nsXULColumnsAccessible(aNode, aWeakShell);
+      accessible = new nsXULColumnsAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULListHeader:
-      accessible = new nsXULColumnItemAccessible(aNode, aWeakShell);
+      accessible = new nsXULColumnItemAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULListitem:
-      accessible = new nsXULListitemAccessible(aNode, aWeakShell);
+      accessible = new nsXULListitemAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULMenubar:
-      accessible = new nsXULMenubarAccessible(aNode, aWeakShell);
+      accessible = new nsXULMenubarAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULMenuitem:
-      accessible = new nsXULMenuitemAccessibleWrap(aNode, aWeakShell);
+      accessible = new nsXULMenuitemAccessibleWrap(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULMenupopup:
     {
 #ifdef MOZ_ACCESSIBILITY_ATK
       // ATK considers this node to be redundant when within menubars, and it makes menu
       // navigation with assistive technologies more difficult
       // XXX In the future we will should this for consistency across the nsIAccessible
       // implementations on each platform for a consistent scripting environment, but
       // then strip out redundant accessibles in the nsAccessibleWrap class for each platform.
-      nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
-      if (content) {
-        nsIContent *parent = content->GetParent();
-        if (parent && parent->NodeInfo()->Equals(nsAccessibilityAtoms::menu, kNameSpaceID_XUL)) {
-          return nsnull;
-        }
-      }
+      nsIContent *parent = aContent->GetParent();
+      if (parent && parent->NodeInfo()->Equals(nsAccessibilityAtoms::menu,
+                                               kNameSpaceID_XUL))
+        return nsnull;
 #endif
-      accessible = new nsXULMenupopupAccessible(aNode, aWeakShell);
+      accessible = new nsXULMenupopupAccessible(aContent, aWeakShell);
       break;
     }
     case nsIAccessibleProvider::XULMenuSeparator:
-      accessible = new nsXULMenuSeparatorAccessible(aNode, aWeakShell);
+      accessible = new nsXULMenuSeparatorAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULPane:
-      accessible = new nsEnumRoleAccessible(aNode, aWeakShell,
+      accessible = new nsEnumRoleAccessible(aContent, aWeakShell,
                                             nsIAccessibleRole::ROLE_PANE);
       break;
     case nsIAccessibleProvider::XULProgressMeter:
-      accessible = new nsXULProgressMeterAccessible(aNode, aWeakShell);
+      accessible = new nsXULProgressMeterAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULStatusBar:
-      accessible = new nsXULStatusBarAccessible(aNode, aWeakShell);
+      accessible = new nsXULStatusBarAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULScale:
-      accessible = new nsXULSliderAccessible(aNode, aWeakShell);
+      accessible = new nsXULSliderAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULRadioButton:
-      accessible = new nsXULRadioButtonAccessible(aNode, aWeakShell);
+      accessible = new nsXULRadioButtonAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULRadioGroup:
-      accessible = new nsXULRadioGroupAccessible(aNode, aWeakShell);
+      accessible = new nsXULRadioGroupAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTab:
-      accessible = new nsXULTabAccessible(aNode, aWeakShell);
+      accessible = new nsXULTabAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTabs:
-      accessible = new nsXULTabsAccessible(aNode, aWeakShell);
+      accessible = new nsXULTabsAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTabpanels:
-      accessible = new nsXULTabpanelsAccessible(aNode, aWeakShell);
+      accessible = new nsXULTabpanelsAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULText:
-      accessible = new nsXULTextAccessible(aNode, aWeakShell);
+      accessible = new nsXULTextAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTextBox:
-      accessible = new nsXULTextFieldAccessible(aNode, aWeakShell);
+      accessible = new nsXULTextFieldAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULThumb:
-      accessible = new nsXULThumbAccessible(aNode, aWeakShell);
+      accessible = new nsXULThumbAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTree:
-      return CreateAccessibleForXULTree(aNode, aWeakShell);
+      return CreateAccessibleForXULTree(aContent, aWeakShell);
 
     case nsIAccessibleProvider::XULTreeColumns:
-      accessible = new nsXULTreeColumnsAccessible(aNode, aWeakShell);
+      accessible = new nsXULTreeColumnsAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTreeColumnItem:
-      accessible = new nsXULColumnItemAccessible(aNode, aWeakShell);
+      accessible = new nsXULColumnItemAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULToolbar:
-      accessible = new nsXULToolbarAccessible(aNode, aWeakShell);
+      accessible = new nsXULToolbarAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULToolbarSeparator:
-      accessible = new nsXULToolbarSeparatorAccessible(aNode, aWeakShell);
+      accessible = new nsXULToolbarSeparatorAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULTooltip:
-      accessible = new nsXULTooltipAccessible(aNode, aWeakShell);
+      accessible = new nsXULTooltipAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XULToolbarButton:
-      accessible = new nsXULToolbarButtonAccessible(aNode, aWeakShell);
+      accessible = new nsXULToolbarButtonAccessible(aContent, aWeakShell);
       break;
 #endif // MOZ_XUL
 
 #ifndef DISABLE_XFORMS_HOOKS
     // XForms elements
     case nsIAccessibleProvider::XFormsContainer:
-      accessible = new nsXFormsContainerAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsContainerAccessible(aContent, aWeakShell);
       break;
 
     case nsIAccessibleProvider::XFormsLabel:
-      accessible = new nsXFormsLabelAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsLabelAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsOutput:
-      accessible = new nsXFormsOutputAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsOutputAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsTrigger:
-      accessible = new nsXFormsTriggerAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsTriggerAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsInput:
-      accessible = new nsXFormsInputAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsInputAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsInputBoolean:
-      accessible = new nsXFormsInputBooleanAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsInputBooleanAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsInputDate:
-      accessible = new nsXFormsInputDateAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsInputDateAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsSecret:
-      accessible = new nsXFormsSecretAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsSecretAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsSliderRange:
-      accessible = new nsXFormsRangeAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsRangeAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsSelect:
-      accessible = new nsXFormsSelectAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsSelectAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsChoices:
-      accessible = new nsXFormsChoicesAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsChoicesAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsSelectFull:
-      accessible = new nsXFormsSelectFullAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsSelectFullAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsItemCheckgroup:
-      accessible = new nsXFormsItemCheckgroupAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsItemCheckgroupAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsItemRadiogroup:
-      accessible = new nsXFormsItemRadiogroupAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsItemRadiogroupAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsSelectCombobox:
-      accessible = new nsXFormsSelectComboboxAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsSelectComboboxAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsItemCombobox:
-      accessible = new nsXFormsItemComboboxAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsItemComboboxAccessible(aContent, aWeakShell);
       break;
 
     case nsIAccessibleProvider::XFormsDropmarkerWidget:
-      accessible = new nsXFormsDropmarkerWidgetAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsDropmarkerWidgetAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsCalendarWidget:
-      accessible = new nsXFormsCalendarWidgetAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsCalendarWidgetAccessible(aContent, aWeakShell);
       break;
     case nsIAccessibleProvider::XFormsComboboxPopupWidget:
-      accessible = new nsXFormsComboboxPopupWidgetAccessible(aNode, aWeakShell);
+      accessible = new nsXFormsComboboxPopupWidgetAccessible(aContent, aWeakShell);
       break;
 #endif
 
     default:
       return nsnull;
   }
 
   return accessible.forget();
@@ -1994,63 +1972,62 @@ NS_GetAccessibilityService(nsIAccessibil
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessibilityService private (DON'T put methods here)
 
 already_AddRefed<nsAccessible>
 nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame,
-                                                     nsIDOMNode *aNode,
+                                                     nsIContent *aContent,
                                                      nsIWeakReference *aWeakShell)
 {
   nsRefPtr<nsAccessible> accessible;
 
   if (aFrame->GetType() == nsAccessibilityAtoms::boxFrame ||
       aFrame->GetType() == nsAccessibilityAtoms::scrollFrame) {
 
     nsIFrame* parentFrame = aFrame->GetParent();
     if (parentFrame && parentFrame->GetType() == nsAccessibilityAtoms::deckFrame) {
       // If deck frame is for xul:tabpanels element then the given node has
       // tabpanel accessible.
       nsCOMPtr<nsIContent> parentContent = parentFrame->GetContent();
 #ifdef MOZ_XUL
       if (parentContent->NodeInfo()->Equals(nsAccessibilityAtoms::tabpanels,
                                             kNameSpaceID_XUL)) {
-        accessible = new nsXULTabpanelAccessible(aNode, aWeakShell);
+        accessible = new nsXULTabpanelAccessible(aContent, aWeakShell);
       } else
 #endif
         accessible =
-          new nsEnumRoleAccessible(aNode, aWeakShell,
+          new nsEnumRoleAccessible(aContent, aWeakShell,
                                    nsIAccessibleRole::ROLE_PROPERTYPAGE);
     }
   }
 
   return accessible.forget();
 }
 
 #ifdef MOZ_XUL
 already_AddRefed<nsAccessible>
-nsAccessibilityService::CreateAccessibleForXULTree(nsIDOMNode *aNode,
+nsAccessibilityService::CreateAccessibleForXULTree(nsIContent *aContent,
                                                    nsIWeakReference *aWeakShell)
 {
-  nsCOMPtr<nsITreeBoxObject> treeBoxObj;
-  nsCoreUtils::GetTreeBoxObject(aNode, getter_AddRefs(treeBoxObj));
+  nsCOMPtr<nsITreeBoxObject> treeBoxObj = nsCoreUtils::GetTreeBoxObject(aContent);
   if (!treeBoxObj)
     return nsnull;
 
   nsCOMPtr<nsITreeColumns> treeColumns;
   treeBoxObj->GetColumns(getter_AddRefs(treeColumns));
   if (!treeColumns)
     return nsnull;
 
   nsRefPtr<nsAccessible> accessible;
 
   PRInt32 count = 0;
   treeColumns->GetCount(&count);
   if (count == 1) // outline of list accessible
-    accessible = new nsXULTreeAccessible(aNode, aWeakShell);
+    accessible = new nsXULTreeAccessible(aContent, aWeakShell);
   else // table or tree table accessible
-    accessible = new nsXULTreeGridAccessibleWrap(aNode, aWeakShell);
+    accessible = new nsXULTreeGridAccessibleWrap(aContent, aWeakShell);
 
   return accessible.forget();
 }
 #endif
--- a/accessible/src/base/nsAccessibilityService.h
+++ b/accessible/src/base/nsAccessibilityService.h
@@ -39,30 +39,18 @@
 #ifndef __nsAccessibilityService_h__
 #define __nsAccessibilityService_h__
 
 #include "nsIAccessibilityService.h"
 
 #include "a11yGeneric.h"
 #include "nsAccDocManager.h"
 
-#include "nsCOMArray.h"
 #include "nsIObserver.h"
 
-class nsAccessNode;
-class nsAccessible;
-class nsIFrame;
-class nsIWeakReference;
-class nsIDOMNode;
-class nsObjectFrame;
-class nsIDocShell;
-class nsIPresShell;
-class nsIContent;
-struct nsRoleMapEntry;
-
 class nsAccessibilityService : public nsAccDocManager,
                                public nsIAccessibilityService,
                                public nsIObserver
 {
 public:
   virtual ~nsAccessibilityService();
 
   NS_DECL_ISUPPORTS_INHERITED
@@ -136,73 +124,91 @@ public:
 
   virtual void NotifyOfAnchorJumpTo(nsIContent *aTarget);
 
   virtual nsresult FireAccessibleEvent(PRUint32 aEvent, nsIAccessible *aTarget);
 
   // nsAccessibiltiyService
 
   /**
-   * Return presentation shell for the given node.
-   *
-   * @param aNode - the given DOM node.
-   */
-  static nsresult GetShellFromNode(nsIDOMNode *aNode,
-                                   nsIWeakReference **weakShell);
-
-  /**
    * Return true if accessibility service has been shutdown.
    */
   static PRBool IsShutdown() { return gIsShutdown; }
 
   /**
    * Return an accessible for the given DOM node.
    *
    * @param  aNode       [in] the given node
    * @param  aPresShell  [in] the pres shell of the node
    * @param  aWeakShell  [in] the weak shell for the pres shell
    * @param  aIsHidden   [out, optional] indicates whether the node's frame is
    *                       hidden
    */
   already_AddRefed<nsAccessible>
-    GetAccessible(nsIDOMNode *aNode, nsIPresShell *aPresShell,
+    GetAccessible(nsINode *aNode, nsIPresShell *aPresShell,
                   nsIWeakReference *aWeakShell, PRBool *aIsHidden = nsnull);
 
   /**
    * Return an accessible for the given DOM node.
    */
-  nsAccessible *GetAccessible(nsIDOMNode *aNode);
+  nsAccessible *GetAccessible(nsINode *aNode);
 
   /**
    * Return an accessible for a DOM node in the given pres shell.
    * 
    * @param aNode       [in] the given node.
    * @param aPresShell  [in] the presentation shell of the given node.
    */
-  nsAccessible *GetAccessibleInWeakShell(nsIDOMNode *aNode,
+  nsAccessible *GetAccessibleInWeakShell(nsINode *aNode,
                                          nsIWeakReference *aPresShell);
 
   /**
    * Return the first accessible parent of a DOM node.
    *
    * @param aDOMNode    [in] the DOM node to get an accessible for
    * @param aCanCreate  [in] specifies if accessible can be created if it didn't
    *                     exist
    */
-  nsAccessible *GetContainerAccessible(nsIDOMNode *aNode, PRBool aCanCreate);
+  nsAccessible *GetContainerAccessible(nsINode *aNode, PRBool aCanCreate);
+
+  /**
+   * The same as getAccessibleFor method except it returns accessible only if
+   * it is attached, i.e. accessible is certified to be a descendant of the root
+   * accessible.
+   *
+   * XXX: this method must go away once we'll implement correct accessible tree.
+   *
+   * @param  aNode  [in] the DOM node to get an accessible for
+   * @return         the accessible for the given DOM node
+   */
+  nsAccessible *GetAttachedAccessibleFor(nsINode *aNode);
+
+  /**
+   * Return an DOM node that is relevant to attached accessible check. This
+   * node is either from bindings chain if given node is anonymous and owner
+   * binding denies accessible in anonymous content or given node (it's not
+   * important whether it is accessible or not). This method doesn't create
+   * accessible object for returned node.
+   *
+   * XXX: this method must go away once we'll implement correct accessible tree.
+   *
+   * @param  aNode  [in] the DOM node to get relevant content node
+   * @return         the DOM node for parent attached accessible
+   */
+  nsINode *GetRelevantContentNodeFor(nsINode *aNode);
 
   /**
    * Return an access node for the DOM node in the given presentation shell if
    * the access node already exists, otherwise null.
    *
    * @param  aNode       [in] the DOM node to get an access node for
    * @param  aPresShell  [in] the presentation shell which contains layout info
    *                       for the DOM node
    */
-  nsAccessNode* GetCachedAccessNode(nsIDOMNode *aNode,
+  nsAccessNode* GetCachedAccessNode(nsINode *aNode,
                                     nsIWeakReference *aShell);
 
   /**
    * Initialize an accessible and cache it. The method should be called for
    * every created accessible.
    *
    * @param  aAccessible    [in] accessible to initialize.
    * @param  aRoleMapEntry  [in] the role map entry role the ARIA role or nsnull
@@ -229,59 +235,59 @@ private:
   /**
    * Shutdowns accessibility service.
    */
   void Shutdown();
 
   /**
    * Return presentation shell, DOM node for the given frame.
    *
-   * @param aFrame - the given frame
-   * @param aShell [out] - presentation shell for DOM node associated with the
-   *                 given frame
-   * @param aContent [out] - DOM node associated with the given frame
+   * @param aFrame    [in] the given frame
+   * @param aShell    [out] presentation shell for DOM node associated with the
+   *                    given frame
+   * @param aContent  [out] DOM node associated with the given frame
    */
-  nsresult GetInfo(nsIFrame *aFrame,
-                   nsIWeakReference **aShell,
-                   nsIDOMNode **aContent);
+  nsresult GetInfo(nsIFrame *aFrame, nsIWeakReference **aShell,
+                   nsIContent **aContent);
 
   /**
    * Return accessible for HTML area element associated with an image map.
    */
   already_AddRefed<nsAccessible>
-    GetAreaAccessible(nsIFrame *aImageFrame, nsIDOMNode *aAreaNode,
+    GetAreaAccessible(nsIFrame *aImageFrame, nsINode *aAreaNode,
                       nsIWeakReference *aWeakShell);
 
   /**
    * Create accessible for the element implementing nsIAccessibleProvider
    * interface.
    */
   already_AddRefed<nsAccessible>
-    CreateAccessibleByType(nsIDOMNode *aNode, nsIWeakReference *aWeakShell);
+    CreateAccessibleByType(nsIContent *aContent, nsIWeakReference *aWeakShell);
 
   /**
    * Create accessible for HTML node by tag name.
    */
   already_AddRefed<nsAccessible>
     CreateHTMLAccessibleByMarkup(nsIFrame *aFrame, nsIWeakReference *aWeakShell,
-                                 nsIDOMNode *aNode);
+                                 nsINode *aNode);
 
   /**
    * Create accessible if parent is a deck frame.
    */
   already_AddRefed<nsAccessible>
-    CreateAccessibleForDeckChild(nsIFrame *aFrame, nsIDOMNode *aNode,
+    CreateAccessibleForDeckChild(nsIFrame *aFrame, nsIContent *aContent,
                                  nsIWeakReference *aWeakShell);
 
 #ifdef MOZ_XUL
   /**
    * Create accessible for XUL tree element.
    */
   already_AddRefed<nsAccessible>
-    CreateAccessibleForXULTree(nsIDOMNode *aNode, nsIWeakReference *aWeakShell);
+    CreateAccessibleForXULTree(nsIContent *aContent,
+                               nsIWeakReference *aWeakShell);
 #endif
 
   /**
    * Reference for accessibility service.
    */
   static nsAccessibilityService *gAccessibilityService;
 
   /**
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -185,19 +185,19 @@ nsresult nsAccessible::QueryInterface(RE
       return NS_OK;
     }
     return NS_ERROR_NO_INTERFACE;
   }
 
   return nsAccessNodeWrap::QueryInterface(aIID, aInstancePtr);
 }
 
-nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsAccessNodeWrap(aNode, aShell), 
-  mParent(nsnull), mRoleMapEntry(nsnull),
-  mAreChildrenInitialized(PR_FALSE)
+nsAccessible::nsAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsAccessNodeWrap(aContent, aShell),
+  mParent(nsnull), mAreChildrenInitialized(PR_FALSE), mRoleMapEntry(nsnull)
 {
 #ifdef NS_DEBUG_X
    {
      nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aShell));
      printf(">>> %p Created Acc - DOM: %p  PS: %p", 
             (void*)static_cast<nsIAccessible*>(this), (void*)aNode,
             (void*)shell.get());
     nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
@@ -235,46 +235,42 @@ nsAccessible::GetName(nsAString& aName)
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   GetARIAName(aName);
   if (!aName.IsEmpty())
     return NS_OK;
 
-  nsCOMPtr<nsIXBLAccessible> xblAccessible(do_QueryInterface(mDOMNode));
+  nsCOMPtr<nsIXBLAccessible> xblAccessible(do_QueryInterface(mContent));
   if (xblAccessible) {
     xblAccessible->GetAccessibleName(aName);
     if (!aName.IsEmpty())
       return NS_OK;
   }
 
   nsresult rv = GetNameInternal(aName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!aName.IsEmpty())
     return NS_OK;
 
   // In the end get the name from tooltip.
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
   nsIAtom *tooltipAttr = nsnull;
 
-  if (content->IsHTML())
+  if (mContent->IsHTML())
     tooltipAttr = nsAccessibilityAtoms::title;
-  else if (content->IsXUL())
+  else if (mContent->IsXUL())
     tooltipAttr = nsAccessibilityAtoms::tooltiptext;
   else
     return NS_OK;
 
   // XXX: if CompressWhiteSpace worked on nsAString we could avoid a copy.
   nsAutoString name;
-  if (content->GetAttr(kNameSpaceID_None, tooltipAttr, name)) {
+  if (mContent->GetAttr(kNameSpaceID_None, tooltipAttr, name)) {
     name.CompressWhitespace();
     aName = name;
     return NS_OK_NAME_FROM_TOOLTIP;
   }
 
   if (rv != NS_OK_EMPTY_NAME)
     aName.SetIsVoid(PR_TRUE);
 
@@ -286,47 +282,43 @@ NS_IMETHODIMP nsAccessible::GetDescripti
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   // There are 4 conditions that make an accessible have no accDescription:
   // 1. it's a text node; or
   // 2. It has no DHTML describedby property
   // 3. it doesn't have an accName; or
   // 4. its title attribute already equals to its accName nsAutoString name; 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  NS_ASSERTION(content, "No content of valid accessible!");
-  if (!content)
-    return NS_ERROR_FAILURE;
-
-  if (!content->IsNodeOfType(nsINode::eTEXT)) {
+
+  if (!mContent->IsNodeOfType(nsINode::eTEXT)) {
     nsAutoString description;
     nsresult rv = nsTextEquivUtils::
       GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
                              description);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (description.IsEmpty()) {
-      PRBool isXUL = content->IsXUL();
+      PRBool isXUL = mContent->IsXUL();
       if (isXUL) {
         // Try XUL <description control="[id]">description text</description>
         nsIContent *descriptionContent =
-          nsCoreUtils::FindNeighbourPointingToNode(content,
+          nsCoreUtils::FindNeighbourPointingToNode(mContent,
                                                    nsAccessibilityAtoms::control,
                                                    nsAccessibilityAtoms::description);
 
         if (descriptionContent) {
           // We have a description content node
           nsTextEquivUtils::
             AppendTextEquivFromContent(this, descriptionContent, &description);
         }
       }
       if (description.IsEmpty()) {
         nsIAtom *descAtom = isXUL ? nsAccessibilityAtoms::tooltiptext :
                                     nsAccessibilityAtoms::title;
-        if (content->GetAttr(kNameSpaceID_None, descAtom, description)) {
+        if (mContent->GetAttr(kNameSpaceID_None, descAtom, description)) {
           nsAutoString name;
           GetName(name);
           if (name.IsEmpty() || description == name) {
             // Don't use tooltip for a description if this object
             // has no name or the tooltip is the same as the name
             description.Truncate();
           }
         }
@@ -396,38 +388,36 @@ GetAccessModifierMask(nsIContent* aConte
   return NS_SUCCEEDED(rv) ? accessModifierMask : 0;
 }
 
 NS_IMETHODIMP
 nsAccessible::GetKeyboardShortcut(nsAString& aAccessKey)
 {
   aAccessKey.Truncate();
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (!content)
+  if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  PRUint32 key = nsCoreUtils::GetAccessKeyFor(content);
-  if (!key && content->IsElement()) {
+  PRUint32 key = nsCoreUtils::GetAccessKeyFor(mContent);
+  if (!key && mContent->IsElement()) {
     // Copy access key from label node unless it is labeled
     // via an ancestor <label>, in which case that would be redundant
-    nsCOMPtr<nsIContent> labelContent(nsCoreUtils::GetLabelContent(content));
-    nsCOMPtr<nsINode> thisNode = do_QueryInterface(mDOMNode);
-    if (labelContent && !nsCoreUtils::IsAncestorOf(labelContent, thisNode))
+    nsCOMPtr<nsIContent> labelContent(nsCoreUtils::GetLabelContent(mContent));
+    if (labelContent && !nsCoreUtils::IsAncestorOf(labelContent, mContent))
       key = nsCoreUtils::GetAccessKeyFor(labelContent);
   }
 
   if (!key)
     return NS_OK;
 
   nsAutoString accesskey(key);
 
   // Append the modifiers in reverse order, result: Control+Alt+Shift+Meta+<key>
   nsAutoString propertyKey;
-  PRInt32 modifierMask = GetAccessModifierMask(content);
+  PRInt32 modifierMask = GetAccessModifierMask(mContent);
   if (modifierMask & NS_MODIFIER_META) {
     propertyKey.AssignLiteral("VK_META");
     nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
   }
   if (modifierMask & NS_MODIFIER_SHIFT) {
     propertyKey.AssignLiteral("VK_SHIFT");
     nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
   }
@@ -624,19 +614,18 @@ nsresult nsAccessible::GetFullKeyName(co
 
 PRBool nsAccessible::IsVisible(PRBool *aIsOffscreen) 
 {
   // We need to know if at least a kMinPixels around the object is visible
   // Otherwise it will be marked nsIAccessibleStates::STATE_OFFSCREEN
   // The STATE_INVISIBLE flag is for elements which are programmatically hidden
   
   *aIsOffscreen = PR_TRUE;
-  if (!mDOMNode) {
-    return PR_FALSE; // Defunct object
-  }
+  if (IsDefunct())
+    return PR_FALSE;
 
   const PRUint16 kMinPixels  = 12;
    // Set up the variables we need, return false if we can't get at them all
   nsCOMPtr<nsIPresShell> shell(GetPresShell());
   if (!shell) 
     return PR_FALSE;
 
   nsIFrame *frame = GetFrame();
@@ -681,19 +670,17 @@ PRBool nsAccessible::IsVisible(PRBool *a
     if (isEmpty && !(frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
       // Consider zero area objects hidden unless they are absolutely positioned
       // or floating and may have descendants that have a non-zero size
       return PR_FALSE;
     }
   }
 
   // The frame intersects the viewport, but we need to check the parent view chain :(
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
+  nsIDocument* doc = mContent->GetOwnerDoc();
   if (!doc)  {
     return PR_FALSE;
   }
 
   nsIFrame* frameWithView =
     frame->HasView() ? frame : frame->GetAncestorWithViewExternal();
   nsIView* view = frameWithView->GetViewExternal();
   PRBool isVisible = CheckVisibilityInParentChain(doc, view);
@@ -713,47 +700,43 @@ nsAccessible::GetStateInternal(PRUint32 
       *aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
 
     return NS_OK_DEFUNCT_OBJECT;
   }
 
   if (aExtraState)
     *aExtraState = 0;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (!content) {
-    return NS_OK;  // On document, this is not an error
-  }
-
   // Set STATE_UNAVAILABLE state based on disabled attribute
   // The disabled attribute is mostly used in XUL elements and HTML forms, but
   // if someone sets it on another attribute, 
   // it seems reasonable to consider it unavailable
   PRBool isDisabled;
-  if (content->IsHTML()) {
+  if (mContent->IsHTML()) {
     // In HTML, just the presence of the disabled attribute means it is disabled,
     // therefore disabled="false" indicates disabled!
-    isDisabled = content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::disabled);
+    isDisabled = mContent->HasAttr(kNameSpaceID_None,
+                                   nsAccessibilityAtoms::disabled);
   }
   else {
-    isDisabled = content->AttrValueIs(kNameSpaceID_None,
-                                      nsAccessibilityAtoms::disabled,
-                                      nsAccessibilityAtoms::_true,
-                                      eCaseMatters);
+    isDisabled = mContent->AttrValueIs(kNameSpaceID_None,
+                                       nsAccessibilityAtoms::disabled,
+                                       nsAccessibilityAtoms::_true,
+                                       eCaseMatters);
   }
   if (isDisabled) {
     *aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
   }
-  else if (content->IsElement()) {
+  else if (mContent->IsElement()) {
     nsIFrame *frame = GetFrame();
     if (frame && frame->IsFocusable()) {
       *aState |= nsIAccessibleStates::STATE_FOCUSABLE;
     }
 
-    if (gLastFocusedNode == mDOMNode) {
+    if (gLastFocusedNode == mContent) {
       *aState |= nsIAccessibleStates::STATE_FOCUSED;
     }
   }
 
   // Check if nsIAccessibleStates::STATE_INVISIBLE and
   // STATE_OFFSCREEN flags should be turned on for this object.
   PRBool isOffscreen;
   if (!IsVisible(&isOffscreen)) {
@@ -763,44 +746,39 @@ nsAccessible::GetStateInternal(PRUint32 
     *aState |= nsIAccessibleStates::STATE_OFFSCREEN;
   }
 
   nsIFrame *frame = GetFrame();
   if (frame && (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW))
     *aState |= nsIAccessibleStates::STATE_FLOATING;
 
   // Check if a XUL element has the popup attribute (an attached popup menu).
-  if (content->IsXUL())
-    if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
+  if (mContent->IsXUL())
+    if (mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
       *aState |= nsIAccessibleStates::STATE_HASPOPUP;
 
   // Add 'linked' state for simple xlink.
-  if (nsCoreUtils::IsXLink(content))
+  if (nsCoreUtils::IsXLink(mContent))
     *aState |= nsIAccessibleStates::STATE_LINKED;
 
   return NS_OK;
 }
 
   /* readonly attribute boolean focusedChild; */
-NS_IMETHODIMP nsAccessible::GetFocusedChild(nsIAccessible **aFocusedChild) 
+NS_IMETHODIMP
+nsAccessible::GetFocusedChild(nsIAccessible **aFocusedChild) 
 { 
-  nsCOMPtr<nsIAccessible> focusedChild;
-  if (gLastFocusedNode == mDOMNode) {
+  nsAccessible *focusedChild = nsnull;
+  if (gLastFocusedNode == mContent) {
     focusedChild = this;
   }
   else if (gLastFocusedNode) {
-    GetAccService()->GetAccessibleFor(gLastFocusedNode,
-                                      getter_AddRefs(focusedChild));
-    if (focusedChild) {
-      nsCOMPtr<nsIAccessible> focusedParentAccessible;
-      focusedChild->GetParent(getter_AddRefs(focusedParentAccessible));
-      if (focusedParentAccessible != this) {
-        focusedChild = nsnull;
-      }
-    }
+    focusedChild = GetAccService()->GetAccessible(gLastFocusedNode);
+    if (focusedChild && focusedChild->GetParent() != this)
+      focusedChild = nsnull;
   }
 
   NS_IF_ADDREF(*aFocusedChild = focusedChild);
   return NS_OK;
 }
 
 // nsAccessible::GetChildAtPoint()
 nsresult
@@ -844,26 +822,17 @@ nsAccessible::GetChildAtPoint(PRInt32 aX
   nsIFrame *foundFrame = presShell->GetFrameForPoint(frame, offset);
 
   nsIContent* content = nsnull;
   if (!foundFrame || !(content = foundFrame->GetContent())) {
     NS_IF_ADDREF(*aChild = fallbackAnswer);
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
-
-  nsCOMPtr<nsIDOMNode> relevantNode;
-  GetAccService()->GetRelevantContentNodeFor(node,
-                                             getter_AddRefs(relevantNode));
-  if (!relevantNode) {
-    NS_IF_ADDREF(*aChild = fallbackAnswer);
-    return NS_OK;
-  }
-
+  nsINode *relevantNode = GetAccService()->GetRelevantContentNodeFor(content);
   nsAccessible *accessible = GetAccService()->GetAccessible(relevantNode);
   if (!accessible) {
     // No accessible for the node with the point, so find the first
     // accessible in the DOM parent chain
     accessible = GetAccService()->GetContainerAccessible(relevantNode, PR_TRUE);
     if (!accessible) {
       NS_IF_ADDREF(*aChild = fallbackAnswer);
       return NS_OK;
@@ -982,17 +951,17 @@ void nsAccessible::GetBoundsRect(nsRect&
                                          nsAccessibilityAtoms::inlineFrame) &&
         !nsCoreUtils::IsCorrectFrameType(ancestorFrame,
                                          nsAccessibilityAtoms::textFrame))
       break;
     ancestorFrame = ancestorFrame->GetParent();
   }
 
   nsIFrame *iterFrame = firstFrame;
-  nsCOMPtr<nsIContent> firstContent(do_QueryInterface(mDOMNode));
+  nsCOMPtr<nsIContent> firstContent(mContent);
   nsIContent* iterContent = firstContent;
   PRInt32 depth = 0;
 
   // Look only at frames below this depth, or at this depth (if we're still on the content node we started with)
   while (iterContent == firstContent || depth > 0) {
     // Coordinates will come back relative to parent frame
     nsRect currFrameBounds = iterFrame->GetRect();
     
@@ -1082,54 +1051,52 @@ nsIFrame* nsAccessible::GetBoundsFrame()
 {
   return GetFrame();
 }
 
 /* void removeSelection (); */
 NS_IMETHODIMP nsAccessible::SetSelected(PRBool aSelect)
 {
   // Add or remove selection
-  if (!mDOMNode) {
+  if (IsDefunct())
     return NS_ERROR_FAILURE;
-  }
 
   PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
     nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectableContainer(mDOMNode);
+      nsAccUtils::GetMultiSelectableContainer(mContent);
     if (!multiSelect) {
       return aSelect ? TakeFocus() : NS_ERROR_FAILURE;
     }
-    nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-    NS_ASSERTION(content, "Called for dead accessible");
 
     if (mRoleMapEntry) {
       if (aSelect) {
-        return content->SetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected,
-                                NS_LITERAL_STRING("true"), PR_TRUE);
+        return mContent->SetAttr(kNameSpaceID_None,
+                                 nsAccessibilityAtoms::aria_selected,
+                                 NS_LITERAL_STRING("true"), PR_TRUE);
       }
-      return content->UnsetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected, PR_TRUE);
+      return mContent->UnsetAttr(kNameSpaceID_None,
+                                 nsAccessibilityAtoms::aria_selected, PR_TRUE);
     }
   }
 
-  return NS_ERROR_FAILURE;
+  return NS_OK;
 }
 
 /* void takeSelection (); */
 NS_IMETHODIMP nsAccessible::TakeSelection()
 {
   // Select only this item
-  if (!mDOMNode) {
+  if (IsDefunct())
     return NS_ERROR_FAILURE;
-  }
 
   PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
     nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectableContainer(mDOMNode);
+      nsAccUtils::GetMultiSelectableContainer(mContent);
     if (multiSelect) {
       nsCOMPtr<nsIAccessibleSelectable> selectable = do_QueryInterface(multiSelect);
       selectable->ClearSelection();
     }
     return SetSelected(PR_TRUE);
   }
 
   return NS_ERROR_FAILURE;
@@ -1137,68 +1104,61 @@ NS_IMETHODIMP nsAccessible::TakeSelectio
 
 /* void takeFocus (); */
 NS_IMETHODIMP
 nsAccessible::TakeFocus()
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-
   nsIFrame *frame = GetFrame();
   NS_ENSURE_STATE(frame);
 
+  nsIContent* focusContent = mContent;
+
   // If the current element can't take real DOM focus and if it has an ID and
   // ancestor with a the aria-activedescendant attribute present, then set DOM
   // focus to that ancestor and set aria-activedescendant on the ancestor to
   // the ID of the desired element.
   if (!frame->IsFocusable()) {
     nsAutoString id;
-    if (content && nsCoreUtils::GetID(content, id)) {
-
-      nsCOMPtr<nsIContent> ancestorContent = content;
+    if (nsCoreUtils::GetID(mContent, id)) {
+
+      nsIContent* ancestorContent = mContent;
       while ((ancestorContent = ancestorContent->GetParent()) &&
              !ancestorContent->HasAttr(kNameSpaceID_None,
                                        nsAccessibilityAtoms::aria_activedescendant));
 
       if (ancestorContent) {
         nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
         if (presShell) {
           nsIFrame *frame = ancestorContent->GetPrimaryFrame();
           if (frame && frame->IsFocusable()) {
-
-            content = ancestorContent;            
-            content->SetAttr(kNameSpaceID_None,
-                             nsAccessibilityAtoms::aria_activedescendant,
-                             id, PR_TRUE);
+            focusContent = ancestorContent;
+            focusContent->SetAttr(kNameSpaceID_None,
+                                  nsAccessibilityAtoms::aria_activedescendant,
+                                  id, PR_TRUE);
           }
         }
       }
     }
   }
 
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(content));
+  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(focusContent));
   nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
   if (fm)
     fm->SetFocus(element, 0);
 
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetHTMLName(nsAString& aLabel)
 {
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content) {
-    aLabel.SetIsVoid(PR_TRUE);
-    return NS_OK;
-  }
-
-  nsIContent *labelContent = nsCoreUtils::GetHTMLLabelContent(content);
+  nsIContent *labelContent = nsCoreUtils::GetHTMLLabelContent(mContent);
   if (labelContent) {
     nsAutoString label;
     nsresult rv =
       nsTextEquivUtils::AppendTextEquivFromContent(this, labelContent, &label);
     NS_ENSURE_SUCCESS(rv, rv);
 
     label.CompressWhitespace();
     if (!label.IsEmpty()) {
@@ -1224,47 +1184,44 @@ nsAccessible::GetHTMLName(nsAString& aLa
   */
 nsresult
 nsAccessible::GetXULName(nsAString& aLabel)
 {
   // CASE #1 (via label attribute) -- great majority of the cases
   nsresult rv = NS_OK;
 
   nsAutoString label;
-  nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(mDOMNode));
+  nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(mContent));
   if (labeledEl) {
     rv = labeledEl->GetLabel(label);
   }
   else {
-    nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl(do_QueryInterface(mDOMNode));
+    nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl(do_QueryInterface(mContent));
     if (itemEl) {
       rv = itemEl->GetLabel(label);
     }
     else {
-      nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mDOMNode));
+      nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mContent));
       // Use label if this is not a select control element which 
       // uses label attribute to indicate which option is selected
       if (!select) {
-        nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(mDOMNode));
+        nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(mContent));
         if (xulEl) {
           rv = xulEl->GetAttribute(NS_LITERAL_STRING("label"), label);
         }
       }
     }
   }
 
   // CASES #2 and #3 ------ label as a child or <label control="id" ... > </label>
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
   if (NS_FAILED(rv) || label.IsEmpty()) {
     label.Truncate();
     nsIContent *labelContent =
-      nsCoreUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::control,
+      nsCoreUtils::FindNeighbourPointingToNode(mContent,
+                                               nsAccessibilityAtoms::control,
                                                nsAccessibilityAtoms::label);
 
     nsCOMPtr<nsIDOMXULLabelElement> xulLabel(do_QueryInterface(labelContent));
     // Check if label's value attribute is used
     if (xulLabel && NS_SUCCEEDED(xulLabel->GetValue(label)) && label.IsEmpty()) {
       // If no value attribute, a non-empty label must contain
       // children that define its text -- possibly using HTML
       nsTextEquivUtils::AppendTextEquivFromContent(this, labelContent, &label);
@@ -1274,19 +1231,19 @@ nsAccessible::GetXULName(nsAString& aLab
   // XXX If CompressWhiteSpace worked on nsAString we could avoid a copy
   label.CompressWhitespace();
   if (!label.IsEmpty()) {
     aLabel = label;
     return NS_OK;
   }
 
   // Can get text from title of <toolbaritem> if we're a child of a <toolbaritem>
-  nsIContent *bindingParent = content->GetBindingParent();
+  nsIContent *bindingParent = mContent->GetBindingParent();
   nsIContent *parent = bindingParent? bindingParent->GetParent() :
-                                      content->GetParent();
+                                      mContent->GetParent();
   while (parent) {
     if (parent->Tag() == nsAccessibilityAtoms::toolbaritem &&
         parent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, label)) {
       label.CompressWhitespace();
       aLabel = label;
       return NS_OK;
     }
     parent = parent->GetParent();
@@ -1294,55 +1251,54 @@ nsAccessible::GetXULName(nsAString& aLab
 
   return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
 }
 
 nsresult
 nsAccessible::HandleAccEvent(nsAccEvent *aEvent)
 {
   NS_ENSURE_ARG_POINTER(aEvent);
-  nsCOMPtr<nsIDOMNode> eventNode;
-  aEvent->GetDOMNode(getter_AddRefs(eventNode));
-  NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(aEvent->GetNode()),
+                 NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIObserverService> obsService =
     mozilla::services::GetObserverService();
   NS_ENSURE_TRUE(obsService, NS_ERROR_FAILURE);
 
   return obsService->NotifyObservers(aEvent, NS_ACCESSIBLE_EVENT_TOPIC, nsnull);
 }
 
 NS_IMETHODIMP
 nsAccessible::GetRole(PRUint32 *aRole)
 {
   NS_ENSURE_ARG_POINTER(aRole);
-
   *aRole = nsIAccessibleRole::ROLE_NOTHING;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   if (mRoleMapEntry) {
     *aRole = mRoleMapEntry->role;
 
     // These unfortunate exceptions don't fit into the ARIA table
     // This is where the nsIAccessible role depends on both the role and ARIA state
     if (*aRole == nsIAccessibleRole::ROLE_PUSHBUTTON) {
-      nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
-      if (content) {
-        if (nsAccUtils::HasDefinedARIAToken(content, nsAccessibilityAtoms::aria_pressed)) {
-          // For simplicity, any existing pressed attribute except "", or "undefined"
-          // indicates a toggle
-          *aRole = nsIAccessibleRole::ROLE_TOGGLE_BUTTON;
-        }
-        else if (content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_haspopup,
-                                      nsAccessibilityAtoms::_true, eCaseMatters)) {
-          // For button with aria-haspopup="true"
-          *aRole = nsIAccessibleRole::ROLE_BUTTONMENU;
-        }
+
+      if (nsAccUtils::HasDefinedARIAToken(mContent,
+                                          nsAccessibilityAtoms::aria_pressed)) {
+        // For simplicity, any existing pressed attribute except "", or "undefined"
+        // indicates a toggle.
+        *aRole = nsIAccessibleRole::ROLE_TOGGLE_BUTTON;
+
+      } else if (mContent->AttrValueIs(kNameSpaceID_None,
+                                       nsAccessibilityAtoms::aria_haspopup,
+                                       nsAccessibilityAtoms::_true,
+                                       eCaseMatters)) {
+        // For button with aria-haspopup="true".
+        *aRole = nsIAccessibleRole::ROLE_BUTTONMENU;
       }
     }
     else if (*aRole == nsIAccessibleRole::ROLE_LISTBOX) {
       // A listbox inside of a combo box needs a special role because of ATK mapping to menu
       nsCOMPtr<nsIAccessible> possibleCombo;
       GetParent(getter_AddRefs(possibleCombo));
       if (nsAccUtils::Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
         *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
@@ -1350,19 +1306,17 @@ nsAccessible::GetRole(PRUint32 *aRole)
       else {   // Check to see if combo owns the listbox instead
         possibleCombo = nsRelUtils::
           GetRelatedAccessible(this, nsIAccessibleRelation::RELATION_NODE_CHILD_OF);
         if (nsAccUtils::Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX)
           *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
       }
     }
     else if (*aRole == nsIAccessibleRole::ROLE_OPTION) {
-      nsCOMPtr<nsIAccessible> parent;
-      GetParent(getter_AddRefs(parent));
-      if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
+      if (nsAccUtils::Role(GetParent()) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
         *aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
     }
 
     // We are done if the mapped role trumps native semantics
     if (mRoleMapEntry->roleRule == kUseMapRole)
       return NS_OK;
   }
 
@@ -1372,42 +1326,37 @@ nsAccessible::GetRole(PRUint32 *aRole)
 NS_IMETHODIMP
 nsAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);  // In/out param. Created if necessary.
   
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content) {
-    return NS_ERROR_FAILURE;
-  }
-
   nsCOMPtr<nsIPersistentProperties> attributes = *aAttributes;
   if (!attributes) {
     // Create only if an array wasn't already passed in
     attributes = do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
     NS_ENSURE_TRUE(attributes, NS_ERROR_OUT_OF_MEMORY);
     NS_ADDREF(*aAttributes = attributes);
   }
  
   nsresult rv = GetAttributesInternal(attributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString id;
   nsAutoString oldValueUnused;
-  if (nsCoreUtils::GetID(content, id)) {
+  if (nsCoreUtils::GetID(mContent, id)) {
     // Expose ID. If an <iframe id> exists override the one on the <body> of the source doc,
     // because the specific instance is what makes the ID useful for scripts
     attributes->SetStringProperty(NS_LITERAL_CSTRING("id"), id, oldValueUnused);
   }
   
   nsAutoString xmlRoles;
-  if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, xmlRoles)) {
+  if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, xmlRoles)) {
     attributes->SetStringProperty(NS_LITERAL_CSTRING("xml-roles"),  xmlRoles, oldValueUnused);          
   }
 
   nsCOMPtr<nsIAccessibleValue> supportsValue = do_QueryInterface(static_cast<nsIAccessible*>(this));
   if (supportsValue) {
     // We support values, so expose the string value as well, via the valuetext object attribute
     // We test for the value interface because we don't want to expose traditional get_accValue()
     // information such as URL's on links and documents, or text in an input
@@ -1422,32 +1371,32 @@ nsAccessible::GetAttributes(nsIPersisten
 
   // Group attributes (level/setsize/posinset)
   PRInt32 level = 0, posInSet = 0, setSize = 0;
   rv = GroupPosition(&level, &setSize, &posInSet);
   if (NS_SUCCEEDED(rv))
     nsAccUtils::SetAccGroupAttrs(attributes, level, setSize, posInSet);
 
   // Expose object attributes from ARIA attributes.
-  PRUint32 numAttrs = content->GetAttrCount();
+  PRUint32 numAttrs = mContent->GetAttrCount();
   for (PRUint32 count = 0; count < numAttrs; count ++) {
-    const nsAttrName *attr = content->GetAttrNameAt(count);
+    const nsAttrName *attr = mContent->GetAttrNameAt(count);
     if (attr && attr->NamespaceEquals(kNameSpaceID_None)) {
       nsIAtom *attrAtom = attr->Atom();
       nsDependentAtomString attrStr(attrAtom);
       if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-"))) 
         continue; // Not ARIA
       PRUint8 attrFlags = nsAccUtils::GetAttributeCharacteristics(attrAtom);
       if (attrFlags & ATTR_BYPASSOBJ)
         continue; // No need to handle exposing as obj attribute here
       if ((attrFlags & ATTR_VALTOKEN) &&
-          !nsAccUtils::HasDefinedARIAToken(content, attrAtom))
+          !nsAccUtils::HasDefinedARIAToken(mContent, attrAtom))
         continue; // only expose token based attributes if they are defined
       nsAutoString value;
-      if (content->GetAttr(kNameSpaceID_None, attrAtom, value)) {
+      if (mContent->GetAttr(kNameSpaceID_None, attrAtom, value)) {
         attributes->SetStringProperty(NS_ConvertUTF16toUTF8(Substring(attrStr, 5)), value, oldValueUnused);
       }
     }
   }
 
   // If there is no aria-live attribute then expose default value of 'live'
   // object attribute used for ARIA role of this accessible.
   if (mRoleMapEntry) {
@@ -1462,53 +1411,48 @@ nsAccessible::GetAttributes(nsIPersisten
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   // Attributes set by this method will not be used to override attributes on a sub-document accessible
   // when there is a <frame>/<iframe> element that spawned the sub-document
-  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(content));
-  NS_ENSURE_TRUE(element, NS_ERROR_UNEXPECTED);
+  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mContent));
 
   nsAutoString tagName;
   element->GetTagName(tagName);
   if (!tagName.IsEmpty()) {
     nsAutoString oldValueUnused;
     aAttributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName,
                                    oldValueUnused);
   }
 
-  nsEventShell::GetEventAttributes(mDOMNode, aAttributes);
+  nsEventShell::GetEventAttributes(GetNode(), aAttributes);
  
   // Expose class because it may have useful microformat information
   // Let the class from an iframe's document be exposed, don't override from <iframe class>
   nsAutoString _class;
-  if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::_class, _class))
+  if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::_class, _class))
     nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::_class, _class);
 
   // Get container-foo computed live region properties based on the closest container with
   // the live region attribute. 
   // Inner nodes override outer nodes within the same document --
   //   The inner nodes can be used to override live region behavior on more general outer nodes
   // However, nodes in outer documents override nodes in inner documents:
   //   Outer doc author may want to override properties on a widget they used in an iframe
-  nsCOMPtr<nsIDOMNode> startNode = mDOMNode;
-  nsIContent *startContent = content;
+  nsIContent *startContent = mContent;
   while (PR_TRUE) {
     NS_ENSURE_STATE(startContent);
     nsIDocument *doc = startContent->GetDocument();
-    nsCOMPtr<nsIDOMNode> docNode = do_QueryInterface(doc);
-    NS_ENSURE_STATE(docNode);
-    nsIContent *topContent = nsCoreUtils::GetRoleContent(docNode);
-    NS_ENSURE_STATE(topContent);
+    nsIContent* rootContent = nsCoreUtils::GetRoleContent(doc);
+    NS_ENSURE_STATE(rootContent);
     nsAccUtils::SetLiveContainerAttributes(aAttributes, startContent,
-                                           topContent);
+                                           rootContent);
 
     // Allow ARIA live region markup from outer documents to override
     nsCOMPtr<nsISupports> container = doc->GetContainer(); 
     nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
       do_QueryInterface(container);
     if (!docShellTreeItem)
       break;
 
@@ -1543,17 +1487,17 @@ nsAccessible::GetAttributesInternal(nsIP
   // Expose 'text-indent' attribute.
   rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("text-indent"),
                              value);
   if (NS_SUCCEEDED(rv))
     nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::textIndent,
                            value);
 
   // Expose draggable object attribute?
-  nsCOMPtr<nsIDOMNSHTMLElement> htmlElement = do_QueryInterface(content);
+  nsCOMPtr<nsIDOMNSHTMLElement> htmlElement = do_QueryInterface(mContent);
   if (htmlElement) {
     PRBool draggable = PR_FALSE;
     htmlElement->GetDraggable(&draggable);
     if (draggable) {
       nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::draggable,
                              NS_LITERAL_STRING("true"));
     }
   }
@@ -1574,25 +1518,21 @@ nsAccessible::GroupPosition(PRInt32 *aGr
 
   NS_ENSURE_ARG_POINTER(aPositionInGroup);
   *aPositionInGroup = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   // Get group position from ARIA attributes.
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
-  nsCoreUtils::GetUIntAttr(content, nsAccessibilityAtoms::aria_level,
+  nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_level,
                            aGroupLevel);
-  nsCoreUtils::GetUIntAttr(content, nsAccessibilityAtoms::aria_posinset,
+  nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_posinset,
                            aPositionInGroup);
-  nsCoreUtils::GetUIntAttr(content, nsAccessibilityAtoms::aria_setsize,
+  nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_setsize,
                            aSimilarItemsInGroup);
 
   // If ARIA is missed and the accessible is visible then calculate group
   // position from hierarchy.
   if (nsAccUtils::State(this) & nsIAccessibleStates::STATE_INVISIBLE)
     return NS_OK;
 
   // Calculate group level if ARIA is missed.
@@ -1642,24 +1582,19 @@ nsAccessible::GetState(PRUint32 *aState,
       *aState |= nsIAccessibleStates::STATE_SELECTED;
     } else {
       // Expose 'selected' state on ARIA tab if the focus is on internal element
       // of related tabpanel.
       nsCOMPtr<nsIAccessible> tabPanel = nsRelUtils::
         GetRelatedAccessible(this, nsIAccessibleRelation::RELATION_LABEL_FOR);
 
       if (nsAccUtils::Role(tabPanel) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
-        nsCOMPtr<nsIAccessNode> tabPanelAccessNode(do_QueryInterface(tabPanel));
-        nsCOMPtr<nsIDOMNode> tabPanelDOMNode;
-        tabPanelAccessNode->GetDOMNode(getter_AddRefs(tabPanelDOMNode));
-        NS_ENSURE_STATE(tabPanelDOMNode);
-
-        nsCOMPtr<nsINode> tabPanelNode(do_QueryInterface(tabPanelDOMNode));
-        nsCOMPtr<nsINode> lastFocusedNode(do_QueryInterface(gLastFocusedNode));
-        if (nsCoreUtils::IsAncestorOf(tabPanelNode, lastFocusedNode))
+        nsRefPtr<nsAccessible> tabPanelAcc(do_QueryObject(tabPanel));
+        nsINode *tabPanelNode = tabPanelAcc->GetNode();
+        if (nsCoreUtils::IsAncestorOf(tabPanelNode, gLastFocusedNode))
           *aState |= nsIAccessibleStates::STATE_SELECTED;
       }
     }
   }
 
   const PRUint32 kExpandCollapseStates =
     nsIAccessibleStates::STATE_COLLAPSED | nsIAccessibleStates::STATE_EXPANDED;
   if ((*aState & kExpandCollapseStates) == kExpandCollapseStates) {
@@ -1684,20 +1619,19 @@ nsAccessible::GetState(PRUint32 *aState,
       (*aState & nsIAccessibleStates::STATE_EXPANDED))
     *aExtraState |= nsIAccessibleStates::EXT_STATE_EXPANDABLE;
 
   if (mRoleMapEntry) {
     // If an object has an ancestor with the activedescendant property
     // pointing at it, we mark it as ACTIVE even if it's not currently focused.
     // This allows screen reader virtual buffer modes to know which descendant
     // is the current one that would get focus if the user navigates to the container widget.
-    nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
     nsAutoString id;
-    if (content && nsCoreUtils::GetID(content, id)) {
-      nsIContent *ancestorContent = content;
+    if (nsCoreUtils::GetID(mContent, id)) {
+      nsIContent *ancestorContent = mContent;
       nsAutoString activeID;
       while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
         if (ancestorContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant, activeID)) {
           if (id == activeID) {
             *aExtraState |= nsIAccessibleStates::EXT_STATE_ACTIVE;
           }
           break;
         }
@@ -1738,110 +1672,105 @@ nsAccessible::GetState(PRUint32 *aState,
  
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetARIAState(PRUint32 *aState, PRUint32 *aExtraState)
 {
   // Test for universal states first
-  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content) {
-    return NS_OK;
-  }
-
   PRUint32 index = 0;
-  while (nsStateMapEntry::MapToStates(content, aState, aExtraState,
+  while (nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
                                       nsARIAMap::gWAIUnivStateMap[index])) {
     ++ index;
   }
 
   if (mRoleMapEntry) {
 
     // We only force the readonly bit off if we have a real mapping for the aria
     // role. This preserves the ability for screen readers to use readonly
     // (primarily on the document) as the hint for creating a virtual buffer.
     if (mRoleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING)
       *aState &= ~nsIAccessibleStates::STATE_READONLY;
 
-    if (content->HasAttr(kNameSpaceID_None, content->GetIDAttributeName())) {
+    if (mContent->HasAttr(kNameSpaceID_None, mContent->GetIDAttributeName())) {
       // If has a role & ID and aria-activedescendant on the container, assume focusable
-      nsIContent *ancestorContent = content;
+      nsIContent *ancestorContent = mContent;
       while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
         if (ancestorContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant)) {
             // ancestor has activedescendant property, this content could be active
           *aState |= nsIAccessibleStates::STATE_FOCUSABLE;
           break;
         }
       }
     }
   }
 
   if (*aState & nsIAccessibleStates::STATE_FOCUSABLE) {
     // Special case: aria-disabled propagates from ancestors down to any focusable descendant
-    nsIContent *ancestorContent = content;
+    nsIContent *ancestorContent = mContent;
     while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
       if (ancestorContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_disabled,
                                        nsAccessibilityAtoms::_true, eCaseMatters)) {
           // ancestor has aria-disabled property, this is disabled
         *aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
         break;
       }
     }    
   }
 
   if (!mRoleMapEntry)
     return NS_OK;
 
   // Note: the readonly bitflag will be overridden later if content is editable
   *aState |= mRoleMapEntry->state;
-  if (nsStateMapEntry::MapToStates(content, aState, aExtraState,
+  if (nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
                                    mRoleMapEntry->attributeMap1) &&
-      nsStateMapEntry::MapToStates(content, aState, aExtraState,
+      nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
                                    mRoleMapEntry->attributeMap2)) {
-    nsStateMapEntry::MapToStates(content, aState, aExtraState,
+    nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
                                  mRoleMapEntry->attributeMap3);
   }
 
   return NS_OK;
 }
 
 // Not implemented by this class
 
 /* DOMString getValue (); */
 NS_IMETHODIMP
 nsAccessible::GetValue(nsAString& aValue)
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (!content)
-    return NS_OK;
-
   if (mRoleMapEntry) {
     if (mRoleMapEntry->valueRule == eNoValue) {
       return NS_OK;
     }
 
     // aria-valuenow is a number, and aria-valuetext is the optional text equivalent
     // For the string value, we will try the optional text equivalent first
-    if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_valuetext, aValue)) {
-      content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_valuenow, aValue);
+    if (!mContent->GetAttr(kNameSpaceID_None,
+                           nsAccessibilityAtoms::aria_valuetext, aValue)) {
+      mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_valuenow,
+                        aValue);
     }
   }
 
   if (!aValue.IsEmpty())
     return NS_OK;
 
   // Check if it's a simple xlink.
-  if (nsCoreUtils::IsXLink(content)) {
+  if (nsCoreUtils::IsXLink(mContent)) {
     nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
-    if (presShell)
-      return presShell->GetLinkLocation(mDOMNode, aValue);
+    if (presShell) {
+      nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mContent));
+      return presShell->GetLinkLocation(DOMNode, aValue);
+    }
   }
 
   return NS_OK;
 }
 
 // nsIAccessibleValue
 NS_IMETHODIMP
 nsAccessible::GetMaximumValue(double *aMaximumValue)
@@ -1869,18 +1798,18 @@ NS_IMETHODIMP
 nsAccessible::GetCurrentValue(double *aValue)
 {
   return GetAttrValue(nsAccessibilityAtoms::aria_valuenow, aValue);
 }
 
 NS_IMETHODIMP
 nsAccessible::SetCurrentValue(double aValue)
 {
-  if (!mDOMNode)
-    return NS_ERROR_FAILURE;  // Node already shut down
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
 
   if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
     return NS_OK_NO_ARIA_VALUE;
 
   const PRUint32 kValueCannotChange = nsIAccessibleStates::STATE_READONLY |
                                       nsIAccessibleStates::STATE_UNAVAILABLE;
 
   if (nsAccUtils::State(this) & kValueCannotChange)
@@ -1889,23 +1818,21 @@ nsAccessible::SetCurrentValue(double aVa
   double minValue = 0;
   if (NS_SUCCEEDED(GetMinimumValue(&minValue)) && aValue < minValue)
     return NS_ERROR_INVALID_ARG;
 
   double maxValue = 0;
   if (NS_SUCCEEDED(GetMaximumValue(&maxValue)) && aValue > maxValue)
     return NS_ERROR_INVALID_ARG;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  NS_ENSURE_STATE(content);
-
   nsAutoString newValue;
   newValue.AppendFloat(aValue);
-  return content->SetAttr(kNameSpaceID_None,
-                          nsAccessibilityAtoms::aria_valuenow, newValue, PR_TRUE);
+  return mContent->SetAttr(kNameSpaceID_None,
+                           nsAccessibilityAtoms::aria_valuenow, newValue,
+                           PR_TRUE);
 }
 
 /* void setName (in DOMString name); */
 NS_IMETHODIMP nsAccessible::SetName(const nsAString& name)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
@@ -1941,18 +1868,17 @@ nsAccessible::GetKeyBindings(PRUint8 aAc
 nsresult
 nsAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_NOTHING;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (nsCoreUtils::IsXLink(content))
+  if (nsCoreUtils::IsXLink(mContent))
     *aRole = nsIAccessibleRole::ROLE_LINK;
 
   return NS_OK;
 }
 
 // readonly attribute PRUint8 numActions
 NS_IMETHODIMP
 nsAccessible::GetNumActions(PRUint8 *aNumActions)
@@ -2095,18 +2021,17 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
 /* nsIAccessible getAccessibleBelow(); */
 NS_IMETHODIMP nsAccessible::GetAccessibleBelow(nsIAccessible **_retval)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsIDOMNode* nsAccessible::GetAtomicRegion()
 {
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  nsIContent *loopContent = content;
+  nsIContent *loopContent = mContent;
   nsAutoString atomic;
   while (loopContent && !loopContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_atomic, atomic)) {
     loopContent = loopContent->GetParent();
   }
 
   nsCOMPtr<nsIDOMNode> atomicRegion;
   if (atomic.EqualsLiteral("true")) {
     atomicRegion = do_QueryInterface(loopContent);
@@ -2122,114 +2047,109 @@ nsAccessible::GetRelationByType(PRUint32
   NS_ENSURE_ARG_POINTER(aRelation);
   *aRelation = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   // Relationships are defined on the same content node that the role would be
   // defined on.
-  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
   nsresult rv;
-
   switch (aRelationType)
   {
   case nsIAccessibleRelation::RELATION_LABEL_FOR:
     {
-      if (content->Tag() == nsAccessibilityAtoms::label) {
-        nsIAtom *IDAttr = content->IsHTML() ?
+      if (mContent->Tag() == nsAccessibilityAtoms::label) {
+        nsIAtom *IDAttr = mContent->IsHTML() ?
           nsAccessibilityAtoms::_for : nsAccessibilityAtoms::control;
         rv = nsRelUtils::
-          AddTargetFromIDRefAttr(aRelationType, aRelation, content, IDAttr);
+          AddTargetFromIDRefAttr(aRelationType, aRelation, mContent, IDAttr);
         NS_ENSURE_SUCCESS(rv, rv);
 
         if (rv != NS_OK_NO_RELATION_TARGET)
           return NS_OK; // XXX bug 381599, avoid performance problems
       }
 
       return nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::aria_labelledby);
     }
 
   case nsIAccessibleRelation::RELATION_LABELLED_BY:
     {
       rv = nsRelUtils::
-        AddTargetFromIDRefsAttr(aRelationType, aRelation, content,
+        AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
                                 nsAccessibilityAtoms::aria_labelledby);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (rv != NS_OK_NO_RELATION_TARGET)
         return NS_OK; // XXX bug 381599, avoid performance problems
 
       return nsRelUtils::
         AddTargetFromContent(aRelationType, aRelation,
-                             nsCoreUtils::GetLabelContent(content));
+                             nsCoreUtils::GetLabelContent(mContent));
     }
 
   case nsIAccessibleRelation::RELATION_DESCRIBED_BY:
     {
       rv = nsRelUtils::
-        AddTargetFromIDRefsAttr(aRelationType, aRelation, content,
+        AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
                                 nsAccessibilityAtoms::aria_describedby);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (rv != NS_OK_NO_RELATION_TARGET)
         return NS_OK; // XXX bug 381599, avoid performance problems
 
       return nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::control,
                                nsAccessibilityAtoms::description);
     }
 
   case nsIAccessibleRelation::RELATION_DESCRIPTION_FOR:
     {
       rv = nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::aria_describedby);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (rv != NS_OK_NO_RELATION_TARGET)
         return NS_OK; // XXX bug 381599, avoid performance problems
 
-      if (content->Tag() == nsAccessibilityAtoms::description &&
-          content->IsXUL()) {
+      if (mContent->Tag() == nsAccessibilityAtoms::description &&
+          mContent->IsXUL()) {
         // This affectively adds an optional control attribute to xul:description,
         // which only affects accessibility, by allowing the description to be
         // tied to a control.
         return nsRelUtils::
-          AddTargetFromIDRefAttr(aRelationType, aRelation, content,
+          AddTargetFromIDRefAttr(aRelationType, aRelation, mContent,
                                  nsAccessibilityAtoms::control);
       }
 
       return NS_OK;
     }
 
   case nsIAccessibleRelation::RELATION_NODE_CHILD_OF:
     {
       rv = nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::aria_owns);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (rv != NS_OK_NO_RELATION_TARGET)
         return NS_OK; // XXX bug 381599, avoid performance problems
 
       // This is an ARIA tree or treegrid that doesn't use owns, so we need to
       // get the parent the hard way.
       if (mRoleMapEntry &&
           (mRoleMapEntry->role == nsIAccessibleRole::ROLE_OUTLINEITEM ||
            mRoleMapEntry->role == nsIAccessibleRole::ROLE_ROW)) {
 
         nsCOMPtr<nsIAccessible> accTarget;
-        nsAccUtils::GetARIATreeItemParent(this, content,
+        nsAccUtils::GetARIATreeItemParent(this, mContent,
                                           getter_AddRefs(accTarget));
 
         return nsRelUtils::AddTarget(aRelationType, aRelation, accTarget);
       }
 
       // If accessible is in its own Window, or is the root of a document,
       // then we should provide NODE_CHILD_OF relation so that MSAA clients
       // can easily get to true parent instead of getting to oleacc's
@@ -2248,61 +2168,62 @@ nsAccessible::GetRelationByType(PRUint32
       }
 
       return NS_OK;
     }
 
   case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
     {
       return nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::aria_controls);
     }
 
   case nsIAccessibleRelation::RELATION_CONTROLLER_FOR:
     {
       return nsRelUtils::
-        AddTargetFromIDRefsAttr(aRelationType, aRelation, content,
+        AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
                                 nsAccessibilityAtoms::aria_controls);
     }
 
   case nsIAccessibleRelation::RELATION_FLOWS_TO:
     {
       return nsRelUtils::
-        AddTargetFromIDRefsAttr(aRelationType, aRelation, content,
+        AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
                                 nsAccessibilityAtoms::aria_flowto);
     }
 
   case nsIAccessibleRelation::RELATION_FLOWS_FROM:
     {
       return nsRelUtils::
-        AddTargetFromNeighbour(aRelationType, aRelation, content,
+        AddTargetFromNeighbour(aRelationType, aRelation, mContent,
                                nsAccessibilityAtoms::aria_flowto);
     }
 
   case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON:
     {
-      if (content->IsHTML()) {
+      if (mContent->IsHTML()) {
         // HTML form controls implements nsIFormControl interface.
-        nsCOMPtr<nsIFormControl> control(do_QueryInterface(content));
+        nsCOMPtr<nsIFormControl> control(do_QueryInterface(mContent));
         if (control) {
           nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
           control->GetForm(getter_AddRefs(htmlform));
           nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
           if (form) {
             nsCOMPtr<nsIContent> formContent =
               do_QueryInterface(form->GetDefaultSubmitElement());
             return nsRelUtils::AddTargetFromContent(aRelationType, aRelation,
                                                     formContent);
           }
         }
       }
       else {
         // In XUL, use first <button default="true" .../> in the document
-        nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(content->GetDocument());
+        nsCOMPtr<nsIDOMXULDocument> xulDoc =
+          do_QueryInterface(mContent->GetOwnerDoc());
         nsCOMPtr<nsIDOMXULButtonElement> buttonEl;
         if (xulDoc) {
           nsCOMPtr<nsIDOMNodeList> possibleDefaultButtons;
           xulDoc->GetElementsByAttribute(NS_LITERAL_STRING("default"),
                                          NS_LITERAL_STRING("true"),
                                          getter_AddRefs(possibleDefaultButtons));
           if (possibleDefaultButtons) {
             PRUint32 length;
@@ -2431,22 +2352,19 @@ NS_IMETHODIMP nsAccessible::ExtendSelect
 NS_IMETHODIMP nsAccessible::GetNativeInterface(void **aOutAccessible)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 void
 nsAccessible::DoCommand(nsIContent *aContent, PRUint32 aActionIndex)
 {
-  nsCOMPtr<nsIContent> content = aContent;
-  if (!content)
-    content = nsCoreUtils::GetRoleContent(mDOMNode);
-
-  NS_DISPATCH_RUNNABLEMETHOD_ARG2(DispatchClickEvent, this,
-                                  content, aActionIndex)
+  nsIContent* content = aContent ? aContent : mContent.get();
+  NS_DISPATCH_RUNNABLEMETHOD_ARG2(DispatchClickEvent, this, content,
+                                  aActionIndex);
 }
 
 void
 nsAccessible::DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex)
 {
   if (IsDefunct())
     return;
 
@@ -2646,23 +2564,22 @@ nsAccessible::GetURI(PRInt32 aIndex, nsI
 {
   NS_ENSURE_ARG_POINTER(aURI);
   *aURI = nsnull;
 
   if (aIndex != 0)
     return NS_ERROR_INVALID_ARG;
 
   // Check if it's a simple xlink.
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  if (nsCoreUtils::IsXLink(content)) {
+  if (nsCoreUtils::IsXLink(mContent)) {
     nsAutoString href;
-    content->GetAttr(kNameSpaceID_XLink, nsAccessibilityAtoms::href, href);
-
-    nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
-    nsCOMPtr<nsIDocument> document = content->GetOwnerDoc();
+    mContent->GetAttr(kNameSpaceID_XLink, nsAccessibilityAtoms::href, href);
+
+    nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
+    nsCOMPtr<nsIDocument> document = mContent->GetOwnerDoc();
     return NS_NewURI(aURI, href,
                      document ? document->GetDocumentCharacterSet().get() : nsnull,
                      baseURI);
   }
 
   return NS_OK;
 }
 
@@ -2696,17 +2613,18 @@ nsAccessible::GetValid(PRBool *aValid)
   return NS_OK;
 }
 
 // readonly attribute boolean nsIAccessibleHyperLink::selected
 NS_IMETHODIMP
 nsAccessible::GetSelected(PRBool *aSelected)
 {
   NS_ENSURE_ARG_POINTER(aSelected);
-  *aSelected = (gLastFocusedNode == mDOMNode);
+
+  *aSelected = (gLastFocusedNode == GetNode());
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetLinkOffset(PRInt32 *aStartOffset, PRInt32 *aEndOffset)
 {
   nsAccessible *parent = GetParent();
   NS_ENSURE_STATE(parent);
@@ -2754,23 +2672,20 @@ nsAccessible::AppendTextTo(nsAString& aT
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible public methods
 
 nsresult
 nsAccessible::GetARIAName(nsAString& aName)
 {
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
   // First check for label override via aria-label property
   nsAutoString label;
-  if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) {
+  if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label,
+                        label)) {
     label.CompressWhitespace();
     aName = label;
     return NS_OK;
   }
   
   // Second check for label override via aria-labelledby relationship
   nsresult rv = nsTextEquivUtils::
     GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_labelledby, label);
@@ -2780,24 +2695,20 @@ nsAccessible::GetARIAName(nsAString& aNa
   }
 
   return rv;
 }
 
 nsresult
 nsAccessible::GetNameInternal(nsAString& aName)
 {
-  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return NS_OK;
-
-  if (content->IsHTML())
+  if (mContent->IsHTML())
     return GetHTMLName(aName);
 
-  if (content->IsXUL())
+  if (mContent->IsXUL())
     return GetXULName(aName);
 
   return NS_OK;
 }
 
 void
 nsAccessible::SetParent(nsAccessible *aParent)
 {
@@ -2838,17 +2749,17 @@ nsAccessible::GetParent()
   if (mParent)
     return mParent;
 
 #ifdef DEBUG
   nsDocAccessible *docAccessible = GetDocAccessible();
   NS_ASSERTION(docAccessible, "No document accessible for valid accessible!");
 #endif
 
-  nsAccessible *parent = GetAccService()->GetContainerAccessible(mDOMNode,
+  nsAccessible *parent = GetAccService()->GetContainerAccessible(mContent,
                                                                  PR_TRUE);
   NS_ASSERTION(parent, "No accessible parent for valid accessible!");
   if (!parent)
     return nsnull;
 
 #ifdef DEBUG
   NS_ASSERTION(!parent->IsDefunct(), "Defunct parent!");
 
@@ -2918,18 +2829,17 @@ nsAccessible::GetCachedFirstChild()
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible protected methods
 
 void
 nsAccessible::CacheChildren()
 {
-  nsAccTreeWalker walker(mWeakShell, nsCoreUtils::GetRoleContent(mDOMNode),
-                         GetAllowsAnonChildAccessibles());
+  nsAccTreeWalker walker(mWeakShell, mContent, GetAllowsAnonChildAccessibles());
 
   nsRefPtr<nsAccessible> child;
   while ((child = walker.GetNextChild())) {
     mChildren.AppendElement(child);
     child->SetParent(this);
   }
 }
 
@@ -3010,45 +2920,27 @@ nsAccessible::GetSiblingAtOffset(PRInt32
   nsAccessible *child = parent->GetChildAt(indexInParent + aOffset);
   if (aError && !child)
     *aError = NS_ERROR_UNEXPECTED;
 
   return child;
 }
 
 nsAccessible *
-nsAccessible::GetFirstAvailableAccessible(nsIDOMNode *aStartNode) const
+nsAccessible::GetFirstAvailableAccessible(nsINode *aStartNode) const
 {
-  nsCOMPtr<nsIDOMTreeWalker> walker; 
-  nsCOMPtr<nsIDOMNode> currentNode(aStartNode);
-
-  while (currentNode) {
-    nsAccessible *accessible =
-      GetAccService()->GetAccessibleInWeakShell(currentNode, mWeakShell);
-    if (accessible)
-      return accessible;
-
-    if (!walker) {
-      // Instantiate walker lazily since we won't need it in 90% of the cases
-      // where the first DOM node we're given provides an accessible
-      nsCOMPtr<nsIDOMDocument> document;
-      currentNode->GetOwnerDocument(getter_AddRefs(document));
-      nsCOMPtr<nsIDOMDocumentTraversal> trav = do_QueryInterface(document);
-      NS_ASSERTION(trav, "No DOM document traversal for document");
-      NS_ENSURE_TRUE(trav, nsnull);
-      trav->CreateTreeWalker(mDOMNode, nsIDOMNodeFilter::SHOW_ELEMENT | nsIDOMNodeFilter::SHOW_TEXT,
-                            nsnull, PR_FALSE, getter_AddRefs(walker));
-      NS_ENSURE_TRUE(walker, nsnull);
-      walker->SetCurrentNode(currentNode);
-    }
-
-    walker->NextNode(getter_AddRefs(currentNode));
-  }
-
-  return nsnull;
+  nsAccessible *accessible =
+    GetAccService()->GetAccessibleInWeakShell(aStartNode, mWeakShell);
+  if (accessible)
+    return accessible;
+
+  nsIContent *content = nsCoreUtils::GetRoleContent(aStartNode);
+  nsAccTreeWalker walker(mWeakShell, content, PR_FALSE);
+  nsRefPtr<nsAccessible> childAccessible = walker.GetNextChild();
+  return childAccessible;
 }
 
 PRBool nsAccessible::CheckVisibilityInParentChain(nsIDocument* aDocument, nsIView* aView)
 {
   nsIDocument* document = aDocument;
   nsIView* view = aView;
   // both view chain and widget chain are broken between chrome and content
   while (document != nsnull) {
@@ -3091,21 +2983,18 @@ nsAccessible::GetAttrValue(nsIAtom *aPro
   *aValue = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;  // Node already shut down
 
  if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
     return NS_OK_NO_ARIA_VALUE;
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  NS_ENSURE_STATE(content);
-
   nsAutoString attrValue;
-  content->GetAttr(kNameSpaceID_None, aProperty, attrValue);
+  mContent->GetAttr(kNameSpaceID_None, aProperty, attrValue);
 
   // Return zero value if there is no attribute or its value is empty.
   if (attrValue.IsEmpty())
     return NS_OK;
 
   PRInt32 error = NS_OK;
   double value = attrValue.ToFloat(&error);
   if (NS_SUCCEEDED(error))
@@ -3114,44 +3003,40 @@ nsAccessible::GetAttrValue(nsIAtom *aPro
   return NS_OK;
 }
 
 PRUint32
 nsAccessible::GetActionRule(PRUint32 aStates)
 {
   if (aStates & nsIAccessibleStates::STATE_UNAVAILABLE)
     return eNoAction;
-
-  nsIContent* content = nsCoreUtils::GetRoleContent(mDOMNode);
-  if (!content)
-    return eNoAction;
   
   // Check if it's simple xlink.
-  if (nsCoreUtils::IsXLink(content))
+  if (nsCoreUtils::IsXLink(mContent))
     return eJumpAction;
 
   // Return "click" action on elements that have an attached popup menu.
-  if (content->IsXUL())
-    if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
+  if (mContent->IsXUL())
+    if (mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
       return eClickAction;
 
   // Has registered 'click' event handler.
-  PRBool isOnclick = nsCoreUtils::HasClickListener(content);
+  PRBool isOnclick = nsCoreUtils::HasClickListener(mContent);
 
   if (isOnclick)
     return eClickAction;
   
   // Get an action based on ARIA role.
   if (mRoleMapEntry &&
       mRoleMapEntry->actionRule != eNoAction)
     return mRoleMapEntry->actionRule;
 
   // Get an action based on ARIA attribute.
-  if (nsAccUtils::HasDefinedARIAToken(content,
-                                   nsAccessibilityAtoms::aria_expanded))
+  if (nsAccUtils::HasDefinedARIAToken(mContent,
+                                      nsAccessibilityAtoms::aria_expanded))
     return eExpandAction;
 
   return eNoAction;
 }
 
 void
 nsAccessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet, PRInt32 *aSetSize)
 {
@@ -3179,17 +3064,17 @@ nsAccessible::GetPositionAndSizeInternal
   PRInt32 indexInParent = parent->GetIndexOf(this);
   PRInt32 level = nsAccUtils::GetARIAOrDefaultLevel(this);
 
   // Compute 'posinset'.
   PRInt32 positionInGroup = 1;
   for (PRInt32 idx = indexInParent - 1; idx >= 0; idx--) {
     nsAccessible* sibling = parent->GetChildAt(idx);
 
-    PRUint32 siblingRole = siblingRole = nsAccUtils::Role(sibling);
+    PRUint32 siblingRole = nsAccUtils::Role(sibling);
 
     // If the sibling is separator then the group is ended.
     if (siblingRole == nsIAccessibleRole::ROLE_SEPARATOR)
       break;
 
     PRUint32 siblingBaseRole = siblingRole;
     if (siblingRole == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
         siblingRole == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -87,17 +87,17 @@ NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODUL
 
 class nsAccessible : public nsAccessNodeWrap, 
                      public nsIAccessible, 
                      public nsIAccessibleHyperLink,
                      public nsIAccessibleSelectable,
                      public nsIAccessibleValue
 {
 public:
-  nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
+  nsAccessible(nsIContent *aContent, nsIWeakReference *aShell);
   virtual ~nsAccessible();
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsAccessible, nsAccessNode)
 
   NS_DECL_NSIACCESSIBLE
   NS_DECL_NSIACCESSIBLEHYPERLINK
   NS_DECL_NSIACCESSIBLESELECTABLE
@@ -344,17 +344,17 @@ protected:
   /**
    * Return an accessible for the given DOM node, or if that node isn't
    * accessible, return the accessible for the next DOM node which has one
    * (based on forward depth first search).
    *
    * @param  aStartNode  [in] the DOM node to start from
    * @return              the resulting accessible
    */
-  nsAccessible *GetFirstAvailableAccessible(nsIDOMNode *aStartNode) const;
+  nsAccessible *GetFirstAvailableAccessible(nsINode *aStartNode) const;
 
   // Hyperlink helpers
   virtual nsresult GetLinkOffset(PRInt32* aStartOffset, PRInt32* aEndOffset);
 
   //////////////////////////////////////////////////////////////////////////////
   // Action helpers
 
   /**
--- a/accessible/src/base/nsApplicationAccessible.cpp
+++ b/accessible/src/base/nsApplicationAccessible.cpp
@@ -59,29 +59,41 @@ nsApplicationAccessible::nsApplicationAc
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsApplicationAccessible, nsAccessible,
                              nsIAccessibleApplication)
 
 ////////////////////////////////////////////////////////////////////////////////
-// nsIAccessNode
+// nsIAccessible
 
 NS_IMETHODIMP
-nsApplicationAccessible::GetRootDocument(nsIAccessibleDocument **aRootDocument)
+nsApplicationAccessible::GetParent(nsIAccessible **aAccessible)
 {
-  NS_ENSURE_ARG_POINTER(aRootDocument);
-  *aRootDocument = nsnull;
-
+  NS_ENSURE_ARG_POINTER(aAccessible);
+  *aAccessible = nsnull;
   return NS_OK;
 }
 
-////////////////////////////////////////////////////////////////////////////////
-// nsIAccessible
+NS_IMETHODIMP
+nsApplicationAccessible::GetNextSibling(nsIAccessible **aNextSibling)
+{
+  NS_ENSURE_ARG_POINTER(aNextSibling);
+  *aNextSibling = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetPreviousSibling(nsIAccessible **aPreviousSibling)
+{
+  NS_ENSURE_ARG_POINTER(aPreviousSibling);
+  *aPreviousSibling = nsnull;
+  return NS_OK;
+}
 
 NS_IMETHODIMP
 nsApplicationAccessible::GetName(nsAString& aName)
 {
   aName.Truncate();
 
   nsCOMPtr<nsIStringBundleService> bundleService =
     mozilla::services::GetStringBundleService();
@@ -102,49 +114,185 @@ nsApplicationAccessible::GetName(nsAStri
     appName.AssignLiteral("Gecko based application");
   }
 
   aName.Assign(appName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsApplicationAccessible::GetDescription(nsAString& aValue)
+nsApplicationAccessible::GetValue(nsAString &aValue)
 {
   aValue.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsApplicationAccessible::GetDescription(nsAString &aDescription)
+{
+  aDescription.Truncate();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetKeyboardShortcut(nsAString &aKeyboardShortcut)
+{
+  aKeyboardShortcut.Truncate();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsApplicationAccessible::GetRole(PRUint32 *aRole)
 {
   NS_ENSURE_ARG_POINTER(aRole);
-
   return GetRoleInternal(aRole);
 }
 
 NS_IMETHODIMP
 nsApplicationAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
 {
   NS_ENSURE_ARG_POINTER(aState);
-  *aState = 0;
+  GetStateInternal(aState, aExtraState);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
+{
+  NS_ENSURE_ARG_POINTER(aAttributes);
+  *aAttributes = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GroupPosition(PRInt32 *aGroupLevel,
+                                       PRInt32 *aSimilarItemsInGroup,
+                                       PRInt32 *aPositionInGroup)
+{
+  NS_ENSURE_ARG_POINTER(aGroupLevel);
+  *aGroupLevel = 0;
+  NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
+  *aSimilarItemsInGroup = 0;
+  NS_ENSURE_ARG_POINTER(aPositionInGroup);
+  *aPositionInGroup = 0;
+  return NS_OK;
+}
 
-  if (aExtraState)
-    *aExtraState = 0;
+NS_IMETHODIMP
+nsApplicationAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
+                                         nsIAccessible **aChild)
+{
+  NS_ENSURE_ARG_POINTER(aChild);
+  *aChild = nsnull;
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
 
+NS_IMETHODIMP
+nsApplicationAccessible::GetDeepestChildAtPoint(PRInt32 aX, PRInt32 aY,
+                                                nsIAccessible **aChild)
+{
+  NS_ENSURE_ARG_POINTER(aChild);
+  *aChild = nsnull;
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetRelationByType(PRUint32 aRelationType,
+                                           nsIAccessibleRelation **aRelation)
+{
+  NS_ENSURE_ARG_POINTER(aRelation);
+  *aRelation = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetRelationsCount(PRUint32 *aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsApplicationAccessible::GetParent(nsIAccessible **aAccessible)
+nsApplicationAccessible::GetRelation(PRUint32 aIndex,
+                                     nsIAccessibleRelation **aRelation)
+{
+  NS_ENSURE_ARG_POINTER(aRelation);
+  *aRelation = nsnull;
+  return NS_ERROR_INVALID_ARG;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetRelations(nsIArray **aRelations)
+{
+  NS_ENSURE_ARG_POINTER(aRelations);
+  *aRelations = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetBounds(PRInt32 *aX, PRInt32 *aY,
+                                   PRInt32 *aWidth, PRInt32 *aHeight)
+{
+  NS_ENSURE_ARG_POINTER(aX);
+  *aX = 0;
+  NS_ENSURE_ARG_POINTER(aY);
+  *aY = 0;
+  NS_ENSURE_ARG_POINTER(aWidth);
+  *aWidth = 0;
+  NS_ENSURE_ARG_POINTER(aHeight);
+  *aHeight = 0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::SetSelected(PRBool aIsSelected)
 {
-  NS_ENSURE_ARG_POINTER(aAccessible);
-  *aAccessible = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::TakeSelection()
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::TakeFocus()
+{
+  return NS_OK;
+}
 
-  return IsDefunct() ? NS_ERROR_FAILURE : NS_OK;
+NS_IMETHODIMP
+nsApplicationAccessible::GetNumActions(PRUint8 *aNumActions)
+{
+  NS_ENSURE_ARG_POINTER(aNumActions);
+  *aNumActions = 0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetActionName(PRUint8 aIndex, nsAString &aName)
+{
+  aName.Truncate();
+  return NS_ERROR_INVALID_ARG;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetActionDescription(PRUint8 aIndex,
+                                              nsAString &aDescription)
+{
+  aDescription.Truncate();
+  return NS_ERROR_INVALID_ARG;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::DoAction(PRUint8 aIndex)
+{
+  return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessibleApplication
 
 NS_IMETHODIMP
 nsApplicationAccessible::GetAppName(nsAString& aName)
 {
@@ -222,27 +370,41 @@ nsApplicationAccessible::Shutdown()
   mAppInfo = nsnull;
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible public methods
 
 nsresult
+nsApplicationAccessible::GetARIAState(PRUint32 *aState, PRUint32 *aExtraState)
+{
+  return NS_OK;
+}
+
+nsresult
 nsApplicationAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_APP_ROOT;
   return NS_OK;
 }
 
 nsresult
 nsApplicationAccessible::GetStateInternal(PRUint32 *aState,
                                           PRUint32 *aExtraState)
 {
   *aState = 0;
+
+  if (IsDefunct()) {
+    if (aExtraState)
+      *aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
+
+    return NS_OK_DEFUNCT_OBJECT;
+  }
+
   if (aExtraState)
     *aExtraState = 0;
 
   return NS_OK;
 }
 
 nsAccessible*
 nsApplicationAccessible::GetParent()
@@ -340,8 +502,153 @@ nsApplicationAccessible::RemoveRootAcces
 {
   NS_ENSURE_ARG_POINTER(aRootAccessible);
 
   // It's not needed to void root accessible parent because this method is
   // called on root accessible shutdown and its parent will be cleared
   // properly.
   return mChildren.RemoveElement(aRootAccessible) ? NS_OK : NS_ERROR_FAILURE;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// nsIAccessNode
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetDOMNode(nsIDOMNode **aDOMNode)
+{
+  NS_ENSURE_ARG_POINTER(aDOMNode);
+  *aDOMNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetNumChildren(PRInt32 *aNumChildren)
+{
+  NS_ENSURE_ARG_POINTER(aNumChildren);
+  *aNumChildren = 0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetChildNodeAt(PRInt32 aChildNum,
+                                        nsIAccessNode **aChildNode)
+{
+  NS_ENSURE_ARG_POINTER(aChildNode);
+  *aChildNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetParentNode(nsIAccessNode **aParentNode)
+{
+  NS_ENSURE_ARG_POINTER(aParentNode);
+  *aParentNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetFirstChildNode(nsIAccessNode **aFirstChildNode)
+{
+  NS_ENSURE_ARG_POINTER(aFirstChildNode);
+  *aFirstChildNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetLastChildNode(nsIAccessNode **aLastChildNode)
+{
+  NS_ENSURE_ARG_POINTER(aLastChildNode);
+  *aLastChildNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetPreviousSiblingNode(nsIAccessNode **aPreviousSiblingNode)
+{
+  NS_ENSURE_ARG_POINTER(aPreviousSiblingNode);
+  *aPreviousSiblingNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetNextSiblingNode(nsIAccessNode **aNextSiblingNode)
+{
+  NS_ENSURE_ARG_POINTER(aNextSiblingNode);
+  *aNextSiblingNode = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetDocument(nsIAccessibleDocument **aDocument)
+{
+  NS_ENSURE_ARG_POINTER(aDocument);
+  *aDocument = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetRootDocument(nsIAccessibleDocument **aRootDocument)
+{
+  NS_ENSURE_ARG_POINTER(aRootDocument);
+  *aRootDocument = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetInnerHTML(nsAString &aInnerHTML)
+{
+  aInnerHTML.Truncate();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::ScrollTo(PRUint32 aScrollType)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::ScrollToPoint(PRUint32 aCoordinateType,
+                                       PRInt32 aX, PRInt32 aY)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetOwnerWindow(void **aOwnerWindow)
+{
+  NS_ENSURE_ARG_POINTER(aOwnerWindow);
+  *aOwnerWindow = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetUniqueID(void **aUniqueID)
+{
+  NS_ENSURE_ARG_POINTER(aUniqueID);
+  *aUniqueID = static_cast<void *>(this);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetComputedStyleValue(const nsAString &aPseudoElt,
+                                               const nsAString &aPropertyName,
+                                               nsAString &aValue)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetComputedStyleCSSValue(const nsAString &aPseudoElt,
+                                                  const nsAString &aPropertyName,
+                                                  nsIDOMCSSPrimitiveValue **aCSSPrimitiveValue)
+{
+  NS_ENSURE_ARG_POINTER(aCSSPrimitiveValue);
+  *aCSSPrimitiveValue = nsnull;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsApplicationAccessible::GetLanguage(nsAString &aLanguage)
+{
+  aLanguage.Truncate();
+  return NS_OK;
+}
--- a/accessible/src/base/nsApplicationAccessible.h
+++ b/accessible/src/base/nsApplicationAccessible.h
@@ -64,35 +64,58 @@ class nsApplicationAccessible: public ns
 {
 public:
   nsApplicationAccessible();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessNode
-  NS_IMETHOD GetRootDocument(nsIAccessibleDocument **aRootDocument);
+  NS_DECL_NSIACCESSNODE
 
   // nsIAccessible
-  NS_IMETHOD GetName(nsAString& aName);
-  NS_IMETHOD GetDescription(nsAString& aValue);
+  NS_IMETHOD GetParent(nsIAccessible **aParent);
+  NS_IMETHOD GetNextSibling(nsIAccessible **aNextSibling);
+  NS_IMETHOD GetPreviousSibling(nsIAccessible **aPreviousSibling);
+  NS_IMETHOD GetName(nsAString &aName);
+  NS_IMETHOD GetValue(nsAString &aValue);
+  NS_IMETHOD GetDescription(nsAString &aDescription);
+  NS_IMETHOD GetKeyboardShortcut(nsAString &aKeyboardShortcut);
   NS_IMETHOD GetRole(PRUint32 *aRole);
-  NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
-
-  NS_IMETHOD GetParent(nsIAccessible **aAccessible);
+  NS_IMETHOD GetState(PRUint32 *aState , PRUint32 *aExtraState );
+  NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
+  NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel, PRInt32 *aSimilarItemsInGroup,
+                           PRInt32 *aPositionInGroup);
+  NS_IMETHOD GetChildAtPoint(PRInt32 aX, PRInt32 aY, nsIAccessible **aChild);
+  NS_IMETHOD GetDeepestChildAtPoint(PRInt32 aX, PRInt32 aY, nsIAccessible **aChild);
+  NS_IMETHOD GetRelationByType(PRUint32 aRelationType,
+                               nsIAccessibleRelation **aRelation);
+  NS_IMETHOD GetRelationsCount(PRUint32 *aRelationsCount);
+  NS_IMETHOD GetRelation(PRUint32 aIndex, nsIAccessibleRelation **aRelation);
+  NS_IMETHOD GetRelations(nsIArray **aRelations);
+  NS_IMETHOD GetBounds(PRInt32 *aX, PRInt32 *aY,
+                       PRInt32 *aWidth, PRInt32 *aHeight);
+  NS_IMETHOD SetSelected(PRBool aIsSelected);
+  NS_IMETHOD TakeSelection();
+  NS_IMETHOD TakeFocus();
+  NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
+  NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString &aName);
+  NS_IMETHOD GetActionDescription(PRUint8 aIndex, nsAString &aDescription);
+  NS_IMETHOD DoAction(PRUint8 aIndex);
 
   // nsIAccessibleApplication
   NS_DECL_NSIACCESSIBLEAPPLICATION
 
   // nsAccessNode
   virtual PRBool IsDefunct();
   virtual nsresult Init();
   virtual nsresult Shutdown();
 
   // nsAccessible
+  virtual nsresult GetARIAState(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsAccessible* GetParent();
 
   virtual void InvalidateChildren();
 
   // nsApplicationAccessible
   virtual nsresult AddRootAccessible(nsIAccessible *aRootAccWrap);
--- a/accessible/src/base/nsBaseWidgetAccessible.cpp
+++ b/accessible/src/base/nsBaseWidgetAccessible.cpp
@@ -51,18 +51,19 @@
 #include "nsIFrame.h"
 #include "nsINameSpaceManager.h"
 #include "nsIURI.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLeafAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
-nsLeafAccessible::nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
-nsAccessibleWrap(aNode, aShell)
+nsLeafAccessible::
+  nsLeafAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsAccessibleWrap(aContent, aShell)
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsLeafAccessible, nsAccessible)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLeafAccessible: nsAccessible public
 
@@ -86,18 +87,18 @@ nsLeafAccessible::CacheChildren()
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLinkableAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 nsLinkableAccessible::
-  nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell) :
-  nsAccessibleWrap(aNode, aShell),
+  nsLinkableAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsAccessibleWrap(aContent, aShell),
   mActionContent(nsnull),
   mIsLink(PR_FALSE),
   mIsOnclick(PR_FALSE)
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsLinkableAccessible, nsAccessibleWrap)
 
@@ -242,32 +243,29 @@ nsLinkableAccessible::Shutdown()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLinkableAccessible
 
 void
 nsLinkableAccessible::CacheActionContent()
 {
-  nsCOMPtr<nsIContent> walkUpContent(do_QueryInterface(mDOMNode));
+  nsIContent* walkUpContent = mContent;
   PRBool isOnclick = nsCoreUtils::HasClickListener(walkUpContent);
 
   if (isOnclick) {
     mActionContent = walkUpContent;
     mIsOnclick = PR_TRUE;
     return;
   }
 
   while ((walkUpContent = walkUpContent->GetParent())) {
     isOnclick = nsCoreUtils::HasClickListener(walkUpContent);
-  
-    nsCOMPtr<nsIDOMNode> walkUpNode(do_QueryInterface(walkUpContent));
-
     nsAccessible *walkUpAcc =
-      GetAccService()->GetAccessibleInWeakShell(walkUpNode, mWeakShell);
+      GetAccService()->GetAccessibleInWeakShell(walkUpContent, mWeakShell);
 
     if (nsAccUtils::Role(walkUpAcc) == nsIAccessibleRole::ROLE_LINK &&
         nsAccUtils::State(walkUpAcc) & nsIAccessibleStates::STATE_LINKED) {
       mIsLink = PR_TRUE;
       mActionContent = walkUpContent;
       return;
     }
 
@@ -281,30 +279,30 @@ nsLinkableAccessible::CacheActionContent
 
 nsAccessible *
 nsLinkableAccessible::GetActionAccessible() const
 {
   // Return accessible for the action content if it's different from node of
   // this accessible. If the action accessible is not null then it is used to
   // redirect methods calls otherwise we use method implementation from the
   // base class.
-  nsCOMPtr<nsIDOMNode> actionNode(do_QueryInterface(mActionContent));
-  if (!actionNode || mDOMNode == actionNode)
+  if (!mActionContent || mContent == mActionContent)
     return nsnull;
 
-  return GetAccService()->GetAccessibleInWeakShell(actionNode, mWeakShell);
+  return GetAccService()->GetAccessibleInWeakShell(mActionContent, mWeakShell);
 }
 
-//---------------------
+////////////////////////////////////////////////////////////////////////////////
 // nsEnumRoleAccessible
-//---------------------
+////////////////////////////////////////////////////////////////////////////////
 
-nsEnumRoleAccessible::nsEnumRoleAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell, PRUint32 aRole) :
-  nsAccessibleWrap(aNode, aShell),
-  mRole(aRole)
+nsEnumRoleAccessible::
+  nsEnumRoleAccessible(nsIContent *aNode, nsIWeakReference *aShell,
+                       PRUint32 aRole) :
+  nsAccessibleWrap(aNode, aShell), mRole(aRole)
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsEnumRoleAccessible, nsAccessible)
 
 nsresult
 nsEnumRoleAccessible::GetRoleInternal(PRUint32 *aRole)
 {
--- a/accessible/src/base/nsBaseWidgetAccessible.h
+++ b/accessible/src/base/nsBaseWidgetAccessible.h
@@ -38,31 +38,29 @@
 
 #ifndef _nsBaseWidgetAccessible_H_
 #define _nsBaseWidgetAccessible_H_
 
 #include "nsAccessibleWrap.h"
 #include "nsHyperTextAccessibleWrap.h"
 #include "nsIContent.h"
 
-class nsIDOMNode;
-
 /**
   * This file contains a number of classes that are used as base
   *  classes for the different accessibility implementations of
   *  the HTML and XUL widget sets.  --jgaunt
   */
 
 /** 
   * Leaf version of DOM Accessible -- has no children
   */
 class nsLeafAccessible : public nsAccessibleWrap
 {
 public:
-  nsLeafAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
+  nsLeafAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsAccessible
   virtual nsresult GetChildAtPoint(PRInt32 aX, PRInt32 aY,
                                    PRBool aDeepestChild,
                                    nsIAccessible **aChild);
@@ -79,17 +77,17 @@ protected:
  * report the state of the host link (traveled or not) and can activate (click)
  * the host accessible programmatically.
  */
 class nsLinkableAccessible : public nsAccessibleWrap
 {
 public:
   enum { eAction_Jump = 0 };
 
-  nsLinkableAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
+  nsLinkableAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessible
   NS_IMETHOD GetNumActions(PRUint8 *_retval);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 index);
   NS_IMETHOD GetValue(nsAString& _retval);
@@ -123,17 +121,18 @@ protected:
 };
 
 /**
  * A simple accessible that gets its enumerated role passed into constructor.
  */ 
 class nsEnumRoleAccessible : public nsAccessibleWrap
 {
 public:
-  nsEnumRoleAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell, PRUint32 aRole);
+  nsEnumRoleAccessible(nsIContent *aContent, nsIWeakReference *aShell,
+                       PRUint32 aRole);
   virtual ~nsEnumRoleAccessible() { }
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
 
 protected:
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -105,36 +105,34 @@ nsresult nsCaretAccessible::ClearControl
   controller->GetSelection(nsISelectionController::SELECTION_SPELLCHECK,
                            getter_AddRefs(spellcheckSel));
   selPrivate = do_QueryInterface(spellcheckSel);
   NS_ENSURE_TRUE(selPrivate, NS_ERROR_FAILURE);
 
   return selPrivate->RemoveSelectionListener(this);
 }
 
-nsresult nsCaretAccessible::SetControlSelectionListener(nsIDOMNode *aCurrentNode)
+nsresult
+nsCaretAccessible::SetControlSelectionListener(nsIContent *aCurrentNode)
 {
   NS_ENSURE_TRUE(mRootAccessible, NS_ERROR_FAILURE);
 
   ClearControlSelectionListener();
 
   mCurrentControl = aCurrentNode;
   mLastTextAccessible = nsnull;
 
   // When focus moves such that the caret is part of a new frame selection
   // this removes the old selection listener and attaches a new one for
   // the current focus.
 
   nsCOMPtr<nsISelectionController> controller =
     GetSelectionControllerForNode(mCurrentControl);
 #ifdef DEBUG
-  PRUint16 nodeType;
-  nsresult result = aCurrentNode->GetNodeType(&nodeType);
-  NS_ASSERTION(NS_SUCCEEDED(result) &&
-               (controller || nodeType == nsIDOMNode::DOCUMENT_NODE),
+  NS_ASSERTION(controller || aCurrentNode->IsNodeOfType(nsINode::eDOCUMENT),
                "No selection controller for non document node!");
 #endif
   if (!controller)
     return NS_OK;
 
   // Register 'this' as selection listener for the normal selection.
   nsCOMPtr<nsISelection> normalSel;
   controller->GetSelection(nsISelectionController::SELECTION_NORMAL,
@@ -242,17 +240,17 @@ nsCaretAccessible::NormalSelectionChange
   nsresult rv = aSel->GetRangeCount(&rangeCount);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (rangeCount == 0) {
     mLastTextAccessible = nsnull;
     return NS_OK; // No selection
   }
 
-  nsCOMPtr<nsIDOMNode> textNode;
+  nsCOMPtr<nsINode> textNode;
   nsCOMPtr<nsIAccessibleText> textAcc =
     nsAccUtils::GetTextAccessibleFromSelection(aSel, getter_AddRefs(textNode));
   NS_ENSURE_STATE(textAcc);
 
   PRInt32 caretOffset;
   rv = textAcc->GetCaretOffset(&caretOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -304,25 +302,23 @@ nsCaretAccessible::GetCaretRect(nsIWidge
   NS_ENSURE_TRUE(aOutWidget, caretRect);
   *aOutWidget = nsnull;
   NS_ENSURE_TRUE(mRootAccessible, caretRect);
 
   if (!mLastTextAccessible) {
     return caretRect;    // Return empty rect
   }
 
-  nsCOMPtr<nsIAccessNode> lastAccessNode(do_QueryInterface(mLastTextAccessible));
-  NS_ENSURE_TRUE(lastAccessNode, caretRect);
+  nsRefPtr<nsAccessible> lastTextAccessible =
+    do_QueryObject(mLastTextAccessible);
 
-  nsCOMPtr<nsIDOMNode> lastNodeWithCaret;
-  lastAccessNode->GetDOMNode(getter_AddRefs(lastNodeWithCaret));
+  nsINode *lastNodeWithCaret = lastTextAccessible->GetNode();
   NS_ENSURE_TRUE(lastNodeWithCaret, caretRect);
 
-  nsIPresShell *presShell =
-    nsCoreUtils::GetPresShellFor(lastNodeWithCaret);
+  nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(lastNodeWithCaret);
   NS_ENSURE_TRUE(presShell, caretRect);
 
   nsRefPtr<nsCaret> caret = presShell->GetCaret();
   NS_ENSURE_TRUE(caret, caretRect);
 
   nsCOMPtr<nsISelection> caretSelection(do_QueryReferent(mLastUsedSelection));
   NS_ENSURE_TRUE(caretSelection, caretRect);
   
@@ -356,35 +352,30 @@ nsCaretAccessible::GetCaretRect(nsIWidge
     caretRect.height -= charY - caretRect.y;
     caretRect.y = charY;
   }
 
   return caretRect;
 }
 
 already_AddRefed<nsISelectionController>
-nsCaretAccessible::GetSelectionControllerForNode(nsIDOMNode *aNode)
+nsCaretAccessible::GetSelectionControllerForNode(nsIContent *aContent)
 {
-  if (!aNode)
+  if (!aContent)
     return nsnull;
 
-  nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
+  nsIDocument *document = aContent->GetOwnerDoc();
+  if (!document)
+    return nsnull;
+
+  nsIPresShell *presShell = document->GetPrimaryShell();
   if (!presShell)
     return nsnull;
 
-  nsCOMPtr<nsIDocument> doc = presShell->GetDocument();
-  if (!doc)
-    return nsnull;
-
-  // Get selection controller only for form controls, not for the document.
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
-  if (!content)
-    return nsnull;
-
-  nsIFrame *frame = content->GetPrimaryFrame();
+  nsIFrame *frame = aContent->GetPrimaryFrame();
   if (!frame)
     return nsnull;
 
   nsPresContext *presContext = presShell->GetPresContext();
   if (!presContext)
     return nsnull;
 
   nsISelectionController *controller = nsnull;
--- a/accessible/src/base/nsCaretAccessible.h
+++ b/accessible/src/base/nsCaretAccessible.h
@@ -35,17 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __nsCaretAccessible_h__
 #define __nsCaretAccessible_h__
 
 #include "nsIWeakReference.h"
 #include "nsIAccessibleText.h"
-#include "nsIDOMNode.h"
+#include "nsIContent.h"
 #include "nsISelectionListener.h"
 #include "nsISelectionController.h"
 #include "nsRect.h"
 
 class nsRootAccessible;
 class nsIView;
 class nsIPresShell;
 class nsIWidget;
@@ -87,17 +87,17 @@ public:
   /**
    * Listen to selection events on the focused control.
    * Only one control's selection events are listened to at a time, per top-level window.
    * This will remove the previous control's selection listener.
    * It will fail if aFocusedNode is a document node -- document selection must be listened
    * to via AddDocSelectionListener().
    * @param aFocusedNode   The node for the focused control
    */
-  nsresult SetControlSelectionListener(nsIDOMNode *aCurrentNode);
+  nsresult SetControlSelectionListener(nsIContent *aCurrentNode);
 
   /**
    * Stop listening to selection events for any control.
    * This does not have to be called explicitly in Shutdown() procedures,
    * because the nsCaretAccessible implementation guarantees that.
    */
   nsresult ClearControlSelectionListener();
 
@@ -120,25 +120,30 @@ public:
   nsresult RemoveDocSelectionListener(nsIPresShell *aShell);
 
   nsIntRect GetCaretRect(nsIWidget **aOutWidget);
 
 protected:
   nsresult NormalSelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel);
   nsresult SpellcheckSelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel);
 
+  /**
+   * Return selection controller for the given node.
+   */
   already_AddRefed<nsISelectionController>
-  GetSelectionControllerForNode(nsIDOMNode *aNode);
+    GetSelectionControllerForNode(nsIContent *aNode);
 
 private:
   // The currently focused control -- never a document.
   // We listen to selection for one control at a time (the focused one)
   // Document selection is handled separately via additional listeners on all active documents
   // The current control is set via SetControlSelectionListener()
-  nsCOMPtr<nsIDOMNode> mCurrentControl;  // Selection controller for the currently focused control
+
+  // Currently focused control.
+  nsCOMPtr<nsIContent> mCurrentControl;
 
   // Info for the the last selection event.
   // If it was on a control, then its control's selection. Otherwise, it's for
   // a document where the selection changed.
   nsCOMPtr<nsIWeakReference> mLastUsedSelection; // Weak ref to nsISelection
   nsCOMPtr<nsIAccessibleText> mLastTextAccessible;
   PRInt32 mLastCaretOffset;
 
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -231,48 +231,26 @@ nsCoreUtils::GetAccessKeyFor(nsIContent 
   if (!esm)
     return 0;
 
   PRUint32 key = 0;
   esm->GetRegisteredAccessKey(aContent, &key);
   return key;
 }
 
-already_AddRefed<nsIDOMElement>
-nsCoreUtils::GetDOMElementFor(nsIDOMNode *aNode)
+nsIContent *
+nsCoreUtils::GetDOMElementFor(nsIContent *aContent)
 {
-  nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
-  nsIDOMElement *element = nsnull;
-
-  if (node->IsElement())
-    CallQueryInterface(node, &element);
-
-  else if (node->IsNodeOfType(nsINode::eTEXT)) {
-    nsCOMPtr<nsINode> nodeParent = node->GetNodeParent();
-    NS_ASSERTION(nodeParent, "Text node has no parent!");
-    if (nodeParent)
-      CallQueryInterface(nodeParent, &element);
-  }
+  if (aContent->IsElement())
+    return aContent;
 
-  else if (node->IsNodeOfType(nsINode::eDOCUMENT)) {
-    nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(node));
-    if (htmlDoc) {
-      nsCOMPtr<nsIDOMHTMLElement> bodyElement;
-      htmlDoc->GetBody(getter_AddRefs(bodyElement));
-      if (bodyElement) {
-        CallQueryInterface(bodyElement, &element);
-        return element;
-      }
-    }
+  if (aContent->IsNodeOfType(nsINode::eTEXT))
+    return aContent->GetParent();
 
-    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(node));
-    domDoc->GetDocumentElement(&element);
-  }
-
-  return element;
+  return nsnull;
 }
 
 nsINode *
 nsCoreUtils::GetDOMNodeFromDOMPoint(nsINode *aNode, PRUint32 aOffset)
 {
   if (aNode && aNode->IsElement()) {
     PRUint32 childCount = aNode->GetChildCount();
     NS_ASSERTION(aOffset >= 0 && aOffset <= childCount,
@@ -284,23 +262,23 @@ nsCoreUtils::GetDOMNodeFromDOMPoint(nsIN
     if (aOffset != childCount)
       return aNode->GetChildAt(aOffset);
   }
 
   return aNode;
 }
 
 nsIContent*
-nsCoreUtils::GetRoleContent(nsIDOMNode *aDOMNode)
+nsCoreUtils::GetRoleContent(nsINode *aNode)
 {
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
   if (!content) {
-    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aDOMNode));
+    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aNode));
     if (domDoc) {
-      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aDOMNode));
+      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aNode));
       if (htmlDoc) {
         nsCOMPtr<nsIDOMHTMLElement> bodyElement;
         htmlDoc->GetBody(getter_AddRefs(bodyElement));
         content = do_QueryInterface(bodyElement);
       }
       else {
         nsCOMPtr<nsIDOMElement> docElement;
         domDoc->GetDocumentElement(getter_AddRefs(docElement));
@@ -439,17 +417,17 @@ nsCoreUtils::ConvertScrollTypeToPercents
       break;
     default:
       *aVPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
       *aHPercent = NS_PRESSHELL_SCROLL_ANYWHERE;
   }
 }
 
 nsIntPoint
-nsCoreUtils::GetScreenCoordsForWindow(nsIDOMNode *aNode)
+nsCoreUtils::GetScreenCoordsForWindow(nsINode *aNode)
 {
   nsIntPoint coords(0, 0);
   nsCOMPtr<nsIDocShellTreeItem> treeItem(GetDocShellTreeItemFor(aNode));
   if (!treeItem)
     return coords;
 
   nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
   treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
@@ -465,27 +443,22 @@ nsCoreUtils::GetScreenCoordsForWindow(ns
     return coords;
 
   windowInter->GetScreenX(&coords.x);
   windowInter->GetScreenY(&coords.y);
   return coords;
 }
 
 already_AddRefed<nsIDocShellTreeItem>
-nsCoreUtils::GetDocShellTreeItemFor(nsIDOMNode *aNode)
+nsCoreUtils::GetDocShellTreeItemFor(nsINode *aNode)
 {
   if (!aNode)
     return nsnull;
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aNode->GetOwnerDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
-  if (!doc)
-    doc = do_QueryInterface(aNode);
-
+  nsIDocument *doc = aNode->GetOwnerDoc();
   NS_ASSERTION(doc, "No document for node passed in");
   NS_ENSURE_TRUE(doc, nsnull);
 
   nsCOMPtr<nsISupports> container = doc->GetContainer();
   nsIDocShellTreeItem *docShellTreeItem = nsnull;
   if (container)
     CallQueryInterface(container, &docShellTreeItem);
 
@@ -547,26 +520,16 @@ nsCoreUtils::IsErrorPage(nsIDocument *aD
   nsCAutoString::const_iterator start, end;
   path.BeginReading(start);
   path.EndReading(end);
 
   NS_NAMED_LITERAL_CSTRING(neterror, "neterror");
   return FindInReadable(neterror, start, end);
 }
 
-nsIFrame*
-nsCoreUtils::GetFrameFor(nsIDOMElement *aElm)
-{
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aElm));
-  if (!content)
-    return nsnull;
-  
-  return content->GetPrimaryFrame();
-}
-
 PRBool
 nsCoreUtils::IsCorrectFrameType(nsIFrame *aFrame, nsIAtom *aAtom)
 {
   NS_ASSERTION(aFrame != nsnull,
                "aFrame is null in call to IsCorrectFrameType!");
   NS_ASSERTION(aAtom != nsnull,
                "aAtom is null in call to IsCorrectFrameType!");
   
@@ -952,84 +915,75 @@ nsCoreUtils::GetElementsHavingIDRefsAttr
         continue; // Do not search inside children.
       }
     }
     GetElementsHavingIDRefsAttrImpl(child, aIdWithSpaces,
                                     aIDRefsAttr, aElements);
   }
 }
 
-void
+already_AddRefed<nsIDOMCSSStyleDeclaration>
 nsCoreUtils::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
-                                         nsIDOMNode *aNode,
-                                         nsIDOMCSSStyleDeclaration **aCssDecl)
+                                         nsIContent *aContent)
 {
-  *aCssDecl = nsnull;
-
-  nsCOMPtr<nsIDOMElement> domElement = GetDOMElementFor(aNode);
-  if (!domElement)
-    return;
+  nsIContent* content = GetDOMElementFor(aContent);
+  if (!content)
+    return nsnull;
 
   // Returns number of items in style declaration
-  nsCOMPtr<nsIContent> content = do_QueryInterface(domElement);
-  nsCOMPtr<nsIDocument> doc = content->GetDocument();
-  if (!doc)
-    return;
+  nsIDocument* document = content->GetOwnerDoc();
+  if (!document)
+    return nsnull;
 
-  nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(doc->GetWindow()));
+  nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(document->GetWindow()));
   if (!viewCSS)
-    return;
+    return nsnull;
 
-  viewCSS->GetComputedStyle(domElement, aPseudoElt, aCssDecl);
+  nsIDOMCSSStyleDeclaration* cssDecl = nsnull;
+  nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(content));
+  viewCSS->GetComputedStyle(domElement, aPseudoElt, &cssDecl);
+  return cssDecl;
 }
 
 already_AddRefed<nsIBoxObject>
 nsCoreUtils::GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj)
 {
   nsCOMPtr<nsIDOMElement> tcElm;
   aTreeBoxObj->GetTreeBody(getter_AddRefs(tcElm));
   nsCOMPtr<nsIDOMXULElement> tcXULElm(do_QueryInterface(tcElm));
   if (!tcXULElm)
     return nsnull;
 
   nsIBoxObject *boxObj = nsnull;
   tcXULElm->GetBoxObject(&boxObj);
   return boxObj;
 }
 
-void
-nsCoreUtils::GetTreeBoxObject(nsIDOMNode *aDOMNode,
-                              nsITreeBoxObject **aBoxObject)
+already_AddRefed<nsITreeBoxObject>
+nsCoreUtils::GetTreeBoxObject(nsIContent *aContent)
 {
-  nsAutoString name;
-  nsCOMPtr<nsIDOMNode> parentNode, currentNode;
-  
   // Find DOMNode's parents recursively until reach the <tree> tag
-  currentNode = aDOMNode;
-  while (currentNode) {
-    currentNode->GetLocalName(name);
-    if (name.EqualsLiteral("tree")) {
+  nsIContent* currentContent = aContent;
+  while (currentContent) {
+    if (currentContent->NodeInfo()->Equals(nsAccessibilityAtoms::tree,
+                                           kNameSpaceID_XUL)) {
       // We will get the nsITreeBoxObject from the tree node
-      nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(currentNode));
+      nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(currentContent));
       if (xulElement) {
         nsCOMPtr<nsIBoxObject> box;
         xulElement->GetBoxObject(getter_AddRefs(box));
         nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box));
-        if (treeBox) {
-          *aBoxObject = treeBox;
-          NS_ADDREF(*aBoxObject);
-          return;
-        }
+        if (treeBox)
+          return treeBox.forget();
       }
     }
-    currentNode->GetParentNode(getter_AddRefs(parentNode));
-    currentNode = parentNode;
+    currentContent = currentContent->GetParent();
   }
-  
-  *aBoxObject = nsnull;
+
+  return nsnull;
 }
 
 already_AddRefed<nsITreeColumn>
 nsCoreUtils::GetFirstSensibleColumn(nsITreeBoxObject *aTree)
 {
   nsCOMPtr<nsITreeColumns> cols;
   aTree->GetColumns(getter_AddRefs(cols));
   if (!cols)
@@ -1137,30 +1091,29 @@ nsCoreUtils::IsColumnHidden(nsITreeColum
   nsCOMPtr<nsIDOMElement> element;
   aColumn->GetElement(getter_AddRefs(element));
   nsCOMPtr<nsIContent> content = do_QueryInterface(element);
   return content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::hidden,
                               nsAccessibilityAtoms::_true, eCaseMatters);
 }
 
 void
-nsCoreUtils::GeneratePopupTree(nsIDOMNode *aNode, PRBool aIsAnon)
+nsCoreUtils::GeneratePopupTree(nsIContent *aContent, PRBool aIsAnon)
 {
   // Set menugenerated="true" on the menupopup node to generate the sub-menu
   // items if they have not been generated.
 
   nsCOMPtr<nsIDOMNodeList> list;
-  if (aIsAnon) {
-    nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
-    nsIDocument* document = content->GetCurrentDoc();
+  if (aIsAnon) {    
+    nsIDocument* document = aContent->GetCurrentDoc();
     if (document)
-      document->GetXBLChildNodesFor(content, getter_AddRefs(list));
+      document->GetXBLChildNodesFor(aContent, getter_AddRefs(list));
 
   } else {
-    aNode->GetChildNodes(getter_AddRefs(list));
+    list = aContent->GetChildNodesList();
   }
 
   PRUint32 length = 0;
   if (!list || NS_FAILED(list->GetLength(&length)))
     return;
 
   for (PRUint32 idx = 0; idx < length; idx++) {
     nsCOMPtr<nsIDOMNode> childNode;
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -114,38 +114,37 @@ public:
    * @param aContent - the given element.
    */
   static PRUint32 GetAccessKeyFor(nsIContent *aContent);
 
   /**
    * Return DOM element related with the given node, i.e.
    * a) itself if it is DOM element
    * b) parent element if it is text node
-   * c) body element if it is HTML document node
-   * d) document element if it is document node.
+   * c) otherwise nsnull
    *
    * @param aNode  [in] the given DOM node
    */
-  static already_AddRefed<nsIDOMElement> GetDOMElementFor(nsIDOMNode *aNode);
+  static nsIContent* GetDOMElementFor(nsIContent *aContent);
 
   /**
    * Return DOM node for the given DOM point.
    */
   static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, PRUint32 aOffset);
 
   /**
    * Return the nsIContent* to check for ARIA attributes on -- this may not
    * always be the DOM node for the accessible. Specifically, for doc
    * accessibles, it is not the document node, but either the root element or
-   * <body> in HTML. Similar with GetDOMElementFor() method.
+   * <body> in HTML.
    *
-   * @param aDOMNode  DOM node for the accessible that may be affected by ARIA
-   * @return          the nsIContent which may have ARIA markup
+   * @param aNode  [in] DOM node for the accessible that may be affected by ARIA
+   * @return        the nsIContent which may have ARIA markup
    */
-  static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
+  static nsIContent* GetRoleContent(nsINode *aNode);
 
   /**
    * Is the first passed in node an ancestor of the second?
    * Note: A node is not considered to be the ancestor of itself.
    *
    * @param  aPossibleAncestorNode   [in] node to test for ancestor-ness of
    *                                   aPossibleDescendantNode
    * @param  aPossibleDescendantNode [in] node to test for descendant-ness of
@@ -210,23 +209,23 @@ public:
                                           PRInt16 *aVPercent,
                                           PRInt16 *aHPercent);
 
   /**
    * Returns coordinates relative screen for the top level window.
    *
    * @param aNode  the DOM node hosted in the window.
    */
-  static nsIntPoint GetScreenCoordsForWindow(nsIDOMNode *aNode);
+  static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode);
 
   /**
    * Return document shell tree item for the given DOM node.
    */
   static already_AddRefed<nsIDocShellTreeItem>
-    GetDocShellTreeItemFor(nsIDOMNode *aNode);
+    GetDocShellTreeItemFor(nsINode *aNode);
 
   /**
    * Return true if document is loading.
    */
   static PRBool IsDocumentBusy(nsIDocument *aDocument);
 
   /**
    * Return true if the given document is root document.
@@ -239,37 +238,37 @@ public:
   static PRBool IsContentDocument(nsIDocument *aDocument);
 
   /**
    * Return true if the given document is an error page.
    */
   static PRBool IsErrorPage(nsIDocument *aDocument);
 
   /**
-   * Retrun frame for the given DOM element.
-   */
-  static nsIFrame* GetFrameFor(nsIDOMElement *aElm);
-
-  /**
    * Retrun true if the type of given frame equals to the given frame type.
    *
    * @param aFrame  the frame
    * @param aAtom   the frame type
    */
   static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
 
   /**
    * Return presShell for the document containing the given DOM node.
    */
-  static nsIPresShell *GetPresShellFor(nsIDOMNode *aNode)
+  static nsIPresShell *GetPresShellFor(nsINode *aNode)
   {
-    nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
-    nsIDocument *document = node->GetOwnerDoc();
+    nsIDocument *document = aNode->GetOwnerDoc();
     return document ? document->GetPrimaryShell() : nsnull;
   }
+  static already_AddRefed<nsIWeakReference> GetWeakShellFor(nsINode *aNode)
+  {
+    nsCOMPtr<nsIWeakReference> weakShell =
+      do_GetWeakReference(GetPresShellFor(aNode));
+    return weakShell.forget();
+  }
 
   /**
    * Return document node for the given document shell tree item.
    */
   static already_AddRefed<nsIDOMNode>
     GetDOMNodeForContainer(nsIDocShellTreeItem *aContainer);
 
   /**
@@ -335,19 +334,19 @@ public:
   static void GetElementsHavingIDRefsAttrImpl(nsIContent *aRootContent,
                                               nsCString& aIdWithSpaces,
                                               nsIAtom *aIDRefsAttr,
                                               nsIMutableArray *aElements);
 
   /**
    * Return computed styles declaration for the given node.
    */
-  static void GetComputedStyleDeclaration(const nsAString& aPseudoElt,
-                                          nsIDOMNode *aNode,
-                                          nsIDOMCSSStyleDeclaration **aCssDecl);
+  static already_AddRefed<nsIDOMCSSStyleDeclaration>
+    GetComputedStyleDeclaration(const nsAString& aPseudoElt,
+                                nsIContent *aContent);
 
   /**
    * Search element in neighborhood of the given element by tag name and
    * attribute value that equals to ID attribute of the given element.
    * ID attribute can be either 'id' attribute or 'anonid' if the element is
    * anonymous.
    * The first matched content will be returned.
    *
@@ -427,18 +426,18 @@ public:
    * Return box object for XUL treechildren element by tree box object.
    */
   static already_AddRefed<nsIBoxObject>
     GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
 
   /**
    * Return tree box object from any levels DOMNode under the XUL tree.
    */
-  static void
-    GetTreeBoxObject(nsIDOMNode* aDOMNode, nsITreeBoxObject** aBoxObject);
+  static already_AddRefed<nsITreeBoxObject>
+    GetTreeBoxObject(nsIContent* aContent);
 
   /**
    * Return first sensible column for the given tree box object.
    */
   static already_AddRefed<nsITreeColumn>
     GetFirstSensibleColumn(nsITreeBoxObject *aTree);
 
   /**
@@ -482,21 +481,22 @@ public:
   {
     return aContent->NodeInfo()->Equals(nsAccessibilityAtoms::th) ||
       aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::scope);
   }
 
   /**
    * Generates frames for popup subtree.
    *
-   * @param aNode    [in] DOM node containing the menupopup element as a child
+   * @param aContent [in] DOM node containing the menupopup element as a child
    * @param aIsAnon  [in] specifies whether popup should be searched inside of
    *                  anonymous or explicit content
    */
-  static void GeneratePopupTree(nsIDOMNode *aNode, PRBool aIsAnon = PR_FALSE);
+  static void GeneratePopupTree(nsIContent *aContent,
+                                PRBool aIsAnon = PR_FALSE);
 };
 
 
 /**
  * nsIDOMDOMStringList implementation.
  */
 class nsAccessibleDOMStringList : public nsIDOMDOMStringList
 {
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -49,16 +49,17 @@
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocument.h"
 #include "nsIDOMAttr.h"
 #include "nsIDOMCharacterData.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentType.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMNSHTMLDocument.h"
+#include "nsIDOMXULDocument.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMXULPopupElement.h"
 #include "nsIEditingSession.h"
 #include "nsIEventStateManager.h"
 #include "nsIFrame.h"
 #include "nsHTMLSelectAccessible.h"
 #include "nsIInterfaceRequestorUtils.h"
@@ -80,34 +81,31 @@
 
 PRUint32 nsDocAccessible::gLastFocusedAccessiblesState = 0;
 nsIAtom *nsDocAccessible::gLastFocusedFrameType = nsnull;
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
-nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode,
-                                 nsIWeakReference *aShell) :
-  nsHyperTextAccessibleWrap(aDOMNode, aShell), mWnd(nsnull),
-  mIsLoaded(PR_FALSE), mScrollPositionChangedTicks(0)
+nsDocAccessible::
+  nsDocAccessible(nsIDocument *aDocument, nsIContent *aRootContent,
+                  nsIWeakReference *aShell) :
+  nsHyperTextAccessibleWrap(aRootContent, aShell), mWnd(nsnull),
+  mDocument(aDocument), mIsLoaded(PR_FALSE), mScrollPositionChangedTicks(0)
 {
   // XXX aaronl should we use an algorithm for the initial cache size?
   mAccessNodeCache.Init(kDefaultCacheSize);
 
   // For GTK+ native window, we do nothing here.
-  if (!mDOMNode)
+  if (!mDocument)
     return;
 
+  // Initialize mWnd
   nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
-
-  // Initalize mDocument
-  mDocument = shell->GetDocument();
-
-  // Initalize mWnd
   nsIViewManager* vm = shell->GetViewManager();
   if (vm) {
     nsCOMPtr<nsIWidget> widget;
     vm->GetRootWidget(getter_AddRefs(widget));
     if (widget) {
       mWnd = widget->GetNativeData(NS_NATIVE_WINDOW);
     }
   }
@@ -142,17 +140,39 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDocAccessible)
   NS_INTERFACE_MAP_STATIC_AMBIGUOUS(nsDocAccessible)
   NS_INTERFACE_MAP_ENTRY(nsIAccessibleDocument)
   NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver)
   NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAccessibleDocument)
-NS_INTERFACE_MAP_END_INHERITING(nsHyperTextAccessible)
+    foundInterface = 0;
+
+  nsresult status;
+  if (!foundInterface) {
+    // HTML document accessible must inherit from nsHyperTextAccessible to get
+    // support text interfaces. XUL document accessible doesn't need this.
+    // However at some point we may push <body> to implement the interfaces and
+    // return nsDocAccessible to inherit from nsAccessibleWrap.
+
+    nsCOMPtr<nsIDOMXULDocument> xulDoc(do_QueryInterface(mDocument));
+    if (xulDoc)
+      status = nsAccessible::QueryInterface(aIID, (void**)&foundInterface);
+    else
+      status = nsHyperTextAccessible::QueryInterface(aIID,
+                                                     (void**)&foundInterface);
+  } else {
+    NS_ADDREF(foundInterface);
+    status = NS_OK;
+  }
+
+  *aInstancePtr = foundInterface;
+  return status;
+}
 
 NS_IMPL_ADDREF_INHERITED(nsDocAccessible, nsHyperTextAccessible)
 NS_IMPL_RELEASE_INHERITED(nsDocAccessible, nsHyperTextAccessible)
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessible
 
@@ -180,17 +200,17 @@ nsDocAccessible::GetName(nsAString& aNam
 
 // nsAccessible public method
 nsresult
 nsDocAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_PANE; // Fall back
 
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
-    nsCoreUtils::GetDocShellTreeItemFor(mDOMNode);
+    nsCoreUtils::GetDocShellTreeItemFor(mDocument);
   if (docShellTreeItem) {
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
     PRInt32 itemType;
     docShellTreeItem->GetItemType(&itemType);
     if (sameTypeRoot == docShellTreeItem) {
       // Root of content or chrome tree
       if (itemType == nsIDocShellTreeItem::typeChrome) {
@@ -228,19 +248,18 @@ nsDocAccessible::SetRoleMapEntry(nsRoleM
   mRoleMapEntry = aRoleMapEntry;
 
   nsIDocument *parentDoc = mDocument->GetParentDocument();
   if (!parentDoc)
     return; // No parent document for the root document
 
   // Allow use of ARIA role from outer to override
   nsIContent *ownerContent = parentDoc->FindContentForSubDocument(mDocument);
-  nsCOMPtr<nsIDOMNode> ownerNode(do_QueryInterface(ownerContent));
-  if (ownerNode) {
-    nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(ownerNode);
+  if (ownerContent) {
+    nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(ownerContent);
     if (roleMapEntry)
       mRoleMapEntry = roleMapEntry; // Override
   }
 }
 
 NS_IMETHODIMP 
 nsDocAccessible::GetDescription(nsAString& aDescription)
 {
@@ -257,31 +276,39 @@ nsDocAccessible::GetDescription(nsAStrin
 
   return NS_OK;
 }
 
 // nsAccessible public method
 nsresult
 nsDocAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
 {
-  nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
-  NS_ENSURE_A11Y_SUCCESS(rv, rv);
+  *aState = 0;
+
+  if (IsDefunct()) {
+    if (aExtraState)
+      *aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
+
+    return NS_OK_DEFUNCT_OBJECT;
+  }
+
+  if (aExtraState)
+    *aExtraState = 0;
 
 #ifdef MOZ_XUL
   nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
   if (!xulDoc)
 #endif
   {
     // XXX Need to invent better check to see if doc is focusable,
     // which it should be if it is scrollable. A XUL document could be focusable.
     // See bug 376803.
     *aState |= nsIAccessibleStates::STATE_FOCUSABLE;
-    if (gLastFocusedNode == mDOMNode) {
+    if (gLastFocusedNode == mDocument)
       *aState |= nsIAccessibleStates::STATE_FOCUSED;
-    }
   }
 
   if (nsCoreUtils::IsDocumentBusy(mDocument)) {
     *aState |= nsIAccessibleStates::STATE_BUSY;
     if (aExtraState) {
       *aExtraState |= nsIAccessibleStates::EXT_STATE_STALE;
     }
   }
@@ -339,54 +366,50 @@ NS_IMETHODIMP nsDocAccessible::GetFocuse
   // XXXndeakin P3 accessibility shouldn't be caching the focus
   if (!gLastFocusedNode) {
     *aFocusedChild = nsnull;
     return NS_OK;
   }
 
   // Return an accessible for the current global focus, which does not have to
   // be contained within the current document.
-  nsCOMPtr<nsIAccessibilityService> accService =
-    do_GetService("@mozilla.org/accessibilityService;1");
-  return accService->GetAccessibleFor(gLastFocusedNode, aFocusedChild);
+  NS_IF_ADDREF(*aFocusedChild = GetAccService()->GetAccessible(gLastFocusedNode));
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsDocAccessible::TakeFocus()
 {
-  NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
   PRUint32 state;
   GetStateInternal(&state, nsnull);
   if (0 == (state & nsIAccessibleStates::STATE_FOCUSABLE)) {
     return NS_ERROR_FAILURE; // Not focusable
   }
 
+  // Focus the document.
   nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
-  if (fm) {
-    nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(mDOMNode));
-    nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
-    if (document) {
-      // focus the document
-      nsCOMPtr<nsIDOMElement> newFocus;
-      return fm->MoveFocus(document->GetWindow(), nsnull,
-                           nsIFocusManager::MOVEFOCUS_ROOT, 0,
-                           getter_AddRefs(newFocus));
-    }
-  }
-  return NS_ERROR_FAILURE;
+  NS_ENSURE_STATE(fm);
+
+  nsCOMPtr<nsIDOMElement> newFocus;
+  return fm->MoveFocus(mDocument->GetWindow(), nsnull,
+                       nsIFocusManager::MOVEFOCUS_ROOT, 0,
+                       getter_AddRefs(newFocus));
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessibleDocument
 
 NS_IMETHODIMP nsDocAccessible::GetURL(nsAString& aURL)
 {
-  if (!mDocument) {
-    return NS_ERROR_FAILURE; // Document has been shut down
-  }
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
   nsCOMPtr<nsISupports> container = mDocument->GetContainer();
   nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(container));
   nsCAutoString theURL;
   if (webNav) {
     nsCOMPtr<nsIURI> pURI;
     webNav->GetCurrentURI(getter_AddRefs(pURI));
     if (pURI)
       pURI->GetSpec(theURL);
@@ -478,30 +501,24 @@ nsDocAccessible::GetDOMDocument(nsIDOMDo
 }
 
 // nsIAccessibleHyperText method
 NS_IMETHODIMP nsDocAccessible::GetAssociatedEditor(nsIEditor **aEditor)
 {
   NS_ENSURE_ARG_POINTER(aEditor);
   *aEditor = nsnull;
 
-  if (!mDocument)
+  if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   // Check if document is editable (designMode="on" case). Otherwise check if
   // the html:body (for HTML document case) or document element is editable.
-  if (!mDocument->HasFlag(NODE_IS_EDITABLE)) {
-    nsCOMPtr<nsIDOMNode> DOMDocument(do_QueryInterface(mDocument));
-    nsCOMPtr<nsIDOMElement> DOMElement =
-      nsCoreUtils::GetDOMElementFor(DOMDocument);
-    nsCOMPtr<nsIContent> content(do_QueryInterface(DOMElement));
-
-    if (!content || !content->HasFlag(NODE_IS_EDITABLE))
-      return NS_OK;
-  }
+  if (!mDocument->HasFlag(NODE_IS_EDITABLE) &&
+      !mContent->HasFlag(NODE_IS_EDITABLE))
+    return NS_OK;
 
   nsCOMPtr<nsISupports> container = mDocument->GetContainer();
   nsCOMPtr<nsIEditingSession> editingSession(do_GetInterface(container));
   if (!editingSession)
     return NS_OK; // No editing session interface
 
   nsCOMPtr<nsIEditor> editor;
   editingSession->GetEditorForWindow(mDocument->GetWindow(), getter_AddRefs(editor));
@@ -583,17 +600,17 @@ nsDocAccessible::Init()
   if (!mEventQueue)
     return NS_ERROR_OUT_OF_MEMORY;
 
   AddEventListeners();
 
   // Fire reorder event to notify new accessible document has been created and
   // attached to the tree.
   nsRefPtr<nsAccEvent> reorderEvent =
-    new nsAccReorderEvent(mParent, PR_FALSE, PR_TRUE, mDOMNode);
+    new nsAccReorderEvent(mParent, PR_FALSE, PR_TRUE, mDocument);
   if (!reorderEvent)
     return NS_ERROR_OUT_OF_MEMORY;
 
   FireDelayedAccessibleEvent(reorderEvent);
   return NS_OK;
 }
 
 nsresult
@@ -638,20 +655,17 @@ nsDocAccessible::GetFrame()
     root = shell->GetRootFrame();
 
   return root;
 }
 
 PRBool
 nsDocAccessible::IsDefunct()
 {
-  if (nsHyperTextAccessibleWrap::IsDefunct())
-    return PR_TRUE;
-
-  return !mDocument;
+  return nsHyperTextAccessibleWrap::IsDefunct() || !mDocument;
 }
 
 // nsDocAccessible protected member
 void nsDocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame)
 {
   *aRelativeFrame = GetFrame();
 
   nsIDocument *document = mDocument;
@@ -893,23 +907,20 @@ nsDocAccessible::AttributeWillChange(nsI
 void
 nsDocAccessible::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
                                   PRInt32 aNameSpaceID, nsIAtom* aAttribute,
                                   PRInt32 aModType)
 {
   AttributeChangedImpl(aContent, aNameSpaceID, aAttribute);
 
   // If it was the focused node, cache the new state
-  nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(aContent);
-  if (targetNode == gLastFocusedNode) {
-    nsCOMPtr<nsIAccessible> focusedAccessible;
-    GetAccService()->GetAccessibleFor(targetNode, getter_AddRefs(focusedAccessible));
-    if (focusedAccessible) {
+  if (aContent == gLastFocusedNode) {
+    nsAccessible *focusedAccessible = GetAccService()->GetAccessible(aContent);
+    if (focusedAccessible)
       gLastFocusedAccessiblesState = nsAccUtils::State(focusedAccessible);
-    }
   }
 }
 
 // nsDocAccessible protected member
 void
 nsDocAccessible::AttributeChangedImpl(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute)
 {
   // Fire accessible event after short timer, because we need to wait for
@@ -937,42 +948,41 @@ nsDocAccessible::AttributeChangedImpl(ns
   if (!IsContentLoaded())
     return; // Still loading, ignore setting of initial attributes
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell();
   if (!shell) {
     return; // Document has been shut down
   }
 
-  nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(aContent));
-  NS_ASSERTION(targetNode, "No node for attr modified");
-  if (!targetNode || !nsAccUtils::IsNodeRelevant(targetNode))
+  NS_ASSERTION(aContent, "No node for attr modified");
+  if (!aContent || !nsAccUtils::IsNodeRelevant(aContent))
     return;
 
   // Universal boolean properties that don't require a role. Fire the state
   // change when disabled or aria-disabled attribute is set.
   if (aAttribute == nsAccessibilityAtoms::disabled ||
       aAttribute == nsAccessibilityAtoms::aria_disabled) {
 
     // Note. Checking the XUL or HTML namespace would not seem to gain us
     // anything, because disabled attribute really is going to mean the same
     // thing in any namespace.
 
     // Note. We use the attribute instead of the disabled state bit because
     // ARIA's aria-disabled does not affect the disabled state bit.
 
     nsRefPtr<nsAccEvent> enabledChangeEvent =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::EXT_STATE_ENABLED,
                                 PR_TRUE);
 
     FireDelayedAccessibleEvent(enabledChangeEvent);
 
     nsRefPtr<nsAccEvent> sensitiveChangeEvent =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::EXT_STATE_SENSITIVE,
                                 PR_TRUE);
 
     FireDelayedAccessibleEvent(sensitiveChangeEvent);
     return;
   }
 
   // Check for namespaced ARIA attribute
@@ -995,119 +1005,111 @@ nsDocAccessible::AttributeChangedImpl(ns
     return;
   }
   
   if (aAttribute == nsAccessibilityAtoms::alt ||
       aAttribute == nsAccessibilityAtoms::title ||
       aAttribute == nsAccessibilityAtoms::aria_label ||
       aAttribute == nsAccessibilityAtoms::aria_labelledby) {
     FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE,
-                               targetNode);
+                               aContent);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::selected ||
       aAttribute == nsAccessibilityAtoms::aria_selected) {
     // ARIA or XUL selection
-    nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectableContainer(targetNode);
+
+    nsAccessible *multiSelect =
+      nsAccUtils::GetMultiSelectableContainer(aContent);
     // Multi selects use selection_add and selection_remove
     // Single select widgets just mirror event_selection for
     // whatever gets event_focus, which is done in
     // nsRootAccessible::FireAccessibleFocusEvent()
     // So right here we make sure only to deal with multi selects
     if (multiSelect) {
       // Need to find the right event to use here, SELECTION_WITHIN would
       // seem right but we had started using it for something else
-      nsCOMPtr<nsIAccessNode> multiSelectAccessNode =
-        do_QueryInterface(multiSelect);
-      nsCOMPtr<nsIDOMNode> multiSelectDOMNode;
-      multiSelectAccessNode->GetDOMNode(getter_AddRefs(multiSelectDOMNode));
-      NS_ASSERTION(multiSelectDOMNode, "A new accessible without a DOM node!");
       FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
-                                 multiSelectDOMNode,
+                                 multiSelect->GetNode(),
                                  nsAccEvent::eAllowDupes);
 
       static nsIContent::AttrValuesArray strings[] =
         {&nsAccessibilityAtoms::_empty, &nsAccessibilityAtoms::_false, nsnull};
       if (aContent->FindAttrValueIn(kNameSpaceID_None, aAttribute,
                                     strings, eCaseMatters) >= 0) {
         FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_SELECTION_REMOVE,
-                                   targetNode);
+                                   aContent);
         return;
       }
 
       FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_SELECTION_ADD,
-                                 targetNode);
+                                 aContent);
     }
   }
 
   if (aAttribute == nsAccessibilityAtoms::contenteditable) {
     nsRefPtr<nsAccEvent> editableChangeEvent =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::EXT_STATE_EDITABLE,
                                 PR_TRUE);
     FireDelayedAccessibleEvent(editableChangeEvent);
     return;
   }
 }
 
 // nsDocAccessible protected member
 void
 nsDocAccessible::ARIAAttributeChanged(nsIContent* aContent, nsIAtom* aAttribute)
 {
-  nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(aContent));
-  if (!targetNode)
-    return;
-
   // Note: For universal/global ARIA states and properties we don't care if
   // there is an ARIA role present or not.
 
   if (aAttribute == nsAccessibilityAtoms::aria_required) {
     nsRefPtr<nsAccEvent> event =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::STATE_REQUIRED,
                                 PR_FALSE);
     FireDelayedAccessibleEvent(event);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::aria_invalid) {
     nsRefPtr<nsAccEvent> event =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::STATE_INVALID,
                                 PR_FALSE);
     FireDelayedAccessibleEvent(event);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::aria_activedescendant) {
     // The activedescendant universal property redirects accessible focus events
     // to the element with the id that activedescendant points to
-    nsCOMPtr<nsIDOMNode> currentFocus = GetCurrentFocus();
-    if (SameCOMIdentity(nsCoreUtils::GetRoleContent(currentFocus), targetNode)) {
+    nsCOMPtr<nsINode> focusedNode = GetCurrentFocus();
+    if (nsCoreUtils::GetRoleContent(focusedNode) == aContent) {
       nsRefPtr<nsRootAccessible> rootAcc = GetRootAccessible();
       if (rootAcc)
-        rootAcc->FireAccessibleFocusEvent(nsnull, currentFocus, nsnull, PR_TRUE);
+        rootAcc->FireAccessibleFocusEvent(nsnull, focusedNode, nsnull, PR_TRUE);
     }
     return;
   }
 
   // For aria drag and drop changes we fire a generic attribute change event;
   // at least until native API comes up with a more meaningful event.
   if (aAttribute == nsAccessibilityAtoms::aria_grabbed ||
       aAttribute == nsAccessibilityAtoms::aria_dropeffect) {
     FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_OBJECT_ATTRIBUTE_CHANGED,
-                               targetNode);
+                               aContent);
   }
 
   // We treat aria-expanded as a global ARIA state for historical reasons
   if (aAttribute == nsAccessibilityAtoms::aria_expanded) {
     nsRefPtr<nsAccEvent> event =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::STATE_EXPANDED,
                                 PR_FALSE);
     FireDelayedAccessibleEvent(event);
     return;
   }
 
   if (!aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
     // We don't care about these other ARIA attribute changes unless there is
@@ -1119,61 +1121,61 @@ nsDocAccessible::ARIAAttributeChanged(ns
 
   // The following ARIA attributes only take affect when dynamic content role is present
   if (aAttribute == nsAccessibilityAtoms::aria_checked ||
       aAttribute == nsAccessibilityAtoms::aria_pressed) {
     const PRUint32 kState = (aAttribute == nsAccessibilityAtoms::aria_checked) ?
                             nsIAccessibleStates::STATE_CHECKED : 
                             nsIAccessibleStates::STATE_PRESSED;
     nsRefPtr<nsAccEvent> event =
-      new nsAccStateChangeEvent(targetNode, kState, PR_FALSE);
+      new nsAccStateChangeEvent(aContent, kState, PR_FALSE);
     FireDelayedAccessibleEvent(event);
-    if (targetNode == gLastFocusedNode) {
+    if (aContent == gLastFocusedNode) {
       // State changes for MIXED state currently only supported for focused item, because
       // otherwise we would need access to the old attribute value in this listener.
       // This is because we don't know if the previous value of aria-checked or aria-pressed was "mixed"
       // without caching that info.
       nsCOMPtr<nsIAccessible> accessible;
       event->GetAccessible(getter_AddRefs(accessible));
       if (accessible) {
         PRBool wasMixed = (gLastFocusedAccessiblesState & nsIAccessibleStates::STATE_MIXED) != 0;
         PRBool isMixed  =
           (nsAccUtils::State(accessible) & nsIAccessibleStates::STATE_MIXED) != 0;
         if (wasMixed != isMixed) {
           nsRefPtr<nsAccEvent> event =
-            new nsAccStateChangeEvent(targetNode,
+            new nsAccStateChangeEvent(aContent,
                                       nsIAccessibleStates::STATE_MIXED,
                                       PR_FALSE, isMixed);
           FireDelayedAccessibleEvent(event);
         }
       }
     }
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::aria_readonly) {
     nsRefPtr<nsAccEvent> event =
-      new nsAccStateChangeEvent(targetNode,
+      new nsAccStateChangeEvent(aContent,
                                 nsIAccessibleStates::STATE_READONLY,
                                 PR_FALSE);
     FireDelayedAccessibleEvent(event);
     return;
   }
 
   // Fire value change event whenever aria-valuetext is changed, or
   // when aria-valuenow is changed and aria-valuetext is empty
   if (aAttribute == nsAccessibilityAtoms::aria_valuetext ||      
       (aAttribute == nsAccessibilityAtoms::aria_valuenow &&
        (!aContent->HasAttr(kNameSpaceID_None,
            nsAccessibilityAtoms::aria_valuetext) ||
         aContent->AttrValueIs(kNameSpaceID_None,
             nsAccessibilityAtoms::aria_valuetext, nsAccessibilityAtoms::_empty,
             eCaseMatters)))) {
     FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
-                               targetNode);
+                               aContent);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::aria_multiselectable &&
       aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
     // This affects whether the accessible supports nsIAccessibleSelectable.
     // COM says we cannot change what interfaces are supported on-the-fly,
     // so invalidate this object. A new one will be created on demand.
@@ -1317,29 +1319,28 @@ nsDocAccessible::FireTextChangeEventForT
   PRInt32 contentOffset = aInfo->mChangeStart;
   PRUint32 contentLength = aIsInserted ?
     aInfo->mReplaceLength: // text has been added
     aInfo->mChangeEnd - contentOffset; // text has been removed
 
   if (contentLength == 0)
     return;
 
-  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
-  nsAccessible *accessible = GetAccService()->GetAccessible(node);
+  nsAccessible *accessible = GetAccService()->GetAccessible(aContent);
   if (!accessible)
     return;
 
   nsRefPtr<nsHyperTextAccessible> textAccessible =
     do_QueryObject(accessible->GetParent());
   if (!textAccessible)
     return;
 
   // Get offset within hypertext accessible.
   PRInt32 offset = 0;
-  textAccessible->DOMPointToHypertextOffset(node, contentOffset, &offset);
+  textAccessible->DOMPointToHypertextOffset(aContent, contentOffset, &offset);
 
   nsIFrame* frame = aContent->GetPrimaryFrame();
   if (!frame)
     return;
 
   // Get added or removed text.
   PRUint32 textOffset = 0;
   nsresult rv = textAccessible->ContentToRenderedOffset(frame, contentOffset,
@@ -1365,17 +1366,17 @@ nsDocAccessible::FireTextChangeEventForT
                                aIsInserted, PR_FALSE);
   FireDelayedAccessibleEvent(event);
 
   FireValueChangeForTextFields(textAccessible);
 }
 
 already_AddRefed<nsAccEvent>
 nsDocAccessible::CreateTextChangeEventForNode(nsAccessible *aContainerAccessible,
-                                              nsIDOMNode *aChangeNode,
+                                              nsIContent *aChangeNode,
                                               nsAccessible *aAccessibleForChangeNode,
                                               PRBool aIsInserting,
                                               PRBool aIsAsynch,
                                               EIsFromUserInput aIsFromUserInput)
 {
   nsRefPtr<nsHyperTextAccessible> textAccessible =
     do_QueryObject(aContainerAccessible);
   if (!textAccessible) {
@@ -1391,28 +1392,26 @@ nsDocAccessible::CreateTextChangeEventFo
     // A span-level object or something else without an accessible is being removed, where
     // it has no accessible but it has descendant content which is aggregated as text
     // into the parent hypertext.
     // In this case, accessibleToBeRemoved may just be the first
     // accessible that is removed, which affects the text in the hypertext container
     if (!changeAcc)
       return nsnull; // No descendant content that represents any text in the hypertext parent
 
-    nsCOMPtr<nsINode> changeNode(do_QueryInterface(aChangeNode));
-
     nsAccessible *parent = changeAcc->GetParent();
-    nsCOMPtr<nsINode> parentNode = do_QueryInterface(parent->GetDOMNode());
+    nsINode *parentNode = parent->GetNode();
     PRInt32 childCount = parent->GetChildCount();
     PRInt32 changeAccIdx = parent->GetIndexOf(changeAcc);
 
     for (PRInt32 idx = changeAccIdx; idx < childCount; idx++) {
       nsAccessible *child = parent->GetChildAt(idx);
-      nsCOMPtr<nsINode> childNode(do_QueryInterface(child->GetDOMNode()));
+      nsINode *childNode = child->GetNode();
 
-      if (!nsCoreUtils::IsAncestorOf(changeNode, childNode, parentNode)) {
+      if (!nsCoreUtils::IsAncestorOf(aChangeNode, childNode, parentNode)) {
         // We only want accessibles with DOM nodes as children of this node
         break;
       }
 
       child->AppendTextTo(text, 0, PR_UINT32_MAX);
     }
   }
   else {
@@ -1444,24 +1443,23 @@ nsDocAccessible::CreateTextChangeEventFo
                                aIsInserting, aIsAsynch, aIsFromUserInput);
   NS_IF_ADDREF(event);
 
   return event;
 }
 
 // nsDocAccessible public member
 nsresult
-nsDocAccessible::FireDelayedAccessibleEvent(PRUint32 aEventType,
-                                            nsIDOMNode *aDOMNode,
+nsDocAccessible::FireDelayedAccessibleEvent(PRUint32 aEventType, nsINode *aNode,
                                             nsAccEvent::EEventRule aAllowDupes,
                                             PRBool aIsAsynch,
                                             EIsFromUserInput aIsFromUserInput)
 {
   nsRefPtr<nsAccEvent> event =
-    new nsAccEvent(aEventType, aDOMNode, aIsAsynch, aIsFromUserInput, aAllowDupes);
+    new nsAccEvent(aEventType, aNode, aIsAsynch, aIsFromUserInput, aAllowDupes);
   NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
 
   return FireDelayedAccessibleEvent(event);
 }
 
 // nsDocAccessible public member
 nsresult
 nsDocAccessible::FireDelayedAccessibleEvent(nsAccEvent *aEvent)
@@ -1477,92 +1475,92 @@ nsDocAccessible::FireDelayedAccessibleEv
 
 void
 nsDocAccessible::ProcessPendingEvent(nsAccEvent *aEvent)
 {  
   nsCOMPtr<nsIAccessible> acc;
   aEvent->GetAccessible(getter_AddRefs(acc));
   nsRefPtr<nsAccessible> accessible(do_QueryObject(acc));
 
-  nsCOMPtr<nsIDOMNode> domNode;
-  aEvent->GetDOMNode(getter_AddRefs(domNode));
+  nsINode *node = aEvent->GetNode();
 
   PRUint32 eventType = aEvent->GetEventType();
   EIsFromUserInput isFromUserInput =
     aEvent->IsFromUserInput() ? eFromUserInput : eNoUserInput;
 
   PRBool isAsync = aEvent->IsAsync();
 
-  if (domNode == gLastFocusedNode && isAsync &&
+  if (node == gLastFocusedNode && isAsync &&
       (eventType == nsIAccessibleEvent::EVENT_SHOW ||
        eventType == nsIAccessibleEvent::EVENT_HIDE)) {
     // If frame type didn't change for this event, then we don't actually need to invalidate
     // However, we only keep track of the old frame type for the focus, where it's very
     // important not to destroy and recreate the accessible for minor style changes,
     // such as a:focus { overflow: scroll; }
-    nsCOMPtr<nsIContent> focusContent(do_QueryInterface(domNode));
+    nsCOMPtr<nsIContent> focusContent(do_QueryInterface(node));
     if (focusContent) {
       nsIFrame *focusFrame = focusContent->GetPrimaryFrame();
       nsIAtom *newFrameType =
         (focusFrame && focusFrame->GetStyleVisibility()->IsVisible()) ?
         focusFrame->GetType() : nsnull;
 
       if (newFrameType == gLastFocusedFrameType) {
         // Don't need to invalidate this current accessible, but can
         // just invalidate the children instead
-        FireShowHideEvents(domNode, PR_TRUE, eventType, eNormalEvent,
+        FireShowHideEvents(node, PR_TRUE, eventType, eNormalEvent,
                            isAsync, isFromUserInput); 
         return;
       }
       gLastFocusedFrameType = newFrameType;
     }
   }
 
   if (eventType == nsIAccessibleEvent::EVENT_SHOW) {
 
     nsAccessible *containerAccessible = nsnull;
     if (accessible)
       containerAccessible = accessible->GetParent();
 
     if (!containerAccessible) {
-      containerAccessible = GetAccService()->GetContainerAccessible(domNode,
+      containerAccessible = GetAccService()->GetContainerAccessible(node,
                                                                     PR_TRUE);
       if (!containerAccessible)
         containerAccessible = this;
     }
 
     if (isAsync) {
       // For asynch show, delayed invalidatation of parent's children
       containerAccessible->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);
+      InvalidateChildrenInSubtree(node);
     }
 
     // Also fire text changes if the node being created could affect the text in an nsIAccessibleText parent.
     // When a node is being made visible or is inserted, the text in an ancestor hyper text will gain characters
     // At this point we now have the frame and accessible for this node if there is one. That is why we
     // wait to fire this here, instead of in InvalidateCacheSubtree(), where we wouldn't be able to calculate
     // the offset, length and text for the text change.
-    if (domNode && domNode != mDOMNode) {
+    if (node && node != mDocument) {
+      nsCOMPtr<nsIContent> content(do_QueryInterface(node));
       nsRefPtr<nsAccEvent> textChangeEvent =
-        CreateTextChangeEventForNode(containerAccessible, domNode, accessible,
+        CreateTextChangeEventForNode(containerAccessible, content, accessible,
                                      PR_TRUE, PR_TRUE, isFromUserInput);
       if (textChangeEvent) {
         // XXX Queue them up and merge the text change events
         // XXX We need a way to ignore SplitNode and JoinNode() when they
         // do not affect the text within the hypertext
         nsEventShell::FireEvent(textChangeEvent);
       }
     }
 
     // Fire show/create events for this node or first accessible descendants of it
-    FireShowHideEvents(domNode, PR_FALSE, eventType, eNormalEvent, isAsync,
+    FireShowHideEvents(node, PR_FALSE, eventType, eNormalEvent, isAsync,
                        isFromUserInput); 
     return;
   }
 
   if (accessible) {
     if (eventType == nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED) {
       nsCOMPtr<nsIAccessibleText> accessibleText = do_QueryObject(accessible);
       PRInt32 caretOffset;
@@ -1570,19 +1568,19 @@ nsDocAccessible::ProcessPendingEvent(nsA
 #ifdef DEBUG_A11Y
         PRUnichar chAtOffset;
         accessibleText->GetCharacterAtOffset(caretOffset, &chAtOffset);
         printf("\nCaret moved to %d with char %c", caretOffset, chAtOffset);
 #endif
 #ifdef DEBUG_CARET
         // Test caret line # -- fire an EVENT_ALERT on the focused node so we can watch the
         // line-number object attribute on it
-        nsCOMPtr<nsIAccessible> accForFocus;
-        GetAccService()->GetAccessibleFor(gLastFocusedNode, getter_AddRefs(accForFocus));
-        nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_ALERT, accForFocus);
+        nsAccessible *focusedAcc =
+          GetAccService()->GetAccessible(gLastFocusedNode);
+        nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_ALERT, focusedAcc);
 #endif
         nsRefPtr<nsAccEvent> caretMoveEvent =
           new nsAccCaretMoveEvent(accessible, caretOffset);
         if (!caretMoveEvent)
           return;
 
         nsEventShell::FireEvent(caretMoveEvent);
 
@@ -1603,63 +1601,58 @@ nsDocAccessible::ProcessPendingEvent(nsA
           reorderEvent->HasAccessibleInReasonSubtree()) {
         nsEventShell::FireEvent(aEvent);
       }
     }
     else {
       nsEventShell::FireEvent(aEvent);
 
       // Post event processing
-      if (eventType == nsIAccessibleEvent::EVENT_HIDE) {
+      if (eventType == nsIAccessibleEvent::EVENT_HIDE && node) {
         // Shutdown nsIAccessNode's or nsIAccessibles for any DOM nodes in
         // this subtree.
-        nsCOMPtr<nsIDOMNode> hidingNode;
-        aEvent->GetDOMNode(getter_AddRefs(hidingNode));
-        if (hidingNode) {
-          RefreshNodes(hidingNode); // Will this bite us with asynch events
-        }
+        // XXX: Will this bite us with asynch events.
+        RefreshNodes(node);
       }
     }
   }
 }
 
-void nsDocAccessible::InvalidateChildrenInSubtree(nsIDOMNode *aStartNode)
+void
+nsDocAccessible::InvalidateChildrenInSubtree(nsINode *aStartNode)
 {
   nsRefPtr<nsAccessible> acc = do_QueryObject(GetCachedAccessNode(aStartNode));
   if (acc)
     acc->InvalidateChildren();
 
   // Invalidate accessible children in the DOM subtree 
-  nsCOMPtr<nsINode> node = do_QueryInterface(aStartNode);
-  PRInt32 index, numChildren = node->GetChildCount();
+  PRInt32 index, numChildren = aStartNode->GetChildCount();
   for (index = 0; index < numChildren; index ++) {
-    nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(node->GetChildAt(index));
-    if (childNode)
-      InvalidateChildrenInSubtree(childNode);
+    nsINode *childNode = aStartNode->GetChildAt(index);
+    InvalidateChildrenInSubtree(childNode);
   }
 }
 
-void nsDocAccessible::RefreshNodes(nsIDOMNode *aStartNode)
+void
+nsDocAccessible::RefreshNodes(nsINode *aStartNode)
 {
   if (mAccessNodeCache.Count() <= 1) {
     return; // All we have is a doc accessible. There is nothing to invalidate, quit early
   }
 
   nsRefPtr<nsAccessNode> accessNode = GetCachedAccessNode(aStartNode);
 
   // Shut down accessible subtree, which may have been created for
   // anonymous content subtree
   nsRefPtr<nsAccessible> accessible = do_QueryObject(accessNode);
   if (accessible) {
     // Fire menupopup end if a menu goes away
     PRUint32 role = nsAccUtils::Role(accessible);
     if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
-      nsCOMPtr<nsIDOMNode> domNode;
-      accessNode->GetDOMNode(getter_AddRefs(domNode));
-      nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(domNode));
+      nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(aStartNode));
       if (!popup) {
         // Popup elements already fire these via DOMMenuInactive
         // handling in nsRootAccessible::HandleEvent
         nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
                                 accessible);
       }
     }
 
@@ -1668,41 +1661,39 @@ void nsDocAccessible::RefreshNodes(nsIDO
     if (accessible->GetCachedFirstChild()) {
       nsCOMPtr<nsIArray> children;
       // use GetChildren() to fetch all children at once, because after shutdown
       // the child references are cleared.
       accessible->GetChildren(getter_AddRefs(children));
       PRUint32 childCount =0;
       if (children)
         children->GetLength(&childCount);
-      nsCOMPtr<nsIDOMNode> possibleAnonNode;
+      nsINode *possibleAnonNode = nsnull;
       for (PRUint32 index = 0; index < childCount; index++) {
-        nsCOMPtr<nsIAccessNode> childAccessNode;
-        children->QueryElementAt(index, NS_GET_IID(nsIAccessNode),
+        nsRefPtr<nsAccessNode> childAccessNode;
+        children->QueryElementAt(index, NS_GET_IID(nsAccessNode),
                                  getter_AddRefs(childAccessNode));
-        childAccessNode->GetDOMNode(getter_AddRefs(possibleAnonNode));
+        possibleAnonNode = childAccessNode->GetNode();
         nsCOMPtr<nsIContent> iterContent = do_QueryInterface(possibleAnonNode);
         if (iterContent && iterContent->IsInAnonymousSubtree()) {
           // IsInAnonymousSubtree() check is a perf win -- make sure we don't
           // shut down the same subtree twice since we'll reach non-anon content via
           // DOM traversal later in this method
           RefreshNodes(possibleAnonNode);
         }
       }
     }
   }
 
   // Shutdown ordinary content subtree as well -- there may be
   // access node children which are not full accessible objects
-  nsCOMPtr<nsIDOMNode> nextNode, iterNode;
-  aStartNode->GetFirstChild(getter_AddRefs(nextNode));
-  while (nextNode) {
-    nextNode.swap(iterNode);
-    RefreshNodes(iterNode);
-    iterNode->GetNextSibling(getter_AddRefs(nextNode));
+  PRUint32 childCount = aStartNode->GetChildCount();
+  for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
+    nsIContent *childContent = aStartNode->GetChildAt(childIdx);
+    RefreshNodes(childContent);
   }
 
   if (!accessNode)
     return;
 
   if (accessNode == this) {
     // Don't shutdown our doc object -- this may just be from the finished loading.
     // We will completely shut it down when the pagehide event is received
@@ -1746,19 +1737,21 @@ nsDocAccessible::InvalidateCacheSubtree(
     aChangeType == nsIAccessibilityService::FRAME_SHOW ||
     aChangeType == nsIAccessibilityService::FRAME_SIGNIFICANT_CHANGE;
 
   // Invalidate cache subtree
   // We have to check for accessibles for each dom node by traversing DOM tree
   // instead of just the accessible tree, although that would be faster
   // Otherwise we might miss the nsAccessNode's that are not nsAccessible's.
 
-  NS_ENSURE_TRUE(mDOMNode,);
+  NS_ENSURE_TRUE(mDocument,);
 
-  nsCOMPtr<nsIDOMNode> childNode = aChild ? do_QueryInterface(aChild) : mDOMNode;
+  nsINode *childNode = aChild;
+  if (!childNode)
+    childNode = mDocument;
 
   nsCOMPtr<nsIPresShell> presShell = GetPresShell();
   NS_ENSURE_TRUE(presShell,);
   
   if (!IsContentLoaded()) {
     // Still loading document
     if (mAccessNodeCache.Count() <= 1) {
       // Still loading and no accessibles has yet been created other than this
@@ -1794,17 +1787,18 @@ nsDocAccessible::InvalidateCacheSubtree(
   }
 
   // Update last change state information
   nsRefPtr<nsAccessible> childAccessible =
     do_QueryObject(GetCachedAccessNode(childNode));
 
 #ifdef DEBUG_A11Y
   nsAutoString localName;
-  childNode->GetLocalName(localName);
+  if (aChild)
+    aChild->NodeInfo()->GetName(localName);
   const char *hasAccessible = childAccessible ? " (acc)" : "";
   if (aChangeType == nsIAccessibilityService::FRAME_HIDE)
     printf("[Hide %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   else if (aChangeType == nsIAccessibilityService::FRAME_SHOW)
     printf("[Show %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   else if (aChangeType == nsIAccessibilityService::FRAME_SIGNIFICANT_CHANGE)
     printf("[Layout change %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   else if (aChangeType == nsIAccessibilityService::NODE_APPEND)
@@ -1819,19 +1813,18 @@ nsDocAccessible::InvalidateCacheSubtree(
     GetAccService()->GetContainerAccessible(childNode, PR_TRUE);
   if (!containerAccessible) {
     containerAccessible = this;
   }
 
   if (!isShowing) {
     // Fire EVENT_HIDE.
     if (isHiding) {
-      nsCOMPtr<nsIContent> content(do_QueryInterface(childNode));
-      if (content) {
-        nsIFrame *frame = content->GetPrimaryFrame();
+      if (aChild) {
+        nsIFrame *frame = aChild->GetPrimaryFrame();
         if (frame) {
           nsIFrame *frameParent = frame->GetParent();
           if (!frameParent || !frameParent->GetStyleVisibility()->IsVisible()) {
             // Ancestor already hidden or being hidden at the same time:
             // don't process redundant hide event
             // This often happens when visibility is cleared for node,
             // which hides an entire subtree -- we get notified for each
             // node in the subtree and need to collate the hide events ourselves.
@@ -1845,27 +1838,28 @@ nsDocAccessible::InvalidateCacheSubtree(
     // for the first line accessible descendants. Fire before the accessible(s)
     // away.
     nsresult rv = FireShowHideEvents(childNode, PR_FALSE,
                                      nsIAccessibleEvent::EVENT_HIDE,
                                      eDelayedEvent, isAsynch);
     if (NS_FAILED(rv))
       return;
 
-    if (childNode != mDOMNode) { // Fire text change unless the node being removed is for this doc
+    if (aChild) {
+      // Fire text change unless the node being removed is for this doc.
       // When a node is hidden or removed, the text in an ancestor hyper text will lose characters
       // At this point we still have the frame and accessible for this node if there was one
       // XXX Collate events when a range is deleted
       // XXX We need a way to ignore SplitNode and JoinNode() when they
       // do not affect the text within the hypertext
       // Normally we only fire delayed events created from the node, not an
       // accessible object. See the nsAccTextChangeEvent constructor for details
       // about this exceptional case.
       nsRefPtr<nsAccEvent> textChangeEvent =
-        CreateTextChangeEventForNode(containerAccessible, childNode, childAccessible,
+        CreateTextChangeEventForNode(containerAccessible, aChild, childAccessible,
                                      PR_FALSE, isAsynch);
       if (textChangeEvent) {
         FireDelayedAccessibleEvent(textChangeEvent);
       }
     }
   }
 
   // We need to get an accessible for the mutation event's container node
@@ -1901,27 +1895,25 @@ nsDocAccessible::InvalidateCacheSubtree(
                                  childNode, nsAccEvent::eRemoveDupes,
                                  isAsynch);
     }
 
     // Check to see if change occurred inside an alert, and fire an EVENT_ALERT if it did
     nsIContent *ancestor = aChild;
     while (PR_TRUE) {
       if (roleMapEntry && roleMapEntry->role == nsIAccessibleRole::ROLE_ALERT) {
-        nsCOMPtr<nsIDOMNode> alertNode(do_QueryInterface(ancestor));
-        FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_ALERT, alertNode,
+        FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_ALERT, ancestor,
                                    nsAccEvent::eRemoveDupes, isAsynch);
         break;
       }
       ancestor = ancestor->GetParent();
-      nsCOMPtr<nsIDOMNode> ancestorNode = do_QueryInterface(ancestor);
-      if (!ancestorNode) {
+      if (!ancestor)
         break;
-      }
-      roleMapEntry = nsAccUtils::GetRoleMapEntry(ancestorNode);
+
+      roleMapEntry = nsAccUtils::GetRoleMapEntry(ancestor);
     }
   }
 
   FireValueChangeForTextFields(containerAccessible);
 
   // Fire an event so the MSAA clients know the children have changed. Also
   // the event is used internally by MSAA part.
 
@@ -1935,41 +1927,40 @@ nsDocAccessible::InvalidateCacheSubtree(
   // Filtering/coalescing of these events happens during the queue flush.
 
   PRBool isUnconditionalEvent = childAccessible ||
     aChild && nsAccUtils::HasAccessibleChildren(childNode);
 
   nsRefPtr<nsAccEvent> reorderEvent =
     new nsAccReorderEvent(containerAccessible, isAsynch,
                           isUnconditionalEvent,
-                          aChild ? childNode.get() : nsnull);
+                          aChild ? aChild : nsnull);
   NS_ENSURE_TRUE(reorderEvent,);
 
   FireDelayedAccessibleEvent(reorderEvent);
 }
 
 nsresult
-nsDocAccessible::FireShowHideEvents(nsIDOMNode *aDOMNode,
+nsDocAccessible::FireShowHideEvents(nsINode *aNode,
                                     PRBool aAvoidOnThisNode,
                                     PRUint32 aEventType,
                                     EEventFiringType aDelayedOrNormal,
                                     PRBool aIsAsyncChange,
                                     EIsFromUserInput aIsFromUserInput)
 {
-  NS_ENSURE_ARG(aDOMNode);
+  NS_ENSURE_ARG(aNode);
 
-  nsCOMPtr<nsIAccessible> accessible;
+  nsRefPtr<nsAccessible> accessible;
   if (!aAvoidOnThisNode) {
     if (aEventType == nsIAccessibleEvent::EVENT_HIDE) {
       // Don't allow creation for accessibles when nodes going away
-      accessible = do_QueryInterface(GetCachedAccessNode(aDOMNode));
+      accessible = do_QueryObject(GetCachedAccessNode(aNode));
     } else {
       // Allow creation of new accessibles for show events
-      GetAccService()->GetAttachedAccessibleFor(aDOMNode,
-                                                getter_AddRefs(accessible));
+      accessible = GetAccService()->GetAttachedAccessibleFor(aNode);
     }
   }
 
   if (accessible) {
     // Found an accessible, so fire the show/hide on it and don't look further
     // into this subtree.
     nsRefPtr<nsAccEvent> event =
       new nsAccEvent(aEventType, accessible, aIsAsyncChange, aIsFromUserInput,
@@ -1980,20 +1971,19 @@ nsDocAccessible::FireShowHideEvents(nsID
       return FireDelayedAccessibleEvent(event);
 
     nsEventShell::FireEvent(event);
     return NS_OK;
   }
 
   // Could not find accessible to show hide yet, so fire on any
   // accessible descendants in this subtree
-  nsCOMPtr<nsINode> node(do_QueryInterface(aDOMNode));
-  PRUint32 count = node->GetChildCount();
+  PRUint32 count = aNode->GetChildCount();
   for (PRUint32 index = 0; index < count; index++) {
-    nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(node->GetChildAt(index));
+    nsINode *childNode = aNode->GetChildAt(index);
     nsresult rv = FireShowHideEvents(childNode, PR_FALSE, aEventType,
                                      aDelayedOrNormal, aIsAsyncChange,
                                      aIsFromUserInput);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
--- a/accessible/src/base/nsDocAccessible.h
+++ b/accessible/src/base/nsDocAccessible.h
@@ -77,17 +77,18 @@ class nsDocAccessible : public nsHyperTe
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocAccessible, nsAccessible)
 
   NS_DECL_NSIACCESSIBLEDOCUMENT
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOCACCESSIBLE_IMPL_CID)
 
   NS_DECL_NSIOBSERVER
 
 public:
-  nsDocAccessible(nsIDOMNode *aNode, nsIWeakReference* aShell);
+  nsDocAccessible(nsIDocument *aDocument, nsIContent *aRootContent,
+                  nsIWeakReference* aShell);
   virtual ~nsDocAccessible();
 
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& aName);
   NS_IMETHOD GetDescription(nsAString& aDescription);
   NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
   NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
   NS_IMETHOD TakeFocus(void);
@@ -99,16 +100,17 @@ public:
   // nsIDocumentObserver
   NS_DECL_NSIDOCUMENTOBSERVER
 
   // nsAccessNode
   virtual nsresult Init();
   virtual nsresult Shutdown();
   virtual nsIFrame* GetFrame();
   virtual PRBool IsDefunct();
+  virtual nsINode* GetNode() const { return mDocument; }
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetARIAState(PRUint32 *aState, PRUint32 *aExtraState);
 
   virtual void SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry);
   virtual nsAccessible* GetParent();
@@ -144,17 +146,17 @@ public:
    * Non-virtual method to fire a delayed event after a 0 length timeout.
    *
    * @param aEventType   [in] the nsIAccessibleEvent event type
    * @param aDOMNode     [in] DOM node the accesible event should be fired for
    * @param aAllowDupes  [in] rule to process an event (see EEventRule constants)
    * @param aIsAsynch    [in] set to PR_TRUE if this is not being called from
    *                      code synchronous with a DOM event
    */
-  nsresult FireDelayedAccessibleEvent(PRUint32 aEventType, nsIDOMNode *aDOMNode,
+  nsresult FireDelayedAccessibleEvent(PRUint32 aEventType, nsINode *aNode,
                                       nsAccEvent::EEventRule aAllowDupes = nsAccEvent::eRemoveDupes,
                                       PRBool aIsAsynch = PR_FALSE,
                                       EIsFromUserInput aIsFromUserInput = eAutoDetect);
 
   /**
    * Fire accessible event after timeout.
    *
    * @param aEvent  [in] the event to fire
@@ -218,19 +220,23 @@ protected:
 
   /**
    * Invalidate parent-child relations for any cached accessible in the DOM
    * subtree. Accessible objects aren't destroyed.
    *
    * @param aStartNode  [in] the root of the subrtee to invalidate accessible
    *                      child/parent refs in
    */
-  void InvalidateChildrenInSubtree(nsIDOMNode *aStartNode);
+  void InvalidateChildrenInSubtree(nsINode *aStartNode);
 
-    void RefreshNodes(nsIDOMNode *aStartNode);
+  /**
+   * Traverse through DOM tree and shutdown accessible objects.
+   */
+  void RefreshNodes(nsINode *aStartNode);
+
     static void ScrollTimerCallback(nsITimer *aTimer, void *aClosure);
 
     /**
      * Fires accessible events when attribute is changed.
      *
      * @param aContent - node that attribute is changed for
      * @param aNameSpaceID - namespace of changed attribute
      * @param aAttribute - changed attribute
@@ -257,28 +263,28 @@ protected:
     void FireTextChangeEventForText(nsIContent *aContent,
                                     CharacterDataChangeInfo* aInfo,
                                     PRBool aIsInserted);
 
   /**
    * Create a text change event for a changed node.
    *
    * @param  aContainerAccessible  [in] the parent accessible for the node
-   * @param  aNode                 [in] the node that is being inserted or
+   * @param  aChangeNode           [in] the node that is being inserted or
    *                                 removed, or shown/hidden
    * @param  aAccessible           [in] the accessible for that node, or nsnull
    *                                 if none exists
    * @param  aIsInserting          [in] is aChangeNode being created or shown
    *                                 (vs. removed or hidden)
    * @param  aIsAsync              [in] whether casual change is async
    * @param  aIsFromUserInput      [in] the event is known to be from user input
    */
   already_AddRefed<nsAccEvent>
     CreateTextChangeEventForNode(nsAccessible *aContainerAccessible,
-                                 nsIDOMNode *aNode,
+                                 nsIContent *aChangeNode,
                                  nsAccessible *aAccessible,
                                  PRBool aIsInserting,
                                  PRBool aIsAsynch,
                                  EIsFromUserInput aIsFromUserInput = eAutoDetect);
 
   /**
    * Used to define should the event be fired on a delay.
    */
@@ -294,17 +300,17 @@ protected:
    * @param  aDOMNode          [in] the given node
    * @param  aAvoidOnThisNode  [in] call with PR_TRUE the first time to
    *                             prevent event firing on root node for change
    * @param  aEventType        [in] event type to fire an event
    * @param  aDelayedOrNormal  [in] whether to fire the event on a delay
    * @param  aIsAsyncChange    [in] whether casual change is async
    * @param  aIsFromUserInput  [in] the event is known to be from user input
    */
-  nsresult FireShowHideEvents(nsIDOMNode *aDOMNode, PRBool aAvoidOnThisNode,
+  nsresult FireShowHideEvents(nsINode *aDOMNode, PRBool aAvoidOnThisNode,
                               PRUint32 aEventType,
                               EEventFiringType aDelayedOrNormal,
                               PRBool aIsAsyncChange,
                               EIsFromUserInput aIsFromUserInput = eAutoDetect);
 
     /**
      * If the given accessible object is a ROLE_ENTRY, fire a value change event for it
      */
--- a/accessible/src/base/nsEventShell.cpp
+++ b/accessible/src/base/nsEventShell.cpp
@@ -50,18 +50,17 @@ void
 nsEventShell::FireEvent(nsAccEvent *aEvent)
 {
   if (!aEvent)
     return;
 
   nsRefPtr<nsAccessible> acc = do_QueryObject(aEvent->GetAccessible());
   NS_ENSURE_TRUE(acc,);
 
-  nsCOMPtr<nsIDOMNode> node;
-  aEvent->GetDOMNode(getter_AddRefs(node));
+  nsINode* node = aEvent->GetNode();
   if (node) {
     sEventTargetNode = node;
     sEventFromUserInput = aEvent->IsFromUserInput();
   }
 
   acc->HandleAccEvent(aEvent);
 
   sEventTargetNode = nsnull;
@@ -75,32 +74,32 @@ nsEventShell::FireEvent(PRUint32 aEventT
 
   nsRefPtr<nsAccEvent> event = new nsAccEvent(aEventType, aAccessible,
                                               aIsAsynch, aIsFromUserInput);
 
   FireEvent(event);
 }
 
 void 
-nsEventShell::GetEventAttributes(nsIDOMNode *aNode,
+nsEventShell::GetEventAttributes(nsINode *aNode,
                                  nsIPersistentProperties *aAttributes)
 {
   if (aNode != sEventTargetNode)
     return;
 
   nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::eventFromInput,
                          sEventFromUserInput ? NS_LITERAL_STRING("true") :
                                                NS_LITERAL_STRING("false"));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsEventShell: private
 
 PRBool nsEventShell::sEventFromUserInput = PR_FALSE;
-nsCOMPtr<nsIDOMNode> nsEventShell::sEventTargetNode;
+nsCOMPtr<nsINode> nsEventShell::sEventTargetNode;
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccEventQueue
 ////////////////////////////////////////////////////////////////////////////////
 
 nsAccEventQueue::nsAccEventQueue(nsDocAccessible *aDocument):
   mProcessingStarted(PR_FALSE), mDocument(aDocument), mFlushingEventsCount(0)
--- a/accessible/src/base/nsEventShell.h
+++ b/accessible/src/base/nsEventShell.h
@@ -73,21 +73,21 @@ public:
 
   /**
    * Append 'event-from-input' object attribute if the accessible event has
    * been fired just now for the given node.
    *
    * @param  aNode        [in] the DOM node
    * @param  aAttributes  [in, out] the attributes
    */
-  static void GetEventAttributes(nsIDOMNode *aNode,
+  static void GetEventAttributes(nsINode *aNode,
                                  nsIPersistentProperties *aAttributes);
 
 private:
-  static nsCOMPtr<nsIDOMNode> sEventTargetNode;
+  static nsCOMPtr<nsINode> sEventTargetNode;
   static PRBool sEventFromUserInput;
 };
 
 
 /**
  * Event queue.
  */
 class nsAccEventQueue : public nsISupports
--- a/accessible/src/base/nsFormControlAccessible.cpp
+++ b/accessible/src/base/nsFormControlAccessible.cpp
@@ -39,37 +39,35 @@
 
 // NOTE: alphabetically ordered
 #include "nsFormControlAccessible.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULControlElement.h"
 
-// ------------
-// Radio button
-// ------------
+////////////////////////////////////////////////////////////////////////////////
+// nsRadioButtonAccessible
+////////////////////////////////////////////////////////////////////////////////
 
-nsRadioButtonAccessible::nsRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
-nsFormControlAccessible(aNode, aShell)
-{ 
+nsRadioButtonAccessible::
+  nsRadioButtonAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsFormControlAccessible(aContent, aShell)
+{
 }
 
-/**
-  *
-  */
-NS_IMETHODIMP nsRadioButtonAccessible::GetNumActions(PRUint8 *_retval)
+NS_IMETHODIMP
+nsRadioButtonAccessible::GetNumActions(PRUint8 *aNumActions)
 {
-  *_retval = 1;
+  NS_ENSURE_ARG_POINTER(aNumActions);
+  *aNumActions = 1;
+
   return NS_OK;
 }
 
-/**
-  *
-  */
 NS_IMETHODIMP nsRadioButtonAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
 {
   if (aIndex == eAction_Click) {
     aName.AssignLiteral("select"); 
     return NS_OK;
   }
   return NS_ERROR_INVALID_ARG;
 }
--- a/accessible/src/base/nsFormControlAccessible.h
+++ b/accessible/src/base/nsFormControlAccessible.h
@@ -39,23 +39,23 @@
 #ifndef _nsFormControlAccessible_H_
 #define _nsFormControlAccessible_H_
 
 #include "nsBaseWidgetAccessible.h"
 
 typedef nsLeafAccessible nsFormControlAccessible;
 
 /**
-  * nsRadioButtonAccessible
+  * Generic class used for radio buttons.
   */
 class nsRadioButtonAccessible : public nsFormControlAccessible
 {
 
 public:
-  nsRadioButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
+  nsRadioButtonAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   // nsIAccessible
   NS_IMETHOD GetNumActions(PRUint8 *_retval);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 aIndex);
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
--- a/accessible/src/base/nsOuterDocAccessible.cpp
+++ b/accessible/src/base/nsOuterDocAccessible.cpp
@@ -40,19 +40,19 @@
 
 #include "nsAccUtils.h"
 #include "nsDocAccessible.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsOuterDocAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
-nsOuterDocAccessible::nsOuterDocAccessible(nsIDOMNode* aNode, 
-                                           nsIWeakReference* aShell):
-  nsAccessibleWrap(aNode, aShell)
+nsOuterDocAccessible::
+  nsOuterDocAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsAccessibleWrap(aContent, aShell)
 {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsOuterDocAccessible,
                              nsAccessible)
@@ -223,22 +223,20 @@ nsOuterDocAccessible::RemoveChild(nsAcce
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible protected
 
 void
 nsOuterDocAccessible::CacheChildren()
 {
   // Request document accessible for the content document to make sure it's
   // created because once it's created it appends itself as a child.
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  nsIDocument *outerDoc = content->GetCurrentDoc();
+  nsIDocument *outerDoc = mContent->GetCurrentDoc();
   if (!outerDoc)
     return;
 
-  nsIDocument *innerDoc = outerDoc->GetSubDocumentFor(content);
-  nsCOMPtr<nsIDOMNode> innerNode(do_QueryInterface(innerDoc));
-  if (!innerNode)
+  nsIDocument *innerDoc = outerDoc->GetSubDocumentFor(mContent);
+  if (!innerDoc)
     return;
 
   nsDocAccessible *docAcc = GetAccService()->GetDocAccessible(innerDoc);
   NS_ASSERTION(docAcc && docAcc->GetParent() == this,
                "Document accessible isn't a child of outerdoc accessible!");
 }
--- a/accessible/src/base/nsOuterDocAccessible.h
+++ b/accessible/src/base/nsOuterDocAccessible.h
@@ -48,18 +48,17 @@
  * opposed to the nsDocAccessibleWrap which is "inner". The outer node is
  * a something like tags listed above, whereas the inner node corresponds to
  * the inner document root.
  */
 
 class nsOuterDocAccessible : public nsAccessibleWrap
 {
 public:
-  nsOuterDocAccessible(nsIDOMNode* aNode, 
-                       nsIWeakReference* aShell);
+  nsOuterDocAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIAccessible
   NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD GetActionDescription(PRUint8 aIndex, nsAString& aDescription);
   NS_IMETHOD DoAction(PRUint8 aIndex);
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -36,16 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAccessibilityService.h"
 #include "nsApplicationAccessibleWrap.h"
 #include "nsAccUtils.h"
 #include "nsCoreUtils.h"
 #include "nsRelUtils.h"
 
+#include "mozilla/dom/Element.h"
 #include "nsHTMLSelectAccessible.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEventListener.h"
@@ -100,18 +101,20 @@ else
 NS_IMPL_QUERY_TAIL_INHERITING(nsDocAccessible)
 
 NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsDocAccessible) 
 NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsDocAccessible)
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
-nsRootAccessible::nsRootAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell):
-  nsDocAccessibleWrap(aDOMNode, aShell)
+nsRootAccessible::
+  nsRootAccessible(nsIDocument *aDocument, nsIContent *aRootContent,
+                   nsIWeakReference *aShell) :
+  nsDocAccessibleWrap(aDocument, aRootContent, aShell)
 {
 }
 
 nsRootAccessible::~nsRootAccessible()
 {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -166,17 +169,17 @@ nsRootAccessible::GetRoleInternal(PRUint
 // nsRootAccessible protected member
 #ifdef MOZ_XUL
 PRUint32 nsRootAccessible::GetChromeFlags()
 {
   // Return the flag set for the top level window as defined 
   // by nsIWebBrowserChrome::CHROME_WINDOW_[FLAGNAME]
   // Not simple: nsIXULWindow is not just a QI from nsIDOMWindow
   nsCOMPtr<nsIDocShellTreeItem> treeItem =
-    nsCoreUtils::GetDocShellTreeItemFor(mDOMNode);
+    nsCoreUtils::GetDocShellTreeItemFor(mDocument);
   NS_ENSURE_TRUE(treeItem, 0);
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
   NS_ENSURE_TRUE(treeOwner, 0);
   nsCOMPtr<nsIXULWindow> xulWin(do_GetInterface(treeOwner));
   if (!xulWin) {
     return 0;
   }
@@ -312,18 +315,18 @@ nsresult nsRootAccessible::RemoveEventLi
 
 nsCaretAccessible*
 nsRootAccessible::GetCaretAccessible()
 {
   return mCaretAccessible;
 }
 
 PRBool
-nsRootAccessible::FireAccessibleFocusEvent(nsIAccessible *aAccessible,
-                                           nsIDOMNode *aNode,
+nsRootAccessible::FireAccessibleFocusEvent(nsAccessible *aAccessible,
+                                           nsINode *aNode,
                                            nsIDOMEvent *aFocusEvent,
                                            PRBool aForceEvent,
                                            PRBool aIsAsynch,
                                            EIsFromUserInput aIsFromUserInput)
 {
   if (mCaretAccessible) {
     nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aFocusEvent));
     if (nsevent) {
@@ -332,86 +335,75 @@ nsRootAccessible::FireAccessibleFocusEve
       // XUL:textbox. In this case, sometimes it is a later focus event
       // which points to the actual anonymous child with focus, so to be safe 
       // we need to reset the selection listener every time.
       // This happens because when some bindings handle focus, they retarget
       // focus to the appropriate child inside of themselves, but DOM focus
       // stays outside on that binding parent.
       nsCOMPtr<nsIDOMEventTarget> domEventTarget;
       nsevent->GetOriginalTarget(getter_AddRefs(domEventTarget));
-      nsCOMPtr<nsIDOMNode> realFocusedNode(do_QueryInterface(domEventTarget));
+      nsCOMPtr<nsIContent> realFocusedNode(do_QueryInterface(domEventTarget));
       if (!realFocusedNode) {
         // When FireCurrentFocusEvent() synthesizes a focus event,
         // the orignal target does not exist, so use the passed-in node
         // which is the relevant focused node
-        realFocusedNode = aNode;
+        realFocusedNode = do_QueryInterface(aNode);
       }
       if (realFocusedNode) {
         mCaretAccessible->SetControlSelectionListener(realFocusedNode);
       }
     }
   }
 
   // Check for aria-activedescendant, which changes which element has focus
-  nsCOMPtr<nsIDOMNode> finalFocusNode = aNode;
-  nsCOMPtr<nsIAccessible> finalFocusAccessible = aAccessible;
-  nsCOMPtr<nsIContent> finalFocusContent =
-    nsCoreUtils::GetRoleContent(finalFocusNode);
+  nsINode *finalFocusNode = aNode;
+  nsAccessible *finalFocusAccessible = aAccessible;
 
+  nsIContent *finalFocusContent = nsCoreUtils::GetRoleContent(finalFocusNode);
   if (finalFocusContent) {
     nsAutoString id;
     if (finalFocusContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant, id)) {
-      nsCOMPtr<nsIDOMDocument> domDoc;
-      aNode->GetOwnerDocument(getter_AddRefs(domDoc));
-      if (!domDoc) {  // Maybe the passed-in node actually is a doc
-        domDoc = do_QueryInterface(aNode);
-      }
-      if (!domDoc) {
-        return PR_FALSE;
-      }
-      nsCOMPtr<nsIDOMElement> relatedEl;
-      domDoc->GetElementById(id, getter_AddRefs(relatedEl));
-      finalFocusNode = do_QueryInterface(relatedEl);
+      nsIDocument *doc = aNode->GetOwnerDoc();
+      finalFocusNode = doc->GetElementById(id);
       if (!finalFocusNode) {
         // If aria-activedescendant is set to nonextistant ID, then treat as focus
         // on the activedescendant container (which has real DOM focus)
         finalFocusNode = aNode;
       }
       finalFocusAccessible = nsnull;
     }
   }
 
   // Fire focus only if it changes, but always fire focus events when aForceEvent == PR_TRUE
   if (gLastFocusedNode == finalFocusNode && !aForceEvent) {
     return PR_FALSE;
   }
 
   if (!finalFocusAccessible) {
-    GetAccService()->GetAccessibleFor(finalFocusNode, getter_AddRefs(finalFocusAccessible));      
+    finalFocusAccessible = GetAccService()->GetAccessible(finalFocusNode);
     // For activedescendant, the ARIA spec does not require that the user agent
     // checks whether finalFocusNode is actually a descendant of the element with
     // the activedescendant attribute.
     if (!finalFocusAccessible) {
       return PR_FALSE;
     }
   }
 
   gLastFocusedAccessiblesState = nsAccUtils::State(finalFocusAccessible);
   PRUint32 role = nsAccUtils::Role(finalFocusAccessible);
   if (role == nsIAccessibleRole::ROLE_MENUITEM) {
     if (!mCurrentARIAMenubar) {  // Entering menus
       // The natural role is the role that this type of element normally has
       PRUint32 naturalRole = nsAccUtils::RoleInternal(finalFocusAccessible);
       if (role != naturalRole) { // Must be a DHTML menuitem
-        nsCOMPtr<nsIAccessible> menuBarAccessible =
+        nsAccessible *menuBarAccessible =
           nsAccUtils::GetAncestorWithRole(finalFocusAccessible,
                                           nsIAccessibleRole::ROLE_MENUBAR);
-        nsCOMPtr<nsIAccessNode> menuBarAccessNode = do_QueryInterface(menuBarAccessible);
-        if (menuBarAccessNode) {
-          menuBarAccessNode->GetDOMNode(getter_AddRefs(mCurrentARIAMenubar));
+        if (menuBarAccessible) {
+          mCurrentARIAMenubar = menuBarAccessible->GetNode();
           if (mCurrentARIAMenubar) {
             nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_START,
                                     menuBarAccessible, PR_FALSE,
                                     aIsFromUserInput);
           }
         }
       }
     }
@@ -454,103 +446,98 @@ nsRootAccessible::FireAccessibleFocusEve
 }
 
 void
 nsRootAccessible::FireCurrentFocusEvent()
 {
   if (IsDefunct())
     return;
 
-  nsCOMPtr<nsIDOMNode> focusedNode = GetCurrentFocus();
+  nsCOMPtr<nsINode> focusedNode = GetCurrentFocus();
   if (!focusedNode) {
     return; // No current focus
   }
 
   // Simulate a focus event so that we can reuse code that fires focus for container children like treeitems
   nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(mDocument);
   if (docEvent) {
     nsCOMPtr<nsIDOMEvent> event;
     if (NS_SUCCEEDED(docEvent->CreateEvent(NS_LITERAL_STRING("Events"),
                                            getter_AddRefs(event))) &&
         NS_SUCCEEDED(event->InitEvent(NS_LITERAL_STRING("focus"), PR_TRUE, PR_TRUE))) {
       // Get the target node we really want for the event.
-      nsIAccessibilityService* accService = GetAccService();
-      if (accService) {
-        nsCOMPtr<nsIDOMNode> targetNode;
-        accService->GetRelevantContentNodeFor(focusedNode,
-                                            getter_AddRefs(targetNode));
 
-        if (targetNode) {
-          // If the focused element is document element or HTML body element
-          // then simulate the focus event for the document.
-          nsCOMPtr<nsIContent> targetContent(do_QueryInterface(targetNode));
-          if (targetContent) {
-            nsCOMPtr<nsIDOMNode> document =
-              do_QueryInterface(targetContent->GetOwnerDoc());
-            if (targetContent == nsCoreUtils::GetRoleContent(document)) {
-              HandleEventWithTarget(event, document);
-              return;
-            }
-          }
+      nsINode *targetNode =
+        GetAccService()->GetRelevantContentNodeFor(focusedNode);
+      if (targetNode) {
+        // If the focused element is document element or HTML body element
+        // then simulate the focus event for the document.
+        nsINode *document = targetNode->GetOwnerDoc();
+        if (targetNode == nsCoreUtils::GetRoleContent(document)) {
+          HandleEventWithTarget(event, document);
+          return;
+        }
 
-          // Otherwise simulate the focus event for currently focused node.
-          HandleEventWithTarget(event, targetNode);
-        }
+        // Otherwise simulate the focus event for currently focused node.
+        HandleEventWithTarget(event, targetNode);
       }
     }
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIDOMEventListener
 
 NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
 {
   // Turn DOM events in accessibility events
   // Get info about event and target
   nsCOMPtr<nsIDOMNode> targetNode;
   GetTargetNode(aEvent, getter_AddRefs(targetNode));
   if (!targetNode)
     return NS_ERROR_FAILURE;
-  
-  return HandleEventWithTarget(aEvent, targetNode);
+
+  nsCOMPtr<nsINode> node(do_QueryInterface(targetNode));
+  return HandleEventWithTarget(aEvent, node);
 }
 
 
 // nsRootAccessible protected member
 nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent,
-                                                 nsIDOMNode* aTargetNode)
+                                                 nsINode* aTargetNode)
 {
   nsAutoString eventType;
   aEvent->GetType(eventType);
   nsAutoString localName;
-  aTargetNode->GetLocalName(localName);
+  nsCOMPtr<nsIContent> targetContent(do_QueryInterface(aTargetNode));
+  if (targetContent)
+    targetContent->NodeInfo()->GetName(localName);
 #ifdef MOZ_XUL
   PRBool isTree = localName.EqualsLiteral("tree");
 #endif
 #ifdef DEBUG_A11Y
   // Very useful for debugging, please leave this here.
   if (eventType.EqualsLiteral("AlertActive")) {
     printf("\ndebugging %s events for %s", NS_ConvertUTF16toUTF8(eventType).get(), NS_ConvertUTF16toUTF8(localName).get());
   }
   if (localName.LowerCaseEqualsLiteral("textbox")) {
     printf("\ndebugging %s events for %s", NS_ConvertUTF16toUTF8(eventType).get(), NS_ConvertUTF16toUTF8(localName).get());
   }
 #endif
 
-  nsIAccessibilityService *accService = GetAccService();
+  nsAccessibilityService *accService = GetAccService();
   NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
 
-  nsIPresShell *eventShell = nsCoreUtils::GetPresShellFor(aTargetNode);
-  if (!eventShell) {
+  nsCOMPtr<nsIWeakReference> weakShell =
+    nsCoreUtils::GetWeakShellFor(aTargetNode);
+  if (!weakShell)
     return NS_OK;
-  }
 
   nsAccessible *accessible =
-    accService->GetAccessibleInShell(aTargetNode, eventShell);
+    accService->GetAccessibleInWeakShell(aTargetNode, weakShell);
 
   if (eventType.EqualsLiteral("popuphiding"))
     return HandlePopupHidingEvent(aTargetNode, accessible);
 
   if (!accessible)
     return NS_OK;
 
 #ifdef MOZ_XUL
@@ -662,27 +649,27 @@ nsresult nsRootAccessible::HandleEventWi
       nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SELECTION,
                               treeItemAccessible);
       return NS_OK;
     }
   }
   else
 #endif
   if (eventType.EqualsLiteral("focus")) {
-    if (aTargetNode == mDOMNode && mDOMNode != gLastFocusedNode) {
+    if (aTargetNode == mDocument && mDocument != gLastFocusedNode) {
       // Got focus event for the window, we will make sure that an accessible
       // focus event for initial focus is fired. We do this on a short timer
       // because the initial focus may not have been set yet.
       NS_DISPATCH_RUNNABLEMETHOD(FireCurrentFocusEvent, this)
     }
 
     // Keep a reference to the target node. We might want to change
     // it to the individual radio button or selected item, and send
     // the focus event to that.
-    nsCOMPtr<nsIDOMNode> focusedItem(aTargetNode);
+    nsCOMPtr<nsINode> focusedItem(aTargetNode);
 
     if (!treeItemAccessible) {
       nsCOMPtr<nsIDOMXULSelectControlElement> selectControl =
         do_QueryInterface(aTargetNode);
       if (selectControl) {
         nsCOMPtr<nsIDOMXULMenuListElement> menuList =
           do_QueryInterface(aTargetNode);
         if (!menuList) {
@@ -691,17 +678,18 @@ nsresult nsRootAccessible::HandleEventWi
           nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
           selectControl->GetSelectedItem(getter_AddRefs(selectedItem));
           if (selectedItem)
             focusedItem = do_QueryInterface(selectedItem);
 
           if (!focusedItem)
             return NS_OK;
 
-          accessible = accService->GetAccessibleInShell(focusedItem, eventShell);
+          accessible = accService->GetAccessibleInWeakShell(focusedItem,
+                                                            weakShell);
           if (!accessible)
             return NS_OK;
         }
       }
     }
     FireAccessibleFocusEvent(accessible, focusedItem, aEvent);
   }
   else if (eventType.EqualsLiteral("blur")) {
@@ -752,17 +740,17 @@ nsresult nsRootAccessible::HandleEventWi
           NS_ENSURE_TRUE(containerParent, NS_ERROR_FAILURE);
           if (nsAccUtils::Role(containerParent) != nsIAccessibleRole::ROLE_COMBOBOX) {
             return NS_OK;
           }
         }
       }
     }
     if (!fireFocus) {
-      nsCOMPtr<nsIDOMNode> realFocusedNode = GetCurrentFocus();
+      nsCOMPtr<nsINode> realFocusedNode = GetCurrentFocus();
       nsCOMPtr<nsIContent> realFocusedContent = do_QueryInterface(realFocusedNode);
       nsCOMPtr<nsIContent> targetContent = do_QueryInterface(aTargetNode);
       nsIContent *containerContent = targetContent;
       while (containerContent) {
         nsCOMPtr<nsIDOMXULPopupElement> popup = do_QueryInterface(containerContent);
         if (popup || containerContent == realFocusedContent) { 
           // If we're inside the focus or a popup we can fire focus events
           // for the changed active item
@@ -914,22 +902,22 @@ nsRootAccessible::GetContentDocShell(nsI
 // nsIAccessible method
 NS_IMETHODIMP
 nsRootAccessible::GetRelationByType(PRUint32 aRelationType,
                                     nsIAccessibleRelation **aRelation)
 {
   NS_ENSURE_ARG_POINTER(aRelation);
   *aRelation = nsnull;
 
-  if (!mDOMNode || aRelationType != nsIAccessibleRelation::RELATION_EMBEDS) {
+  if (!mDocument || aRelationType != nsIAccessibleRelation::RELATION_EMBEDS) {
     return nsDocAccessibleWrap::GetRelationByType(aRelationType, aRelation);
   }
 
   nsCOMPtr<nsIDocShellTreeItem> treeItem =
-    nsCoreUtils::GetDocShellTreeItemFor(mDOMNode);
+    nsCoreUtils::GetDocShellTreeItemFor(mDocument);
   nsCOMPtr<nsIDocShellTreeItem> contentTreeItem = GetContentDocShell(treeItem);
   // there may be no content area, so we need a null check
   if (contentTreeItem) {
     nsDocAccessible *accDoc = nsAccUtils::GetDocAccessibleFor(contentTreeItem);
     return nsRelUtils::AddTarget(aRelationType, aRelation, accDoc);
   }
 
   return NS_OK;
@@ -945,17 +933,17 @@ nsRootAccessible::GetParent()
   // when root accessible was intialized.
   return mParent;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Protected members
 
 nsresult
-nsRootAccessible::HandlePopupShownEvent(nsIAccessible *aAccessible)
+nsRootAccessible::HandlePopupShownEvent(nsAccessible *aAccessible)
 {
   PRUint32 role = nsAccUtils::Role(aAccessible);
 
   if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
     // Don't fire menupopup events for combobox and autocomplete lists.
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_START,
                             aAccessible);
     return NS_OK;
@@ -967,68 +955,59 @@ nsRootAccessible::HandlePopupShownEvent(
     // AT's expect to get an EVENT_SHOW for the tooltip. 
     // In event callback the tooltip's accessible will be ready.
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SHOW, aAccessible);
     return NS_OK;
   }
 
   if (role == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
     // Fire expanded state change event for comboboxes and autocompeletes.
-    nsCOMPtr<nsIAccessible> comboboxAcc;
-    nsresult rv = aAccessible->GetParent(getter_AddRefs(comboboxAcc));
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    nsAccessible *comboboxAcc = aAccessible->GetParent();
     PRUint32 comboboxRole = nsAccUtils::Role(comboboxAcc);
     if (comboboxRole == nsIAccessibleRole::ROLE_COMBOBOX ||
         comboboxRole == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
       nsRefPtr<nsAccEvent> event =
         new nsAccStateChangeEvent(comboboxAcc,
                                   nsIAccessibleStates::STATE_EXPANDED,
                                   PR_FALSE, PR_TRUE);
       NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
 
-      nsRefPtr<nsAccessible> acc(do_QueryObject(comboboxAcc));
       nsEventShell::FireEvent(event);
       return NS_OK;
     }
   }
 
   return NS_OK;
 }
 
 nsresult
-nsRootAccessible::HandlePopupHidingEvent(nsIDOMNode *aNode,
-                                         nsIAccessible *aAccessible)
+nsRootAccessible::HandlePopupHidingEvent(nsINode *aNode,
+                                         nsAccessible *aAccessible)
 {
   // If accessible focus was on or inside popup that closes, then restore it
   // to true current focus. This is the case when we've been getting
   // DOMMenuItemActive events inside of a combo box that closes. The real focus
   // is on the combo box. It's also the case when a popup gets focus in ATK --
   // when it closes we need to fire an event to restore focus to where it was.
-  nsCOMPtr<nsINode> node(do_QueryInterface(aNode));
-  nsCOMPtr<nsINode> lastFocusedNode(do_QueryInterface(gLastFocusedNode));
 
   if (gLastFocusedNode &&
-      nsCoreUtils::IsAncestorOf(node, lastFocusedNode)) {
+      nsCoreUtils::IsAncestorOf(aNode, gLastFocusedNode)) {
     // Focus was on or inside of a popup that's being hidden
     FireCurrentFocusEvent();
   }
 
   // Fire expanded state change event for comboboxes and autocompletes.
   if (!aAccessible)
     return NS_OK;
 
   PRUint32 role = nsAccUtils::Role(aAccessible);
   if (role != nsIAccessibleRole::ROLE_COMBOBOX_LIST)
     return NS_OK;
 
-  nsCOMPtr<nsIAccessible> comboboxAcc;
-  nsresult rv = aAccessible->GetParent(getter_AddRefs(comboboxAcc));
-  NS_ENSURE_SUCCESS(rv, rv);
-
+  nsAccessible *comboboxAcc = aAccessible->GetParent();
   PRUint32 comboboxRole = nsAccUtils::Role(comboboxAcc);
   if (comboboxRole == nsIAccessibleRole::ROLE_COMBOBOX ||
       comboboxRole == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
     nsRefPtr<nsAccEvent> event =
       new nsAccStateChangeEvent(comboboxAcc,
                                 nsIAccessibleStates::STATE_EXPANDED,
                                 PR_FALSE, PR_FALSE);
     NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
--- a/accessible/src/base/nsRootAccessible.h
+++ b/accessible/src/base/nsRootAccessible.h
@@ -63,17 +63,18 @@
 const PRInt32 SCROLL_HASH_START_SIZE = 6;
 
 class nsRootAccessible : public nsDocAccessibleWrap,
                          public nsIDOMEventListener
 {
   NS_DECL_ISUPPORTS_INHERITED
 
 public:
-  nsRootAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell);
+  nsRootAccessible(nsIDocument *aDocument, nsIContent *aRootContent,
+                   nsIWeakReference *aShell);
   virtual ~nsRootAccessible();
 
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& aName);
   NS_IMETHOD GetRelationByType(PRUint32 aRelationType,
                                nsIAccessibleRelation **aRelation);
 
   // nsIDOMEventListener
@@ -98,18 +99,18 @@ public:
    * @param  aFocusAccessible  [in] the accessible which has received focus
    * @param  aFocusNode        [in] the DOM node which has received focus
    * @param  aFocusEvent       [in] DOM focus event that caused
    *                             the node/accessible to receive focus
    * @param  aForceEvent       [in] fire a focus event even if the last focused
    *                             item was the same
    * @return                    boolean -- was a focus event actually fired
    */
-  PRBool FireAccessibleFocusEvent(nsIAccessible *aFocusAccessible,
-                                  nsIDOMNode *aFocusNode,
+  PRBool FireAccessibleFocusEvent(nsAccessible *aFocusAccessible,
+                                  nsINode *aFocusNode,
                                   nsIDOMEvent *aFocusEvent,
                                   PRBool aForceEvent = PR_FALSE,
                                   PRBool aIsAsynch = PR_FALSE,
                                   EIsFromUserInput aIsFromUserInput = eAutoDetect);
 
     /**
       * Fire an accessible focus event for the current focused node,
       * if there is a focus.
@@ -118,36 +119,43 @@ public:
 
     nsCaretAccessible *GetCaretAccessible();
 
 protected:
   NS_DECL_RUNNABLEMETHOD(nsRootAccessible, FireCurrentFocusEvent)
 
     nsresult AddEventListeners();
     nsresult RemoveEventListeners();
-    nsresult HandleEventWithTarget(nsIDOMEvent* aEvent,
-                                   nsIDOMNode* aTargetNode);
+
+  /**
+   * Process DOM events.
+   */
+  nsresult HandleEventWithTarget(nsIDOMEvent* aEvent, nsINode* aTargetNode);
+
     static void GetTargetNode(nsIDOMEvent *aEvent, nsIDOMNode **aTargetNode);
 
-    /**
-     * Used in HandleEventWithTarget().
-     */
-    nsresult HandlePopupShownEvent(nsIAccessible *aAccessible);
-    nsresult HandlePopupHidingEvent(nsIDOMNode *aNode,
-                                    nsIAccessible *aAccessible);
+  /**
+   * Process "popupshown" event. Used by HandleEventWithTarget().
+   */
+
+  nsresult HandlePopupShownEvent(nsAccessible *aAccessible);
+  /*
+   * Process "popuphiding" event. Used by HandleEventWithTarget().
+   */
+  nsresult HandlePopupHidingEvent(nsINode *aNode, nsAccessible *aAccessible);
 
 #ifdef MOZ_XUL
     nsresult HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
                                             nsXULTreeAccessible *aAccessible);
     nsresult HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
                                         nsXULTreeAccessible *aAccessible);
 
     PRUint32 GetChromeFlags();
 #endif
     already_AddRefed<nsIDocShellTreeItem>
            GetContentDocShell(nsIDocShellTreeItem *aStart);
     nsRefPtr<nsCaretAccessible> mCaretAccessible;
-    nsCOMPtr<nsIDOMNode> mCurrentARIAMenubar;
+  nsCOMPtr<nsINode> mCurrentARIAMenubar;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsRootAccessible, NS_ROOTACCESSIBLE_IMPL_CID)
 
 #endif  
--- a/accessible/src/base/nsTextAccessible.cpp
+++ b/accessible/src/base/nsTextAccessible.cpp
@@ -40,18 +40,18 @@
 
 #include "nsTextAccessible.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsTextAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 nsTextAccessible::
-  nsTextAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell) :
-  nsLinkableAccessible(aDOMNode, aShell)
+  nsTextAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
+  nsLinkableAccessible(aContent, aShell)
 {
 }
 
 nsresult
 nsTextAccessible::GetRoleInternal(PRUint32 *aRole)
 {
   *aRole = nsIAccessibleRole::ROLE_TEXT_LEAF;
   return NS_OK;
--- a/accessible/src/base/nsTextAccessible.h
+++ b/accessible/src/base/nsTextAccessible.h
@@ -42,17 +42,17 @@
 #include "nsBaseWidgetAccessible.h"
 
 /**
  * Generic class used for text nodes.
  */
 class nsTextAccessible : public nsLinkableAccessible
 {
 public:
-  nsTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
+  nsTextAccessible(nsIContent *aContent, nsIWeakReference *aShell);
 
   // nsAccessible
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
                                 PRUint32 aLength);
 
 protected:
 
--- a/accessible/src/base/nsTextAttrs.cpp
+++ b/accessible/src/base/nsTextAttrs.cpp
@@ -126,34 +126,36 @@ nsTextAttrsMgr::GetAttributes(nsIPersist
         break;
 
       (*aEndHTOffset)++;
     }
 
     return NS_OK;
   }
 
-  nsIDOMNode *hyperTextNode = mHyperTextAcc->GetDOMNode();
-  nsCOMPtr<nsIDOMElement> hyperTextElm =
-    nsCoreUtils::GetDOMElementFor(mHyperTextAcc->GetDOMNode());
-  nsIFrame *rootFrame = nsCoreUtils::GetFrameFor(hyperTextElm);
+  // Get the content and frame of the accessible. In the case of document
+  // accessible it's role content and root frame.
+  nsIContent *hyperTextElm = mHyperTextAcc->GetContent();
+  nsIFrame *rootFrame = mHyperTextAcc->GetFrame();
+  NS_ASSERTION(rootFrame, "No frame for accessible!");
+  if (!rootFrame)
+    return NS_OK;
 
-  nsIDOMNode *offsetNode = nsnull;
-  nsCOMPtr<nsIDOMElement> offsetElm;
+  nsIContent *offsetNode = nsnull, *offsetElm = nsnull;
   nsIFrame *frame = nsnull;
   if (mOffsetAcc) {
-    offsetNode = mOffsetAcc->GetDOMNode();
+    offsetNode = mOffsetAcc->GetContent();
     offsetElm = nsCoreUtils::GetDOMElementFor(offsetNode);
-    frame = nsCoreUtils::GetFrameFor(offsetElm);
+    frame = offsetElm->GetPrimaryFrame();
   }
 
   nsTPtrArray<nsITextAttr> textAttrArray(10);
 
   // "language" text attribute
-  nsLangTextAttr langTextAttr(mHyperTextAcc, hyperTextNode, offsetNode);
+  nsLangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
   textAttrArray.AppendElement(static_cast<nsITextAttr*>(&langTextAttr));
 
   // "color" text attribute
   nsCSSTextAttr colorTextAttr(0, hyperTextElm, offsetElm);
   textAttrArray.AppendElement(static_cast<nsITextAttr*>(&colorTextAttr));
 
   // "font-family" text attribute
   nsCSSTextAttr fontFamilyTextAttr(1, hyperTextElm, offsetElm);
@@ -219,18 +221,17 @@ nsTextAttrsMgr::GetRange(const nsTPtrArr
   for (PRInt32 childIdx = mOffsetAccIdx - 1; childIdx >= 0; childIdx--) {
     nsAccessible *currAcc = mHyperTextAcc->GetChildAt(childIdx);
 
     // Stop on embedded accessible since embedded accessibles are combined into
     // own range.
     if (nsAccUtils::IsEmbeddedObject(currAcc))
       break;
 
-    nsCOMPtr<nsIDOMElement> currElm =
-      nsCoreUtils::GetDOMElementFor(currAcc->GetDOMNode());
+    nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
     NS_ENSURE_STATE(currElm);
 
     PRBool offsetFound = PR_FALSE;
     for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
       nsITextAttr *textAttr = aTextAttrArray[attrIdx];
       if (!textAttr->Equal(currElm)) {
         offsetFound = PR_TRUE;
         break;
@@ -245,18 +246,17 @@ nsTextAttrsMgr::GetRange(const nsTPtrArr
 
   // Navigate forward from anchor accessible to find end offset.
   PRInt32 childLen = mHyperTextAcc->GetChildCount();
   for (PRInt32 childIdx = mOffsetAccIdx + 1; childIdx < childLen; childIdx++) {
     nsAccessible *currAcc = mHyperTextAcc->GetChildAt(childIdx);
     if (nsAccUtils::IsEmbeddedObject(currAcc))
       break;
 
-    nsCOMPtr<nsIDOMElement> currElm =
-      nsCoreUtils::GetDOMElementFor(currAcc->GetDOMNode());
+    nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
     NS_ENSURE_STATE(currElm);
 
     PRBool offsetFound = PR_FALSE;
     for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
       nsITextAttr *textAttr = aTextAttrArray[attrIdx];
 
       // Alter the end offset when text attribute changes its value and stop
       // the search.
@@ -274,75 +274,71 @@ nsTextAttrsMgr::GetRange(const nsTPtrArr
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLangTextAttr
 
 nsLangTextAttr::nsLangTextAttr(nsHyperTextAccessible *aRootAcc, 
-                               nsIDOMNode *aRootNode, nsIDOMNode *aNode) :
-  nsTextAttr<nsAutoString>(aNode == nsnull)
+                               nsIContent *aRootContent, nsIContent *aContent) :
+  nsTextAttr<nsAutoString>(aContent == nsnull), mRootContent(aRootContent)
 {
-  mRootContent = do_QueryInterface(aRootNode);
-
   nsresult rv = aRootAcc->GetLanguage(mRootNativeValue);
   mIsRootDefined = NS_SUCCEEDED(rv) && !mRootNativeValue.IsEmpty();
 
-  if (aNode) {
-    nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
-    mIsDefined = GetLang(content, mNativeValue);
-  }
+  if (aContent)
+    mIsDefined = GetLang(aContent, mNativeValue);
 }
 
 PRBool
-nsLangTextAttr::GetValueFor(nsIDOMElement *aElm, nsAutoString *aValue)
+nsLangTextAttr::GetValueFor(nsIContent *aElm, nsAutoString *aValue)
 {
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aElm);
-  return GetLang(content, *aValue);
+  return GetLang(aElm, *aValue);
 }
 
 void
 nsLangTextAttr::Format(const nsAutoString& aValue, nsAString& aFormattedValue)
 {
   aFormattedValue = aValue;
 }
 
 PRBool
 nsLangTextAttr::GetLang(nsIContent *aContent, nsAString& aLang)
 {
   nsCoreUtils::GetLanguageFor(aContent, mRootContent, aLang);
   return !aLang.IsEmpty();
 }
 
+
 ////////////////////////////////////////////////////////////////////////////////
 // nsCSSTextAttr