Bug 460239 - move static methods from nsAccessible and nsAccessNode to utils, r=aaronlev
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 17 Oct 2008 18:10:43 +0800
changeset 20566 a65f95d85884b977aa59e714206efd8f37d0ae01
parent 20565 47f2b5370886063a011b4bbe326effaba2a0a192
child 20567 4ffb7e96343f32342434f3bc5f2cf78a7e91cab6
push id2970
push usersurkov.alexander@gmail.com
push dateFri, 17 Oct 2008 09:11:13 +0000
treeherdermozilla-central@a65f95d85884 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaaronlev
bugs460239
milestone1.9.1b2pre
Bug 460239 - move static methods from nsAccessible and nsAccessNode to utils, r=aaronlev
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsMaiInterfaceComponent.cpp
accessible/src/base/nsAccUtils.cpp
accessible/src/base/nsAccUtils.h
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessNode.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsAccessible.h
accessible/src/base/nsBaseWidgetAccessible.cpp
accessible/src/base/nsCaretAccessible.cpp
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsRootAccessible.cpp
accessible/src/base/nsTextUtils.cpp
accessible/src/html/nsHTMLFormControlAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/html/nsHyperTextAccessible.cpp
accessible/src/mac/mozAccessible.mm
accessible/src/mac/nsAccessibleWrap.h
accessible/src/mac/nsAccessibleWrap.mm
accessible/src/msaa/nsAccessNodeWrap.cpp
accessible/src/msaa/nsAccessibleWrap.cpp
accessible/src/msaa/nsDocAccessibleWrap.cpp
accessible/src/xul/nsXULFormControlAccessible.cpp
accessible/src/xul/nsXULMenuAccessible.cpp
accessible/src/xul/nsXULSelectAccessible.cpp
accessible/src/xul/nsXULTabAccessible.cpp
accessible/src/xul/nsXULTextAccessible.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -366,17 +366,17 @@ void nsAccessibleWrap::SetMaiHyperlink(M
     }
 }
 
 NS_IMETHODIMP nsAccessibleWrap::GetNativeInterface(void **aOutAccessible)
 {
     *aOutAccessible = nsnull;
 
     if (!mAtkObject) {
-        if (!mWeakShell || !IsEmbeddedObject(this)) {
+        if (!mWeakShell || !nsAccUtils::IsEmbeddedObject(this)) {
             // We don't create ATK objects for node which has been shutdown, or
             // nsIAccessible plain text leaves
             return NS_ERROR_FAILURE;
         }
 
         GType type = GetMaiAtkType(CreateMaiInterfaces());
         NS_ENSURE_TRUE(type, NS_ERROR_FAILURE);
         mAtkObject =
@@ -472,17 +472,17 @@ nsAccessibleWrap::CreateMaiInterfaces(vo
     //nsIAccessibleHyperLink
     nsCOMPtr<nsIAccessibleHyperLink> accessInterfaceHyperlink;
     QueryInterface(NS_GET_IID(nsIAccessibleHyperLink),
                    getter_AddRefs(accessInterfaceHyperlink));
     if (accessInterfaceHyperlink) {
        interfacesBits |= 1 << MAI_INTERFACE_HYPERLINK_IMPL;
     }
 
-    if (!MustPrune(this)) {  // These interfaces require children
+    if (!nsAccUtils::MustPrune(this)) {  // These interfaces require children
       //nsIAccessibleHypertext
       nsCOMPtr<nsIAccessibleHyperText> accessInterfaceHypertext;
       QueryInterface(NS_GET_IID(nsIAccessibleHyperText),
                      getter_AddRefs(accessInterfaceHypertext));
       if (accessInterfaceHypertext) {
           interfacesBits |= 1 << MAI_INTERFACE_HYPERTEXT;
       }
 
@@ -765,17 +765,18 @@ AtkRole
 getRoleCB(AtkObject *aAtkObj)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
     if (!accWrap) {
         return ATK_ROLE_INVALID;
     }
 
 #ifdef DEBUG_A11Y
-    NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(accWrap), "Does not support nsIAccessibleText when it should");
+    NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap),
+                 "Does not support nsIAccessibleText when it should");
 #endif
 
     if (aAtkObj->role == ATK_ROLE_INVALID) {
         PRUint32 accRole, atkRole;
         nsresult rv = accWrap->GetFinalRole(&accRole);
         NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID);
 
         atkRole = atkRoleMap[accRole]; // map to the actual value
@@ -875,17 +876,17 @@ getParentCB(AtkObject *aAtkObj)
     }
     return aAtkObj->accessible_parent;
 }
 
 gint
 getChildCountCB(AtkObject *aAtkObj)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
-    if (!accWrap || nsAccessibleWrap::MustPrune(accWrap)) {
+    if (!accWrap || nsAccUtils::MustPrune(accWrap)) {
         return 0;
     }
 
     PRInt32 count = 0;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
@@ -909,17 +910,17 @@ refChildCB(AtkObject *aAtkObj, gint aChi
       return nsnull;
     }
 
     // XXX Fix this so it is not O(n^2) to walk through the children!
     // Either we can cache the last accessed child so that we can just GetNextSibling()
     // or we should cache an array of children in each nsAccessible
     // (instead of mNextSibling on the children)
     nsAccessibleWrap *accWrap = GetAccessibleWrap(aAtkObj);
-    if (!accWrap || nsAccessibleWrap::MustPrune(accWrap)) {
+    if (!accWrap || nsAccUtils::MustPrune(accWrap)) {
         return nsnull;
     }
 
     nsCOMPtr<nsIAccessible> accChild;
     nsCOMPtr<nsIAccessibleHyperText> hyperText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleHyperText), getter_AddRefs(hyperText));
     if (hyperText) {
         // If HyperText, then number of links matches number of children
@@ -975,17 +976,17 @@ getIndexInParentCB(AtkObject *aAtkObj)
     PRInt32 currentIndex = 0;
 
     while (sibling != static_cast<nsIAccessible*>(accWrap)) {
       NS_ASSERTION(sibling, "Never ran into the same child that we started from");
 
       if (!sibling) {
           return -1;
       }
-      if (nsAccessible::IsEmbeddedObject(sibling)) {
+      if (nsAccUtils::IsEmbeddedObject(sibling)) {
         ++ currentIndex;
       }
 
       nsCOMPtr<nsIAccessible> tempAccessible;
       sibling->GetNextSibling(getter_AddRefs(tempAccessible));
       sibling.swap(tempAccessible);
     }
 
--- a/accessible/src/atk/nsMaiInterfaceComponent.cpp
+++ b/accessible/src/atk/nsMaiInterfaceComponent.cpp
@@ -64,17 +64,17 @@ componentInterfaceInitCB(AtkComponentIfa
 }
 
 AtkObject *
 refAccessibleAtPointCB(AtkComponent *aComponent,
                        gint aAccX, gint aAccY,
                        AtkCoordType aCoordType)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
-    if (!accWrap || nsAccessibleWrap::MustPrune(accWrap))
+    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);
         aAccX += winCoords.x;
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -38,21 +38,23 @@
 
 #include "nsCoreUtils.h"
 #include "nsAccUtils.h"
 
 #include "nsIAccessibleStates.h"
 #include "nsIAccessibleTypes.h"
 #include "nsPIAccessible.h"
 #include "nsPIAccessNode.h"
+
 #include "nsAccessibleEventData.h"
-
+#include "nsHyperTextAccessible.h"
 #include "nsAccessibilityAtoms.h"
 #include "nsAccessible.h"
 #include "nsARIAMap.h"
+
 #include "nsIDOMXULContainerElement.h"
 #include "nsIDOMXULSelectCntrlEl.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsWhitespaceTokenizer.h"
 
 void
 nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
                        nsIAtom *aAttrName, nsAString& aAttrValue)
@@ -170,17 +172,17 @@ nsAccUtils::SetAccAttrsForXULSelectContr
     nsCOMPtr<nsIDOMXULSelectControlItemElement> currItem;
     control->GetItemAtIndex(index, getter_AddRefs(currItem));
     nsCOMPtr<nsIDOMNode> currNode(do_QueryInterface(currItem));
 
     nsCOMPtr<nsIAccessible> itemAcc;
     nsAccessNode::GetAccService()->GetAccessibleFor(currNode,
                                                     getter_AddRefs(itemAcc));
     if (!itemAcc ||
-        nsAccessible::State(itemAcc) & nsIAccessibleStates::STATE_INVISIBLE) {
+        State(itemAcc) & nsIAccessibleStates::STATE_INVISIBLE) {
       setSize--;
       if (index < static_cast<PRUint32>(indexOf))
         posInSet--;
     }
   }
 
   SetAccGroupAttrs(aAttributes, 0, posInSet + 1, setSize);
 }
@@ -212,21 +214,21 @@ nsAccUtils::SetAccAttrsForXULContainerIt
     nsCOMPtr<nsIDOMXULElement> item;
     container->GetItemAtIndex(index, getter_AddRefs(item));
 
     nsCOMPtr<nsIAccessible> itemAcc;
     nsAccessNode::GetAccService()->GetAccessibleFor(item,
                                                     getter_AddRefs(itemAcc));
 
     if (itemAcc) {
-      PRUint32 itemRole = nsAccessible::Role(itemAcc);
+      PRUint32 itemRole = Role(itemAcc);
       if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
         break; // We reached the beginning of our group.
 
-      PRUint32 itemState = nsAccessible::State(itemAcc);
+      PRUint32 itemState = State(itemAcc);
       if (!(itemState & nsIAccessibleStates::STATE_INVISIBLE)) {
         setSize++;
         posInSet++;
       }
     }
   }
 
   for (PRInt32 index = indexOf + 1; index < static_cast<PRInt32>(itemsCount);
@@ -234,21 +236,21 @@ nsAccUtils::SetAccAttrsForXULContainerIt
     nsCOMPtr<nsIDOMXULElement> item;
     container->GetItemAtIndex(index, getter_AddRefs(item));
     
     nsCOMPtr<nsIAccessible> itemAcc;
     nsAccessNode::GetAccService()->GetAccessibleFor(item,
                                                     getter_AddRefs(itemAcc));
 
     if (itemAcc) {
-      PRUint32 itemRole = nsAccessible::Role(itemAcc);
+      PRUint32 itemRole = Role(itemAcc);
       if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
         break; // We reached the end of our group.
 
-      PRUint32 itemState = nsAccessible::State(itemAcc);
+      PRUint32 itemState = State(itemAcc);
       if (!(itemState & nsIAccessibleStates::STATE_INVISIBLE))
         setSize++;
     }
   }
 
   // Get level of the item.
   PRInt32 level = -1;
   while (container) {
@@ -544,17 +546,17 @@ nsAccUtils::GetScreenCoordsForParent(nsI
 
   nsIntRect parentRect = parentFrame->GetScreenRectExternal();
   return nsIntPoint(parentRect.x, parentRect.y);
 }
 
 nsRoleMapEntry*
 nsAccUtils::GetRoleMapEntry(nsIDOMNode *aNode)
 {
-  nsIContent *content = nsAccessible::GetRoleContent(aNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(aNode);
   nsAutoString roleString;
   if (!content || !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, roleString)) {
     return nsnull;
   }
 
   nsWhitespaceTokenizer tokenizer(roleString);
   while (tokenizer.hasMoreTokens()) {
     // Do a binary search through table for the next role in role list
@@ -576,8 +578,137 @@ nsAccUtils::GetRoleMapEntry(nsIDOMNode *
       }
     }
   }
 
   // Always use some entry if there is a role string
   // To ensure an accessible object is created
   return &nsARIAMap::gLandmarkRoleMap;
 }
+
+
+#ifdef DEBUG_A11Y
+
+PRBool
+nsAccUtils::IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible)
+{
+  PRBool foundText = PR_FALSE;
+  
+  nsCOMPtr<nsIAccessibleDocument> accDoc = do_QueryInterface(aAccessible);
+  if (accDoc) {
+    // Don't test for accessible docs, it makes us create accessibles too
+    // early and fire mutation events before we need to
+    return PR_TRUE;
+  }
+
+  nsCOMPtr<nsIAccessible> child, nextSibling;
+  aAccessible->GetFirstChild(getter_AddRefs(child));
+  while (child) {
+    if (IsText(child)) {
+      foundText = PR_TRUE;
+      break;
+    }
+    child->GetNextSibling(getter_AddRefs(nextSibling));
+    child.swap(nextSibling);
+  }
+
+  if (foundText) {
+    // found text child node
+    nsCOMPtr<nsIAccessibleText> text = do_QueryInterface(aAccessible);
+    if (!text)
+      return PR_FALSE;
+  }
+
+  return PR_TRUE; 
+}
+#endif
+
+PRInt32
+nsAccUtils::TextLength(nsIAccessible *aAccessible)
+{
+  if (!IsText(aAccessible))
+    return 1;
+  
+  nsCOMPtr<nsPIAccessNode> pAccNode(do_QueryInterface(aAccessible));
+  
+  nsIFrame *frame = pAccNode->GetFrame();
+  if (frame && frame->GetType() == nsAccessibilityAtoms::textFrame) {
+    // Ensure that correct text length is calculated (with non-rendered
+    // whitespace chars not counted).
+    nsIContent *content = frame->GetContent();
+    if (content) {
+      PRUint32 length;
+      nsresult rv = nsHyperTextAccessible::
+        ContentToRenderedOffset(frame, content->TextLength(), &length);
+      return NS_SUCCEEDED(rv) ? static_cast<PRInt32>(length) : -1;
+    }
+  }
+  
+  // For list bullets (or anything other accessible which would compute its own
+  // text. They don't have their own frame.
+  // XXX In the future, list bullets may have frame and anon content, so 
+  // we should be able to remove this at that point
+  nsCOMPtr<nsPIAccessible> pAcc(do_QueryInterface(aAccessible));
+  
+  nsAutoString text;
+  pAcc->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
+  return text.Length();
+}
+
+PRBool
+nsAccUtils::MustPrune(nsIAccessible *aAccessible)
+{ 
+  PRUint32 role = nsAccUtils::Role(aAccessible);
+
+  return role == nsIAccessibleRole::ROLE_MENUITEM || 
+    role == nsIAccessibleRole::ROLE_COMBOBOX_OPTION ||
+    role == nsIAccessibleRole::ROLE_OPTION ||
+    role == nsIAccessibleRole::ROLE_ENTRY ||
+    role == nsIAccessibleRole::ROLE_FLAT_EQUATION ||
+    role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
+    role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
+    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)
+{
+  nsCOMPtr<nsIDOMNode> relevantNode;
+  nsAccessNode::GetAccService()->GetRelevantContentNodeFor(aNode,
+                                                           getter_AddRefs(relevantNode));
+  return aNode == relevantNode;
+}
+
+already_AddRefed<nsIAccessible>
+nsAccUtils::GetMultiSelectFor(nsIDOMNode *aNode)
+{
+  if (!aNode)
+    return nsnull;
+
+  nsCOMPtr<nsIAccessible> accessible;
+  nsAccessNode::GetAccService()->GetAccessibleFor(aNode,
+                                                  getter_AddRefs(accessible));
+  if (!accessible)
+    return nsnull;
+
+  PRUint32 state = State(accessible);
+  if (0 == (state & nsIAccessibleStates::STATE_SELECTABLE))
+    return nsnull;
+
+  PRUint32 containerRole;
+  while (0 == (state & nsIAccessibleStates::STATE_MULTISELECTABLE)) {
+    nsIAccessible *current = accessible;
+    current->GetParent(getter_AddRefs(accessible));
+    if (!accessible || (NS_SUCCEEDED(accessible->GetFinalRole(&containerRole)) &&
+                        containerRole == nsIAccessibleRole::ROLE_PANE)) {
+      return nsnull;
+    }
+    state = State(accessible);
+  }
+
+  nsIAccessible *returnAccessible = nsnull;
+  accessible.swap(returnAccessible);
+  return returnAccessible;
+}
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsAccUtils_h_
 #define nsAccUtils_h_
 
 #include "nsIAccessible.h"
 #include "nsIAccessNode.h"
+#include "nsIAccessibleRole.h"
 #include "nsARIAMap.h"
 
 #include "nsIDOMNode.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIContent.h"
 #include "nsPoint.h"
 
 class nsAccUtils
@@ -205,13 +206,97 @@ public:
   static nsIntPoint GetScreenCoordsForParent(nsIAccessNode *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
    */
-   static nsRoleMapEntry* GetRoleMapEntry(nsIDOMNode *aNode);
+  static nsRoleMapEntry* GetRoleMapEntry(nsIDOMNode *aNode);
+
+  /**
+   * Return the role of the given accessible.
+   */
+  static PRUint32 Role(nsIAccessible *aAcc)
+  {
+    PRUint32 role = nsIAccessibleRole::ROLE_NOTHING;
+    if (aAcc)
+      aAcc->GetFinalRole(&role);
+
+    return role;
+  }
+
+  /**
+   * Return the state for the given accessible.
+   */
+  static PRUint32 State(nsIAccessible *aAcc)
+  {
+    PRUint32 state = 0;
+    if (aAcc)
+      aAcc->GetFinalState(&state, nsnull);
+
+    return state;
+  }
+
+#ifdef DEBUG_A11Y
+  /**
+   * Detect whether the given accessible object implements nsIAccessibleText,
+   * when it is text or has text child node.
+   */
+  static PRBool IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible);
+#endif
+
+  /**
+   * Return true if the given accessible has text role.
+   */
+  static PRBool IsText(nsIAccessible *aAcc)
+  {
+    PRUint32 role = Role(aAcc);
+    return role == nsIAccessibleRole::ROLE_TEXT_LEAF ||
+           role == nsIAccessibleRole::ROLE_STATICTEXT;
+  }
+
+  /**
+   * Return text length of the given accessible, return -1 on failure.
+   */
+  static PRInt32 TextLength(nsIAccessible *aAccessible);
+
+  /**
+   * Return true if the given accessible is embedded object.
+   */
+  static PRBool IsEmbeddedObject(nsIAccessible *aAcc)
+  {
+    PRUint32 role = Role(aAcc);
+    return role != nsIAccessibleRole::ROLE_TEXT_LEAF &&
+           role != nsIAccessibleRole::ROLE_WHITESPACE &&
+           role != nsIAccessibleRole::ROLE_STATICTEXT;
+  }
+
+  /**
+   * Return true if the given accessible hasn't children.
+   */
+  static PRBool IsLeaf(nsIAccessible *aAcc)
+  {
+    PRInt32 numChildren;
+    aAcc->GetChildCount(&numChildren);
+    return numChildren > 0;
+  }
+
+  /**
+   * Return true if the given accessible can't have children. Used when exposing
+   * 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);
+
+  /**
+   * Return multiselectable parent for the given selectable accessible if any.
+   */
+  static already_AddRefed<nsIAccessible> GetMultiSelectFor(nsIDOMNode *aNode);
 };
 
 #endif
-
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -41,26 +41,24 @@
 #include "nsAccessibilityAtoms.h"
 #include "nsHashtable.h"
 #include "nsIAccessibilityService.h"
 #include "nsIAccessibleDocument.h"
 #include "nsPIAccessibleDocument.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocument.h"
