Merge m-c into s-c
authorGregory Szorc <gps@mozilla.com>
Mon, 11 Jun 2012 17:48:04 +0200
changeset 96565 25696b79f0cc0a38476ae2511ce9b37d7fed8419
parent 96564 a20a6e06991442f2e5aadd2fa2225cb584e061dc (current diff)
parent 96338 e3cf457bd8d8c29d7210b6da2cca94c98e4e76f0 (diff)
child 96566 4f7437c3c663ef8dc785134a8fe2a403babcec0a
push id22914
push usergszorc@mozilla.com
push dateWed, 13 Jun 2012 15:37:56 +0000
treeherdermozilla-central@a42d6b7ef3fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-c into s-c
accessible/src/atk/nsHTMLTableAccessibleWrap.h
accessible/src/atk/nsXULListboxAccessibleWrap.h
accessible/src/atk/nsXULMenuAccessibleWrap.h
accessible/src/atk/nsXULTreeGridAccessibleWrap.h
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.h
accessible/src/mac/nsHTMLTableAccessibleWrap.h
accessible/src/mac/nsXULListboxAccessibleWrap.h
accessible/src/mac/nsXULMenuAccessibleWrap.h
accessible/src/mac/nsXULTreeGridAccessibleWrap.h
accessible/src/msaa/nsHTMLTableAccessibleWrap.cpp
accessible/src/msaa/nsHTMLTableAccessibleWrap.h
accessible/src/msaa/nsXULListboxAccessibleWrap.cpp
accessible/src/msaa/nsXULListboxAccessibleWrap.h
accessible/src/msaa/nsXULMenuAccessibleWrap.cpp
accessible/src/msaa/nsXULMenuAccessibleWrap.h
accessible/src/msaa/nsXULTreeGridAccessibleWrap.cpp
accessible/src/msaa/nsXULTreeGridAccessibleWrap.h
accessible/src/other/nsHTMLTableAccessibleWrap.h
accessible/src/other/nsXULListboxAccessibleWrap.h
accessible/src/other/nsXULMenuAccessibleWrap.h
accessible/src/other/nsXULTreeGridAccessibleWrap.h
accessible/src/xul/nsXULAlertAccessible.cpp
accessible/src/xul/nsXULAlertAccessible.h
accessible/src/xul/nsXULColorPickerAccessible.cpp
accessible/src/xul/nsXULColorPickerAccessible.h
accessible/src/xul/nsXULComboboxAccessible.cpp
accessible/src/xul/nsXULComboboxAccessible.h
accessible/src/xul/nsXULListboxAccessible.cpp
accessible/src/xul/nsXULListboxAccessible.h
accessible/src/xul/nsXULMenuAccessible.cpp
accessible/src/xul/nsXULMenuAccessible.h
accessible/src/xul/nsXULSliderAccessible.cpp
accessible/src/xul/nsXULSliderAccessible.h
accessible/src/xul/nsXULTabAccessible.cpp
accessible/src/xul/nsXULTabAccessible.h
accessible/src/xul/nsXULTextAccessible.cpp
accessible/src/xul/nsXULTextAccessible.h
accessible/src/xul/nsXULTreeAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.h
accessible/src/xul/nsXULTreeGridAccessible.cpp
accessible/src/xul/nsXULTreeGridAccessible.h
config/expandlibs_deps.py
content/events/public/nsIPrivateDOMEvent.h
content/html/content/test/test_bug657938.html
content/html/content/test/test_bug660238.html
dom/base/BrowserElementChild.js
dom/base/BrowserElementParent.js
dom/base/BrowserElementParent.manifest
dom/tests/mochitest/browser-frame/Makefile.in
dom/tests/mochitest/browser-frame/browserFrameHelpers.js
dom/tests/mochitest/browser-frame/file_empty.html
dom/tests/mochitest/browser-frame/file_focus.html
dom/tests/mochitest/browser-frame/test_browserFrame1.html
dom/tests/mochitest/browser-frame/test_browserFrame10.html
dom/tests/mochitest/browser-frame/test_browserFrame2.html
dom/tests/mochitest/browser-frame/test_browserFrame3.html
dom/tests/mochitest/browser-frame/test_browserFrame4.html
dom/tests/mochitest/browser-frame/test_browserFrame5.html
dom/tests/mochitest/browser-frame/test_browserFrame6.html
dom/tests/mochitest/browser-frame/test_browserFrame7.html
dom/tests/mochitest/browser-frame/test_browserFrame8.html
dom/tests/mochitest/browser-frame/test_browserFrame9.html
dom/tests/mochitest/browser-frame/test_browserFrame_keyEvents.html
embedding/browser/webBrowser/nsIEmbeddingSiteWindow2.idl
js/src/config/expandlibs_deps.py
js/src/jit-test/tests/arguments/e4x-descendants-with-arguments.js
js/src/jit-test/tests/basic/bug557168-1.js
js/src/jit-test/tests/basic/bug557168-2.js
js/src/jit-test/tests/basic/bug557168-3.js
js/src/jit-test/tests/basic/bug557168.js
js/src/jit-test/tests/basic/bug569843.js
js/src/jit-test/tests/basic/bug574280.js
js/src/jit-test/tests/basic/bug596502-version.js
js/src/jit-test/tests/basic/bug605200.js
js/src/jit-test/tests/basic/bug613151.js
js/src/jit-test/tests/basic/bug632206.js
js/src/jit-test/tests/basic/bug651966.js
js/src/jit-test/tests/basic/bug665812.js
js/src/jit-test/tests/basic/bug672153.js
js/src/jit-test/tests/basic/bug700799.js
js/src/jit-test/tests/basic/bug716713.js
js/src/jit-test/tests/basic/bug731724.js
js/src/jit-test/tests/basic/bug731745.js
js/src/jit-test/tests/basic/bug737251.js
js/src/jit-test/tests/basic/bug753885-1.js
js/src/jit-test/tests/basic/bug753885-2.js
js/src/jit-test/tests/basic/testXMLPropertyNames.js
layout/generic/nsTypedSelection.h
layout/mathml/mathfontCMEX10.properties
layout/mathml/mathfontCMSY10.properties
layout/mathml/mathfontMTExtra.properties
layout/mathml/mathfontMath1.properties
layout/mathml/mathfontMath2.properties
layout/mathml/mathfontMath4.properties
layout/mathml/mathfontPUA.properties
layout/mathml/tests/maxwell.xml
layout/mathml/tests/mixing.xml
layout/mathml/tests/simple.xml
layout/mathml/tests/stretchy.xml
layout/mathml/tests/symbol.html
mobile/android/base/GeckoActionBar.java
mobile/android/base/resources/drawable-hdpi/address_bar_pressed_texture_port.png
mobile/android/base/resources/drawable-hdpi/tab_selected.png
mobile/android/base/resources/drawable-hdpi/tabs_more.png
mobile/android/base/resources/drawable-hdpi/tabs_plus.png
mobile/android/base/resources/drawable-land-hdpi-v14/address_bar_pressed_texture_land.png
mobile/android/base/resources/drawable-land-hdpi-v14/tabs_more.png
mobile/android/base/resources/drawable-land-hdpi-v14/tabs_plus.png
mobile/android/base/resources/drawable-land-mdpi-v14/address_bar_pressed_texture_land.png
mobile/android/base/resources/drawable-land-mdpi-v14/tabs_more.png
mobile/android/base/resources/drawable-land-mdpi-v14/tabs_plus.png
mobile/android/base/resources/drawable-land-v14/address_bar_pressed_bg.xml
mobile/android/base/resources/drawable-land-xhdpi-v14/address_bar_pressed_texture_land.png
mobile/android/base/resources/drawable-land-xhdpi-v14/tabs_more.png
mobile/android/base/resources/drawable-land-xhdpi-v14/tabs_plus.png
mobile/android/base/resources/drawable-nodpi/tabs_tray_pressed_bg.png
mobile/android/base/resources/drawable-sw600dp-hdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-sw600dp-hdpi/tabs_more.png
mobile/android/base/resources/drawable-sw600dp-hdpi/tabs_plus.png
mobile/android/base/resources/drawable-sw600dp-mdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-sw600dp-mdpi/tabs_more.png
mobile/android/base/resources/drawable-sw600dp-mdpi/tabs_plus.png
mobile/android/base/resources/drawable-sw600dp-xhdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-sw600dp-xhdpi/tabs_more.png
mobile/android/base/resources/drawable-sw600dp-xhdpi/tabs_plus.png
mobile/android/base/resources/drawable-xhdpi-v11/address_bar_pressed_texture_port.png
mobile/android/base/resources/drawable-xhdpi-v11/tab_selected.png
mobile/android/base/resources/drawable-xhdpi-v11/tabs_more.png
mobile/android/base/resources/drawable-xhdpi-v11/tabs_plus.png
mobile/android/base/resources/drawable-xlarge-hdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-xlarge-hdpi/tabs_more.png
mobile/android/base/resources/drawable-xlarge-hdpi/tabs_plus.png
mobile/android/base/resources/drawable-xlarge-mdpi/address_bar_pressed_bg.xml
mobile/android/base/resources/drawable-xlarge-mdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-xlarge-mdpi/tabs_more.png
mobile/android/base/resources/drawable-xlarge-mdpi/tabs_plus.png
mobile/android/base/resources/drawable-xlarge-xhdpi/address_bar_pressed_texture_tablet.png
mobile/android/base/resources/drawable-xlarge-xhdpi/tabs_more.png
mobile/android/base/resources/drawable-xlarge-xhdpi/tabs_plus.png
mobile/android/base/resources/drawable/address_bar_pressed_bg.xml
mobile/android/base/resources/drawable/address_bar_pressed_texture_port.png
mobile/android/base/resources/drawable/remote_tabs_group_bg_repeat.xml
mobile/android/base/resources/drawable/tab_selected.png
mobile/android/base/resources/drawable/tabs_more.png
mobile/android/base/resources/drawable/tabs_plus.png
mobile/android/base/resources/drawable/tabs_tray_close_button.xml
mobile/android/base/resources/drawable/tabs_tray_list_selector.xml
mobile/android/base/resources/drawable/tabs_tray_pressed_bg_repeat.xml
mobile/android/base/resources/layout-v11/gecko_app.xml
mobile/android/base/sync/SynchronizerConfigurations.java
mobile/android/base/sync/stage/EnsureKeysStage.java
--- a/accessible/public/nsIAccessible.idl
+++ b/accessible/public/nsIAccessible.idl
@@ -18,17 +18,17 @@ interface nsIAccessibleRelation;
  * accessibility APIs like MSAA and ATK. Contains the sum of what's needed
  * to support IAccessible as well as ATK's generic accessibility objects.
  * Can also be used by in-process accessibility clients to get information
  * about objects in the accessible tree. The accessible tree is a subset of 
  * nodes in the DOM tree -- such as documents, focusable elements and text.
  * Mozilla creates the implementations of nsIAccessible on demand.
  * See http://www.mozilla.org/projects/ui/accessibility for more information.
  */
-[scriptable, uuid(45ce2c92-4d92-49d2-bff1-855934443261)]
+[scriptable, uuid(45600c50-b06a-11e1-afa6-0800200c9a66)]
 interface nsIAccessible : nsISupports
 {
   /**
    * Parent node in accessible tree.
    */
   readonly attribute nsIAccessible parent;
 
   /**
@@ -110,31 +110,23 @@ interface nsIAccessible : nsISupports
    */
   readonly attribute AString description;
 
   /**
    * Provides localized string of accesskey name, such as Alt+D.
    * The modifier may be affected by user and platform preferences.
    * Usually alt+letter, or just the letter alone for menu items. 
    */
-  readonly attribute AString keyboardShortcut;
+  readonly attribute AString accessKey;
 
   /**
    * Provides localized string of global keyboard accelerator for default
    * action, such as Ctrl+O for Open file
    */
-  readonly attribute AString defaultKeyBinding;
-
-  /**
-   * Provides array of localized string of global keyboard accelerator for
-   * the given action index supported by accessible.
-   *
-   * @param aActionIndex - index of the given action
-   */
-  nsIDOMDOMStringList getKeyBindings(in PRUint8 aActionIndex);
+  readonly attribute AString keyboardShortcut;
 
   /**
    * Enumerated accessible role (see the constants defined in nsIAccessibleRole).
    *
    * @note  The values might depend on platform because of variations. Widgets
    *        can use ARIA role attribute to force the final role.
    */
   readonly attribute unsigned long role;
new file mode 100644
--- /dev/null
+++ b/accessible/src/atk/HTMLTableAccessibleWrap.h
@@ -0,0 +1,23 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HTMLTableAccessibleWrap_h__
+#define mozilla_a11y_HTMLTableAccessibleWrap_h__
+
+#include "HTMLTableAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class HTMLTableAccessible HTMLTableAccessibleWrap;
+typedef class HTMLTableCellAccessible HTMLTableCellAccessibleWrap;
+typedef class HTMLTableHeaderCellAccessible HTMLTableHeaderCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+
new file mode 100644
--- /dev/null
+++ b/accessible/src/atk/XULListboxAccessibleWrap.h
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULListboxAccessibleWrap_h__
+#define mozilla_a11y_XULListboxAccessibleWrap_h__
+
+#include "XULListboxAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULListboxAccessible XULListboxAccessibleWrap;
+typedef class XULListCellAccessible XULListCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/atk/XULMenuAccessibleWrap.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULMenuAccessibleWrap_h__
+#define mozilla_a11y_XULMenuAccessibleWrap_h__
+
+#include "XULMenuAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULMenuitemAccessible XULMenuitemAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/atk/XULTreeGridAccessibleWrap.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULTreeGridAccessibleWrap_h__
+#define mozilla_a11y_XULTreeGridAccessibleWrap_h__
+
+#include "XULTreeGridAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULTreeGridAccessible XULTreeGridAccessibleWrap;
+typedef class XULTreeGridCellAccessible XULTreeGridCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+
deleted file mode 100644
--- a/accessible/src/atk/nsHTMLTableAccessibleWrap.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _NSHTMLTABLEACCESSIBLEWRAP_H
-#define _NSHTMLTABLEACCESSIBLEWRAP_H
-
-#include "nsHTMLTableAccessible.h"
-
-typedef class nsHTMLTableAccessible nsHTMLTableAccessibleWrap;
-typedef class nsHTMLTableCellAccessible nsHTMLTableCellAccessibleWrap;
-typedef class nsHTMLTableHeaderCellAccessible nsHTMLTableHeaderCellAccessibleWrap;
-
-#endif
-
deleted file mode 100644
--- a/accessible/src/atk/nsXULListboxAccessibleWrap.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULListboxAccessibleWrap_h__
-#define __nsXULListboxAccessibleWrap_h__
-
-#include "nsXULListboxAccessible.h"
-
-typedef class nsXULListboxAccessible nsXULListboxAccessibleWrap;
-typedef class nsXULListCellAccessible nsXULListCellAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/atk/nsXULMenuAccessibleWrap.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULMenuAccessibleWrap_h__
-#define __nsXULMenuAccessibleWrap_h__
-
-#include "nsXULMenuAccessible.h"
-
-typedef class nsXULMenuitemAccessible nsXULMenuitemAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/atk/nsXULTreeGridAccessibleWrap.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULTreeGridAccessibleWrap_h__
-#define __nsXULTreeGridAccessibleWrap_h__
-
-#include "nsXULTreeGridAccessible.h"
-
-typedef class nsXULTreeGridAccessible nsXULTreeGridAccessibleWrap;
-typedef class nsXULTreeGridCellAccessible nsXULTreeGridCellAccessibleWrap;
-
-#endif
-
--- a/accessible/src/base/TextAttrs.cpp
+++ b/accessible/src/base/TextAttrs.cpp
@@ -96,31 +96,35 @@ TextAttrsMgr::GetAttributes(nsIPersisten
   FontSizeTextAttr fontSizeTextAttr(rootFrame, frame);
 
   // "font-style" text attribute
   FontStyleTextAttr fontStyleTextAttr(rootFrame, frame);
 
   // "font-weight" text attribute
   FontWeightTextAttr fontWeightTextAttr(rootFrame, frame);
 
+  // "auto-generated" text attribute
+  AutoGeneratedTextAttr autoGenTextAttr(mHyperTextAcc, mOffsetAcc);
+
   // "text-underline(line-through)-style(color)" text attributes
   TextDecorTextAttr textDecorTextAttr(rootFrame, frame);
 
   // "text-position" text attribute
   TextPosTextAttr textPosTextAttr(rootFrame, frame);
 
   TextAttr* attrArray[] =
   {
     &langTextAttr,
     &bgColorTextAttr,
     &colorTextAttr,
     &fontFamilyTextAttr,
     &fontSizeTextAttr,
     &fontStyleTextAttr,
     &fontWeightTextAttr,
+    &autoGenTextAttr,
     &textDecorTextAttr,
     &textPosTextAttr
   };
 
   // Expose text attributes if applicable.
   if (aAttributes) {
     for (PRUint32 idx = 0; idx < ArrayLength(attrArray); idx++)
       attrArray[idx]->Expose(aAttributes, mIncludeDefAttrs);
@@ -139,24 +143,20 @@ TextAttrsMgr::GetRange(TextAttr* aAttrAr
   for (PRInt32 childIdx = mOffsetAccIdx - 1; childIdx >= 0; childIdx--) {
     Accessible* currAcc = mHyperTextAcc->GetChildAt(childIdx);
 
     // Stop on embedded accessible since embedded accessibles are combined into
     // own range.
     if (nsAccUtils::IsEmbeddedObject(currAcc))
       break;
 
-    nsIContent* currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
-    if (!currElm)
-      return;
-
     bool offsetFound = false;
     for (PRUint32 attrIdx = 0; attrIdx < aAttrArrayLen; attrIdx++) {
       TextAttr* textAttr = aAttrArray[attrIdx];
-      if (!textAttr->Equal(currElm)) {
+      if (!textAttr->Equal(currAcc)) {
         offsetFound = true;
         break;
       }
     }
 
     if (offsetFound)
       break;
 
@@ -165,27 +165,23 @@ TextAttrsMgr::GetRange(TextAttr* aAttrAr
 
   // Navigate forward from anchor accessible to find end offset.
   PRUint32 childLen = mHyperTextAcc->ChildCount();
   for (PRUint32 childIdx = mOffsetAccIdx + 1; childIdx < childLen; childIdx++) {
     Accessible* currAcc = mHyperTextAcc->GetChildAt(childIdx);
     if (nsAccUtils::IsEmbeddedObject(currAcc))
       break;
 
-    nsIContent* currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
-    if (!currElm)
-      return;
-
     bool offsetFound = false;
     for (PRUint32 attrIdx = 0; attrIdx < aAttrArrayLen; attrIdx++) {
       TextAttr* textAttr = aAttrArray[attrIdx];
 
       // Alter the end offset when text attribute changes its value and stop
       // the search.
-      if (!textAttr->Equal(currElm)) {
+      if (!textAttr->Equal(currAcc)) {
         offsetFound = true;
         break;
       }
     }
 
     if (offsetFound)
       break;
 
@@ -201,61 +197,57 @@ TextAttrsMgr::GetRange(TextAttr* aAttrAr
 TextAttrsMgr::LangTextAttr::
   LangTextAttr(HyperTextAccessible* aRoot,
                nsIContent* aRootElm, nsIContent* aElm) :
   TTextAttr<nsString>(!aElm), mRootContent(aRootElm)
 {
   aRoot->Language(mRootNativeValue);
   mIsRootDefined =  !mRootNativeValue.IsEmpty();
 
-  if (aElm)
-    mIsDefined = GetLang(aElm, mNativeValue);
+  if (aElm) {
+    nsCoreUtils::GetLanguageFor(aElm, mRootContent, mNativeValue);
+    mIsDefined = !mNativeValue.IsEmpty();
+  }
 }
 
 bool
 TextAttrsMgr::LangTextAttr::
-  GetValueFor(nsIContent* aElm, nsString* aValue)
+  GetValueFor(Accessible* aAccessible, nsString* aValue)
 {
-  return GetLang(aElm, *aValue);
+  nsCoreUtils::GetLanguageFor(aAccessible->GetContent(), mRootContent, *aValue);
+  return !aValue->IsEmpty();
 }
 
 void
 TextAttrsMgr::LangTextAttr::
   ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
 {
   nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::language, aValue);
 }
 
-bool
-TextAttrsMgr::LangTextAttr::
-  GetLang(nsIContent* aElm, nsAString& aLang)
-{
-  nsCoreUtils::GetLanguageFor(aElm, mRootContent, aLang);
-  return !aLang.IsEmpty();
-}
-
 
 ////////////////////////////////////////////////////////////////////////////////
 // BGColorTextAttr
 ////////////////////////////////////////////////////////////////////////////////
 
 TextAttrsMgr::BGColorTextAttr::
   BGColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
   TTextAttr<nscolor>(!aFrame), mRootFrame(aRootFrame)
 {
   mIsRootDefined = GetColor(mRootFrame, &mRootNativeValue);
   if (aFrame)
     mIsDefined = GetColor(aFrame, &mNativeValue);
 }
 
 bool
 TextAttrsMgr::BGColorTextAttr::
-  GetValueFor(nsIContent* aElm, nscolor* aValue)
+  GetValueFor(Accessible* aAccessible, nscolor* aValue)
 {
-  nsIFrame* frame = aElm->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   return frame ? GetColor(frame, aValue) : false;
 }
 
 void
 TextAttrsMgr::BGColorTextAttr::
   ExposeValue(nsIPersistentProperties* aAttributes, const nscolor& aValue)
 {
   nsAutoString formattedValue;
@@ -305,19 +297,20 @@ TextAttrsMgr::ColorTextAttr::
   if (aFrame) {
     mNativeValue = aFrame->GetStyleColor()->mColor;
     mIsDefined = true;
   }
 }
 
 bool
 TextAttrsMgr::ColorTextAttr::
-  GetValueFor(nsIContent* aElm, nscolor* aValue)
+  GetValueFor(Accessible* aAccessible, nscolor* aValue)
 {
-  nsIFrame* frame = aElm->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   if (frame) {
     *aValue = frame->GetStyleColor()->mColor;
     return true;
   }
 
   return false;
 }
 
@@ -342,19 +335,20 @@ TextAttrsMgr::FontFamilyTextAttr::
   mIsRootDefined = GetFontFamily(aRootFrame, mRootNativeValue);
 
   if (aFrame)
     mIsDefined = GetFontFamily(aFrame, mNativeValue);
 }
 
 bool
 TextAttrsMgr::FontFamilyTextAttr::
-  GetValueFor(nsIContent* aElm, nsString* aValue)
+  GetValueFor(Accessible* aAccessible, nsString* aValue)
 {
-  nsIFrame* frame = aElm->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   return frame ? GetFontFamily(frame, *aValue) : false;
 }
 
 void
 TextAttrsMgr::FontFamilyTextAttr::
   ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
 {
   nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::font_family, aValue);
@@ -391,19 +385,20 @@ TextAttrsMgr::FontSizeTextAttr::
   if (aFrame) {
     mNativeValue = aFrame->GetStyleFont()->mSize;
     mIsDefined = true;
   }
 }
 
 bool
 TextAttrsMgr::FontSizeTextAttr::
-  GetValueFor(nsIContent* aElm, nscoord* aValue)
+  GetValueFor(Accessible* aAccessible, nscoord* aValue)
 {
-  nsIFrame* frame = aElm->GetPrimaryFrame();
+  nsIContent* content = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = content->GetPrimaryFrame();
   if (frame) {
     *aValue = frame->GetStyleFont()->mSize;
     return true;
   }
 
   return false;
 }
 
@@ -446,19 +441,20 @@ TextAttrsMgr::FontStyleTextAttr::
   if (aFrame) {
     mNativeValue = aFrame->GetStyleFont()->mFont.style;
     mIsDefined = true;
   }
 }
 
 bool
 TextAttrsMgr::FontStyleTextAttr::
-  GetValueFor(nsIContent* aContent, nscoord* aValue)
+  GetValueFor(Accessible* aAccessible, nscoord* aValue)
 {
-  nsIFrame* frame = aContent->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   if (frame) {
     *aValue = frame->GetStyleFont()->mFont.style;
     return true;
   }
 
   return false;
 }
 
@@ -487,19 +483,20 @@ TextAttrsMgr::FontWeightTextAttr::
   if (aFrame) {
     mNativeValue = GetFontWeight(aFrame);
     mIsDefined = true;
   }
 }
 
 bool
 TextAttrsMgr::FontWeightTextAttr::
-  GetValueFor(nsIContent* aElm, PRInt32* aValue)
+  GetValueFor(Accessible* aAccessible, PRInt32* aValue)
 {
-  nsIFrame* frame = aElm->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   if (frame) {
     *aValue = GetFontWeight(frame);
     return true;
   }
 
   return false;
 }
 
@@ -545,16 +542,46 @@ TextAttrsMgr::FontWeightTextAttr::
   // On Mac, font->GetStyle()->weight will just give the same number as
   // getComputedStyle(). fontEntry->Weight() will give the weight of the font
   // face used.
   gfxFontEntry *fontEntry = font->GetFontEntry();
   return fontEntry->Weight();
 #endif
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// AutoGeneratedTextAttr
+////////////////////////////////////////////////////////////////////////////////
+TextAttrsMgr::AutoGeneratedTextAttr::
+  AutoGeneratedTextAttr(HyperTextAccessible* aHyperTextAcc,
+                        Accessible* aAccessible) :
+  TTextAttr<bool>(!aAccessible)
+{
+  mRootNativeValue = false;
+  mIsRootDefined = false;
+
+  if (aAccessible)
+    mIsDefined = mNativeValue = (aAccessible->NativeRole() == roles::STATICTEXT);
+}
+
+bool
+TextAttrsMgr::AutoGeneratedTextAttr::
+  GetValueFor(Accessible* aAccessible, bool* aValue)
+{
+  return *aValue = (aAccessible->NativeRole() == roles::STATICTEXT);
+}
+
+void
+TextAttrsMgr::AutoGeneratedTextAttr::
+  ExposeValue(nsIPersistentProperties* aAttributes, const bool& aValue)
+{
+  nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::auto_generated,
+                         aValue ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"));
+}
+
 
 ////////////////////////////////////////////////////////////////////////////////
 // TextDecorTextAttr
 ////////////////////////////////////////////////////////////////////////////////
 
 TextAttrsMgr::TextDecorValue::
   TextDecorValue(nsIFrame* aFrame)
 {
@@ -581,19 +608,20 @@ TextAttrsMgr::TextDecorTextAttr::
   if (aFrame) {
     mNativeValue = TextDecorValue(aFrame);
     mIsDefined = mNativeValue.IsDefined();
   }
 }
 
 bool
 TextAttrsMgr::TextDecorTextAttr::
-  GetValueFor(nsIContent* aContent, TextDecorValue* aValue)
+  GetValueFor(Accessible* aAccessible, TextDecorValue* aValue)
 {
-  nsIFrame* frame = aContent->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   if (frame) {
     *aValue = TextDecorValue(frame);
     return aValue->IsDefined();
   }
 
   return false;
 }
 
@@ -643,19 +671,20 @@ TextAttrsMgr::TextPosTextAttr::
   if (aFrame) {
     mNativeValue = GetTextPosValue(aFrame);
     mIsDefined = mNativeValue != eTextPosNone;
   }
 }
 
 bool
 TextAttrsMgr::TextPosTextAttr::
-  GetValueFor(nsIContent* aContent, TextPosValue* aValue)
+  GetValueFor(Accessible* aAccessible, TextPosValue* aValue)
 {
-  nsIFrame* frame = aContent->GetPrimaryFrame();
+  nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
+  nsIFrame* frame = elm->GetPrimaryFrame();
   if (frame) {
     *aValue = GetTextPosValue(frame);
     return *aValue != eTextPosNone;
   }
 
   return false;
 }
 
--- a/accessible/src/base/TextAttrs.h
+++ b/accessible/src/base/TextAttrs.h
@@ -105,17 +105,17 @@ protected:
      */
     virtual void Expose(nsIPersistentProperties* aAttributes,
                         bool aIncludeDefAttrValue) = 0;
 
     /**
      * Return true if the text attribute value on the given element equals with
      * predefined attribute value.
      */
-    virtual bool Equal(nsIContent* aElm) = 0;
+    virtual bool Equal(Accessible* aAccessible) = 0;
   };
 
 
   /**
    * Base class to work with text attributes. See derived classes below.
    */
   template<class T>
   class TTextAttr : public TextAttr
@@ -138,20 +138,20 @@ protected:
           ExposeValue(aAttributes, mNativeValue);
         return;
       }
 
       if (aIncludeDefAttrValue && mIsRootDefined)
         ExposeValue(aAttributes, mRootNativeValue);
     }
 
-    virtual bool Equal(nsIContent* aElm)
+    virtual bool Equal(Accessible* aAccessible)
     {
       T nativeValue;
-      bool isDefined = GetValueFor(aElm, &nativeValue);
+      bool isDefined = GetValueFor(aAccessible, &nativeValue);
 
       if (!mIsDefined && !isDefined)
         return true;
 
       if (mIsDefined && isDefined)
         return nativeValue == mNativeValue;
 
       if (mIsDefined)
@@ -162,17 +162,17 @@ protected:
 
   protected:
 
     // Expose the text attribute with the given value to attribute set.
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const T& aValue) = 0;
 
     // Return native value for the given DOM element.
-    virtual bool GetValueFor(nsIContent* aElm, T* aValue) = 0;
+    virtual bool GetValueFor(Accessible* aAccessible, T* aValue) = 0;
 
     // Indicates if root value should be exposed.
     bool mGetRootValue;
 
     // Native value and flag indicating if the value is defined (initialized in
     // derived classes). Note, undefined native value means it is inherited
     // from root.
     T mNativeValue;
@@ -193,39 +193,38 @@ protected:
   public:
     LangTextAttr(HyperTextAccessible* aRoot, nsIContent* aRootElm,
                  nsIContent* aElm);
     virtual ~LangTextAttr() { }
 
   protected:
 
     // TextAttr
-    virtual bool GetValueFor(nsIContent* aElm, nsString* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, nsString* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nsString& aValue);
 
   private:
-    bool GetLang(nsIContent* aElm, nsAString& aLang);
     nsCOMPtr<nsIContent> mRootContent;
   };
 
 
   /**
    * Class is used for the work with 'background-color' text attribute.
    */
   class BGColorTextAttr : public TTextAttr<nscolor>
   {
   public:
     BGColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~BGColorTextAttr() { }
 
   protected:
 
     // TextAttr
-    virtual bool GetValueFor(nsIContent* aElm, nscolor* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, nscolor* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nscolor& aValue);
 
   private:
     bool GetColor(nsIFrame* aFrame, nscolor* aColor);
     nsIFrame* mRootFrame;
   };
 
@@ -237,17 +236,17 @@ protected:
   {
   public:
     ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~ColorTextAttr() { }
 
   protected:
 
     // TTextAttr
-    virtual bool GetValueFor(nsIContent* aElm, nscolor* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, nscolor* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nscolor& aValue);
   };
 
 
   /**
    * Class is used for the work with "font-family" text attribute.
    */
@@ -255,17 +254,17 @@ protected:
   {
   public:
     FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~FontFamilyTextAttr() { }
 
   protected:
 
     // TTextAttr
-    virtual bool GetValueFor(nsIContent* aElm, nsString* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, nsString* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nsString& aValue);
 
   private:
 
     bool GetFontFamily(nsIFrame* aFrame, nsString& aFamily);
   };
 
@@ -274,20 +273,20 @@ protected:
    * Class is used for the work with "font-size" text attribute.
    */
   class FontSizeTextAttr : public TTextAttr<nscoord>
   {
   public:
     FontSizeTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~FontSizeTextAttr() { }
 
-  protected:
+  protected: 
 
     // TTextAttr
-    virtual bool GetValueFor(nsIContent* aElm, nscoord* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, nscoord* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nscoord& aValue);
 
   private:
     nsDeviceContext* mDC;
   };
 
 