-#include "nsIDocumentViewer.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsIDOMCSSPrimitiveValue.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMNSHTMLElement.h"
-#include "nsIDOMViewCSS.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFrame.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
@@ -611,17 +609,18 @@ NS_IMETHODIMP
 nsAccessNode::GetComputedStyleValue(const nsAString& aPseudoElt,
                                     const nsAString& aPropertyName,
                                     nsAString& aValue)
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
-  GetComputedStyleDeclaration(aPseudoElt, mDOMNode, getter_AddRefs(styleDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
+                                           getter_AddRefs(styleDecl));
   NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
 
   return styleDecl->GetPropertyValue(aPropertyName, aValue);
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetComputedStyleCSSValue(const nsAString& aPseudoElt,
                                        const nsAString& aPropertyName,
@@ -629,53 +628,27 @@ nsAccessNode::GetComputedStyleCSSValue(c
 {
   NS_ENSURE_ARG_POINTER(aCSSValue);
   *aCSSValue = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
-  GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
-                              getter_AddRefs(styleDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
+                                           getter_AddRefs(styleDecl));
   NS_ENSURE_STATE(styleDecl);
 
   nsCOMPtr<nsIDOMCSSValue> cssValue;
   styleDecl->GetPropertyCSSValue(aPropertyName, getter_AddRefs(cssValue));
   NS_ENSURE_TRUE(cssValue, NS_ERROR_FAILURE);
 
   return CallQueryInterface(cssValue, aCSSValue);
 }
 
-void
-nsAccessNode::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
-                                          nsIDOMNode *aNode,
-                                          nsIDOMCSSStyleDeclaration **aCssDecl)
-{
-  *aCssDecl = nsnull;
-
-  nsCOMPtr<nsIDOMElement> domElement = nsCoreUtils::GetDOMElementFor(aNode);
-  if (!domElement)
-    return;
-
-  // Returns number of items in style declaration
-  nsCOMPtr<nsIContent> content = do_QueryInterface(domElement);
-  nsCOMPtr<nsIDocument> doc = content->GetDocument();
-  if (!doc)
-    return;
-
-  nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(doc->GetWindow()));
-  if (!viewCSS)
-    return;
-
-  nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
-  viewCSS->GetComputedStyle(domElement, aPseudoElt, getter_AddRefs(cssDecl));
-  NS_IF_ADDREF(*aCssDecl = cssDecl);
-}
-
 /***************** Hashtable of nsIAccessNode's *****************/
 
 already_AddRefed<nsIAccessibleDocument>
 nsAccessNode::GetDocAccessibleFor(nsIDocument *aDocument)
 {
   if (!aDocument) {
     return nsnull;
   }
@@ -708,84 +681,46 @@ nsAccessNode::GetDocAccessibleFor(nsIDoc
   if (!aCanCreate) {
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
     NS_ASSERTION(docShell, "This method currently only supports docshells");
     nsCOMPtr<nsIPresShell> presShell;
     docShell->GetPresShell(getter_AddRefs(presShell));
     return presShell ? GetDocAccessibleFor(presShell->GetDocument()) : nsnull;
   }
 
-  nsCOMPtr<nsIDOMNode> node = GetDOMNodeForContainer(aContainer);
+  nsCOMPtr<nsIDOMNode> node = nsCoreUtils::GetDOMNodeForContainer(aContainer);
   if (!node) {
     return nsnull;
   }
 
   nsCOMPtr<nsIAccessible> accessible;
   GetAccService()->GetAccessibleFor(node, getter_AddRefs(accessible));
   nsIAccessibleDocument *docAccessible = nsnull;
   if (accessible) {
     CallQueryInterface(accessible, &docAccessible);
   }
   return docAccessible;
 }
  
 already_AddRefed<nsIAccessibleDocument>
 nsAccessNode::GetDocAccessibleFor(nsIDOMNode *aNode)
 {
-  nsCOMPtr<nsIPresShell> eventShell = GetPresShellFor(aNode);
+  nsCOMPtr<nsIPresShell> eventShell = nsCoreUtils::GetPresShellFor(aNode);
   if (eventShell) {
     return GetDocAccessibleFor(eventShell->GetDocument());
   }
 
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(aNode));
   if (doc) {
     return GetDocAccessibleFor(doc);
   }
 
   return nsnull;
 }
 
-already_AddRefed<nsIPresShell>
-nsAccessNode::GetPresShellFor(nsIDOMNode *aNode)
-{
-  nsCOMPtr<nsIDOMDocument> domDocument;
-  aNode->GetOwnerDocument(getter_AddRefs(domDocument));
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));
-  if (!doc) {   // This is necessary when the node is the document node
-    doc = do_QueryInterface(aNode);
-  }
-  nsIPresShell *presShell = nsnull;
-  if (doc) {
-    presShell = doc->GetPrimaryShell();
-    NS_IF_ADDREF(presShell);
-  }
-  return presShell;
-}
-
-already_AddRefed<nsIDOMNode>
-nsAccessNode::GetDOMNodeForContainer(nsISupports *aContainer)
-{
-  nsIDOMNode* node = nsnull;
-  nsCOMPtr<nsIDocShell> shell = do_QueryInterface(aContainer);
-  nsCOMPtr<nsIContentViewer> cv;
-  shell->GetContentViewer(getter_AddRefs(cv));
-  if (cv) {
-    nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
-    if (docv) {
-      nsCOMPtr<nsIDocument> doc;
-      docv->GetDocument(getter_AddRefs(doc));
-      if (doc) {
-        CallQueryInterface(doc.get(), &node);
-      }
-    }
-  }
-
-  return node;
-}
-
 void
 nsAccessNode::PutCacheEntry(nsAccessNodeHashtable& aCache,
                             void* aUniqueID,
                             nsIAccessNode *aAccessNode)
 {
 #ifdef DEBUG_A11Y
   nsCOMPtr<nsIAccessNode> oldAccessNode;
   GetCacheEntry(aCache, aUniqueID, getter_AddRefs(oldAccessNode));
@@ -816,17 +751,17 @@ PLDHashOperator nsAccessNode::ClearCache
 void
 nsAccessNode::ClearCache(nsAccessNodeHashtable& aCache)
 {
   aCache.Enumerate(ClearCacheEntry, nsnull);
 }
 
 already_AddRefed<nsIDOMNode> nsAccessNode::GetCurrentFocus()
 {
-  nsCOMPtr<nsIPresShell> shell = GetPresShellFor(mDOMNode);
+  nsCOMPtr<nsIPresShell> shell = nsCoreUtils::GetPresShellFor(mDOMNode);
   NS_ENSURE_TRUE(shell, nsnull);
   nsCOMPtr<nsIDocument> doc = shell->GetDocument();
   NS_ENSURE_TRUE(doc, nsnull);
 
   nsCOMPtr<nsPIDOMWindow> privateDOMWindow(do_QueryInterface(doc->GetWindow()));
   if (!privateDOMWindow) {
     return nsnull;
   }
--- a/accessible/src/base/nsAccessNode.h
+++ b/accessible/src/base/nsAccessNode.h
@@ -106,23 +106,16 @@ class nsAccessNode: public nsIAccessNode
     static PLDHashOperator ClearCacheEntry(const void* aKey, nsCOMPtr<nsIAccessNode>& aAccessNode, void* aUserArg);
 
     // Static cache methods for global document cache
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDocument *aDocument);
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIWeakReference *aWeakShell);
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDocShellTreeItem *aContainer, PRBool aCanCreate = PR_FALSE);
     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDOMNode *aNode);
 
-    static already_AddRefed<nsIDOMNode> GetDOMNodeForContainer(nsISupports *aContainer);
-    static already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aStartNode);
-    
-    static void GetComputedStyleDeclaration(const nsAString& aPseudoElt,
-                                            nsIDOMNode *aNode,
-                                            nsIDOMCSSStyleDeclaration **aCssDecl);
-
     already_AddRefed<nsRootAccessible> GetRootAccessible();
 
     static nsIDOMNode *gLastFocusedNode;
     static nsIAccessibilityService* GetAccService();
     already_AddRefed<nsIDOMNode> GetCurrentFocus();
 
     /**
      * Returns true when the accessible is defunct.
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -1533,17 +1533,18 @@ NS_IMETHODIMP nsAccessibilityService::Ge
             NS_ASSERTION(tableRoleMapEntry &&
                          !nsCRT::strcmp(tableRoleMapEntry->roleString, "presentation"),
                          "No accessible for parent table and it didn't have role of presentation");
 #endif
             // Table-related descendants of presentation table are also presentation
             // Don't create accessibles for them unless they need to fire focus events
             return NS_OK;
           }
-          if (tableAccessible && nsAccessible::Role(tableAccessible) != nsIAccessibleRole::ROLE_TABLE) {
+          if (tableAccessible &&
+              nsAccUtils::Role(tableAccessible) != nsIAccessibleRole::ROLE_TABLE) {
             NS_ASSERTION(!roleMapEntry, "Should not be changing ARIA role, just overriding impl class role");
             // Not in table: override role (roleMap entry was null).
             roleMapEntry = &nsARIAMap::gEmptyRoleMap;
           }
           break;
         }
         else if (tableContent->Tag() == nsAccessibilityAtoms::table) {
           // Stop before we are fooled by any additional table ancestors
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -155,53 +155,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstChild)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mNextSibling)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_ADDREF_INHERITED(nsAccessible, nsAccessNode)
 NS_IMPL_RELEASE_INHERITED(nsAccessible, nsAccessNode)
 
-#ifdef DEBUG_A11Y
-/*
- * static
- * help method. to detect whether this accessible object implements
- * nsIAccessibleText, when it is text or has text child node.
- */
-PRBool nsAccessible::IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible)
-{
-  PRBool foundText = PR_FALSE;
-
-  nsCOMPtr<nsIAccessibleDocument> accDoc = do_QueryInterface(aAccessible);
-  if (accDoc) {
-    // Don't test for accessible docs, it makes us create accessibles too
-    // early and fire mutation events before we need to
-    return PR_TRUE;
-  }
-  nsCOMPtr<nsIAccessible> child, nextSibling;
-  aAccessible->GetFirstChild(getter_AddRefs(child));
-  while (child) {
-    if (IsText(child)) {
-      foundText = PR_TRUE;
-      break;
-    }
-    child->GetNextSibling(getter_AddRefs(nextSibling));
-    child.swap(nextSibling);
-  }
-  if (foundText) {
-    // found text child node
-    nsCOMPtr<nsIAccessibleText> text = do_QueryInterface(aAccessible);
-    if (!text) {
-      return PR_FALSE;
-    }
-  }
-  return PR_TRUE; 
-}
-#endif
-
 nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
   // Custom-built QueryInterface() knows when we support nsIAccessibleSelectable
   // based on role attribute and aria-multiselectable
   *aInstancePtr = nsnull;
 
   if (aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
     *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(nsAccessible);
@@ -436,17 +399,17 @@ nsAccessible::GetKeyboardShortcut(nsAStr
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   if (!content)
     return NS_ERROR_FAILURE;
 
   PRUint32 key = nsCoreUtils::GetAccessKeyFor(content);
   if (!key && content->IsNodeOfType(nsIContent::eELEMENT)) {
     // Copy access key from label node unless it is labeled
     // via an ancestor <label>, in which case that would be redundant
-    nsCOMPtr<nsIContent> labelContent(GetLabelContent(content));
+    nsCOMPtr<nsIContent> labelContent(nsCoreUtils::GetLabelContent(content));
     nsCOMPtr<nsIDOMNode> labelNode = do_QueryInterface(labelContent);
     if (labelNode && !nsCoreUtils::IsAncestorOf(labelNode, mDOMNode))
       key = nsCoreUtils::GetAccessKeyFor(labelContent);
   }
 
   if (!key)
     return NS_OK;
 
@@ -501,43 +464,16 @@ NS_IMETHODIMP nsAccessible::SetFirstChil
 }
 
 NS_IMETHODIMP nsAccessible::SetNextSibling(nsIAccessible *aNextSibling)
 {
   mNextSibling = aNextSibling;
   return NS_OK;
 }
 
-nsIContent *nsAccessible::GetRoleContent(nsIDOMNode *aDOMNode)
-{
-  // Given the DOM node for an acessible, return content node that
-  // we should look for ARIA properties on.
-  // For non-document accessibles, this is the associated content node.
-  // For doc accessibles, use the <body>/<frameset> if it's HTML.
-  // For any other doc accessible , this is the document element.
-  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
-  if (!content) {
-    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aDOMNode));
-    if (domDoc) {
-      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aDOMNode));
-      if (htmlDoc) {
-        nsCOMPtr<nsIDOMHTMLElement> bodyElement;
-        htmlDoc->GetBody(getter_AddRefs(bodyElement));
-        content = do_QueryInterface(bodyElement);
-      }
-      else {
-        nsCOMPtr<nsIDOMElement> docElement;
-        domDoc->GetDocumentElement(getter_AddRefs(docElement));
-        content = do_QueryInterface(docElement);
-      }
-    }
-  }
-  return content;
-}
-
 NS_IMETHODIMP nsAccessible::Shutdown()
 {
   mNextSibling = nsnull;
 
   // Invalidate the child count and pointers to other accessibles, also make
   // sure none of its children point to this parent
   InvalidateChildren();
   if (mParent) {
@@ -1120,17 +1056,17 @@ nsAccessible::GetDeepestChildAtPoint(PRI
   // we return |this| if the point is within it, otherwise nsnull
   nsCOMPtr<nsIAccessible> fallbackAnswer;
   PRInt32 x, y, width, height;
   GetBounds(&x, &y, &width, &height);
   if (aX >= x && aX < x + width &&
       aY >= y && aY < y + height) {
     fallbackAnswer = this;
   }
-  if (MustPrune(this)) {  // Do not dig any further
+  if (nsAccUtils::MustPrune(this)) {  // Do not dig any further
     NS_IF_ADDREF(*aAccessible = fallbackAnswer);
     return NS_OK;
   }
 
   // Search an accessible at the given point starting from accessible document
   // because containing block (see CSS2) for out of flow element (for example,
   // absolutely positioned element) may be different from its DOM parent and
   // therefore accessible for containing block may be different from accessible
@@ -1191,17 +1127,17 @@ nsAccessible::GetDeepestChildAtPoint(PRI
     // This takes care of cases where layout won't walk into
     // things for us, such as image map areas and sub documents
     nsCOMPtr<nsIAccessible> child;
     while (NextChild(child)) {
       PRInt32 childX, childY, childWidth, childHeight;
       child->GetBounds(&childX, &childY, &childWidth, &childHeight);
       if (aX >= childX && aX < childX + childWidth &&
           aY >= childY && aY < childY + childHeight &&
-          (State(child) & nsIAccessibleStates::STATE_INVISIBLE) == 0) {
+          (nsAccUtils::State(child) & nsIAccessibleStates::STATE_INVISIBLE) == 0) {
         // Don't walk into offscreen or invisible items
         NS_IF_ADDREF(*aAccessible = child);
         return NS_OK;
       }
     }
     // Fall through -- the point is in this accessible but not in a child
     // We are allowed to return |this| as the answer
   }
@@ -1274,18 +1210,20 @@ void nsAccessible::GetBoundsRect(nsRect&
   // This is an ancestor frame that will incompass all frames for this content node.
   // We need the relative parent so we can get absolute screen coordinates
   nsIFrame *ancestorFrame = firstFrame;
 
   while (ancestorFrame) {  
     *aBoundingFrame = ancestorFrame;
     // If any other frame type, we only need to deal with the primary frame
     // Otherwise, there may be more frames attached to the same content node
-    if (!IsCorrectFrameType(ancestorFrame, nsAccessibilityAtoms::inlineFrame) &&
-        !IsCorrectFrameType(ancestorFrame, nsAccessibilityAtoms::textFrame))
+    if (!nsCoreUtils::IsCorrectFrameType(ancestorFrame,
+                                         nsAccessibilityAtoms::inlineFrame) &&
+        !nsCoreUtils::IsCorrectFrameType(ancestorFrame,
+                                         nsAccessibilityAtoms::textFrame))
       break;
     ancestorFrame = ancestorFrame->GetParent();
   }
 
   nsIFrame *iterFrame = firstFrame;
   nsCOMPtr<nsIContent> firstContent(do_QueryInterface(mDOMNode));
   nsIContent* iterContent = firstContent;
   PRInt32 depth = 0;
@@ -1299,17 +1237,18 @@ void nsAccessible::GetBoundsRect(nsRect&
     currFrameBounds +=
       iterFrame->GetParent()->GetOffsetToExternal(*aBoundingFrame);
 
     // Add this frame's bounds to total
     aTotalBounds.UnionRect(aTotalBounds, currFrameBounds);
 
     nsIFrame *iterNextFrame = nsnull;
 
-    if (IsCorrectFrameType(iterFrame, nsAccessibilityAtoms::inlineFrame)) {
+    if (nsCoreUtils::IsCorrectFrameType(iterFrame,
+                                        nsAccessibilityAtoms::inlineFrame)) {
       // Only do deeper bounds search if we're on an inline frame
       // Inline frames can contain larger frames inside of them
       iterNextFrame = iterFrame->GetFirstChild(nsnull);
     }
 
     if (iterNextFrame) 
       ++depth;  // Child was found in code above this: We are going deeper in this iteration of the loop
     else {  
@@ -1371,79 +1310,33 @@ NS_IMETHODIMP nsAccessible::GetBounds(PR
   *x += orgRectPixels.x;
   *y += orgRectPixels.y;
 
   return NS_OK;
 }
 
 // helpers
 
-/**
-  * Static
-  * Helper method to help sub classes make sure they have the proper
-  *     frame when walking the frame tree to get at children and such
-  */
-PRBool nsAccessible::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!");
-
-  return aFrame->GetType() == aAtom;
-}
-
-
 nsIFrame* nsAccessible::GetBoundsFrame()
 {
   return GetFrame();
 }
 
-already_AddRefed<nsIAccessible>
-nsAccessible::GetMultiSelectFor(nsIDOMNode *aNode)
-{
-  NS_ENSURE_TRUE(aNode, nsnull);
-  nsCOMPtr<nsIAccessibilityService> accService =
-    do_GetService("@mozilla.org/accessibilityService;1");
-  NS_ENSURE_TRUE(accService, nsnull);
-  nsCOMPtr<nsIAccessible> accessible;
-  accService->GetAccessibleFor(aNode, getter_AddRefs(accessible));
-  if (!accessible) {
-    return nsnull;
-  }
-
-  PRUint32 state = State(accessible);
-  if (0 == (state & nsIAccessibleStates::STATE_SELECTABLE)) {
-    return nsnull;
-  }
-
-  PRUint32 containerRole;
-  while (0 == (state & nsIAccessibleStates::STATE_MULTISELECTABLE)) {
-    nsIAccessible *current = accessible;
-    current->GetParent(getter_AddRefs(accessible));
-    if (!accessible || (NS_SUCCEEDED(accessible->GetFinalRole(&containerRole)) &&
-                        containerRole == nsIAccessibleRole::ROLE_PANE)) {
-      return nsnull;
-    }
-    state = State(accessible);
-  }
-  nsIAccessible *returnAccessible = nsnull;
-  accessible.swap(returnAccessible);
-  return returnAccessible;
-}
-
 /* void removeSelection (); */
 NS_IMETHODIMP nsAccessible::SetSelected(PRBool aSelect)
 {
   // Add or remove selection
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
-  PRUint32 state = State(this);
+  PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
-    nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(mDOMNode);
+    nsCOMPtr<nsIAccessible> multiSelect =
+      nsAccUtils::GetMultiSelectFor(mDOMNode);
     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) {
@@ -1460,19 +1353,20 @@ NS_IMETHODIMP nsAccessible::SetSelected(
 /* void takeSelection (); */
 NS_IMETHODIMP nsAccessible::TakeSelection()
 {
   // Select only this item
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
-  PRUint32 state = State(this);
+  PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
-    nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(mDOMNode);
+    nsCOMPtr<nsIAccessible> multiSelect =
+      nsAccUtils::GetMultiSelectFor(mDOMNode);
     if (multiSelect) {
       nsCOMPtr<nsIAccessibleSelectable> selectable = do_QueryInterface(multiSelect);
       selectable->ClearSelection();
     }
     return SetSelected(PR_TRUE);
   }
 
   return NS_ERROR_FAILURE;
@@ -1761,62 +1655,22 @@ nsAccessible::AppendFlatStringFromSubtre
 
     AppendFlatStringFromSubtreeRecurse(childContent, aFlatString,
                                        aIsRootHidden);
   }
 
   return NS_OK;
 }
 
-nsIContent *nsAccessible::GetLabelContent(nsIContent *aForNode)
-{
-  if (aForNode->IsNodeOfType(nsINode::eXUL))
-    return nsCoreUtils::FindNeighbourPointingToNode(aForNode, nsAccessibilityAtoms::control,
-                                                    nsAccessibilityAtoms::label);
-
-  return GetHTMLLabelContent(aForNode);
-}
-
-nsIContent* nsAccessible::GetHTMLLabelContent(nsIContent *aForNode)
-{
-  // Get either <label for="[id]"> element which explictly points to aForNode, or 
-  // <label> ancestor which implicitly point to it
-  nsIContent *walkUpContent = aForNode;
-
-  // go up tree get name of ancestor label if there is one. Don't go up farther than form element
-  while ((walkUpContent = walkUpContent->GetParent()) != nsnull) {
-    nsIAtom *tag = walkUpContent->Tag();
-    if (tag == nsAccessibilityAtoms::label) {
-      return walkUpContent;  // An ancestor <label> implicitly points to us
-    }
-    if (tag == nsAccessibilityAtoms::form ||
-        tag == nsAccessibilityAtoms::body) {
-      // Reached top ancestor in form
-      // There can be a label targeted at this control using the 
-      // for="control_id" attribute. To save computing time, only 
-      // look for those inside of a form element
-      nsAutoString forId;
-      if (!nsCoreUtils::GetID(aForNode, forId)) {
-        break;
-      }
-      // Actually we'll be walking down the content this time, with a depth first search
-      return nsCoreUtils::FindDescendantPointingToID(&forId, walkUpContent,
-                                                     nsAccessibilityAtoms::_for);
-    }
-  }
-
-  return nsnull;
-}
-
 nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aName)
 {
   // Get DHTML name from content subtree pointed to by ID attribute
   aName.Truncate();
   NS_ASSERTION(mDOMNode, "Called from shutdown accessible");
-  nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
+  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content)
     return NS_OK;
 
   nsAutoString ids;
   if (!content->GetAttr(kNameSpaceID_None, aIDProperty, ids))
     return NS_OK;
 
   ids.CompressWhitespace(PR_TRUE, PR_TRUE);
@@ -1858,23 +1712,23 @@ nsresult nsAccessible::GetTextFromRelati
 
 /**
   * Only called if the element is not a nsIDOMXULControlElement. Initially walks up
   *   the DOM tree to the form, concatonating label elements as it goes. Then checks for
   *   labels with the for="controlID" property.
   */
 nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree)
 {
-  nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
+  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content) {
     aLabel.SetIsVoid(PR_TRUE);
     return NS_OK;
   }
 
-  nsIContent *labelContent = GetHTMLLabelContent(content);
+  nsIContent *labelContent = nsCoreUtils::GetHTMLLabelContent(content);
   if (labelContent) {
     nsAutoString label;
     nsresult rv = AppendFlatStringFromSubtree(labelContent, &label);
     NS_ENSURE_SUCCESS(rv, rv);
 
     label.CompressWhitespace();
     if (!label.IsEmpty()) {
       aLabel = label;
@@ -1939,17 +1793,17 @@ nsresult nsAccessible::GetXULName(nsAStr
         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 = GetRoleContent(mDOMNode);
+  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,
                                                nsAccessibilityAtoms::label);
@@ -1994,28 +1848,16 @@ nsresult nsAccessible::GetXULName(nsAStr
   PRBool canAggregateName = mRoleMapEntry ?
                             mRoleMapEntry->nameRule == eNameOkFromChildren :
                             aCanAggregateSubtree;
 
   return canAggregateName ?
          AppendFlatStringFromSubtree(content, &aLabel) : NS_OK;
 }
 
-PRBool nsAccessible::IsNodeRelevant(nsIDOMNode *aNode)
-{
-  // Can this node be accessible and attached to
-  // the document's accessible tree?
-  nsCOMPtr<nsIAccessibilityService> accService =
-    do_GetService("@mozilla.org/accessibilityService;1");
-  NS_ENSURE_TRUE(accService, PR_FALSE);
-  nsCOMPtr<nsIDOMNode> relevantNode;
-  accService->GetRelevantContentNodeFor(aNode, getter_AddRefs(relevantNode));
-  return aNode == relevantNode;
-}
-
 NS_IMETHODIMP
 nsAccessible::FireToolkitEvent(PRUint32 aEvent, nsIAccessible *aTarget)
 {
   // Don't fire event for accessible that has been shut down.
   if (!mWeakShell)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIAccessibleEvent> accEvent =
@@ -2026,17 +1868,17 @@ nsAccessible::FireToolkitEvent(PRUint32 
 }
 
 NS_IMETHODIMP
 nsAccessible::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   NS_ENSURE_ARG_POINTER(aEvent);
   nsCOMPtr<nsIDOMNode> eventNode;
   aEvent->GetDOMNode(getter_AddRefs(eventNode));
-  NS_ENSURE_TRUE(IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIObserverService> obsService =
     do_GetService("@mozilla.org/observer-service;1");
   NS_ENSURE_TRUE(obsService, NS_ERROR_FAILURE);
 
   return obsService->NotifyObservers(aEvent, NS_ACCESSIBLE_EVENT_TOPIC, nsnull);
 }
 
@@ -2064,32 +1906,30 @@ NS_IMETHODIMP nsAccessible::GetFinalRole
           *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 (possibleCombo && Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
+      if (nsAccUtils::Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
         *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
       }
       else {   // Check to see if combo owns the listbox instead
         GetAccessibleRelated(nsIAccessibleRelation::RELATION_NODE_CHILD_OF, getter_AddRefs(possibleCombo));
-        if (possibleCombo && Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
+        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 (parent && Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
+      if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
         *aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
-      }
     }
 
     // gLandmarkRoleMap: can use role of accessible class impl
     // gEmptyRoleMap and all others: cannot use role of accessible class impl
     if (mRoleMapEntry != &nsARIAMap::gLandmarkRoleMap) {
       // We can now expose ROLE_NOTHING when there is a role map entry, which
       // will cause ATK to use ROLE_UNKNOWN and MSAA to use a BSTR role with
       // the ARIA role or element's tag. In either case the AT can also use
@@ -2103,17 +1943,17 @@ NS_IMETHODIMP nsAccessible::GetFinalRole
 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 = GetRoleContent(mDOMNode);
+  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);
@@ -2143,17 +1983,17 @@ nsAccessible::GetAttributes(nsIPersisten
     // 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
     nsAutoString valuetext;
     GetValue(valuetext);
     attributes->SetStringProperty(NS_LITERAL_CSTRING("valuetext"), valuetext, oldValueUnused);
   }
 
 
-  PRUint32 role = Role(this);
+  PRUint32 role = nsAccUtils::Role(this);
   if (role == nsIAccessibleRole::ROLE_CHECKBUTTON ||
       role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
       role == nsIAccessibleRole::ROLE_MENUITEM ||
       role == nsIAccessibleRole::ROLE_LISTITEM ||
       role == nsIAccessibleRole::ROLE_OPTION ||
       role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
       role == nsIAccessibleRole::ROLE_RICH_OPTION ||
       role == nsIAccessibleRole::ROLE_OUTLINEITEM ||
@@ -2180,17 +2020,17 @@ nsAccessible::GetAttributes(nsIPersisten
          role == nsIAccessibleRole::ROLE_MENUITEM ||
          role == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
          role == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM ||
          role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
          role == nsIAccessibleRole::ROLE_PAGETAB ||
          role == nsIAccessibleRole::ROLE_OPTION ||
          role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
          role == nsIAccessibleRole::ROLE_OUTLINEITEM) &&
-        0 == (State(this) & nsIAccessibleStates::STATE_INVISIBLE)) {
+        0 == (nsAccUtils::State(this) & nsIAccessibleStates::STATE_INVISIBLE)) {
 
       PRUint32 baseRole = role;
       if (role == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
           role == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
         baseRole = nsIAccessibleRole::ROLE_MENUITEM;
 
       nsCOMPtr<nsIAccessible> parent = GetParent();
       NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
@@ -2209,17 +2049,17 @@ nsAccessible::GetAttributes(nsIPersisten
 
         siblingBaseRole = siblingRole;
         if (siblingRole == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
             siblingRole == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
           siblingBaseRole = nsIAccessibleRole::ROLE_MENUITEM;
 
         // If sibling is visible and has the same base role.
         if (siblingBaseRole == baseRole &&
-            !(State(sibling) & nsIAccessibleStates::STATE_INVISIBLE)) {
+            !(nsAccUtils::State(sibling) & nsIAccessibleStates::STATE_INVISIBLE)) {
           ++ setSize;
           if (!foundCurrent) {
             ++ positionInGroup;
             if (sibling == this)
               foundCurrent = PR_TRUE;
           }
         }
 
@@ -2281,17 +2121,17 @@ 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 = GetRoleContent(mDOMNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
   nsCOMPtr<nsIDOMElement> element(do_QueryInterface(content));
   NS_ENSURE_TRUE(element, NS_ERROR_UNEXPECTED);
 
   nsAutoString tagName;
   element->GetTagName(tagName);
   if (!tagName.IsEmpty()) {
     nsAutoString oldValueUnused;
     aAttributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName,
@@ -2314,17 +2154,17 @@ nsAccessible::GetAttributesInternal(nsIP
   //   Outer doc author may want to override properties on a widget they used in an iframe
   nsCOMPtr<nsIDOMNode> startNode = mDOMNode;
   nsIContent *startContent = content;
   while (PR_TRUE) {
     NS_ENSURE_STATE(startContent);
     nsIDocument *doc = startContent->GetDocument();
     nsCOMPtr<nsIDOMNode> docNode = do_QueryInterface(doc);
     NS_ENSURE_STATE(docNode);
-    nsIContent *topContent = GetRoleContent(docNode);
+    nsIContent *topContent = nsCoreUtils::GetRoleContent(docNode);
     NS_ENSURE_STATE(topContent);
     nsAccUtils::SetLiveContainerAttributes(aAttributes, startContent,
                                            topContent);
     // Allow ARIA live region markup from outer documents to override
     nsCOMPtr<nsISupports> container = doc->GetContainer();
     nsIDocShellTreeItem *docShellTreeItem = nsnull;
     if (container)
       CallQueryInterface(container, &docShellTreeItem);
@@ -2435,17 +2275,17 @@ nsAccessible::GetFinalState(PRUint32 *aS
     } else {
       // Expose 'selected' state on ARIA tab if the focus is on internal element
       // of related tabpanel.
       nsCOMPtr<nsIAccessible> tabPanel;
       rv = GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABEL_FOR,
                                 getter_AddRefs(tabPanel));
       NS_ENSURE_SUCCESS(rv, rv);
 
-      if (tabPanel && Role(tabPanel) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
+      if (nsAccUtils::Role(tabPanel) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
         nsCOMPtr<nsIAccessNode> tabPanelAccessNode(do_QueryInterface(tabPanel));
         nsCOMPtr<nsIDOMNode> tabPanelNode;
         tabPanelAccessNode->GetDOMNode(getter_AddRefs(tabPanelNode));
         NS_ENSURE_STATE(tabPanelNode);
 
         if (nsCoreUtils::IsAncestorOf(tabPanelNode, gLastFocusedNode))
           *aState |= nsIAccessibleStates::STATE_SELECTED;
       }
@@ -2514,17 +2354,18 @@ nsAccessible::GetFinalState(PRUint32 *aS
          autocomplete.EqualsIgnoreCase("both"))) {
       *aExtraState |= nsIAccessibleStates::EXT_STATE_SUPPORTS_AUTOCOMPLETION;
     }
 
     // XXX We can remove this hack once we support RDF-based role & state maps
     if (mRoleMapEntry && mRoleMapEntry->role == nsIAccessibleRole::ROLE_ENTRY) {
       PRBool isMultiLine = content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_multiline,
                                                 nsAccessibilityAtoms::_true, eCaseMatters);
-      *aExtraState |= isMultiLine ? nsIAccessibleStates::EXT_STATE_MULTI_LINE : nsIAccessibleStates::EXT_STATE_SINGLE_LINE;
+      *aExtraState |= isMultiLine ? nsIAccessibleStates::EXT_STATE_MULTI_LINE :
+                                    nsIAccessibleStates::EXT_STATE_SINGLE_LINE;
       if (0 == (*aState & nsIAccessibleStates::STATE_READONLY))
         *aExtraState |= nsIAccessibleStates::EXT_STATE_EDITABLE; // Not readonly
       else  // We're readonly: make sure editable state wasn't set by impl class
         *aExtraState &= ~nsIAccessibleStates::EXT_STATE_EDITABLE;
     }
   }
 
   // For some reasons DOM node may have not a frame. We tract such accessibles
@@ -2552,17 +2393,17 @@ nsAccessible::GetFinalState(PRUint32 *aS
 
   return NS_OK;
 }
 
 nsresult
 nsAccessible::GetARIAState(PRUint32 *aState)
 {
   // Test for universal states first
-  nsIContent *content = GetRoleContent(mDOMNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content) {
     return NS_OK;
   }
 
   PRUint32 index = 0;
   while (MappedAttrState(content, aState, &nsARIAMap::gWAIUnivStateMap[index])) {
     ++ index;
   }
@@ -2688,17 +2529,17 @@ nsAccessible::SetCurrentValue(double aVa
     return NS_ERROR_FAILURE;  // Node already shut down
 
   if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
     return NS_OK_NO_ARIA_VALUE;
 
   const PRUint32 kValueCannotChange = nsIAccessibleStates::STATE_READONLY |
                                       nsIAccessibleStates::STATE_UNAVAILABLE;
 
-  if (State(this) & kValueCannotChange)
+  if (nsAccUtils::State(this) & kValueCannotChange)
     return NS_ERROR_FAILURE;
 
   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)
@@ -2768,17 +2609,17 @@ NS_IMETHODIMP
 nsAccessible::GetNumActions(PRUint8 *aNumActions)
 {
   NS_ENSURE_ARG_POINTER(aNumActions);
   *aNumActions = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  PRUint32 actionRule = GetActionRule(State(this));
+  PRUint32 actionRule = GetActionRule(nsAccUtils::State(this));
   if (actionRule == eNoAction)
     return NS_OK;
 
   *aNumActions = 1;
   return NS_OK;
 }
 
 /* DOMString getAccActionName (in PRUint8 index); */
@@ -2788,17 +2629,17 @@ nsAccessible::GetActionName(PRUint8 aInd
   aName.Truncate();
 
   if (aIndex != 0)
     return NS_ERROR_INVALID_ARG;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  PRUint32 states = State(this);
+  PRUint32 states = nsAccUtils::State(this);
   PRUint32 actionRule = GetActionRule(states);
 
  switch (actionRule) {
    case eActivateAction:
      aName.AssignLiteral("activate");
      return NS_OK;
 
    case eClickAction:
@@ -2852,17 +2693,17 @@ NS_IMETHODIMP
 nsAccessible::DoAction(PRUint8 aIndex)
 {
   if (aIndex != 0)
     return NS_ERROR_INVALID_ARG;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  if (GetActionRule(State(this)) != eNoAction) {
+  if (GetActionRule(nsAccUtils::State(this)) != eNoAction) {
     nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
     return DoCommand(content);
   }
 
   return NS_ERROR_INVALID_ARG;
 }
 
 /* DOMString getHelp (); */
@@ -2892,17 +2733,17 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
 /* nsIAccessible getAccessibleBelow(); */
 NS_IMETHODIMP nsAccessible::GetAccessibleBelow(nsIAccessible **_retval)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsIDOMNode* nsAccessible::GetAtomicRegion()
 {
-  nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
+  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
   nsIContent *loopContent = content;
   nsAutoString atomic;
   while (loopContent && !loopContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_atomic, atomic)) {
     loopContent = loopContent->GetParent();
   }
 
   nsCOMPtr<nsIDOMNode> atomicRegion;
   if (atomic.EqualsLiteral("true")) {
@@ -2915,17 +2756,17 @@ nsIDOMNode* nsAccessible::GetAtomicRegio
 NS_IMETHODIMP nsAccessible::GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated)
 {
   // When adding support for relations, make sure to add them to
   // appropriate places in nsAccessibleWrap implementations
   *aRelated = nsnull;
 
   // Relationships are defined on the same content node
   // that the role would be defined on
-  nsIContent *content = GetRoleContent(mDOMNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content) {
     return NS_ERROR_FAILURE;  // Node already shut down
   }
 
   nsCOMPtr<nsIDOMNode> relatedNode;
   nsAutoString relatedID;
 
   // Search for the related DOM node according to the specified "relation type"
@@ -2942,17 +2783,17 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
         relatedNode =
           do_QueryInterface(nsCoreUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_labelledby));
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_LABELLED_BY:
     {
       if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby, relatedID)) {
-        relatedNode = do_QueryInterface(GetLabelContent(content));
+        relatedNode = do_QueryInterface(nsCoreUtils::GetLabelContent(content));
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_DESCRIBED_BY:
     {
       if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_describedby, relatedID)) {
         relatedNode = do_QueryInterface(
           nsCoreUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::control, nsAccessibilityAtoms::description));
@@ -3259,17 +3100,17 @@ nsAccessible::GetNextWithState(nsIAccess
       if (!look) {
         current->GetParent(getter_AddRefs(look));
         current = look;
         look = nsnull;
         continue;
       }
     }
     current.swap(look);
-    state = State(current);
+    state = nsAccUtils::State(current);
   }
 
   nsIAccessible *returnAccessible = nsnull;
   current.swap(returnAccessible);
 
   return returnAccessible;
 }
 
@@ -3333,17 +3174,17 @@ NS_IMETHODIMP nsAccessible::AddChildToSe
   // implement a selection methods for their specific interfaces, because being
   // able to deal with selection on a per-child basis would not be enough.
 
   NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIAccessible> child;
   GetChildAt(aIndex, getter_AddRefs(child));
 
-  PRUint32 state = State(child);
+  PRUint32 state = nsAccUtils::State(child);
   if (!(state & nsIAccessibleStates::STATE_SELECTABLE)) {
     return NS_OK;
   }
 
   return child->SetSelected(PR_TRUE);
 }
 
 NS_IMETHODIMP nsAccessible::RemoveChildFromSelection(PRInt32 aIndex)
@@ -3352,17 +3193,17 @@ NS_IMETHODIMP nsAccessible::RemoveChildF
   // implement a selection methods for their specific interfaces, because being
   // able to deal with selection on a per-child basis would not be enough.
 
   NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIAccessible> child;
   GetChildAt(aIndex, getter_AddRefs(child));
 
-  PRUint32 state = State(child);
+  PRUint32 state = nsAccUtils::State(child);
   if (!(state & nsIAccessibleStates::STATE_SELECTED)) {
     return NS_OK;
   }
 
   return child->SetSelected(PR_FALSE);
 }
 
 NS_IMETHODIMP nsAccessible::IsChildSelected(PRInt32 aIndex, PRBool *aIsSelected)
@@ -3372,17 +3213,17 @@ NS_IMETHODIMP nsAccessible::IsChildSelec
   // able to deal with selection on a per-child basis would not be enough.
 
   *aIsSelected = PR_FALSE;
   NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIAccessible> child;
   GetChildAt(aIndex, getter_AddRefs(child));
 
-  PRUint32 state = State(child);
+  PRUint32 state = nsAccUtils::State(child);
   if (state & nsIAccessibleStates::STATE_SELECTED) {
     *aIsSelected = PR_TRUE;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAccessible::ClearSelection()
 {
@@ -3477,17 +3318,17 @@ nsAccessible::GetAnchor(PRInt32 aIndex,
   return NS_OK;
 }
 
 // readonly attribute boolean nsIAccessibleHyperLink::valid
 NS_IMETHODIMP
 nsAccessible::GetValid(PRBool *aValid)
 {
   NS_ENSURE_ARG_POINTER(aValid);
-  PRUint32 state = State(this);
+  PRUint32 state = nsAccUtils::State(this);
   *aValid = (0 == (state & nsIAccessibleStates::STATE_INVALID));
   // XXX In order to implement this we would need to follow every link
   // Perhaps we can get information about invalid links from the cache
   // In the mean time authors can use role="link" aria-invalid="true"
   // to force it for links they internally know to be invalid
   return NS_OK;
 }
 
@@ -3508,78 +3349,47 @@ nsresult nsAccessible::GetLinkOffset(PRI
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIAccessible> accessible, nextSibling;
   PRInt32 characterCount = 0;
   parent->GetFirstChild(getter_AddRefs(accessible));
 
   while (accessible) {
-    if (IsText(accessible)) {
-      characterCount += TextLength(accessible);
-    }
+    if (nsAccUtils::IsText(accessible))
+      characterCount += nsAccUtils::TextLength(accessible);
+
     else if (accessible == this) {
       *aStartOffset = characterCount;
       *aEndOffset = characterCount + 1;
       return NS_OK;
     }
     else {
       ++ characterCount;
     }
     accessible->GetNextSibling(getter_AddRefs(nextSibling));
     accessible.swap(nextSibling);
   }
 
   return NS_ERROR_FAILURE;
 }
 
-PRInt32 nsAccessible::TextLength(nsIAccessible *aAccessible)
-{
-  if (!IsText(aAccessible))
-    return 1;
-
-  nsCOMPtr<nsPIAccessNode> pAccNode(do_QueryInterface(aAccessible));
-  NS_ASSERTION(pAccNode, "QI to nsPIAccessNode failed");
-
-  nsIFrame *frame = pAccNode->GetFrame();
-  if (frame && frame->GetType() == nsAccessibilityAtoms::textFrame) {
-    // Ensure that correct text length is calculated (with non-rendered whitespace chars not counted)
-    nsIContent *content = frame->GetContent();
-    if (content) {
-      PRUint32 length;
-      nsresult rv = nsHyperTextAccessible::ContentToRenderedOffset(frame, content->TextLength(), &length);
-      return NS_SUCCEEDED(rv) ? static_cast<PRInt32>(length) : -1;
-    }
-  }
-
-  // For list bullets (or anything other accessible which would compute its own text
-  // They don't have their own frame.
-  // XXX In the future, list bullets may have frame and anon content, so 
-  // we should be able to remove this at that point
-  nsCOMPtr<nsPIAccessible> pAcc(do_QueryInterface(aAccessible));
-  NS_ASSERTION(pAcc, "QI to nsPIAccessible failed");
-
-  nsAutoString text;
-  pAcc->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
-  return text.Length();
-}
-
 NS_IMETHODIMP
 nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
 {
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible public methods
 
 nsresult
 nsAccessible::GetARIAName(nsAString& aName)
 {
-  nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
+  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)) {
     aName = label;
     return NS_OK;
@@ -3591,17 +3401,17 @@ nsAccessible::GetARIAName(nsAString& aNa
     aName = label;
 
   return rv;
 }
 
 nsresult
 nsAccessible::GetNameInternal(nsAString& aName)
 {
-  nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
+  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content)
     return NS_OK;
 
   if (content->IsNodeOfType(nsINode::eHTML))
     return GetHTMLName(aName, PR_FALSE);
 
   if (content->IsNodeOfType(nsINode::eXUL))
     return GetXULName(aName, PR_FALSE);
@@ -3617,17 +3427,17 @@ nsAccessible::GetFirstAvailableAccessibl
 {
   nsIAccessibilityService *accService = GetAccService();
   nsCOMPtr<nsIAccessible> accessible;
   nsCOMPtr<nsIDOMTreeWalker> walker; 
   nsCOMPtr<nsIDOMNode> currentNode(aStartNode);
 
   while (currentNode) {
     accService->GetAccessibleInWeakShell(currentNode, mWeakShell, getter_AddRefs(accessible)); // AddRef'd
-    if (accessible && (!aRequireLeaf || IsLeaf(accessible))) {
+    if (accessible && (!aRequireLeaf || nsAccUtils::IsLeaf(accessible))) {
       nsIAccessible *retAccessible = accessible;
       NS_ADDREF(retAccessible);
       return retAccessible;
     }
     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;
@@ -3727,25 +3537,8 @@ nsAccessible::GetActionRule(PRUint32 aSt
     return eClickAction;
 
   // Get an action based on ARIA role.
   if (mRoleMapEntry)
     return mRoleMapEntry->actionRule;
 
   return eNoAction;
 }
-
-PRBool nsAccessible::MustPrune(nsIAccessible *aAccessible)
-{ 
-  PRUint32 role = Role(aAccessible);
-  return role == nsIAccessibleRole::ROLE_MENUITEM || 
-         role == nsIAccessibleRole::ROLE_COMBOBOX_OPTION ||
-         role == nsIAccessibleRole::ROLE_OPTION ||
-         role == nsIAccessibleRole::ROLE_ENTRY ||
-         role == nsIAccessibleRole::ROLE_FLAT_EQUATION ||
-         role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
-         role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
-         role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
-         role == nsIAccessibleRole::ROLE_GRAPHIC ||
-         role == nsIAccessibleRole::ROLE_SLIDER ||
-         role == nsIAccessibleRole::ROLE_PROGRESSBAR ||
-         role == nsIAccessibleRole::ROLE_SEPARATOR;
-}
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -150,50 +150,22 @@ public:
   /**
    * Returns attributes for accessible without explicitly setted ARIA
    * attributes.
    */
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 
   //////////////////////////////////////////////////////////////////////////////
   // Helper methods
-  //
-  // XXX: should be moved into utility class
-
-#ifdef DEBUG_A11Y
-  static PRBool IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible);
-#endif
-
-  static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
-  static PRUint32 State(nsIAccessible *aAcc) { PRUint32 state = 0; if (aAcc) aAcc->GetFinalState(&state, nsnull); return state; }
-  static PRUint32 Role(nsIAccessible *aAcc) { PRUint32 role = nsIAccessibleRole::ROLE_NOTHING; if (aAcc) aAcc->GetFinalRole(&role); return role; }
-  static PRBool IsText(nsIAccessible *aAcc) { PRUint32 role = Role(aAcc); return role == nsIAccessibleRole::ROLE_TEXT_LEAF || role == nsIAccessibleRole::ROLE_STATICTEXT; }
-  static PRBool IsEmbeddedObject(nsIAccessible *aAcc) { PRUint32 role = Role(aAcc); return role != nsIAccessibleRole::ROLE_TEXT_LEAF && role != nsIAccessibleRole::ROLE_WHITESPACE && role != nsIAccessibleRole::ROLE_STATICTEXT; }
-  static PRInt32 TextLength(nsIAccessible *aAccessible); // Returns -1 on failure
-  static PRBool IsLeaf(nsIAccessible *aAcc) { PRInt32 numChildren; aAcc->GetChildCount(&numChildren); return numChildren > 0; }
-  static PRBool IsNodeRelevant(nsIDOMNode *aNode); // Is node something that could have an attached accessible
-  /**
-   * When exposing to platform accessibility APIs, should the children be pruned off?
-   */
-  static PRBool MustPrune(nsIAccessible *aAccessible);
   
   already_AddRefed<nsIAccessible> GetParent() {
     nsIAccessible *parent = nsnull;
     GetParent(&parent);
     return parent;
   }
-  
-  /**
-   *  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.
-   *  @param aDOMNode   The DOM node for the accessible that may be affected by ARIA
-   *  @return The nsIContent which may have ARIA markup
-   */
-  static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
 
 protected:
   PRBool MappedAttrState(nsIContent *aContent, PRUint32 *aStateInOut, nsStateMapEntry *aStateMapEntry);
   virtual nsIFrame* GetBoundsFrame();
   virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame);
   PRBool IsVisible(PRBool *aIsOffscreen); 
 
   // Relation helpers
@@ -203,19 +175,16 @@ protected:
    * for the subtree that's pointed to.
    *
    * @param aIDProperty  The ARIA relationship property to get the text for
    * @param aName        Where to put the text
    * @return error or success code
    */
   nsresult GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aName);
 
-  static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
-  static nsIContent *GetLabelContent(nsIContent *aForNode);
-
   // Name helpers
   nsresult GetHTMLName(nsAString& _retval, PRBool aCanAggregateSubtree = PR_TRUE);
   nsresult GetXULName(nsAString& aName, PRBool aCanAggregateSubtree = PR_TRUE);
   // For accessibles that are not lists of choices, the name of the subtree should be the 
   // sum of names in the subtree
   nsresult AppendFlatStringFromSubtree(nsIContent *aContent, nsAString *aFlatString);
   nsresult AppendNameFromAccessibleFor(nsIContent *aContent, nsAString *aFlatString,
                                        PRBool aFromValue = PR_FALSE);
@@ -255,19 +224,16 @@ 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, the DOM node to start from
    * @param aRequireLeaf, only accept leaf accessible nodes
    * @return the resulting accessible
    */   
   already_AddRefed<nsIAccessible> GetFirstAvailableAccessible(nsIDOMNode *aStartNode, PRBool aRequireLeaf = PR_FALSE);
 
-  // Selection helpers
-  static already_AddRefed<nsIAccessible> GetMultiSelectFor(nsIDOMNode *aNode);
-
   // Hyperlink helpers
   virtual nsresult GetLinkOffset(PRInt32* aStartOffset, PRInt32* aEndOffset);
 
   // For accessibles that have actions
   static void DoCommandCallback(nsITimer *aTimer, void *aClosure);
   nsresult DoCommand(nsIContent *aContent = nsnull);
 
   // Check the visibility across both parent content and chrome
--- a/accessible/src/base/nsBaseWidgetAccessible.cpp
+++ b/accessible/src/base/nsBaseWidgetAccessible.cpp
@@ -125,17 +125,17 @@ NS_IMETHODIMP
 nsLinkableAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
 {
   nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mIsLink) {
     *aState |= nsIAccessibleStates::STATE_LINKED;
     nsCOMPtr<nsIAccessible> actionAcc = GetActionAccessible();
-    if (actionAcc && (State(actionAcc) & nsIAccessibleStates::STATE_TRAVERSED))
+    if (nsAccUtils::State(actionAcc) & nsIAccessibleStates::STATE_TRAVERSED)
       *aState |= nsIAccessibleStates::STATE_TRAVERSED;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLinkableAccessible::GetValue(nsAString& aValue)
@@ -270,18 +270,18 @@ nsLinkableAccessible::CacheActionContent
                                          NS_LITERAL_STRING("click"));
   
     nsCOMPtr<nsIDOMNode> walkUpNode(do_QueryInterface(walkUpContent));
 
     nsCOMPtr<nsIAccessible> walkUpAcc;
     GetAccService()->GetAccessibleInWeakShell(walkUpNode, mWeakShell,
                                               getter_AddRefs(walkUpAcc));
 
-    if (walkUpAcc && Role(walkUpAcc) == nsIAccessibleRole::ROLE_LINK &&
-        (State(walkUpAcc) & nsIAccessibleStates::STATE_LINKED)) {
+    if (nsAccUtils::Role(walkUpAcc) == nsIAccessibleRole::ROLE_LINK &&
+        nsAccUtils::State(walkUpAcc) & nsIAccessibleStates::STATE_LINKED) {
       mIsLink = PR_TRUE;
       mActionContent = walkUpContent;
       return;
     }
 
     if (isOnclick) {
       mActionContent = walkUpContent;
       mIsOnclick = PR_TRUE;
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -358,17 +358,18 @@ nsCaretAccessible::GetCaretRect(nsIWidge
 
   nsCOMPtr<nsIAccessNode> lastAccessNode(do_QueryInterface(mLastTextAccessible));
   NS_ENSURE_TRUE(lastAccessNode, caretRect);
 
   nsCOMPtr<nsIDOMNode> lastNodeWithCaret;
   lastAccessNode->GetDOMNode(getter_AddRefs(lastNodeWithCaret));
   NS_ENSURE_TRUE(lastNodeWithCaret, caretRect);
 
-  nsCOMPtr<nsIPresShell> presShell = mRootAccessible->GetPresShellFor(lastNodeWithCaret);
+  nsCOMPtr<nsIPresShell> presShell =
+    nsCoreUtils::GetPresShellFor(lastNodeWithCaret);
   NS_ENSURE_TRUE(presShell, caretRect);
 
   nsRefPtr<nsCaret> caret;
   presShell->GetCaret(getter_AddRefs(caret));
   NS_ENSURE_TRUE(caret, caretRect);
 
   PRBool isCollapsed;
   nsIView *view;
@@ -415,17 +416,17 @@ nsCaretAccessible::GetCaretRect(nsIWidge
 }
 
 already_AddRefed<nsISelectionController>
 nsCaretAccessible::GetSelectionControllerForNode(nsIDOMNode *aNode)
 {
   if (!aNode)
     return nsnull;
 
-  nsCOMPtr<nsIPresShell> presShell = mRootAccessible->GetPresShellFor(aNode);
+  nsCOMPtr<nsIPresShell> presShell = nsCoreUtils::GetPresShellFor(aNode);
   if (!presShell)
     return nsnull;
 
   nsCOMPtr<nsIDocument> doc = presShell->GetDocument();
   if (!doc)
     return nsnull;
 
   // Get selection controller only for form controls, not for the document.
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -47,24 +47,29 @@
 #include "nsIDOM3Node.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentView.h"
 #include "nsIDOMDocumentXBL.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMRange.h"
+#include "nsIDOMViewCSS.h"
 #include "nsIDOMWindowInternal.h"
+#include "nsIDocShell.h"
+#include "nsIDocumentViewer.h"
+#include "nsIContentViewer.h"
 #include "nsIEventListenerManager.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIScrollableFrame.h"
 #include "nsIEventStateManager.h"
 #include "nsISelection2.h"
 #include "nsISelectionController.h"
+#include "nsPIDOMWindow.h"
 #include "nsGUIEvent.h"
 
 #include "nsContentCID.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 
 static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
 
@@ -178,16 +183,40 @@ nsCoreUtils::GetDOMElementFor(nsIDOMNode
 
     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(node));
     domDoc->GetDocumentElement(&element);
   }
 
   return element;
 }
 
+nsIContent*
+nsCoreUtils::GetRoleContent(nsIDOMNode *aDOMNode)
+{
+  nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
+  if (!content) {
+    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aDOMNode));
+    if (domDoc) {
+      nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aDOMNode));
+      if (htmlDoc) {
+        nsCOMPtr<nsIDOMHTMLElement> bodyElement;
+        htmlDoc->GetBody(getter_AddRefs(bodyElement));
+        content = do_QueryInterface(bodyElement);
+      }
+      else {
+        nsCOMPtr<nsIDOMElement> docElement;
+        domDoc->GetDocumentElement(getter_AddRefs(docElement));
+        content = do_QueryInterface(docElement);
+      }
+    }
+  }
+
+  return content;
+}
+
 PRBool
 nsCoreUtils::IsAncestorOf(nsIDOMNode *aPossibleAncestorNode,
                           nsIDOMNode *aPossibleDescendantNode)
 {
   NS_ENSURE_TRUE(aPossibleAncestorNode && aPossibleDescendantNode, PR_FALSE);
 
   nsCOMPtr<nsIDOMNode> loopNode = aPossibleDescendantNode;
   nsCOMPtr<nsIDOMNode> parentNode;
@@ -378,28 +407,83 @@ nsCoreUtils::GetDocShellTreeItemFor(nsID
     CallQueryInterface(container, &docShellTreeItem);
 
   return docShellTreeItem;
 }
 
 nsIFrame*
 nsCoreUtils::GetFrameFor(nsIDOMElement *aElm)
 {
-  nsCOMPtr<nsIPresShell> shell = nsAccessNode::GetPresShellFor(aElm);
+  nsCOMPtr<nsIPresShell> shell = GetPresShellFor(aElm);
   if (!shell)
     return nsnull;
   
   nsCOMPtr<nsIContent> content(do_QueryInterface(aElm));
   if (!content)
     return nsnull;
   
   return shell->GetPrimaryFrameFor(content);
 }
 
 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!");
+  
+  return aFrame->GetType() == aAtom;
+}
+
+already_AddRefed<nsIPresShell>
+nsCoreUtils::GetPresShellFor(nsIDOMNode *aNode)
+{
+  nsCOMPtr<nsIDOMDocument> domDocument;
+  aNode->GetOwnerDocument(getter_AddRefs(domDocument));
+
+  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));
+  if (!doc) // This is necessary when the node is the document node
+    doc = do_QueryInterface(aNode);
+
+  nsIPresShell *presShell = nsnull;
+  if (doc) {
+    presShell = doc->GetPrimaryShell();
+    NS_IF_ADDREF(presShell);
+  }
+
+  return presShell;
+}
+
+already_AddRefed<nsIDOMNode>
+nsCoreUtils::GetDOMNodeForContainer(nsIDocShellTreeItem *aContainer)
+{
+  nsCOMPtr<nsIDocShell> shell = do_QueryInterface(aContainer);
+
+  nsCOMPtr<nsIContentViewer> cv;
+  shell->GetContentViewer(getter_AddRefs(cv));
+
+  if (!cv)
+    return nsnull;
+
+  nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
+  if (!docv)
+    return nsnull;
+
+  nsCOMPtr<nsIDocument> doc;
+  docv->GetDocument(getter_AddRefs(doc));
+  if (!doc)
+    return nsnull;
+
+  nsIDOMNode* node = nsnull;
+  CallQueryInterface(doc.get(), &node);
+  return node;
+}
+
+PRBool
 nsCoreUtils::GetID(nsIContent *aContent, nsAString& aID)
 {
   nsIAtom *idAttribute = aContent->GetIDAttributeName();
   return idAttribute ? aContent->GetAttr(kNameSpaceID_None, idAttribute, aID) : PR_FALSE;
 }
 
 PRBool
 nsCoreUtils::IsXLink(nsIContent *aContent)
@@ -569,20 +653,87 @@ nsCoreUtils::FindDescendantPointingToIDI
       if (labelContent) {
         return labelContent;
       }
     }
   }
   return nsnull;
 }
 
+nsIContent*
+nsCoreUtils::GetLabelContent(nsIContent *aForNode)
+{
+  if (aForNode->IsNodeOfType(nsINode::eXUL))
+    return FindNeighbourPointingToNode(aForNode, nsAccessibilityAtoms::control,
+                                       nsAccessibilityAtoms::label);
+
+  return GetHTMLLabelContent(aForNode);
+}
+
+nsIContent*
+nsCoreUtils::GetHTMLLabelContent(nsIContent *aForNode)
+{
+  // Get either <label for="[id]"> element which explictly points to aForNode,
+  // or <label> ancestor which implicitly point to it.
+  nsIContent *walkUpContent = aForNode;
+  
+  // Go up tree get name of ancestor label if there is one. Don't go up farther
+  // than form element.
+  while ((walkUpContent = walkUpContent->GetParent()) != nsnull) {
+    nsIAtom *tag = walkUpContent->Tag();
+    if (tag == nsAccessibilityAtoms::label)
+      return walkUpContent;  // An ancestor <label> implicitly points to us
+
+    if (tag == nsAccessibilityAtoms::form ||
+        tag == nsAccessibilityAtoms::body) {
+      // Reached top ancestor in form
+      // There can be a label targeted at this control using the 
+      // for="control_id" attribute. To save computing time, only 
+      // look for those inside of a form element
+      nsAutoString forId;
+      if (!GetID(aForNode, forId))
+        break;
+
+      // Actually we'll be walking down the content this time, with a depth first search
+      return FindDescendantPointingToID(&forId, walkUpContent,
+                                        nsAccessibilityAtoms::_for);
+    }
+  }
+
+  return nsnull;
+}
+
 void
 nsCoreUtils::GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
                             nsAString& aLanguage)
 {
   aLanguage.Truncate();
 
   nsIContent *walkUp = aContent;
   while (walkUp && walkUp != aRootContent &&
          !walkUp->GetAttr(kNameSpaceID_None,
                           nsAccessibilityAtoms::lang, aLanguage))
     walkUp = walkUp->GetParent();
 }
+
+void
+nsCoreUtils::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
+                                         nsIDOMNode *aNode,
+                                         nsIDOMCSSStyleDeclaration **aCssDecl)
+{
+  *aCssDecl = nsnull;
+
+  nsCOMPtr<nsIDOMElement> domElement = GetDOMElementFor(aNode);
+  if (!domElement)
+    return;
+
+  // Returns number of items in style declaration
+  nsCOMPtr<nsIContent> content = do_QueryInterface(domElement);
+  nsCOMPtr<nsIDocument> doc = content->GetDocument();
+  if (!doc)
+    return;
+
+  nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(doc->GetWindow()));
+  if (!viewCSS)
+    return;
+
+  viewCSS->GetComputedStyle(domElement, aPseudoElt, aCssDecl);
+}
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -82,16 +82,27 @@ public:
    * c) body element if it is HTML document node
    * d) document element if it is document node.
    *
    * @param aNode  [in] the given DOM node
    */
   static already_AddRefed<nsIDOMElement> GetDOMElementFor(nsIDOMNode *aNode);
 
   /**
+   * 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.
+   *
+   * @param aDOMNode  DOM node for the accessible that may be affected by ARIA
+   * @return          the nsIContent which may have ARIA markup
+   */
+  static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
+
+  /**
    * 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 -- node to test for ancestor-ness of aPossibleDescendantNode
    * @param aPossibleDescendantNode -- node to test for descendant-ness of aPossibleAncestorNode
    * @return PR_TRUE if aPossibleAncestorNode is an ancestor of aPossibleDescendantNode
    */
    static PRBool IsAncestorOf(nsIDOMNode *aPossibleAncestorNode,
                               nsIDOMNode *aPossibleDescendantNode);
@@ -168,16 +179,35 @@ public:
     GetDocShellTreeItemFor(nsIDOMNode *aNode);
 
   /**
    * 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 already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aNode);
+
+  /**
+   * Return document node for the given document shell tree item.
+   */
+  static already_AddRefed<nsIDOMNode>
+    GetDOMNodeForContainer(nsIDocShellTreeItem *aContainer);
+
+  /**
    * Get the ID for an element, in some types of XML this may not be the ID attribute
    * @param aContent  Node to get the ID for
    * @param aID       Where to put ID string
    * @return          PR_TRUE if there is an ID set for this node
    */
   static PRBool GetID(nsIContent *aContent, nsAString& aID);
 
   /**
@@ -194,16 +224,23 @@ public:
    * @param aContent     [in] the given node
    * @param aRootContent [in] container of the given node
    * @param aLanguage    [out] language
    */
   static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
                              nsAString& aLanguage);
 
   /**
+   * Return computed styles declaration for the given node.
+   */
+  static void GetComputedStyleDeclaration(const nsAString& aPseudoElt,
+                                          nsIDOMNode *aNode,
+                                          nsIDOMCSSStyleDeclaration **aCssDecl);
+
+  /**
    * 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.
    *
    * @param aForNode - the given element the search is performed for
    * @param aRelationAttrs - an array of attributes, element is attribute name of searched element, ignored if aAriaProperty passed in
@@ -261,12 +298,24 @@ public:
 
   // Helper for FindDescendantPointingToID(), same args
   static nsIContent *FindDescendantPointingToIDImpl(nsCString& aIdWithSpaces,
                                                     nsIContent *aLookContent,
                                                     nsIAtom **aRelationAttrs,
                                                     PRUint32 aAttrNum = 1,
                                                     nsIContent *aExcludeContent = nsnull,
                                                     nsIAtom *aTagType = nsAccessibilityAtoms::label);
+
+  /**
+   * Return the label element for the given DOM element.
+   */
+  static nsIContent *GetLabelContent(nsIContent *aForNode);
+
+  /**
+   * Return the HTML label element for the given HTML element.
+   */
+  static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
+
+  
 };
 
 #endif
 
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -1035,17 +1035,17 @@ nsDocAccessible::AttributeChanged(nsIDoc
   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) {
-      gLastFocusedAccessiblesState = State(focusedAccessible);
+      gLastFocusedAccessiblesState = nsAccUtils::State(focusedAccessible);
     }
   }
 }
 
 
 void
 nsDocAccessible::AttributeChangedImpl(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute)
 {
@@ -1073,19 +1073,18 @@ nsDocAccessible::AttributeChangedImpl(ns
 
   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 || !IsNodeRelevant(targetNode)) {
+  if (!targetNode || !nsAccUtils::IsNodeRelevant(targetNode))
     return;
-  }
 
   // Since we're in synchronous code, we can store whether the current attribute
   // change is from user input or not. If the attribute change causes an asynchronous
   // layout change, that event can use the last known user input state
   nsAccEvent::PrepareForEvent(targetNode);
 
   // Universal boolean properties that don't require a role.
   if (aAttribute == nsAccessibilityAtoms::disabled ||
@@ -1135,17 +1134,18 @@ nsDocAccessible::AttributeChangedImpl(ns
     FireDelayedToolkitEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE,
                             targetNode);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::selected ||
       aAttribute == nsAccessibilityAtoms::aria_selected) {
     // ARIA or XUL selection
-    nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(targetNode);
+    nsCOMPtr<nsIAccessible> multiSelect =
+      nsAccUtils::GetMultiSelectFor(targetNode);
     // 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
@@ -1206,17 +1206,17 @@ nsDocAccessible::ARIAAttributeChanged(ns
     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(GetRoleContent(currentFocus), targetNode)) {
+    if (SameCOMIdentity(nsCoreUtils::GetRoleContent(currentFocus), targetNode)) {
       nsRefPtr<nsRootAccessible> rootAcc = GetRootAccessible();
       if (rootAcc)
         rootAcc->FireAccessibleFocusEvent(nsnull, currentFocus, nsnull, PR_TRUE);
     }
     return;
   }
 
   if (!aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
@@ -1240,17 +1240,18 @@ nsDocAccessible::ARIAAttributeChanged(ns
       // 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  = (State(accessible) & nsIAccessibleStates::STATE_MIXED) != 0;
+        PRBool isMixed  =
+          (nsAccUtils::State(accessible) & nsIAccessibleStates::STATE_MIXED) != 0;
         if (wasMixed != isMixed) {
           nsCOMPtr<nsIAccessibleStateChangeEvent> event =
             new nsAccStateChangeEvent(targetNode,
                                       nsIAccessibleStates::STATE_MIXED,
                                       PR_FALSE, isMixed);
           FireDelayedAccessibleEvent(event);
         }
       }
@@ -1364,17 +1365,17 @@ nsDocAccessible::ContentRemoved(nsIDocum
 void
 nsDocAccessible::ParentChainChanged(nsIContent *aContent)
 {
 }
 
 void
 nsDocAccessible::FireValueChangeForTextFields(nsIAccessible *aPossibleTextFieldAccessible)
 {
-  if (Role(aPossibleTextFieldAccessible) != nsIAccessibleRole::ROLE_ENTRY)
+  if (nsAccUtils::Role(aPossibleTextFieldAccessible) != nsIAccessibleRole::ROLE_ENTRY)
     return;
 
   // Dependent value change event for text changes in textfields
   nsCOMPtr<nsIAccessibleEvent> valueChangeEvent =
     new nsAccEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE, aPossibleTextFieldAccessible,
                    PR_FALSE, nsAccEvent::eRemoveDupes);
   FireDelayedAccessibleEvent(valueChangeEvent );
 }
@@ -1478,29 +1479,30 @@ nsDocAccessible::CreateTextChangeEventFo
     while (PR_TRUE) {
       nsCOMPtr<nsIAccessNode> childAccessNode =
         do_QueryInterface(changeAccessible);
       nsCOMPtr<nsIDOMNode> childNode;
       childAccessNode->GetDOMNode(getter_AddRefs(childNode));
       if (!nsCoreUtils::IsAncestorOf(aChangeNode, childNode)) {
         break;  // We only want accessibles with DOM nodes as children of this node
       }
-      length += TextLength(child);
+      length += nsAccUtils::TextLength(child);
       child->GetNextSibling(getter_AddRefs(changeAccessible));
       if (!changeAccessible) {
         break;
       }
       child.swap(changeAccessible);
     }
   }
   else {
     NS_ASSERTION(!changeAccessible || changeAccessible == aAccessibleForChangeNode,
                  "Hypertext is reporting a different accessible for this node");
-    length = TextLength(aAccessibleForChangeNode);
-    if (Role(aAccessibleForChangeNode) == nsIAccessibleRole::ROLE_WHITESPACE) {  // newline
+
+    length = nsAccUtils::TextLength(aAccessibleForChangeNode);
+    if (nsAccUtils::Role(aAccessibleForChangeNode) == nsIAccessibleRole::ROLE_WHITESPACE) {  // newline
       // Don't fire event for the first html:br in an editor.
       nsCOMPtr<nsIEditor> editor;
       textAccessible->GetAssociatedEditor(getter_AddRefs(editor));
       if (editor) {
         PRBool isEmpty = PR_FALSE;
         editor->GetDocumentIsEmpty(&isEmpty);
         if (isEmpty) {
           return nsnull;
@@ -1760,17 +1762,17 @@ void nsDocAccessible::RefreshNodes(nsIDO
   nsCOMPtr<nsIAccessNode> accessNode;
   GetCachedAccessNode(aStartNode, getter_AddRefs(accessNode));
 
   // Shut down accessible subtree, which may have been created for
   // anonymous content subtree
   nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
   if (accessible) {
     // Fire menupopup end if a menu goes away
-    PRUint32 role = Role(accessible);
+    PRUint32 role = nsAccUtils::Role(accessible);
     if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
       nsCOMPtr<nsIDOMNode> domNode;
       accessNode->GetDOMNode(getter_AddRefs(domNode));
       nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(domNode));
       if (!popup) {
         // Popup elements already fire these via DOMMenuInactive
         // handling in nsRootAccessible::HandleEvent
         nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -446,17 +446,19 @@ PRBool nsRootAccessible::FireAccessibleF
         mCaretAccessible->SetControlSelectionListener(realFocusedNode);
       }
     }
   }
 
   // Check for aria-activedescendant, which changes which element has focus
   nsCOMPtr<nsIDOMNode> finalFocusNode = aNode;
   nsCOMPtr<nsIAccessible> finalFocusAccessible = aAccessible;
-  nsCOMPtr<nsIContent> finalFocusContent = GetRoleContent(finalFocusNode);
+  nsCOMPtr<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);
       }
@@ -485,18 +487,18 @@ PRBool nsRootAccessible::FireAccessibleF
     // 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 = State(finalFocusAccessible);
-  PRUint32 role = Role(finalFocusAccessible);
+  gLastFocusedAccessiblesState = nsAccUtils::State(finalFocusAccessible);
+  PRUint32 role = nsAccUtils::Role(finalFocusAccessible);
   if (role == nsIAccessibleRole::ROLE_MENUITEM) {
     if (!mCurrentARIAMenubar) {  // Entering menus
       PRUint32 naturalRole; // The natural role is the role that this type of element normally has
       finalFocusAccessible->GetRole(&naturalRole);
       if (role != naturalRole) { // Must be a DHTML menuitem
         nsCOMPtr<nsIAccessible> menuBarAccessible =
           nsAccUtils::GetAncestorWithRole(finalFocusAccessible,
                                           nsIAccessibleRole::ROLE_MENUBAR);
@@ -523,17 +525,18 @@ PRBool nsRootAccessible::FireAccessibleF
 
   NS_IF_RELEASE(gLastFocusedNode);
   gLastFocusedNode = finalFocusNode;
   NS_IF_ADDREF(gLastFocusedNode);
 
   nsCOMPtr<nsIContent> focusContent = do_QueryInterface(gLastFocusedNode);
   nsIFrame *focusFrame = nsnull;
   if (focusContent) {
-    nsCOMPtr<nsIPresShell> shell = nsAccessNode::GetPresShellFor(gLastFocusedNode);
+    nsCOMPtr<nsIPresShell> shell =
+      nsCoreUtils::GetPresShellFor(gLastFocusedNode);
     focusFrame = shell->GetRealPrimaryFrameFor(focusContent);
   }
   gLastFocusedFrameType = (focusFrame && focusFrame->GetStyleVisibility()->IsVisible()) ? focusFrame->GetType() : 0;
 
   nsCOMPtr<nsIAccessibleDocument> docAccessible = do_QueryInterface(finalFocusAccessible);
   if (docAccessible) {
     // Doc is gaining focus, but actual focus may be on an element within document
     nsCOMPtr<nsIDOMNode> realFocusedNode = GetCurrentFocus();
@@ -629,17 +632,17 @@ nsresult nsRootAccessible::HandleEventWi
     nsCOMPtr<nsIAccessibleDocument> accDoc = GetDocAccessibleFor(doc);
     nsCOMPtr<nsPIAccessNode> privateAcc = do_QueryInterface(accDoc);
     if (privateAcc) {
       privateAcc->Shutdown();
     }
     return NS_OK;
   }
 
-  nsCOMPtr<nsIPresShell> eventShell = GetPresShellFor(aTargetNode);
+  nsCOMPtr<nsIPresShell> eventShell = nsCoreUtils::GetPresShellFor(aTargetNode);
   if (!eventShell) {
     return NS_OK;
   }
 
   if (eventType.EqualsLiteral("DOMContentLoaded")) {
     // Don't create the doc accessible until load scripts have a chance to set
     // role attribute for <body> or <html> element, because the value of 
     // role attribute will be cached when the doc accessible is Init()'d
@@ -684,17 +687,17 @@ nsresult nsRootAccessible::HandleEventWi
       
       if (eventType.EqualsLiteral("TreeInvalidated"))
         return HandleTreeInvalidatedEvent(aEvent, treeAcc);
     }
   }
 #endif
 
   if (eventType.EqualsLiteral("RadioStateChange")) {
-    PRUint32 state = State(accessible);
+    PRUint32 state = nsAccUtils::State(accessible);
 
     // radiogroup in prefWindow is exposed as a list,
     // and panebutton is exposed as XULListitem in A11y.
     // nsXULListitemAccessible::GetState uses STATE_SELECTED in this case,
     // so we need to check nsIAccessibleStates::STATE_SELECTED also.
     PRBool isEnabled = (state & (nsIAccessibleStates::STATE_CHECKED |
                         nsIAccessibleStates::STATE_SELECTED)) != 0;
 
@@ -705,17 +708,17 @@ nsresult nsRootAccessible::HandleEventWi
 
     if (isEnabled)
       FireAccessibleFocusEvent(accessible, aTargetNode, aEvent);
 
     return NS_OK;
   }
 
   if (eventType.EqualsLiteral("CheckboxStateChange")) {
-    PRUint32 state = State(accessible);
+    PRUint32 state = nsAccUtils::State(accessible);
 
     PRBool isEnabled = !!(state & nsIAccessibleStates::STATE_CHECKED);
 
     nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
       new nsAccStateChangeEvent(accessible,
                                 nsIAccessibleStates::STATE_CHECKED,
                                 PR_FALSE, isEnabled);
 
@@ -744,17 +747,17 @@ nsresult nsRootAccessible::HandleEventWi
         accessible = treeItemAccessible;
       }
     }
   }
 #endif
 
 #ifdef MOZ_XUL
   if (treeItemAccessible && eventType.EqualsLiteral("OpenStateChange")) {
-    PRUint32 state = State(accessible); // collapsed/expanded changed
+    PRUint32 state = nsAccUtils::State(accessible); // collapsed/expanded changed
     PRBool isEnabled = (state & nsIAccessibleStates::STATE_EXPANDED) != 0;
 
     nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
       new nsAccStateChangeEvent(accessible, nsIAccessibleStates::STATE_EXPANDED,
                                 PR_FALSE, isEnabled);
     return FireAccessibleEvent(accEvent);
   }
 
@@ -825,34 +828,34 @@ nsresult nsRootAccessible::HandleEventWi
     }
     FireAccessibleFocusEvent(accessible, focusedItem, aEvent);
   }
   else if (eventType.EqualsLiteral("AlertActive")) { 
     nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_ALERT, accessible);
   }
   else if (eventType.EqualsLiteral("popupshown")) {
     // Don't fire menupopup events for combobox and autocomplete lists
-    PRUint32 role = Role(accessible);
+    PRUint32 role = nsAccUtils::Role(accessible);
     PRInt32 event = 0;
     if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
       event = nsIAccessibleEvent::EVENT_MENUPOPUP_START;
     }
     else if (role == nsIAccessibleRole::ROLE_TOOLTIP) {
       // There is a single <xul:tooltip> node which Mozilla moves around.
       // The accessible for it stays the same no matter where it moves. 
       // AT's expect to get an EVENT_SHOW for the tooltip. 
       // In event callback the tooltip's accessible will be ready.
       event = nsIAccessibleEvent::EVENT_ASYNCH_SHOW;
     }
     if (event) {
       nsAccUtils::FireAccEvent(event, accessible);
     }
   }
   else if (eventType.EqualsLiteral("DOMMenuInactive")) {
-    if (Role(accessible) == nsIAccessibleRole::ROLE_MENUPOPUP) {
+    if (nsAccUtils::Role(accessible) == nsIAccessibleRole::ROLE_MENUPOPUP) {
       nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
                                accessible);
     }
   }
   else if (eventType.EqualsLiteral("DOMMenuItemActive")) {
     PRBool fireFocus = PR_FALSE;
     if (!treeItemAccessible) {
 #ifdef MOZ_XUL
@@ -876,21 +879,21 @@ nsresult nsRootAccessible::HandleEventWi
         return NS_OK;
       } else {
         nsCOMPtr<nsIAccessible> containerAccessible;
         accessible->GetParent(getter_AddRefs(containerAccessible));
         NS_ENSURE_TRUE(containerAccessible, NS_ERROR_FAILURE);
         // It is not top level menuitem
         // Only fire focus event if it is not inside collapsed popup
         // and not a listitem of a combo box
-        if (State(containerAccessible) & nsIAccessibleStates::STATE_COLLAPSED) {
+        if (nsAccUtils::State(containerAccessible) & nsIAccessibleStates::STATE_COLLAPSED) {
           nsCOMPtr<nsIAccessible> containerParent;
           containerAccessible->GetParent(getter_AddRefs(containerParent));
           NS_ENSURE_TRUE(containerParent, NS_ERROR_FAILURE);
-          if (Role(containerParent) != nsIAccessibleRole::ROLE_COMBOBOX) {
+          if (nsAccUtils::Role(containerParent) != nsIAccessibleRole::ROLE_COMBOBOX) {
             return NS_OK;
           }
         }
       }
     }
     if (!fireFocus) {
       nsCOMPtr<nsIDOMNode> realFocusedNode = GetCurrentFocus();
       nsCOMPtr<nsIContent> realFocusedContent = do_QueryInterface(realFocusedNode);
@@ -1015,19 +1018,19 @@ nsRootAccessible::GetContentDocShell(nsI
   if (itemType == nsIDocShellTreeItem::typeContent) {
     nsCOMPtr<nsIAccessibleDocument> accDoc =
       GetDocAccessibleFor(aStart, PR_TRUE);
     nsCOMPtr<nsIAccessible> accessible = do_QueryInterface(accDoc);
     // If ancestor chain of accessibles is not completely visible,
     // don't use this one. This happens for example if it's inside
     // a background tab (tabbed browsing)
     while (accessible) {
-      if (State(accessible) & nsIAccessibleStates::STATE_INVISIBLE) {
+      if (nsAccUtils::State(accessible) & nsIAccessibleStates::STATE_INVISIBLE)
         return nsnull;
-      }
+
       nsCOMPtr<nsIAccessible> ancestor;
       accessible->GetParent(getter_AddRefs(ancestor));
       if (ancestor == this) {
         break; // Don't check past original root accessible we started with
       }
       accessible.swap(ancestor);
     }
 
--- a/accessible/src/base/nsTextUtils.cpp
+++ b/accessible/src/base/nsTextUtils.cpp
@@ -34,17 +34,16 @@
  * 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 "nsTextUtils.h"
 
 #include "nsAccessNode.h"
-#include "nsCoreUtils.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsLangTextAttr
 
 PRBool
 nsLangTextAttr::Equal(nsIDOMElement *aElm)
 {
   nsCOMPtr<nsIContent> content(do_QueryInterface(aElm));
@@ -92,33 +91,33 @@ static nsCSSTextAttrMapItem gCSSTextAttr
   { "text-indent",       kAnyValue,       kCopyName,                  kCopyValue },
   { "vertical-align",    kAnyValue,       "text-position",            kCopyValue }
 };
 
 nsCSSTextAttr::nsCSSTextAttr(PRBool aIncludeDefAttrValue, nsIDOMElement *aElm,
                              nsIDOMElement *aRootElm) :
   mIndex(-1), mIncludeDefAttrValue(aIncludeDefAttrValue)
 {
-  nsAccessNode::GetComputedStyleDeclaration(EmptyString(), aElm,
-                                            getter_AddRefs(mStyleDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aElm,
+                                           getter_AddRefs(mStyleDecl));
 
   if (!mIncludeDefAttrValue)
-    nsAccessNode::GetComputedStyleDeclaration(EmptyString(), aRootElm,
-                                              getter_AddRefs(mDefStyleDecl));
+    nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aRootElm,
+                                             getter_AddRefs(mDefStyleDecl));
 }
 
 PRBool
 nsCSSTextAttr::Equal(nsIDOMElement *aElm)
 {
   if (!aElm || !mStyleDecl)
     return PR_FALSE;
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> currStyleDecl;
-  nsAccessNode::GetComputedStyleDeclaration(EmptyString(), aElm,
-                                            getter_AddRefs(currStyleDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aElm,
+                                           getter_AddRefs(currStyleDecl));
   if (!currStyleDecl)
     return PR_FALSE;
 
   NS_ConvertASCIItoUTF16 cssName(gCSSTextAttrsMap[mIndex].mCSSName);
 
   nsAutoString currValue;
   nsresult rv = currStyleDecl->GetPropertyValue(cssName, currValue);
   if (NS_FAILED(rv))
--- a/accessible/src/html/nsHTMLFormControlAccessible.cpp
+++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp
@@ -454,19 +454,18 @@ nsHTMLTextFieldAccessible::GetState(PRUi
 
   if (content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::type,
                            nsAccessibilityAtoms::password, eIgnoreCase)) {
     *aState |= nsIAccessibleStates::STATE_PROTECTED;
   }
   else {
     nsCOMPtr<nsIAccessible> parent;
     GetParent(getter_AddRefs(parent));
-    if (parent && Role(parent) == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
+    if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_AUTOCOMPLETE)
       *aState |= nsIAccessibleStates::STATE_HASPOPUP;
-    }
   }
 
   if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::readonly)) {
     *aState |= nsIAccessibleStates::STATE_READONLY;
   }
 
   if (!aExtraState)
     return NS_OK;
@@ -672,18 +671,17 @@ nsHTMLLegendAccessible::GetAccessibleRel
 
   if (aRelationType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
     // Look for groupbox parent
     nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
     if (!content) {
       return NS_ERROR_FAILURE;  // Node already shut down
     }
     nsCOMPtr<nsIAccessible> groupboxAccessible = GetParent();
-    if (groupboxAccessible &&
-        Role(groupboxAccessible) == nsIAccessibleRole::ROLE_GROUPING) {
+    if (nsAccUtils::Role(groupboxAccessible) == nsIAccessibleRole::ROLE_GROUPING) {
       nsCOMPtr<nsIAccessible> testLabelAccessible;
       groupboxAccessible->GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABELLED_BY,
                                                getter_AddRefs(testLabelAccessible));
       if (testLabelAccessible == this) {
         // We're the first child of the parent groupbox
         NS_ADDREF(*aRelated = groupboxAccessible);
       }
     }
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -352,22 +352,21 @@ nsHTMLSelectListAccessible::GetState(PRU
                  nsIAccessibleStates::STATE_EXTSELECTABLE;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLSelectListAccessible::GetRole(PRUint32 *aRole)
 {
-  if (mParent && Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX) {
+  if (nsAccUtils::Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX)
     *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
-  }
-  else {
+  else
     *aRole = nsIAccessibleRole::ROLE_LIST;
-  }
+
   return NS_OK;
 }
 
 already_AddRefed<nsIAccessible>
 nsHTMLSelectListAccessible::AccessibleForOption(nsIAccessibilityService *aAccService,
                                                 nsIContent *aContent,
                                                 nsIAccessible *aLastGoodAccessible,
                                                 PRInt32 *aChildCount)
@@ -496,22 +495,21 @@ nsHyperTextAccessibleWrap(aDOMNode, aShe
     }
   }
   SetParent(parentAccessible);
 }
 
 /** We are a ListItem */
 NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetRole(PRUint32 *aRole)
 {
-  if (mParent && Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
+  if (nsAccUtils::Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
     *aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
-  }
-  else {
+  else
     *aRole = nsIAccessibleRole::ROLE_OPTION;
-  }
+
   return NS_OK;
 }
 
 nsresult
 nsHTMLSelectOptionAccessible::GetNameInternal(nsAString& aName)
 {
   // CASE #1 -- great majority of the cases
   // find the label attribute - this is what the W3C says we should use
@@ -554,17 +552,17 @@ nsHTMLSelectOptionAccessible::GetAttribu
   nsCOMPtr<nsIDOMNode> parentNode;
   mDOMNode->GetParentNode(getter_AddRefs(parentNode));
   nsCOMPtr<nsIDOMElement> parentElement(do_QueryInterface(parentNode));
   NS_ENSURE_TRUE(parentElement, NS_ERROR_FAILURE);
   nsAutoString parentTagName;
   parentNode->GetLocalName(parentTagName);
 
   PRInt32 level = parentTagName.LowerCaseEqualsLiteral("optgroup") ? 2 : 1;
-  if (level == 1 && Role(this) != nsIAccessibleRole::ROLE_HEADING) {
+  if (level == 1 && nsAccUtils::Role(this) != nsIAccessibleRole::ROLE_HEADING) {
     level = 0; // In a single level list, the level is irrelevant
   }
 
   nsAutoString tagName;
   mDOMNode->GetLocalName(tagName);  // Will be looking for similar DOM siblings
   nsCOMPtr<nsIDOMNodeList> siblings;
   parentElement->GetElementsByTagName(tagName, getter_AddRefs(siblings));
   PRInt32 posInSet = 0;
@@ -842,34 +840,35 @@ void nsHTMLSelectOptionAccessible::Selec
   if (!aPossibleOption || aPossibleOption->Tag() != nsAccessibilityAtoms::option ||
       !aPossibleOption->IsNodeOfType(nsINode::eHTML)) {
     return;
   }
 
   nsCOMPtr<nsIDOMNode> optionNode(do_QueryInterface(aPossibleOption));
   NS_ASSERTION(optionNode, "No option node for nsIContent with option tag!");
 
-  nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(optionNode);
+  nsCOMPtr<nsIAccessible> multiSelect =
+    nsAccUtils::GetMultiSelectFor(optionNode);
   nsCOMPtr<nsPIAccessible> privateMultiSelect = do_QueryInterface(multiSelect);
   if (!privateMultiSelect) {
     return;
   }
 
   nsCOMPtr<nsIAccessibilityService> accService = 
     do_GetService("@mozilla.org/accessibilityService;1");
   nsCOMPtr<nsIAccessible> optionAccessible;
   accService->GetAccessibleFor(optionNode, getter_AddRefs(optionAccessible));
   if (!optionAccessible) {
     return;
   }
 
   nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
                            multiSelect);
 
-  PRUint32 state = State(optionAccessible);
+  PRUint32 state = nsAccUtils::State(optionAccessible);
   PRUint32 eventType;
   if (state & nsIAccessibleStates::STATE_SELECTED) {
     eventType = nsIAccessibleEvent::EVENT_SELECTION_ADD;
   }
   else {
     eventType = nsIAccessibleEvent::EVENT_SELECTION_REMOVE;
   }
 
@@ -1489,17 +1488,17 @@ void nsHTMLComboboxListAccessible::GetBo
 {
   *aBoundingFrame = nsnull;
 
   nsCOMPtr<nsIAccessible> comboAccessible;
   GetParent(getter_AddRefs(comboAccessible));
   if (!comboAccessible) {
     return;
   }
-  if (0 == (State(comboAccessible) & nsIAccessibleStates::STATE_COLLAPSED)) {
+  if (0 == (nsAccUtils::State(comboAccessible) & nsIAccessibleStates::STATE_COLLAPSED)) {
     nsHTMLSelectListAccessible::GetBoundsRect(aBounds, aBoundingFrame);
     return;
   }
    // get our first option
   nsCOMPtr<nsIDOMNode> child;
   mDOMNode->GetFirstChild(getter_AddRefs(child));
 
   // now get its frame
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -105,17 +105,17 @@ nsHTMLTableCellAccessible::GetAttributes
 
   nsCOMPtr<nsIAccessible> childAcc(this);
 
   nsCOMPtr<nsIAccessible> parentAcc;
   rv = childAcc->GetParent(getter_AddRefs(parentAcc));
   NS_ENSURE_SUCCESS(rv, rv);
 
   while (parentAcc) {
-    if (Role(parentAcc) == nsIAccessibleRole::ROLE_TABLE) {
+    if (nsAccUtils::Role(parentAcc) == nsIAccessibleRole::ROLE_TABLE) {
       // Table accessible must implement nsIAccessibleTable interface but if
       // it isn't happen (for example because of ARIA usage) we shouldn't fail
       // on getting other attributes.
       nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(parentAcc));
       if (!tableAcc)
         return NS_OK;
 
       PRInt32 idx = -1;
@@ -154,17 +154,17 @@ void nsHTMLTableAccessible::CacheChildre
     mAccChildCount = eChildCountUninitialized;
     return;
   }
   
   if (mAccChildCount == eChildCountUninitialized) {
     nsAccessible::CacheChildren();
     nsCOMPtr<nsIAccessible> captionAccessible;
     while (NextChild(captionAccessible)) {
-      if (Role(captionAccessible) == nsIAccessibleRole::ROLE_CAPTION) {
+      if (nsAccUtils::Role(captionAccessible) == nsIAccessibleRole::ROLE_CAPTION) {
         nsCOMPtr<nsIAccessible> captionParentAccessible;
         captionAccessible->GetParent(getter_AddRefs(captionParentAccessible));
         if (captionParentAccessible != this) {
           NS_WARNING("Should not happen: parser ensures caption is the table's child, not the tbody's");
           return;
         }
         nsCOMPtr<nsIAccessible> beforeCaptionAccessible;
         captionAccessible->GetPreviousSibling(getter_AddRefs(beforeCaptionAccessible));
@@ -265,19 +265,19 @@ nsHTMLTableAccessible::GetAccessibleRela
 }
 
 
 NS_IMETHODIMP
 nsHTMLTableAccessible::GetCaption(nsIAccessible **aCaption)
 {
   nsCOMPtr<nsIAccessible> firstChild;
   GetFirstChild(getter_AddRefs(firstChild));
-  if (firstChild && Role(firstChild) == nsIAccessibleRole::ROLE_CAPTION) {
+  if (nsAccUtils::Role(firstChild) == nsIAccessibleRole::ROLE_CAPTION)
     NS_ADDREF(*aCaption = firstChild);
-  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLTableAccessible::GetSummary(nsAString &aSummary)
 {
   nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
   NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
@@ -1061,17 +1061,18 @@ NS_IMETHODIMP nsHTMLTableAccessible::IsP
     PRUint32 state, extState;
     docAccessible->GetFinalState(&state, &extState);
     if (extState & nsIAccessibleStates::EXT_STATE_EDITABLE) {  // Need to see all elements while document is being edited
       RETURN_LAYOUT_ANSWER(PR_FALSE, "In editable document");
     }
   }
 
   // Check role and role attribute
-  PRBool hasNonTableRole = (Role(this) != nsIAccessibleRole::ROLE_TABLE);
+  PRBool hasNonTableRole =
+    (nsAccUtils::Role(this) != nsIAccessibleRole::ROLE_TABLE);
   if (hasNonTableRole) {
     RETURN_LAYOUT_ANSWER(PR_FALSE, "Has role attribute");
   }
 
   if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
     RETURN_LAYOUT_ANSWER(PR_TRUE, "Has role attribute, and role is table");
   }
   
@@ -1135,18 +1136,18 @@ NS_IMETHODIMP nsHTMLTableAccessible::IsP
   PRUint32 length;
   nodeList->GetLength(&length);
   nsAutoString color, lastRowColor;
   for (PRInt32 rowCount = 0; rowCount < rows; rowCount ++) {
     nsCOMPtr<nsIDOMNode> rowNode;
     nodeList->Item(rowCount, getter_AddRefs(rowNode));
 
     nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
-    GetComputedStyleDeclaration(EmptyString(), rowNode,
-                                getter_AddRefs(styleDecl));
+    nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), rowNode,
+                                             getter_AddRefs(styleDecl));
     NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
 
     lastRowColor = color;
     styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), color);
     if (rowCount > 0 && PR_FALSE == lastRowColor.Equals(color)) {
       RETURN_LAYOUT_ANSWER(PR_FALSE, "2 styles of row background color, non-bordered");
     }
   }
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -342,17 +342,18 @@ nsHyperTextAccessible::GetPosAndText(PRI
   }
   if (aEndOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
     GetCaretOffset(&aEndOffset);
   }
 
   PRInt32 startOffset = aStartOffset;
   PRInt32 endOffset = aEndOffset;
   // XXX this prevents text interface usage on <input type="password">
-  PRBool isPassword = (Role(this) == nsIAccessibleRole::ROLE_PASSWORD_TEXT);
+  PRBool isPassword =
+    (nsAccUtils::Role(this) == nsIAccessibleRole::ROLE_PASSWORD_TEXT);
 
   // Clear out parameters and set up loop
   if (aText) {
     aText->Truncate();
   }
   if (endOffset < 0) {
     const PRInt32 kMaxTextLength = 32767;
     endOffset = kMaxTextLength; // Max end offset
@@ -384,17 +385,17 @@ nsHyperTextAccessible::GetPosAndText(PRI
   while (NextChild(accessible)) {
     lastAccessible = accessible;
     nsCOMPtr<nsPIAccessNode> accessNode(do_QueryInterface(accessible));
     nsIFrame *frame = accessNode->GetFrame();
     if (!frame) {
       continue;
     }
     nsIFrame *primaryFrame = frame;
-    if (IsText(accessible)) {
+    if (nsAccUtils::IsText(accessible)) {
       // We only need info up to rendered offset -- that is what we're
       // converting to content offset
       PRInt32 substringEndOffset = -1;
       PRUint32 ourRenderedStart = 0;
       PRInt32 ourContentStart = 0;
       if (frame->GetType() == nsAccessibilityAtoms::textFrame) {
         nsresult rv = frame->GetRenderedText(nsnull, &skipChars, &iter);
         if (NS_SUCCEEDED(rv)) {
@@ -403,17 +404,17 @@ nsHyperTextAccessible::GetPosAndText(PRI
           substringEndOffset =
             iter.ConvertOriginalToSkipped(skipChars.GetOriginalCharCount() +
                                           ourContentStart) - ourRenderedStart;
         }
       }
       if (substringEndOffset < 0) {
         // XXX for non-textframe text like list bullets,
         // should go away after list bullet rewrite
-        substringEndOffset = TextLength(accessible);
+        substringEndOffset = nsAccUtils::TextLength(accessible);
       }
       if (startOffset < substringEndOffset) {
         // Our start is within this substring
         if (startOffset > 0 || endOffset < substringEndOffset) {
           // We don't want the whole string for this accessible
           // Get out the continuing text frame with this offset
           PRInt32 outStartLineUnused;
           PRInt32 contentOffset;
@@ -477,17 +478,17 @@ nsHyperTextAccessible::GetPosAndText(PRI
       if (startOffset >= 1) {
         -- startOffset;
       }
       else {
         if (endOffset > 0) {
           if (aText) {
             if (frame->GetType() == nsAccessibilityAtoms::brFrame) {
               *aText += kForcedNewLineChar;
-            } else if (MustPrune(this)) {
+            } else if (nsAccUtils::MustPrune(this)) {
               *aText += kImaginaryEmbeddedObjectChar;
               // Expose imaginary embedded object character if the accessible
               // hans't children.
             } else {
               *aText += kEmbeddedObjectChar;
             }
           }
           if (aBoundsRect) {
@@ -537,17 +538,17 @@ NS_IMETHODIMP nsHyperTextAccessible::Get
   *aCharacterCount = 0;
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIAccessible> accessible;
 
   while (NextChild(accessible)) {
-    PRInt32 textLength = TextLength(accessible);
+    PRInt32 textLength = nsAccUtils::TextLength(accessible);
     NS_ENSURE_TRUE(textLength >= 0, nsnull);
     *aCharacterCount += textLength;
   }
   return NS_OK;
 }
 
 /*
  * Gets the specified character.
@@ -671,35 +672,38 @@ nsresult nsHyperTextAccessible::DOMPoint
     // addTextOffset, to put us after the embedded object char. We'll only treat the offset as
     // before the embedded object char if we end at the very beginning of the child.
     addTextOffset = addTextOffset > 0;
     }
     else {
       // Start offset, inclusive
       // Make sure the offset lands on the embedded object character in order to indicate
       // the true inner offset is inside the subtree for that link
-      addTextOffset = (TextLength(descendantAccessible) == static_cast<PRInt32>(addTextOffset)) ? 1 : 0;
+      addTextOffset =
+        (nsAccUtils::TextLength(descendantAccessible) == static_cast<PRInt32>(addTextOffset)) ? 1 : 0;
     }
     descendantAccessible = parentAccessible;
   }  
 
   // Loop through, adding offsets until we reach childAccessible
   // If childAccessible is null we will end up adding up the entire length of
   // the hypertext, which is good -- it just means our offset node
   // came after the last accessible child's node
   nsCOMPtr<nsIAccessible> accessible;
   while (NextChild(accessible) && accessible != childAccessible) {
-    PRInt32 textLength = TextLength(accessible);
+    PRInt32 textLength = nsAccUtils::TextLength(accessible);
     NS_ENSURE_TRUE(textLength >= 0, nsnull);
     *aHyperTextOffset += textLength;
   }
   if (accessible) {
     *aHyperTextOffset += addTextOffset;
     NS_ASSERTION(accessible == childAccessible, "These should be equal whenever we exit loop and accessible != nsnull");
-    if (aFinalAccessible && (NextChild(accessible) || static_cast<PRInt32>(addTextOffset) < TextLength(childAccessible))) {  
+    if (aFinalAccessible &&
+        (NextChild(accessible) ||
+         static_cast<PRInt32>(addTextOffset) < nsAccUtils::TextLength(childAccessible))) {  
       // If not at end of last text node, we will return the accessible we were in
       NS_ADDREF(*aFinalAccessible = childAccessible);
     }
   }
 
   return NS_OK;
 }
 
@@ -811,17 +815,17 @@ nsHyperTextAccessible::GetRelativeOffset
     aAmount = (aDirection == eDirNext) ? eSelectEndLine : eSelectBeginLine;
   }
 
   // Ask layout for the new node and offset, after moving the appropriate amount
   nsPeekOffsetStruct pos;
 
   nsresult rv;
   PRInt32 contentOffset = aFromOffset;
-  if (IsText(aFromAccessible)) {
+  if (nsAccUtils::IsText(aFromAccessible)) {
     nsCOMPtr<nsPIAccessNode> accessNode(do_QueryInterface(aFromAccessible));
     NS_ASSERTION(accessNode, "nsIAccessible doesn't support nsPIAccessNode");
 
     nsIFrame *frame = accessNode->GetFrame();
     NS_ENSURE_TRUE(frame, -1);
     if (frame->GetType() == nsAccessibilityAtoms::textFrame) {
       rv = RenderedToContentOffset(frame, aFromOffset, &contentOffset);
       NS_ENSURE_SUCCESS(rv, -1);
@@ -863,29 +867,29 @@ nsHyperTextAccessible::GetRelativeOffset
   if (!finalAccessible && aDirection == eDirPrevious) {
     // If we reached the end during search, this means we didn't find the DOM point
     // and we're actually at the start of the paragraph
     hyperTextOffset = 0;
   }  
   else if (aAmount == eSelectBeginLine) {
     // For line selection with needsStart, set start of line exactly to line break
     if (pos.mContentOffset == 0 && mFirstChild && 
-        Role(mFirstChild) == nsIAccessibleRole::ROLE_STATICTEXT &&
-        TextLength(mFirstChild) == hyperTextOffset) {
+        nsAccUtils::Role(mFirstChild) == nsIAccessibleRole::ROLE_STATICTEXT &&
+        nsAccUtils::TextLength(mFirstChild) == hyperTextOffset) {
       // XXX Bullet hack -- we should remove this once list bullets use anonymous content
       hyperTextOffset = 0;
     }
     if (!aNeedsStart && hyperTextOffset > 0) {
       -- hyperTextOffset;
     }
   }
   else if (aAmount == eSelectEndLine && finalAccessible) { 
     // If not at very end of hypertext, we may need change the end of line offset by 1, 
     // to make sure we are in the right place relative to the line ending
-    if (Role(finalAccessible) == nsIAccessibleRole::ROLE_WHITESPACE) {  // Landed on <br> hard line break
+    if (nsAccUtils::Role(finalAccessible) == nsIAccessibleRole::ROLE_WHITESPACE) {  // Landed on <br> hard line break
       // if aNeedsStart, set end of line exactly 1 character past line break
       // XXX It would be cleaner if we did not have to have the hard line break check,
       // and just got the correct results from PeekOffset() for the <br> case -- the returned offset should
       // come after the new line, as it does in other cases.
       ++ hyperTextOffset;  // Get past hard line break
     }
     // We are now 1 character past the line break
     if (!aNeedsStart) {
@@ -1044,20 +1048,23 @@ nsresult nsHyperTextAccessible::GetTextH
     // Start moving forward from the start so that we don't get 
     // 2 words/lines if the offset occured on whitespace boundary
     // Careful, startOffset and endOffset are passed by reference to GetPosAndText() and changed
     // For BOUNDARY_LINE_END, make sure we start of this line
     startOffset = endOffset = finalStartOffset + (aBoundaryType == BOUNDARY_LINE_END);
     nsCOMPtr<nsIAccessible> endAcc;
     nsIFrame *endFrame = GetPosAndText(startOffset, endOffset, nsnull, nsnull,
                                        nsnull, getter_AddRefs(endAcc));
-    if (endAcc && Role(endAcc) == nsIAccessibleRole::ROLE_STATICTEXT) {
+    if (nsAccUtils::Role(endAcc) == nsIAccessibleRole::ROLE_STATICTEXT) {
       // Static text like list bullets will ruin our forward calculation,
       // since the caret cannot be in the static text. Start just after the static text.
-      startOffset = endOffset = finalStartOffset + (aBoundaryType == BOUNDARY_LINE_END) + TextLength(endAcc);
+      startOffset = endOffset = finalStartOffset +
+                                (aBoundaryType == BOUNDARY_LINE_END) +
+                                nsAccUtils::TextLength(endAcc);
+
       endFrame = GetPosAndText(startOffset, endOffset, nsnull, nsnull,
                                nsnull, getter_AddRefs(endAcc));
     }
     if (!endFrame) {
       return NS_ERROR_FAILURE;
     }
     finalEndOffset = GetRelativeOffset(presShell, endFrame, endOffset, endAcc,
                                        amount, eDirNext, needsStart);
@@ -1230,17 +1237,17 @@ nsHyperTextAccessible::GetAttributesInte
 {
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;  // Node already shut down
   }
 
   nsresult rv = nsAccessibleWrap::GetAttributesInternal(aAttributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIContent> content(do_QueryInterface(GetRoleContent(mDOMNode)));
+  nsCOMPtr<nsIContent> content = nsCoreUtils::GetRoleContent(mDOMNode);
   NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED);
   nsIAtom *tag = content->Tag();
 
   PRInt32 headLevel = 0;
   if (tag == nsAccessibilityAtoms::h1)
     headLevel = 1;
   else if (tag == nsAccessibilityAtoms::h2)
     headLevel = 2;
@@ -1386,17 +1393,17 @@ nsHyperTextAccessible::GetOffsetAtPoint(
           NS_ENSURE_SUCCESS(rv, rv);
           offset += addToOffset;
         }
         *aOffset = offset;
         return NS_OK;
       }
       frame = frame->GetNextContinuation();
     }
-    PRInt32 textLength = TextLength(accessible);
+    PRInt32 textLength = nsAccUtils::TextLength(accessible);
     NS_ENSURE_TRUE(textLength >= 0, NS_ERROR_FAILURE);
     offset += textLength;
   }
 
   return NS_OK; // Not found, will return -1
 }
 
 // ------- nsIAccessibleHyperText ---------------
@@ -1407,19 +1414,18 @@ nsHyperTextAccessible::GetLinkCount(PRIn
   *aLinkCount = 0;
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIAccessible> accessible;
 
   while (NextChild(accessible)) {
-    if (IsEmbeddedObject(accessible)) {
+    if (nsAccUtils::IsEmbeddedObject(accessible))
       ++*aLinkCount;
-    }
   }
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsHyperTextAccessible::GetLink(PRInt32 aLinkIndex, nsIAccessibleHyperLink **aLink)
 {
@@ -1427,17 +1433,17 @@ nsHyperTextAccessible::GetLink(PRInt32 a
   *aLink = nsnull;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   PRInt32 linkIndex = aLinkIndex;
   nsCOMPtr<nsIAccessible> accessible;
   while (NextChild(accessible)) {
-    if (IsEmbeddedObject(accessible) && linkIndex-- == 0)
+    if (nsAccUtils::IsEmbeddedObject(accessible) && linkIndex-- == 0)
       return CallQueryInterface(accessible, aLink);
   }
 
   return NS_ERROR_INVALID_ARG;
 }
 
 NS_IMETHODIMP
 nsHyperTextAccessible::GetLinkIndex(PRInt32 aCharIndex, PRInt32 *aLinkIndex)
@@ -1449,20 +1455,20 @@ nsHyperTextAccessible::GetLinkIndex(PRIn
   PRInt32 linkIndex = 0;
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIAccessible> accessible;
 
   while (NextChild(accessible) && characterCount <= aCharIndex) {
-    PRUint32 role = Role(accessible);
+    PRUint32 role = nsAccUtils::Role(accessible);
     if (role == nsIAccessibleRole::ROLE_TEXT_LEAF ||
         role == nsIAccessibleRole::ROLE_STATICTEXT) {
-      PRInt32 textLength = TextLength(accessible);
+      PRInt32 textLength = nsAccUtils::TextLength(accessible);
       NS_ENSURE_TRUE(textLength >= 0, NS_ERROR_FAILURE);
       characterCount += textLength;
     }
     else {
       if (characterCount ++ == aCharIndex) {
         *aLinkIndex = linkIndex;
         break;
       }
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -463,17 +463,18 @@ GetNativeFromGeckoAccessible(nsIAccessib
   return [NSValue valueWithSize:NSMakeSize (width, height)];
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (NSString*)role
 {
 #ifdef DEBUG_A11Y
-  NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(mGeckoAccessible), "Does not support nsIAccessibleText when it should");
+  NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(mGeckoAccessible),
+               "Does not support nsIAccessibleText when it should");
 #endif
   return AXRoles[mRole];
 }
 
 - (NSString*)subrole
 {
   return nil;
 }
--- a/accessible/src/mac/nsAccessibleWrap.h
+++ b/accessible/src/mac/nsAccessibleWrap.h
@@ -103,18 +103,19 @@ class nsAccessibleWrap : public nsAccess
       // we don't create a native object if we're child of a "flat" accessible; for example, on OS X buttons 
       // shouldn't have any children, because that makes the OS confused. 
       //
       // to maintain a scripting environment where the XPCOM accessible hierarchy look the same 
       // on all platforms, we still let the C++ objects be created though.
       
       nsCOMPtr<nsIAccessible> curParent = GetParent();
       while (curParent) {
-        if (MustPrune(curParent))
+        if (nsAccUtils::MustPrune(curParent))
           return PR_TRUE;
+
         nsCOMPtr<nsIAccessible> newParent;
         curParent->GetParent(getter_AddRefs(newParent));
         curParent.swap(newParent);
       }
       // no parent was flat
       return PR_FALSE;
     }
 
--- a/accessible/src/mac/nsAccessibleWrap.mm
+++ b/accessible/src/mac/nsAccessibleWrap.mm
@@ -98,17 +98,17 @@ nsAccessibleWrap::GetNativeWindow (void 
 
 // overridden in subclasses to create the right kind of object. by default we create a generic
 // 'mozAccessible' node.
 objc_class*
 nsAccessibleWrap::GetNativeType () 
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
-  PRUint32 role = Role(this);
+  PRUint32 role = nsAccUtils::Role(this);
   switch (role) {
     case nsIAccessibleRole::ROLE_PUSHBUTTON:
     case nsIAccessibleRole::ROLE_SPLITBUTTON:
     case nsIAccessibleRole::ROLE_TOGGLE_BUTTON:
     {
       // if this button may show a popup, let's make it of the popupbutton type.
       if (HasPopup())
         return [mozPopupButtonAccessible class];
@@ -224,33 +224,33 @@ nsAccessibleWrap::InvalidateChildren ()
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 PRInt32
 nsAccessibleWrap::GetUnignoredChildCount(PRBool aDeepCount)
 {
   // if we're flat, we have no children.
-  if (MustPrune(this))
+  if (nsAccUtils::MustPrune(this))
     return 0;
   
   PRInt32 childCount = 0;
   GetChildCount(&childCount);
   
   nsCOMPtr<nsIAccessible> curAcc;
   
   while (NextChild(curAcc)) {
     nsAccessibleWrap *childWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)curAcc.get());
     
     // if the current child is not ignored, count it.
     if (!childWrap->IsIgnored())
       ++childCount;
       
     // if it's flat, we don't care to inspect its children.
-    if (MustPrune(childWrap))
+    if (nsAccUtils::MustPrune(childWrap))
       continue;
     
     if (aDeepCount) {
       // recursively count the unignored children of our children since it's a deep count.
       childCount += childWrap->GetUnignoredChildCount(PR_TRUE);
     } else {
       // no deep counting, but if the child is ignored, we want to substitute it for its
       // children.
@@ -271,24 +271,24 @@ nsAccessibleWrap::IsIgnored()
 }
 
 void
 nsAccessibleWrap::GetUnignoredChildren(nsTArray<nsRefPtr<nsAccessibleWrap> > &aChildrenArray)
 {
   nsCOMPtr<nsIAccessible> curAcc;
   
   // we're flat; there are no children.
-  if (MustPrune(this))
+  if (nsAccUtils::MustPrune(this))
     return;
   
   while (NextChild(curAcc)) {
     nsAccessibleWrap *childWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)curAcc.get());
     if (childWrap->IsIgnored()) {
       // element is ignored, so try adding its children as substitutes, if it has any.
-      if (!MustPrune(childWrap)) {
+      if (!nsAccUtils::MustPrune(childWrap)) {
         nsTArray<nsRefPtr<nsAccessibleWrap> > children;
         childWrap->GetUnignoredChildren(children);
         if (!children.IsEmpty()) {
           // add the found unignored descendants to the array.
           aChildrenArray.AppendElements(children);
         }
       }
     } else
--- a/accessible/src/msaa/nsAccessNodeWrap.cpp
+++ b/accessible/src/msaa/nsAccessNodeWrap.cpp
@@ -311,17 +311,18 @@ STDMETHODIMP nsAccessNodeWrap::get_compu
 {
 __try{
   *aNumStyleProperties = 0;
 
   if (IsDefunct())
     return E_FAIL;
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
-  GetComputedStyleDeclaration(EmptyString(), mDOMNode, getter_AddRefs(cssDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), mDOMNode,
+                                           getter_AddRefs(cssDecl));
   NS_ENSURE_TRUE(cssDecl, E_FAIL);
 
   PRUint32 length;
   cssDecl->GetLength(&length);
 
   PRUint32 index, realIndex;
   for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties; index ++) {
     nsAutoString property, value;
@@ -346,17 +347,18 @@ STDMETHODIMP nsAccessNodeWrap::get_compu
     /* [length_is][size_is][in] */ BSTR __RPC_FAR *aStyleProperties,
     /* [length_is][size_is][out] */ BSTR __RPC_FAR *aStyleValues)
 {
 __try {
   if (IsDefunct())
     return E_FAIL;
  
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
-  GetComputedStyleDeclaration(EmptyString(), mDOMNode, getter_AddRefs(cssDecl));
+  nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), mDOMNode,
+                                           getter_AddRefs(cssDecl));
   NS_ENSURE_TRUE(cssDecl, E_FAIL);
 
   PRUint32 index;
   for (index = 0; index < aNumStyleProperties; index ++) {
     nsAutoString value;
     if (aStyleProperties[index])
       cssDecl->GetPropertyValue(nsDependentString(static_cast<PRUnichar*>(aStyleProperties[index])), value);  // Get property value
     aStyleValues[index] = ::SysAllocString(value.get());
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -241,19 +241,18 @@ STDMETHODIMP nsAccessibleWrap::get_accPa
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return S_OK;
 }
 
 STDMETHODIMP nsAccessibleWrap::get_accChildCount( long __RPC_FAR *pcountChildren)
 {
 __try {
   *pcountChildren = 0;
-  if (MustPrune(this)) {
+  if (nsAccUtils::MustPrune(this))
     return NS_OK;
-  }
 
   PRInt32 numChildren;
   GetChildCount(&numChildren);
   *pcountChildren = numChildren;
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
 
   return S_OK;
 }
@@ -269,17 +268,17 @@ STDMETHODIMP nsAccessibleWrap::get_accCh
 
   if (varChild.lVal == CHILDID_SELF) {
     *ppdispChild = static_cast<IDispatch*>(this);
     AddRef();
     return S_OK;
   }
 
   nsCOMPtr<nsIAccessible> childAccessible;
-  if (!MustPrune(this)) {
+  if (!nsAccUtils::MustPrune(this)) {
     GetChildAt(varChild.lVal - 1, getter_AddRefs(childAccessible));
     if (childAccessible) {
       *ppdispChild = NativeAccessible(childAccessible);
     }
   }
 } __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
 
   return (*ppdispChild)? S_OK: E_FAIL;
@@ -468,35 +467,35 @@ STDMETHODIMP nsAccessibleWrap::get_accRo
 
   nsCOMPtr<nsIAccessible> xpAccessible;
   GetXPAccessibleFor(varChild, getter_AddRefs(xpAccessible));
 
   if (!xpAccessible)
     return E_FAIL;
 
 #ifdef DEBUG_A11Y
-  NS_ASSERTION(nsAccessible::IsTextInterfaceSupportCorrect(xpAccessible), "Does not support nsIAccessibleText when it should");
+  NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(xpAccessible),
+               "Does not support nsIAccessibleText when it should");
 #endif
 
   PRUint32 xpRole = 0, msaaRole = 0;
   if (NS_FAILED(xpAccessible->GetFinalRole(&xpRole)))
     return E_FAIL;
 
   msaaRole = gWindowsRoleMap[xpRole].msaaRole;
   NS_ASSERTION(gWindowsRoleMap[nsIAccessibleRole::ROLE_LAST_ENTRY].msaaRole == ROLE_WINDOWS_LAST_ENTRY,
                "MSAA role map skewed");
 
   // Special case, if there is a ROLE_ROW inside of a ROLE_TREE_TABLE, then call the MSAA role
   // a ROLE_OUTLINEITEM for consistency and compatibility.
   // We need this because ARIA has a role of "row" for both grid and treegrid
   if (xpRole == nsIAccessibleRole::ROLE_ROW) {
     nsCOMPtr<nsIAccessible> parent = GetParent();
-    if (parent && Role(parent) == nsIAccessibleRole::ROLE_TREE_TABLE) {
+    if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_TREE_TABLE)
       msaaRole = ROLE_SYSTEM_OUTLINEITEM;
-    }
   }
   
   // -- Try enumerated role
   if (msaaRole != USE_ROLE_STRING) {
     pvarRole->vt = VT_I4;
     pvarRole->lVal = msaaRole;  // Normal enumerated role
     return S_OK;
   }
@@ -505,17 +504,17 @@ STDMETHODIMP nsAccessibleWrap::get_accRo
   // Could not map to known enumerated MSAA role like ROLE_BUTTON
   // Use BSTR role to expose role attribute or tag name + namespace
   nsCOMPtr<nsIDOMNode> domNode;
   nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(xpAccessible));
   if (!accessNode)
     return E_FAIL;
 
   accessNode->GetDOMNode(getter_AddRefs(domNode));
-  nsIContent *content = GetRoleContent(domNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(domNode);
   if (!content)
     return E_FAIL;
 
   if (content->IsNodeOfType(nsINode::eELEMENT)) {
     nsAutoString roleString;
     if (msaaRole != ROLE_SYSTEM_CLIENT &&
         !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, roleString)) {
       nsINodeInfo *nodeInfo = content->NodeInfo();
@@ -908,24 +907,22 @@ STDMETHODIMP nsAccessibleWrap::accNaviga
   VariantInit(pvarEndUpAt);
   PRUint32 xpRelation = 0;
 
   switch(navDir) {
     case NAVDIR_DOWN:
       xpAccessibleStart->GetAccessibleBelow(getter_AddRefs(xpAccessibleResult));
       break;
     case NAVDIR_FIRSTCHILD:
-      if (!MustPrune(xpAccessibleStart)) {
+      if (!nsAccUtils::MustPrune(xpAccessibleStart))
         xpAccessibleStart->GetFirstChild(getter_AddRefs(xpAccessibleResult));
-      }
       break;
     case NAVDIR_LASTCHILD:
-      if (!MustPrune(xpAccessibleStart)) {
+      if (!nsAccUtils::MustPrune(xpAccessibleStart))
         xpAccessibleStart->GetLastChild(getter_AddRefs(xpAccessibleResult));
-      }
       break;
     case NAVDIR_LEFT:
       xpAccessibleStart->GetAccessibleToLeft(getter_AddRefs(xpAccessibleResult));
       break;
     case NAVDIR_NEXT:
       xpAccessibleStart->GetNextSibling(getter_AddRefs(xpAccessibleResult));
       break;
     case NAVDIR_PREVIOUS:
@@ -1017,17 +1014,17 @@ STDMETHODIMP nsAccessibleWrap::accHitTes
   VariantInit(pvarChild);
 
   // convert to window coords
   nsCOMPtr<nsIAccessible> xpAccessible;
 
   xLeft = xLeft;
   yTop = yTop;
 
-  if (MustPrune(this)) {
+  if (nsAccUtils::MustPrune(this)) {
     xpAccessible = this;
   }
   else {
     GetChildAtPoint(xLeft, yTop, getter_AddRefs(xpAccessible));
   }
 
   // if we got a child
   if (xpAccessible) {
@@ -1876,17 +1873,17 @@ void nsAccessibleWrap::GetXPAccessibleFo
   *aXPAccessible = nsnull;
   if (!mWeakShell)
     return; // Fail, we don't want to do anything after we've shut down
 
   // if its us real easy - this seems to always be the case
   if (aVarChild.lVal == CHILDID_SELF) {
     *aXPAccessible = static_cast<nsIAccessible*>(this);
   }
-  else if (MustPrune(this)) {
+  else if (nsAccUtils::MustPrune(this)) {
     return;
   }
   else {
     // XXX It is rare to use a VARIANT with a child num
     // so optimizing this is not a priority
     // We can come back it do it later, if there are perf problems
     // with a specific assistive technology
     nsCOMPtr<nsIAccessible> xpAccessible, nextAccessible;
--- a/accessible/src/msaa/nsDocAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsDocAccessibleWrap.cpp
@@ -317,17 +317,17 @@ STDMETHODIMP nsDocAccessibleWrap::get_ac
 {
   // For backwards-compat, we still support old MSAA hack to provide URL in accValue
   *pszValue = NULL;
   // Check for real value first
   HRESULT hr = nsAccessibleWrap::get_accValue(varChild, pszValue);
   if (FAILED(hr) || *pszValue || varChild.lVal != CHILDID_SELF)
     return hr;
   // If document is being used to create a widget, don't use the URL hack
-  PRUint32 role = Role(this);
+  PRUint32 role = nsAccUtils::Role(this);
   if (role != nsIAccessibleRole::ROLE_DOCUMENT &&
       role != nsIAccessibleRole::ROLE_APPLICATION &&
       role != nsIAccessibleRole::ROLE_DIALOG &&
       role != nsIAccessibleRole::ROLE_ALERT)
     return hr;
 
   return get_URL(pszValue);
 }
--- a/accessible/src/xul/nsXULFormControlAccessible.cpp
+++ b/accessible/src/xul/nsXULFormControlAccessible.cpp
@@ -443,17 +443,17 @@ nsXULGroupboxAccessible::GetAccessibleRe
   }
 
   if (aRelationType == nsIAccessibleRelation::RELATION_LABELLED_BY) {
     // The label for xul:groupbox is generated from xul:label that is
     // inside the anonymous content of the xul:caption.
     // The xul:label has an accessible object but the xul:caption does not
     nsCOMPtr<nsIAccessible> testLabelAccessible;
     while (NextChild(testLabelAccessible)) {
-      if (Role(testLabelAccessible) == nsIAccessibleRole::ROLE_LABEL) {
+      if (nsAccUtils::Role(testLabelAccessible) == nsIAccessibleRole::ROLE_LABEL) {
         // Ensure that it's our label
         nsCOMPtr<nsIAccessible> testGroupboxAccessible;
         testLabelAccessible->GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABEL_FOR,
                                                   getter_AddRefs(testGroupboxAccessible));
         if (testGroupboxAccessible == this) {
           // The <label> points back to this groupbox
           NS_ADDREF(*aRelated = testLabelAccessible);
           return NS_OK;
--- a/accessible/src/xul/nsXULMenuAccessible.cpp
+++ b/accessible/src/xul/nsXULMenuAccessible.cpp
@@ -322,43 +322,41 @@ nsXULMenuitemAccessible::GetState(PRUint
     element->GetAttribute(NS_LITERAL_STRING("checked"), checkValue);
     if (checkValue.EqualsLiteral("true")) {
       *aState |= nsIAccessibleStates::STATE_CHECKED;
     }
   }
 
   // Combo box listitem
   PRBool isComboboxOption =
-    (Role(this) == nsIAccessibleRole::ROLE_COMBOBOX_OPTION);
+    (nsAccUtils::Role(this) == nsIAccessibleRole::ROLE_COMBOBOX_OPTION);
   if (isComboboxOption) {
     // Is selected?
     PRBool isSelected = PR_FALSE;
     nsCOMPtr<nsIDOMXULSelectControlItemElement>
       item(do_QueryInterface(mDOMNode));
     NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
     item->GetSelected(&isSelected);
 
     // Is collapsed?
     PRBool isCollapsed = PR_FALSE;
     nsCOMPtr<nsIAccessible> parentAccessible(GetParent());
-    if (parentAccessible &&
-        State(parentAccessible) & nsIAccessibleStates::STATE_INVISIBLE) {
+    if (nsAccUtils::State(parentAccessible) & nsIAccessibleStates::STATE_INVISIBLE)
       isCollapsed = PR_TRUE;
-    }
     
     if (isSelected) {
       *aState |= nsIAccessibleStates::STATE_SELECTED;
       
       // Selected and collapsed?
       if (isCollapsed) {
         // Set selected option offscreen/invisible according to combobox state
         nsCOMPtr<nsIAccessible> grandParentAcc;
         parentAccessible->GetParent(getter_AddRefs(grandParentAcc));
         NS_ENSURE_TRUE(grandParentAcc, NS_ERROR_FAILURE);
-        NS_ASSERTION((Role(grandParentAcc) == nsIAccessibleRole::ROLE_COMBOBOX),
+        NS_ASSERTION(nsAccUtils::Role(grandParentAcc) == nsIAccessibleRole::ROLE_COMBOBOX,
                      "grandparent of combobox listitem is not combobox");
         PRUint32 grandParentState, grandParentExtState;
         grandParentAcc->GetFinalState(&grandParentState, &grandParentExtState);
         *aState &= ~(nsIAccessibleStates::STATE_OFFSCREEN |
                      nsIAccessibleStates::STATE_INVISIBLE);
         *aState |= grandParentState & nsIAccessibleStates::STATE_OFFSCREEN |
                    grandParentState & nsIAccessibleStates::STATE_INVISIBLE;
         if (aExtraState) {
@@ -480,17 +478,17 @@ NS_IMETHODIMP nsXULMenuitemAccessible::G
   nsCOMPtr<nsIDOMXULContainerElement> xulContainer(do_QueryInterface(mDOMNode));
   if (xulContainer) {
     *aRole = nsIAccessibleRole::ROLE_PARENT_MENUITEM;
     return NS_OK;
   }
 
   nsCOMPtr<nsIAccessible> parent;
   GetParent(getter_AddRefs(parent));
-  if (parent && Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
+  if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
     *aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
     return NS_OK;
   }
 
   *aRole = nsIAccessibleRole::ROLE_MENUITEM;
   nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
   if (!element)
     return NS_ERROR_FAILURE;
@@ -705,17 +703,17 @@ NS_IMETHODIMP nsXULMenupopupAccessible::
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   if (!content) {
     return NS_ERROR_FAILURE;
   }
   nsCOMPtr<nsIAccessible> parent;
   GetParent(getter_AddRefs(parent));
   if (parent) {
     // Some widgets like the search bar have several popups, owned by buttons
-    PRUint32 role = Role(parent);
+    PRUint32 role = nsAccUtils::Role(parent);
     if (role == nsIAccessibleRole::ROLE_COMBOBOX ||
         role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
         role == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
       *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
       return NS_OK;
     }
   }
   *aRole = nsIAccessibleRole::ROLE_MENUPOPUP;
--- a/accessible/src/xul/nsXULSelectAccessible.cpp
+++ b/accessible/src/xul/nsXULSelectAccessible.cpp
@@ -878,24 +878,24 @@ nsXULListitemAccessible::GetNameInternal
 /**
   *
   */
 NS_IMETHODIMP nsXULListitemAccessible::GetRole(PRUint32 *aRole)
 {
   nsCOMPtr<nsIAccessible> listAcc = GetListAccessible();
   NS_ENSURE_STATE(listAcc);
 
-  if (Role(listAcc) == nsIAccessibleRole::ROLE_TABLE) {
+  if (nsAccUtils::Role(listAcc) == nsIAccessibleRole::ROLE_TABLE) {
     *aRole = nsIAccessibleRole::ROLE_ROW;
     return NS_OK;
   }
 
   if (mIsCheckbox)
     *aRole = nsIAccessibleRole::ROLE_CHECKBUTTON;
-  else if (mParent && Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
+  else if (nsAccUtils::Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
     *aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
   else
     *aRole = nsIAccessibleRole::ROLE_RICH_OPTION;
   return NS_OK;
 }
 
 /**
   *
--- a/accessible/src/xul/nsXULTabAccessible.cpp
+++ b/accessible/src/xul/nsXULTabAccessible.cpp
@@ -176,43 +176,43 @@ nsXULTabAccessible::GetAccessibleRelated
     }
   }
 
   // If there is no 'linkedPanel' attribute on xul:tab element then we
   // assume tab and tabpanels are related 1 to 1. We follow algorithm from
   // the setter 'selectedIndex' of tabbox.xml#tabs binding.
 
   nsCOMPtr<nsIAccessible> tabsAcc = GetParent();
-  NS_ENSURE_TRUE(tabsAcc && Role(tabsAcc) == nsIAccessibleRole::ROLE_PAGETABLIST,
+  NS_ENSURE_TRUE(nsAccUtils::Role(tabsAcc) == nsIAccessibleRole::ROLE_PAGETABLIST,
                  NS_ERROR_FAILURE);
 
   PRInt32 tabIndex = -1;
 
   nsCOMPtr<nsIAccessible> childAcc;
   tabsAcc->GetFirstChild(getter_AddRefs(childAcc));
   while (childAcc) {
-    if (Role(childAcc) == nsIAccessibleRole::ROLE_PAGETAB)
+    if (nsAccUtils::Role(childAcc) == nsIAccessibleRole::ROLE_PAGETAB)
       tabIndex++;
 
     if (childAcc == this)
       break;
 
     nsCOMPtr<nsIAccessible> acc;
     childAcc->GetNextSibling(getter_AddRefs(acc));
     childAcc.swap(acc);
   }
 
   nsCOMPtr<nsIAccessible> tabBoxAcc;
   tabsAcc->GetParent(getter_AddRefs(tabBoxAcc));
-  NS_ENSURE_TRUE(tabBoxAcc && Role(tabBoxAcc) == nsIAccessibleRole::ROLE_PANE,
+  NS_ENSURE_TRUE(nsAccUtils::Role(tabBoxAcc) == nsIAccessibleRole::ROLE_PANE,
                  NS_ERROR_FAILURE);
 
   tabBoxAcc->GetFirstChild(getter_AddRefs(childAcc));
   while (childAcc) {
-    if (Role(childAcc) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
+    if (nsAccUtils::Role(childAcc) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
       if (tabIndex == 0) {
         NS_ADDREF(*aRelatedAccessible = childAcc);
         return NS_OK;
       }
 
       tabIndex--;
     }
 
@@ -337,31 +337,31 @@ nsXULTabpanelAccessible::GetAccessibleRe
 
   if (*aRelatedAccessible ||
       aRelationType != nsIAccessibleRelation::RELATION_LABELLED_BY)
     return NS_OK;
 
   // Expose 'LABELLED_BY' relation on tabpanel accessible for tab accessible.
   nsCOMPtr<nsIAccessible> tabBoxAcc;
   GetParent(getter_AddRefs(tabBoxAcc));
-  NS_ENSURE_TRUE(tabBoxAcc && Role(tabBoxAcc) == nsIAccessibleRole::ROLE_PANE,
+  NS_ENSURE_TRUE(nsAccUtils::Role(tabBoxAcc) == nsIAccessibleRole::ROLE_PANE,
                  NS_ERROR_FAILURE);
 
   PRInt32 tabpanelIndex = -1;
   nsCOMPtr<nsIAccessible> tabsAcc;
 
   PRBool isTabpanelFound = PR_FALSE;
   nsCOMPtr<nsIAccessible> childAcc;
   tabBoxAcc->GetFirstChild(getter_AddRefs(childAcc));
   while (childAcc && (!tabsAcc || !isTabpanelFound)) {
-    if (Role(childAcc) == nsIAccessibleRole::ROLE_PAGETABLIST)
+    if (nsAccUtils::Role(childAcc) == nsIAccessibleRole::ROLE_PAGETABLIST)
       tabsAcc = childAcc;
 
     if (!isTabpanelFound &&
-        Role(childAcc) == nsIAccessibleRole::ROLE_PROPERTYPAGE)
+        nsAccUtils::Role(childAcc) == nsIAccessibleRole::ROLE_PROPERTYPAGE)
       tabpanelIndex++;
 
     if (childAcc == this)
       isTabpanelFound = PR_TRUE;
 
     nsCOMPtr<nsIAccessible> acc;
     childAcc->GetNextSibling(getter_AddRefs(acc));
     childAcc.swap(acc);
@@ -371,17 +371,17 @@ nsXULTabpanelAccessible::GetAccessibleRe
     return NS_OK;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   nsIAtom *atomID = content->GetID();
 
   nsCOMPtr<nsIAccessible> foundTabAcc;
   tabsAcc->GetFirstChild(getter_AddRefs(childAcc));
   while (childAcc) {
-    if (Role(childAcc) == nsIAccessibleRole::ROLE_PAGETAB) {
+    if (nsAccUtils::Role(childAcc) == nsIAccessibleRole::ROLE_PAGETAB) {
       if (atomID) {
         nsCOMPtr<nsIAccessNode> tabAccNode(do_QueryInterface(childAcc));
         nsCOMPtr<nsIDOMNode> tabNode;
         tabAccNode->GetDOMNode(getter_AddRefs(tabNode));
         nsCOMPtr<nsIContent> tabContent(do_QueryInterface(tabNode));
         NS_ENSURE_TRUE(tabContent, NS_ERROR_FAILURE);
 
         if (tabContent->AttrValueIs(kNameSpaceID_None,
--- a/accessible/src/xul/nsXULTextAccessible.cpp
+++ b/accessible/src/xul/nsXULTextAccessible.cpp
@@ -85,29 +85,28 @@ nsXULTextAccessible::GetAccessibleRelate
 {
   nsresult rv =
     nsHyperTextAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
   NS_ENSURE_SUCCESS(rv, rv);
   if (*aRelated) {
     return NS_OK;
   }
 
-  nsIContent *content = GetRoleContent(mDOMNode);
+  nsIContent *content = nsCoreUtils::GetRoleContent(mDOMNode);
   if (!content)
     return NS_ERROR_FAILURE;
 
   if (aRelationType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
     // Caption is the label for groupbox
     nsIContent *parent = content->GetParent();
     if (parent && parent->Tag() == nsAccessibilityAtoms::caption) {
       nsCOMPtr<nsIAccessible> parentAccessible;
       GetParent(getter_AddRefs(parentAccessible));
-      if (Role(parentAccessible) == nsIAccessibleRole::ROLE_GROUPING) {
+      if (nsAccUtils::Role(parentAccessible) == nsIAccessibleRole::ROLE_GROUPING)
         parentAccessible.swap(*aRelated);
-      }
     }
   }
 
   return NS_OK;
 }
 
 /**
   * For XUL tooltip