@@ -298,17 +297,17 @@ protected:
   {
   public:
     FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~FontStyleTextAttr() { }
 
   protected:
 
     // TTextAttr
-    virtual bool GetValueFor(nsIContent* aContent, nscoord* aValue);
+    virtual bool GetValueFor(Accessible* aContent, nscoord* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const nscoord& aValue);
   };
 
 
   /**
    * Class is used for the work with "font-weight" text attribute.
    */
@@ -316,24 +315,41 @@ protected:
   {
   public:
     FontWeightTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~FontWeightTextAttr() { }
 
   protected:
 
     // TTextAttr
-    virtual bool GetValueFor(nsIContent* aElm, PRInt32* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, PRInt32* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const PRInt32& aValue);
 
   private:
     PRInt32 GetFontWeight(nsIFrame* aFrame);
   };
 
+  /**
+   * Class is used for the work with 'auto-generated' text attribute.
+   */
+  class AutoGeneratedTextAttr : public TTextAttr<bool>
+  {
+  public:
+    AutoGeneratedTextAttr(HyperTextAccessible* aHyperTextAcc,
+                          Accessible* aAccessible);
+    virtual ~AutoGeneratedTextAttr() { }
+
+  protected:
+    // TextAttr
+    virtual bool GetValueFor(Accessible* aAccessible, bool* aValue);
+    virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+                             const bool& aValue);
+  };
+
 
   /**
    * TextDecorTextAttr class is used for the work with
    * "text-line-through-style", "text-line-through-color",
    * "text-underline-style" and "text-underline-color" text attributes.
    */
 
   class TextDecorValue
@@ -370,17 +386,17 @@ protected:
   {
   public:
     TextDecorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~TextDecorTextAttr() { }
 
   protected:
 
     // TextAttr
-    virtual bool GetValueFor(nsIContent* aElm, TextDecorValue* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, TextDecorValue* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const TextDecorValue& aValue);
   };
 
   /**
    * Class is used for the work with "text-position" text attribute.
    */
 
@@ -395,17 +411,17 @@ protected:
   {
   public:
     TextPosTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
     virtual ~TextPosTextAttr() { }
 
   protected:
 
     // TextAttr
-    virtual bool GetValueFor(nsIContent* aElm, TextPosValue* aValue);
+    virtual bool GetValueFor(Accessible* aAccessible, TextPosValue* aValue);
     virtual void ExposeValue(nsIPersistentProperties* aAttributes,
                              const TextPosValue& aValue);
 
   private:
     TextPosValue GetTextPosValue(nsIFrame* aFrame) const;
   };
 
 }; // TextAttrMgr
--- a/accessible/src/base/nsARIAMap.cpp
+++ b/accessible/src/base/nsARIAMap.cpp
@@ -30,550 +30,550 @@ using namespace mozilla::a11y::aria;
  *  In addition, in MSAA, the unmapped role will also be exposed as a BSTR string role.
  *
  *  There are no nsIAccessibleRole enums for the following landmark roles:
  *    banner, contentinfo, main, navigation, note, search, secondary, seealso, breadcrumbs
  */
 
 static nsRoleMapEntry sWAIRoleMaps[] =
 {
-  {
-    "alert",
+  { // alert
+    &nsGkAtoms::alert,
     roles::ALERT,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "alertdialog",
+  { // alertdialog
+    &nsGkAtoms::alertdialog,
     roles::DIALOG,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "application",
+  { // application
+    &nsGkAtoms::application,
     roles::APPLICATION,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "article",
+  { // article
+    &nsGkAtoms::article,
     roles::DOCUMENT,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eReadonlyUntilEditable
   },
-  {
-    "button",
+  { // button
+    &nsGkAtoms::button,
     roles::PUSHBUTTON,
     kUseMapRole,
     eNoValue,
     ePressAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAPressed
   },
-  {
-    "checkbox",
+  { // checkbox
+    &nsGkAtoms::checkbox,
     roles::CHECKBUTTON,
     kUseMapRole,
     eNoValue,
     eCheckUncheckAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIACheckableMixed,
     eARIAReadonly
   },
-  {
-    "columnheader",
+  { // columnheader
+    &nsGkAtoms::columnheader,
     roles::COLUMNHEADER,
     kUseMapRole,
     eNoValue,
     eSortAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable,
     eARIAReadonly
   },
-  {
-    "combobox",
+  { // combobox
+    &nsGkAtoms::combobox,
     roles::COMBOBOX,
     kUseMapRole,
     eNoValue,
     eOpenCloseAction,
     eNoLiveAttr,
     states::COLLAPSED | states::HASPOPUP,
     eARIAAutoComplete,
     eARIAReadonly
   },
-  {
-    "dialog",
+  { // dialog
+    &nsGkAtoms::dialog,
     roles::DIALOG,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "directory",
+  { // directory
+    &nsGkAtoms::directory,
     roles::LIST,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "document",
+  { // document
+    &nsGkAtoms::document,
     roles::DOCUMENT,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eReadonlyUntilEditable
   },
-  {
-    "form",
+  { // form
+    &nsGkAtoms::form,
     roles::FORM,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "grid",
+  { // grid
+    &nsGkAtoms::grid,
     roles::TABLE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     states::FOCUSABLE,
     eARIAMultiSelectable,
     eARIAReadonly
   },
-  {
-    "gridcell",
+  { // gridcell
+    &nsGkAtoms::gridcell,
     roles::GRID_CELL,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable,
     eARIAReadonly
   },
-  {
-    "group",
+  { // group
+    &nsGkAtoms::group,
     roles::GROUPING,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "heading",
+  { // heading
+    &nsGkAtoms::heading,
     roles::HEADING,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "img",
+  { // img
+    &nsGkAtoms::img,
     roles::GRAPHIC,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "link",
+  { // link
+    &nsGkAtoms::link,
     roles::LINK,
     kUseMapRole,
     eNoValue,
     eJumpAction,
     eNoLiveAttr,
     states::LINKED
   },
-  {
-    "list",
+  { // list
+    &nsGkAtoms::list,
     roles::LIST,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     states::READONLY
   },
-  {
-    "listbox",
+  { // listbox
+    &nsGkAtoms::listbox,
     roles::LISTBOX,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAMultiSelectable,
     eARIAReadonly
   },
-  {
-    "listitem",
+  { // listitem
+    &nsGkAtoms::listitem,
     roles::LISTITEM,
     kUseMapRole,
     eNoValue,
     eNoAction, // XXX: should depend on state, parent accessible
     eNoLiveAttr,
     states::READONLY
   },
-  {
-    "log",
+  { // log
+    &nsGkAtoms::log_,
     roles::NOTHING,
     kUseNativeRole,
     eNoValue,
     eNoAction,
     ePoliteLiveAttr,
     kNoReqStates
   },
-  {
-    "marquee",
+  { // marquee
+    &nsGkAtoms::marquee,
     roles::ANIMATION,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eOffLiveAttr,
     kNoReqStates
   },
-  {
-    "math",
+  { // math
+    &nsGkAtoms::math,
     roles::FLAT_EQUATION,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "menu",
+  { // menu
+    &nsGkAtoms::menu,
     roles::MENUPOPUP,
     kUseMapRole,
     eNoValue,
     eNoAction, // XXX: technically accessibles of menupopup role haven't
                // any action, but menu can be open or close.
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "menubar",
+  { // menubar
+    &nsGkAtoms::menubar,
     roles::MENUBAR,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "menuitem",
+  { // menuitem
+    &nsGkAtoms::menuitem,
     roles::MENUITEM,
     kUseMapRole,
     eNoValue,
     eClickAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIACheckedMixed
   },
-  {
-    "menuitemcheckbox",
+  { // menuitemcheckbox
+    &nsGkAtoms::menuitemcheckbox,
     roles::CHECK_MENU_ITEM,
     kUseMapRole,
     eNoValue,
     eClickAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIACheckableMixed
   },
-  {
-    "menuitemradio",
+  { // menuitemradio
+    &nsGkAtoms::menuitemradio,
     roles::RADIO_MENU_ITEM,
     kUseMapRole,
     eNoValue,
     eClickAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIACheckableBool
   },
-  {
-    "note",
+  { // note
+    &nsGkAtoms::note_,
     roles::NOTE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "option",
+  { // option
+    &nsGkAtoms::option,
     roles::OPTION,
     kUseMapRole,
     eNoValue,
     eSelectAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable,
     eARIACheckedMixed
   },
-  {
-    "presentation",
+  { // presentation
+    &nsGkAtoms::presentation,
     roles::NOTHING,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "progressbar",
+  { // progressbar
+    &nsGkAtoms::progressbar,
     roles::PROGRESSBAR,
     kUseMapRole,
     eHasValueMinMax,
     eNoAction,
     eNoLiveAttr,
     states::READONLY,
     eIndeterminateIfNoValue
   },
-  {
-    "radio",
+  { // radio
+    &nsGkAtoms::radio,
     roles::RADIOBUTTON,
     kUseMapRole,
     eNoValue,
     eSelectAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIACheckableBool
   },
-  {
-    "radiogroup",
+  { // radiogroup
+    &nsGkAtoms::radiogroup,
     roles::GROUPING,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "region",
+  { // region
+    &nsGkAtoms::region,
     roles::PANE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "row",
+  { // row
+    &nsGkAtoms::row,
     roles::ROW,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable
   },
-  {
-    "rowheader",
+  { // rowheader
+    &nsGkAtoms::rowheader,
     roles::ROWHEADER,
     kUseMapRole,
     eNoValue,
     eSortAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable,
     eARIAReadonly
   },
-  {
-    "scrollbar",
+  { // scrollbar
+    &nsGkAtoms::scrollbar,
     roles::SCROLLBAR,
     kUseMapRole,
     eHasValueMinMax,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAOrientation,
     eARIAReadonly
   },
-  {
-    "separator",
+  { // separator
+    &nsGkAtoms::separator_,
     roles::SEPARATOR,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAOrientation
   },
-  {
-    "slider",
+  { // slider
+    &nsGkAtoms::slider,
     roles::SLIDER,
     kUseMapRole,
     eHasValueMinMax,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAOrientation,
     eARIAReadonly
   },
-  {
-    "spinbutton",
+  { // spinbutton
+    &nsGkAtoms::spinbutton,
     roles::SPINBUTTON,
     kUseMapRole,
     eHasValueMinMax,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAReadonly
   },
-  {
-    "status",
+  { // status
+    &nsGkAtoms::status,
     roles::STATUSBAR,
     kUseMapRole,
     eNoValue,
     eNoAction,
     ePoliteLiveAttr,
     kNoReqStates
   },
-  {
-    "tab",
+  { // tab
+    &nsGkAtoms::tab,
     roles::PAGETAB,
     kUseMapRole,
     eNoValue,
     eSwitchAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable
   },
-  {
-    "tablist",
+  { // tablist
+    &nsGkAtoms::tablist,
     roles::PAGETABLIST,
     kUseMapRole,
     eNoValue,
     eNoAction,
     ePoliteLiveAttr,
     kNoReqStates
   },
-  {
-    "tabpanel",
+  { // tabpanel
+    &nsGkAtoms::tabpanel,
     roles::PROPERTYPAGE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "textbox",
+  { // textbox
+    &nsGkAtoms::textbox,
     roles::ENTRY,
     kUseMapRole,
     eNoValue,
     eActivateAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAAutoComplete,
     eARIAMultiline,
     eARIAReadonlyOrEditable
   },
-  {
-    "timer",
+  { // timer
+    &nsGkAtoms::timer,
     roles::NOTHING,
     kUseNativeRole,
     eNoValue,
     eNoAction,
     eOffLiveAttr,
     kNoReqStates
   },
-  {
-    "toolbar",
+  { // toolbar
+    &nsGkAtoms::toolbar,
     roles::TOOLBAR,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "tooltip",
+  { // tooltip
+    &nsGkAtoms::tooltip,
     roles::TOOLTIP,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates
   },
-  {
-    "tree",
+  { // tree
+    &nsGkAtoms::tree,
     roles::OUTLINE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAReadonly,
     eARIAMultiSelectable
   },
-  {
-    "treegrid",
+  { // treegrid
+    &nsGkAtoms::treegrid,
     roles::TREE_TABLE,
     kUseMapRole,
     eNoValue,
     eNoAction,
     eNoLiveAttr,
     kNoReqStates,
     eARIAReadonly,
     eARIAMultiSelectable
   },
-  {
-    "treeitem",
+  { // treeitem
+    &nsGkAtoms::treeitem,
     roles::OUTLINEITEM,
     kUseMapRole,
     eNoValue,
     eActivateAction, // XXX: should expose second 'expand/collapse' action based
                      // on states
     eNoLiveAttr,
     kNoReqStates,
     eARIASelectable,
     eARIACheckedMixed
   }
 };
 
 static nsRoleMapEntry sLandmarkRoleMap = {
-  "",
+  &nsGkAtoms::_empty,
   roles::NOTHING,
   kUseNativeRole,
   eNoValue,
   eNoAction,
   eNoLiveAttr,
   kNoReqStates
 };
 
 nsRoleMapEntry nsARIAMap::gEmptyRoleMap = {
-  "",
+  &nsGkAtoms::_empty,
   roles::NOTHING,
   kUseMapRole,
   eNoValue,
   eNoAction,
   eNoLiveAttr,
   kNoReqStates
 };
 
@@ -636,34 +636,34 @@ nsAttributeCharacteristics nsARIAMap::gW
 };
 
 PRUint32 nsARIAMap::gWAIUnivAttrMapLength = NS_ARRAY_LENGTH(nsARIAMap::gWAIUnivAttrMap);
 
 nsRoleMapEntry*
 aria::GetRoleMap(nsINode* aNode)
 {
   nsIContent* content = nsCoreUtils::GetRoleContent(aNode);
-  nsAutoString roleString;
+  nsAutoString roles;
   if (!content ||
-      !content->GetAttr(kNameSpaceID_None, nsGkAtoms::role, roleString) ||
-      roleString.IsEmpty()) {
+      !content->GetAttr(kNameSpaceID_None, nsGkAtoms::role, roles) ||
+      roles.IsEmpty()) {
     // We treat role="" as if the role attribute is absent (per aria spec:8.1.1)
     return nsnull;
   }
 
-  nsWhitespaceTokenizer tokenizer(roleString);
+  nsWhitespaceTokenizer tokenizer(roles);
   while (tokenizer.hasMoreTokens()) {
     // Do a binary search through table for the next role in role list
-    NS_LossyConvertUTF16toASCII role(tokenizer.nextToken());
+    const nsDependentSubstring role = tokenizer.nextToken();
     PRUint32 low = 0;
     PRUint32 high = ArrayLength(sWAIRoleMaps);
     while (low < high) {
       PRUint32 idx = (low + high) / 2;
-      PRInt32 compare = strcmp(role.get(), sWAIRoleMaps[idx].roleString);
-      if (compare == 0) 
+      PRInt32 compare = Compare(role, sWAIRoleMaps[idx].ARIARoleString());
+      if (compare == 0)
         return sWAIRoleMaps + idx;
 
       if (compare < 0)
         high = idx;
       else
         low = idx + 1;
     }
   }
--- a/accessible/src/base/nsARIAMap.h
+++ b/accessible/src/base/nsARIAMap.h
@@ -6,17 +6,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef _nsARIAMap_H_
 #define _nsARIAMap_H_
 
 #include "ARIAStateMap.h"
 #include "mozilla/a11y/Role.h"
 
-class nsIAtom;
+#include "nsIAtom.h"
+
 class nsIContent;
 class nsINode;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Value constants
 
 /**
  * Used to define if role requires to expose nsIAccessibleValue.
@@ -131,19 +132,31 @@ enum EDefaultStateRule
 ////////////////////////////////////////////////////////////////////////////////
 // Role map entry
 
 /**
  * For each ARIA role, this maps the nsIAccessible information.
  */
 struct nsRoleMapEntry
 {
+  /**
+   * Return true if matches to the given ARIA role.
+   */
+  bool Is(nsIAtom* aARIARole) const
+    { return *roleAtom == aARIARole; }
+
+  /**
+   * Return ARIA role.
+   */
+  const nsDependentAtomString ARIARoleString() const
+    { return nsDependentAtomString(*roleAtom); }
+
   // ARIA role: string representation such as "button"
-  const char *roleString;
-  
+  nsIAtom** roleAtom;
+
   // Role mapping rule: maps to this nsIAccessibleRole
   mozilla::a11y::role role;
   
   // Role rule: whether to use mapped role or native semantics
   bool roleRule;
   
   // Value mapping rule: how to compute nsIAccessible value
   EValueRule valueRule;
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -147,19 +147,18 @@ nsAccUtils::SetLiveContainerAttributes(n
         ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_live,
                           live);
       } else if (role) {
         GetLiveAttrValue(role->liveAttRule, live);
       }
       if (!live.IsEmpty()) {
         SetAccAttr(aAttributes, nsGkAtoms::containerLive, live);
         if (role) {
-          nsAccUtils::SetAccAttr(aAttributes,
-                                 nsGkAtoms::containerLiveRole,
-                                 NS_ConvertASCIItoUTF16(role->roleString));
+          nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::containerLiveRole,
+                                 role->ARIARoleString());
         }
       }
     }
 
     // container-atomic attribute
     if (atomic.IsEmpty() &&
         nsAccUtils::HasDefinedARIAToken(ancestor, nsGkAtoms::aria_atomic) &&
         ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_atomic, atomic))
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -19,22 +19,18 @@
 #include "nsIDOMNode.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIPresShell.h"
 #include "nsPoint.h"
 
 class nsAccessNode;
 class Accessible;
 class HyperTextAccessible;
-class nsHTMLTableAccessible;
 class DocAccessible;
 struct nsRoleMapEntry;
-#ifdef MOZ_XUL
-class nsXULTreeAccessible;
-#endif
 
 class nsAccUtils
 {
 public:
   /**
    * Returns value of attribute from the given attributes container.
    *
    * @param aAttributes - attributes container
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -15,22 +15,22 @@
 #include "DocAccessible-inl.h"
 #include "FocusManager.h"
 #include "HTMLCanvasAccessible.h"
 #include "HTMLElementAccessibles.h"
 #include "HTMLImageMapAccessible.h"
 #include "HTMLLinkAccessible.h"
 #include "HTMLListAccessible.h"
 #include "HTMLSelectAccessible.h"
+#include "HTMLTableAccessibleWrap.h"
 #include "HyperTextAccessibleWrap.h"
 #include "nsAccessiblePivot.h"
 #include "nsAccUtils.h"
 #include "nsARIAMap.h"
 #include "nsIAccessibleProvider.h"
-#include "nsHTMLTableAccessibleWrap.h"
 #include "nsXFormsFormControlsAccessible.h"
 #include "nsXFormsWidgetsAccessible.h"
 #include "OuterDocAccessible.h"
 #include "Role.h"
 #include "RootAccessibleWrap.h"
 #include "States.h"
 #include "Statistics.h"
 #ifdef XP_WIN
@@ -62,26 +62,26 @@
 #include "nsObjectFrame.h"
 #include "nsTextFragment.h"
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/Services.h"
 #include "mozilla/Util.h"
 
 #ifdef MOZ_XUL
-#include "nsXULAlertAccessible.h"
-#include "nsXULColorPickerAccessible.h"
-#include "nsXULComboboxAccessible.h"
+#include "XULAlertAccessible.h"
+#include "XULColorPickerAccessible.h"
+#include "XULComboboxAccessible.h"
+#include "XULElementAccessibles.h"
 #include "XULFormControlAccessible.h"
-#include "nsXULListboxAccessibleWrap.h"
-#include "nsXULMenuAccessibleWrap.h"
-#include "nsXULSliderAccessible.h"
-#include "nsXULTabAccessible.h"
-#include "nsXULTextAccessible.h"
-#include "nsXULTreeGridAccessibleWrap.h"
+#include "XULListboxAccessibleWrap.h"
+#include "XULMenuAccessibleWrap.h"
+#include "XULSliderAccessible.h"
+#include "XULTabAccessible.h"
+#include "XULTreeGridAccessibleWrap.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessibilityService
 ////////////////////////////////////////////////////////////////////////////////
@@ -380,27 +380,27 @@ nsAccessibilityService::CreateHTMLRadioB
   return accessible;
 }
 
 already_AddRefed<Accessible>
 nsAccessibilityService::CreateHTMLTableAccessible(nsIContent* aContent,
                                                   nsIPresShell* aPresShell)
 {
   Accessible* accessible =
-    new nsHTMLTableAccessibleWrap(aContent, GetDocAccessible(aPresShell));
+    new HTMLTableAccessibleWrap(aContent, GetDocAccessible(aPresShell));
   NS_ADDREF(accessible);
   return accessible;
 }
 
 already_AddRefed<Accessible>
 nsAccessibilityService::CreateHTMLTableCellAccessible(nsIContent* aContent,
                                                       nsIPresShell* aPresShell)
 {
   Accessible* accessible =
-    new nsHTMLTableCellAccessibleWrap(aContent, GetDocAccessible(aPresShell));
+    new HTMLTableCellAccessibleWrap(aContent, GetDocAccessible(aPresShell));
   NS_ADDREF(accessible);
   return accessible;
 }
 
 already_AddRefed<Accessible>
 nsAccessibilityService::CreateHTMLTableRowAccessible(nsIContent* aContent,
                                                      nsIPresShell* aPresShell)
 {
@@ -460,17 +460,17 @@ nsAccessibilityService::CreateHTMLBRAcce
   return accessible;
 }
 
 already_AddRefed<Accessible>
 nsAccessibilityService::CreateHTMLCaptionAccessible(nsIContent* aContent,
                                                     nsIPresShell* aPresShell)
 {
   Accessible* accessible =
-    new nsHTMLCaptionAccessible(aContent, GetDocAccessible(aPresShell));
+    new HTMLCaptionAccessible(aContent, GetDocAccessible(aPresShell));
   NS_ADDREF(accessible);
   return accessible;
 }
 
 void
 nsAccessibilityService::ContentRangeInserted(nsIPresShell* aPresShell,
                                              nsIContent* aContainer,
                                              nsIContent* aStartChild,
@@ -525,17 +525,17 @@ void
 nsAccessibilityService::TreeViewChanged(nsIPresShell* aPresShell,
                                         nsIContent* aContent,
                                         nsITreeView* aView)
 {
   DocAccessible* document = GetDocAccessible(aPresShell);
   if (document) {
     Accessible* accessible = document->GetAccessible(aContent);
     if (accessible) {
-      nsXULTreeAccessible* treeAcc = accessible->AsXULTree();
+      XULTreeAccessible* treeAcc = accessible->AsXULTree();
       if (treeAcc) 
         treeAcc->TreeViewChanged(aView);
     }
   }
 }
 
 void
 nsAccessibilityService::UpdateListBullet(nsIPresShell* aPresShell,
@@ -1021,17 +1021,17 @@ nsAccessibilityService::GetOrCreateAcces
 
     newAcc = new HyperTextAccessibleWrap(content, docAcc);
     if (docAcc->BindToDocument(newAcc, aria::GetRoleMap(aNode)))
       return newAcc;
     return nsnull;
   }
 
   nsRoleMapEntry* roleMapEntry = aria::GetRoleMap(aNode);
-  if (roleMapEntry && !nsCRT::strcmp(roleMapEntry->roleString, "presentation")) {
+  if (roleMapEntry && roleMapEntry->Is(nsGkAtoms::presentation)) {
     // Ignore presentation role if element is focusable (focus event shouldn't
     // be ever lost and should be sensible).
     if (content->IsFocusable())
       roleMapEntry = nsnull;
     else
       return nsnull;
   }
 
@@ -1068,18 +1068,17 @@ nsAccessibilityService::GetOrCreateAcces
                 roleMapEntry = &nsARIAMap::gEmptyRoleMap;
             }
 
             break;
           }
 
 #ifdef DEBUG
           nsRoleMapEntry* tableRoleMapEntry = aria::GetRoleMap(tableContent);
-          NS_ASSERTION(tableRoleMapEntry &&
-                       !nsCRT::strcmp(tableRoleMapEntry->roleString, "presentation"),
+          NS_ASSERTION(tableRoleMapEntry && tableRoleMapEntry->Is(nsGkAtoms::presentation),
                        "No accessible for parent table and it didn't have role of presentation");
 #endif
 
           if (!roleMapEntry && !content->IsFocusable()) {
             // Table-related descendants of presentation table are also
             // presentation if they aren't focusable and have not explicit ARIA
             // role (don't create accessibles for them unless they need to fire
             // focus events).
@@ -1309,37 +1308,37 @@ nsAccessibilityService::CreateAccessible
   switch (type)
   {
 #ifdef MOZ_XUL
     case nsIAccessibleProvider::NoAccessible:
       return nsnull;
 
     // XUL controls
     case nsIAccessibleProvider::XULAlert:
-      accessible = new nsXULAlertAccessible(aContent, aDoc);
+      accessible = new XULAlertAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULButton:
       accessible = new XULButtonAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULCheckbox:
       accessible = new XULCheckboxAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULColorPicker:
-      accessible = new nsXULColorPickerAccessible(aContent, aDoc);
+      accessible = new XULColorPickerAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULColorPickerTile:
-      accessible = new nsXULColorPickerTileAccessible(aContent, aDoc);
+      accessible = new XULColorPickerTileAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULCombobox:
-      accessible = new nsXULComboboxAccessible(aContent, aDoc);
+      accessible = new XULComboboxAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULDropmarker:
       accessible = new XULDropmarkerAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULGroupbox:
       accessible = new XULGroupboxAccessible(aContent, aDoc);
@@ -1352,137 +1351,137 @@ nsAccessibilityService::CreateAccessible
                              nsGkAtoms::tooltiptext))
         return nsnull;
 
       accessible = new ImageAccessibleWrap(aContent, aDoc);
       break;
 
     }
     case nsIAccessibleProvider::XULLink:
-      accessible = new nsXULLinkAccessible(aContent, aDoc);
+      accessible = new XULLinkAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULListbox:
-      accessible = new nsXULListboxAccessibleWrap(aContent, aDoc);
+      accessible = new XULListboxAccessibleWrap(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULListCell:
-      accessible = new nsXULListCellAccessibleWrap(aContent, aDoc);
+      accessible = new XULListCellAccessibleWrap(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULListHead:
-      accessible = new nsXULColumAccessible(aContent, aDoc);
+      accessible = new XULColumAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULListHeader:
-      accessible = new nsXULColumnItemAccessible(aContent, aDoc);
+      accessible = new XULColumnItemAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULListitem:
-      accessible = new nsXULListitemAccessible(aContent, aDoc);
+      accessible = new XULListitemAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULMenubar:
-      accessible = new nsXULMenubarAccessible(aContent, aDoc);
+      accessible = new XULMenubarAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULMenuitem:
-      accessible = new nsXULMenuitemAccessibleWrap(aContent, aDoc);
+      accessible = new XULMenuitemAccessibleWrap(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULMenupopup:
     {
 #ifdef MOZ_ACCESSIBILITY_ATK
       // ATK considers this node to be redundant when within menubars, and it makes menu
       // navigation with assistive technologies more difficult
       // XXX In the future we will should this for consistency across the nsIAccessible
       // implementations on each platform for a consistent scripting environment, but
       // then strip out redundant accessibles in the AccessibleWrap class for each platform.
       nsIContent *parent = aContent->GetParent();
       if (parent && parent->NodeInfo()->Equals(nsGkAtoms::menu,
                                                kNameSpaceID_XUL))
         return nsnull;
 #endif
-      accessible = new nsXULMenupopupAccessible(aContent, aDoc);
+      accessible = new XULMenupopupAccessible(aContent, aDoc);
       break;
 
     }
     case nsIAccessibleProvider::XULMenuSeparator:
-      accessible = new nsXULMenuSeparatorAccessible(aContent, aDoc);
+      accessible = new XULMenuSeparatorAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULPane:
       accessible = new EnumRoleAccessible(aContent, aDoc, roles::PANE);
       break;
 
     case nsIAccessibleProvider::XULProgressMeter:
       accessible = new XULProgressMeterAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULStatusBar:
       accessible = new XULStatusBarAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULScale:
-      accessible = new nsXULSliderAccessible(aContent, aDoc);
+      accessible = new XULSliderAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULRadioButton:
       accessible = new XULRadioButtonAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULRadioGroup:
       accessible = new XULRadioGroupAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTab:
-      accessible = new nsXULTabAccessible(aContent, aDoc);
+      accessible = new XULTabAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTabs:
-      accessible = new nsXULTabsAccessible(aContent, aDoc);
+      accessible = new XULTabsAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTabpanels:
-      accessible = new nsXULTabpanelsAccessible(aContent, aDoc);
+      accessible = new XULTabpanelsAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULText:
-      accessible = new nsXULTextAccessible(aContent, aDoc);
+      accessible = new XULLabelAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTextBox:
       accessible = new XULTextFieldAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULThumb:
-      accessible = new nsXULThumbAccessible(aContent, aDoc);
+      accessible = new XULThumbAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTree:
       return CreateAccessibleForXULTree(aContent, aDoc);
 
     case nsIAccessibleProvider::XULTreeColumns:
-      accessible = new nsXULTreeColumAccessible(aContent, aDoc);
+      accessible = new XULTreeColumAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTreeColumnItem:
-      accessible = new nsXULColumnItemAccessible(aContent, aDoc);
+      accessible = new XULColumnItemAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULToolbar:
       accessible = new XULToolbarAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULToolbarSeparator:
       accessible = new XULToolbarSeparatorAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULTooltip:
-      accessible = new nsXULTooltipAccessible(aContent, aDoc);
+      accessible = new XULTooltipAccessible(aContent, aDoc);
       break;
 
     case nsIAccessibleProvider::XULToolbarButton:
       accessible = new XULToolbarButtonAccessible(aContent, aDoc);
       break;
 
 #endif // MOZ_XUL
 
@@ -1655,18 +1654,17 @@ nsAccessibilityService::CreateHTMLAccess
       tag == nsGkAtoms::h6 ||
       tag == nsGkAtoms::q) {
     Accessible* accessible = new HyperTextAccessibleWrap(aContent, aDoc);
     NS_IF_ADDREF(accessible);
     return accessible;
   }
 
   if (nsCoreUtils::IsHTMLTableHeader(aContent)) {
-    Accessible* accessible = new nsHTMLTableHeaderCellAccessibleWrap(aContent,
-                                                                     aDoc);
+    Accessible* accessible = new HTMLTableHeaderCellAccessibleWrap(aContent, aDoc);
     NS_IF_ADDREF(accessible);
     return accessible;
   }
 
   if (tag == nsGkAtoms::output) {
     Accessible* accessible = new HTMLOutputAccessible(aContent, aDoc);
     NS_IF_ADDREF(accessible);
     return accessible;
@@ -1766,17 +1764,17 @@ nsAccessibilityService::CreateAccessible
     nsIFrame* parentFrame = aFrame->GetParent();
     if (parentFrame && parentFrame->GetType() == nsGkAtoms::deckFrame) {
       // If deck frame is for xul:tabpanels element then the given node has
       // tabpanel accessible.
       nsCOMPtr<nsIContent> parentContent = parentFrame->GetContent();
 #ifdef MOZ_XUL
       if (parentContent->NodeInfo()->Equals(nsGkAtoms::tabpanels,
                                             kNameSpaceID_XUL)) {
-        Accessible* accessible = new nsXULTabpanelAccessible(aContent, aDoc);
+        Accessible* accessible = new XULTabpanelAccessible(aContent, aDoc);
         NS_IF_ADDREF(accessible);
         return accessible;
       }
 #endif
       Accessible* accessible = new EnumRoleAccessible(aContent, aDoc,
                                                       roles::PROPERTYPAGE);
       NS_IF_ADDREF(accessible);
       return accessible;
@@ -1800,23 +1798,23 @@ nsAccessibilityService::CreateAccessible
   if (!treeColumns)
     return nsnull;
 
   PRInt32 count = 0;
   treeColumns->GetCount(&count);
 
   // Outline of list accessible.
   if (count == 1) {
-    Accessible* accessible = new nsXULTreeAccessible(aContent, aDoc);
+    Accessible* accessible = new XULTreeAccessible(aContent, aDoc);
     NS_IF_ADDREF(accessible);
     return accessible;
   }
 
   // Table or tree table accessible.
-  Accessible* accessible = new nsXULTreeGridAccessibleWrap(aContent, aDoc);
+  Accessible* accessible = new XULTreeGridAccessibleWrap(aContent, aDoc);
   NS_IF_ADDREF(accessible);
   return accessible;
 }
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // Services
 ////////////////////////////////////////////////////////////////////////////////
--- a/accessible/src/base/nsAccessibilityService.h
+++ b/accessible/src/base/nsAccessibilityService.h
@@ -165,17 +165,17 @@ public:
    */
   static bool IsShutdown() { return gIsShutdown; }
 
   /**
    * Return an accessible for the given DOM node from the cache or create new
    * one.
    *
    * @param  aNode             [in] the given node
-   * @param  aDoc              [in] the doc accessible of the node  
+   * @param  aDoc              [in] the doc accessible of the node
    * @param  aIsSubtreeHidden  [out, optional] indicates whether the node's
    *                             frame and its subtree is hidden
    */
   Accessible* GetOrCreateAccessible(nsINode* aNode, DocAccessible* aDoc,
                                     bool* aIsSubtreeHidden = nsnull);
 
 private:
   // nsAccessibilityService creation is controlled by friend
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -340,17 +340,17 @@ Accessible::Description(nsString& aDescr
             aDescription.Truncate();
         }
       }
     }
     aDescription.CompressWhitespace();
 }
 
 NS_IMETHODIMP
-Accessible::GetKeyboardShortcut(nsAString& aAccessKey)
+Accessible::GetAccessKey(nsAString& aAccessKey)
 {
   aAccessKey.Truncate();
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   AccessKey().ToString(aAccessKey);
   return NS_OK;
@@ -876,99 +876,25 @@ Accessible::GetDeepestChildAtPoint(PRInt
 
   NS_IF_ADDREF(*aAccessible = ChildAtPoint(aX, aY, eDeepestChild));
   return NS_OK;
 }
 
 void
 Accessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
 {
-/*
- * This method is used to determine the bounds of a content node.
- * Because HTML wraps and links are not always rectangular, this
- * method uses the following algorithm:
- *
- * 1) Start with an empty rectangle
- * 2) Add the rect for the primary frame from for the DOM node.
- * 3) For each next frame at the same depth with the same DOM node, add that rect to total
- * 4) If that frame is an inline frame, search deeper at that point in the tree, adding all rects
- */
-
-  // Initialization area
-  *aBoundingFrame = nsnull;
-  nsIFrame* firstFrame = GetFrame();
-  if (!firstFrame)
-    return;
-
-  // Find common relative parent
-  // 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 (ancestorFrame->GetType() != nsGkAtoms::inlineFrame &&
-        ancestorFrame->GetType() != nsGkAtoms::textFrame)
-      break;
-    ancestorFrame = ancestorFrame->GetParent();
-  }
-
-  nsIFrame *iterFrame = firstFrame;
-  nsCOMPtr<nsIContent> firstContent(mContent);
-  nsIContent* iterContent = firstContent;
-  PRInt32 depth = 0;
-
-  // Look only at frames below this depth, or at this depth (if we're still on the content node we started with)
-  while (iterContent == firstContent || depth > 0) {
-    // Coordinates will come back relative to parent frame
-    nsRect currFrameBounds = iterFrame->GetRect();
-    
-    // Make this frame's bounds relative to common parent frame
-    currFrameBounds +=
-      iterFrame->GetParent()->GetOffsetToExternal(*aBoundingFrame);
-
-    // Add this frame's bounds to total
-    aTotalBounds.UnionRect(aTotalBounds, currFrameBounds);
-
-    nsIFrame *iterNextFrame = nsnull;
-
-    if (iterFrame->GetType() == nsGkAtoms::inlineFrame) {
-      // Only do deeper bounds search if we're on an inline frame
-      // Inline frames can contain larger frames inside of them
-      iterNextFrame = iterFrame->GetFirstPrincipalChild();
-    }
-
-    if (iterNextFrame) 
-      ++depth;  // Child was found in code above this: We are going deeper in this iteration of the loop
-    else {  
-      // Use next sibling if it exists, or go back up the tree to get the first next-in-flow or next-sibling 
-      // within our search
-      while (iterFrame) {
-        iterNextFrame = iterFrame->GetNextContinuation();
-        if (!iterNextFrame)
-          iterNextFrame = iterFrame->GetNextSibling();
-        if (iterNextFrame || --depth < 0) 
-          break;
-        iterFrame = iterFrame->GetParent();
-      }
-    }
-
-    // Get ready for the next round of our loop
-    iterFrame = iterNextFrame;
-    if (iterFrame == nsnull)
-      break;
-    iterContent = nsnull;
-    if (depth == 0)
-      iterContent = iterFrame->GetContent();
+  nsIFrame* frame = GetFrame();
+  if (frame) {
+    *aBoundingFrame = nsLayoutUtils::GetContainingBlockForClientRect(frame);
+    aTotalBounds = nsLayoutUtils::
+      GetAllInFlowRectsUnion(frame, *aBoundingFrame,
+                             nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
   }
 }
 
-
 /* void getBounds (out long x, out long y, out long width, out long height); */
 NS_IMETHODIMP
 Accessible::GetBounds(PRInt32* aX, PRInt32* aY,
                       PRInt32* aWidth, PRInt32* aHeight)
 {
   NS_ENSURE_ARG_POINTER(aX);
   *aX = 0;
   NS_ENSURE_ARG_POINTER(aY);
@@ -1748,47 +1674,26 @@ Accessible::SetCurrentValue(double aValu
 /* void setName (in DOMString name); */
 NS_IMETHODIMP
 Accessible::SetName(const nsAString& aName)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-Accessible::GetDefaultKeyBinding(nsAString& aKeyBinding)
+Accessible::GetKeyboardShortcut(nsAString& aKeyBinding)
 {
   aKeyBinding.Truncate();
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   KeyboardShortcut().ToString(aKeyBinding);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-Accessible::GetKeyBindings(PRUint8 aActionIndex,
-                             nsIDOMDOMStringList** aKeyBindings)
-{
-  // Currently we support only unique key binding on element for default action.
-  NS_ENSURE_TRUE(aActionIndex == 0, NS_ERROR_INVALID_ARG);
-
-  nsAccessibleDOMStringList* keyBindings = new nsAccessibleDOMStringList();
-  NS_ENSURE_TRUE(keyBindings, NS_ERROR_OUT_OF_MEMORY);
-
-  nsAutoString defaultKey;
-  nsresult rv = GetDefaultKeyBinding(defaultKey);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!defaultKey.IsEmpty())
-    keyBindings->Add(defaultKey);
-
-  NS_ADDREF(*aKeyBindings = keyBindings);
-  return NS_OK;
-}
-
 role
 Accessible::ARIATransformRole(role aRole)
 {
   // XXX: these unfortunate exceptions don't fit into the ARIA table. This is
   // where the accessible role depends on both the role and ARIA state.
   if (aRole == roles::PUSHBUTTON) {
     if (nsAccUtils::HasDefinedARIAToken(mContent, nsGkAtoms::aria_pressed)) {
       // For simplicity, any existing pressed attribute except "" or "undefined"
--- a/accessible/src/generic/Accessible.h
+++ b/accessible/src/generic/Accessible.h
@@ -33,16 +33,17 @@ class Relation;
 namespace mozilla {
 namespace a11y {
 
 class HTMLImageMapAccessible;
 class HTMLLIAccessible;
 class ImageAccessible;
 class TableAccessible;
 class TextLeafAccessible;
+class XULTreeAccessible;
 
 /**
  * Name type flags.
  */
 enum ENameValueFlag {
   /**
    * Name either
    *  a) present (not empty): !name.IsEmpty()
@@ -63,18 +64,16 @@ struct GroupPos
   PRInt32 level;
   PRInt32 posInSet;
   PRInt32 setSize;
 };
 
 } // namespace a11y
 } // namespace mozilla
 
-class nsXULTreeAccessible;
-
 struct nsRect;
 class nsIContent;
 class nsIFrame;
 class nsIAtom;
 class nsIView;
 
 typedef nsRefPtrHashtable<nsPtrHashKey<const void>, Accessible>
   AccessibleHashtable;
@@ -95,18 +94,18 @@ NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODUL
 #define NS_ACCESSIBLE_IMPL_IID                          \
 {  /* 133c8bf4-4913-4355-bd50-426bd1d6e1ad */           \
   0x133c8bf4,                                           \
   0x4913,                                               \
   0x4355,                                               \
   { 0xbd, 0x50, 0x42, 0x6b, 0xd1, 0xd6, 0xe1, 0xad }    \
 }
 
-class Accessible : public nsAccessNodeWrap, 
-                   public nsIAccessible, 
+class Accessible : public nsAccessNodeWrap,
+                   public nsIAccessible,
                    public nsIAccessibleHyperLink,
                    public nsIAccessibleSelectable,
                    public nsIAccessibleValue
 {
 public:
   Accessible(nsIContent* aContent, DocAccessible* aDoc);
   virtual ~Accessible();
 
@@ -311,17 +310,17 @@ public:
 
   //////////////////////////////////////////////////////////////////////////////
   // Initializing methods
 
   /**
    * Set the ARIA role map entry for a new accessible.
    * For a newly created accessible, specify which role map entry should be used.
    *
-   * @param aRoleMapEntry The ARIA nsRoleMapEntry* for the accessible, or 
+   * @param aRoleMapEntry The ARIA nsRoleMapEntry* for the accessible, or
    *                      nsnull if none.
    */
   virtual void SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry);
 
   /**
    * Update the children cache.
    */
   inline bool UpdateChildren()
@@ -502,17 +501,17 @@ public:
 
   inline bool IsImage() const { return mFlags & eImageAccessible; }
   mozilla::a11y::ImageAccessible* AsImage();
 
   bool IsImageMapAccessible() const { return mFlags & eImageMapAccessible; }
   mozilla::a11y::HTMLImageMapAccessible* AsImageMap();
 
   inline bool IsXULTree() const { return mFlags & eXULTreeAccessible; }
-  nsXULTreeAccessible* AsXULTree();
+  mozilla::a11y::XULTreeAccessible* AsXULTree();
 
   inline bool IsListControl() const { return mFlags & eListControlAccessible; }
 
   inline bool IsMenuButton() const { return mFlags & eMenuButtonAccessible; }
 
   inline bool IsMenuPopup() const { return mFlags & eMenuPopupAccessible; }
 
   inline bool IsRoot() const { return mFlags & eRootAccessible; }
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -2001,16 +2001,25 @@ DocAccessible::CacheChildrenInSubtree(Ac
   PRUint32 count = aRoot->ContentChildCount();
   for (PRUint32 idx = 0; idx < count; idx++) {
     Accessible* child = aRoot->ContentChildAt(idx);
     NS_ASSERTION(child, "Illicit tree change while tree is created!");
     // Don't cross document boundaries.
     if (child && child->IsContent())
       CacheChildrenInSubtree(child);
   }
+
+  // Fire document load complete on ARIA documents.
+  // XXX: we should delay an event if the ARIA document has aria-busy.
+  if (aRoot->HasARIARole() && !aRoot->IsDoc()) {
+    a11y::role role = aRoot->ARIARole();
+    if (role == roles::DIALOG || role == roles::DOCUMENT)
+      FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE,
+                                 aRoot->GetContent());
+  }
 }
 
 void
 DocAccessible::UncacheChildrenInSubtree(Accessible* aRoot)
 {
   if (aRoot->IsElement())
     RemoveDependentIDsFor(aRoot);
 
--- a/accessible/src/generic/HyperTextAccessible.cpp
+++ b/accessible/src/generic/HyperTextAccessible.cpp
@@ -26,17 +26,17 @@
 #include "nsFrameSelection.h"
 #include "nsILineIterator.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIPlaintextEditor.h"
 #include "nsIScrollableFrame.h"
 #include "nsISelectionPrivate.h"
 #include "nsIServiceManager.h"
 #include "nsTextFragment.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "gfxSkipChars.h"
 
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // HyperTextAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
--- a/accessible/src/generic/RootAccessible.cpp
+++ b/accessible/src/generic/RootAccessible.cpp
@@ -13,16 +13,19 @@
 #include "Accessible-inl.h"
 #include "DocAccessible-inl.h"
 #include "nsAccessibilityService.h"
 #include "nsAccUtils.h"
 #include "nsCoreUtils.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
+#ifdef MOZ_XUL
+#include "XULTreeAccessible.h"
+#endif
 
 #include "mozilla/dom/Element.h"
 
 #include "nsIAccessibleRelation.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
 #include "nsIDocShellTreeOwner.h"
@@ -42,21 +45,19 @@
 #include "nsIFrame.h"
 #include "nsIHTMLDocument.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsISelectionPrivate.h"
 #include "nsIServiceManager.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsReadableUtils.h"
-#include "nsIPrivateDOMEvent.h"
 #include "nsFocusManager.h"
 
 #ifdef MOZ_XUL
-#include "nsXULTreeAccessible.h"
 #include "nsIXULDocument.h"
 #include "nsIXULWindow.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -319,17 +320,17 @@ RootAccessible::ProcessDOMEvent(nsIDOMEv
   Accessible* accessible = 
     targetDocument->GetAccessibleOrContainer(origTargetNode);
   if (!accessible)
     return;
 
   nsINode* targetNode = accessible->GetNode();
 
 #ifdef MOZ_XUL
-  nsXULTreeAccessible* treeAcc = accessible->AsXULTree();
+  XULTreeAccessible* treeAcc = accessible->AsXULTree();
   if (treeAcc) {
     if (eventType.EqualsLiteral("TreeRowCountChanged")) {
       HandleTreeRowCountChangedEvent(aDOMEvent, treeAcc);
       return;
     }
 
     if (eventType.EqualsLiteral("TreeInvalidated")) {
       HandleTreeInvalidatedEvent(aDOMEvent, treeAcc);
@@ -338,17 +339,17 @@ RootAccessible::ProcessDOMEvent(nsIDOMEv
   }
 #endif
 
   if (eventType.EqualsLiteral("RadioStateChange")) {
     PRUint64 state = accessible->State();
 
     // radiogroup in prefWindow is exposed as a list,
     // and panebutton is exposed as XULListitem in A11y.
-    // nsXULListitemAccessible::GetStateInternal uses STATE_SELECTED in this case,
+    // XULListitemAccessible::GetStateInternal uses STATE_SELECTED in this case,
     // so we need to check states::SELECTED also.
     bool isEnabled = (state & (states::CHECKED | states::SELECTED)) != 0;
 
     nsRefPtr<AccEvent> accEvent =
       new AccStateChangeEvent(accessible, states::CHECKED, isEnabled);
     nsEventShell::FireEvent(accEvent);
 
     if (isEnabled) {
@@ -398,17 +399,17 @@ RootAccessible::ProcessDOMEvent(nsIDOMEv
       nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSel =
         do_QueryInterface(targetNode);
       nsAutoString selType;
       multiSel->GetSelType(selType);
       if (selType.IsEmpty() || !selType.EqualsLiteral("single")) {
         // XXX: We need to fire EVENT_SELECTION_ADD and EVENT_SELECTION_REMOVE
         // for each tree item. Perhaps each tree item will need to cache its
         // selection state and fire an event after a DOM "select" event when
-        // that state changes. nsXULTreeAccessible::UpdateTreeSelection();
+        // that state changes. XULTreeAccessible::UpdateTreeSelection();
         nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
                                 accessible);
         return;
       }
 
       nsRefPtr<AccSelChangeEvent> selChangeEvent =
         new AccSelChangeEvent(treeAcc, treeItemAcc,
                               AccSelChangeEvent::eSelectionAdd);
@@ -667,17 +668,17 @@ RootAccessible::HandlePopupHidingEvent(n
       new AccStateChangeEvent(widget, states::EXPANDED, false);
     document->FireDelayedAccessibleEvent(event);
   }
 }
 
 #ifdef MOZ_XUL
 void
 RootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent* aEvent,
-                                               nsXULTreeAccessible* aAccessible)
+                                               XULTreeAccessible* aAccessible)
 {
   nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
   if (!dataEvent)
     return;
 
   nsCOMPtr<nsIVariant> indexVariant;
   dataEvent->GetData(NS_LITERAL_STRING("index"),
                      getter_AddRefs(indexVariant));
@@ -694,17 +695,17 @@ RootAccessible::HandleTreeRowCountChange
   indexVariant->GetAsInt32(&index);
   countVariant->GetAsInt32(&count);
 
   aAccessible->InvalidateCache(index, count);
 }
 
 void
 RootAccessible::HandleTreeInvalidatedEvent(nsIDOMEvent* aEvent,
-                                           nsXULTreeAccessible* aAccessible)
+                                           XULTreeAccessible* aAccessible)
 {
   nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
   if (!dataEvent)
     return;
 
   PRInt32 startRow = 0, endRow = -1, startCol = 0, endCol = -1;
 
   nsCOMPtr<nsIVariant> startRowVariant;
--- a/accessible/src/generic/RootAccessible.h
+++ b/accessible/src/generic/RootAccessible.h
@@ -10,17 +10,16 @@
 #include "DocAccessibleWrap.h"
 
 
 #include "nsHashtable.h"
 #include "nsCaretAccessible.h"
 #include "nsIDocument.h"
 #include "nsIDOMEventListener.h"
 
-class nsXULTreeAccessible;
 class Relation;
 
 namespace mozilla {
 namespace a11y {
 
 class RootAccessible : public DocAccessibleWrap,
                        public nsIDOMEventListener
 {
@@ -71,19 +70,19 @@ protected:
 
   /*
    * Process "popuphiding" event. Used by HandleEvent().
    */
   void HandlePopupHidingEvent(nsINode* aNode);
 
 #ifdef MOZ_XUL
     void HandleTreeRowCountChangedEvent(nsIDOMEvent* aEvent,
-                                        nsXULTreeAccessible* aAccessible);
+                                        XULTreeAccessible* aAccessible);
     void HandleTreeInvalidatedEvent(nsIDOMEvent* aEvent,
-                                    nsXULTreeAccessible* aAccessible);
+                                    XULTreeAccessible* aAccessible);
 
     PRUint32 GetChromeFlags();
 #endif
 
     nsRefPtr<nsCaretAccessible> mCaretAccessible;
 };
 
 } // namespace a11y
--- a/accessible/src/generic/TextLeafAccessible.cpp
+++ b/accessible/src/generic/TextLeafAccessible.cpp
@@ -46,25 +46,13 @@ TextLeafAccessible::AppendTextTo(nsAStri
 ENameValueFlag
 TextLeafAccessible::Name(nsString& aName)
 {
   // Text node, ARIA can't be used.
   aName = mText;
   return eNameOK;
 }
 
-nsresult
-TextLeafAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
-{
-  if (NativeRole() == roles::STATICTEXT) {
-    nsAutoString oldValueUnused;
-    aAttributes->SetStringProperty(NS_LITERAL_CSTRING("auto-generated"),
-                                  NS_LITERAL_STRING("true"), oldValueUnused);
-  }
-
-  return NS_OK;
-}
-
 void
 TextLeafAccessible::CacheChildren()
 {
   // No children for text accessible.
 }
--- a/accessible/src/generic/TextLeafAccessible.h
+++ b/accessible/src/generic/TextLeafAccessible.h
@@ -20,17 +20,16 @@ public:
   TextLeafAccessible(nsIContent* aContent, DocAccessible* aDoc);
   virtual ~TextLeafAccessible();
 
   // Accessible
   virtual mozilla::a11y::role NativeRole();
   virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
                             PRUint32 aLength = PR_UINT32_MAX);
   virtual ENameValueFlag Name(nsString& aName);
-  virtual nsresult GetAttributesInternal(nsIPersistentProperties* aAttributes);
 
   // TextLeafAccessible
   void SetText(const nsAString& aText) { mText = aText; }
   const nsString& Text() const { return mText; }
 
 protected:
   // Accessible
   virtual void CacheChildren();
new file mode 100644
--- /dev/null
+++ b/accessible/src/html/HTMLTableAccessible.cpp
@@ -0,0 +1,1524 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "HTMLTableAccessible.h"
+
+#include "Accessible-inl.h"
+#include "nsAccessibilityService.h"
+#include "nsAccTreeWalker.h"
+#include "nsAccUtils.h"
+#include "DocAccessible.h"
+#include "nsTextEquivUtils.h"
+#include "Relation.h"
+#include "Role.h"
+#include "States.h"
+
+#include "nsIAccessibleRelation.h"
+#include "nsIDOMElement.h"
+#include "nsIDOMDocument.h"
+#include "nsIDOMRange.h"
+#include "nsISelectionPrivate.h"
+#include "nsINameSpaceManager.h"
+#include "nsIDOMNodeList.h"
+#include "nsIDOMHTMLCollection.h"
+#include "nsIDOMHTMLTableCellElement.h"
+#include "nsIDOMHTMLTableElement.h"
+#include "nsIDOMHTMLTableRowElement.h"
+#include "nsIDOMHTMLTableSectionElem.h"
+#include "nsIDocument.h"
+#include "nsIPresShell.h"
+#include "nsITableLayout.h"
+#include "nsITableCellLayout.h"
+#include "nsFrameSelection.h"
+#include "nsLayoutErrors.h"
+#include "nsArrayUtils.h"
+#include "nsComponentManagerUtils.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+HTMLTableCellAccessible::
+  HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  HyperTextAccessibleWrap(aContent, aDoc)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessible: nsISupports implementation
+
+NS_IMPL_ISUPPORTS_INHERITED1(HTMLTableCellAccessible,
+                             HyperTextAccessible,
+                             nsIAccessibleTableCell)
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessible: Accessible implementation
+
+role
+HTMLTableCellAccessible::NativeRole()
+{
+  return roles::CELL;
+}
+
+PRUint64
+HTMLTableCellAccessible::NativeState()
+{
+  PRUint64 state = HyperTextAccessibleWrap::NativeState();
+
+  nsIFrame *frame = mContent->GetPrimaryFrame();
+  NS_ASSERTION(frame, "No frame for valid cell accessible!");
+
+  if (frame && frame->IsSelected())
+    state |= states::SELECTED;
+
+  return state;
+}
+
+PRUint64
+HTMLTableCellAccessible::NativeInteractiveState() const
+{
+  return HyperTextAccessibleWrap::NativeInteractiveState() | states::SELECTABLE;
+}
+
+nsresult
+HTMLTableCellAccessible::GetAttributesInternal(nsIPersistentProperties* aAttributes)
+{
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsresult rv = HyperTextAccessibleWrap::GetAttributesInternal(aAttributes);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // table-cell-index attribute
+  nsCOMPtr<nsIAccessibleTable> tableAcc(GetTableAccessible());
+  if (!tableAcc)
+    return NS_OK;
+
+  PRInt32 rowIdx = -1, colIdx = -1;
+  rv = GetCellIndexes(rowIdx, colIdx);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 idx = -1;
+  rv = tableAcc->GetCellIndexAt(rowIdx, colIdx, &idx);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsAutoString stringIdx;
+  stringIdx.AppendInt(idx);
+  nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex, stringIdx);
+
+  // abbr attribute
+
+  // Pick up object attribute from abbr DOM element (a child of the cell) or
+  // from abbr DOM attribute.
+  nsAutoString abbrText;
+  if (ChildCount() == 1) {
+    Accessible* abbr = FirstChild();
+    if (abbr->IsAbbreviation()) {
+      nsTextEquivUtils::
+        AppendTextEquivFromTextContent(abbr->GetContent()->GetFirstChild(),
+                                       &abbrText);
+    }
+  }
+  if (abbrText.IsEmpty())
+    mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, abbrText);
+
+  if (!abbrText.IsEmpty())
+    nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::abbr, abbrText);
+
+  // axis attribute
+  nsAutoString axisText;
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
+  if (!axisText.IsEmpty())
+    nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::axis, axisText);
+
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessible: nsIAccessibleTableCell implementation
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetTable(nsIAccessibleTable** aTable)
+{
+  NS_ENSURE_ARG_POINTER(aTable);
+  *aTable = nsnull;
+
+  if (IsDefunct())
+    return NS_OK;
+
+  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
+  table.swap(*aTable);
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetColumnIndex(PRInt32* aColumnIndex)
+{
+  NS_ENSURE_ARG_POINTER(aColumnIndex);
+  *aColumnIndex = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsITableCellLayout* cellLayout = GetCellLayout();
+  NS_ENSURE_STATE(cellLayout);
+
+  return cellLayout->GetColIndex(*aColumnIndex);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetRowIndex(PRInt32* aRowIndex)
+{
+  NS_ENSURE_ARG_POINTER(aRowIndex);
+  *aRowIndex = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsITableCellLayout* cellLayout = GetCellLayout();
+  NS_ENSURE_STATE(cellLayout);
+
+  return cellLayout->GetRowIndex(*aRowIndex);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetColumnExtent(PRInt32* aExtentCount)
+{
+  NS_ENSURE_ARG_POINTER(aExtentCount);
+  *aExtentCount = 1;
+
+  PRInt32 rowIdx = -1, colIdx = -1;
+  GetCellIndexes(rowIdx, colIdx);
+
+  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
+  NS_ENSURE_STATE(table);
+
+  return table->GetColumnExtentAt(rowIdx, colIdx, aExtentCount);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetRowExtent(PRInt32* aExtentCount)
+{
+  NS_ENSURE_ARG_POINTER(aExtentCount);
+  *aExtentCount = 1;
+
+  PRInt32 rowIdx = -1, colIdx = -1;
+  GetCellIndexes(rowIdx, colIdx);
+
+  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
+  NS_ENSURE_STATE(table);
+
+  return table->GetRowExtentAt(rowIdx, colIdx, aExtentCount);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetColumnHeaderCells(nsIArray** aHeaderCells)
+{
+  NS_ENSURE_ARG_POINTER(aHeaderCells);
+  *aHeaderCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  return GetHeaderCells(nsAccUtils::eColumnHeaderCells, aHeaderCells);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::GetRowHeaderCells(nsIArray** aHeaderCells)
+{
+  NS_ENSURE_ARG_POINTER(aHeaderCells);
+  *aHeaderCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  return GetHeaderCells(nsAccUtils::eRowHeaderCells, aHeaderCells);
+}
+
+NS_IMETHODIMP
+HTMLTableCellAccessible::IsSelected(bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  PRInt32 rowIdx = -1, colIdx = -1;
+  GetCellIndexes(rowIdx, colIdx);
+
+  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
+  NS_ENSURE_STATE(table);
+
+  return table->IsCellSelected(rowIdx, colIdx, aIsSelected);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessible: protected implementation
+
+already_AddRefed<nsIAccessibleTable>
+HTMLTableCellAccessible::GetTableAccessible()
+{
+  Accessible* parent = this;
+  while ((parent = parent->Parent())) {
+    roles::Role role = parent->Role();
+    if (role == roles::TABLE || role == roles::TREE_TABLE) {
+      nsIAccessibleTable* tableAcc = nsnull;
+      CallQueryInterface(parent, &tableAcc);
+      return tableAcc;
+    }
+  }
+
+  return nsnull;
+}
+
+nsITableCellLayout*
+HTMLTableCellAccessible::GetCellLayout()
+{
+  nsIFrame *frame = mContent->GetPrimaryFrame();
+  NS_ASSERTION(frame, "The frame cannot be obtaied for HTML table cell.");
+  if (!frame)
+    return nsnull;
+
+  nsITableCellLayout *cellLayout = do_QueryFrame(frame);
+  return cellLayout;
+}
+
+nsresult
+HTMLTableCellAccessible::GetCellIndexes(PRInt32& aRowIndex, PRInt32& aColIndex)
+{
+  nsITableCellLayout *cellLayout = GetCellLayout();
+  NS_ENSURE_STATE(cellLayout);
+
+  return cellLayout->GetCellIndexes(aRowIndex, aColIndex);
+}
+
+nsresult
+HTMLTableCellAccessible::GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
+                                        nsIArray** aHeaderCells)
+{
+  // Get header cells from @header attribute.
+  IDRefsIterator iter(mDoc, mContent, nsGkAtoms::headers);
+  nsIContent* headerCellElm = iter.NextElem();
+  if (headerCellElm) {
+    nsresult rv = NS_OK;
+    nsCOMPtr<nsIMutableArray> headerCells =
+      do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+    roles::Role desiredRole = static_cast<roles::Role>(-1) ;
+    if (aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells)
+      desiredRole = roles::ROWHEADER;
+    else if (aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells)
+      desiredRole = roles::COLUMNHEADER;
+
+    do {
+      Accessible* headerCell = mDoc->GetAccessible(headerCellElm);
+
+      if (headerCell && headerCell->Role() == desiredRole)
+        headerCells->AppendElement(static_cast<nsIAccessible*>(headerCell),
+                                   false);
+    } while ((headerCellElm = iter.NextElem()));
+
+    NS_ADDREF(*aHeaderCells = headerCells);
+    return NS_OK;
+  }
+
+  // Otherwise calculate header cells from hierarchy (see 11.4.3 "Algorithm to
+  // find heading information" of w3c HTML 4.01).
+  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
+  if (table) {
+    return nsAccUtils::GetHeaderCellsFor(table, this, aRowOrColumnHeaderCell,
+                                         aHeaderCells);
+  }
+
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableHeaderCellAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+HTMLTableHeaderCellAccessible::
+  HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  HTMLTableCellAccessible(aContent, aDoc)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableHeaderCellAccessible: Accessible implementation
+
+role
+HTMLTableHeaderCellAccessible::NativeRole()
+{
+  // Check value of @scope attribute.
+  static nsIContent::AttrValuesArray scopeValues[] =
+    {&nsGkAtoms::col, &nsGkAtoms::row, nsnull};
+  PRInt32 valueIdx =
+    mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
+                              scopeValues, eCaseMatters);
+
+  switch (valueIdx) {
+    case 0:
+      return roles::COLUMNHEADER;
+    case 1:
+      return roles::ROWHEADER;
+  }
+
+  // Assume it's columnheader if there are headers in siblings, oterwise
+  // rowheader.
+  nsIContent* parentContent = mContent->GetParent();
+  if (!parentContent) {
+    NS_ERROR("Deattached content on alive accessible?");
+    return roles::NOTHING;
+  }
+
+  for (nsIContent* siblingContent = mContent->GetPreviousSibling(); siblingContent;
+       siblingContent = siblingContent->GetPreviousSibling()) {
+    if (siblingContent->IsElement()) {
+      return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
+	     roles::COLUMNHEADER : roles::ROWHEADER;
+    }
+  }
+
+  for (nsIContent* siblingContent = mContent->GetNextSibling(); siblingContent;
+       siblingContent = siblingContent->GetNextSibling()) {
+    if (siblingContent->IsElement()) {
+      return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
+	     roles::COLUMNHEADER : roles::ROWHEADER;
+    }
+  }
+
+  // No elements in siblings what means the table has one column only. Therefore
+  // it should be column header.
+  return roles::COLUMNHEADER;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+HTMLTableAccessible::
+  HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessible: nsISupports implementation
+
+NS_IMPL_ISUPPORTS_INHERITED1(HTMLTableAccessible, Accessible,
+                             nsIAccessibleTable)
+
+////////////////////////////////////////////////////////////////////////////////
+//nsAccessNode
+
+void
+HTMLTableAccessible::Shutdown()
+{
+  mTable = nsnull;
+  AccessibleWrap::Shutdown();
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessible: Accessible implementation
+
+void
+HTMLTableAccessible::CacheChildren()
+{
+  // Move caption accessible so that it's the first child. Check for the first
+  // caption only, because nsAccessibilityService ensures we don't create
+  // accessibles for the other captions, since only the first is actually
+  // visible.
+  nsAccTreeWalker walker(mDoc, mContent, CanHaveAnonChildren());
+
+  Accessible* child = nsnull;
+  while ((child = walker.NextChild())) {
+    if (child->Role() == roles::CAPTION) {
+      InsertChildAt(0, child);
+      while ((child = walker.NextChild()) && AppendChild(child));
+      break;
+    }
+    AppendChild(child);
+  }
+}
+
+role
+HTMLTableAccessible::NativeRole()
+{
+  return roles::TABLE;
+}
+
+PRUint64
+HTMLTableAccessible::NativeState()
+{
+  return Accessible::NativeState() | states::READONLY;
+}
+
+nsresult
+HTMLTableAccessible::GetNameInternal(nsAString& aName)
+{
+  Accessible::GetNameInternal(aName);
+  if (!aName.IsEmpty())
+    return NS_OK;
+
+  // Use table caption as a name.
+  Accessible* caption = Caption();
+  if (caption) {
+    nsIContent* captionContent = caption->GetContent();
+    if (captionContent) {
+      nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
+      if (!aName.IsEmpty())
+        return NS_OK;
+    }
+  }
+
+  // If no caption then use summary as a name.
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
+  return NS_OK;
+}
+
+nsresult
+HTMLTableAccessible::GetAttributesInternal(nsIPersistentProperties* aAttributes)
+{
+  nsresult rv = AccessibleWrap::GetAttributesInternal(aAttributes);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (IsProbablyLayoutTable()) {
+    nsAutoString oldValueUnused;
+    aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
+                                   NS_LITERAL_STRING("true"), oldValueUnused);
+  }
+
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessible: nsIAccessible implementation
+
+Relation
+HTMLTableAccessible::RelationByType(PRUint32 aType)
+{
+  Relation rel = AccessibleWrap::RelationByType(aType);
+  if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
+    rel.AppendTarget(Caption());
+
+  return rel;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessible: nsIAccessibleTable implementation
+
+Accessible*
+HTMLTableAccessible::Caption()
+{
+  Accessible* child = mChildren.SafeElementAt(0, nsnull);
+  return child && child->Role() == roles::CAPTION ? child : nsnull;
+}
+
+void
+HTMLTableAccessible::Summary(nsString& aSummary)
+{
+  nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mContent));
+
+  if (table)
+    table->GetSummary(aSummary);
+}
+
+PRUint32
+HTMLTableAccessible::ColCount()
+{
+  nsITableLayout* tableLayout = GetTableLayout();
+  if (!tableLayout)
+    return 0;
+
+  PRInt32 rowCount = 0, colCount = 0;
+  tableLayout->GetTableSize(rowCount, colCount);
+  return colCount;
+}
+
+PRUint32
+HTMLTableAccessible::RowCount()
+{
+  nsITableLayout* tableLayout = GetTableLayout();
+  if (!tableLayout)
+    return 0;
+
+  PRInt32 rowCount = 0, colCount = 0;
+  tableLayout->GetTableSize(rowCount, colCount);
+  return rowCount;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  PRInt32 rowCount = 0;
+  nsresult rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsCOMPtr<nsIDOMElement> domElement;
+  PRInt32 startRowIndex = 0, startColIndex = 0,
+    rowSpan, colSpan, actualRowSpan, actualColSpan;
+  bool isSelected = false;
+
+  PRInt32 rowIndex;
+  for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
+    PRInt32 columnIndex;
+    for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
+      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
+                                      *getter_AddRefs(domElement),
+                                      startRowIndex, startColIndex,
+                                      rowSpan, colSpan,
+                                      actualRowSpan, actualColSpan,
+                                      isSelected);
+
+      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
+          startColIndex == columnIndex && isSelected) {
+        (*aCount)++;
+      }
+    }
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedColumnCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  PRInt32 count = 0;
+  nsresult rv = GetColumnCount(&count);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 index;
+  for (index = 0; index < count; index++) {
+    bool state = false;
+    rv = IsColumnSelected(index, &state);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (state)
+      (*aCount)++;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedRowCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  PRInt32 count = 0;
+  nsresult rv = GetRowCount(&count);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 index;
+  for (index = 0; index < count; index++) {
+    bool state = false;
+    rv = IsRowSelected(index, &state);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (state)
+      (*aCount)++;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedCells(nsIArray** aCells)
+{
+  NS_ENSURE_ARG_POINTER(aCells);
+  *aCells = nsnull;
+
+  PRInt32 rowCount = 0;
+  nsresult rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsCOMPtr<nsIMutableArray> selCells =
+    do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIDOMElement> cellElement;
+  PRInt32 startRowIndex = 0, startColIndex = 0,
+    rowSpan, colSpan, actualRowSpan, actualColSpan;
+  bool isSelected = false;
+
+  PRInt32 rowIndex, index;
+  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
+    PRInt32 columnIndex;
+    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
+      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
+                                      *getter_AddRefs(cellElement),
+                                      startRowIndex, startColIndex,
+                                      rowSpan, colSpan,
+                                      actualRowSpan, actualColSpan,
+                                      isSelected);
+
+      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
+          startColIndex == columnIndex && isSelected) {
+        nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
+        Accessible* cell = mDoc->GetAccessible(cellContent);
+        selCells->AppendElement(static_cast<nsIAccessible*>(cell), false);
+      }
+    }
+  }
+
+  NS_ADDREF(*aCells = selCells);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedCellIndices(PRUint32* aNumCells,
+                                            PRInt32** aCells)
+{
+  NS_ENSURE_ARG_POINTER(aNumCells);
+  *aNumCells = 0;
+  NS_ENSURE_ARG_POINTER(aCells);
+  *aCells = nsnull;
+
+  PRInt32 rowCount = 0;
+  nsresult rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsCOMPtr<nsIDOMElement> domElement;
+  PRInt32 startRowIndex = 0, startColIndex = 0,
+    rowSpan, colSpan, actualRowSpan, actualColSpan;
+  bool isSelected = false;
+
+  PRInt32 cellsCount = columnCount * rowCount;
+  nsAutoArrayPtr<bool> states(new bool[cellsCount]);
+  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
+
+  PRInt32 rowIndex, index;
+  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
+    PRInt32 columnIndex;
+    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
+      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
+                                      *getter_AddRefs(domElement),
+                                      startRowIndex, startColIndex,
+                                      rowSpan, colSpan,
+                                      actualRowSpan, actualColSpan,
+                                      isSelected);
+
+      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
+          startColIndex == columnIndex && isSelected) {
+        states[index] = true;
+        (*aNumCells)++;
+      } else {
+        states[index] = false;
+      }
+    }
+  }
+
+  PRInt32 *cellsArray =
+    static_cast<PRInt32*>(nsMemory::Alloc((*aNumCells) * sizeof(PRInt32)));
+  NS_ENSURE_TRUE(cellsArray, NS_ERROR_OUT_OF_MEMORY);
+
+  PRInt32 curr = 0;
+  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
+    PRInt32 columnIndex;
+    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
+      if (states[index]) {
+        PRInt32 cellIndex = -1;
+        GetCellIndexAt(rowIndex, columnIndex, &cellIndex);
+        cellsArray[curr++] = cellIndex;
+      }
+    }
+  }
+
+  *aCells = cellsArray;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedColumnIndices(PRUint32* aNumColumns,
+                                              PRInt32** aColumns)
+{
+  nsresult rv = NS_OK;
+
+  PRInt32 columnCount;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  bool *states = new bool[columnCount];
+  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
+
+  *aNumColumns = 0;
+  PRInt32 index;
+  for (index = 0; index < columnCount; index++) {
+    rv = IsColumnSelected(index, &states[index]);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (states[index]) {
+      (*aNumColumns)++;
+    }
+  }
+
+  PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumColumns) * sizeof(PRInt32));
+  if (!outArray) {
+    delete []states;
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  PRInt32 curr = 0;
+  for (index = 0; index < columnCount; index++) {
+    if (states[index]) {
+      outArray[curr++] = index;
+    }
+  }
+
+  delete []states;
+  *aColumns = outArray;
+  return rv;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetSelectedRowIndices(PRUint32* aNumRows,
+                                           PRInt32** aRows)
+{
+  nsresult rv = NS_OK;
+
+  PRInt32 rowCount;
+  rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  bool *states = new bool[rowCount];
+  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
+
+  *aNumRows = 0;
+  PRInt32 index;
+  for (index = 0; index < rowCount; index++) {
+    rv = IsRowSelected(index, &states[index]);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (states[index]) {
+      (*aNumRows)++;
+    }
+  }
+
+  PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumRows) * sizeof(PRInt32));
+  if (!outArray) {
+    delete []states;
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  PRInt32 curr = 0;
+  for (index = 0; index < rowCount; index++) {
+    if (states[index]) {
+      outArray[curr++] = index;
+    }
+  }
+
+  delete []states;
+  *aRows = outArray;
+  return rv;
+}
+
+Accessible*
+HTMLTableAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
+{ 
+  nsCOMPtr<nsIDOMElement> cellElement;
+  GetCellAt(aRowIndex, aColumnIndex, *getter_AddRefs(cellElement));
+  if (!cellElement)
+    return nsnull;
+
+  nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
+  if (!cellContent)
+    return nsnull;
+
+  Accessible* cell = mDoc->GetAccessible(cellContent);
+
+  // XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
+  // return itself as a cell what makes Orca hang.
+  return cell == this ? nsnull : cell;
+}
+
+PRInt32
+HTMLTableAccessible::CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx)
+{
+  nsITableLayout* tableLayout = GetTableLayout();
+
+  PRInt32 index = -1;
+  tableLayout->GetIndexByRowAndColumn(aRowIdx, aColIdx, &index);
+  return index;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32* aColumn)
+{
+  NS_ENSURE_ARG_POINTER(aColumn);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  PRInt32 row;
+  nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32* aRow)
+{
+  NS_ENSURE_ARG_POINTER(aRow);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  PRInt32 column;
+  nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetRowAndColumnIndicesAt(PRInt32 aIndex,
+                                              PRInt32* aRowIdx,
+                                              PRInt32* aColumnIdx)
+{
+  NS_ENSURE_ARG_POINTER(aRowIdx);
+  *aRowIdx = -1;
+  NS_ENSURE_ARG_POINTER(aColumnIdx);
+  *aColumnIdx = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsITableLayout* tableLayout = GetTableLayout();
+  if (tableLayout)
+    tableLayout->GetRowAndColumnByIndex(aIndex, aRowIdx, aColumnIdx);
+
+  return (*aRowIdx == -1 || *aColumnIdx == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
+}
+
+PRUint32
+HTMLTableAccessible::ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
+{
+  nsITableLayout* tableLayout = GetTableLayout();
+  if (!tableLayout)
+    return 0;
+
+  nsCOMPtr<nsIDOMElement> domElement;
+  PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan;
+  bool isSelected;
+  PRInt32 columnExtent = 0;
+
+  nsresult rv = tableLayout->
+    GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
+                  startRowIndex, startColIndex, rowSpan, colSpan,
+                  actualRowSpan, columnExtent, isSelected);
+
+  return columnExtent;
+}
+
+PRUint32
+HTMLTableAccessible::RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
+{
+  nsITableLayout* tableLayout = GetTableLayout();
+  if (!tableLayout)
+    return 0;
+
+  nsCOMPtr<nsIDOMElement> domElement;
+  PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualColSpan;
+  bool isSelected;
+  PRInt32 rowExtent = 0;
+
+  nsresult rv = tableLayout->
+    GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
+                  startRowIndex, startColIndex, rowSpan, colSpan,
+                  rowExtent, actualColSpan, isSelected);
+
+  return rowExtent;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetColumnDescription(PRInt32 aColumn, nsAString& _retval)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::GetRowDescription(PRInt32 aRow, nsAString& _retval)
+{
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  PRInt32 colCount = 0;
+  nsresult rv = GetColumnCount(&colCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (aColumn < 0 || aColumn >= colCount)
+    return NS_ERROR_INVALID_ARG;
+
+  PRInt32 rowCount = 0;
+  rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  for (PRInt32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
+    bool isSelected = false;
+    rv = IsCellSelected(rowIdx, aColumn, &isSelected);
+    if (NS_SUCCEEDED(rv)) {
+      *aIsSelected = isSelected;
+      if (!isSelected)
+        break;
+    }
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::IsRowSelected(PRInt32 aRow, bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  PRInt32 rowCount = 0;
+  nsresult rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (aRow < 0 || aRow >= rowCount)
+    return NS_ERROR_INVALID_ARG;
+
+  PRInt32 colCount = 0;
+  rv = GetColumnCount(&colCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++) {
+    bool isSelected = false;
+    rv = IsCellSelected(aRow, colIdx, &isSelected);
+    if (NS_SUCCEEDED(rv)) {
+      *aIsSelected = isSelected;
+      if (!isSelected)
+        break;
+    }
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::IsCellSelected(PRInt32 aRow, PRInt32 aColumn,
+                                    bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsCOMPtr<nsIDOMElement> domElement;
+  PRInt32 startRowIndex = 0, startColIndex = 0,
+          rowSpan, colSpan, actualRowSpan, actualColSpan;
+
+  nsresult rv = tableLayout->
+    GetCellDataAt(aRow, aColumn, *getter_AddRefs(domElement),
+                  startRowIndex, startColIndex, rowSpan, colSpan,
+                  actualRowSpan, actualColSpan, *aIsSelected);
+
+  if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
+    return NS_ERROR_INVALID_ARG;
+  return rv;
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::SelectRow(PRInt32 aRow)
+{
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsresult rv =
+    RemoveRowsOrColumnsFromSelection(aRow,
+                                     nsISelectionPrivate::TABLESELECTION_ROW,
+                                     true);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return AddRowOrColumnToSelection(aRow,
+                                   nsISelectionPrivate::TABLESELECTION_ROW);
+}
+
+NS_IMETHODIMP
+HTMLTableAccessible::SelectColumn(PRInt32 aColumn)
+{
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsresult rv =
+    RemoveRowsOrColumnsFromSelection(aColumn,
+                                     nsISelectionPrivate::TABLESELECTION_COLUMN,
+                                     true);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return AddRowOrColumnToSelection(aColumn,
+                                   nsISelectionPrivate::TABLESELECTION_COLUMN);
+}
+
+void
+HTMLTableAccessible::UnselectRow(PRUint32 aRowIdx)
+{
+  RemoveRowsOrColumnsFromSelection(aRowIdx,
+                                   nsISelectionPrivate::TABLESELECTION_ROW,
+                                   false);
+}
+
+void
+HTMLTableAccessible::UnselectCol(PRUint32 aColIdx)
+{
+  RemoveRowsOrColumnsFromSelection(aColIdx,
+                                   nsISelectionPrivate::TABLESELECTION_COLUMN,
+                                   false);
+}
+
+nsresult
+HTMLTableAccessible::AddRowOrColumnToSelection(PRInt32 aIndex, PRUint32 aTarget)
+{
+  bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsCOMPtr<nsIDOMElement> cellElm;
+  PRInt32 startRowIdx, startColIdx, rowSpan, colSpan,
+    actualRowSpan, actualColSpan;
+  bool isSelected = false;
+
+  nsresult rv = NS_OK;
+  PRInt32 count = 0;
+  if (doSelectRow)
+    rv = GetColumnCount(&count);
+  else
+    rv = GetRowCount(&count);
+
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsIPresShell* presShell(mDoc->PresShell());
+  nsRefPtr<nsFrameSelection> tableSelection =
+    const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
+
+  for (PRInt32 idx = 0; idx < count; idx++) {
+    PRInt32 rowIdx = doSelectRow ? aIndex : idx;
+    PRInt32 colIdx = doSelectRow ? idx : aIndex;
+    rv = tableLayout->GetCellDataAt(rowIdx, colIdx,
+                                    *getter_AddRefs(cellElm),
+                                    startRowIdx, startColIdx,
+                                    rowSpan, colSpan,
+                                    actualRowSpan, actualColSpan,
+                                    isSelected);
+
+    if (NS_SUCCEEDED(rv) && !isSelected) {
+      nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElm));
+      rv = tableSelection->SelectCellElement(cellContent);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+  }
+
+  return NS_OK;
+}
+
+nsresult
+HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
+                                                      PRUint32 aTarget,
+                                                      bool aIsOuter)
+{
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsIPresShell* presShell(mDoc->PresShell());
+  nsRefPtr<nsFrameSelection> tableSelection =
+    const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
+
+  bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
+  PRInt32 count = 0;
+  nsresult rv = doUnselectRow ? GetColumnCount(&count) : GetRowCount(&count);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 startRowIdx = doUnselectRow ? aIndex : 0;
+  PRInt32 endRowIdx = doUnselectRow ? aIndex : count - 1;
+  PRInt32 startColIdx = doUnselectRow ? 0 : aIndex;
+  PRInt32 endColIdx = doUnselectRow ? count - 1 : aIndex;
+
+  if (aIsOuter)
+    return tableSelection->RestrictCellsToSelection(mContent,
+                                                    startRowIdx, startColIdx,
+                                                    endRowIdx, endColIdx);
+
+  return tableSelection->RemoveCellsFromSelection(mContent,
+                                                  startRowIdx, startColIdx,
+                                                  endRowIdx, endColIdx);
+}
+
+nsITableLayout*
+HTMLTableAccessible::GetTableLayout()
+{
+  nsIFrame *frame = mContent->GetPrimaryFrame();
+  if (!frame)
+    return nsnull;
+
+  nsITableLayout *tableLayout = do_QueryFrame(frame);
+  return tableLayout;
+}
+
+nsresult
+HTMLTableAccessible::GetCellAt(PRInt32 aRowIndex, PRInt32 aColIndex,
+                               nsIDOMElement*& aCell)
+{
+  PRInt32 startRowIndex = 0, startColIndex = 0,
+          rowSpan, colSpan, actualRowSpan, actualColSpan;
+  bool isSelected;
+
+  nsITableLayout *tableLayout = GetTableLayout();
+  NS_ENSURE_STATE(tableLayout);
+
+  nsresult rv = tableLayout->
+    GetCellDataAt(aRowIndex, aColIndex, aCell, startRowIndex, startColIndex,
+                  rowSpan, colSpan, actualRowSpan, actualColSpan, isSelected);
+
+  if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
+    return NS_ERROR_INVALID_ARG;
+  return rv;
+}
+
+void
+HTMLTableAccessible::Description(nsString& aDescription)
+{
+  // Helpful for debugging layout vs. data tables
+  aDescription.Truncate();
+  Accessible::Description(aDescription);
+  if (!aDescription.IsEmpty())
+    return;
+
+  // Use summary as description if it weren't used as a name.
+  // XXX: get rid code duplication with NameInternal().
+  Accessible* caption = Caption();
+  if (caption) {
+    nsIContent* captionContent = caption->GetContent();
+    if (captionContent) {
+      nsAutoString captionText;
+      nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
+                                                   &captionText);
+
+      if (!captionText.IsEmpty()) { // summary isn't used as a name.
+        mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
+                          aDescription);
+      }
+    }
+  }
+
+#ifdef SHOW_LAYOUT_HEURISTIC
+  if (aDescription.IsEmpty()) {
+    bool isProbablyForLayout = IsProbablyLayoutTable();
+    aDescription = mLayoutHeuristic;
+  }
+  printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
+#endif
+}
+
+bool
+HTMLTableAccessible::HasDescendant(const nsAString& aTagName, bool aAllowEmpty)
+{
+  nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
+  NS_ENSURE_TRUE(tableElt, false);
+
+  nsCOMPtr<nsIDOMNodeList> nodeList;
+  tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
+  NS_ENSURE_TRUE(nodeList, false);
+
+  nsCOMPtr<nsIDOMNode> foundItem;
+  nodeList->Item(0, getter_AddRefs(foundItem));
+  if (!foundItem)
+    return false;
+
+  if (aAllowEmpty)
+    return true;
+
+  // Make sure that the item we found has contents and either has multiple
+  // children or the found item is not a whitespace-only text node.
+  nsCOMPtr<nsIContent> foundItemContent = do_QueryInterface(foundItem);
+  if (foundItemContent->GetChildCount() > 1)
+    return true; // Treat multiple child nodes as non-empty
+
+  nsIContent *innerItemContent = foundItemContent->GetFirstChild();
+  if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
+    return true;
+
+  // If we found more than one node then return true not depending on
+  // aAllowEmpty flag.
+  // XXX it might be dummy but bug 501375 where we changed this addresses
+  // performance problems only. Note, currently 'aAllowEmpty' flag is used for
+  // caption element only. On another hand we create accessible object for
+  // the first entry of caption element (see
+  // HTMLTableAccessible::CacheChildren).
+  nodeList->Item(1, getter_AddRefs(foundItem));
+  return !!foundItem;
+}
+
+bool
+HTMLTableAccessible::IsProbablyLayoutTable()
+{
+  // Implement a heuristic to determine if table is most likely used for layout
+  // XXX do we want to look for rowspan or colspan, especialy that span all but a couple cells
+  // at the beginning or end of a row/col, and especially when they occur at the edge of a table?
+  // XXX expose this info via object attributes to AT-SPI
+
+  // XXX For now debugging descriptions are always on via SHOW_LAYOUT_HEURISTIC
+  // This will allow release trunk builds to be used by testers to refine the algorithm
+  // Change to |#define SHOW_LAYOUT_HEURISTIC DEBUG| before final release
+#ifdef SHOW_LAYOUT_HEURISTIC
+#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) \
+  { \
+    mLayoutHeuristic = isLayout ? \
+      NS_LITERAL_STRING("layout table: " heuristic) : \
+      NS_LITERAL_STRING("data table: " heuristic); \
+    return isLayout; \
+  }
+#else
+#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
+#endif
+
+  DocAccessible* docAccessible = Document();
+  if (docAccessible) {
+    PRUint64 docState = docAccessible->State();
+    if (docState & states::EDITABLE) {  // Need to see all elements while document is being edited
+      RETURN_LAYOUT_ANSWER(false, "In editable document");
+    }
+  }
+
+  // Check to see if an ARIA role overrides the role from native markup,
+  // but for which we still expose table semantics (treegrid, for example).
+  if (Role() != roles::TABLE)
+    RETURN_LAYOUT_ANSWER(false, "Has role attribute");
+
+  if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
+    // Role attribute is present, but overridden roles have already been dealt with.
+    // Only landmarks and other roles that don't override the role from native
+    // markup are left to deal with here.
+    RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
+  }
+
+  if (mContent->Tag() != nsGkAtoms::table)
+    RETURN_LAYOUT_ANSWER(true, "table built by CSS display:table style");
+
+  // Check if datatable attribute has "0" value.
+  if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::datatable,
+                            NS_LITERAL_STRING("0"), eCaseMatters)) {
+    RETURN_LAYOUT_ANSWER(true, "Has datatable = 0 attribute, it's for layout");
+  }
+
+  // Check for legitimate data table attributes.
+  nsAutoString summary;
+  if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, summary) &&
+      !summary.IsEmpty())
+    RETURN_LAYOUT_ANSWER(false, "Has summary -- legitimate table structures");
+
+  // Check for legitimate data table elements.
+  Accessible* caption = FirstChild();
+  if (caption && caption->Role() == roles::CAPTION && caption->HasChildren()) 
+    RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
+
+  for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
+       childElm = childElm->GetNextSibling()) {
+    if (!childElm->IsHTML())
+      continue;
+
+    if (childElm->Tag() == nsGkAtoms::col ||
+        childElm->Tag() == nsGkAtoms::colgroup ||
+        childElm->Tag() == nsGkAtoms::tfoot ||
+        childElm->Tag() == nsGkAtoms::thead) {
+      RETURN_LAYOUT_ANSWER(false,
+                           "Has col, colgroup, tfoot or thead -- legitimate table structures");
+    }
+
+    if (childElm->Tag() == nsGkAtoms::tbody) {
+      for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
+           rowElm = rowElm->GetNextSibling()) {
+        if (rowElm->IsHTML() && rowElm->Tag() == nsGkAtoms::tr) {
+          for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
+               cellElm = cellElm->GetNextSibling()) {
+            if (cellElm->IsHTML()) {
+
+              if (cellElm->NodeInfo()->Equals(nsGkAtoms::th)) {
+                RETURN_LAYOUT_ANSWER(false,
+                                     "Has th -- legitimate table structures");
+              }
+
+              if (cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::headers) ||
+                  cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::scope) ||
+                  cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::abbr)) {
+                RETURN_LAYOUT_ANSWER(false,
+                                     "Has headers, scope, or abbr attribute -- legitimate table structures");
+              }
+
+              Accessible* cell = mDoc->GetAccessible(cellElm);
+              if (cell && cell->ChildCount() == 1 &&
+                  cell->FirstChild()->IsAbbreviation()) {
+                RETURN_LAYOUT_ANSWER(false,
+                                     "has abbr -- legitimate table structures");
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+
+  if (HasDescendant(NS_LITERAL_STRING("table"))) {
+    RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
+  }
+
+  // If only 1 column or only 1 row, it's for layout
+  PRInt32 columns, rows;
+  GetColumnCount(&columns);
+  if (columns <=1) {
+    RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
+  }
+  GetRowCount(&rows);
+  if (rows <=1) {
+    RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
+  }
+
+  // Check for many columns
+  if (columns >= 5) {
+    RETURN_LAYOUT_ANSWER(false, ">=5 columns");
+  }
+
+  // Now we know there are 2-4 columns and 2 or more rows
+  // Check to see if there are visible borders on the cells
+  // XXX currently, we just check the first cell -- do we really need to do more?
+  nsCOMPtr<nsIDOMElement> cellElement;
+  nsresult rv = GetCellAt(0, 0, *getter_AddRefs(cellElement));
+  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+
+  nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
+  NS_ENSURE_TRUE(cellContent, NS_ERROR_FAILURE);
+  nsIFrame *cellFrame = cellContent->GetPrimaryFrame();
+  if (!cellFrame) {
+    return NS_OK;
+  }
+  nsMargin border;
+  cellFrame->GetBorder(border);
+  if (border.top && border.bottom && border.left && border.right) {
+    RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
+  }
+
+  /**
+   * Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
+   */
+
+  // Check for styled background color across rows (alternating background
+  // color is a common feature for data tables).
+  PRUint32 childCount = ChildCount();
+  nscolor rowColor, prevRowColor;
+  for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
+    Accessible* child = GetChildAt(childIdx);
+    if (child->Role() == roles::ROW) {
+      prevRowColor = rowColor;
+      nsIFrame* rowFrame = child->GetFrame();
+      rowColor = rowFrame->GetStyleBackground()->mBackgroundColor;
+
+      if (childIdx > 0 && prevRowColor != rowColor)
+        RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered");
+    }
+  }
+
+  // Check for many rows
+  const PRInt32 kMaxLayoutRows = 20;
+  if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
+    RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
+  }
+
+  // Check for very wide table.
+  nsIFrame* documentFrame = Document()->GetFrame();
+  nsSize documentSize = documentFrame->GetSize();
+  if (documentSize.width > 0) {
+    nsSize tableSize = GetFrame()->GetSize();
+    PRInt32 percentageOfDocWidth = (100 * tableSize.width) / documentSize.width;
+    if (percentageOfDocWidth > 95) {
+      // 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
+      // Probably for layout
+      RETURN_LAYOUT_ANSWER(true,
+                           "<= 4 columns, table width is 95% of document width");
+    }
+  }
+
+  // Two column rules
+  if (rows * columns <= 10) {
+    RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
+  }
+
+  if (HasDescendant(NS_LITERAL_STRING("embed")) ||
+      HasDescendant(NS_LITERAL_STRING("object")) ||
+      HasDescendant(NS_LITERAL_STRING("applet")) ||
+      HasDescendant(NS_LITERAL_STRING("iframe"))) {
+    RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
+  }
+
+  RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLCaptionAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+Relation
+HTMLCaptionAccessible::RelationByType(PRUint32 aType)
+{
+  Relation rel = HyperTextAccessible::RelationByType(aType);
+  if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR)
+    rel.AppendTarget(Parent());
+
+  return rel;
+}
+
+role
+HTMLCaptionAccessible::NativeRole()
+{
+  return roles::CAPTION;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/html/HTMLTableAccessible.h
@@ -0,0 +1,201 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HTMLTableAccessible_h__
+#define mozilla_a11y_HTMLTableAccessible_h__
+
+#include "HyperTextAccessibleWrap.h"
+#include "nsIAccessibleTable.h"
+#include "TableAccessible.h"
+#include "xpcAccessibleTable.h"
+
+class nsITableLayout;
+class nsITableCellLayout;
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * HTML table cell accessible (html:td).
+ */
+class HTMLTableCellAccessible : public HyperTextAccessibleWrap,
+                                public nsIAccessibleTableCell
+{
+public:
+  HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIAccessibleTableCell
+  NS_DECL_NSIACCESSIBLETABLECELL
+
+  // Accessible
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+  virtual PRUint64 NativeInteractiveState() const;
+  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
+
+protected:
+  /**
+   * Return host table accessible.
+   */
+  already_AddRefed<nsIAccessibleTable> GetTableAccessible();
+
+  /**
+   * Return nsITableCellLayout of the table cell frame.
+   */
+  nsITableCellLayout* GetCellLayout();
+
+  /**
+   * Return row and column indices of the cell.
+   */
+  nsresult GetCellIndexes(PRInt32& aRowIdx, PRInt32& aColIdx);
+
+  /**
+   * Return an array of row or column header cells.
+   */
+  nsresult GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
+                          nsIArray **aHeaderCells);
+};
+
+
+/**
+ * HTML table row/column header accessible (html:th or html:td@scope).
+ */
+class HTMLTableHeaderCellAccessible : public HTMLTableCellAccessible
+{
+public:
+  HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // Accessible
+  virtual a11y::role NativeRole();
+};
+
+
+/**
+ * HTML table accessible (html:table).
+ */
+
+// To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC
+// This allow release trunk builds to be used by testers to refine the
+// data vs. layout heuristic
+// #define SHOW_LAYOUT_HEURISTIC
+
+class HTMLTableAccessible : public AccessibleWrap,
+                            public xpcAccessibleTable,
+                            public nsIAccessibleTable,
+                            public TableAccessible
+{
+public:
+  HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIAccessible Table
+  NS_DECL_OR_FORWARD_NSIACCESSIBLETABLE_WITH_XPCACCESSIBLETABLE
+
+  // TableAccessible
+  virtual Accessible* Caption();
+  virtual void Summary(nsString& aSummary);
+  virtual PRUint32 ColCount();
+  virtual PRUint32 RowCount();
+  virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
+  virtual PRInt32 CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual void UnselectCol(PRUint32 aColIdx);
+  virtual void UnselectRow(PRUint32 aRowIdx);
+  virtual bool IsProbablyLayoutTable();
+
+  // nsAccessNode
+  virtual void Shutdown();
+
+  // Accessible
+  virtual mozilla::a11y::TableAccessible* AsTable() { return this; }
+  virtual void Description(nsString& aDescription);
+  virtual nsresult GetNameInternal(nsAString& aName);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
+  virtual Relation RelationByType(PRUint32 aRelationType);
+
+  // HTMLTableAccessible
+
+  /**
+   * Retun cell element at the given row and column index.
+   */
+  nsresult GetCellAt(PRInt32 aRowIndex, PRInt32 aColIndex,
+                     nsIDOMElement* &aCell);
+
+  /**
+   * Return nsITableLayout for the frame of the accessible table.
+   */
+  nsITableLayout* GetTableLayout();
+
+protected:
+
+  // Accessible
+  virtual void CacheChildren();
+
+  // HTMLTableAccessible
+
+  /**
+   * Add row or column to selection.
+   *
+   * @param aIndex   [in] index of row or column to be selected
+   * @param aTarget  [in] indicates what should be selected, either row or column
+   *                  (see nsISelectionPrivate)
+   */
+  nsresult AddRowOrColumnToSelection(PRInt32 aIndex, PRUint32 aTarget);
+
+  /**
+   * Removes rows or columns at the given index or outside it from selection.
+   *
+   * @param  aIndex    [in] row or column index
+   * @param  aTarget   [in] indicates whether row or column should unselected
+   * @param  aIsOuter  [in] indicates whether all rows or column excepting
+   *                    the given one should be unselected or the given one
+   *                    should be unselected only
+   */
+  nsresult RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
+                                            PRUint32 aTarget,
+                                            bool aIsOuter);
+
+  /**
+   * Return true if table has an element with the given tag name.
+   *
+   * @param  aTagName     [in] tag name of searched element
+   * @param  aAllowEmpty  [in, optional] points if found element can be empty
+   *                       or contain whitespace text only.
+   */
+  bool HasDescendant(const nsAString& aTagName, bool aAllowEmpty = true);
+
+#ifdef SHOW_LAYOUT_HEURISTIC
+  nsString mLayoutHeuristic;
+#endif
+};
+
+/**
+ * HTML caption accessible (html:caption).
+ */
+class HTMLCaptionAccessible : public HyperTextAccessibleWrap
+{
+public:
+  HTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+    HyperTextAccessibleWrap(aContent, aDoc) { }
+  virtual ~HTMLCaptionAccessible() { }
+
+  // nsIAccessible
+
+  // Accessible
+  virtual a11y::role NativeRole();
+  virtual Relation RelationByType(PRUint32 aRelationType);
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
--- a/accessible/src/html/Makefile.in
+++ b/accessible/src/html/Makefile.in
@@ -19,17 +19,17 @@ LIBXUL_LIBRARY = 1
 CPPSRCS = \
   HTMLCanvasAccessible.cpp \
   HTMLElementAccessibles.cpp \
   HTMLFormControlAccessible.cpp \
   HTMLImageMapAccessible.cpp \
   HTMLLinkAccessible.cpp \
   HTMLListAccessible.cpp \
   HTMLSelectAccessible.cpp \
-  nsHTMLTableAccessible.cpp \
+  HTMLTableAccessible.cpp \
   $(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = \
deleted file mode 100644
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ /dev/null
@@ -1,1529 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsHTMLTableAccessible.h"
-
-#include "Accessible-inl.h"
-#include "nsAccessibilityService.h"
-#include "nsAccTreeWalker.h"
-#include "nsAccUtils.h"
-#include "DocAccessible.h"
-#include "nsTextEquivUtils.h"
-#include "Relation.h"
-#include "Role.h"
-#include "States.h"
-
-#include "nsIAccessibleRelation.h"
-#include "nsIDOMElement.h"
-#include "nsIDOMDocument.h"
-#include "nsIDOMRange.h"
-#include "nsISelectionPrivate.h"
-#include "nsINameSpaceManager.h"
-#include "nsIDOMNodeList.h"
-#include "nsIDOMHTMLCollection.h"
-#include "nsIDOMHTMLTableCellElement.h"
-#include "nsIDOMHTMLTableElement.h"
-#include "nsIDOMHTMLTableRowElement.h"
-#include "nsIDOMHTMLTableSectionElem.h"
-#include "nsIDocument.h"
-#include "nsIPresShell.h"
-#include "nsITableLayout.h"
-#include "nsITableCellLayout.h"
-#include "nsFrameSelection.h"
-#include "nsLayoutErrors.h"
-#include "nsArrayUtils.h"
-#include "nsComponentManagerUtils.h"
-
-using namespace mozilla::a11y;
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessible
-////////////////////////////////////////////////////////////////////////////////
-
-nsHTMLTableCellAccessible::
-  nsHTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
-  HyperTextAccessibleWrap(aContent, aDoc)
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessible: nsISupports implementation
-
-NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableCellAccessible,
-                             HyperTextAccessible,
-                             nsIAccessibleTableCell)
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessible: Accessible implementation
-
-role
-nsHTMLTableCellAccessible::NativeRole()
-{
-  return roles::CELL;
-}
-
-PRUint64
-nsHTMLTableCellAccessible::NativeState()
-{
-  PRUint64 state = HyperTextAccessibleWrap::NativeState();
-
-  nsIFrame *frame = mContent->GetPrimaryFrame();
-  NS_ASSERTION(frame, "No frame for valid cell accessible!");
-
-  if (frame && frame->IsSelected())
-    state |= states::SELECTED;
-
-  return state;
-}
-
-PRUint64
-nsHTMLTableCellAccessible::NativeInteractiveState() const
-{
-  return HyperTextAccessibleWrap::NativeInteractiveState() | states::SELECTABLE;
-}
-
-nsresult
-nsHTMLTableCellAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
-{
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsresult rv = HyperTextAccessibleWrap::GetAttributesInternal(aAttributes);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // table-cell-index attribute
-  nsCOMPtr<nsIAccessibleTable> tableAcc(GetTableAccessible());
-  if (!tableAcc)
-    return NS_OK;
-
-  PRInt32 rowIdx = -1, colIdx = -1;
-  rv = GetCellIndexes(rowIdx, colIdx);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 idx = -1;
-  rv = tableAcc->GetCellIndexAt(rowIdx, colIdx, &idx);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoString stringIdx;
-  stringIdx.AppendInt(idx);
-  nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex, stringIdx);
-
-  // abbr attribute
-
-  // Pick up object attribute from abbr DOM element (a child of the cell) or
-  // from abbr DOM attribute.
-  nsAutoString abbrText;
-  if (ChildCount() == 1) {
-    Accessible* abbr = FirstChild();
-    if (abbr->IsAbbreviation()) {
-      nsTextEquivUtils::
-        AppendTextEquivFromTextContent(abbr->GetContent()->GetFirstChild(),
-                                       &abbrText);
-    }
-  }
-  if (abbrText.IsEmpty())
-    mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, abbrText);
-
-  if (!abbrText.IsEmpty())
-    nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::abbr, abbrText);
-
-  // axis attribute
-  nsAutoString axisText;
-  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText);
-  if (!axisText.IsEmpty())
-    nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::axis, axisText);
-
-  return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessible: nsIAccessibleTableCell implementation
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetTable(nsIAccessibleTable **aTable)
-{
-  NS_ENSURE_ARG_POINTER(aTable);
-  *aTable = nsnull;
-
-  if (IsDefunct())
-    return NS_OK;
-
-  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
-  table.swap(*aTable);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetColumnIndex(PRInt32 *aColumnIndex)
-{
-  NS_ENSURE_ARG_POINTER(aColumnIndex);
-  *aColumnIndex = -1;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsITableCellLayout* cellLayout = GetCellLayout();
-  NS_ENSURE_STATE(cellLayout);
-
-  return cellLayout->GetColIndex(*aColumnIndex);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetRowIndex(PRInt32 *aRowIndex)
-{
-  NS_ENSURE_ARG_POINTER(aRowIndex);
-  *aRowIndex = -1;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsITableCellLayout* cellLayout = GetCellLayout();
-  NS_ENSURE_STATE(cellLayout);
-
-  return cellLayout->GetRowIndex(*aRowIndex);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetColumnExtent(PRInt32 *aExtentCount)
-{
-  NS_ENSURE_ARG_POINTER(aExtentCount);
-  *aExtentCount = 1;
-
-  PRInt32 rowIdx = -1, colIdx = -1;
-  GetCellIndexes(rowIdx, colIdx);
-
-  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
-  NS_ENSURE_STATE(table);
-
-  return table->GetColumnExtentAt(rowIdx, colIdx, aExtentCount);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetRowExtent(PRInt32 *aExtentCount)
-{
-  NS_ENSURE_ARG_POINTER(aExtentCount);
-  *aExtentCount = 1;
-
-  PRInt32 rowIdx = -1, colIdx = -1;
-  GetCellIndexes(rowIdx, colIdx);
-
-  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
-  NS_ENSURE_STATE(table);
-
-  return table->GetRowExtentAt(rowIdx, colIdx, aExtentCount);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetColumnHeaderCells(nsIArray **aHeaderCells)
-{
-  NS_ENSURE_ARG_POINTER(aHeaderCells);
-  *aHeaderCells = nsnull;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  return GetHeaderCells(nsAccUtils::eColumnHeaderCells, aHeaderCells);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::GetRowHeaderCells(nsIArray **aHeaderCells)
-{
-  NS_ENSURE_ARG_POINTER(aHeaderCells);
-  *aHeaderCells = nsnull;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  return GetHeaderCells(nsAccUtils::eRowHeaderCells, aHeaderCells);
-}
-
-NS_IMETHODIMP
-nsHTMLTableCellAccessible::IsSelected(bool *aIsSelected)
-{
-  NS_ENSURE_ARG_POINTER(aIsSelected);
-  *aIsSelected = false;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  PRInt32 rowIdx = -1, colIdx = -1;
-  GetCellIndexes(rowIdx, colIdx);
-
-  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
-  NS_ENSURE_STATE(table);
-
-  return table->IsCellSelected(rowIdx, colIdx, aIsSelected);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessible: protected implementation
-
-already_AddRefed<nsIAccessibleTable>
-nsHTMLTableCellAccessible::GetTableAccessible()
-{
-  Accessible* parent = this;
-  while ((parent = parent->Parent())) {
-    roles::Role role = parent->Role();
-    if (role == roles::TABLE || role == roles::TREE_TABLE) {
-      nsIAccessibleTable* tableAcc = nsnull;
-      CallQueryInterface(parent, &tableAcc);
-      return tableAcc;
-    }
-  }
-
-  return nsnull;
-}
-
-nsITableCellLayout*
-nsHTMLTableCellAccessible::GetCellLayout()
-{
-  nsIFrame *frame = mContent->GetPrimaryFrame();
-  NS_ASSERTION(frame, "The frame cannot be obtaied for HTML table cell.");
-  if (!frame)
-    return nsnull;
-
-  nsITableCellLayout *cellLayout = do_QueryFrame(frame);
-  return cellLayout;
-}
-
-nsresult
-nsHTMLTableCellAccessible::GetCellIndexes(PRInt32& aRowIndex,
-                                          PRInt32& aColIndex)
-{
-  nsITableCellLayout *cellLayout = GetCellLayout();
-  NS_ENSURE_STATE(cellLayout);
-
-  return cellLayout->GetCellIndexes(aRowIndex, aColIndex);
-}
-
-nsresult
-nsHTMLTableCellAccessible::GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
-                                          nsIArray **aHeaderCells)
-{
-  // Get header cells from @header attribute.
-  IDRefsIterator iter(mDoc, mContent, nsGkAtoms::headers);
-  nsIContent* headerCellElm = iter.NextElem();
-  if (headerCellElm) {
-    nsresult rv = NS_OK;
-    nsCOMPtr<nsIMutableArray> headerCells =
-      do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    roles::Role desiredRole = static_cast<roles::Role>(-1) ;
-    if (aRowOrColumnHeaderCell == nsAccUtils::eRowHeaderCells)
-      desiredRole = roles::ROWHEADER;
-    else if (aRowOrColumnHeaderCell == nsAccUtils::eColumnHeaderCells)
-      desiredRole = roles::COLUMNHEADER;
-
-    do {
-      Accessible* headerCell = mDoc->GetAccessible(headerCellElm);
-
-      if (headerCell && headerCell->Role() == desiredRole)
-        headerCells->AppendElement(static_cast<nsIAccessible*>(headerCell),
-                                   false);
-    } while ((headerCellElm = iter.NextElem()));
-
-    NS_ADDREF(*aHeaderCells = headerCells);
-    return NS_OK;
-  }
-
-  // Otherwise calculate header cells from hierarchy (see 11.4.3 "Algorithm to
-  // find heading information" of w3c HTML 4.01).
-  nsCOMPtr<nsIAccessibleTable> table = GetTableAccessible();
-  if (table) {
-    return nsAccUtils::GetHeaderCellsFor(table, this, aRowOrColumnHeaderCell,
-                                         aHeaderCells);
-  }
-
-  return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableHeaderAccessible
-////////////////////////////////////////////////////////////////////////////////
-
-nsHTMLTableHeaderCellAccessible::
-  nsHTMLTableHeaderCellAccessible(nsIContent* aContent,
-                                  DocAccessible* aDoc) :
-  nsHTMLTableCellAccessible(aContent, aDoc)
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableHeaderAccessible: Accessible implementation
-
-role
-nsHTMLTableHeaderCellAccessible::NativeRole()
-{
-  // Check value of @scope attribute.
-  static nsIContent::AttrValuesArray scopeValues[] =
-    {&nsGkAtoms::col, &nsGkAtoms::row, nsnull};
-  PRInt32 valueIdx =
-    mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::scope,
-                              scopeValues, eCaseMatters);
-
-  switch (valueIdx) {
-    case 0:
-      return roles::COLUMNHEADER;
-    case 1:
-      return roles::ROWHEADER;
-  }
-
-  // Assume it's columnheader if there are headers in siblings, oterwise
-  // rowheader.
-  nsIContent* parentContent = mContent->GetParent();
-  if (!parentContent) {
-    NS_ERROR("Deattached content on alive accessible?");
-    return roles::NOTHING;
-  }
-
-  for (nsIContent* siblingContent = mContent->GetPreviousSibling(); siblingContent;
-       siblingContent = siblingContent->GetPreviousSibling()) {
-    if (siblingContent->IsElement()) {
-      return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
-	     roles::COLUMNHEADER : roles::ROWHEADER;
-    }
-  }
-
-  for (nsIContent* siblingContent = mContent->GetNextSibling(); siblingContent;
-       siblingContent = siblingContent->GetNextSibling()) {
-    if (siblingContent->IsElement()) {
-      return nsCoreUtils::IsHTMLTableHeader(siblingContent) ?
-	     roles::COLUMNHEADER : roles::ROWHEADER;
-    }
-  }
-
-  // No elements in siblings what means the table has one column only. Therefore
-  // it should be column header.
-  return roles::COLUMNHEADER;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessible
-////////////////////////////////////////////////////////////////////////////////
-
-nsHTMLTableAccessible::
-  nsHTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
-  AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessible: nsISupports implementation
-
-NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableAccessible, Accessible,
-                             nsIAccessibleTable)
-
-////////////////////////////////////////////////////////////////////////////////
-//nsAccessNode
-
-void
-nsHTMLTableAccessible::Shutdown()
-{
-  mTable = nsnull;
-  AccessibleWrap::Shutdown();
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessible: Accessible implementation
-
-void
-nsHTMLTableAccessible::CacheChildren()
-{
-  // Move caption accessible so that it's the first child. Check for the first
-  // caption only, because nsAccessibilityService ensures we don't create
-  // accessibles for the other captions, since only the first is actually
-  // visible.
-  nsAccTreeWalker walker(mDoc, mContent, CanHaveAnonChildren());
-
-  Accessible* child = nsnull;
-  while ((child = walker.NextChild())) {
-    if (child->Role() == roles::CAPTION) {
-      InsertChildAt(0, child);
-      while ((child = walker.NextChild()) && AppendChild(child));
-      break;
-    }
-    AppendChild(child);
-  }
-}
-
-role
-nsHTMLTableAccessible::NativeRole()
-{
-  return roles::TABLE;
-}
-
-PRUint64
-nsHTMLTableAccessible::NativeState()
-{
-  return Accessible::NativeState() | states::READONLY;
-}
-
-nsresult
-nsHTMLTableAccessible::GetNameInternal(nsAString& aName)
-{
-  Accessible::GetNameInternal(aName);
-  if (!aName.IsEmpty())
-    return NS_OK;
-
-  // Use table caption as a name.
-  Accessible* caption = Caption();
-  if (caption) {
-    nsIContent* captionContent = caption->GetContent();
-    if (captionContent) {
-      nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
-      if (!aName.IsEmpty())
-        return NS_OK;
-    }
-  }
-
-  // If no caption then use summary as a name.
-  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName);
-  return NS_OK;
-}
-
-nsresult
-nsHTMLTableAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
-{
-  nsresult rv = AccessibleWrap::GetAttributesInternal(aAttributes);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (IsProbablyLayoutTable()) {
-    nsAutoString oldValueUnused;
-    aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
-                                   NS_LITERAL_STRING("true"), oldValueUnused);
-  }
-
-  return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessible: nsIAccessible implementation
-
-Relation
-nsHTMLTableAccessible::RelationByType(PRUint32 aType)
-{
-  Relation rel = AccessibleWrap::RelationByType(aType);
-  if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
-    rel.AppendTarget(Caption());
-
-  return rel;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessible: nsIAccessibleTable implementation
-
-Accessible*
-nsHTMLTableAccessible::Caption()
-{
-  Accessible* child = mChildren.SafeElementAt(0, nsnull);
-  return child && child->Role() == roles::CAPTION ? child : nsnull;
-}
-
-void
-nsHTMLTableAccessible::Summary(nsString& aSummary)
-{
-  nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mContent));
-
-  if (table)
-    table->GetSummary(aSummary);
-}
-
-PRUint32
-nsHTMLTableAccessible::ColCount()
-{
-  nsITableLayout* tableLayout = GetTableLayout();
-  if (!tableLayout)
-    return 0;
-
-  PRInt32 rowCount = 0, colCount = 0;
-  tableLayout->GetTableSize(rowCount, colCount);
-  return colCount;
-}
-
-PRUint32
-nsHTMLTableAccessible::RowCount()
-{
-  nsITableLayout* tableLayout = GetTableLayout();
-  if (!tableLayout)
-    return 0;
-
-  PRInt32 rowCount = 0, colCount = 0;
-  tableLayout->GetTableSize(rowCount, colCount);
-  return rowCount;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
-{
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsCOMPtr<nsIDOMElement> domElement;
-  PRInt32 startRowIndex = 0, startColIndex = 0,
-    rowSpan, colSpan, actualRowSpan, actualColSpan;
-  bool isSelected = false;
-
-  PRInt32 rowIndex;
-  for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
-    PRInt32 columnIndex;
-    for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
-      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
-                                      *getter_AddRefs(domElement),
-                                      startRowIndex, startColIndex,
-                                      rowSpan, colSpan,
-                                      actualRowSpan, actualColSpan,
-                                      isSelected);
-
-      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
-          startColIndex == columnIndex && isSelected) {
-        (*aCount)++;
-      }
-    }
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedColumnCount(PRUint32* aCount)
-{
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRInt32 count = 0;
-  nsresult rv = GetColumnCount(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 index;
-  for (index = 0; index < count; index++) {
-    bool state = false;
-    rv = IsColumnSelected(index, &state);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (state)
-      (*aCount)++;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedRowCount(PRUint32* aCount)
-{
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRInt32 count = 0;
-  nsresult rv = GetRowCount(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 index;
-  for (index = 0; index < count; index++) {
-    bool state = false;
-    rv = IsRowSelected(index, &state);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (state)
-      (*aCount)++;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedCells(nsIArray **aCells)
-{
-  NS_ENSURE_ARG_POINTER(aCells);
-  *aCells = nsnull;
-
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsCOMPtr<nsIMutableArray> selCells =
-    do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMElement> cellElement;
-  PRInt32 startRowIndex = 0, startColIndex = 0,
-    rowSpan, colSpan, actualRowSpan, actualColSpan;
-  bool isSelected = false;
-
-  PRInt32 rowIndex, index;
-  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
-    PRInt32 columnIndex;
-    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
-      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
-                                      *getter_AddRefs(cellElement),
-                                      startRowIndex, startColIndex,
-                                      rowSpan, colSpan,
-                                      actualRowSpan, actualColSpan,
-                                      isSelected);
-
-      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
-          startColIndex == columnIndex && isSelected) {
-        nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
-        Accessible* cell = mDoc->GetAccessible(cellContent);
-        selCells->AppendElement(static_cast<nsIAccessible*>(cell), false);
-      }
-    }
-  }
-
-  NS_ADDREF(*aCells = selCells);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedCellIndices(PRUint32 *aNumCells,
-                                              PRInt32 **aCells)
-{
-  NS_ENSURE_ARG_POINTER(aNumCells);
-  *aNumCells = 0;
-  NS_ENSURE_ARG_POINTER(aCells);
-  *aCells = nsnull;
-
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsCOMPtr<nsIDOMElement> domElement;
-  PRInt32 startRowIndex = 0, startColIndex = 0,
-    rowSpan, colSpan, actualRowSpan, actualColSpan;
-  bool isSelected = false;
-
-  PRInt32 cellsCount = columnCount * rowCount;
-  nsAutoArrayPtr<bool> states(new bool[cellsCount]);
-  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
-
-  PRInt32 rowIndex, index;
-  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
-    PRInt32 columnIndex;
-    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
-      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
-                                      *getter_AddRefs(domElement),
-                                      startRowIndex, startColIndex,
-                                      rowSpan, colSpan,
-                                      actualRowSpan, actualColSpan,
-                                      isSelected);
-
-      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
-          startColIndex == columnIndex && isSelected) {
-        states[index] = true;
-        (*aNumCells)++;
-      } else {
-        states[index] = false;
-      }
-    }
-  }
-
-  PRInt32 *cellsArray =
-    static_cast<PRInt32*>(nsMemory::Alloc((*aNumCells) * sizeof(PRInt32)));
-  NS_ENSURE_TRUE(cellsArray, NS_ERROR_OUT_OF_MEMORY);
-
-  PRInt32 curr = 0;
-  for (rowIndex = 0, index = 0; rowIndex < rowCount; rowIndex++) {
-    PRInt32 columnIndex;
-    for (columnIndex = 0; columnIndex < columnCount; columnIndex++, index++) {
-      if (states[index]) {
-        PRInt32 cellIndex = -1;
-        GetCellIndexAt(rowIndex, columnIndex, &cellIndex);
-        cellsArray[curr++] = cellIndex;
-      }
-    }
-  }
-
-  *aCells = cellsArray;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedColumnIndices(PRUint32 *aNumColumns,
-                                                PRInt32 **aColumns)
-{
-  nsresult rv = NS_OK;
-
-  PRInt32 columnCount;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  bool *states = new bool[columnCount];
-  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
-
-  *aNumColumns = 0;
-  PRInt32 index;
-  for (index = 0; index < columnCount; index++) {
-    rv = IsColumnSelected(index, &states[index]);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (states[index]) {
-      (*aNumColumns)++;
-    }
-  }
-
-  PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumColumns) * sizeof(PRInt32));
-  if (!outArray) {
-    delete []states;
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  PRInt32 curr = 0;
-  for (index = 0; index < columnCount; index++) {
-    if (states[index]) {
-      outArray[curr++] = index;
-    }
-  }
-
-  delete []states;
-  *aColumns = outArray;
-  return rv;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetSelectedRowIndices(PRUint32 *aNumRows,
-                                             PRInt32 **aRows)
-{
-  nsresult rv = NS_OK;
-
-  PRInt32 rowCount;
-  rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  bool *states = new bool[rowCount];
-  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);
-
-  *aNumRows = 0;
-  PRInt32 index;
-  for (index = 0; index < rowCount; index++) {
-    rv = IsRowSelected(index, &states[index]);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (states[index]) {
-      (*aNumRows)++;
-    }
-  }
-
-  PRInt32 *outArray = (PRInt32 *)nsMemory::Alloc((*aNumRows) * sizeof(PRInt32));
-  if (!outArray) {
-    delete []states;
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  PRInt32 curr = 0;
-  for (index = 0; index < rowCount; index++) {
-    if (states[index]) {
-      outArray[curr++] = index;
-    }
-  }
-
-  delete []states;
-  *aRows = outArray;
-  return rv;
-}
-
-Accessible*
-nsHTMLTableAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
-{ 
-  nsCOMPtr<nsIDOMElement> cellElement;
-  GetCellAt(aRowIndex, aColumnIndex, *getter_AddRefs(cellElement));
-  if (!cellElement)
-    return nsnull;
-
-  nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
-  if (!cellContent)
-    return nsnull;
-
-  Accessible* cell = mDoc->GetAccessible(cellContent);
-
-  // XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
-  // return itself as a cell what makes Orca hang.
-  return cell == this ? nsnull : cell;
-}
-
-PRInt32
-nsHTMLTableAccessible::CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx)
-{
-  nsITableLayout* tableLayout = GetTableLayout();
-
-  PRInt32 index = -1;
-  tableLayout->GetIndexByRowAndColumn(aRowIdx, aColIdx, &index);
-  return index;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32 *aColumn)
-{
-  NS_ENSURE_ARG_POINTER(aColumn);
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  PRInt32 row;
-  nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32 *aRow)
-{
-  NS_ENSURE_ARG_POINTER(aRow);
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  PRInt32 column;
-  nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetRowAndColumnIndicesAt(PRInt32 aIndex,
-                                                PRInt32* aRowIdx,
-                                                PRInt32* aColumnIdx)
-{
-  NS_ENSURE_ARG_POINTER(aRowIdx);
-  *aRowIdx = -1;
-  NS_ENSURE_ARG_POINTER(aColumnIdx);
-  *aColumnIdx = -1;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsITableLayout* tableLayout = GetTableLayout();
-  if (tableLayout)
-    tableLayout->GetRowAndColumnByIndex(aIndex, aRowIdx, aColumnIdx);
-
-  return (*aRowIdx == -1 || *aColumnIdx == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
-}
-
-PRUint32
-nsHTMLTableAccessible::ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
-{
-  nsITableLayout* tableLayout = GetTableLayout();
-  if (!tableLayout)
-    return 0;
-
-  nsCOMPtr<nsIDOMElement> domElement;
-  PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan;
-  bool isSelected;
-  PRInt32 columnExtent = 0;
-
-  nsresult rv = tableLayout->
-    GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
-                  startRowIndex, startColIndex, rowSpan, colSpan,
-                  actualRowSpan, columnExtent, isSelected);
-
-  return columnExtent;
-}
-
-PRUint32
-nsHTMLTableAccessible::RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx)
-{
-  nsITableLayout* tableLayout = GetTableLayout();
-  if (!tableLayout)
-    return 0;
-
-  nsCOMPtr<nsIDOMElement> domElement;
-  PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualColSpan;
-  bool isSelected;
-  PRInt32 rowExtent = 0;
-
-  nsresult rv = tableLayout->
-    GetCellDataAt(aRowIdx, aColIdx, *getter_AddRefs(domElement),
-                  startRowIndex, startColIndex, rowSpan, colSpan,
-                  rowExtent, actualColSpan, isSelected);
-
-  return rowExtent;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetColumnDescription(PRInt32 aColumn, nsAString &_retval)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::GetRowDescription(PRInt32 aRow, nsAString &_retval)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, bool *aIsSelected)
-{
-  NS_ENSURE_ARG_POINTER(aIsSelected);
-  *aIsSelected = false;
-
-  PRInt32 colCount = 0;
-  nsresult rv = GetColumnCount(&colCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (aColumn < 0 || aColumn >= colCount)
-    return NS_ERROR_INVALID_ARG;
-
-  PRInt32 rowCount = 0;
-  rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  for (PRInt32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
-    bool isSelected = false;
-    rv = IsCellSelected(rowIdx, aColumn, &isSelected);
-    if (NS_SUCCEEDED(rv)) {
-      *aIsSelected = isSelected;
-      if (!isSelected)
-        break;
-    }
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::IsRowSelected(PRInt32 aRow, bool *aIsSelected)
-{
-  NS_ENSURE_ARG_POINTER(aIsSelected);
-  *aIsSelected = false;
-
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (aRow < 0 || aRow >= rowCount)
-    return NS_ERROR_INVALID_ARG;
-
-  PRInt32 colCount = 0;
-  rv = GetColumnCount(&colCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++) {
-    bool isSelected = false;
-    rv = IsCellSelected(aRow, colIdx, &isSelected);
-    if (NS_SUCCEEDED(rv)) {
-      *aIsSelected = isSelected;
-      if (!isSelected)
-        break;
-    }
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::IsCellSelected(PRInt32 aRow, PRInt32 aColumn,
-                                      bool *aIsSelected)
-{
-  NS_ENSURE_ARG_POINTER(aIsSelected);
-  *aIsSelected = false;
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsCOMPtr<nsIDOMElement> domElement;
-  PRInt32 startRowIndex = 0, startColIndex = 0,
-          rowSpan, colSpan, actualRowSpan, actualColSpan;
-
-  nsresult rv = tableLayout->
-    GetCellDataAt(aRow, aColumn, *getter_AddRefs(domElement),
-                  startRowIndex, startColIndex, rowSpan, colSpan,
-                  actualRowSpan, actualColSpan, *aIsSelected);
-
-  if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
-    return NS_ERROR_INVALID_ARG;
-  return rv;
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::SelectRow(PRInt32 aRow)
-{
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsresult rv =
-    RemoveRowsOrColumnsFromSelection(aRow,
-                                     nsISelectionPrivate::TABLESELECTION_ROW,
-                                     true);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return AddRowOrColumnToSelection(aRow,
-                                   nsISelectionPrivate::TABLESELECTION_ROW);
-}
-
-NS_IMETHODIMP
-nsHTMLTableAccessible::SelectColumn(PRInt32 aColumn)
-{
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  nsresult rv =
-    RemoveRowsOrColumnsFromSelection(aColumn,
-                                     nsISelectionPrivate::TABLESELECTION_COLUMN,
-                                     true);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return AddRowOrColumnToSelection(aColumn,
-                                   nsISelectionPrivate::TABLESELECTION_COLUMN);
-}
-
-void
-nsHTMLTableAccessible::UnselectRow(PRUint32 aRowIdx)
-{
-  RemoveRowsOrColumnsFromSelection(aRowIdx,
-                                   nsISelectionPrivate::TABLESELECTION_ROW,
-                                   false);
-}
-
-void
-nsHTMLTableAccessible::UnselectCol(PRUint32 aColIdx)
-{
-  RemoveRowsOrColumnsFromSelection(aColIdx,
-                                   nsISelectionPrivate::TABLESELECTION_COLUMN,
-                                   false);
-}
-
-nsresult
-nsHTMLTableAccessible::AddRowOrColumnToSelection(PRInt32 aIndex,
-                                                 PRUint32 aTarget)
-{
-  bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsCOMPtr<nsIDOMElement> cellElm;
-  PRInt32 startRowIdx, startColIdx, rowSpan, colSpan,
-    actualRowSpan, actualColSpan;
-  bool isSelected = false;
-
-  nsresult rv = NS_OK;
-  PRInt32 count = 0;
-  if (doSelectRow)
-    rv = GetColumnCount(&count);
-  else
-    rv = GetRowCount(&count);
-
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsIPresShell* presShell(mDoc->PresShell());
-  nsRefPtr<nsFrameSelection> tableSelection =
-    const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
-
-  for (PRInt32 idx = 0; idx < count; idx++) {
-    PRInt32 rowIdx = doSelectRow ? aIndex : idx;
-    PRInt32 colIdx = doSelectRow ? idx : aIndex;
-    rv = tableLayout->GetCellDataAt(rowIdx, colIdx,
-                                    *getter_AddRefs(cellElm),
-                                    startRowIdx, startColIdx,
-                                    rowSpan, colSpan,
-                                    actualRowSpan, actualColSpan,
-                                    isSelected);
-
-    if (NS_SUCCEEDED(rv) && !isSelected) {
-      nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElm));
-      rv = tableSelection->SelectCellElement(cellContent);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLTableAccessible::RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
-                                                        PRUint32 aTarget,
-                                                        bool aIsOuter)
-{
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsIPresShell* presShell(mDoc->PresShell());
-  nsRefPtr<nsFrameSelection> tableSelection =
-    const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());
-
-  bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
-  PRInt32 count = 0;
-  nsresult rv = doUnselectRow ? GetColumnCount(&count) : GetRowCount(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 startRowIdx = doUnselectRow ? aIndex : 0;
-  PRInt32 endRowIdx = doUnselectRow ? aIndex : count - 1;
-  PRInt32 startColIdx = doUnselectRow ? 0 : aIndex;
-  PRInt32 endColIdx = doUnselectRow ? count - 1 : aIndex;
-
-  if (aIsOuter)
-    return tableSelection->RestrictCellsToSelection(mContent,
-                                                    startRowIdx, startColIdx,
-                                                    endRowIdx, endColIdx);
-
-  return tableSelection->RemoveCellsFromSelection(mContent,
-                                                  startRowIdx, startColIdx,
-                                                  endRowIdx, endColIdx);
-}
-
-nsITableLayout*
-nsHTMLTableAccessible::GetTableLayout()
-{
-  nsIFrame *frame = mContent->GetPrimaryFrame();
-  if (!frame)
-    return nsnull;
-
-  nsITableLayout *tableLayout = do_QueryFrame(frame);
-  return tableLayout;
-}
-
-nsresult
-nsHTMLTableAccessible::GetCellAt(PRInt32        aRowIndex,
-                                 PRInt32        aColIndex,
-                                 nsIDOMElement* &aCell)
-{
-  PRInt32 startRowIndex = 0, startColIndex = 0,
-          rowSpan, colSpan, actualRowSpan, actualColSpan;
-  bool isSelected;
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
-
-  nsresult rv = tableLayout->
-    GetCellDataAt(aRowIndex, aColIndex, aCell, startRowIndex, startColIndex,
-                  rowSpan, colSpan, actualRowSpan, actualColSpan, isSelected);
-
-  if (rv == NS_TABLELAYOUT_CELL_NOT_FOUND)
-    return NS_ERROR_INVALID_ARG;
-  return rv;
-}
-
-void
-nsHTMLTableAccessible::Description(nsString& aDescription)
-{
-  // Helpful for debugging layout vs. data tables
-  aDescription.Truncate();
-  Accessible::Description(aDescription);
-  if (!aDescription.IsEmpty())
-    return;
-
-  // Use summary as description if it weren't used as a name.
-  // XXX: get rid code duplication with NameInternal().
-  Accessible* caption = Caption();
-  if (caption) {
-    nsIContent* captionContent = caption->GetContent();
-    if (captionContent) {
-      nsAutoString captionText;
-      nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent,
-                                                   &captionText);
-
-      if (!captionText.IsEmpty()) { // summary isn't used as a name.
-        mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary,
-                          aDescription);
-      }
-    }
-  }
-
-#ifdef SHOW_LAYOUT_HEURISTIC
-  if (aDescription.IsEmpty()) {
-    bool isProbablyForLayout = IsProbablyLayoutTable();
-    aDescription = mLayoutHeuristic;
-  }
-  printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
-#endif
-}
-
-bool
-nsHTMLTableAccessible::HasDescendant(const nsAString& aTagName,
-                                     bool aAllowEmpty)
-{
-  nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mContent));
-  NS_ENSURE_TRUE(tableElt, false);
-
-  nsCOMPtr<nsIDOMNodeList> nodeList;
-  tableElt->GetElementsByTagName(aTagName, getter_AddRefs(nodeList));
-  NS_ENSURE_TRUE(nodeList, false);
-
-  nsCOMPtr<nsIDOMNode> foundItem;
-  nodeList->Item(0, getter_AddRefs(foundItem));
-  if (!foundItem)
-    return false;
-
-  if (aAllowEmpty)
-    return true;
-
-  // Make sure that the item we found has contents and either has multiple
-  // children or the found item is not a whitespace-only text node.
-  nsCOMPtr<nsIContent> foundItemContent = do_QueryInterface(foundItem);
-  if (foundItemContent->GetChildCount() > 1)
-    return true; // Treat multiple child nodes as non-empty
-
-  nsIContent *innerItemContent = foundItemContent->GetFirstChild();
-  if (innerItemContent && !innerItemContent->TextIsOnlyWhitespace())
-    return true;
-
-  // If we found more than one node then return true not depending on
-  // aAllowEmpty flag.
-  // XXX it might be dummy but bug 501375 where we changed this addresses
-  // performance problems only. Note, currently 'aAllowEmpty' flag is used for
-  // caption element only. On another hand we create accessible object for
-  // the first entry of caption element (see
-  // nsHTMLTableAccessible::CacheChildren).
-  nodeList->Item(1, getter_AddRefs(foundItem));
-  return !!foundItem;
-}
-
-bool
-nsHTMLTableAccessible::IsProbablyLayoutTable()
-{
-  // Implement a heuristic to determine if table is most likely used for layout
-  // XXX do we want to look for rowspan or colspan, especialy that span all but a couple cells
-  // at the beginning or end of a row/col, and especially when they occur at the edge of a table?
-  // XXX expose this info via object attributes to AT-SPI
-
-  // XXX For now debugging descriptions are always on via SHOW_LAYOUT_HEURISTIC
-  // This will allow release trunk builds to be used by testers to refine the algorithm
-  // Change to |#define SHOW_LAYOUT_HEURISTIC DEBUG| before final release
-#ifdef SHOW_LAYOUT_HEURISTIC
-#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) \
-  { \
-    mLayoutHeuristic = isLayout ? \
-      NS_LITERAL_STRING("layout table: " heuristic) : \
-      NS_LITERAL_STRING("data table: " heuristic); \
-    return isLayout; \
-  }
-#else
-#define RETURN_LAYOUT_ANSWER(isLayout, heuristic) { return isLayout; }
-#endif
-
-  DocAccessible* docAccessible = Document();
-  if (docAccessible) {
-    PRUint64 docState = docAccessible->State();
-    if (docState & states::EDITABLE) {  // Need to see all elements while document is being edited
-      RETURN_LAYOUT_ANSWER(false, "In editable document");
-    }
-  }
-
-  // Check to see if an ARIA role overrides the role from native markup,
-  // but for which we still expose table semantics (treegrid, for example).
-  if (Role() != roles::TABLE)
-    RETURN_LAYOUT_ANSWER(false, "Has role attribute");
-
-  if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::role)) {
-    // Role attribute is present, but overridden roles have already been dealt with.
-    // Only landmarks and other roles that don't override the role from native
-    // markup are left to deal with here.
-    RETURN_LAYOUT_ANSWER(false, "Has role attribute, weak role, and role is table");
-  }
-
-  if (mContent->Tag() != nsGkAtoms::table)
-    RETURN_LAYOUT_ANSWER(true, "table built by CSS display:table style");
-
-  // Check if datatable attribute has "0" value.
-  if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::datatable,
-                            NS_LITERAL_STRING("0"), eCaseMatters)) {
-    RETURN_LAYOUT_ANSWER(true, "Has datatable = 0 attribute, it's for layout");
-  }
-
-  // Check for legitimate data table attributes.
-  nsAutoString summary;
-  if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, summary) &&
-      !summary.IsEmpty())
-    RETURN_LAYOUT_ANSWER(false, "Has summary -- legitimate table structures");
-
-  // Check for legitimate data table elements.
-  Accessible* caption = FirstChild();
-  if (caption && caption->Role() == roles::CAPTION && caption->HasChildren()) 
-    RETURN_LAYOUT_ANSWER(false, "Not empty caption -- legitimate table structures");
-
-  for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
-       childElm = childElm->GetNextSibling()) {
-    if (!childElm->IsHTML())
-      continue;
-
-    if (childElm->Tag() == nsGkAtoms::col ||
-        childElm->Tag() == nsGkAtoms::colgroup ||
-        childElm->Tag() == nsGkAtoms::tfoot ||
-        childElm->Tag() == nsGkAtoms::thead) {
-      RETURN_LAYOUT_ANSWER(false,
-                           "Has col, colgroup, tfoot or thead -- legitimate table structures");
-    }
-
-    if (childElm->Tag() == nsGkAtoms::tbody) {
-      for (nsIContent* rowElm = childElm->GetFirstChild(); rowElm;
-           rowElm = rowElm->GetNextSibling()) {
-        if (rowElm->IsHTML() && rowElm->Tag() == nsGkAtoms::tr) {
-          for (nsIContent* cellElm = rowElm->GetFirstChild(); cellElm;
-               cellElm = cellElm->GetNextSibling()) {
-            if (cellElm->IsHTML()) {
-
-              if (cellElm->NodeInfo()->Equals(nsGkAtoms::th)) {
-                RETURN_LAYOUT_ANSWER(false,
-                                     "Has th -- legitimate table structures");
-              }
-
-              if (cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::headers) ||
-                  cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::scope) ||
-                  cellElm->HasAttr(kNameSpaceID_None, nsGkAtoms::abbr)) {
-                RETURN_LAYOUT_ANSWER(false,
-                                     "Has headers, scope, or abbr attribute -- legitimate table structures");
-              }
-
-              Accessible* cell = mDoc->GetAccessible(cellElm);
-              if (cell && cell->ChildCount() == 1 &&
-                  cell->FirstChild()->IsAbbreviation()) {
-                RETURN_LAYOUT_ANSWER(false,
-                                     "has abbr -- legitimate table structures");
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-
-  if (HasDescendant(NS_LITERAL_STRING("table"))) {
-    RETURN_LAYOUT_ANSWER(true, "Has a nested table within it");
-  }
-
-  // If only 1 column or only 1 row, it's for layout
-  PRInt32 columns, rows;
-  GetColumnCount(&columns);
-  if (columns <=1) {
-    RETURN_LAYOUT_ANSWER(true, "Has only 1 column");
-  }
-  GetRowCount(&rows);
-  if (rows <=1) {
-    RETURN_LAYOUT_ANSWER(true, "Has only 1 row");
-  }
-
-  // Check for many columns
-  if (columns >= 5) {
-    RETURN_LAYOUT_ANSWER(false, ">=5 columns");
-  }
-
-  // Now we know there are 2-4 columns and 2 or more rows
-  // Check to see if there are visible borders on the cells
-  // XXX currently, we just check the first cell -- do we really need to do more?
-  nsCOMPtr<nsIDOMElement> cellElement;
-  nsresult rv = GetCellAt(0, 0, *getter_AddRefs(cellElement));
-  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIContent> cellContent(do_QueryInterface(cellElement));
-  NS_ENSURE_TRUE(cellContent, NS_ERROR_FAILURE);
-  nsIFrame *cellFrame = cellContent->GetPrimaryFrame();
-  if (!cellFrame) {
-    return NS_OK;
-  }
-  nsMargin border;
-  cellFrame->GetBorder(border);
-  if (border.top && border.bottom && border.left && border.right) {
-    RETURN_LAYOUT_ANSWER(false, "Has nonzero border-width on table cell");
-  }
-
-  /**
-   * Rules for non-bordered tables with 2-4 columns and 2+ rows from here on forward
-   */
-
-  // Check for styled background color across rows (alternating background
-  // color is a common feature for data tables).
-  PRUint32 childCount = ChildCount();
-  nscolor rowColor, prevRowColor;
-  for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
-    Accessible* child = GetChildAt(childIdx);
-    if (child->Role() == roles::ROW) {
-      prevRowColor = rowColor;
-      nsIFrame* rowFrame = child->GetFrame();
-      rowColor = rowFrame->GetStyleBackground()->mBackgroundColor;
-
-      if (childIdx > 0 && prevRowColor != rowColor)
-        RETURN_LAYOUT_ANSWER(false, "2 styles of row background color, non-bordered");
-    }
-  }
-
-  // Check for many rows
-  const PRInt32 kMaxLayoutRows = 20;
-  if (rows > kMaxLayoutRows) { // A ton of rows, this is probably for data
-    RETURN_LAYOUT_ANSWER(false, ">= kMaxLayoutRows (20) and non-bordered");
-  }
-
-  // Check for very wide table.
-  nsIFrame* documentFrame = Document()->GetFrame();
-  nsSize documentSize = documentFrame->GetSize();
-  if (documentSize.width > 0) {
-    nsSize tableSize = GetFrame()->GetSize();
-    PRInt32 percentageOfDocWidth = (100 * tableSize.width) / documentSize.width;
-    if (percentageOfDocWidth > 95) {
-      // 3-4 columns, no borders, not a lot of rows, and 95% of the doc's width
-      // Probably for layout
-      RETURN_LAYOUT_ANSWER(true,
-                           "<= 4 columns, table width is 95% of document width");
-    }
-  }
-
-  // Two column rules
-  if (rows * columns <= 10) {
-    RETURN_LAYOUT_ANSWER(true, "2-4 columns, 10 cells or less, non-bordered");
-  }
-
-  if (HasDescendant(NS_LITERAL_STRING("embed")) ||
-      HasDescendant(NS_LITERAL_STRING("object")) ||
-      HasDescendant(NS_LITERAL_STRING("applet")) ||
-      HasDescendant(NS_LITERAL_STRING("iframe"))) {
-    RETURN_LAYOUT_ANSWER(true, "Has no borders, and has iframe, object, applet or iframe, typical of advertisements");
-  }
-
-  RETURN_LAYOUT_ANSWER(false, "no layout factor strong enough, so will guess data");
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLCaptionAccessible
-////////////////////////////////////////////////////////////////////////////////
-
-Relation
-nsHTMLCaptionAccessible::RelationByType(PRUint32 aType)
-{
-  Relation rel = HyperTextAccessible::RelationByType(aType);
-  if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR)
-    rel.AppendTarget(Parent());
-
-  return rel;
-}
-
-role
-nsHTMLCaptionAccessible::NativeRole()
-{
-  return roles::CAPTION;
-}
deleted file mode 100644
--- a/accessible/src/html/nsHTMLTableAccessible.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _nsHTMLTableAccessible_H_
-#define _nsHTMLTableAccessible_H_
-
-#include "HyperTextAccessibleWrap.h"
-#include "nsIAccessibleTable.h"
-#include "TableAccessible.h"
-#include "xpcAccessibleTable.h"
-
-class nsITableLayout;
-class nsITableCellLayout;
-
-/**
- * HTML table cell accessible (html:td).
- */
-class nsHTMLTableCellAccessible : public HyperTextAccessibleWrap,
-                                  public nsIAccessibleTableCell
-{
-public:
-  nsHTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIAccessibleTableCell
-  NS_DECL_NSIACCESSIBLETABLECELL
-
-  // Accessible
-  virtual mozilla::a11y::role NativeRole();
-  virtual PRUint64 NativeState();
-  virtual PRUint64 NativeInteractiveState() const;
-  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
-
-protected:
-  /**
-   * Return host table accessible.
-   */
-  already_AddRefed<nsIAccessibleTable> GetTableAccessible();
-
-  /**
-   * Return nsITableCellLayout of the table cell frame.
-   */
-  nsITableCellLayout* GetCellLayout();
-
-  /**
-   * Return row and column indices of the cell.
-   */
-  nsresult GetCellIndexes(PRInt32& aRowIdx, PRInt32& aColIdx);
-
-  /**
-   * Return an array of row or column header cells.
-   */
-  nsresult GetHeaderCells(PRInt32 aRowOrColumnHeaderCell,
-                          nsIArray **aHeaderCells);
-};
-
-
-/**
- * HTML table row/column header accessible (html:th or html:td@scope).
- */
-class nsHTMLTableHeaderCellAccessible : public nsHTMLTableCellAccessible
-{
-public:
-  nsHTMLTableHeaderCellAccessible(nsIContent* aContent,
-                                  DocAccessible* aDoc);
-
-  // Accessible
-  virtual mozilla::a11y::role NativeRole();
-};
-
-
-/**
- * HTML table accessible (html:table).
- */
-
-// To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC
-// This allow release trunk builds to be used by testers to refine the
-// data vs. layout heuristic
-// #define SHOW_LAYOUT_HEURISTIC
-
-class nsHTMLTableAccessible : public AccessibleWrap,
-                              public xpcAccessibleTable,
-                              public nsIAccessibleTable,
-                              public mozilla::a11y::TableAccessible
-{
-public:
-  nsHTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc);
-
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIAccessible Table
-  NS_DECL_OR_FORWARD_NSIACCESSIBLETABLE_WITH_XPCACCESSIBLETABLE
-
-  // TableAccessible
-  virtual Accessible* Caption();
-  virtual void Summary(nsString& aSummary);
-  virtual PRUint32 ColCount();
-  virtual PRUint32 RowCount();
-  virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
-  virtual PRInt32 CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx);
-  virtual PRUint32 ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
-  virtual PRUint32 RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
-  virtual void UnselectCol(PRUint32 aColIdx);
-  virtual void UnselectRow(PRUint32 aRowIdx);
-  virtual bool IsProbablyLayoutTable();
-
-  // nsAccessNode
-  virtual void Shutdown();
-
-  // Accessible
-  virtual mozilla::a11y::TableAccessible* AsTable() { return this; }
-  virtual void Description(nsString& aDescription);
-  virtual nsresult GetNameInternal(nsAString& aName);
-  virtual mozilla::a11y::role NativeRole();
-  virtual PRUint64 NativeState();
-  virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
-  virtual Relation RelationByType(PRUint32 aRelationType);
-
-  // nsHTMLTableAccessible
-
-  /**
-   * Retun cell element at the given row and column index.
-   */
-  nsresult GetCellAt(PRInt32 aRowIndex, PRInt32 aColIndex,
-                     nsIDOMElement* &aCell);
-
-  /**
-   * Return nsITableLayout for the frame of the accessible table.
-   */
-  nsITableLayout* GetTableLayout();
-
-protected:
-
-  // Accessible
-  virtual void CacheChildren();
-
-  // nsHTMLTableAccessible
-
-  /**
-   * Add row or column to selection.
-   *
-   * @param aIndex   [in] index of row or column to be selected
-   * @param aTarget  [in] indicates what should be selected, either row or column
-   *                  (see nsISelectionPrivate)
-   */
-  nsresult AddRowOrColumnToSelection(PRInt32 aIndex, PRUint32 aTarget);
-
-  /**
-   * Removes rows or columns at the given index or outside it from selection.
-   *
-   * @param  aIndex    [in] row or column index
-   * @param  aTarget   [in] indicates whether row or column should unselected
-   * @param  aIsOuter  [in] indicates whether all rows or column excepting
-   *                    the given one should be unselected or the given one
-   *                    should be unselected only
-   */
-  nsresult RemoveRowsOrColumnsFromSelection(PRInt32 aIndex,
-                                            PRUint32 aTarget,
-                                            bool aIsOuter);
-
-  /**
-   * Return true if table has an element with the given tag name.
-   *
-   * @param  aTagName     [in] tag name of searched element
-   * @param  aAllowEmpty  [in, optional] points if found element can be empty
-   *                       or contain whitespace text only.
-   */
-  bool HasDescendant(const nsAString& aTagName, bool aAllowEmpty = true);
-
-#ifdef SHOW_LAYOUT_HEURISTIC
-  nsString mLayoutHeuristic;
-#endif
-};
-
-/**
- * HTML caption accessible (html:caption).
- */
-class nsHTMLCaptionAccessible : public HyperTextAccessibleWrap
-{
-public:
-  nsHTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) :
-    HyperTextAccessibleWrap(aContent, aDoc) { }
-  virtual ~nsHTMLCaptionAccessible() { }
-
-  // nsIAccessible
-
-  // Accessible
-  virtual mozilla::a11y::role NativeRole();
-  virtual Relation RelationByType(PRUint32 aRelationType);
-};
-
-#endif  
--- a/accessible/src/mac/AccessibleWrap.h
+++ b/accessible/src/mac/AccessibleWrap.h
@@ -104,13 +104,9 @@ private:
   /**
    * We have created our native. This does not mean there is one.
    * This can never go back to false.
    * We need it because checking whether we need a native object cost time.
    */
   bool mNativeInited;  
 };
 
-// Define unsupported wrap classes here
-typedef class nsHTMLTableCellAccessible    nsHTMLTableCellAccessibleWrap;
-typedef class nsHTMLTableAccessible        nsHTMLTableAccessibleWrap;
-
 #endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/mac/HTMLTableAccessibleWrap.h
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HTMLTableAccessibleWrap_h__
+#define mozilla_a11y_HTMLTableAccessibleWrap_h__
+
+#include "HTMLTableAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class HTMLTableAccessible HTMLTableAccessibleWrap;
+typedef class HTMLTableCellAccessible HTMLTableCellAccessibleWrap;
+typedef class HTMLTableHeaderCellAccessible HTMLTableHeaderCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+
new file mode 100644
--- /dev/null
+++ b/accessible/src/mac/XULListboxAccessibleWrap.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULListboxAccessibleWrap_h__
+#define mozilla_a11y_XULListboxAccessibleWrap_h__
+
+#include "XULListboxAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULListboxAccessible XULListboxAccessibleWrap;
+typedef class XULListCellAccessible XULListCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/mac/XULMenuAccessibleWrap.h
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULMenuAccessibleWrap_h__
+#define mozilla_a11y_XULMenuAccessibleWrap_h__
+
+#include "XULMenuAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULMenuitemAccessible XULMenuitemAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/mac/XULTreeGridAccessibleWrap.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULTreeGridAccessibleWrap_h__
+#define mozilla_a11y_XULTreeGridAccessibleWrap_h__
+
+#include "XULTreeGridAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULTreeGridAccessible XULTreeGridAccessibleWrap;
+typedef class XULTreeGridCellAccessible XULTreeGridCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
--- a/accessible/src/mac/mozActionElements.mm
+++ b/accessible/src/mac/mozActionElements.mm
@@ -2,17 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #import "mozActionElements.h"
 
 #import "MacUtils.h"
 #include "Accessible-inl.h"
-#include "nsXULTabAccessible.h"
+#include "XULTabAccessible.h"
 
 #include "nsObjCExceptions.h"
 
 using namespace mozilla::a11y;
 
 enum CheckboxValue {
   // these constants correspond to the values in the OS
   kUnchecked = 0,
deleted file mode 100644
--- a/accessible/src/mac/nsHTMLTableAccessibleWrap.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:expandtab:shiftwidth=2:tabstop=2:
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _NSHTMLTABLEACCESSIBLEWRAP_H
-#define _NSHTMLTABLEACCESSIBLEWRAP_H
-
-#include "nsHTMLTableAccessible.h"
-
-typedef class nsHTMLTableAccessible nsHTMLTableAccessibleWrap;
-typedef class nsHTMLTableCellAccessible nsHTMLTableCellAccessibleWrap;
-typedef class nsHTMLTableHeaderCellAccessible nsHTMLTableHeaderCellAccessibleWrap;
-
-#endif
-
deleted file mode 100644
--- a/accessible/src/mac/nsXULListboxAccessibleWrap.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULListboxAccessibleWrap_h__
-#define __nsXULListboxAccessibleWrap_h__
-
-#include "nsXULListboxAccessible.h"
-
-typedef class nsXULListboxAccessible nsXULListboxAccessibleWrap;
-typedef class nsXULListCellAccessible nsXULListCellAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/mac/nsXULMenuAccessibleWrap.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULMenuAccessibleWrap_h__
-#define __nsXULMenuAccessibleWrap_h__
-
-#include "nsXULMenuAccessible.h"
-
-typedef class nsXULMenuitemAccessible nsXULMenuitemAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/mac/nsXULTreeGridAccessibleWrap.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULTreeGridAccessibleWrap_h__
-#define __nsXULTreeGridAccessibleWrap_h__
-
-#include "nsXULTreeGridAccessible.h"
-
-typedef class nsXULTreeGridAccessible nsXULTreeGridAccessibleWrap;
-typedef class nsXULTreeGridCellAccessible nsXULTreeGridCellAccessibleWrap;
-
-#endif
--- a/accessible/src/msaa/AccessibleWrap.h
+++ b/accessible/src/msaa/AccessibleWrap.h
@@ -307,13 +307,9 @@ protected:
     NAVRELATION_POPUP_FOR = 0x100b,
     NAVRELATION_PARENT_WINDOW_OF = 0x100c,
     NAVRELATION_DEFAULT_BUTTON = 0x100d,
     NAVRELATION_DESCRIBED_BY = 0x100e,
     NAVRELATION_DESCRIPTION_FOR = 0x100f
   };
 };
 
-// Define unsupported wrap classes here
-typedef class nsHTMLTextFieldAccessible    nsHTMLTextFieldAccessibleWrap;
-typedef class nsXULTextFieldAccessible     nsXULTextFieldAccessibleWrap;
-
 #endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/HTMLTableAccessibleWrap.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "HTMLTableAccessibleWrap.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableAccessibleWrap,
+                             HTMLTableAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(HTMLTableAccessibleWrap,
+                         AccessibleWrap,
+                         CAccessibleTable)
+
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableCellAccessibleWrap,
+                             HTMLTableCellAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(HTMLTableCellAccessibleWrap,
+                         HyperTextAccessibleWrap,
+                         CAccessibleTableCell)
+
+
+////////////////////////////////////////////////////////////////////////////////
+// HTMLTableCellAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableHeaderCellAccessibleWrap,
+                             HTMLTableHeaderCellAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(HTMLTableHeaderCellAccessibleWrap,
+                         HyperTextAccessibleWrap,
+                         CAccessibleTableCell)
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/HTMLTableAccessibleWrap.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HTMLTableAccessibleWrap_h__
+#define mozilla_a11y_HTMLTableAccessibleWrap_h__
+
+#include "HTMLTableAccessible.h"
+
+#include "CAccessibleTable.h"
+#include "CAccessibleTableCell.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * IA2 wrapper class for HTMLTableAccessible implementing IAccessibleTable
+ * and IAccessibleTable2 interfaces.
+ */
+class HTMLTableAccessibleWrap : public HTMLTableAccessible,
+                                public CAccessibleTable
+{
+public:
+  HTMLTableAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+    HTMLTableAccessible(aContent, aDoc) {}
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+
+/**
+ * IA2 wrapper class for HTMLTableCellAccessible implementing
+ * IAccessibleTableCell interface.
+ */
+class HTMLTableCellAccessibleWrap : public HTMLTableCellAccessible,
+                                    public CAccessibleTableCell
+{
+public:
+  HTMLTableCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+    HTMLTableCellAccessible(aContent, aDoc) {}
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+
+/**
+ * IA2 wrapper class for HTMLTableHeaderCellAccessible implementing
+ * IAccessibleTableCell interface.
+ */
+class HTMLTableHeaderCellAccessibleWrap : public HTMLTableHeaderCellAccessible,
+                                          public CAccessibleTableCell
+{
+public:
+  HTMLTableHeaderCellAccessibleWrap(nsIContent* aContent,
+                                    DocAccessible* aDoc) :
+    HTMLTableHeaderCellAccessible(aContent, aDoc) {}
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+
--- a/accessible/src/msaa/Makefile.in
+++ b/accessible/src/msaa/Makefile.in
@@ -15,24 +15,21 @@ EXPORT_LIBRARY = ..
 LIBXUL_LIBRARY = 1
 
 
 CPPSRCS = \
   AccessibleWrap.cpp \
   ApplicationAccessibleWrap.cpp \
   ARIAGridAccessibleWrap.cpp \
   DocAccessibleWrap.cpp \
+  HTMLTableAccessibleWrap.cpp \
   HyperTextAccessibleWrap.cpp \
   ImageAccessibleWrap.cpp \
   nsAccessNodeWrap.cpp \
   nsHTMLWin32ObjectAccessible.cpp \
-  nsXULMenuAccessibleWrap.cpp \
-  nsXULListboxAccessibleWrap.cpp \
-  nsXULTreeGridAccessibleWrap.cpp \
-  nsHTMLTableAccessibleWrap.cpp \
   nsWinUtils.cpp \
   CAccessibleText.cpp \
   CAccessibleEditableText.cpp \
   CAccessibleHyperlink.cpp \
   CAccessibleTable.cpp \
   CAccessibleTableCell.cpp \
   CAccessibleValue.cpp \
   Compatibility.cpp \
@@ -41,16 +38,24 @@ CPPSRCS = \
   ia2AccessibleComponent.cpp \
   ia2AccessibleImage.cpp \
   ia2AccessibleHypertext.cpp \
   ia2AccessibleRelation.cpp \
   RootAccessibleWrap.cpp \
   TextLeafAccessibleWrap.cpp \
   $(NULL)
 
+ifdef MOZ_XUL
+CPPSRCS += \
+  XULListboxAccessibleWrap.cpp \
+  XULMenuAccessibleWrap.cpp \
+  XULTreeGridAccessibleWrap.cpp \
+  $(NULL)
+endif
+
 EXPORTS = \
   nsAccessNodeWrap.h \
   $(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/config.mk
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULListboxAccessibleWrap.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULListboxAccessibleWrap.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListboxAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+XULListboxAccessibleWrap::
+  XULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+  XULListboxAccessible(aContent, aDoc)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULListboxAccessibleWrap,
+                             XULListboxAccessible)
+
+IMPL_IUNKNOWN_QUERY_HEAD(XULListboxAccessibleWrap)
+IMPL_IUNKNOWN_QUERY_ENTRY_COND(CAccessibleTable, IsMulticolumn());
+IMPL_IUNKNOWN_QUERY_ENTRY(AccessibleWrap)
+IMPL_IUNKNOWN_QUERY_TAIL
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListCellAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+XULListCellAccessibleWrap::
+  XULListCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+  XULListCellAccessible(aContent, aDoc)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULListCellAccessibleWrap,
+                             XULListCellAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(XULListCellAccessibleWrap,
+                         HyperTextAccessibleWrap,
+                         CAccessibleTableCell)
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULListboxAccessibleWrap.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULListboxAccessibleWrap_h__
+#define mozilla_a11y_XULListboxAccessibleWrap_h__
+
+#include "XULListboxAccessible.h"
+
+#include "CAccessibleTable.h"
+#include "CAccessibleTableCell.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * IA2 wrapper class for XULListboxAccessible class implementing
+ * IAccessibleTable and IAccessibleTable2 interfaces.
+ */
+class XULListboxAccessibleWrap : public XULListboxAccessible,
+                                 public CAccessibleTable
+{
+public:
+  XULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+/**
+ * IA2 wrapper class for XULListCellAccessible class, implements
+ * IAccessibleTableCell interface.
+ */
+class XULListCellAccessibleWrap : public XULListCellAccessible,
+                                  public CAccessibleTableCell
+{
+public:
+  XULListCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULMenuAccessibleWrap.cpp
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULMenuAccessibleWrap.h"
+#include "nsINameSpaceManager.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULMenuAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+XULMenuitemAccessibleWrap::
+  XULMenuitemAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+  XULMenuitemAccessible(aContent, aDoc)
+{
+}
+
+ENameValueFlag
+XULMenuitemAccessibleWrap::Name(nsString& aName)
+{
+  // XXX This should be done in get_accName() so that nsIAccessible::GetName()]
+  // provides the same results on all platforms
+  XULMenuitemAccessible::Name(aName);
+  if (aName.IsEmpty())
+    return eNameOK;
+  
+  nsAutoString accel;
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accel);
+  if (!accel.IsEmpty())
+    aName += NS_LITERAL_STRING("\t") + accel;
+
+  return eNameOK;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULMenuAccessibleWrap.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULMenuAccessibleWrap_h__
+#define mozilla_a11y_XULMenuAccessibleWrap_h__
+
+#include "XULMenuAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+class XULMenuitemAccessibleWrap : public XULMenuitemAccessible
+{
+public:
+  XULMenuitemAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
+  virtual ~XULMenuitemAccessibleWrap() {}
+
+  // nsIAccessible
+  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULTreeGridAccessibleWrap.cpp
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULTreeGridAccessibleWrap.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULTreeGridAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+XULTreeGridAccessibleWrap::
+  XULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
+  XULTreeGridAccessible(aContent, aDoc)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULTreeGridAccessibleWrap,
+                             XULTreeGridAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(XULTreeGridAccessibleWrap,
+                         AccessibleWrap,
+                         CAccessibleTable)
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULTreeGridCellAccessibleWrap
+////////////////////////////////////////////////////////////////////////////////
+
+XULTreeGridCellAccessibleWrap::
+  XULTreeGridCellAccessibleWrap(nsIContent* aContent,
+                                DocAccessible* aDoc,
+                                XULTreeGridRowAccessible* aRowAcc,
+                                nsITreeBoxObject* aTree,
+                                nsITreeView* aTreeView,
+                                PRInt32 aRow, nsITreeColumn* aColumn) :
+  XULTreeGridCellAccessible(aContent, aDoc, aRowAcc, aTree, aTreeView,
+                            aRow, aColumn)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULTreeGridCellAccessibleWrap,
+                             XULTreeGridCellAccessible)
+
+IMPL_IUNKNOWN_INHERITED1(XULTreeGridCellAccessibleWrap,
+                         AccessibleWrap,
+                         CAccessibleTableCell)
new file mode 100644
--- /dev/null
+++ b/accessible/src/msaa/XULTreeGridAccessibleWrap.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULTreeGridAccessibleWrap_h__
+#define mozilla_a11y_XULTreeGridAccessibleWrap_h__
+
+#include "XULTreeGridAccessible.h"
+
+#include "CAccessibleTable.h"
+#include "CAccessibleTableCell.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * IA2 wrapper class for XULTreeGridAccessible class implementing
+ * IAccessibleTable and IAccessibleTable2 interfaces.
+ */
+class XULTreeGridAccessibleWrap : public XULTreeGridAccessible,
+                                  public CAccessibleTable
+{
+public:
+  XULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+/**
+ * IA2 wrapper class for XULTreeGridCellAccessible class, implements
+ * IAccessibleTableCell interface.
+ */
+class XULTreeGridCellAccessibleWrap : public XULTreeGridCellAccessible,
+                                      public CAccessibleTableCell
+{
+public:
+  XULTreeGridCellAccessibleWrap(nsIContent* aContent,
+                                DocAccessible* aDoc,
+                                XULTreeGridRowAccessible* aRowAcc,
+                                nsITreeBoxObject* aTree,
+                                nsITreeView* aTreeView,
+                                PRInt32 aRow, nsITreeColumn* aColumn);
+
+  // IUnknown
+  DECL_IUNKNOWN_INHERITED
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
deleted file mode 100644
--- a/accessible/src/msaa/nsHTMLTableAccessibleWrap.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:expandtab:shiftwidth=2:tabstop=2:
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsHTMLTableAccessibleWrap.h"
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableAccessibleWrap,
-                             nsHTMLTableAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsHTMLTableAccessibleWrap,
-                         AccessibleWrap,
-                         CAccessibleTable)
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableCellAccessibleWrap,
-                             nsHTMLTableCellAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsHTMLTableCellAccessibleWrap,
-                         HyperTextAccessibleWrap,
-                         CAccessibleTableCell)
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsHTMLTableCellAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableHeaderCellAccessibleWrap,
-                             nsHTMLTableHeaderCellAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsHTMLTableHeaderCellAccessibleWrap,
-                         HyperTextAccessibleWrap,
-                         CAccessibleTableCell)
deleted file mode 100644
--- a/accessible/src/msaa/nsHTMLTableAccessibleWrap.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:expandtab:shiftwidth=2:tabstop=2:
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _NSHTMLTABLEACCESSIBLEWRAP_H
-#define _NSHTMLTABLEACCESSIBLEWRAP_H
-
-#include "nsHTMLTableAccessible.h"
-
-#include "CAccessibleTable.h"
-#include "CAccessibleTableCell.h"
-
-/**
- * IA2 wrapper class for nsHTMLTableAccessible implementing IAccessibleTable
- * and IAccessibleTable2 interfaces.
- */
-class nsHTMLTableAccessibleWrap : public nsHTMLTableAccessible,
-                                  public CAccessibleTable
-{
-public:
-  nsHTMLTableAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-    nsHTMLTableAccessible(aContent, aDoc) {}
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-
-/**
- * IA2 wrapper class for nsHTMLTableCellAccessible implementing
- * IAccessibleTableCell interface.
- */
-class nsHTMLTableCellAccessibleWrap : public nsHTMLTableCellAccessible,
-                                      public CAccessibleTableCell
-{
-public:
-  nsHTMLTableCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-    nsHTMLTableCellAccessible(aContent, aDoc) {}
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-
-/**
- * IA2 wrapper class for nsHTMLTableHeaderCellAccessible implementing
- * IAccessibleTableCell interface.
- */
-class nsHTMLTableHeaderCellAccessibleWrap : public nsHTMLTableHeaderCellAccessible,
-                                            public CAccessibleTableCell
-{
-public:
-  nsHTMLTableHeaderCellAccessibleWrap(nsIContent* aContent,
-                                      DocAccessible* aDoc) :
-    nsHTMLTableHeaderCellAccessible(aContent, aDoc) {}
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-#endif
-
deleted file mode 100644
--- a/accessible/src/msaa/nsXULListboxAccessibleWrap.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsXULListboxAccessibleWrap.h"
-
-////////////////////////////////////////////////////////////////////////////////
-// nsXULListboxAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-nsXULListboxAccessibleWrap::
-  nsXULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-  nsXULListboxAccessible(aContent, aDoc)
-{
-}
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsXULListboxAccessibleWrap,
-                             nsXULListboxAccessible)
-
-IMPL_IUNKNOWN_QUERY_HEAD(nsXULListboxAccessibleWrap)
-IMPL_IUNKNOWN_QUERY_ENTRY_COND(CAccessibleTable, IsMulticolumn());
-IMPL_IUNKNOWN_QUERY_ENTRY(AccessibleWrap)
-IMPL_IUNKNOWN_QUERY_TAIL
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsXULListCellAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-nsXULListCellAccessibleWrap::
-  nsXULListCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-  nsXULListCellAccessible(aContent, aDoc)
-{
-}
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsXULListCellAccessibleWrap,
-                             nsXULListCellAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsXULListCellAccessibleWrap,
-                         HyperTextAccessibleWrap,
-                         CAccessibleTableCell)
deleted file mode 100644
--- a/accessible/src/msaa/nsXULListboxAccessibleWrap.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULListboxAccessibleWrap_h__
-#define __nsXULListboxAccessibleWrap_h__
-
-#include "nsXULListboxAccessible.h"
-
-#include "CAccessibleTable.h"
-#include "CAccessibleTableCell.h"
-
-/**
- * IA2 wrapper class for nsXULListboxAccessible class implementing
- * IAccessibleTable and IAccessibleTable2 interfaces.
- */
-class nsXULListboxAccessibleWrap : public nsXULListboxAccessible,
-                                   public CAccessibleTable
-{
-public:
-  nsXULListboxAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-/**
- * IA2 wrapper class for nsXULListCellAccessible class, implements
- * IAccessibleTableCell interface.
- */
-class nsXULListCellAccessibleWrap : public nsXULListCellAccessible,
-                                    public CAccessibleTableCell
-{
-public:
-  nsXULListCellAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-#endif
deleted file mode 100644
--- a/accessible/src/msaa/nsXULMenuAccessibleWrap.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsXULMenuAccessibleWrap.h"
-#include "nsINameSpaceManager.h"
-
-using namespace mozilla::a11y;
-
-////////////////////////////////////////////////////////////////////////////////
-// nsXULMenuAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-nsXULMenuitemAccessibleWrap::
-  nsXULMenuitemAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-  nsXULMenuitemAccessible(aContent, aDoc)
-{
-}
-
-ENameValueFlag
-nsXULMenuitemAccessibleWrap::Name(nsString& aName)
-{
-  // XXX This should be done in get_accName() so that nsIAccessible::GetName()]
-  // provides the same results on all platforms
-  nsXULMenuitemAccessible::Name(aName);
-  if (aName.IsEmpty())
-    return eNameOK;
-  
-  nsAutoString accel;
-  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accel);
-  if (!accel.IsEmpty())
-    aName += NS_LITERAL_STRING("\t") + accel;
-
-  return eNameOK;
-}
deleted file mode 100644
--- a/accessible/src/msaa/nsXULMenuAccessibleWrap.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULMenuAccessibleWrap_h__
-#define __nsXULMenuAccessibleWrap_h__
-
-#include "nsXULMenuAccessible.h"
-
-class nsXULMenuitemAccessibleWrap : public nsXULMenuitemAccessible
-{
-public:
-  nsXULMenuitemAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
-  virtual ~nsXULMenuitemAccessibleWrap() {}
-
-  // nsIAccessible
-  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
-};
-
-#endif
deleted file mode 100644
--- a/accessible/src/msaa/nsXULTreeGridAccessibleWrap.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsXULTreeGridAccessibleWrap.h"
-
-////////////////////////////////////////////////////////////////////////////////
-// nsXULTreeGridAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-nsXULTreeGridAccessibleWrap::
-  nsXULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
-  nsXULTreeGridAccessible(aContent, aDoc)
-{
-}
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeGridAccessibleWrap,
-                             nsXULTreeGridAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsXULTreeGridAccessibleWrap,
-                         AccessibleWrap,
-                         CAccessibleTable)
-
-
-////////////////////////////////////////////////////////////////////////////////
-// nsXULTreeGridCellAccessibleWrap
-////////////////////////////////////////////////////////////////////////////////
-
-nsXULTreeGridCellAccessibleWrap::
-  nsXULTreeGridCellAccessibleWrap(nsIContent* aContent,
-                                  DocAccessible* aDoc,
-                                  nsXULTreeGridRowAccessible* aRowAcc,
-                                  nsITreeBoxObject* aTree,
-                                  nsITreeView* aTreeView,
-                                  PRInt32 aRow, nsITreeColumn* aColumn) :
-  nsXULTreeGridCellAccessible(aContent, aDoc, aRowAcc, aTree, aTreeView,
-                              aRow, aColumn)
-{
-}
-
-NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeGridCellAccessibleWrap,
-                             nsXULTreeGridCellAccessible)
-
-IMPL_IUNKNOWN_INHERITED1(nsXULTreeGridCellAccessibleWrap,
-                         AccessibleWrap,
-                         CAccessibleTableCell)
deleted file mode 100644
--- a/accessible/src/msaa/nsXULTreeGridAccessibleWrap.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULTreeGridAccessibleWrap_h__
-#define __nsXULTreeGridAccessibleWrap_h__
-
-#include "nsXULTreeGridAccessible.h"
-
-#include "CAccessibleTable.h"
-#include "CAccessibleTableCell.h"
-
-/**
- * IA2 wrapper class for nsXULTreeGridAccessible class implementing
- * IAccessibleTable and IAccessibleTable2 interfaces.
- */
-class nsXULTreeGridAccessibleWrap : public nsXULTreeGridAccessible,
-                                    public CAccessibleTable
-{
-public:
-  nsXULTreeGridAccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-/**
- * IA2 wrapper class for nsXULTreeGridCellAccessible class, implements
- * IAccessibleTableCell interface.
- */
-class nsXULTreeGridCellAccessibleWrap : public nsXULTreeGridCellAccessible,
-                                        public CAccessibleTableCell
-{
-public:
-  nsXULTreeGridCellAccessibleWrap(nsIContent* aContent,
-                                  DocAccessible* aDoc,
-                                  nsXULTreeGridRowAccessible* aRowAcc,
-                                  nsITreeBoxObject* aTree,
-                                  nsITreeView* aTreeView,
-                                  PRInt32 aRow, nsITreeColumn* aColumn);
-
-  // IUnknown
-  DECL_IUNKNOWN_INHERITED
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-};
-
-#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/other/HTMLTableAccessibleWrap.h
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_HTMLTableAccessibleWrap_h__
+#define mozilla_a11y_HTMLTableAccessibleWrap_h__
+
+#include "HTMLTableAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class HTMLTableAccessible HTMLTableAccessibleWrap;
+typedef class HTMLTableCellAccessible HTMLTableCellAccessibleWrap;
+typedef class HTMLTableHeaderCellAccessible HTMLTableHeaderCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
+
new file mode 100644
--- /dev/null
+++ b/accessible/src/other/XULListboxAccessibleWrap.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULListboxAccessibleWrap_h__
+#define mozilla_a11y_XULListboxAccessibleWrap_h__
+
+#include "XULListboxAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULListboxAccessible XULListboxAccessibleWrap;
+typedef class XULListCellAccessible XULListCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/other/XULMenuAccessibleWrap.h
@@ -0,0 +1,19 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULMenuAccessibleWrap_h__
+#define mozilla_a11y_XULMenuAccessibleWrap_h__
+
+#include "XULMenuAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULMenuitemAccessible XULMenuitemAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/other/XULTreeGridAccessibleWrap.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULTreeGridAccessibleWrap_h__
+#define mozilla_a11y_XULTreeGridAccessibleWrap_h__
+
+#include "XULTreeGridAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+typedef class XULTreeGridAccessible XULTreeGridAccessibleWrap;
+typedef class XULTreeGridCellAccessible XULTreeGridCellAccessibleWrap;
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
deleted file mode 100644
--- a/accessible/src/other/nsHTMLTableAccessibleWrap.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:expandtab:shiftwidth=2:tabstop=2:
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _NSHTMLTABLEACCESSIBLEWRAP_H
-#define _NSHTMLTABLEACCESSIBLEWRAP_H
-
-#include "nsHTMLTableAccessible.h"
-
-typedef class nsHTMLTableAccessible nsHTMLTableAccessibleWrap;
-typedef class nsHTMLTableCellAccessible nsHTMLTableCellAccessibleWrap;
-typedef class nsHTMLTableHeaderCellAccessible nsHTMLTableHeaderCellAccessibleWrap;
-
-#endif
-
deleted file mode 100644
--- a/accessible/src/other/nsXULListboxAccessibleWrap.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULListboxAccessibleWrap_h__
-#define __nsXULListboxAccessibleWrap_h__
-
-#include "nsXULListboxAccessible.h"
-
-typedef class nsXULListboxAccessible nsXULListboxAccessibleWrap;
-typedef class nsXULListCellAccessible nsXULListCellAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/other/nsXULMenuAccessibleWrap.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULMenuAccessibleWrap_h__
-#define __nsXULMenuAccessibleWrap_h__
-
-#include "nsXULMenuAccessible.h"
-
-typedef class nsXULMenuitemAccessible nsXULMenuitemAccessibleWrap;
-
-#endif
deleted file mode 100644
--- a/accessible/src/other/nsXULTreeGridAccessibleWrap.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __nsXULTreeGridAccessibleWrap_h__
-#define __nsXULTreeGridAccessibleWrap_h__
-
-#include "nsXULTreeGridAccessible.h"
-
-typedef class nsXULTreeGridAccessible nsXULTreeGridAccessibleWrap;
-typedef class nsXULTreeGridCellAccessible nsXULTreeGridCellAccessibleWrap;
-
-#endif
--- a/accessible/src/xul/Makefile.in
+++ b/accessible/src/xul/Makefile.in
@@ -12,28 +12,28 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE = accessibility
 LIBRARY_NAME = accessibility_xul_s
 LIBXUL_LIBRARY = 1
 
 
 
 CPPSRCS = \
-  XULSelectControlAccessible.cpp \
-  nsXULAlertAccessible.cpp \
-  nsXULColorPickerAccessible.cpp \
-  nsXULComboboxAccessible.cpp \
+  XULAlertAccessible.cpp \
+  XULColorPickerAccessible.cpp \
+  XULComboboxAccessible.cpp \
+  XULElementAccessibles.cpp \
   XULFormControlAccessible.cpp \
-  nsXULListboxAccessible.cpp \
-  nsXULMenuAccessible.cpp \
-  nsXULSliderAccessible.cpp \
-  nsXULTabAccessible.cpp \
-  nsXULTextAccessible.cpp \
-  nsXULTreeAccessible.cpp \
-  nsXULTreeGridAccessible.cpp \
+  XULListboxAccessible.cpp \
+  XULMenuAccessible.cpp \
+  XULSelectControlAccessible.cpp \
+  XULSliderAccessible.cpp \
+  XULTabAccessible.cpp \
+  XULTreeAccessible.cpp \
+  XULTreeGridAccessible.cpp \
   $(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 LOCAL_INCLUDES = \
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULAlertAccessible.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULAlertAccessible.h"
+
+#include "Role.h"
+#include "States.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULAlertAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULAlertAccessible::
+  XULAlertAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  AccessibleWrap(aContent, aDoc)
+{
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULAlertAccessible, Accessible)
+
+role
+XULAlertAccessible::NativeRole()
+{
+  return roles::ALERT;
+}
+
+PRUint64
+XULAlertAccessible::NativeState()
+{
+  return Accessible::NativeState() | states::ALERT;
+}
+
+ENameValueFlag
+XULAlertAccessible::Name(nsString& aName)
+{
+  // Screen readers need to read contents of alert, not the accessible name.
+  // If we have both some screen readers will read the alert twice.
+  aName.Truncate();
+  return eNameOK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Widgets
+
+bool
+XULAlertAccessible::IsWidget() const
+{
+  return true;
+}
+
+Accessible*
+XULAlertAccessible::ContainerWidget() const
+{
+  // If a part of colorpicker widget.
+  if (mParent && mParent->IsMenuButton())
+    return mParent;
+  return nsnull;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULAlertAccessible.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULAlertAccessible_h__
+#define mozilla_a11y_XULAlertAccessible_h__
+
+#include "AccessibleWrap.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Accessible for supporting XUL alerts.
+ */
+
+class XULAlertAccessible : public AccessibleWrap
+{
+public:
+  XULAlertAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // Accessible
+  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+
+  // Widgets
+  virtual bool IsWidget() const;
+  virtual Accessible* ContainerWidget() const;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULColorPickerAccessible.cpp
@@ -0,0 +1,159 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULColorPickerAccessible.h"
+
+#include "Accessible-inl.h"
+#include "nsAccUtils.h"
+#include "nsAccTreeWalker.h"
+#include "nsCoreUtils.h"
+#include "DocAccessible.h"
+#include "Role.h"
+#include "States.h"
+
+#include "nsIDOMElement.h"
+#include "nsMenuPopupFrame.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerTileAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULColorPickerTileAccessible::
+  XULColorPickerTileAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  AccessibleWrap(aContent, aDoc)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerTileAccessible: nsIAccessible
+
+void
+XULColorPickerTileAccessible::Value(nsString& aValue)
+{
+  aValue.Truncate();
+
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::color, aValue);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerTileAccessible: Accessible
+
+role
+XULColorPickerTileAccessible::NativeRole()
+{
+  return roles::PUSHBUTTON;
+}
+
+PRUint64
+XULColorPickerTileAccessible::NativeState()
+{
+  PRUint64 state = AccessibleWrap::NativeState();
+  if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::selected))
+    state |= states::SELECTED;
+
+  return state;
+}
+
+PRUint64
+XULColorPickerTileAccessible::NativeInteractiveState() const
+{
+  return NativelyUnavailable() ?
+    states::UNAVAILABLE : states::FOCUSABLE | states::SELECTABLE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerTileAccessible: Widgets
+
+Accessible*
+XULColorPickerTileAccessible::ContainerWidget() const
+{
+  Accessible* parent = Parent();
+  if (parent) {
+    Accessible* grandParent = parent->Parent();
+    if (grandParent && grandParent->IsMenuButton())
+      return grandParent;
+  }
+  return nsnull;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULColorPickerAccessible::
+  XULColorPickerAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  XULColorPickerTileAccessible(aContent, aDoc)
+{
+  mFlags |= eMenuButtonAccessible;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerAccessible: Accessible
+
+PRUint64
+XULColorPickerAccessible::NativeState()
+{
+  PRUint64 state = AccessibleWrap::NativeState();
+  return state | states::HASPOPUP;
+}
+
+role
+XULColorPickerAccessible::NativeRole()
+{
+  return roles::BUTTONDROPDOWNGRID;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerAccessible: Widgets
+
+bool
+XULColorPickerAccessible::IsWidget() const
+{
+  return true;
+}
+
+bool
+XULColorPickerAccessible::IsActiveWidget() const
+{
+  return FocusMgr()->HasDOMFocus(mContent);
+}
+
+bool
+XULColorPickerAccessible::AreItemsOperable() const
+{
+  Accessible* menuPopup = mChildren.SafeElementAt(0, nsnull);
+  if (menuPopup) {
+    nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(menuPopup->GetFrame());
+    return menuPopupFrame && menuPopupFrame->IsOpen();
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColorPickerAccessible: protected Accessible
+
+void
+XULColorPickerAccessible::CacheChildren()
+{
+  NS_ENSURE_TRUE(mDoc,);
+
+  nsAccTreeWalker walker(mDoc, mContent, true);
+
+  Accessible* child = nsnull;
+  while ((child = walker.NextChild())) {
+    PRUint32 role = child->Role();
+
+    // Get an accessible for menupopup or panel elements.
+    if (role == roles::ALERT) {
+      AppendChild(child);
+      return;
+    }
+
+    // Unbind rejected accessibles from the document.
+    Document()->UnbindFromDocument(child);
+  }
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULColorPickerAccessible.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULColorPickerAccessible_h__
+#define mozilla_a11y_XULColorPickerAccessible_h__
+
+#include "AccessibleWrap.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Used for color button in colorpicker palette.
+ */
+class XULColorPickerTileAccessible : public AccessibleWrap
+{
+public:
+  XULColorPickerTileAccessible(nsIContent* aContent,
+                               DocAccessible* aDoc);
+
+  // Accessible
+  virtual void Value(nsString& aValue);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+  virtual PRUint64 NativeInteractiveState() const;
+
+  // Widgets
+  virtual Accessible* ContainerWidget() const;
+};
+
+
+/**
+ * Used for colorpicker button (xul:colorpicker@type="button").
+ */
+class XULColorPickerAccessible : public XULColorPickerTileAccessible
+{
+public:
+  XULColorPickerAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // Accessible
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+
+  // Widgets
+  virtual bool IsWidget() const;
+  virtual bool IsActiveWidget() const;
+  virtual bool AreItemsOperable() const;
+
+protected:
+
+  // Accessible
+  virtual void CacheChildren();
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif  
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULComboboxAccessible.cpp
@@ -0,0 +1,215 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULComboboxAccessible.h"
+
+#include "Accessible-inl.h"
+#include "nsAccessibilityService.h"
+#include "DocAccessible.h"
+#include "nsCoreUtils.h"
+#include "Role.h"
+#include "States.h"
+
+#include "nsIAutoCompleteInput.h"
+#include "nsIDOMXULMenuListElement.h"
+#include "nsIDOMXULSelectCntrlItemEl.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULComboboxAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULComboboxAccessible::
+  XULComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  AccessibleWrap(aContent, aDoc)
+{
+  if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
+                            nsGkAtoms::autocomplete, eIgnoreCase))
+    mFlags |= eAutoCompleteAccessible;
+  else
+    mFlags |= eComboboxAccessible;
+}
+
+role
+XULComboboxAccessible::NativeRole()
+{
+  return IsAutoComplete() ? roles::AUTOCOMPLETE : roles::COMBOBOX;
+}
+
+PRUint64
+XULComboboxAccessible::NativeState()
+{
+  // As a nsComboboxAccessible we can have the following states:
+  //     STATE_FOCUSED
+  //     STATE_FOCUSABLE
+  //     STATE_HASPOPUP
+  //     STATE_EXPANDED
+  //     STATE_COLLAPSED
+
+  // Get focus status from base class
+  PRUint64 state = Accessible::NativeState();
+
+  nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
+  if (menuList) {
+    bool isOpen = false;
+    menuList->GetOpen(&isOpen);
+    if (isOpen)
+      state |= states::EXPANDED;
+    else
+      state |= states::COLLAPSED;
+  }
+
+  return state | states::HASPOPUP;
+}
+
+void
+XULComboboxAccessible::Description(nsString& aDescription)
+{
+  aDescription.Truncate();
+  // Use description of currently focused option
+  nsCOMPtr<nsIDOMXULMenuListElement> menuListElm(do_QueryInterface(mContent));
+  if (!menuListElm)
+    return;
+
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> focusedOptionItem;
+  menuListElm->GetSelectedItem(getter_AddRefs(focusedOptionItem));
+  nsCOMPtr<nsIContent> focusedOptionContent =
+    do_QueryInterface(focusedOptionItem);
+  if (focusedOptionContent && mDoc) {
+    Accessible* focusedOptionAcc = mDoc->GetAccessible(focusedOptionContent);
+    if (focusedOptionAcc)
+      focusedOptionAcc->Description(aDescription);
+  }
+}
+
+void
+XULComboboxAccessible::Value(nsString& aValue)
+{
+  aValue.Truncate();
+
+  // The value is the option or text shown entered in the combobox.
+  nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
+  if (menuList)
+    menuList->GetLabel(aValue);
+}
+
+bool
+XULComboboxAccessible::CanHaveAnonChildren()
+{
+  if (mContent->NodeInfo()->Equals(nsGkAtoms::textbox, kNameSpaceID_XUL) ||
+      mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
+                            nsGkAtoms::_true, eIgnoreCase)) {
+    // Both the XUL <textbox type="autocomplete"> and <menulist editable="true"> widgets
+    // use XULComboboxAccessible. We need to walk the anonymous children for these
+    // so that the entry field is a child
+    return true;
+  }
+
+  // Argument of false indicates we don't walk anonymous children for
+  // menuitems
+  return false;
+}
+
+PRUint8
+XULComboboxAccessible::ActionCount()
+{
+  // Just one action (click).
+  return 1;
+}
+
+NS_IMETHODIMP
+XULComboboxAccessible::DoAction(PRUint8 aIndex)
+{
+  if (aIndex != XULComboboxAccessible::eAction_Click) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  // Programmaticaly toggle the combo box.
+  nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
+  if (!menuList) {
+    return NS_ERROR_FAILURE;
+  }
+  bool isDroppedDown;
+  menuList->GetOpen(&isDroppedDown);
+  return menuList->SetOpen(!isDroppedDown);
+}
+
+NS_IMETHODIMP
+XULComboboxAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
+{
+  if (aIndex != XULComboboxAccessible::eAction_Click) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  // Our action name is the reverse of our state:
+  //     if we are close -> open is our name.
+  //     if we are open -> close is our name.
+  // Uses the frame to get the state, updated on every click.
+
+  nsCOMPtr<nsIDOMXULMenuListElement> menuList(do_QueryInterface(mContent));
+  if (!menuList) {
+    return NS_ERROR_FAILURE;
+  }
+  bool isDroppedDown;
+  menuList->GetOpen(&isDroppedDown);
+  if (isDroppedDown)
+    aName.AssignLiteral("close"); 
+  else
+    aName.AssignLiteral("open"); 
+
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Widgets
+
+bool
+XULComboboxAccessible::IsActiveWidget() const
+{
+  if (IsAutoComplete() ||
+     mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
+                           nsGkAtoms::_true, eIgnoreCase)) {
+    PRInt32 childCount = mChildren.Length();
+    for (PRInt32 idx = 0; idx < childCount; idx++) {
+      Accessible* child = mChildren[idx];
+      if (child->Role() == roles::ENTRY)
+        return FocusMgr()->HasDOMFocus(child->GetContent());
+    }
+    return false;
+  }
+
+  return FocusMgr()->HasDOMFocus(mContent);
+}
+
+bool
+XULComboboxAccessible::AreItemsOperable() const
+{
+  if (IsAutoComplete()) {
+    nsCOMPtr<nsIAutoCompleteInput> autoCompleteInputElm =
+      do_QueryInterface(mContent);
+    if (autoCompleteInputElm) {
+      bool isOpen = false;
+      autoCompleteInputElm->GetPopupOpen(&isOpen);
+      return isOpen;
+    }
+    return false;
+  }
+
+  nsCOMPtr<nsIDOMXULMenuListElement> menuListElm = do_QueryInterface(mContent);
+  if (menuListElm) {
+    bool isOpen = false;
+    menuListElm->GetOpen(&isOpen);
+    return isOpen;
+  }
+
+  return false;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULComboboxAccessible.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULComboboxAccessible_h__
+#define mozilla_a11y_XULComboboxAccessible_h__
+
+#include "XULMenuAccessible.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Used for XUL comboboxes like xul:menulist and autocomplete textbox.
+ */
+class XULComboboxAccessible : public AccessibleWrap
+{
+public:
+  enum { eAction_Click = 0 };
+
+  XULComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // nsIAccessible
+  NS_IMETHOD DoAction(PRUint8 aIndex);
+  NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
+
+  // Accessible
+  virtual void Description(nsString& aDescription);
+  virtual void Value(nsString& aValue);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+  virtual bool CanHaveAnonChildren();
+
+  // ActionAccessible
+  virtual PRUint8 ActionCount();
+
+  // Widgets
+  virtual bool IsActiveWidget() const;
+  virtual bool AreItemsOperable() const;
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULElementAccessibles.cpp
@@ -0,0 +1,227 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULElementAccessibles.h"
+
+#include "Accessible-inl.h"
+#include "BaseAccessibles.h"
+#include "nsAccUtils.h"
+#include "nsCoreUtils.h"
+#include "nsTextEquivUtils.h"
+#include "Relation.h"
+#include "Role.h"
+#include "States.h"
+
+#include "nsIAccessibleRelation.h"
+#include "nsIDOMXULDescriptionElement.h"
+#include "nsINameSpaceManager.h"
+#include "nsString.h"
+#include "nsNetUtil.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULLabelAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULLabelAccessible::
+  XULLabelAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  HyperTextAccessibleWrap(aContent, aDoc)
+{
+}
+
+nsresult
+XULLabelAccessible::GetNameInternal(nsAString& aName)
+{
+  // if the value attr doesn't exist, the screen reader must get the accessible text
+  // from the accessible text interface or from the children
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
+  return NS_OK;
+}
+
+role
+XULLabelAccessible::NativeRole()
+{
+  return roles::LABEL;
+}
+
+PRUint64
+XULLabelAccessible::NativeState()
+{
+  // Labels and description have read only state
+  // They are not focusable or selectable
+  return HyperTextAccessibleWrap::NativeState() | states::READONLY;
+}
+
+Relation
+XULLabelAccessible::RelationByType(PRUint32 aType)
+{
+  Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
+  if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
+    // Caption is the label for groupbox
+    nsIContent *parent = mContent->GetParent();
+    if (parent && parent->Tag() == nsGkAtoms::caption) {
+      Accessible* parent = Parent();
+      if (parent && parent->Role() == roles::GROUPING)
+        rel.AppendTarget(parent);
+    }
+  }
+
+  return rel;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULTooltipAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULTooltipAccessible::
+  XULTooltipAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  LeafAccessible(aContent, aDoc)
+{
+}
+
+PRUint64
+XULTooltipAccessible::NativeState()
+{
+  return LeafAccessible::NativeState() | states::READONLY;
+}
+
+role
+XULTooltipAccessible::NativeRole()
+{
+  return roles::TOOLTIP;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULLinkAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULLinkAccessible::
+  XULLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  HyperTextAccessibleWrap(aContent, aDoc)
+{
+}
+
+// Expose nsIAccessibleHyperLink unconditionally
+NS_IMPL_ISUPPORTS_INHERITED1(XULLinkAccessible, HyperTextAccessibleWrap,
+                             nsIAccessibleHyperLink)
+
+////////////////////////////////////////////////////////////////////////////////
+// XULLinkAccessible. nsIAccessible
+
+void
+XULLinkAccessible::Value(nsString& aValue)
+{
+  aValue.Truncate();
+
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, aValue);
+}
+
+nsresult
+XULLinkAccessible::GetNameInternal(nsAString& aName)
+{
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
+  if (!aName.IsEmpty())
+    return NS_OK;
+
+  return nsTextEquivUtils::GetNameFromSubtree(this, aName);
+}
+
+role
+XULLinkAccessible::NativeRole()
+{
+  return roles::LINK;
+}
+
+
+PRUint64
+XULLinkAccessible::NativeLinkState() const
+{
+  return states::LINKED;
+}
+
+PRUint8
+XULLinkAccessible::ActionCount()
+{
+  return 1;
+}
+
+NS_IMETHODIMP
+XULLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
+{
+  aName.Truncate();
+
+  if (aIndex != eAction_Jump)
+    return NS_ERROR_INVALID_ARG;
+
+  aName.AssignLiteral("jump");
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULLinkAccessible::DoAction(PRUint8 aIndex)
+{
+  if (aIndex != eAction_Jump)
+    return NS_ERROR_INVALID_ARG;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  DoCommand();
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULLinkAccessible: HyperLinkAccessible
+
+bool
+XULLinkAccessible::IsLink()
+{
+  // Expose HyperLinkAccessible unconditionally.
+  return true;
+}
+
+PRUint32
+XULLinkAccessible::StartOffset()
+{
+  // If XUL link accessible is not contained by hypertext accessible then
+  // start offset matches index in parent because the parent doesn't contains
+  // a text.
+  // XXX: accessible parent of XUL link accessible should be a hypertext
+  // accessible.
+  if (Accessible::IsLink())
+    return Accessible::StartOffset();
+  return IndexInParent();
+}
+
+PRUint32
+XULLinkAccessible::EndOffset()
+{
+  if (Accessible::IsLink())
+    return Accessible::EndOffset();
+  return IndexInParent() + 1;
+}
+
+already_AddRefed<nsIURI>
+XULLinkAccessible::AnchorURIAt(PRUint32 aAnchorIndex)
+{
+  if (aAnchorIndex != 0)
+    return nsnull;
+
+  nsAutoString href;
+  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
+
+  nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
+  nsIDocument* document = mContent->OwnerDoc();
+
+  nsIURI* anchorURI = nsnull;
+  NS_NewURI(&anchorURI, href,
+            document->GetDocumentCharacterSet().get(),
+            baseURI);
+
+  return anchorURI;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULElementAccessibles.h
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULElementAccessibles_h__
+#define mozilla_a11y_XULElementAccessibles_h__
+
+#include "BaseAccessibles.h"
+#include "HyperTextAccessibleWrap.h"
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Used for XUL description and label elements.
+ */
+class XULLabelAccessible : public HyperTextAccessibleWrap
+{
+public:
+  XULLabelAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // Accessible
+  virtual nsresult GetNameInternal(nsAString& aName);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+  virtual Relation RelationByType(PRUint32 aRelationType);
+};
+
+/**
+ * Used for XUL tooltip element.
+ */
+class XULTooltipAccessible : public LeafAccessible
+{
+
+public:
+  XULTooltipAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  // Accessible
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeState();
+};
+
+class XULLinkAccessible : public HyperTextAccessibleWrap
+{
+
+public:
+  XULLinkAccessible(nsIContent* aContent, DocAccessible* aDoc);
+
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIAccessible
+  NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
+  NS_IMETHOD DoAction(PRUint8 aIndex);
+
+  // Accessible
+  virtual void Value(nsString& aValue);
+  virtual nsresult GetNameInternal(nsAString& aName);
+  virtual a11y::role NativeRole();
+  virtual PRUint64 NativeLinkState() const;
+
+  // ActionAccessible
+  virtual PRUint8 ActionCount();
+
+  // HyperLinkAccessible
+  virtual bool IsLink();
+  virtual PRUint32 StartOffset();
+  virtual PRUint32 EndOffset();
+  virtual already_AddRefed<nsIURI> AnchorURIAt(PRUint32 aAnchorIndex);
+
+protected:
+  enum { eAction_Jump = 0 };
+
+};
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
--- a/accessible/src/xul/XULFormControlAccessible.cpp
+++ b/accessible/src/xul/XULFormControlAccessible.cpp
@@ -7,20 +7,20 @@
 
 #include "Accessible-inl.h"
 #include "HTMLFormControlAccessible.h"
 #include "nsAccUtils.h"
 #include "nsAccTreeWalker.h"
 #include "nsCoreUtils.h"
 #include "DocAccessible.h"
 #include "nsIAccessibleRelation.h"
-#include "nsXULMenuAccessible.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
+#include "XULMenuAccessible.h"
 
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIDOMXULButtonElement.h"
 #include "nsIDOMXULCheckboxElement.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDOMXULTextboxElement.h"
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULListboxAccessible.cpp
@@ -0,0 +1,1177 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "XULListboxAccessible.h"
+
+#include "Accessible-inl.h"
+#include "nsAccessibilityService.h"
+#include "nsAccUtils.h"
+#include "DocAccessible.h"
+#include "Role.h"
+#include "States.h"
+
+#include "nsComponentManagerUtils.h"
+#include "nsIAutoCompleteInput.h"
+#include "nsIAutoCompletePopup.h"
+#include "nsIDOMXULMenuListElement.h"
+#include "nsIDOMXULMultSelectCntrlEl.h"
+#include "nsIDOMNodeList.h"
+#include "nsIDOMXULPopupElement.h"
+#include "nsIDOMXULSelectCntrlItemEl.h"
+
+using namespace mozilla::a11y;
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColumAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULColumAccessible::
+  XULColumAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  AccessibleWrap(aContent, aDoc)
+{
+}
+
+role
+XULColumAccessible::NativeRole()
+{
+  return roles::LIST;
+}
+
+PRUint64
+XULColumAccessible::NativeState()
+{
+  return states::READONLY;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULColumnItemAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULColumnItemAccessible::
+  XULColumnItemAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  LeafAccessible(aContent, aDoc)
+{
+}
+
+role
+XULColumnItemAccessible::NativeRole()
+{
+  return roles::COLUMNHEADER;
+}
+
+PRUint64
+XULColumnItemAccessible::NativeState()
+{
+  return states::READONLY;
+}
+
+PRUint8
+XULColumnItemAccessible::ActionCount()
+{
+  return 1;
+}
+
+NS_IMETHODIMP
+XULColumnItemAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
+{
+  if (aIndex != eAction_Click)
+    return NS_ERROR_INVALID_ARG;
+
+  aName.AssignLiteral("click");
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULColumnItemAccessible::DoAction(PRUint8 aIndex)
+{
+  if (aIndex != eAction_Click)
+    return NS_ERROR_INVALID_ARG;
+
+  DoCommand();
+  return NS_OK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListboxAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULListboxAccessible::
+  XULListboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  XULSelectControlAccessible(aContent, aDoc), xpcAccessibleTable(this)
+{
+  nsIContent* parentContent = mContent->GetParent();
+  if (parentContent) {
+    nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
+      do_QueryInterface(parentContent);
+    if (autoCompletePopupElm)
+      mFlags |= eAutoCompletePopupAccessible;
+  }
+}
+
+NS_IMPL_ADDREF_INHERITED(XULListboxAccessible, XULSelectControlAccessible)
+NS_IMPL_RELEASE_INHERITED(XULListboxAccessible, XULSelectControlAccessible)
+
+nsresult
+XULListboxAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
+{
+  nsresult rv = XULSelectControlAccessible::QueryInterface(aIID, aInstancePtr);
+  if (*aInstancePtr)
+    return rv;
+
+  if (aIID.Equals(NS_GET_IID(nsIAccessibleTable)) && IsMulticolumn()) {
+    *aInstancePtr = static_cast<nsIAccessibleTable*>(this);
+    NS_ADDREF_THIS();
+    return NS_OK;
+  }
+
+  return NS_ERROR_NO_INTERFACE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//nsAccessNode
+
+void
+XULListboxAccessible::Shutdown()
+{
+  mTable = nsnull;
+  XULSelectControlAccessible::Shutdown();
+}
+
+bool
+XULListboxAccessible::IsMulticolumn()
+{
+  PRInt32 numColumns = 0;
+  nsresult rv = GetColumnCount(&numColumns);
+  if (NS_FAILED(rv))
+    return false;
+
+  return numColumns > 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListboxAccessible. nsIAccessible
+
+PRUint64
+XULListboxAccessible::NativeState()
+{
+  // As a XULListboxAccessible we can have the following states:
+  //   FOCUSED, READONLY, FOCUSABLE
+
+  // Get focus status from base class
+  PRUint64 states = Accessible::NativeState();
+
+  // see if we are multiple select if so set ourselves as such
+
+  if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::seltype,
+                            nsGkAtoms::multiple, eCaseMatters)) {
+      states |= states::MULTISELECTABLE | states::EXTSELECTABLE;
+  }
+
+  return states;
+}
+
+/**
+  * Our value is the label of our ( first ) selected child.
+  */
+void
+XULListboxAccessible::Value(nsString& aValue)
+{
+  aValue.Truncate();
+
+  nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mContent));
+  if (select) {
+    nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
+    select->GetSelectedItem(getter_AddRefs(selectedItem));
+    if (selectedItem)
+      selectedItem->GetLabel(aValue);
+  }
+}
+
+role
+XULListboxAccessible::NativeRole()
+{
+  // A richlistbox is used with the new autocomplete URL bar, and has a parent
+  // popup <panel>.
+  nsCOMPtr<nsIDOMXULPopupElement> xulPopup =
+    do_QueryInterface(mContent->GetParent());
+  if (xulPopup)
+    return roles::COMBOBOX_LIST;
+
+  return IsMulticolumn() ? roles::TABLE : roles::LISTBOX;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListboxAccessible. nsIAccessibleTable
+
+PRUint32
+XULListboxAccessible::ColCount()
+{
+  nsIContent* headContent = nsnull;
+  for (nsIContent* childContent = mContent->GetFirstChild(); childContent;
+       childContent = childContent->GetNextSibling()) {
+    if (childContent->NodeInfo()->Equals(nsGkAtoms::listcols,
+                                         kNameSpaceID_XUL)) {
+      headContent = childContent;
+    }
+  }
+  if (!headContent)
+    return 0;
+
+  PRUint32 columnCount = 0;
+  for (nsIContent* childContent = headContent->GetFirstChild(); childContent;
+       childContent = childContent->GetNextSibling()) {
+    if (childContent->NodeInfo()->Equals(nsGkAtoms::listcol,
+                                         kNameSpaceID_XUL)) {
+      columnCount++;
+    }
+  }
+
+  return columnCount;
+}
+
+PRUint32
+XULListboxAccessible::RowCount()
+{
+  nsCOMPtr<nsIDOMXULSelectControlElement> element(do_QueryInterface(mContent));
+
+  PRUint32 itemCount = 0;
+  if(element)
+    element->GetItemCount(&itemCount);
+
+  return itemCount;
+}
+
+Accessible*
+XULListboxAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
+{ 
+  nsCOMPtr<nsIDOMXULSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ENSURE_TRUE(control, nsnull);
+
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
+  control->GetItemAtIndex(aRowIndex, getter_AddRefs(item));
+  if (!item)
+    return nsnull;
+
+  nsCOMPtr<nsIContent> itemContent(do_QueryInterface(item));
+  if (!itemContent)
+    return nsnull;
+
+  Accessible* row = mDoc->GetAccessible(itemContent);
+  NS_ENSURE_TRUE(row, nsnull);
+
+  return row->GetChildAt(aColumnIndex);
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32* aColumn)
+{
+  NS_ENSURE_ARG_POINTER(aColumn);
+  *aColumn = -1;
+
+  PRInt32 columnCount = 0;
+  nsresult rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aColumn = aIndex % columnCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32* aRow)
+{
+  NS_ENSURE_ARG_POINTER(aRow);
+  *aRow = -1;
+
+  PRInt32 columnCount = 0;
+  nsresult rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aRow = aIndex / columnCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetRowAndColumnIndicesAt(PRInt32 aCellIndex,
+                                               PRInt32* aRowIndex,
+                                               PRInt32* aColumnIndex)
+{
+  NS_ENSURE_ARG_POINTER(aRowIndex);
+  *aRowIndex = -1;
+  NS_ENSURE_ARG_POINTER(aColumnIndex);
+  *aColumnIndex = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  PRInt32 columnCount = 0;
+  nsresult rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aColumnIndex = aCellIndex % columnCount;
+  *aRowIndex = aCellIndex / columnCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetColumnDescription(PRInt32 aColumn,
+                                           nsAString& aDescription)
+{
+  aDescription.Truncate();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetRowDescription(PRInt32 aRow, nsAString& aDescription)
+{
+  aDescription.Truncate();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::IsColumnSelected(PRInt32 aColumn, bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  PRInt32 selectedrowCount = 0;
+  nsresult rv = control->GetSelectedCount(&selectedrowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 rowCount = 0;
+  rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aIsSelected = (selectedrowCount == rowCount);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::IsRowSelected(PRInt32 aRow, bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULSelectControlElement.");
+
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
+  control->GetItemAtIndex(aRow, getter_AddRefs(item));
+  NS_ENSURE_TRUE(item, NS_ERROR_INVALID_ARG);
+
+  return item->GetSelected(aIsSelected);
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::IsCellSelected(PRInt32 aRowIndex, PRInt32 aColumnIndex,
+                                     bool* aIsSelected)
+{
+  return IsRowSelected(aRowIndex, aIsSelected);
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedCellCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  nsCOMPtr<nsIDOMNodeList> selectedItems;
+  control->GetSelectedItems(getter_AddRefs(selectedItems));
+  if (!selectedItems)
+    return NS_OK;
+
+  PRUint32 selectedItemsCount = 0;
+  nsresult rv = selectedItems->GetLength(&selectedItemsCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (!selectedItemsCount)
+    return NS_OK;
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aCount = selectedItemsCount * columnCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedColumnCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  PRInt32 selectedrowCount = 0;
+  nsresult rv = control->GetSelectedCount(&selectedrowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 rowCount = 0;
+  rv = GetRowCount(&rowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (selectedrowCount != rowCount)
+    return NS_OK;
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aCount = columnCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedRowCount(PRUint32* aCount)
+{
+  NS_ENSURE_ARG_POINTER(aCount);
+  *aCount = 0;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  PRInt32 selectedrowCount = 0;
+  nsresult rv = control->GetSelectedCount(&selectedrowCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aCount = selectedrowCount;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedCells(nsIArray** aCells)
+{
+  NS_ENSURE_ARG_POINTER(aCells);
+  *aCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsresult rv = NS_OK;
+  nsCOMPtr<nsIMutableArray> selCells =
+    do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  nsCOMPtr<nsIDOMNodeList> selectedItems;
+  control->GetSelectedItems(getter_AddRefs(selectedItems));
+  if (!selectedItems)
+    return NS_OK;
+
+  PRUint32 selectedItemsCount = 0;
+  rv = selectedItems->GetLength(&selectedItemsCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  NS_ENSURE_TRUE(mDoc, NS_ERROR_FAILURE);
+  PRUint32 index = 0;
+  for (; index < selectedItemsCount; index++) {
+    nsCOMPtr<nsIDOMNode> itemNode;
+    selectedItems->Item(index, getter_AddRefs(itemNode));
+    nsCOMPtr<nsIContent> itemContent(do_QueryInterface(itemNode));
+    Accessible* item = mDoc->GetAccessible(itemContent);
+
+    if (item) {
+      PRUint32 cellCount = item->ChildCount();
+      for (PRUint32 cellIdx = 0; cellIdx < cellCount; cellIdx++) {
+        Accessible* cell = mChildren[cellIdx];
+        if (cell->Role() == roles::CELL)
+          selCells->AppendElement(static_cast<nsIAccessible*>(cell), false);
+      }
+    }
+  }
+
+  NS_ADDREF(*aCells = selCells);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedCellIndices(PRUint32* aNumCells,
+                                             PRInt32** aCells)
+{
+  NS_ENSURE_ARG_POINTER(aNumCells);
+  *aNumCells = 0;
+  NS_ENSURE_ARG_POINTER(aCells);
+  *aCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  nsCOMPtr<nsIDOMNodeList> selectedItems;
+  control->GetSelectedItems(getter_AddRefs(selectedItems));
+  if (!selectedItems)
+    return NS_OK;
+
+  PRUint32 selectedItemsCount = 0;
+  nsresult rv = selectedItems->GetLength(&selectedItemsCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 columnCount = 0;
+  rv = GetColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRUint32 cellsCount = selectedItemsCount * columnCount;
+
+  PRInt32 *cellsIdxArray =
+    static_cast<PRInt32*>(nsMemory::Alloc((cellsCount) * sizeof(PRInt32)));
+  NS_ENSURE_TRUE(cellsIdxArray, NS_ERROR_OUT_OF_MEMORY);
+
+  PRUint32 index = 0, cellsIdx = 0;
+  for (; index < selectedItemsCount; index++) {
+    nsCOMPtr<nsIDOMNode> itemNode;
+    selectedItems->Item(index, getter_AddRefs(itemNode));
+    nsCOMPtr<nsIDOMXULSelectControlItemElement> item =
+      do_QueryInterface(itemNode);
+
+    if (item) {
+      PRInt32 itemIdx = -1;
+      control->GetIndexOfItem(item, &itemIdx);
+      if (itemIdx != -1) {
+        PRInt32 colIdx = 0;
+        for (; colIdx < columnCount; colIdx++)
+          cellsIdxArray[cellsIdx++] = itemIdx * columnCount + colIdx;
+      }
+    }
+  }
+
+  *aNumCells = cellsCount;
+  *aCells = cellsIdxArray;
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedColumnIndices(PRUint32* aNumColumns,
+                                               PRInt32** aColumns)
+{
+  NS_ENSURE_ARG_POINTER(aNumColumns);
+  *aNumColumns = 0;
+  NS_ENSURE_ARG_POINTER(aColumns);
+  *aColumns = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  PRUint32 columnCount = 0;
+  nsresult rv = GetSelectedColumnCount(&columnCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (!columnCount)
+    return NS_OK;
+
+  PRInt32 *colsIdxArray =
+    static_cast<PRInt32*>(nsMemory::Alloc((columnCount) * sizeof(PRInt32)));
+  NS_ENSURE_TRUE(colsIdxArray, NS_ERROR_OUT_OF_MEMORY);
+
+  PRUint32 colIdx = 0;
+  for (; colIdx < columnCount; colIdx++)
+    colsIdxArray[colIdx] = colIdx;
+
+  *aNumColumns = columnCount;
+  *aColumns = colsIdxArray;
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::GetSelectedRowIndices(PRUint32* aNumRows,
+                                            PRInt32** aRows)
+{
+  NS_ENSURE_ARG_POINTER(aNumRows);
+  *aNumRows = 0;
+  NS_ENSURE_ARG_POINTER(aRows);
+  *aRows = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  nsCOMPtr<nsIDOMNodeList> selectedItems;
+  control->GetSelectedItems(getter_AddRefs(selectedItems));
+  if (!selectedItems)
+    return NS_OK;
+
+  PRUint32 selectedItemsCount = 0;
+  nsresult rv = selectedItems->GetLength(&selectedItemsCount);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (!selectedItemsCount)
+    return NS_OK;
+
+  PRInt32 *rowsIdxArray =
+    static_cast<PRInt32*>(nsMemory::Alloc((selectedItemsCount) * sizeof(PRInt32)));
+  NS_ENSURE_TRUE(rowsIdxArray, NS_ERROR_OUT_OF_MEMORY);
+
+  PRUint32 index = 0;
+  for (; index < selectedItemsCount; index++) {
+    nsCOMPtr<nsIDOMNode> itemNode;
+    selectedItems->Item(index, getter_AddRefs(itemNode));
+    nsCOMPtr<nsIDOMXULSelectControlItemElement> item =
+      do_QueryInterface(itemNode);
+
+    if (item) {
+      PRInt32 itemIdx = -1;
+      control->GetIndexOfItem(item, &itemIdx);
+      if (itemIdx != -1)
+        rowsIdxArray[index] = itemIdx;
+    }
+  }
+
+  *aNumRows = selectedItemsCount;
+  *aRows = rowsIdxArray;
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::SelectRow(PRInt32 aRow)
+{
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
+  control->GetItemAtIndex(aRow, getter_AddRefs(item));
+  NS_ENSURE_TRUE(item, NS_ERROR_INVALID_ARG);
+
+  return control->SelectItem(item);
+}
+
+NS_IMETHODIMP
+XULListboxAccessible::SelectColumn(PRInt32 aColumn)
+{
+  // xul:listbox and xul:richlistbox support row selection only.
+  return NS_OK;
+}
+
+void
+XULListboxAccessible::UnselectRow(PRUint32 aRowIdx)
+{
+  nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
+    do_QueryInterface(mContent);
+  NS_ASSERTION(control,
+               "Doesn't implement nsIDOMXULMultiSelectControlElement.");
+
+  if (control) {
+    nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
+    control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
+    control->RemoveItemFromSelection(item);
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListboxAccessible: Widgets
+
+bool
+XULListboxAccessible::IsWidget() const
+{
+  return true;
+}
+
+bool
+XULListboxAccessible::IsActiveWidget() const
+{
+  if (IsAutoCompletePopup()) {
+    nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
+      do_QueryInterface(mContent->GetParent());
+
+    if (autoCompletePopupElm) {
+      bool isOpen = false;
+      autoCompletePopupElm->GetPopupOpen(&isOpen);
+      return isOpen;
+    }
+  }
+  return FocusMgr()->HasDOMFocus(mContent);
+}
+
+bool
+XULListboxAccessible::AreItemsOperable() const
+{
+  if (IsAutoCompletePopup()) {
+    nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
+      do_QueryInterface(mContent->GetParent());
+
+    if (autoCompletePopupElm) {
+      bool isOpen = false;
+      autoCompletePopupElm->GetPopupOpen(&isOpen);
+      return isOpen;
+    }
+  }
+  return true;
+}
+
+Accessible*
+XULListboxAccessible::ContainerWidget() const
+{
+  if (IsAutoCompletePopup()) {
+    // This works for XUL autocompletes. It doesn't work for HTML forms
+    // autocomplete because of potential crossprocess calls (when autocomplete
+    // lives in content process while popup lives in chrome process). If that's
+    // a problem then rethink Widgets interface.
+    nsCOMPtr<nsIDOMXULMenuListElement> menuListElm =
+      do_QueryInterface(mContent->GetParent());
+    if (menuListElm) {
+      nsCOMPtr<nsIDOMNode> inputElm;
+      menuListElm->GetInputField(getter_AddRefs(inputElm));
+      if (inputElm) {
+        nsCOMPtr<nsINode> inputNode = do_QueryInterface(inputElm);
+        if (inputNode) {
+          Accessible* input = 
+            mDoc->GetAccessible(inputNode);
+          return input ? input->ContainerWidget() : nsnull;
+        }
+      }
+    }
+  }
+  return nsnull;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListitemAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULListitemAccessible::
+  XULListitemAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  XULMenuitemAccessible(aContent, aDoc)
+{
+  mIsCheckbox = mContent->AttrValueIs(kNameSpaceID_None,
+                                      nsGkAtoms::type,
+                                      nsGkAtoms::checkbox,
+                                      eCaseMatters);
+}
+
+NS_IMPL_ISUPPORTS_INHERITED0(XULListitemAccessible, Accessible)
+
+Accessible* 
+XULListitemAccessible::GetListAccessible()
+{
+  if (IsDefunct())
+    return nsnull;
+  
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> listItem =
+    do_QueryInterface(mContent);
+  if (!listItem)
+    return nsnull;
+
+  nsCOMPtr<nsIDOMXULSelectControlElement> list;
+  listItem->GetControl(getter_AddRefs(list));
+
+  nsCOMPtr<nsIContent> listContent(do_QueryInterface(list));
+  if (!listContent)
+    return nsnull;
+
+  return mDoc->GetAccessible(listContent);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListitemAccessible Accessible
+
+void
+XULListitemAccessible::Description(nsString& aDesc)
+{
+  AccessibleWrap::Description(aDesc);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListitemAccessible. nsIAccessible
+
+/**
+  * If there is a Listcell as a child ( not anonymous ) use it, otherwise
+  *   default to getting the name from GetXULName
+  */
+nsresult
+XULListitemAccessible::GetNameInternal(nsAString& aName)
+{
+  nsIContent* childContent = mContent->GetFirstChild();
+  if (childContent) {
+    if (childContent->NodeInfo()->Equals(nsGkAtoms::listcell,
+                                         kNameSpaceID_XUL)) {
+      childContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
+      return NS_OK;
+    }
+  }
+  return GetXULName(aName);
+}
+
+role
+XULListitemAccessible::NativeRole()
+{
+  Accessible* list = GetListAccessible();
+  if (!list) {
+    NS_ERROR("No list accessible for listitem accessible!");
+    return roles::NOTHING;
+  }
+
+  if (list->Role() == roles::TABLE)
+    return roles::ROW;
+
+  if (mIsCheckbox)
+    return roles::CHECK_RICH_OPTION;
+
+  if (mParent && mParent->Role() == roles::COMBOBOX_LIST)
+    return roles::COMBOBOX_OPTION;
+
+  return roles::RICH_OPTION;
+}
+
+PRUint64
+XULListitemAccessible::NativeState()
+{
+  if (mIsCheckbox)
+    return XULMenuitemAccessible::NativeState();
+
+  PRUint64 states = NativeInteractiveState();
+
+  nsCOMPtr<nsIDOMXULSelectControlItemElement> listItem =
+    do_QueryInterface(mContent);
+
+  if (listItem) {
+    bool isSelected;
+    listItem->GetSelected(&isSelected);
+    if (isSelected)
+      states |= states::SELECTED;
+
+    if (FocusMgr()->IsFocused(this))
+      states |= states::FOCUSED;
+  }
+
+  return states;
+}
+
+PRUint64
+XULListitemAccessible::NativeInteractiveState() const
+{
+  return NativelyUnavailable() || (mParent && mParent->NativelyUnavailable()) ?
+    states::UNAVAILABLE : states::FOCUSABLE | states::SELECTABLE;
+}
+
+NS_IMETHODIMP
+XULListitemAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
+{
+  if (aIndex == eAction_Click && mIsCheckbox) {
+    // check or uncheck
+    PRUint64 states = NativeState();
+
+    if (states & states::CHECKED)
+      aName.AssignLiteral("uncheck");
+    else
+      aName.AssignLiteral("check");
+
+    return NS_OK;
+  }
+  return NS_ERROR_INVALID_ARG;
+}
+
+bool
+XULListitemAccessible::CanHaveAnonChildren()
+{
+  // That indicates we should walk anonymous children for listitems
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListitemAccessible: Widgets
+
+Accessible*
+XULListitemAccessible::ContainerWidget() const
+{
+  return Parent();
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListCellAccessible
+////////////////////////////////////////////////////////////////////////////////
+
+XULListCellAccessible::
+  XULListCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
+  HyperTextAccessibleWrap(aContent, aDoc)
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// nsISupports
+
+NS_IMPL_ISUPPORTS_INHERITED1(XULListCellAccessible,
+                             HyperTextAccessible,
+                             nsIAccessibleTableCell)
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListCellAccessible: nsIAccessibleTableCell implementation
+
+NS_IMETHODIMP
+XULListCellAccessible::GetTable(nsIAccessibleTable** aTable)
+{
+  NS_ENSURE_ARG_POINTER(aTable);
+  *aTable = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  Accessible* thisRow = Parent();
+  if (!thisRow || thisRow->Role() != roles::ROW)
+    return NS_OK;
+
+  Accessible* table = thisRow->Parent();
+  if (!table || table->Role() != roles::TABLE)
+    return NS_OK;
+
+  CallQueryInterface(table, aTable);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetColumnIndex(PRInt32* aColumnIndex)
+{
+  NS_ENSURE_ARG_POINTER(aColumnIndex);
+  *aColumnIndex = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  Accessible* row = Parent();
+  if (!row)
+    return NS_OK;
+
+  *aColumnIndex = 0;
+
+  PRInt32 indexInRow = IndexInParent();
+  for (PRInt32 idx = 0; idx < indexInRow; idx++) {
+    Accessible* cell = row->GetChildAt(idx);
+    roles::Role role = cell->Role();
+    if (role == roles::CELL || role == roles::GRID_CELL ||
+        role == roles::ROWHEADER || role == roles::COLUMNHEADER)
+      (*aColumnIndex)++;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetRowIndex(PRInt32* aRowIndex)
+{
+  NS_ENSURE_ARG_POINTER(aRowIndex);
+  *aRowIndex = -1;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  Accessible* row = Parent();
+  if (!row)
+    return NS_OK;
+
+  Accessible* table = row->Parent();
+  if (!table)
+    return NS_OK;
+
+  *aRowIndex = 0;
+
+  PRInt32 indexInTable = row->IndexInParent();
+  for (PRInt32 idx = 0; idx < indexInTable; idx++) {
+    row = table->GetChildAt(idx);
+    if (row->Role() == roles::ROW)
+      (*aRowIndex)++;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetColumnExtent(PRInt32* aExtentCount)
+{
+  NS_ENSURE_ARG_POINTER(aExtentCount);
+  *aExtentCount = 0;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  *aExtentCount = 1;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetRowExtent(PRInt32* aExtentCount)
+{
+  NS_ENSURE_ARG_POINTER(aExtentCount);
+  *aExtentCount = 0;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  *aExtentCount = 1;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetColumnHeaderCells(nsIArray** aHeaderCells)
+{
+  NS_ENSURE_ARG_POINTER(aHeaderCells);
+  *aHeaderCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIAccessibleTable> table;
+  GetTable(getter_AddRefs(table));
+  NS_ENSURE_STATE(table); // we expect to be in a listbox (table)
+
+  // Get column header cell from XUL listhead.
+  Accessible* list = nsnull;
+
+  nsRefPtr<Accessible> tableAcc(do_QueryObject(table));
+  PRUint32 tableChildCount = tableAcc->ChildCount();
+  for (PRUint32 childIdx = 0; childIdx < tableChildCount; childIdx++) {
+    Accessible* child = tableAcc->GetChildAt(childIdx);
+    if (child->Role() == roles::LIST) {
+      list = child;
+      break;
+    }
+  }
+
+  if (list) {
+    PRInt32 colIdx = -1;
+    GetColumnIndex(&colIdx);
+
+    nsIAccessible *headerCell = list->GetChildAt(colIdx);
+    if (headerCell) {
+      nsresult rv = NS_OK;
+      nsCOMPtr<nsIMutableArray> headerCells =
+        do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      headerCells->AppendElement(headerCell, false);
+      NS_ADDREF(*aHeaderCells = headerCells);
+      return NS_OK;
+    }
+  }
+
+  // No column header cell from XUL markup, try to get it from ARIA markup.
+  return nsAccUtils::GetHeaderCellsFor(table, this,
+                                       nsAccUtils::eColumnHeaderCells,
+                                       aHeaderCells);
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::GetRowHeaderCells(nsIArray** aHeaderCells)
+{
+  NS_ENSURE_ARG_POINTER(aHeaderCells);
+  *aHeaderCells = nsnull;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIAccessibleTable> table;
+  GetTable(getter_AddRefs(table));
+  NS_ENSURE_STATE(table); // we expect to be in a listbox (table)
+
+  // Calculate row header cells from ARIA markup.
+  return nsAccUtils::GetHeaderCellsFor(table, this,
+                                       nsAccUtils::eRowHeaderCells,
+                                       aHeaderCells);
+}
+
+NS_IMETHODIMP
+XULListCellAccessible::IsSelected(bool* aIsSelected)
+{
+  NS_ENSURE_ARG_POINTER(aIsSelected);
+  *aIsSelected = false;
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  nsCOMPtr<nsIAccessibleTable> table;
+  GetTable(getter_AddRefs(table));
+  NS_ENSURE_STATE(table); // we expect to be in a listbox (table)
+
+  PRInt32 rowIdx = -1;
+  GetRowIndex(&rowIdx);
+
+  return table->IsRowSelected(rowIdx, aIsSelected);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// XULListCellAccessible. Accessible implementation
+
+role
+XULListCellAccessible::NativeRole()
+{
+  return roles::CELL;
+}
+
+nsresult
+XULListCellAccessible::GetAttributesInternal(nsIPersistentProperties* aAttributes)
+{
+  NS_ENSURE_ARG_POINTER(aAttributes);
+
+  if (IsDefunct())
+    return NS_ERROR_FAILURE;
+
+  // "table-cell-index" attribute
+  nsCOMPtr<nsIAccessibleTable> table;
+  GetTable(getter_AddRefs(table));
+  NS_ENSURE_STATE(table); // we expect to be in a listbox (table)
+
+  PRInt32 rowIdx = -1;
+  GetRowIndex(&rowIdx);
+  PRInt32 colIdx = -1;
+  GetColumnIndex(&colIdx);
+
+  PRInt32 cellIdx = -1;
+  table->GetCellIndexAt(rowIdx, colIdx, &cellIdx);
+
+  nsAutoString stringIdx;
+  stringIdx.AppendInt(cellIdx);
+  nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex,
+                         stringIdx);
+
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/accessible/src/xul/XULListboxAccessible.h
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_a11y_XULListboxAccessible_h__
+#define mozilla_a11y_XULListboxAccessible_h__
+
+#include "BaseAccessibles.h"
+#include "nsIAccessibleTable.h"
+#include "TableAccessible.h"
+#include "xpcAccessibleTable.h"
+#include "XULMenuAccessible.h"
+#include "XULSelectControlAccessible.h"
+
+class nsIWeakReference;
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * XULColumAccessible are accessible for list and tree columns elements
+ * (xul:treecols and xul:listcols).