merging from cvs-trunk-mirror 2007/07/10
authoredward.lee@engineering.uiuc.edu
Tue, 10 Jul 2007 00:18:34 -0700
changeset 3621 a72b81b85b90ebe105f8dab76494f63ad4faf6d4
parent 3620 a2efe054e21c90482845dbec5cc51f866c7fb138 (current diff)
parent 3287 57ebfdc802ff02abbefa0a2ca42e21809e1c240c (diff)
child 3622 939f02de6695fdaa2a870e1ec1bfbd9792568306
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9a7pre
merging from cvs-trunk-mirror 2007/07/10
browser/base/content/browser-contentPrefSink.js
browser/base/content/browser-textZoom.js
browser/confvars.sh
browser/themes/winstripe/browser/Toolbar-rtl-small.png
browser/themes/winstripe/browser/Toolbar-rtl.png
client.mk
config/aboutime.pl
config/autoconf.mk.in
config/bdate.c
config/bdate.pl
config/build-number.pl
config/mozBDate.pm
configure.in
content/svg/content/src/nsISVGSVGElement.h
content/xul/content/public/Makefile.in
content/xul/content/public/nsIXULPopupListener.h
db/sqlite3/sqlite3-param-indexes.patch
db/sqlite3/src/alter.c
db/sqlite3/src/analyze.c
db/sqlite3/src/attach.c
db/sqlite3/src/auth.c
db/sqlite3/src/btree.c
db/sqlite3/src/btree.h
db/sqlite3/src/build.c
db/sqlite3/src/callback.c
db/sqlite3/src/complete.c
db/sqlite3/src/config.h
db/sqlite3/src/date.c
db/sqlite3/src/delete.c
db/sqlite3/src/experimental.c
db/sqlite3/src/expr.c
db/sqlite3/src/func.c
db/sqlite3/src/hash.c
db/sqlite3/src/hash.h
db/sqlite3/src/insert.c
db/sqlite3/src/keywordhash.h
db/sqlite3/src/legacy.c
db/sqlite3/src/main.c
db/sqlite3/src/md5.c
db/sqlite3/src/opcodes.c
db/sqlite3/src/opcodes.h
db/sqlite3/src/os.c
db/sqlite3/src/os.h
db/sqlite3/src/os_beos.c
db/sqlite3/src/os_common.h
db/sqlite3/src/os_os2.c
db/sqlite3/src/os_os2.h
db/sqlite3/src/os_unix.c
db/sqlite3/src/os_unix.h
db/sqlite3/src/os_win.c
db/sqlite3/src/os_win.h
db/sqlite3/src/pager.c
db/sqlite3/src/pager.h
db/sqlite3/src/parse.c
db/sqlite3/src/parse.h
db/sqlite3/src/pragma.c
db/sqlite3/src/prepare.c
db/sqlite3/src/printf.c
db/sqlite3/src/random.c
db/sqlite3/src/select.c
db/sqlite3/src/shell.c
db/sqlite3/src/sqliteInt.h
db/sqlite3/src/table.c
db/sqlite3/src/tclsqlite.c
db/sqlite3/src/test_async.c
db/sqlite3/src/test_server.c
db/sqlite3/src/tokenize.c
db/sqlite3/src/trigger.c
db/sqlite3/src/update.c
db/sqlite3/src/utf.c
db/sqlite3/src/util.c
db/sqlite3/src/vacuum.c
db/sqlite3/src/vdbe.c
db/sqlite3/src/vdbe.h
db/sqlite3/src/vdbeInt.h
db/sqlite3/src/vdbeapi.c
db/sqlite3/src/vdbeaux.c
db/sqlite3/src/vdbefifo.c
db/sqlite3/src/vdbemem.c
db/sqlite3/src/where.c
extensions/inspector/resources/content/contents.rdf
extensions/inspector/resources/content/search/inSearchModule.js
extensions/inspector/resources/content/search/inSearchService.js
extensions/inspector/resources/content/search/inSearchTreeBuilder.js
extensions/inspector/resources/content/search/inSearchUtils.js
extensions/inspector/resources/content/search/modules/commandOverlay.xul
extensions/inspector/resources/content/search/modules/findFiles/dialog.js
extensions/inspector/resources/content/search/modules/findFiles/dialog.xul
extensions/inspector/resources/content/search/modules/findFiles/findFiles.xml
extensions/inspector/resources/content/search/modules/junkImgs/dialog.js
extensions/inspector/resources/content/search/modules/junkImgs/dialog.xul
extensions/inspector/resources/content/search/modules/junkImgs/junkImgs.xml
extensions/inspector/resources/content/search/modules/popupOverlay.xul
extensions/inspector/resources/locale/en-US/search/findFiles.dtd
extensions/inspector/resources/locale/en-US/search/junkImgs.dtd
extensions/inspector/resources/locale/fr/search/findFiles.dtd
extensions/inspector/resources/locale/fr/search/junkImgs.dtd
extensions/inspector/resources/locale/nb-NO/search/findFiles.dtd
extensions/inspector/resources/locale/nb-NO/search/junkImgs.dtd
extensions/inspector/resources/locale/pl/search/findFiles.dtd
extensions/inspector/resources/locale/pl/search/junkImgs.dtd
extensions/inspector/resources/skin/classic/contents.rdf
extensions/inspector/resources/skin/modern/contents.rdf
gfx/public/nsIBlender.h
gfx/public/nsIDrawingSurface.h
gfx/src/gtk/Makefile.in
gfx/src/gtk/fontEncoding.properties
gfx/src/gtk/gfxgtk.pkg
gfx/src/gtk/mozilla-decoder.cpp
gfx/src/gtk/mozilla-decoder.h
gfx/src/gtk/nsDeviceContextGTK.cpp
gfx/src/gtk/nsDeviceContextGTK.h
gfx/src/gtk/nsDrawingSurfaceGTK.cpp
gfx/src/gtk/nsDrawingSurfaceGTK.h
gfx/src/gtk/nsFontMetricsGTK.cpp
gfx/src/gtk/nsFontMetricsGTK.h
gfx/src/gtk/nsFontMetricsPango.cpp
gfx/src/gtk/nsFontMetricsPango.h
gfx/src/gtk/nsFontMetricsUtils.cpp
gfx/src/gtk/nsFontMetricsUtils.h
gfx/src/gtk/nsFontMetricsXft.cpp
gfx/src/gtk/nsFontMetricsXft.h
gfx/src/gtk/nsGCCache.cpp
gfx/src/gtk/nsGCCache.h
gfx/src/gtk/nsGdkUtils.cpp
gfx/src/gtk/nsGdkUtils.h
gfx/src/gtk/nsGfxFactoryGTK.cpp
gfx/src/gtk/nsGraphicsStateGTK.cpp
gfx/src/gtk/nsGraphicsStateGTK.h
gfx/src/gtk/nsIFontMetricsGTK.h
gfx/src/gtk/nsImageGTK.cpp
gfx/src/gtk/nsImageGTK.h
gfx/src/gtk/nsRegionGTK.cpp
gfx/src/gtk/nsRegionGTK.h
gfx/src/gtk/nsRegionGTK2.cpp
gfx/src/gtk/nsRenderingContextGTK.cpp
gfx/src/gtk/nsRenderingContextGTK.h
gfx/src/gtk/pangoFontEncoding.properties
gfx/src/gtk/xregion.h
gfx/src/nsBlender.cpp
gfx/src/nsBlender.h
gfx/src/ps/Courier-Bold.h
gfx/src/ps/Courier-BoldOblique.h
gfx/src/ps/Courier-Oblique.h
gfx/src/ps/Courier.h
gfx/src/ps/Helvetica-Bold.h
gfx/src/ps/Helvetica-BoldOblique.h
gfx/src/ps/Helvetica-Oblique.h
gfx/src/ps/Helvetica.h
gfx/src/ps/Makefile.in
gfx/src/ps/Symbol.h
gfx/src/ps/Times-Bold.h
gfx/src/ps/Times-BoldItalic.h
gfx/src/ps/Times-Italic.h
gfx/src/ps/Times-Roman.h
gfx/src/ps/gfxps.pkg
gfx/src/ps/isotab.c
gfx/src/ps/nsAFMObject.cpp
gfx/src/ps/nsAFMObject.h
gfx/src/ps/nsCidMap.cpp
gfx/src/ps/nsCidMap.h
gfx/src/ps/nsDeviceContextPS.cpp
gfx/src/ps/nsDeviceContextPS.h
gfx/src/ps/nsEPSObjectPS.cpp
gfx/src/ps/nsEPSObjectPS.h
gfx/src/ps/nsFontMetricsPS.cpp
gfx/src/ps/nsFontMetricsPS.h
gfx/src/ps/nsGfxFactoryPS.cpp
gfx/src/ps/nsGfxPSCID.h
gfx/src/ps/nsIDeviceContextPS.h
gfx/src/ps/nsIDeviceContextSpecPS.h
gfx/src/ps/nsIPrintJobPS.h
gfx/src/ps/nsPostScriptObj.cpp
gfx/src/ps/nsPostScriptObj.h
gfx/src/ps/nsPrintJobFactoryPS.cpp
gfx/src/ps/nsPrintJobFactoryPS.h
gfx/src/ps/nsPrintJobPS.cpp
gfx/src/ps/nsPrintJobPS.h
gfx/src/ps/nsPrintOptionsPS.cpp
gfx/src/ps/nsPrintOptionsPS.h
gfx/src/ps/nsRenderingContextPS.cpp
gfx/src/ps/nsRenderingContextPS.h
gfx/src/ps/nsTempfilePS.cpp
gfx/src/ps/nsTempfilePS.h
gfx/src/ps/nsType1.cpp
gfx/src/ps/nsType1.h
gfx/src/ps/sample.unixpsfonts.properties
gfx/src/thebes/nsIThebesRenderingContext.h
gfx/src/thebes/nsThebesBlender.cpp
gfx/src/thebes/nsThebesBlender.h
gfx/src/thebes/nsThebesDrawingSurface.cpp
gfx/src/thebes/nsThebesDrawingSurface.h
gfx/src/x11shared/README
gfx/src/x11shared/dbyte_special_chars.ccmap
gfx/src/x11shared/nsAntiAliasedGlyph.cpp
gfx/src/x11shared/nsAntiAliasedGlyph.h
gfx/src/x11shared/nsFT2FontCatalog.cpp
gfx/src/x11shared/nsFT2FontCatalog.h
gfx/src/x11shared/nsFT2FontNode.cpp
gfx/src/x11shared/nsFT2FontNode.h
gfx/src/x11shared/nsFontDebug.h
gfx/src/x11shared/nsFontFreeType.cpp
gfx/src/x11shared/nsFontFreeType.h
gfx/src/x11shared/nsNameValuePairDB.cpp
gfx/src/x11shared/nsNameValuePairDB.h
gfx/src/x11shared/nsX11AlphaBlend.cpp
gfx/src/x11shared/nsX11AlphaBlend.h
gfx/src/x11shared/nsXFont.h
gfx/src/x11shared/nsXFontAAScaledBitmap.cpp
gfx/src/x11shared/nsXFontAAScaledBitmap.h
gfx/src/x11shared/nsXFontNormal.cpp
gfx/src/x11shared/nsXFontNormal.h
intl/uconv/ucvja/nsCP932ToUnicode.cpp
intl/uconv/ucvja/nsCP932ToUnicode.h
intl/uconv/ucvja/nsUnicodeToCP932.cpp
intl/uconv/ucvja/nsUnicodeToCP932.h
intl/uconv/ucvtw/nsCP950ToUnicode.cpp
intl/uconv/ucvtw/nsCP950ToUnicode.h
intl/uconv/ucvtw/nsUnicodeToCP950.cpp
intl/uconv/ucvtw/nsUnicodeToCP950.h
js/src/xpconnect/idl/xpcIJSWeakReference.idl
js/src/xpconnect/src/xpcJSWeakReference.cpp
js/src/xpconnect/src/xpcJSWeakReference.h
js/src/xpconnect/tests/unit/test_js_weak_references.js
js/tests/js1_5/Regress/regress-382509.js
js/tests/js1_5/extensions/regress-380831.js
js/tests/js1_5/extensions/regress-382509.js
js/tests/js1_8/extensions/regress-300079.js
layout/base/bidicattable.h
layout/base/nsBidiUtils.cpp
layout/base/nsBidiUtils.h
layout/base/symmtable.h
layout/build/nsContentHTTPStartup.cpp
layout/build/nsContentHTTPStartup.h
layout/generic/nsTextFrame.cpp
layout/generic/nsTextTransformer.cpp
layout/generic/nsTextTransformer.h
layout/reftests/svg/text-font-weight-01.svg
layout/tools/genbidicattable.pl
layout/tools/gensymmtable.pl
layout/xul/base/public/nsIPopupSetFrame.h
layout/xul/base/src/nsMenuDismissalListener.cpp
layout/xul/base/src/nsMenuDismissalListener.h
layout/xul/base/src/nsMenuListener.cpp
layout/xul/base/src/nsMenuListener.h
modules/libpr0n/decoders/gif/GIF2.cpp
netwerk/cookie/public/nsICookieConsent.idl
netwerk/cookie/public/nsICookieServiceInternal.idl
testing/tests/l10n/scripts/compare-packs
toolkit/airbag/tools/make_symbol_store.pl
toolkit/airbag/tools/symbolstore.py
toolkit/components/contentprefs/Makefile.in
toolkit/components/contentprefs/public/Makefile.in
toolkit/components/contentprefs/public/nsIContentPrefService.idl
toolkit/components/contentprefs/public/nsIContentURIGrouper.idl
toolkit/components/contentprefs/src/Makefile.in
toolkit/components/contentprefs/src/nsContentPrefService.js
toolkit/components/contentprefs/tests/Makefile.in
toolkit/components/contentprefs/tests/unit/head_contentPrefs.js
toolkit/components/contentprefs/tests/unit/tail_contentPrefs.js
toolkit/components/contentprefs/tests/unit/test_contentPrefs.js
toolkit/components/downloads/public/nsIXPInstallManagerUI.idl
toolkit/components/passwordmgr/test/test_bug_270558.html
toolkit/mozapps/installer/makeall.pl
toolkit/mozapps/installer/makejs.pl
toolkit/mozapps/installer/makexpi.pl
toolkit/mozapps/installer/parseandmakejs.pl
toolkit/themes/pmstripe/global/browser.css
toolkit/xre/nsIXULAppInfo.idl
tools/l10n/l10n.py
view/public/nsICompositeListener.h
widget/src/gtk2/nsIGdkPixbufImage.h
widget/src/gtk2/nsTempfilePS.cpp
widget/src/gtk2/nsTempfilePS.h
widget/src/xpwidgets/nsDataFlavor.cpp
widget/src/xpwidgets/nsDataFlavor.h
xpcom/glue/standalone/nsGREDirServiceProvider.cpp
xpcom/glue/standalone/nsGREDirServiceProvider.h
xpfe/components/filepicker/res/content/filepicker.js
xpfe/components/filepicker/res/content/filepicker.xul
xpfe/components/filepicker/res/locale/en-US/filepicker.dtd
xpfe/components/filepicker/res/locale/en-US/filepicker.properties
xpinstall/packager/Makefile.in
xpinstall/packager/StageUtils.pm
xpinstall/packager/build/cfgs/gre.pl
xpinstall/packager/build/cfgs/mfcembed.pl
xpinstall/packager/build/cfgs/mozilla.pl
xpinstall/packager/build/scripts/GetLongFile.pl
xpinstall/packager/build/scripts/intljst.tmpl
xpinstall/packager/build/scripts/makeall.pl
xpinstall/packager/build/scripts/makecfgini.pl
xpinstall/packager/build/scripts/makejar.pl
xpinstall/packager/build/scripts/makejs.pl
xpinstall/packager/build/scripts/makeuninstallini.pl
xpinstall/packager/build/scripts/makexpi.pl
xpinstall/packager/build/scripts/rdir.pl
xpinstall/packager/build/win/gre/XPI_JSTs/gre.jst
xpinstall/packager/build/win/gre/config.it
xpinstall/packager/build/win/gre/defaults_info.ini
xpinstall/packager/build/win/gre/install.it
xpinstall/packager/build/win/gre/uninstall.it
xpinstall/packager/build/win/mfcembed/XPI_JSTs/mfcembed.jst
xpinstall/packager/build/win/mfcembed/config.it
xpinstall/packager/build/win/mfcembed/defaults_info.ini
xpinstall/packager/build/win/mfcembed/install.it
xpinstall/packager/build/win/mfcembed/uninstall.it
xpinstall/packager/build/win/mozilla/XPI_JSTs/browser.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/chatzilla.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/deflenus.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/inspector.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/psm.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/talkback.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/venkman.jst
xpinstall/packager/build/win/mozilla/XPI_JSTs/xpcom.jst
xpinstall/packager/build/win/mozilla/config.it
xpinstall/packager/build/win/mozilla/defaults_info.ini
xpinstall/packager/build/win/mozilla/install.it
xpinstall/packager/build/win/mozilla/uninstall.it
xpinstall/packager/mac/ASEncoder/build/ASEncoder
xpinstall/packager/mac/ASEncoder/build/ASEncoder.mcp
xpinstall/packager/mac/ASEncoder/rsrc/ASEncoder.rsrc
xpinstall/packager/mac/ASEncoder/src/ASEncoderUsage.script
xpinstall/packager/mac/ASEncoder/src/FolderCodingUsage.script
xpinstall/packager/mac/ASEncoder/src/nsASEApp.cpp
xpinstall/packager/mac/ASEncoder/src/nsASEApp.h
xpinstall/packager/mac/ASEncoder/src/nsAppleSingleEncoder.cpp
xpinstall/packager/mac/ASEncoder/src/nsAppleSingleEncoder.h
xpinstall/packager/mac/ASEncoder/src/nsEventHandler.cpp
xpinstall/packager/mac/ASEncoder/src/nsEventHandler.h
xpinstall/packager/mac/ASEncoder/src/nsFileSelector.cpp
xpinstall/packager/mac/ASEncoder/src/nsFileSelector.h
xpinstall/packager/mac/browser.jst
xpinstall/packager/mac/chatzilla.jst
xpinstall/packager/mac/deflenus.jst
xpinstall/packager/mac/editor.jst
xpinstall/packager/mac/inspector.jst
xpinstall/packager/mac/langende.jst
xpinstall/packager/mac/langengb.jst
xpinstall/packager/mac/langenus.jst
xpinstall/packager/mac/mail.jst
xpinstall/packager/mac/spellcheck.jst
xpinstall/packager/mac/talkback.jst
xpinstall/packager/mac/update.html
xpinstall/packager/mac/venkman.jst
xpinstall/packager/mac/xpcom.jst
xpinstall/packager/make_pkgs_from_list.pl
xpinstall/packager/make_stage.pl
xpinstall/packager/packages-os2
xpinstall/packager/packages-static-unix
xpinstall/packager/packages-static-win
xpinstall/packager/packages-unix
xpinstall/packager/packages-win
xpinstall/packager/pkgs-mfcembed-win
xpinstall/packager/pkgs-mfcembed-win-supp
xpinstall/packager/stage_gre.pl
xpinstall/packager/stage_mfcembed.pl
xpinstall/packager/stage_mozilla.pl
xpinstall/packager/win_gre/GetLongFile.pl
xpinstall/packager/win_gre/Makefile.in
xpinstall/packager/win_gre/config.it
xpinstall/packager/win_gre/defaults_info.ini
xpinstall/packager/win_gre/gre.jst
xpinstall/packager/win_gre/install.it
xpinstall/packager/win_gre/installgre.pkg
xpinstall/packager/win_gre/makeall.pl
xpinstall/packager/win_gre/makecfgini.pl
xpinstall/packager/win_gre/makejs.pl
xpinstall/packager/win_gre/makeuninstallini.pl
xpinstall/packager/win_gre/makexpi.pl
xpinstall/packager/win_gre/rdir.pl
xpinstall/packager/win_gre/uninstall.it
xpinstall/packager/win_mfcembed/GetLongFile.pl
xpinstall/packager/win_mfcembed/Makefile.in
xpinstall/packager/win_mfcembed/config.it
xpinstall/packager/win_mfcembed/defaults_info.ini
xpinstall/packager/win_mfcembed/install.it
xpinstall/packager/win_mfcembed/installmfc.pkg
xpinstall/packager/win_mfcembed/makeall.pl
xpinstall/packager/win_mfcembed/makecfgini.pl
xpinstall/packager/win_mfcembed/makejs.pl
xpinstall/packager/win_mfcembed/makeuninstallini.pl
xpinstall/packager/win_mfcembed/makexpi.pl
xpinstall/packager/win_mfcembed/mfcembed.jst
xpinstall/packager/win_mfcembed/rdir.pl
xpinstall/packager/win_mfcembed/runapp.bat
xpinstall/packager/win_mfcembed/uninstall.it
xpinstall/packager/windows/GetLongFile.pl
xpinstall/packager/windows/Makefile.in
xpinstall/packager/windows/browser.jst
xpinstall/packager/windows/chatzilla.jst
xpinstall/packager/windows/config.it
xpinstall/packager/windows/defaults_info.ini
xpinstall/packager/windows/deflenus.jst
xpinstall/packager/windows/editor.jst
xpinstall/packager/windows/inspector.jst
xpinstall/packager/windows/install.it
xpinstall/packager/windows/langende.jst
xpinstall/packager/windows/langengb.jst
xpinstall/packager/windows/langenus.jst
xpinstall/packager/windows/mail.jst
xpinstall/packager/windows/makeall.pl
xpinstall/packager/windows/makecfgini.pl
xpinstall/packager/windows/makejs.pl
xpinstall/packager/windows/makeuninstallini.pl
xpinstall/packager/windows/makexpi.pl
xpinstall/packager/windows/mozilla-win32-stub-installer.jst
xpinstall/packager/windows/psm.jst
xpinstall/packager/windows/rdir.pl
xpinstall/packager/windows/redirect.it
xpinstall/packager/windows/reporter.jst
xpinstall/packager/windows/sroaming.jst
xpinstall/packager/windows/talkback.jst
xpinstall/packager/windows/uninstall.it
xpinstall/packager/windows/venkman.jst
xpinstall/packager/windows/xpcom.jst
xpinstall/packager/xpcom-win.pkg
xpinstall/packager/xptzip.pl
--- a/.hgtags
+++ b/.hgtags
@@ -1,1 +1,2 @@
 df7a3c8ffeeaba229067efee5a20e21dae0dd877 MOZILLA_1_9_a4_BASE
+4209e16b58411750ac73f761023e46b76b793e2c MOZILLA_1_9_a6_BASE
--- a/Makefile.in
+++ b/Makefile.in
@@ -106,17 +106,17 @@ endif
 distclean::
 	cat unallmakefiles | $(XARGS) rm -f
 	rm -f unallmakefiles $(DIST_GARBAGE)
 
 ifeq ($(OS_ARCH),WINNT)
 rebase:
 ifdef MOZILLA_OFFICIAL
 	echo rebasing $(DIST)
-	/bin/find $(DIST) -name "*.dll" > rebase.lst
+	/bin/find $(DIST) -name "*.dll" -a -not -name "msvc*" > rebase.lst
 	rebase -b 60000000 -R . -G rebase.lst
 	rm rebase.lst
 endif
 
 splitsymbols:
 ifdef MOZILLA_OFFICIAL
 ifdef MOZ_DEBUG_SYMBOLS
 	echo finding pdb files
@@ -132,56 +132,51 @@ ifdef MOZ_PROFILE
 	/bin/find $(DIST) -name "*.EXE" -exec splitsym {} \;
 	mkdir -p $(DIST)/$(BUILDID)
 	/bin/find $(DIST) -name "*.dbg" -exec mv {} $(DIST)/$(BUILDID) \;
 endif # MOZ_PROFILE
 endif # MOZILLA_OFFICIAL
 endif # WINNT
 
 ifeq ($(OS_ARCH),WINNT)
-SYM_FIND_CMD := /bin/find . -path dist -prune -o -name "*.exe" \
-    -o -name "*.dll" -o -name "*.EXE" | sed "s/\.[^\.]*$$/\.pdb/"
 # we want to copy PDB files on Windows
 MAKE_SYM_STORE_ARGS := -c
 DUMP_SYMS_BIN := $(topsrcdir)/toolkit/airbag/tools/win32/dump_syms.exe
+# PDB files don't get moved to dist, so we need to scan the whole objdir
+MAKE_SYM_STORE_PATH := .
 endif
 ifeq ($(OS_ARCH),Darwin)
 # need to pass arch flags for universal builds
 ifdef UNIVERSAL_BINARY
-MAKE_SYM_STORE_ARGS := -a "ppc i386"
-SYM_DIST := $(DIST)/universal
+MAKE_SYM_STORE_ARGS := -a "ppc i386" --vcs-info
+MAKE_SYM_STORE_PATH := $(DIST)/universal
 else
-MAKE_SYM_STORE_ARGS := -a $(OS_TEST)
-SYM_DIST := $(DIST)
+MAKE_SYM_STORE_ARGS := -a $(OS_TEST) --vcs-info
+MAKE_SYM_STORE_PATH := $(DIST)/bin
 endif
-# |file| is stupid on universal binaries, it produces one line of output
-# for the file, and one line of output for each architecture contained within.
-SYM_FIND_CMD := find -L $(SYM_DIST) -type f -a -perm -100 -o -name "*.dylib" \
-    | xargs file -L | grep "Mach-O" | grep -v "for architecture" | cut -f1 -d':'
 DUMP_SYMS_BIN := $(DIST)/host/bin/dump_syms
 endif
 ifeq ($(OS_ARCH),Linux)
-MAKE_SYM_STORE_ARGS :=
-SYM_FIND_CMD := find -L $(DIST)/bin -type f -a -perm -100 -o -name "*.so" \
-    | xargs file -L | grep "ELF" | cut -f1 -d':'
+MAKE_SYM_STORE_ARGS := --vcs-info
 DUMP_SYMS_BIN := $(DIST)/host/bin/dump_syms
+MAKE_SYM_STORE_PATH := $(DIST)/bin
 endif
 
 ifdef MOZ_SYMBOLS_EXTRA_BUILDID
 EXTRA_BUILDID := -$(MOZ_SYMBOLS_EXTRA_BUILDID)
 endif
 
 buildsymbols:
 ifdef MOZ_AIRBAG
 	echo building symbol store
 	mkdir -p $(DIST)/crashreporter-symbols/$(BUILDID)
-	$(SYM_FIND_CMD) | \
-	  xargs $(topsrcdir)/toolkit/airbag/tools/make_symbol_store.pl    \
-	  $(MAKE_SYM_STORE_ARGS) $(DUMP_SYMS_BIN)                         \
-	  $(DIST)/crashreporter-symbols/$(BUILDID) >                      \
+	$(PYTHON) $(topsrcdir)/toolkit/airbag/tools/symbolstore.py    \
+	  $(MAKE_SYM_STORE_ARGS) -s $(topsrcdir) $(DUMP_SYMS_BIN)     \
+	  $(DIST)/crashreporter-symbols/$(BUILDID)                    \
+	  $(MAKE_SYM_STORE_PATH) >                                    \
 	  $(DIST)/crashreporter-symbols/$(BUILDID)/$(MOZ_APP_NAME)-$(MOZ_APP_VERSION)-$(OS_ARCH)-$(BUILDID)$(EXTRA_BUILDID)-symbols.txt
 	echo packing symbols
 	mkdir -p $(topsrcdir)/../$(BUILDID)
 	cd $(DIST)/crashreporter-symbols/$(BUILDID) && \
           zip -r9D ../crashreporter-symbols-$(BUILDID).zip .
 	mv $(DIST)/crashreporter-symbols/crashreporter-symbols-$(BUILDID).zip \
           $(topsrcdir)/../$(BUILDID)
 endif # MOZ_AIRBAG
@@ -198,9 +193,9 @@ ifdef MOZILLA_OFFICIAL
 	cd $(DIST)/bin; ./shlibsign.exe -v -i softokn3.dll
 	cd $(DIST)/bin; ./shlibsign.exe -v -i freebl3.dll
 endif # MOZILLA_OFFICIAL
 
 deliver: splitsymbols rebase signnss
 
 endif # WINNT
 
-BUILDID = $(shell cat $(DEPTH)/config/build_number)
+BUILDID = $(shell $(PYTHON) $(srcdir)/config/printconfigsetting.py $(DIST)/bin/application.ini App BuildID)
--- a/accessible/public/nsIAccessibilityService.idl
+++ b/accessible/public/nsIAccessibilityService.idl
@@ -40,17 +40,17 @@
 #include "nsIAccessibleRetrieval.idl"
 
 interface nsIAccessibleEventListener;
 interface nsIDocument;
 interface nsIFrame;
 interface nsObjectFrame;
 interface nsIContent;
 
-[uuid(e4cdb7c5-d029-4bee-bff5-99455c6e0057)]
+[uuid(0e9e2f00-b6f1-440d-821f-6b09d264cdaf)]
 interface nsIAccessibilityService : nsIAccessibleRetrieval
 {
   nsIAccessible createOuterDocAccessible(in nsIDOMNode aNode);
   nsIAccessible createRootAccessible(in nsIPresShell aShell, in nsIDocument aDocument);
 
   nsIAccessible createHTML4ButtonAccessible(in nsISupports aFrame);
   nsIAccessible createHTMLAreaAccessible(in nsIWeakReference aPresShell, in nsIDOMNode aDOMNode, in nsIAccessible aAccParent);
   nsIAccessible createHyperTextAccessible(in nsISupports aFrame);
@@ -69,16 +69,17 @@ interface nsIAccessibilityService : nsIA
   nsIAccessible createHTMLObjectFrameAccessible(in nsObjectFrame aFrame);
   nsIAccessible createHTMLRadioButtonAccessible(in nsISupports aFrame);
   nsIAccessible createHTMLSelectOptionAccessible(in nsIDOMNode aNode, in nsIAccessible aAccParent, in nsIWeakReference aPresShell);
   nsIAccessible createHTMLTableAccessible(in nsISupports aFrame);
   nsIAccessible createHTMLTableCellAccessible(in nsISupports aFrame);
   nsIAccessible createHTMLTableHeadAccessible(in nsIDOMNode aDOMNode);
   nsIAccessible createHTMLTextAccessible(in nsISupports aFrame);
   nsIAccessible createHTMLTextFieldAccessible(in nsISupports aFrame);
+  nsIAccessible createHTMLCaptionAccessible(in nsISupports aFrame);
 
   nsIAccessible getAccessible(in nsIDOMNode aNode, in nsIPresShell aPresShell,                          
                               in nsIWeakReference aWeakShell, 
                               inout nsIFrame frameHint, out boolean aIsHidden);
 
   // For gtk+ native window accessible
   nsIAccessible addNativeRootAccessible(in voidPtr aAtkAccessible);
   void removeNativeRootAccessible(in nsIAccessible aRootAccessible);
--- a/accessible/public/nsIAccessibleDocument.idl
+++ b/accessible/public/nsIAccessibleDocument.idl
@@ -53,17 +53,17 @@ interface nsIDOMWindow;
  * You can QueryInterface to nsIAccessibleDocument from
  * the nsIAccessible or nsIAccessNode for the root node
  * of a document. You can also get one from 
  * nsIAccessNode::GetAccessibleDocument() or 
  * nsIAccessibleEvent::GetAccessibleDocument()
  *
  * @status UNDER_REVIEW
  */
-[scriptable, uuid(ae5792a3-77ad-40d6-8450-d28d19b66889)]
+[scriptable, uuid(6cc11286-e02d-4a8d-960a-e7a61161b230)]
 interface nsIAccessibleDocument : nsISupports
 {
   /**
    * The URL of the document
    */
   readonly attribute AString URL;
 
   /**
@@ -115,10 +115,10 @@ interface nsIAccessibleDocument : nsISup
    * Returns the first accessible parent of a DOM node.
    * Guaranteed not to return nsnull if the DOM node is in a document.
    * @param aDOMNode The DOM node we need an accessible for.
    * @param aCanCreate Can accessibles be created or must it be the first 
    *                   cached accessible in the parent chain?
    * @return An first nsIAccessible found by crawling up the DOM node
    *         to the document root.
    */
-  nsIAccessible getAccessibleInParentChain(in nsIDOMNode aDOMNode, in boolean aCanCreate);
+  nsIAccessible getAccessibleInParentChain(in nsIDOMNode aDOMNode);
 };
--- a/accessible/public/nsIAccessibleEditableText.idl
+++ b/accessible/public/nsIAccessibleEditableText.idl
@@ -36,30 +36,83 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
-[scriptable, uuid(91F0A56C-11BE-47C7-8D02-7C15E00C05F5)]
+interface nsIEditor;
+
+[scriptable, uuid(1e9884d3-4017-4032-a121-e0185d166db5)]
 interface nsIAccessibleEditableText : nsISupports
 {
-    /**
-      * Set font styles, such as italic, bold...
-      */
+  /**
+   * Sets the attributes for the text between the two given indices. The old
+   * attributes are replaced by the new list of attributes. For example,
+   * sets font styles, such as italic, bold...
+   *
+   * @param startPos - start index of the text whose attributes are modified.
+   * @param endPos - end index of the text whose attributes are modified.
+   * @param attributes - set of attributes that replaces the old list of
+   *                     attributes of the specified text portion.
+   */
   void setAttributes (in long startPos, in long endPos,
                       in nsISupports attributes);
+
+  /**
+   * Replaces the text represented by this object by the given text.
+   */
   void setTextContents (in AString text);
+
+  /**
+   * Inserts text at the specified position.
+   *
+   * @param text - text that is inserted.
+   * @param position - index at which to insert the text.
+   */
   void insertText (in AString text, in long position);
+
+  /**
+   * Copies the text range into the clipboard.
+   *
+   * @param startPos - start index of the text to moved into the clipboard.
+   * @param endPos - end index of the text to moved into the clipboard.
+   */
   void copyText (in long startPos, in long endPos);
+
+  /**
+   * Deletes a range of text and copies it to the clipboard.
+   *
+   * @param startPos - start index of the text to be deleted.
+   * @param endOffset - end index of the text to be deleted.
+   */
   void cutText (in long startPos, in long endPos);
+
+  /**
+   * Deletes a range of text.
+   *
+   * @param startPos - start index of the text to be deleted.
+   * @param endPos - end index of the text to be deleted.
+   */
   void deleteText (in long startPos, in long endPos);
+
+  /**
+   * Pastes text from the clipboard.
+   *
+   * @param position - index at which to insert the text from the system
+   *                   clipboard into the text represented by this object.
+   */
   void pasteText (in long position);
+
+  /**
+   * Returns an editor.
+   */
+  [noscript] readonly attribute nsIEditor editor;
 };
 
 /*
  Assumptions:
 
  selectAttributes method takes an nsISupports parameter.
         'set' methods throw exception on failure.
  'wstring' inputs are potentially multibyte (UTF-16 for
--- a/accessible/public/nsIAccessibleEvent.idl
+++ b/accessible/public/nsIAccessibleEvent.idl
@@ -536,8 +536,17 @@ interface nsIAccessibleTextChangeEvent :
   readonly attribute unsigned long length;
 
   /**
    * Returns true if text was inserted, otherwise false.
    */
   boolean isInserted();
 };
 
+[scriptable, uuid(b9076dce-4cd3-4e3d-a7f6-7f33a7f40c31)]
+interface nsIAccessibleCaretMoveEvent: nsIAccessibleEvent
+{
+  /**
+   * Return caret offset.
+   */
+  readonly attribute long caretOffset;
+};
+
--- a/accessible/public/nsIAccessibleTable.idl
+++ b/accessible/public/nsIAccessibleTable.idl
@@ -38,21 +38,21 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIAccessible;
 
-[scriptable, uuid(a776fee4-c0b8-4872-9e1e-72017243383f)]
+[scriptable, uuid(dc13d184-a6df-45a1-92f0-5476fdaebc5a)]
 interface nsIAccessibleTable : nsISupports
 {
-           attribute nsIAccessible       caption;
-           attribute AString           summary;
+  readonly attribute nsIAccessible       caption;
+  readonly attribute AString             summary;
   readonly attribute long                columns;
   readonly attribute nsIAccessibleTable  columnHeader;
   readonly attribute long                rows;
   readonly attribute nsIAccessibleTable  rowHeader;
 
   /**
    * Returns the accessible object at the specified row and column in the table.
    * If both row and column index are valid then the corresponding accessible
--- a/accessible/public/nsPIAccessible.idl
+++ b/accessible/public/nsPIAccessible.idl
@@ -36,17 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 interface nsIAccessible;
 interface nsIAccessibleEvent;
 
-[uuid(e4865da3-f292-4f1a-9c56-dd307f1bdc17)]
+[uuid(817ae493-b238-4fbc-a623-d20ed81eebcd)]
 interface nsPIAccessible : nsISupports
 {
   /**
    * Set accessible parent.
    */
   void setParent(in nsIAccessible aAccParent);
 
   /**
--- a/accessible/src/atk/nsAccessNodeWrap.cpp
+++ b/accessible/src/atk/nsAccessNodeWrap.cpp
@@ -67,12 +67,10 @@ nsAccessNodeWrap::~nsAccessNodeWrap()
 void nsAccessNodeWrap::InitAccessibility()
 {
   nsAccessNode::InitXPAccessibility();
 }
 
 void nsAccessNodeWrap::ShutdownAccessibility()
 {
   nsAccessNode::ShutdownXPAccessibility();
+}
 
-  // Shutdown accessibility for ATK
-  nsApplicationAccessibleWrap::Unload();
-}
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -35,17 +35,19 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAccessibleWrap.h"
-#include "nsAccessibleEventData.h"
+#include "nsRootAccessible.h"
+#include "nsDocAccessibleWrap.h"
+#include "nsIAccessibleValue.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
 #include "prprf.h"
 #include "nsRoleMap.h"
 #include "nsStateMap.h"
 
 #include "nsMaiInterfaceComponent.h"
 #include "nsMaiInterfaceAction.h"
@@ -302,26 +304,31 @@ nsAccessibleWrap::~nsAccessibleWrap()
 #ifdef MAI_LOGGING
     ++mAccWrapDeleted;
 #endif
     MAI_LOG_DEBUG(("==nsAccessibleWrap deleting: this=%p,total=%d left=%d\n",
                    (void*)this, mAccWrapDeleted,
                    (mAccWrapCreated-mAccWrapDeleted)));
 }
 
-NS_IMETHODIMP nsAccessibleWrap::Shutdown()
+void nsAccessibleWrap::ShutdownAtkObject()
 {
     if (mAtkObject) {
         if (IS_MAI_OBJECT(mAtkObject)) {
             MAI_ATK_OBJECT(mAtkObject)->accWrap = nsnull;
         }
         SetMaiHyperlink(nsnull);
         g_object_unref(mAtkObject);
         mAtkObject = nsnull;
     }
+}
+
+NS_IMETHODIMP nsAccessibleWrap::Shutdown()
+{
+    ShutdownAtkObject();
     return nsAccessible::Shutdown();
 }
 
 MaiHyperlink* nsAccessibleWrap::GetMaiHyperlink(PRBool aCreate /* = PR_TRUE */)
 {
     // make sure mAtkObject is created
     GetAtkObject();
 
@@ -364,35 +371,35 @@ NS_IMETHODIMP nsAccessibleWrap::GetNativ
         if (!IsEmbeddedObject(this)) {
             // We don't create ATK objects for nsIAccessible plain text leaves
             return NS_ERROR_FAILURE;
         }
 
         GType type = GetMaiAtkType(CreateMaiInterfaces());
         NS_ENSURE_TRUE(type, NS_ERROR_FAILURE);
         mAtkObject =
-            NS_REINTERPRET_CAST(AtkObject *,
-                                g_object_new(type, NULL));
+            reinterpret_cast<AtkObject *>
+                            (g_object_new(type, NULL));
         NS_ENSURE_TRUE(mAtkObject, NS_ERROR_OUT_OF_MEMORY);
 
         atk_object_initialize(mAtkObject, this);
         mAtkObject->role = ATK_ROLE_INVALID;
         mAtkObject->layer = ATK_LAYER_INVALID;
     }
 
     *aOutAccessible = mAtkObject;
     return NS_OK;
 }
 
 AtkObject *
 nsAccessibleWrap::GetAtkObject(void)
 {
     void *atkObj = nsnull;
     GetNativeInterface(&atkObj);
-    return NS_STATIC_CAST(AtkObject *, atkObj);
+    return static_cast<AtkObject *>(atkObj);
 }
 
 // Get AtkObject from nsIAccessible interface
 /* static */
 AtkObject *
 nsAccessibleWrap::GetAtkObject(nsIAccessible * acc)
 {
     void *atkObjPtr = nsnull;
@@ -678,17 +685,17 @@ initializeCB(AtkObject *aAtkObj, gpointe
      * maybe it has later
      */
 
     if (ATK_OBJECT_CLASS(parent_class)->initialize)
         ATK_OBJECT_CLASS(parent_class)->initialize(aAtkObj, aData);
 
     /* initialize object */
     MAI_ATK_OBJECT(aAtkObj)->accWrap =
-        NS_STATIC_CAST(nsAccessibleWrap*, aData);
+        static_cast<nsAccessibleWrap*>(aData);
 
 #ifdef MAI_LOGGING
     ++sMaiAtkObjCreated;
 #endif
     MAI_LOG_DEBUG(("MaiAtkObj Create obj=%p for AccWrap=%p, all=%d, left=%d\n",
                    (void*)aAtkObj, (void*)aData, sMaiAtkObjCreated,
                    (sMaiAtkObjCreated-sMaiAtkObjDeleted)));
 }
@@ -770,29 +777,45 @@ getRoleCB(AtkObject *aAtkObj)
     if (aAtkObj->role == ATK_ROLE_INVALID) {
         PRUint32 accRole, atkRole;
         nsresult rv = accWrap->GetFinalRole(&accRole);
         NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID);
 
         atkRole = atkRoleMap[accRole]; // map to the actual value
         NS_ASSERTION(atkRoleMap[nsIAccessibleRole::ROLE_LAST_ENTRY] ==
                      kROLE_ATK_LAST_ENTRY, "ATK role map skewed");
-        aAtkObj->role = NS_STATIC_CAST(AtkRole, atkRole);
+        aAtkObj->role = static_cast<AtkRole>(atkRole);
     }
     return aAtkObj->role;
 }
 
 AtkAttributeSet *
 GetAttributeSet(nsIAccessible* aAccessible)
 {
     AtkAttributeSet *objAttributeSet = nsnull;
     nsCOMPtr<nsIPersistentProperties> attributes;
     aAccessible->GetAttributes(getter_AddRefs(attributes));
+    
+    if (attributes) {
+        // Deal with attributes that we only need to expose in ATK
+        PRUint32 state, extraState;
+        aAccessible->GetFinalState(&state, &extraState);
+        if (state & nsIAccessibleStates::STATE_HASPOPUP) {
+          // There is no ATK state for haspopup, must use object attribute to expose the same info
+          nsAutoString oldValueUnused;
+          attributes->SetStringProperty(NS_LITERAL_CSTRING("haspopup"), NS_LITERAL_STRING("true"),
+                                        oldValueUnused);
+        }
+        if (state & nsIAccessibleStates::STATE_CHECKABLE) {
+          // There is no ATK state for haspopup, must use object attribute to expose the same info
+          nsAutoString oldValueUnused;
+          attributes->SetStringProperty(NS_LITERAL_CSTRING("checkable"), NS_LITERAL_STRING("true"),
+                                        oldValueUnused);
+        }
 
-    if (attributes) {
         nsCOMPtr<nsISimpleEnumerator> propEnum;
         nsresult rv = attributes->Enumerate(getter_AddRefs(propEnum));
         NS_ENSURE_SUCCESS(rv, nsnull);
 
         PRBool hasMore;
         while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
             nsCOMPtr<nsISupports> sup;
             rv = propEnum->GetNext(getter_AddRefs(sup));
@@ -939,17 +962,17 @@ getIndexInParentCB(AtkObject *aAtkObj)
     nsCOMPtr<nsIAccessible> sibling;
     parent->GetFirstChild(getter_AddRefs(sibling));
     if (!sibling) {
         return -1;  // Error, parent has no children
     }
 
     PRInt32 currentIndex = 0;
 
-    while (sibling != NS_STATIC_CAST(nsIAccessible*, accWrap)) {
+    while (sibling != static_cast<nsIAccessible*>(accWrap)) {
       NS_ASSERTION(sibling, "Never ran into the same child that we started from");
 
       if (!sibling) {
           return -1;
       }
       if (nsAccessible::IsEmbeddedObject(sibling)) {
         ++ currentIndex;
       }
@@ -1032,27 +1055,27 @@ refRelationSetCB(AtkObject *aAtkObj)
                                nsIAccessibleRelation::RELATION_EMBEDS,
                                nsIAccessibleRelation::RELATION_FLOWS_TO,
                                nsIAccessibleRelation::RELATION_FLOWS_FROM,
                                nsIAccessibleRelation::RELATION_DESCRIBED_BY,
                                nsIAccessibleRelation::RELATION_DESCRIPTION_FOR,
                                };
 
     for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(relationType); i++) {
-        relation = atk_relation_set_get_relation_by_type(relation_set, NS_STATIC_CAST(AtkRelationType, relationType[i]));
+        relation = atk_relation_set_get_relation_by_type(relation_set, static_cast<AtkRelationType>(relationType[i]));
         if (relation) {
             atk_relation_set_remove(relation_set, relation);
         }
 
         nsIAccessible* accRelated;
         nsresult rv = accWrap->GetAccessibleRelated(relationType[i], &accRelated);
         if (NS_SUCCEEDED(rv) && accRelated) {
             accessible_array[0] = nsAccessibleWrap::GetAtkObject(accRelated);
             relation = atk_relation_new(accessible_array, 1,
-                                        NS_STATIC_CAST(AtkRelationType, relationType[i]));
+                                        static_cast<AtkRelationType>(relationType[i]));
             atk_relation_set_add(relation_set, relation);
             g_object_unref(relation);
         }
     }
 
     return relation_set;
 }
 
@@ -1068,17 +1091,17 @@ nsAccessibleWrap *GetAccessibleWrap(AtkO
         return nsnull;
     }
 
     NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, nsnull);
 
     nsRefPtr<nsApplicationAccessibleWrap> appAccWrap =
         nsAccessNode::GetApplicationAccessible();
     nsAccessibleWrap* tmpAppAccWrap =
-        NS_STATIC_CAST(nsAccessibleWrap*, appAccWrap.get());
+        static_cast<nsAccessibleWrap*>(appAccWrap.get());
 
     if (tmpAppAccWrap != tmpAccWrap && !tmpAccWrap->IsValidObject())
         return nsnull;
 
     return tmpAccWrap;
 }
 
 NS_IMETHODIMP
@@ -1090,36 +1113,270 @@ nsAccessibleWrap::FireAccessibleEvent(ns
     nsCOMPtr<nsIAccessible> accessible;
     aEvent->GetAccessible(getter_AddRefs(accessible));
     NS_ENSURE_TRUE(accessible, NS_ERROR_FAILURE);
 
     PRUint32 type = 0;
     rv = aEvent->GetEventType(&type);
     NS_ENSURE_SUCCESS(rv, rv);
 
+    nsAccEvent *event = reinterpret_cast<nsAccEvent*>(aEvent);
+    void *eventData = event->mEventData;
+
     AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(accessible);
 
     // We don't create ATK objects for nsIAccessible plain text leaves,
     // just return NS_OK in such case
     if (!atkObj) {
         NS_ASSERTION(type == nsIAccessibleEvent::EVENT_SHOW ||
                      type == nsIAccessibleEvent::EVENT_HIDE,
                      "Event other than SHOW and HIDE fired for plain text leaves");
         return NS_OK;
     }
 
+    nsAccessibleWrap *accWrap = GetAccessibleWrap(atkObj);
+    if (!accWrap) {
+        return NS_OK; // Node is shut down
+    }
+
+    AtkTableChange * pAtkTableChange = nsnull;
+
     switch (type) {
     case nsIAccessibleEvent::EVENT_STATE_CHANGE:
         return FireAtkStateChangeEvent(aEvent, atkObj);
 
     case nsIAccessibleEvent::EVENT_TEXT_CHANGED:
         return FireAtkTextChangedEvent(aEvent, atkObj);
 
     case nsIAccessibleEvent::EVENT_PROPERTY_CHANGED:
         return FireAtkPropChangedEvent(aEvent, atkObj);
+
+    case nsIAccessibleEvent::EVENT_FOCUS:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
+        nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
+        if (rootAccWrap && rootAccWrap->mActivated) {
+            atk_focus_tracker_notify(atkObj);
+            // Fire state change event for focus
+            nsCOMPtr<nsIAccessibleStateChangeEvent> stateChangeEvent =
+              new nsAccStateChangeEvent(accessible,
+                                        nsIAccessibleStates::STATE_FOCUSED,
+                                        PR_FALSE, PR_TRUE);
+            return FireAtkStateChangeEvent(stateChangeEvent, atkObj);
+        }
+      } break;
+
+    case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_VALUE_CHANGE\n"));
+        nsCOMPtr<nsIAccessibleValue> value(do_QueryInterface(accessible));
+        if (value) {    // Make sure this is a numeric value
+            // Don't fire for MSAA string value changes (e.g. text editing)
+            // ATK values are always numeric
+            g_object_notify( (GObject*)atkObj, "accessible-value" );
+        }
+      } break;
+
+    case nsIAccessibleEvent::EVENT_SELECTION_CHANGED:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SELECTION_CHANGED\n"));
+        g_signal_emit_by_name(atkObj, "selection_changed");
+        break;
+
+    case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_SELECTION_CHANGED\n"));
+        g_signal_emit_by_name(atkObj, "text_selection_changed");
+        break;
+
+    case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CARET_MOVED\n"));
+
+        nsCOMPtr<nsIAccessibleCaretMoveEvent> caretMoveEvent(do_QueryInterface(aEvent));
+        NS_ASSERTION(caretMoveEvent, "Event needs event data");
+        if (!caretMoveEvent)
+            break;
+
+        PRInt32 caretOffset = -1;
+        caretMoveEvent->GetCaretOffset(&caretOffset);
+
+        MAI_LOG_DEBUG(("\n\nCaret postion: %d", caretOffset));
+        g_signal_emit_by_name(atkObj,
+                              "text_caret_moved",
+                              // Curent caret position
+                              caretOffset);
+      } break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_MODEL_CHANGED:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_MODEL_CHANGED\n"));
+        g_signal_emit_by_name(atkObj, "model_changed");
+        break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_ROW_INSERT:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_INSERT\n"));
+        NS_ASSERTION(eventData, "Event needs event data");
+        if (!eventData)
+            break;
+
+        pAtkTableChange = reinterpret_cast<AtkTableChange *>(eventData);
+
+        g_signal_emit_by_name(atkObj,
+                              "row_inserted",
+                              // After which the rows are inserted
+                              pAtkTableChange->index,
+                              // The number of the inserted
+                              pAtkTableChange->count);
+        break;
+
+   case nsIAccessibleEvent::EVENT_TABLE_ROW_DELETE:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_DELETE\n"));
+        NS_ASSERTION(eventData, "Event needs event data");
+        if (!eventData)
+            break;
+
+        pAtkTableChange = reinterpret_cast<AtkTableChange *>(eventData);
+
+        g_signal_emit_by_name(atkObj,
+                              "row_deleted",
+                              // After which the rows are deleted
+                              pAtkTableChange->index,
+                              // The number of the deleted
+                              pAtkTableChange->count);
+        break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_ROW_REORDER:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_REORDER\n"));
+        g_signal_emit_by_name(atkObj, "row_reordered");
+        break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_INSERT:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_INSERT\n"));
+        NS_ASSERTION(eventData, "Event needs event data");
+        if (!eventData)
+            break;
+
+        pAtkTableChange = reinterpret_cast<AtkTableChange *>(eventData);
+
+        g_signal_emit_by_name(atkObj,
+                              "column_inserted",
+                              // After which the columns are inserted
+                              pAtkTableChange->index,
+                              // The number of the inserted
+                              pAtkTableChange->count);
+        break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_DELETE:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_DELETE\n"));
+        NS_ASSERTION(eventData, "Event needs event data");
+        if (!eventData)
+            break;
+
+        pAtkTableChange = reinterpret_cast<AtkTableChange *>(eventData);
+
+        g_signal_emit_by_name(atkObj,
+                              "column_deleted",
+                              // After which the columns are deleted
+                              pAtkTableChange->index,
+                              // The number of the deleted
+                              pAtkTableChange->count);
+        break;
+
+    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_REORDER:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_REORDER\n"));
+        g_signal_emit_by_name(atkObj, "column_reordered");
+        break;
+
+    case nsIAccessibleEvent::EVENT_SECTION_CHANGED:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SECTION_CHANGED\n"));
+        g_signal_emit_by_name(atkObj, "visible_data_changed");
+        break;
+
+    case nsIAccessibleEvent::EVENT_HYPERTEXT_LINK_SELECTED:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_HYPERTEXT_LINK_SELECTED\n"));
+        atk_focus_tracker_notify(atkObj);
+        g_signal_emit_by_name(atkObj,
+                              "link_selected",
+                              // Selected link index 
+                              *(gint *)eventData);
+        break;
+
+    case nsIAccessibleEvent::EVENT_SHOW:
+        return FireAtkShowHideEvent(aEvent, atkObj, PR_TRUE);
+
+    case nsIAccessibleEvent::EVENT_HIDE:
+        return FireAtkShowHideEvent(aEvent, atkObj, PR_FALSE);
+
+        /*
+         * Because dealing with menu is very different between nsIAccessible
+         * and ATK, and the menu activity is important, specially transfer the
+         * following two event.
+         * Need more verification by AT test.
+         */
+    case nsIAccessibleEvent::EVENT_MENU_START:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENU_START\n"));
+        break;
+
+    case nsIAccessibleEvent::EVENT_MENU_END:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENU_END\n"));
+        break;
+
+    case nsIAccessibleEvent::EVENT_WINDOW_ACTIVATE:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_WINDOW_ACTIVATED\n"));
+        nsDocAccessibleWrap *accDocWrap =
+          static_cast<nsDocAccessibleWrap *>(accessible.get());
+        accDocWrap->mActivated = PR_TRUE;
+        guint id = g_signal_lookup ("activate", MAI_TYPE_ATK_OBJECT);
+        g_signal_emit(atkObj, id, 0);
+      } break;
+
+    case nsIAccessibleEvent::EVENT_WINDOW_DEACTIVATE:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_WINDOW_DEACTIVATED\n"));
+        nsDocAccessibleWrap *accDocWrap =
+          static_cast<nsDocAccessibleWrap *>(accessible.get());
+        accDocWrap->mActivated = PR_FALSE;
+        guint id = g_signal_lookup ("deactivate", MAI_TYPE_ATK_OBJECT);
+        g_signal_emit(atkObj, id, 0);
+      } break;
+
+    case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_LOAD_COMPLETE\n"));
+        g_signal_emit_by_name (atkObj, "load_complete");
+      } break;
+
+    case nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_RELOAD\n"));
+        g_signal_emit_by_name (atkObj, "reload");
+      } break;
+
+    case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_LOAD_STOPPED\n"));
+        g_signal_emit_by_name (atkObj, "load_stopped");
+      } break;
+    case nsIAccessibleEvent::EVENT_DOCUMENT_ATTRIBUTES_CHANGED:
+      {
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_ATTRIBUTES_CHANGED\n"));
+        g_signal_emit_by_name (atkObj, "attributes_changed");
+      } break;
+
+    case nsIAccessibleEvent::EVENT_MENUPOPUP_START:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENUPOPUP_START\n"));
+        atk_focus_tracker_notify(atkObj); // fire extra focus event
+        atk_object_notify_state_change(atkObj, ATK_STATE_VISIBLE, PR_TRUE);
+        atk_object_notify_state_change(atkObj, ATK_STATE_SHOWING, PR_TRUE);
+        break;
+
+    case nsIAccessibleEvent::EVENT_MENUPOPUP_END:
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENUPOPUP_END\n"));
+        atk_object_notify_state_change(atkObj, ATK_STATE_VISIBLE, PR_FALSE);
+        atk_object_notify_state_change(atkObj, ATK_STATE_SHOWING, PR_FALSE);
+        break;
     }
 
     return NS_OK;
 }
 
 nsresult
 nsAccessibleWrap::FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent,
                                           AtkObject *aObject)
@@ -1195,39 +1452,39 @@ nsAccessibleWrap::FireAtkPropChangedEven
                                           AtkObject *aObject)
 {
     MAI_LOG_DEBUG(("\n\nReceived: EVENT_PROPERTY_CHANGED\n"));
 
     AtkPropertyChange *pAtkPropChange;
     AtkPropertyValues values = { NULL };
     nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull;
 
-    nsAccEvent *event = NS_REINTERPRET_CAST(nsAccEvent*, aEvent);
+    nsAccEvent *event = reinterpret_cast<nsAccEvent*>(aEvent);
 
-    pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, event->mEventData);
+    pAtkPropChange = reinterpret_cast<AtkPropertyChange *>(event->mEventData);
     values.property_name = sAtkPropertyNameArray[pAtkPropChange->type];
 
     NS_ASSERTION(pAtkPropChange, "Event needs event data");
     if (!pAtkPropChange)
         return NS_OK;
 
     MAI_LOG_DEBUG(("\n\nthe type of EVENT_PROPERTY_CHANGED: %d\n\n",
                    pAtkPropChange->type));
 
     switch (pAtkPropChange->type) {
     case PROP_TABLE_CAPTION:
     case PROP_TABLE_SUMMARY:
 
         if (pAtkPropChange->oldvalue)
-            oldAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
-                                             pAtkPropChange->oldvalue);
+            oldAccWrap = reinterpret_cast<nsAccessibleWrap *>
+                                         (pAtkPropChange->oldvalue);
 
         if (pAtkPropChange->newvalue)
-            newAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *,
-                                             pAtkPropChange->newvalue);
+            newAccWrap = reinterpret_cast<nsAccessibleWrap *>
+                                         (pAtkPropChange->newvalue);
 
         if (oldAccWrap && newAccWrap) {
             g_value_init(&values.old_value, G_TYPE_POINTER);
             g_value_set_pointer(&values.old_value,
                                 oldAccWrap->GetAtkObject());
             g_value_init(&values.new_value, G_TYPE_POINTER);
             g_value_set_pointer(&values.new_value,
                                 newAccWrap->GetAtkObject());
@@ -1235,18 +1492,18 @@ nsAccessibleWrap::FireAtkPropChangedEven
         break;
 
     case PROP_TABLE_COLUMN_DESCRIPTION:
     case PROP_TABLE_COLUMN_HEADER:
     case PROP_TABLE_ROW_HEADER:
     case PROP_TABLE_ROW_DESCRIPTION:
         g_value_init(&values.new_value, G_TYPE_INT);
         g_value_set_int(&values.new_value,
-                        *NS_REINTERPRET_CAST(gint *,
-                                             pAtkPropChange->newvalue));
+                        *reinterpret_cast<gint *>
+                                         (pAtkPropChange->newvalue));
         break;
 
         //Perhaps need more cases in the future
     default:
         g_value_init (&values.old_value, G_TYPE_POINTER);
         g_value_set_pointer (&values.old_value, pAtkPropChange->oldvalue);
         g_value_init (&values.new_value, G_TYPE_POINTER);
         g_value_set_pointer (&values.new_value, pAtkPropChange->newvalue);
@@ -1255,8 +1512,42 @@ nsAccessibleWrap::FireAtkPropChangedEven
     char *signal_name = g_strconcat("property_change::",
                                     values.property_name, NULL);
     g_signal_emit_by_name(aObject, signal_name, &values, NULL);
     g_free (signal_name);
 
     return NS_OK;
 }
 
+nsresult
+nsAccessibleWrap::FireAtkShowHideEvent(nsIAccessibleEvent *aEvent,
+                                       AtkObject *aObject, PRBool aIsAdded)
+{
+    if (aIsAdded)
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SHOW\n"));
+    else
+        MAI_LOG_DEBUG(("\n\nReceived: EVENT_HIDE\n"));
+
+    nsCOMPtr<nsIAccessible> accessible;
+    aEvent->GetAccessible(getter_AddRefs(accessible));
+    NS_ENSURE_STATE(accessible);
+
+    nsCOMPtr<nsIAccessible> parentAccessible;
+    accessible->GetParent(getter_AddRefs(parentAccessible));
+    NS_ENSURE_STATE(parentAccessible);
+
+    PRInt32 indexInParent = -1;
+    accessible->GetIndexInParent(&indexInParent);
+
+    AtkObject *parentObject = GetAtkObject(parentAccessible);
+    NS_ENSURE_STATE(parentObject);
+
+    g_signal_emit_by_name(parentObject,
+                          aIsAdded ? \
+                          "children_changed::add" : \
+                          "children_changed::remove",
+                          indexInParent,
+                          aObject,
+                          NULL);
+
+    return NS_OK;
+}
+
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -82,16 +82,17 @@ class MaiHyperlink;
  * nsAccessibleWrap, and its descendents in atk directory provide the
  * implementation of AtkObject.
  */
 class nsAccessibleWrap: public nsAccessible
 {
 public:
     nsAccessibleWrap(nsIDOMNode*, nsIWeakReference *aShell);
     virtual ~nsAccessibleWrap();
+    void ShutdownAtkObject();
     NS_IMETHOD Shutdown();
 
 #ifdef MAI_LOGGING
     virtual void DumpnsAccessibleWrapInfo(int aDepth) {}
     static PRInt32 mAccWrapCreated;
     static PRInt32 mAccWrapDeleted;
 #endif
 
@@ -116,16 +117,18 @@ public:
 
 protected:
     nsresult FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent,
                                      AtkObject *aObject);
     nsresult FireAtkTextChangedEvent(nsIAccessibleEvent *aEvent,
                                      AtkObject *aObject);
     nsresult FireAtkPropChangedEvent(nsIAccessibleEvent *aEvent,
                                      AtkObject *aObject);
+    nsresult FireAtkShowHideEvent(nsIAccessibleEvent *aEvent,
+                                  AtkObject *aObject, PRBool aIsAdded);
 
     AtkObject *mAtkObject;
 
 private:
     PRUint16 CreateMaiInterfaces(void);
 };
 
 #endif /* __NS_ACCESSIBLE_WRAP_H__ */
--- a/accessible/src/atk/nsAppRootAccessible.cpp
+++ b/accessible/src/atk/nsAppRootAccessible.cpp
@@ -564,18 +564,18 @@ nsApplicationAccessibleWrap::Unload()
 
 NS_IMETHODIMP
 nsApplicationAccessibleWrap::GetNativeInterface(void **aOutAccessible)
 {
     *aOutAccessible = nsnull;
 
     if (!mAtkObject) {
         mAtkObject =
-            NS_REINTERPRET_CAST(AtkObject *,
-                                g_object_new(MAI_TYPE_ATK_OBJECT, NULL));
+            reinterpret_cast<AtkObject *>
+                            (g_object_new(MAI_TYPE_ATK_OBJECT, NULL));
         NS_ENSURE_TRUE(mAtkObject, NS_ERROR_OUT_OF_MEMORY);
 
         atk_object_initialize(mAtkObject, this);
         mAtkObject->role = ATK_ROLE_INVALID;
         mAtkObject->layer = ATK_LAYER_INVALID;
     }
 
     *aOutAccessible = mAtkObject;
--- a/accessible/src/atk/nsDocAccessibleWrap.cpp
+++ b/accessible/src/atk/nsDocAccessibleWrap.cpp
@@ -36,341 +36,62 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMai.h"
-#include "nsAutoPtr.h"
-#include "nsRootAccessible.h"
 #include "nsDocAccessibleWrap.h"
-#include "nsAccessibleEventData.h"
-#include "nsIAccessibleValue.h"
-
-#include <atk/atk.h>
-#include <glib.h>
-#include <glib-object.h>
-
-#include "nsStateMap.h"
 
 //----- nsDocAccessibleWrap -----
 
 nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode,
                                          nsIWeakReference *aShell): 
   nsDocAccessible(aDOMNode, aShell), mActivated(PR_FALSE)
 {
 }
 
 nsDocAccessibleWrap::~nsDocAccessibleWrap()
 {
 }
 
-NS_IMETHODIMP nsDocAccessibleWrap::FireToolkitEvent(PRUint32 aEvent,
-                                                    nsIAccessible* aAccessible,
-                                                    void* aEventData)
+void nsDocAccessibleWrap::SetEditor(nsIEditor* aEditor)
 {
-    NS_ENSURE_ARG_POINTER(aAccessible);
-
-    // First fire nsIObserver event for internal xpcom accessibility clients
-    nsDocAccessible::FireToolkitEvent(aEvent, aAccessible, aEventData);
-
-    nsresult rv = NS_ERROR_FAILURE;
+  // Recreate atkobject if editable interface is changing
+  PRBool needRecreate = mAtkObject && (mEditor != aEditor)
+                                   && (!mEditor || !aEditor);
+  nsDocAccessible::SetEditor(aEditor);
 
-    MAI_LOG_DEBUG(("\n\nReceived event: aEvent=%u, obj=0x%x, data=0x%x \n",
-                   aEvent, aAccessible, aEventData));
-
-    AtkObject *atkObj = nsAccessibleWrap::GetAtkObject(aAccessible);
+  if (needRecreate) {
+    // Get parent atkobject and index in parent
+    AtkObject* oldAtkObj = mAtkObject;
+    // getParentCB
+    AtkObject* parentAtkObj = atk_object_get_parent(oldAtkObj);
+    // getIndexInParentCB
+    PRInt32 index = atk_object_get_index_in_parent(oldAtkObj);
 
-    // We don't create ATK objects for nsIAccessible plain text leaves,
-    // just return NS_OK in such case
-    if (!atkObj) {
-      NS_ASSERTION(aEvent == nsIAccessibleEvent::EVENT_SHOW ||
-                   aEvent == nsIAccessibleEvent::EVENT_HIDE,
-                   "Event other than SHOW and HIDE fired for plain text leaves");
-      return NS_OK;
+    // Clear old atkobject
+    ShutdownAtkObject();
+
+    // Get new atkobject
+    GetAtkObject();
+
+    // Emit children_changed events
+    if (parentAtkObj && (index >= 0)) {
+      g_signal_emit_by_name(parentAtkObj, "children_changed::remove", index,
+                            oldAtkObj, NULL);
+      g_signal_emit_by_name(parentAtkObj, "children_changed::add", index,
+                            mAtkObject, NULL);
     }
 
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(atkObj);
-
-    AtkTableChange * pAtkTableChange = nsnull;
-
-    switch (aEvent) {
-    case nsIAccessibleEvent::EVENT_FOCUS:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
-        nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
-        if (rootAccWrap && rootAccWrap->mActivated) {
-          atk_focus_tracker_notify(atkObj);
-        }
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_VALUE_CHANGE :
-      {
-        nsCOMPtr<nsIAccessibleValue> value(do_QueryInterface(aAccessible));
-        if (value) {    // Make sure this is a numeric value
-          // Don't fire for MSAA string value changes (e.g. text editing)
-          // ATK values are always numeric
-          g_object_notify( (GObject*)atkObj, "accessible-value" );
-        }
+    // Set every child's parent to new created atkobject
+    nsCOMPtr<nsIAccessible> accChild;
+    while (NextChild(accChild)) {
+      if (IsEmbeddedObject(accChild)) {
+        AtkObject* childAtkObj = nsAccessibleWrap::GetAtkObject(accChild);
+        atk_object_set_parent(childAtkObj, mAtkObject);
       }
-      break;
-
-    case nsIAccessibleEvent::EVENT_SELECTION_CHANGED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SELECTION_CHANGED\n"));
-        g_signal_emit_by_name(atkObj, "selection_changed");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_SELECTION_CHANGED\n"));
-        g_signal_emit_by_name(atkObj, "text_selection_changed");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CARET_MOVED\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        MAI_LOG_DEBUG(("\n\nCaret postion: %d", *(gint *)aEventData ));
-        g_signal_emit_by_name(atkObj,
-                              "text_caret_moved",
-                              // Curent caret position
-                              *(gint *)aEventData);
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TABLE_MODEL_CHANGED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_MODEL_CHANGED\n"));
-        g_signal_emit_by_name(atkObj, "model_changed");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TABLE_ROW_INSERT:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_INSERT\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData);
-
-        g_signal_emit_by_name(atkObj,
-                              "row_inserted",
-                              // After which the rows are inserted
-                              pAtkTableChange->index,
-                              // The number of the inserted
-                              pAtkTableChange->count);
-        rv = NS_OK;
-        break;
-        
-    case nsIAccessibleEvent::EVENT_TABLE_ROW_DELETE:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_DELETE\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData);
-
-        g_signal_emit_by_name(atkObj,
-                              "row_deleted",
-                              // After which the rows are deleted
-                              pAtkTableChange->index,
-                              // The number of the deleted
-                              pAtkTableChange->count);
-        rv = NS_OK;
-        break;
-        
-    case nsIAccessibleEvent::EVENT_TABLE_ROW_REORDER:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_ROW_REORDER\n"));
-        g_signal_emit_by_name(atkObj, "row_reordered");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_INSERT:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_INSERT\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData);
-
-        g_signal_emit_by_name(atkObj,
-                              "column_inserted",
-                              // After which the columns are inserted
-                              pAtkTableChange->index,
-                              // The number of the inserted
-                              pAtkTableChange->count);
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_DELETE:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_DELETE\n"));
-        NS_ASSERTION(aEventData, "Event needs event data");
-        if (!aEventData)
-            break;
-
-        pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData);
-
-        g_signal_emit_by_name(atkObj,
-                              "column_deleted",
-                              // After which the columns are deleted
-                              pAtkTableChange->index,
-                              // The number of the deleted
-                              pAtkTableChange->count);
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_TABLE_COLUMN_REORDER:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_TABLE_COLUMN_REORDER\n"));
-        g_signal_emit_by_name(atkObj, "column_reordered");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_SECTION_CHANGED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SECTION_CHANGED\n"));
-        g_signal_emit_by_name(atkObj, "visible_data_changed");
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_HYPERTEXT_LINK_SELECTED:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_HYPERTEXT_LINK_SELECTED\n"));
-        atk_focus_tracker_notify(atkObj);
-        g_signal_emit_by_name(atkObj,
-                              "link_selected",
-                              // Selected link index 
-                              *(gint *)aEventData);
-        rv = NS_OK;
-        break;
-
-        // Is a superclass of ATK event children_changed
-    case nsIAccessibleEvent::EVENT_REORDER:
-        AtkChildrenChange *pAtkChildrenChange;
-
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_REORDER(children_change)\n"));
-
-        pAtkChildrenChange = NS_REINTERPRET_CAST(AtkChildrenChange *,
-                                                 aEventData);
-        nsAccessibleWrap *childAccWrap;
-        if (pAtkChildrenChange && pAtkChildrenChange->child) {
-            childAccWrap = NS_STATIC_CAST(nsAccessibleWrap *,
-                                          pAtkChildrenChange->child);
-            g_signal_emit_by_name (atkObj,
-                                   pAtkChildrenChange->add ? \
-                                   "children_changed::add" : \
-                                   "children_changed::remove",
-                                   pAtkChildrenChange->index,
-                                   childAccWrap->GetAtkObject(),
-                                   NULL);
-        }
-        else {
-            //
-            // EVENT_REORDER is normally fired by "HTML Document".
-            //
-            // In GOK, [only] "children_changed::add" can cause foreground
-            // window accessible to update it children, which will
-            // refresh "UI-Grab" window.
-            //
-            g_signal_emit_by_name (atkObj,
-                                   "children_changed::add",
-                                   -1, NULL, NULL);
-        }
-
-        rv = NS_OK;
-        break;
-
-        /*
-         * Because dealing with menu is very different between nsIAccessible
-         * and ATK, and the menu activity is important, specially transfer the
-         * following two event.
-         * Need more verification by AT test.
-         */
-    case nsIAccessibleEvent::EVENT_MENU_START:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENU_START\n"));
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_MENU_END:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENU_END\n"));
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_WINDOW_ACTIVATE:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_WINDOW_ACTIVATED\n"));
-        nsDocAccessibleWrap *accDocWrap =
-          NS_STATIC_CAST(nsDocAccessibleWrap *, aAccessible);
-        accDocWrap->mActivated = PR_TRUE;
-        guint id = g_signal_lookup ("activate", MAI_TYPE_ATK_OBJECT);
-        g_signal_emit(atkObj, id, 0);
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_WINDOW_DEACTIVATE:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_WINDOW_DEACTIVATED\n"));
-        nsDocAccessibleWrap *accDocWrap =
-          NS_STATIC_CAST(nsDocAccessibleWrap *, aAccessible);
-        accDocWrap->mActivated = PR_FALSE;
-        guint id = g_signal_lookup ("deactivate", MAI_TYPE_ATK_OBJECT);
-        g_signal_emit(atkObj, id, 0);
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_LOAD_COMPLETE\n"));
-        g_signal_emit_by_name (atkObj, "load_complete");
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_RELOAD\n"));
-        g_signal_emit_by_name (atkObj, "reload");
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_LOAD_STOPPED\n"));
-        g_signal_emit_by_name (atkObj, "load_stopped");
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_DOCUMENT_ATTRIBUTES_CHANGED:
-      {
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_DOCUMENT_ATTRIBUTES_CHANGED\n"));
-        g_signal_emit_by_name (atkObj, "attributes_changed");
-        rv = NS_OK;
-      } break;
-
-    case nsIAccessibleEvent::EVENT_MENUPOPUP_START:
-        // fire extra focus event, then go down to EVENT_SHOW
-        atk_focus_tracker_notify(atkObj);
-
-    case nsIAccessibleEvent::EVENT_SHOW:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_SHOW\n"));
-        atk_object_notify_state_change(atkObj, ATK_STATE_VISIBLE, PR_TRUE);
-        atk_object_notify_state_change(atkObj, ATK_STATE_SHOWING, PR_TRUE);
-        rv = NS_OK;
-        break;
-
-    case nsIAccessibleEvent::EVENT_HIDE:
-    case nsIAccessibleEvent::EVENT_MENUPOPUP_END:
-        MAI_LOG_DEBUG(("\n\nReceived: EVENT_HIDE\n"));
-        atk_object_notify_state_change(atkObj, ATK_STATE_VISIBLE, PR_FALSE);
-        atk_object_notify_state_change(atkObj, ATK_STATE_SHOWING, PR_FALSE);
-        rv = NS_OK;
-        break;
-
-    default:
-        // Don't transfer others
-        MAI_LOG_DEBUG(("\n\nReceived an unknown event=0x%u\n", aEvent));
-        break;
     }
-
-    return rv;
+  }
 }
 
--- a/accessible/src/atk/nsDocAccessibleWrap.h
+++ b/accessible/src/atk/nsDocAccessibleWrap.h
@@ -49,16 +49,16 @@
 #include "nsDocAccessible.h"
 
 class nsDocAccessibleWrap: public nsDocAccessible
 {
 public:
   nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell);
   virtual ~nsDocAccessibleWrap();
 
-  NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible,
-                              void* aData);
+  // Override SetEditor because we need to recreate atkobject
+  // when editable interface is added/removed
+  void SetEditor(nsIEditor* aEditor);
 
-protected:
   PRBool mActivated;
 };
 
 #endif
--- a/accessible/src/atk/nsMaiHyperlink.cpp
+++ b/accessible/src/atk/nsMaiHyperlink.cpp
@@ -145,18 +145,18 @@ MaiHyperlink::GetAtkHyperlink(void)
     if (mMaiAtkHyperlink)
         return mMaiAtkHyperlink;
 
     nsCOMPtr<nsIAccessibleHyperLink> accessIf(do_QueryInterface(mHyperlink));
     if (!accessIf)
         return nsnull;
 
     mMaiAtkHyperlink =
-        NS_REINTERPRET_CAST(AtkHyperlink *,
-                            g_object_new(mai_atk_hyperlink_get_type(), NULL));
+        reinterpret_cast<AtkHyperlink *>
+                        (g_object_new(mai_atk_hyperlink_get_type(), NULL));
     NS_ASSERTION(mMaiAtkHyperlink, "OUT OF MEMORY");
     NS_ENSURE_TRUE(mMaiAtkHyperlink, nsnull);
 
     /* be sure to initialize it with "this" */
     MaiHyperlink::Initialize(mMaiAtkHyperlink, this);
 
     return mMaiAtkHyperlink;
 }
@@ -255,51 +255,51 @@ gint
 getEndIndexCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 endIndex = -1;
     nsresult rv = accHyperlink->GetEndIndex(&endIndex);
 
-    return (NS_FAILED(rv)) ? -1 : NS_STATIC_CAST(gint, endIndex);
+    return (NS_FAILED(rv)) ? -1 : static_cast<gint>(endIndex);
 }
 
 gint
 getStartIndexCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 startIndex = -1;
     nsresult rv = accHyperlink->GetStartIndex(&startIndex);
 
-    return (NS_FAILED(rv)) ? -1 : NS_STATIC_CAST(gint, startIndex);
+    return (NS_FAILED(rv)) ? -1 : static_cast<gint>(startIndex);
 }
 
 gboolean
 isValidCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, FALSE);
 
     PRBool isValid = PR_FALSE;
     nsresult rv = accHyperlink->IsValid(&isValid);
-    return (NS_FAILED(rv)) ? FALSE : NS_STATIC_CAST(gboolean, isValid);
+    return (NS_FAILED(rv)) ? FALSE : static_cast<gboolean>(isValid);
 }
 
 gint
 getAnchorCountCB(AtkHyperlink *aLink)
 {
     nsIAccessibleHyperLink *accHyperlink = get_accessible_hyperlink(aLink);
     NS_ENSURE_TRUE(accHyperlink, -1);
 
     PRInt32 count = -1;
     nsresult rv = accHyperlink->GetAnchors(&count);
-    return (NS_FAILED(rv)) ? -1 : NS_STATIC_CAST(gint, count);
+    return (NS_FAILED(rv)) ? -1 : static_cast<gint>(count);
 }
 
 // Check if aHyperlink is a valid MaiHyperlink, and return the
 // nsIAccessibleHyperLink related.
 nsIAccessibleHyperLink *
 get_accessible_hyperlink(AtkHyperlink *aHyperlink)
 {
     NS_ENSURE_TRUE(MAI_IS_ATK_HYPERLINK(aHyperlink), nsnull);
--- a/accessible/src/atk/nsMaiInterfaceAction.cpp
+++ b/accessible/src/atk/nsMaiInterfaceAction.cpp
@@ -70,17 +70,17 @@ gint
 getActionCountCB(AtkAction *aAction)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
     if (!accWrap)
         return 0;
 
     PRUint8 num = 0;
     nsresult rv = accWrap->GetNumActions(&num);
-    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, num);
+    return (NS_FAILED(rv)) ? 0 : static_cast<gint>(num);
 }
 
 const gchar *
 getActionDescriptionCB(AtkAction *aAction, gint aActionIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
     if (!accWrap)
         return nsnull;
--- a/accessible/src/atk/nsMaiInterfaceTable.cpp
+++ b/accessible/src/atk/nsMaiInterfaceTable.cpp
@@ -103,17 +103,17 @@ getIndexAtCB(AtkTable *aTable, gint aRow
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 index;
     nsresult rv = accTable->GetIndexAt(aRow, aColumn, &index);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, index);
+    return static_cast<gint>(index);
 }
 
 gint
 getColumnAtIndexCB(AtkTable *aTable, gint aIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return -1;
@@ -122,17 +122,17 @@ getColumnAtIndexCB(AtkTable *aTable, gin
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 col;
     nsresult rv = accTable->GetColumnAtIndex(aIndex, &col);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, col);
+    return static_cast<gint>(col);
 }
 
 gint
 getRowAtIndexCB(AtkTable *aTable, gint aIndex)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return -1;
@@ -141,17 +141,17 @@ getRowAtIndexCB(AtkTable *aTable, gint a
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 row;
     nsresult rv = accTable->GetRowAtIndex(aIndex, &row);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, row);
+    return static_cast<gint>(row);
 }
 
 gint
 getColumnCountCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return -1;
@@ -160,17 +160,17 @@ getColumnCountCB(AtkTable *aTable)
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 count;
     nsresult rv = accTable->GetColumns(&count);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, count);
+    return static_cast<gint>(count);
 }
 
 gint
 getRowCountCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return -1;
@@ -179,17 +179,17 @@ getRowCountCB(AtkTable *aTable)
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 count;
     nsresult rv = accTable->GetRows(&count);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, count);
+    return static_cast<gint>(count);
 }
 
 gint
 getColumnExtentAtCB(AtkTable *aTable,
                     gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
@@ -199,17 +199,17 @@ getColumnExtentAtCB(AtkTable *aTable,
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 extent;
     nsresult rv = accTable->GetColumnExtentAt(aRow, aColumn, &extent);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, extent);
+    return static_cast<gint>(extent);
 }
 
 gint
 getRowExtentAtCB(AtkTable *aTable,
                  gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
@@ -219,17 +219,17 @@ getRowExtentAtCB(AtkTable *aTable,
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, -1);
 
     PRInt32 extent;
     nsresult rv = accTable->GetRowExtentAt(aRow, aColumn, &extent);
     NS_ENSURE_SUCCESS(rv, -1);
 
-    return NS_STATIC_CAST(gint, extent);
+    return static_cast<gint>(extent);
 }
 
 AtkObject*
 getCaptionCB(AtkTable *aTable)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return nsnull;
@@ -370,17 +370,17 @@ getSelectedColumnsCB(AtkTable *aTable, g
     gint *atkColumns = g_new(gint, size);
     if (!atkColumns) {
         NS_WARNING("OUT OF MEMORY");
         return nsnull;
     }
 
     //copy
     for (PRUint32 index = 0; index < size; ++index)
-        atkColumns[index] = NS_STATIC_CAST(gint, columns[index]);
+        atkColumns[index] = static_cast<gint>(columns[index]);
     nsMemory::Free(columns);
 
     *aSelected = atkColumns;
     return size;
 }
 
 gint
 getSelectedRowsCB(AtkTable *aTable, gint **aSelected)
@@ -405,17 +405,17 @@ getSelectedRowsCB(AtkTable *aTable, gint
     gint *atkRows = g_new(gint, size);
     if (!atkRows) {
         NS_WARNING("OUT OF MEMORY");
         return nsnull;
     }
 
     //copy
     for (PRUint32 index = 0; index < size; ++index)
-        atkRows[index] = NS_STATIC_CAST(gint, rows[index]);
+        atkRows[index] = static_cast<gint>(rows[index]);
     nsMemory::Free(rows);
 
     *aSelected = atkRows;
     return size;
 }
 
 gboolean
 isColumnSelectedCB(AtkTable *aTable, gint aColumn)
@@ -426,44 +426,44 @@ isColumnSelectedCB(AtkTable *aTable, gin
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsColumnSelected(aColumn, &outValue);
-    return NS_FAILED(rv) ? FALSE : NS_STATIC_CAST(gboolean, outValue);
+    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
 }
 
 gboolean
 isRowSelectedCB(AtkTable *aTable, gint aRow)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return FALSE;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsRowSelected(aRow, &outValue);
-    return NS_FAILED(rv) ? FALSE : NS_STATIC_CAST(gboolean, outValue);
+    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
 }
 
 gboolean
 isCellSelectedCB(AtkTable *aTable, gint aRow, gint aColumn)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
     if (!accWrap)
         return FALSE;
 
     nsCOMPtr<nsIAccessibleTable> accTable;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
                             getter_AddRefs(accTable));
     NS_ENSURE_TRUE(accTable, FALSE);
 
     PRBool outValue;
     nsresult rv = accTable->IsCellSelected(aRow, aColumn, &outValue);
-    return NS_FAILED(rv) ? FALSE : NS_STATIC_CAST(gboolean, outValue);
+    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
 }
--- a/accessible/src/atk/nsMaiInterfaceText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceText.cpp
@@ -74,17 +74,17 @@ textInterfaceInitCB(AtkTextIface *aIface
 }
 
 
 void ConvertTexttoAsterisks(nsAccessibleWrap* accWrap, nsAString& aString)
 {
     // convert each char to "*" when it's "password text" 
     PRUint32 accRole;
     accWrap->GetRole(&accRole);
-    if (NS_STATIC_CAST(AtkRole, accRole) == ATK_ROLE_PASSWORD_TEXT) {
+    if (static_cast<AtkRole>(accRole) == ATK_ROLE_PASSWORD_TEXT) {
         for (PRUint32 i = 0; i < aString.Length(); i++)
             aString.Replace(i, 1, NS_LITERAL_STRING("*"));
     }
 }
 
 gchar *
 getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
 {
@@ -182,21 +182,21 @@ getCharacterAtOffsetCB(AtkText *aText, g
     /* gnuichar is guint32 in glib */
     PRUnichar uniChar;
     nsresult rv =
         accText->GetCharacterAtOffset(aOffset, &uniChar);
 
     // convert char to "*" when it's "password text" 
     PRUint32 accRole;
     accWrap->GetRole(&accRole);
-    if (NS_STATIC_CAST(AtkRole, accRole) == ATK_ROLE_PASSWORD_TEXT) {
+    if (static_cast<AtkRole>(accRole) == ATK_ROLE_PASSWORD_TEXT) {
         uniChar = '*';
     }
 
-    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gunichar, uniChar);
+    return (NS_FAILED(rv)) ? 0 : static_cast<gunichar>(uniChar);
 }
 
 gchar *
 getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
                       AtkTextBoundary aBoundaryType,
                       gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
@@ -232,17 +232,17 @@ getCaretOffsetCB(AtkText *aText)
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, 0);
 
     PRInt32 offset;
     nsresult rv = accText->GetCaretOffset(&offset);
-    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, offset);
+    return (NS_FAILED(rv)) ? 0 : static_cast<gint>(offset);
 }
 
 AtkAttributeSet *
 getRunAttributesCB(AtkText *aText, gint aOffset,
                    gint *aStartOffset,
                    gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
@@ -353,17 +353,17 @@ getCharacterCountCB(AtkText *aText)
 
     nsCOMPtr<nsIAccessibleText> accText;
     accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
                             getter_AddRefs(accText));
     NS_ENSURE_TRUE(accText, 0);
 
     PRInt32 count = 0;
     nsresult rv = accText->GetCharacterCount(&count);
-    return (NS_FAILED(rv)) ? 0 : NS_STATIC_CAST(gint, count);
+    return (NS_FAILED(rv)) ? 0 : static_cast<gint>(count);
 }
 
 gint
 getOffsetAtPointCB(AtkText *aText,
                    gint aX, gint aY,
                    AtkCoordType aCoords)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
@@ -378,17 +378,17 @@ getOffsetAtPointCB(AtkText *aText,
     PRInt32 offset = 0;
     PRUint32 geckoCoordType;
     if (aCoords == ATK_XY_SCREEN)
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
     else
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
 
     accText->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
-    return NS_STATIC_CAST(gint, offset);
+    return static_cast<gint>(offset);
 }
 
 gint
 getTextSelectionCountCB(AtkText *aText)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
     if (!accWrap)
         return nsnull;
--- a/accessible/src/atk/nsRoleMap.h
+++ b/accessible/src/atk/nsRoleMap.h
@@ -69,17 +69,17 @@ static const PRUint32 atkRoleMap[] = {
     ATK_ROLE_PANEL,               // nsIAccessibleRole::ROLE_GROUPING             20
     ATK_ROLE_SEPARATOR,           // nsIAccessibleRole::ROLE_SEPARATOR            21
     ATK_ROLE_TOOL_BAR,            // nsIAccessibleRole::ROLE_TOOLBAR              22
     ATK_ROLE_STATUSBAR,           // nsIAccessibleRole::ROLE_STATUSBAR            23
     ATK_ROLE_TABLE,               // nsIAccessibleRole::ROLE_TABLE                24
     ATK_ROLE_COLUMN_HEADER,       // nsIAccessibleRole::ROLE_COLUMNHEADER         25
     ATK_ROLE_ROW_HEADER,          // nsIAccessibleRole::ROLE_ROWHEADER            26
     ATK_ROLE_UNKNOWN,             // nsIAccessibleRole::ROLE_COLUMN               27
-    ATK_ROLE_UNKNOWN,             // nsIAccessibleRole::ROLE_ROW                  28
+    ATK_ROLE_LIST_ITEM,           // nsIAccessibleRole::ROLE_ROW                  28
     ATK_ROLE_TABLE_CELL,          // nsIAccessibleRole::ROLE_CELL                 29
     ATK_ROLE_LINK,                // nsIAccessibleRole::ROLE_LINK                 30
     ATK_ROLE_UNKNOWN,             // nsIAccessibleRole::ROLE_HELPBALLOON          31
     ATK_ROLE_IMAGE,               // nsIAccessibleRole::ROLE_CHARACTER            32
     ATK_ROLE_LIST,                // nsIAccessibleRole::ROLE_LIST                 33
     ATK_ROLE_LIST_ITEM,           // nsIAccessibleRole::ROLE_LISTITEM             34
     ATK_ROLE_TREE,                // nsIAccessibleRole::ROLE_OUTLINE              35
     ATK_ROLE_LIST_ITEM,           // nsIAccessibleRole::ROLE_OUTLINEITEM          36
--- a/accessible/src/atk/nsXULTreeAccessibleWrap.cpp
+++ b/accessible/src/atk/nsXULTreeAccessibleWrap.cpp
@@ -45,17 +45,16 @@
 // --------------------------------------------------------
 // nsXULTreeAccessibleWrap Accessible
 // --------------------------------------------------------
 NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessibleWrap, nsXULTreeAccessible, nsIAccessibleTable)
 
 nsXULTreeAccessibleWrap::nsXULTreeAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
 nsXULTreeAccessible(aDOMNode, aShell)
 {
-  mCaption = nsnull;
 }
 
 // tree's children count is row count * col count + treecols count
 // override "children count = row count + treecols count" defined in
 // nsXULTreeAccessible
 NS_IMETHODIMP nsXULTreeAccessibleWrap::GetChildCount(PRInt32 *aAccChildCount)
 {
   NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
@@ -73,36 +72,23 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::G
 
     *aAccChildCount += rowCount * colCount;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeAccessibleWrap::GetCaption(nsIAccessible **aCaption)
 {
-  *aCaption = mCaption;
-  NS_IF_ADDREF(*aCaption);
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsXULTreeAccessibleWrap::SetCaption(nsIAccessible *aCaption)
-{
-  mCaption = aCaption;
+  *aCaption = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeAccessibleWrap::GetSummary(nsAString &aSummary)
 {
-  aSummary = mSummary;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsXULTreeAccessibleWrap::SetSummary(const nsAString &aSummary)
-{
-  mSummary = aSummary;
+  aSummary.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeAccessibleWrap::GetColumns(PRInt32 *aColumns)
 {
   nsresult rv = NS_OK;
 
   nsCOMPtr<nsIAccessible> acc;
@@ -421,42 +407,27 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::I
 // --------------------------------------------------------
 // nsXULTreeAccessibleWrap Accessible
 // --------------------------------------------------------
 NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeColumnsAccessibleWrap, nsXULTreeColumnsAccessible, nsIAccessibleTable)
 
 nsXULTreeColumnsAccessibleWrap::nsXULTreeColumnsAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
 nsXULTreeColumnsAccessible(aDOMNode, aShell)
 {
-  mCaption = nsnull;
 }
 
 NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::GetCaption(nsIAccessible **aCaption)
 {
-  *aCaption = mCaption;
-  NS_IF_ADDREF(*aCaption);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::SetCaption(nsIAccessible *aCaption)
-{
-  mCaption = aCaption;
+  *aCaption = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::GetSummary(nsAString &aSummary)
 {
-  aSummary = mSummary;
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::SetSummary(const nsAString &aSummary)
-{
-  mSummary = aSummary;
+  aSummary.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::GetColumns(PRInt32 *aColumns)
 {
   nsresult rv = GetChildCount(aColumns);
   return *aColumns > 0 ? rv : NS_ERROR_FAILURE;
 }
--- a/accessible/src/atk/nsXULTreeAccessibleWrap.h
+++ b/accessible/src/atk/nsXULTreeAccessibleWrap.h
@@ -52,30 +52,22 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLETABLE
 
   nsXULTreeAccessibleWrap(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
   virtual ~nsXULTreeAccessibleWrap() {}
 
   NS_IMETHOD GetChildCount(PRInt32 *_retval);
   NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
-    
-private:
-  nsCOMPtr<nsIAccessible> mCaption;
-  nsString mSummary;
 };
 
 class nsXULTreeColumnsAccessibleWrap : public nsXULTreeColumnsAccessible,
                                        public nsIAccessibleTable
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLETABLE
 
   nsXULTreeColumnsAccessibleWrap(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
   virtual ~nsXULTreeColumnsAccessibleWrap() {}
-
-private:
-  nsCOMPtr<nsIAccessible> mCaption;
-  nsString mSummary;
 };
 
 #endif
--- a/accessible/src/base/nsARIAMap.cpp
+++ b/accessible/src/base/nsARIAMap.cpp
@@ -60,125 +60,153 @@
 static const nsStateMapEntry kEndEntry = {0, 0, 0};  // To fill in array of state mappings
 
 nsRoleMapEntry nsARIAMap::gWAIRoleMap[] = 
 {
   {"alert", nsIAccessibleRole::ROLE_ALERT, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
   {"alertdialog", nsIAccessibleRole::ROLE_ALERT, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
   {"application", nsIAccessibleRole::ROLE_APPLICATION, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"button", nsIAccessibleRole::ROLE_PUSHBUTTON, eNameOkFromChildren, eNoValue, kNoReqStates,
-            {"pressed", kBoolState, nsIAccessibleStates::STATE_PRESSED},
-            {"haspopup", kBoolState, nsIAccessibleStates::STATE_HASPOPUP}, kEndEntry},
-  {"buttonsubmit", nsIAccessibleRole::ROLE_PUSHBUTTON, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_DEFAULT, kEndEntry},
-  {"buttoncancel", nsIAccessibleRole::ROLE_PUSHBUTTON, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
+            {"pressed", kBoolState, nsIAccessibleStates::STATE_PRESSED}, kEndEntry},
   {"checkbox", nsIAccessibleRole::ROLE_CHECKBUTTON, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_CHECKABLE,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"checkboxtristate", nsIAccessibleRole::ROLE_CHECKBUTTON, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_CHECKABLE,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED},
             {"checked", "mixed", nsIAccessibleStates::STATE_MIXED},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"columnheader", nsIAccessibleRole::ROLE_COLUMNHEADER, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"combobox", nsIAccessibleRole::ROLE_COMBOBOX, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY},
             {"expanded", kBoolState, nsIAccessibleStates::STATE_EXPANDED},
             {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE}, kEndEntry},
   {"description", nsIAccessibleRole::ROLE_TEXT_CONTAINER, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
   {"dialog", nsIAccessibleRole::ROLE_DIALOG, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"document", nsIAccessibleRole::ROLE_DOCUMENT, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"grid", nsIAccessibleRole::ROLE_TABLE, eNameLabelOrTitle, eNoValue, nsIAccessibleStates::STATE_FOCUSABLE,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"gridcell", nsIAccessibleRole::ROLE_CELL, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
+            {"expanded", kBoolState, nsIAccessibleStates::STATE_EXPANDED},
+            {"expanded", "false", nsIAccessibleStates::STATE_COLLAPSED},
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"group", nsIAccessibleRole::ROLE_GROUPING, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"label", nsIAccessibleRole::ROLE_LABEL, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
-  {"link", nsIAccessibleRole::ROLE_LINK, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_LINKED, kEndEntry},
+  {"link", nsIAccessibleRole::ROLE_LINK, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_LINKED,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"list", nsIAccessibleRole::ROLE_LIST, eNameLabelOrTitle, eNoValue, kNoReqStates,
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY},
             {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE}, kEndEntry},
   {"listbox", nsIAccessibleRole::ROLE_LIST, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY},
             {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE}, kEndEntry},
   {"listitem", nsIAccessibleRole::ROLE_LISTITEM, eNameOkFromChildren, eNoValue, kNoReqStates,
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED | nsIAccessibleStates::STATE_CHECKABLE},
             {"checked", "false", nsIAccessibleStates::STATE_CHECKABLE}, kEndEntry},
-  {"menu", nsIAccessibleRole::ROLE_MENUPOPUP, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
-  {"menubar", nsIAccessibleRole::ROLE_MENUBAR, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
+  {"menu", nsIAccessibleRole::ROLE_MENUPOPUP, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
+  {"menubar", nsIAccessibleRole::ROLE_MENUBAR, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"menuitem", nsIAccessibleRole::ROLE_MENUITEM, eNameOkFromChildren, eNoValue, kNoReqStates,
-            {"haspopup", kBoolState, nsIAccessibleStates::STATE_HASPOPUP},
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED | nsIAccessibleStates::STATE_CHECKABLE},
             {"checked", "mixed", nsIAccessibleStates::STATE_MIXED},
             {"checked", "false", nsIAccessibleStates::STATE_CHECKABLE}, kEndEntry},
   {"menuitemcheckbox", nsIAccessibleRole::ROLE_MENUITEM, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_CHECKABLE,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED }, kEndEntry},
   {"menuitemradio", nsIAccessibleRole::ROLE_MENUITEM, eNameOkFromChildren, eNoValue, nsIAccessibleStates::STATE_CHECKABLE,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED }, kEndEntry},
   {"option", nsIAccessibleRole::ROLE_LISTITEM, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED | nsIAccessibleStates::STATE_CHECKABLE},
             {"checked", "false", nsIAccessibleStates::STATE_CHECKABLE}, kEndEntry},
   {"progressbar", nsIAccessibleRole::ROLE_PROGRESSBAR, eNameLabelOrTitle, eHasValueMinMax, nsIAccessibleStates::STATE_READONLY,
-            {"valuenow", "unknown", nsIAccessibleStates::STATE_MIXED}, kEndEntry},
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"radio", nsIAccessibleRole::ROLE_RADIOBUTTON, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED}, kEndEntry},
-  {"radiogroup", nsIAccessibleRole::ROLE_GROUPING, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
+  {"radiogroup", nsIAccessibleRole::ROLE_GROUPING, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
+  {"row", nsIAccessibleRole::ROLE_ROW, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
+            {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
+            {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
+            {"expanded", kBoolState, nsIAccessibleStates::STATE_EXPANDED},
+            {"expanded", "false", nsIAccessibleStates::STATE_COLLAPSED}, kEndEntry},
   {"rowheader", nsIAccessibleRole::ROLE_ROWHEADER, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"secret", nsIAccessibleRole::ROLE_PASSWORD_TEXT, eNameLabelOrTitle, eNoValue, nsIAccessibleStates::STATE_PROTECTED,
-             kEndEntry},  // nsIAccessibleStates::EXT_STATE_SINGLE_LINE manually supported in code
+            // Manually map EXT_STATE_SINGLE_LINE and EXT_STATE_MULTI_LINE FROM aaa:multiline
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"separator", nsIAccessibleRole::ROLE_SEPARATOR, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"slider", nsIAccessibleRole::ROLE_SLIDER, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
   {"spinbutton", nsIAccessibleRole::ROLE_SPINBUTTON, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
-  {"spreadsheet", nsIAccessibleRole::ROLE_TABLE, eNameLabelOrTitle, eNoValue, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE | nsIAccessibleStates::STATE_FOCUSABLE,
-            {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry}, // Still supported, but deprecated in favor of grid
   {"status", nsIAccessibleRole::ROLE_STATUSBAR, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
-  {"tab", nsIAccessibleRole::ROLE_PAGETAB, eNameOkFromChildren, eNoValue, kNoReqStates, kEndEntry},
-  {"table", nsIAccessibleRole::ROLE_TABLE, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
-  {"td", nsIAccessibleRole::ROLE_CELL, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
-  {"th", nsIAccessibleRole::ROLE_CELL, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
+  {"tab", nsIAccessibleRole::ROLE_PAGETAB, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"tablist", nsIAccessibleRole::ROLE_PAGETABLIST, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {"tabpanel", nsIAccessibleRole::ROLE_PROPERTYPAGE, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
-  {"textarea", nsIAccessibleRole::ROLE_ENTRY, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
-            {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry}, // XXX nsIAccessibleStates::EXT_STATE_MULTI_LINE supported in code
-  {"textfield", nsIAccessibleRole::ROLE_ENTRY, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
-            {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, 
-            {"haspopup", kBoolState, nsIAccessibleStates::STATE_HASPOPUP}, kEndEntry}, // XXX nsIAccessibleStates::EXT_STATE_SINGLE_LINE supported in code
-  {"toolbar", nsIAccessibleRole::ROLE_TOOLBAR, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
+  {"textbox", nsIAccessibleRole::ROLE_ENTRY, eNameLabelOrTitle, eHasValueMinMax, kNoReqStates,
+            // Manually map EXT_STATE_SINGLE_LINE and EXT_STATE_MULTI_LINE FROM aaa:multiline
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
+            {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY}, kEndEntry},
+  {"toolbar", nsIAccessibleRole::ROLE_TOOLBAR, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE}, kEndEntry},
   {"tree", nsIAccessibleRole::ROLE_OUTLINE, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
+            {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY},
+            {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE}, kEndEntry},
+  {"treegrid", nsIAccessibleRole::ROLE_TREE_TABLE, eNameLabelOrTitle, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"readonly", kBoolState, nsIAccessibleStates::STATE_READONLY},
             {"multiselectable", kBoolState, nsIAccessibleStates::STATE_MULTISELECTABLE | nsIAccessibleStates::STATE_EXTSELECTABLE}, kEndEntry},
   {"treeitem", nsIAccessibleRole::ROLE_OUTLINEITEM, eNameOkFromChildren, eNoValue, kNoReqStates,
+            {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
             {"selected", kBoolState, nsIAccessibleStates::STATE_SELECTED | nsIAccessibleStates::STATE_SELECTABLE},
             {"selected", "false", nsIAccessibleStates::STATE_SELECTABLE},
             {"expanded", kBoolState, nsIAccessibleStates::STATE_EXPANDED},
             {"expanded", "false", nsIAccessibleStates::STATE_COLLAPSED},
             {"checked", kBoolState, nsIAccessibleStates::STATE_CHECKED | nsIAccessibleStates::STATE_CHECKABLE},
             {"checked", "mixed", nsIAccessibleStates::STATE_MIXED},
             {"checked", "false", nsIAccessibleStates::STATE_CHECKABLE},},
-  {"treegroup", nsIAccessibleRole::ROLE_GROUPING, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry},
   {nsnull, nsIAccessibleRole::ROLE_NOTHING, eNameLabelOrTitle, eNoValue, kNoReqStates, kEndEntry} // Last item
 };
 
 /**
  * Universal states:
  * The following state rules are applied to any accessible element,
  * whether there is an ARIA role or not:
  */
 nsStateMapEntry nsARIAMap::gWAIUnivStateMap[] = {
-  {"disabled", kBoolState, nsIAccessibleStates::STATE_UNAVAILABLE},
   {"required", kBoolState, nsIAccessibleStates::STATE_REQUIRED},
-  {"invalid", kBoolState, nsIAccessibleStates::STATE_INVALID},
+  {"invalid",  kBoolState, nsIAccessibleStates::STATE_INVALID},
+  {"haspopup", kBoolState, nsIAccessibleStates::STATE_HASPOPUP},
+  {"busy",     "true",     nsIAccessibleStates::STATE_BUSY},
+  {"busy",     "error",    nsIAccessibleStates::STATE_INVALID},
   kEndEntry
 };
 
--- a/accessible/src/base/nsARIAMap.h
+++ b/accessible/src/base/nsARIAMap.h
@@ -109,16 +109,17 @@ struct nsRoleMapEntry
   // C++'s struct initialization feature.
   nsStateMapEntry attributeMap1;
   nsStateMapEntry attributeMap2;
   nsStateMapEntry attributeMap3;
   nsStateMapEntry attributeMap4;
   nsStateMapEntry attributeMap5;
   nsStateMapEntry attributeMap6;
   nsStateMapEntry attributeMap7;
+  nsStateMapEntry attributeMap8;
 };
 
 /**
  *  These are currently initialized (hardcoded) in nsARIAMap.cpp, 
  *  and provide the mappings for WAI-ARIA roles and properties using the 
  *  structs defined in this file.
  */
 struct nsARIAMap
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -193,17 +193,17 @@ NS_IMETHODIMP nsAccessNode::Shutdown()
   mDOMNode = nsnull;
   mWeakShell = nsnull;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAccessNode::GetUniqueID(void **aUniqueID)
 {
-  *aUniqueID = NS_STATIC_CAST(void*, mDOMNode);
+  *aUniqueID = static_cast<void*>(mDOMNode);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAccessNode::GetOwnerWindow(void **aWindow)
 {
   nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
   NS_ASSERTION(docAccessible, "No root accessible pointer back, Init() not called.");
   return docAccessible->GetWindowHandle(aWindow);
@@ -288,16 +288,18 @@ void nsAccessNode::ShutdownXPAccessibili
   if (!gIsAccessibilityActive) {
     return;
   }
   NS_IF_RELEASE(gStringBundle);
   NS_IF_RELEASE(gKeyStringBundle);
   NS_IF_RELEASE(gDoCommandTimer);
   NS_IF_RELEASE(gLastFocusedNode);
   NS_IF_RELEASE(sAccService);
+
+  nsApplicationAccessibleWrap::Unload();
   NS_IF_RELEASE(gApplicationAccessible);
 
   ClearCache(gGlobalDocAccessibleCache);
 
   gIsAccessibilityActive = PR_FALSE;
   NotifyA11yInitOrShutdown();
 }
 
@@ -652,17 +654,17 @@ void nsAccessNode::GetComputedStyleDecla
 
 /***************** Hashtable of nsIAccessNode's *****************/
 
 already_AddRefed<nsIAccessibleDocument>
 nsAccessNode::GetDocAccessibleFor(nsIWeakReference *aPresShell)
 {
   nsIAccessibleDocument *docAccessible = nsnull;
   nsCOMPtr<nsIAccessNode> accessNode;
-  gGlobalDocAccessibleCache.Get(NS_STATIC_CAST(void*, aPresShell), getter_AddRefs(accessNode));
+  gGlobalDocAccessibleCache.Get(static_cast<void*>(aPresShell), getter_AddRefs(accessNode));
   if (accessNode) {
     CallQueryInterface(accessNode, &docAccessible);
   }
   return docAccessible;
 }
  
 already_AddRefed<nsIAccessibleDocument>
 nsAccessNode::GetDocAccessibleFor(nsISupports *aContainer, PRBool aCanCreate)
--- a/accessible/src/base/nsAccessibilityAtomList.h
+++ b/accessible/src/base/nsAccessibilityAtomList.h
@@ -85,17 +85,16 @@ ACCESSIBILITY_ATOM(tableOuterFrame, "Tab
   // Alphabetical list of tag names
 ACCESSIBILITY_ATOM(a, "a")
 ACCESSIBILITY_ATOM(abbr, "abbr")
 ACCESSIBILITY_ATOM(acronym, "acronym")
 ACCESSIBILITY_ATOM(area, "area")
 ACCESSIBILITY_ATOM(blockquote, "blockquote")
 ACCESSIBILITY_ATOM(br, "br")
 ACCESSIBILITY_ATOM(body, "body")
-ACCESSIBILITY_ATOM(caption, "caption")
 ACCESSIBILITY_ATOM(choices, "choices") // XForms
 ACCESSIBILITY_ATOM(description, "description")    // XUL
 ACCESSIBILITY_ATOM(dd, "dd")
 ACCESSIBILITY_ATOM(div, "div")
 ACCESSIBILITY_ATOM(dl, "dl")
 ACCESSIBILITY_ATOM(dt, "dt")
 ACCESSIBILITY_ATOM(form, "form")
 ACCESSIBILITY_ATOM(h1, "h1")
@@ -104,16 +103,17 @@ ACCESSIBILITY_ATOM(h3, "h3")
 ACCESSIBILITY_ATOM(h4, "h4")
 ACCESSIBILITY_ATOM(h5, "h5")
 ACCESSIBILITY_ATOM(h6, "h6")
 ACCESSIBILITY_ATOM(item, "item") // XForms
 ACCESSIBILITY_ATOM(itemset, "itemset") // XForms
 ACCESSIBILITY_ATOM(img, "img")
 ACCESSIBILITY_ATOM(input, "input")
 ACCESSIBILITY_ATOM(label, "label")
+ACCESSIBILITY_ATOM(legend, "legend")
 ACCESSIBILITY_ATOM(li, "li")
 ACCESSIBILITY_ATOM(link, "link")
 ACCESSIBILITY_ATOM(map, "map")
 ACCESSIBILITY_ATOM(math, "math")
 ACCESSIBILITY_ATOM(menu, "menu")    // XUL
 ACCESSIBILITY_ATOM(menupopup, "menupopup")     // XUL
 ACCESSIBILITY_ATOM(object, "object")
 ACCESSIBILITY_ATOM(ol, "ol")
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -120,17 +120,17 @@ nsAccessibilityService::nsAccessibilityS
   nsCOMPtr<nsIObserverService> observerService = 
     do_GetService("@mozilla.org/observer-service;1");
   if (!observerService)
     return;
 
   observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
   nsCOMPtr<nsIWebProgress> progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID));
   if (progress) {
-    progress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,this),
+    progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
                                   nsIWebProgress::NOTIFY_STATE_DOCUMENT |
                                   nsIWebProgress::NOTIFY_LOCATION);
   }
   nsAccessNodeWrap::InitAccessibility();
 }
 
 nsAccessibilityService::~nsAccessibilityService()
 {
@@ -150,17 +150,17 @@ nsAccessibilityService::Observe(nsISuppo
   if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
     nsCOMPtr<nsIObserverService> observerService = 
       do_GetService("@mozilla.org/observer-service;1");
     if (observerService) {
       observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
     }
     nsCOMPtr<nsIWebProgress> progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID));
     if (progress) {
-      progress->RemoveProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,this));
+      progress->RemoveProgressListener(static_cast<nsIWebProgressListener*>(this));
     }
     nsAccessNodeWrap::ShutdownAccessibility();
   }
   return NS_OK;
 }
 
 // nsIWebProgressListener
 NS_IMETHODIMP nsAccessibilityService::OnStateChange(nsIWebProgress *aWebProgress,
@@ -274,17 +274,17 @@ NS_IMETHODIMP nsAccessibilityService::On
   return NS_OK;
 }
 
 
 nsresult
 nsAccessibilityService::GetInfo(nsISupports* aFrame, nsIFrame** aRealFrame, nsIWeakReference** aShell, nsIDOMNode** aNode)
 {
   NS_ASSERTION(aFrame,"Error -- 1st argument (aFrame) is null!!");
-  *aRealFrame = NS_STATIC_CAST(nsIFrame*, aFrame);
+  *aRealFrame = static_cast<nsIFrame*>(aFrame);
   nsCOMPtr<nsIContent> content = (*aRealFrame)->GetContent();
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
   if (!content || !node)
     return NS_ERROR_FAILURE;
   *aNode = node;
   NS_IF_ADDREF(*aNode);
 
   nsCOMPtr<nsIDocument> document = content->GetDocument();
@@ -449,37 +449,39 @@ nsAccessibilityService::CreateHTMLAccess
                                                      nsIDOMNode *aNode,
                                                      const nsAString& aRole,
                                                      nsIAccessible **aAccessible)
 {
   // This method assumes we're in an HTML namespace.
   *aAccessible = nsnull;
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
   nsIAtom *tag = content->Tag();
-  if (tag == nsAccessibilityAtoms::option) {
+  if (tag == nsAccessibilityAtoms::legend) {
+    *aAccessible = new nsHTMLLegendAccessible(aNode, aWeakShell);
+  }
+  else if (tag == nsAccessibilityAtoms::option) {
     *aAccessible = new nsHTMLSelectOptionAccessible(aNode, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::optgroup) {
     *aAccessible = new nsHTMLSelectOptGroupAccessible(aNode, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::ul || tag == nsAccessibilityAtoms::ol) {
     *aAccessible = new nsHTMLListAccessible(aNode, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::a) {
-    *aAccessible = new nsHTMLLinkAccessible(aNode, aWeakShell, aFrame);
+    *aAccessible = new nsHTMLLinkAccessible(aNode, aWeakShell);
   }
   else if (tag == nsAccessibilityAtoms::li && aFrame->GetType() != nsAccessibilityAtoms::blockFrame) {
     // Normally this is created by the list item frame which knows about the bullet frame
     // However, in this case the list item must have been styled using display: foo
-    *aAccessible = new nsHTMLLIAccessible(aNode, aWeakShell, nsnull, EmptyString());
+    *aAccessible = new nsHTMLLIAccessible(aNode, aWeakShell, EmptyString());
   }
   else if (tag == nsAccessibilityAtoms::abbr ||
            tag == nsAccessibilityAtoms::acronym ||
            tag == nsAccessibilityAtoms::blockquote ||
-           tag == nsAccessibilityAtoms::caption ||
            tag == nsAccessibilityAtoms::dd ||
            tag == nsAccessibilityAtoms::dl ||
            tag == nsAccessibilityAtoms::dt ||
            tag == nsAccessibilityAtoms::form ||
            tag == nsAccessibilityAtoms::h1 ||
            tag == nsAccessibilityAtoms::h2 ||
            tag == nsAccessibilityAtoms::h3 ||
            tag == nsAccessibilityAtoms::h4 ||
@@ -504,20 +506,18 @@ nsAccessibilityService::CreateHTMLLIAcce
                                                nsIAccessible **_retval)
 {
   nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
   nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
-  nsIFrame *bulletFrame = NS_STATIC_CAST(nsIFrame*, aBulletFrame);
-  NS_ASSERTION(bulletFrame, "bullet frame argument not a frame");
 
-  *_retval = new nsHTMLLIAccessible(node, weakShell, bulletFrame, aBulletText);
+  *_retval = new nsHTMLLIAccessible(node, weakShell, aBulletText);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -528,17 +528,17 @@ nsAccessibilityService::CreateHyperTextA
   nsCOMPtr<nsIWeakReference> weakShell;
   nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
   
-  if (nsAccessibilityUtils::HasListener(content, NS_LITERAL_STRING("click"))) {
+  if (nsAccUtils::HasListener(content, NS_LITERAL_STRING("click"))) {
     // nsLinkableAccessible inherits from nsHyperTextAccessible, but
     // it also includes code for dealing with the onclick
     *aAccessible = new nsLinkableAccessible(node, weakShell);
   }
   else {
     *aAccessible = new nsHyperTextAccessibleWrap(node, weakShell);
   }
   if (nsnull == *aAccessible)
@@ -646,17 +646,17 @@ nsAccessibilityService::CreateHTMLListbo
   */
 NS_IMETHODIMP
 nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame *aFrame,
                                                         nsIAccessible **aAccessible)
 {
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
   nsIFrame *frame;
-  GetInfo(NS_STATIC_CAST(nsIFrame*, aFrame), &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  GetInfo(static_cast<nsIFrame*>(aFrame), &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
 
   *aAccessible = nsnull;
   if (!frame || frame->GetRect().IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
   // 1) for object elements containing either HTML or TXT documents
   nsCOMPtr<nsIDOMDocument> domDoc;
   nsCOMPtr<nsIDOMHTMLObjectElement> obj(do_QueryInterface(node));
@@ -758,17 +758,17 @@ nsAccessibilityService::CreateHTMLTableH
   rv = GetShellFromNode(aDOMNode, getter_AddRefs(weakShell));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsHTMLTableHeadAccessibleWrap* accTableHead =
     new nsHTMLTableHeadAccessibleWrap(aDOMNode, weakShell);
 
   NS_ENSURE_TRUE(accTableHead, NS_ERROR_OUT_OF_MEMORY);
 
-  *_retval = NS_STATIC_CAST(nsIAccessible *, accTableHead);
+  *_retval = static_cast<nsIAccessible *>(accTableHead);
   NS_IF_ADDREF(*_retval);
 
   return rv;
 #endif
 }
 
 NS_IMETHODIMP
 nsAccessibilityService::CreateHTMLTableCellAccessible(nsISupports *aFrame, nsIAccessible **_retval)
@@ -796,17 +796,17 @@ nsAccessibilityService::CreateHTMLTextAc
   nsIFrame* frame;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIWeakReference> weakShell;
   nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
   if (NS_FAILED(rv))
     return rv;
 
   // XXX Don't create ATK objects for these
-  *_retval = new nsHTMLTextAccessible(node, weakShell, frame);
+  *_retval = new nsHTMLTextAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -876,16 +876,34 @@ nsAccessibilityService::CreateHTMLBRAcce
   *_retval = new nsHTMLBRAccessible(node, weakShell);
   if (! *_retval) 
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*_retval);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsAccessibilityService::CreateHTMLCaptionAccessible(nsISupports *aFrame, nsIAccessible **_retval)
+{
+  nsIFrame* frame;
+  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsIWeakReference> weakShell;
+  nsresult rv = GetInfo(aFrame, &frame, getter_AddRefs(weakShell), getter_AddRefs(node));
+  if (NS_FAILED(rv))
+    return rv;
+
+  *_retval = new nsHTMLCaptionAccessible(node, weakShell);
+  if (! *_retval) 
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  NS_ADDREF(*_retval);
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsAccessibilityService::GetCachedAccessible(nsIDOMNode *aNode, 
                                                           nsIWeakReference *aWeakShell,
                                                           nsIAccessible **aAccessible)
 {
   nsCOMPtr<nsIAccessNode> accessNode;
   nsresult rv = GetCachedAccessNode(aNode, aWeakShell, getter_AddRefs(accessNode));
   nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
   NS_IF_ADDREF(*aAccessible = accessible);
@@ -899,17 +917,17 @@ NS_IMETHODIMP nsAccessibilityService::Ge
   nsCOMPtr<nsIAccessibleDocument> accessibleDoc =
     nsAccessNode::GetDocAccessibleFor(aWeakShell);
 
   if (!accessibleDoc) {
     *aAccessNode = nsnull;
     return NS_ERROR_FAILURE;
   }
 
-  return accessibleDoc->GetCachedAccessNode(NS_STATIC_CAST(void*, aNode), aAccessNode);
+  return accessibleDoc->GetCachedAccessNode(static_cast<void*>(aNode), aAccessNode);
 }
 
 NS_IMETHODIMP
 nsAccessibilityService::GetStringRole(PRUint32 aRole, nsAString& aString)
 {
   if ( aRole >= NS_ARRAY_LENGTH(kRoleNames)) {
     aString.AssignLiteral("unknown");
     return NS_OK;
@@ -1363,31 +1381,35 @@ NS_IMETHODIMP nsAccessibilityService::Ge
 
             break;
           }
         }
       }
     }
 
     if (tryFrame) {
+      if (frame->GetRect().IsEmpty()) {
+        *aIsHidden = PR_TRUE;
+        return NS_OK;
+      }
       frame->GetAccessible(getter_AddRefs(newAcc)); // Try using frame to do it
     }
   }
 
   if (!newAcc) {
     GetAccessibleForDeckChildren(aNode, getter_AddRefs(newAcc));
   }
 
   // If no accessible, see if we need to create a generic accessible because
   // of some property that makes this object interesting
   // We don't do this for <body>, <html>, <window>, <dialog> etc. which 
   // correspond to the doc accessible and will be created in any case
   if (!newAcc && content->Tag() != nsAccessibilityAtoms::body && content->GetParent() && 
       (content->IsFocusable() ||
-      (isHTML && nsAccessibilityUtils::HasListener(content, NS_LITERAL_STRING("click"))) ||
+      (isHTML && nsAccUtils::HasListener(content, NS_LITERAL_STRING("click"))) ||
        content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::describedby) ||
        content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::labelledby) ||
        content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::required) ||
        content->HasAttr(kNameSpaceID_WAIProperties, nsAccessibilityAtoms::invalid) ||
        !role.IsEmpty())) {
     // This content is focusable or has an interesting dynamic content accessibility property.
     // If it's interesting we need it in the accessibility hierarchy so that events or
     // other accessibles can point to it, or so that it can hold a state, etc.
@@ -1697,17 +1719,17 @@ nsresult nsAccessibilityService::GetAcce
 }
 
 NS_IMETHODIMP nsAccessibilityService::AddNativeRootAccessible(void * aAtkAccessible,  nsIAccessible **aRootAccessible)
 {
 #ifdef MOZ_ACCESSIBILITY_ATK
   nsNativeRootAccessibleWrap* rootAccWrap =
     new nsNativeRootAccessibleWrap((AtkObject*)aAtkAccessible);
 
-  *aRootAccessible = NS_STATIC_CAST(nsIAccessible*, rootAccWrap);
+  *aRootAccessible = static_cast<nsIAccessible*>(rootAccWrap);
   NS_ADDREF(*aRootAccessible);
 
   nsRefPtr<nsApplicationAccessibleWrap> appRoot =
     nsAccessNode::GetApplicationAccessible();
   NS_ENSURE_STATE(appRoot);
 
   appRoot->AddRootAccessible(*aRootAccessible);
 
--- a/accessible/src/base/nsAccessibilityUtils.cpp
+++ b/accessible/src/base/nsAccessibilityUtils.cpp
@@ -32,47 +32,48 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAccessibilityUtils.h"
+
+#include "nsPIAccessible.h"
+#include "nsAccessibleEventData.h"
+
 #include "nsIDOMXULSelectCntrlEl.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIEventListenerManager.h"
 
 void
-nsAccessibilityUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
-                                 nsIAtom *aAttrName,
-                                 nsAString& aAttrValue)
+nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes, nsIAtom *aAttrName,
+                       nsAString& aAttrValue)
 {
   nsCAutoString attrName;
   aAttrName->ToUTF8String(attrName);
   aAttributes->GetStringProperty(attrName, aAttrValue);
 }
 
 void
-nsAccessibilityUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
-                                 nsIAtom *aAttrName,
-                                 const nsAString& aAttrValue)
+nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes, nsIAtom *aAttrName,
+                       const nsAString& aAttrValue)
 {
   nsAutoString oldValue;
   nsCAutoString attrName;
 
   aAttrName->ToUTF8String(attrName);
   aAttributes->SetStringProperty(attrName, aAttrValue, oldValue);
 }
 
 void
-nsAccessibilityUtils::GetAccGroupAttrs(nsIPersistentProperties *aAttributes,
-                                       PRInt32 *aLevel,
-                                       PRInt32 *aPosInSet,
-                                       PRInt32 *aSetSize)
+nsAccUtils::GetAccGroupAttrs(nsIPersistentProperties *aAttributes,
+                             PRInt32 *aLevel, PRInt32 *aPosInSet,
+                             PRInt32 *aSetSize)
 {
   *aLevel = 0;
   *aPosInSet = 0;
   *aSetSize = 0;
 
   nsAutoString value;
   PRInt32 error = NS_OK;
 
@@ -94,34 +95,33 @@ nsAccessibilityUtils::GetAccGroupAttrs(n
   if (!value.IsEmpty()) {
     PRInt32 sizeSet = value.ToInteger(&error);
     if (NS_SUCCEEDED(error))
       *aSetSize = sizeSet;
   }
 }
 
 PRBool
-nsAccessibilityUtils::HasAccGroupAttrs(nsIPersistentProperties *aAttributes)
+nsAccUtils::HasAccGroupAttrs(nsIPersistentProperties *aAttributes)
 {
   nsAutoString value;
 
   GetAccAttr(aAttributes, nsAccessibilityAtoms::setsize, value);
   if (!value.IsEmpty()) {
     GetAccAttr(aAttributes, nsAccessibilityAtoms::posinset, value);
     return !value.IsEmpty();
   }
 
   return PR_FALSE;
 }
 
 void
-nsAccessibilityUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
-                                       PRInt32 aLevel,
-                                       PRInt32 aPosInSet,
-                                       PRInt32 aSetSize)
+nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
+                             PRInt32 aLevel, PRInt32 aPosInSet,
+                             PRInt32 aSetSize)
 {
   nsAutoString value;
 
   if (aLevel) {
     value.AppendInt(aLevel);
     SetAccAttr(aAttributes, nsAccessibilityAtoms::level, value);
   }
 
@@ -132,18 +132,18 @@ nsAccessibilityUtils::SetAccGroupAttrs(n
 
     value.Truncate();
     value.AppendInt(aSetSize);
     SetAccAttr(aAttributes, nsAccessibilityAtoms::setsize, value);
   }
 }
 
 void
-nsAccessibilityUtils::SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
-                                                         nsIPersistentProperties *aAttributes)
+nsAccUtils::SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
+                                               nsIPersistentProperties *aAttributes)
 {
   nsCOMPtr<nsIDOMXULSelectControlItemElement> item(do_QueryInterface(aNode));
   if (!item)
     return;
 
   nsCOMPtr<nsIDOMXULSelectControlElement> control;
   item->GetControl(getter_AddRefs(control));
   if (!control)
@@ -152,17 +152,33 @@ nsAccessibilityUtils::SetAccAttrsForXULS
   PRUint32 itemsCount;
   control->GetItemCount(&itemsCount);
   PRInt32 indexOf;
   control->GetIndexOfItem(item, &indexOf);
 
   SetAccGroupAttrs(aAttributes, 0, indexOf + 1, itemsCount);
 }
 
-PRBool nsAccessibilityUtils::HasListener(nsIContent *aContent, const nsAString& aEventType)
+PRBool
+nsAccUtils::HasListener(nsIContent *aContent, const nsAString& aEventType)
 {
   NS_ENSURE_ARG_POINTER(aContent);
   nsCOMPtr<nsIEventListenerManager> listenerManager;
   aContent->GetListenerManager(PR_FALSE, getter_AddRefs(listenerManager));
 
   return listenerManager && listenerManager->HasListenersFor(aEventType);  
 }
 
+nsresult
+nsAccUtils::FireAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible)
+{
+  NS_ENSURE_ARG(aAccessible);
+
+  nsCOMPtr<nsPIAccessible> pAccessible(do_QueryInterface(aAccessible));
+  NS_ASSERTION(pAccessible, "Accessible doesn't implement nsPIAccessible");
+
+  nsCOMPtr<nsIAccessibleEvent> event =
+    new nsAccEvent(aEventType, aAccessible, nsnull);
+  NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
+
+  return pAccessible->FireAccessibleEvent(event);
+}
+
--- a/accessible/src/base/nsAccessibilityUtils.h
+++ b/accessible/src/base/nsAccessibilityUtils.h
@@ -35,22 +35,23 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsAccessibilityUtils_h_
 #define nsAccessibilityUtils_h_
 
 #include "nsAccessibilityAtoms.h"
+#include "nsIAccessible.h"
 
 #include "nsIDOMNode.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIContent.h"
 
-class nsAccessibilityUtils
+class nsAccUtils
 {
 public:
   /**
    * Returns value of attribute from the given attributes container.
    *
    * @param aAttributes - attributes container
    * @param aAttrName - the name of requested attribute
    * @param aAttrValue - value of attribute
@@ -96,12 +97,21 @@ public:
    *
    * @param aNode - XUL element that implements
    *                nsIDOMXULSelectControlItemElement interface
    * @param aAttributes - attributes container
    */
   static void SetAccAttrsForXULSelectControlItem(nsIDOMNode *aNode,
                                                  nsIPersistentProperties *aAttributes);
 
+  /**
+   * Return true if the given node has registered event listener of the given
+   * type.
+   */
   static PRBool HasListener(nsIContent *aContent, const nsAString& aEventType);
+
+  /**
+   * Fire accessible event of the given type for the given accessible.
+   */
+  static nsresult FireAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible);
 };
 
 #endif
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -187,23 +187,23 @@ PRBool nsAccessible::IsTextInterfaceSupp
 
 nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
   // Custom-built QueryInterface() knows when we support nsIAccessibleSelectable
   // based on role attribute and waistate:multiselectable
   *aInstancePtr = nsnull;
   
   if (aIID.Equals(NS_GET_IID(nsIAccessible))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIAccessible*, this);
+    *aInstancePtr = static_cast<nsIAccessible*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
   if(aIID.Equals(NS_GET_IID(nsPIAccessible))) {
-    *aInstancePtr = NS_STATIC_CAST(nsPIAccessible*, this);
+    *aInstancePtr = static_cast<nsPIAccessible*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
     nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
     if (!content) {
       return NS_ERROR_FAILURE; // This accessible has been shut down
@@ -215,34 +215,34 @@ nsresult nsAccessible::QueryInterface(RE
       // If either attribute (role or multiselectable) change, then we'll
       // destroy this accessible so that we can follow COM identity rules.
       static nsIContent::AttrValuesArray strings[] =
         {&nsAccessibilityAtoms::_empty, &nsAccessibilityAtoms::_false, nsnull};
       if (content->FindAttrValueIn(kNameSpaceID_WAIProperties ,
                                    nsAccessibilityAtoms::multiselectable,
                                    strings, eCaseMatters) ==
           nsIContent::ATTR_VALUE_NO_MATCH) {
-        *aInstancePtr = NS_STATIC_CAST(nsIAccessibleSelectable*, this);
+        *aInstancePtr = static_cast<nsIAccessibleSelectable*>(this);
         NS_ADDREF_THIS();
       }
     }
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleValue))) {
     if (mRoleMapEntry && mRoleMapEntry->valueRule != eNoValue) {
-      *aInstancePtr = NS_STATIC_CAST(nsIAccessibleValue*, this);
+      *aInstancePtr = static_cast<nsIAccessibleValue*>(this);
       NS_ADDREF_THIS();
     }
   }                       
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperLink))) {
     nsCOMPtr<nsIAccessible> parent(GetParent());
     nsCOMPtr<nsIAccessibleHyperText> hyperTextParent(do_QueryInterface(parent));
     if (hyperTextParent) {
-      *aInstancePtr = NS_STATIC_CAST(nsIAccessibleHyperLink*, this);
+      *aInstancePtr = static_cast<nsIAccessibleHyperLink*>(this);
       NS_ADDREF_THIS();
       return NS_OK;
     }
     return NS_ERROR_NO_INTERFACE;
   }
 
   return nsAccessNode::QueryInterface(aIID, aInstancePtr);
 }
@@ -250,17 +250,17 @@ nsresult nsAccessible::QueryInterface(RE
 nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsAccessNodeWrap(aNode, aShell), 
   mParent(nsnull), mFirstChild(nsnull), mNextSibling(nsnull), mRoleMapEntry(nsnull),
   mAccChildCount(eChildCountUninitialized)
 {
 #ifdef NS_DEBUG_X
    {
      nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aShell));
      printf(">>> %p Created Acc - DOM: %p  PS: %p", 
-            (void*)NS_STATIC_CAST(nsIAccessible*, this), (void*)aNode,
+            (void*)static_cast<nsIAccessible*>(this), (void*)aNode,
             (void*)shell.get());
     nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
     if (content) {
       nsAutoString buf;
       if (content->NodeInfo())
         content->NodeInfo()->GetQualifiedName(buf);
       printf(" Con: %s@%p", NS_ConvertUTF16toUTF8(buf).get(), (void *)content.get());
       if (NS_SUCCEEDED(GetName(buf))) {
@@ -592,17 +592,17 @@ NS_IMETHODIMP nsAccessible::GetParent(ns
   nsresult rv = GetCachedParent(aParent);
   if (NS_FAILED(rv) || *aParent) {
     return rv;
   }
 
   nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
   NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
 
-  return docAccessible->GetAccessibleInParentChain(mDOMNode, PR_TRUE, aParent);
+  return docAccessible->GetAccessibleInParentChain(mDOMNode, aParent);
 }
 
 NS_IMETHODIMP nsAccessible::GetCachedParent(nsIAccessible **  aParent)
 {
   *aParent = nsnull;
   if (!mWeakShell) {
     // This node has been shut down
     return NS_ERROR_FAILURE;
@@ -1072,19 +1072,18 @@ nsAccessible::GetState(PRUint32 *aState,
         *aExtraState |= nsIAccessibleStates::EXT_STATE_HORIZONTAL;
       }
     }
   }
 
   // XXX We can remove this hack once we support RDF-based role & state maps
   if (mRoleMapEntry && (mRoleMapEntry->role == nsIAccessibleRole::ROLE_ENTRY ||
       mRoleMapEntry->role == nsIAccessibleRole::ROLE_PASSWORD_TEXT)) {
-    PRBool isEqual =
-      NS_LITERAL_CSTRING("textarea").Equals(mRoleMapEntry->roleString);
-    if (isEqual) {
+    if (content->AttrValueIs(kNameSpaceID_WAIProperties , nsAccessibilityAtoms::multiline,
+                             nsAccessibilityAtoms::_true, eCaseMatters)) {
       *aExtraState |= nsIAccessibleStates::EXT_STATE_MULTI_LINE;
     }
     else {
       *aExtraState |= nsIAccessibleStates::EXT_STATE_SINGLE_LINE;
     }
   }
 
   if (!(state & nsIAccessibleStates::STATE_UNAVAILABLE)) {  // If not disabled
@@ -1503,17 +1502,17 @@ nsresult nsAccessible::AppendFlatStringF
     nsCOMPtr<nsIContent> appendedSubtreeStart(do_QueryInterface(mDOMNode));
     if (parentContent && parentContent != appendedSubtreeStart) {
       nsIFrame *frame = shell->GetPrimaryFrameFor(parentContent);
       if (frame) {
         // If this text is inside a block level frame (as opposed to span level), we need to add spaces around that 
         // block's text, so we don't get words jammed together in final name
         // Extra spaces will be trimmed out later
         const nsStyleDisplay* display = frame->GetStyleDisplay();
-        if (display->IsBlockLevel() ||
+        if (display->IsBlockOutside() ||
           display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
           isHTMLBlock = PR_TRUE;
           if (!aFlatString->IsEmpty()) {
             aFlatString->Append(PRUnichar(' '));
           }
         }
       }
     }
@@ -1725,17 +1724,18 @@ nsresult nsAccessible::GetTextFromRelati
     }
   }
   
   return rv;
 }
 
 nsIContent*
 nsAccessible::FindNeighbourPointingToNode(nsIContent *aForNode,
-                                          nsIAtom *aTagName, nsIAtom *aAttr,
+                                          nsIAtom *aTagName, nsIAtom *aRelationAttr,
+                                          PRUint32 aRelationNameSpaceID,
                                           PRUint32 aAncestorLevelsToSearch)
 {
   nsCOMPtr<nsIContent> binding;
 
   nsAutoString controlID;
   aForNode->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::id, controlID);
   if (controlID.IsEmpty()) {
     binding = aForNode->GetBindingParent();
@@ -1780,47 +1780,47 @@ nsAccessible::FindNeighbourPointingToNod
         if (NS_FAILED(rv))
           return nsnull;
 
         nsCOMPtr<nsIContent> content = do_QueryInterface(node);
         if (!content)
           return nsnull;
 
         if (content != prevSearched) {
-          labelContent = FindDescendantPointingToID(&controlID, content,  aAttr,
-                                                    nsnull, kNameSpaceID_None,
+          labelContent = FindDescendantPointingToID(&controlID, content,  aRelationAttr,
+                                                    aRelationNameSpaceID, nsnull,
                                                     aTagName);
         }
       }
       break;
     }
 
     labelContent = FindDescendantPointingToID(&controlID, aForNode,
-                                              aAttr, prevSearched,
-                                              kNameSpaceID_None, aTagName);
+                                              aRelationAttr, aRelationNameSpaceID,
+                                              prevSearched, aTagName);
     prevSearched = aForNode;
   }
 
   return labelContent;
 }
 
-// Pass in aForAttrib == nsnull if any <label> will do
+// Pass in aRelationAttr == nsnull if any <label> will do
 nsIContent*
 nsAccessible::FindDescendantPointingToID(const nsAString *aId,
                                          nsIContent *aLookContent,
-                                         nsIAtom *aForAttrib,
+                                         nsIAtom *aRelationAttr,
+                                         PRUint32 aRelationNameSpaceID,
                                          nsIContent *aExcludeContent,
-                                         PRUint32 aForAttribNameSpace,
                                          nsIAtom *aTagType)
 {
   if (!aTagType || aLookContent->Tag() == aTagType) {
-    if (aForAttrib) {
-      // Check for ID in the attribute aForAttrib, which can be a list
+    if (aRelationAttr) {
+      // Check for ID in the attribute aRelationAttr, which can be a list
       nsAutoString idList;
-      if (aLookContent->GetAttr(aForAttribNameSpace, aForAttrib, idList)) {
+      if (aLookContent->GetAttr(aRelationNameSpaceID, aRelationAttr, idList)) {
         idList.Insert(' ', 0);  // Surround idlist with spaces for search
         idList.Append(' ');
         nsAutoString id(*aId);
         id.Insert(' ', 0); // Surround id with spaces for search
         id.Append(' ');
         // idList is now a set of id's with spaces around each,
         // and id also has spaces around it.
         // If id is a substring of idList then we have a match
@@ -1836,22 +1836,22 @@ nsAccessible::FindDescendantPointingToID
 
   // Recursively search descendants for labels
   PRUint32 count  = 0;
   nsIContent *child;
   nsIContent *labelContent = nsnull;
 
   while ((child = aLookContent->GetChildAt(count++)) != nsnull) {
     if (child != aExcludeContent) {
-      labelContent = FindDescendantPointingToID(aId, child, aForAttrib,
-                                                aExcludeContent,
-                                                aForAttribNameSpace, aTagType);
-    }
-    if (labelContent) {
-      return labelContent;
+      labelContent = FindDescendantPointingToID(aId, child, aRelationAttr,
+                                                aRelationNameSpaceID, aExcludeContent,
+                                                aTagType);
+      if (labelContent) {
+        return labelContent;
+      }
     }
   }
   return nsnull;
 }
 
 /**
   * Only called if the element is not a nsIDOMXULControlElement. Initially walks up
   *   the DOM tree to the form, concatonating label elements as it goes. Then checks for
@@ -2001,30 +2001,29 @@ PRBool nsAccessible::IsNodeRelevant(nsID
   nsCOMPtr<nsIAccessibilityService> accService =
     do_GetService("@mozilla.org/accessibilityService;1");
   NS_ENSURE_TRUE(accService, PR_FALSE);
   nsCOMPtr<nsIDOMNode> relevantNode;
   accService->GetRelevantContentNodeFor(aNode, getter_AddRefs(relevantNode));
   return aNode == relevantNode;
 }
 
-NS_IMETHODIMP nsAccessible::FireToolkitEvent(PRUint32 aEvent, nsIAccessible *aTarget, void * aData)
+NS_IMETHODIMP
+nsAccessible::FireToolkitEvent(PRUint32 aEvent, nsIAccessible *aTarget,
+                               void * aData)
 {
-  // Don't fire event for accessible that has been shut down
+  // Don't fire event for accessible that has been shut down.
   if (!mWeakShell)
     return NS_ERROR_FAILURE;
 
-  NS_ENSURE_TRUE(IsNodeRelevant(mDOMNode), NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
-  nsCOMPtr<nsPIAccessible> eventHandlingAccessible(do_QueryInterface(docAccessible));
-  if (eventHandlingAccessible)
-    return eventHandlingAccessible->FireToolkitEvent(aEvent, aTarget, aData);
-
-  return NS_ERROR_FAILURE;
+  nsCOMPtr<nsIAccessibleEvent> accEvent =
+    new nsAccEvent(aEvent, aTarget, aData);
+  NS_ENSURE_TRUE(accEvent, NS_ERROR_OUT_OF_MEMORY);
+
+  return FireAccessibleEvent(accEvent);
 }
 
 NS_IMETHODIMP
 nsAccessible::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
 {
   NS_ENSURE_ARG_POINTER(aEvent);
   nsCOMPtr<nsIDOMNode> eventNode;
   aEvent->GetDOMNode(getter_AddRefs(eventNode));
@@ -2072,29 +2071,30 @@ nsAccessible::GetAttributes(nsIPersisten
     }
     // XXX In the future we may need to expose the dynamic content role inheritance chain
     // through this attribute
     nsAutoString xmlRole;
     if (GetRoleAttribute(content, xmlRole)) {
       attributes->SetStringProperty(NS_LITERAL_CSTRING("xml-roles"), xmlRole, oldValueUnused);          
     }
 
-    char *ariaProperties[] = { "live", "atomic", "relevant", "datatype", "level", "posinset", "setsize", "sort" };
+    char *ariaProperties[] = { "live", "channel", "atomic", "relevant", "datatype", "level",
+                               "posinset", "setsize", "sort", "grab", "dropeffect"};
 
     for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(ariaProperties); index ++) {
       nsAutoString value;
       nsCOMPtr<nsIAtom> attr = do_GetAtom(ariaProperties[index]);
       if (content->GetAttr(kNameSpaceID_WAIProperties, attr, value)) {
         ToLowerCase(value);
         attributes->SetStringProperty(nsDependentCString(ariaProperties[index]), value, oldValueUnused);    
       }
     }
   }
 
-  if (!nsAccessibilityUtils::HasAccGroupAttrs(attributes)) {
+  if (!nsAccUtils::HasAccGroupAttrs(attributes)) {
     // The role of an accessible can be pointed by ARIA attribute but ARIA
     // posinset, level, setsize may be skipped. Therefore we calculate here
     // these properties to map them into description.
 
     // If accessible is invisible we don't want to calculate group ARIA
     // attributes for it.
     PRUint32 state = State(this);
     if (state & nsIAccessibleStates::STATE_INVISIBLE)
@@ -2146,19 +2146,18 @@ nsAccessible::GetAttributes(nsIPersisten
           if (role == nsIAccessibleRole::ROLE_OUTLINEITEM)
             ++ groupLevel;
 
           parent->GetParent(getter_AddRefs(nextParent));
           parent.swap(nextParent);
         }
       }
 
-      nsAccessibilityUtils::SetAccGroupAttrs(attributes, groupLevel,
-                                             positionInGroup,
-                                             setSize);
+      nsAccUtils::SetAccGroupAttrs(attributes, groupLevel, positionInGroup,
+                                   setSize);
     }
   }
 
   attributes.swap(*aAttributes);
 
   return NS_OK;
 }
 
@@ -2201,18 +2200,17 @@ nsAccessible::GroupPosition(PRInt32 *aGr
 
   nsCOMPtr<nsIPersistentProperties> attributes;
   nsresult rv = GetAttributes(getter_AddRefs(attributes));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!attributes) {
     return NS_ERROR_FAILURE;
   }
   PRInt32 level, posInSet, setSize;
-  nsAccessibilityUtils::GetAccGroupAttrs(attributes,
-                                         &level, &posInSet, &setSize);
+  nsAccUtils::GetAccGroupAttrs(attributes, &level, &posInSet, &setSize);
 
   if (!posInSet && !setSize)
     return NS_OK;
 
   *aGroupLevel = level;
 
   *aPositionInGroup = posInSet;
   *aSimilarItemsInGroup = setSize - 1;
@@ -2289,18 +2287,19 @@ nsAccessible::GetARIAState(PRUint32 *aSt
   }
 
   (*aState) |= mRoleMapEntry->state;
   if (MappedAttrState(content, aState, &mRoleMapEntry->attributeMap1) &&
       MappedAttrState(content, aState, &mRoleMapEntry->attributeMap2) &&
       MappedAttrState(content, aState, &mRoleMapEntry->attributeMap3) &&
       MappedAttrState(content, aState, &mRoleMapEntry->attributeMap4) &&
       MappedAttrState(content, aState, &mRoleMapEntry->attributeMap5) &&
-      MappedAttrState(content, aState, &mRoleMapEntry->attributeMap6)) {
-    MappedAttrState(content, aState, &mRoleMapEntry->attributeMap7);
+      MappedAttrState(content, aState, &mRoleMapEntry->attributeMap6) &&
+      MappedAttrState(content, aState, &mRoleMapEntry->attributeMap7)) {
+    MappedAttrState(content, aState, &mRoleMapEntry->attributeMap8);
   }
 
   return NS_OK;
 }
 
 // Not implemented by this class
 
 /* DOMString getValue (); */
@@ -2526,24 +2525,26 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
 /* nsIAccessible getAccessibleBelow(); */
 NS_IMETHODIMP nsAccessible::GetAccessibleBelow(nsIAccessible **_retval)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 already_AddRefed<nsIDOMNode>
 nsAccessible::FindNeighbourPointingToThis(nsIAtom *aRelationAttr,
+                                          PRUint32 aRelationNameSpaceID,
                                           PRUint32 aAncestorLevelsToSearch)
 {
   nsIContent *content = GetRoleContent(mDOMNode);
   if (!content)
     return nsnull; // Node shut down
 
   nsIContent* description = FindNeighbourPointingToNode(content, nsnull,
                                                         aRelationAttr,
+                                                        aRelationNameSpaceID,
                                                         aAncestorLevelsToSearch);
 
   if (!description)
     return nsnull;
 
   nsIDOMNode *relatedNode;
   CallQueryInterface(description, &relatedNode);
   return relatedNode;
@@ -2575,16 +2576,17 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
       if (content->Tag() == nsAccessibilityAtoms::label) {
         nsIAtom *relatedIDAttr = content->IsNodeOfType(nsINode::eHTML) ?
           nsAccessibilityAtoms::_for : nsAccessibilityAtoms::control;
         content->GetAttr(kNameSpaceID_None, relatedIDAttr, relatedID);
       }
       if (relatedID.IsEmpty()) {
         const PRUint32 kAncestorLevelsToSearch = 3;
         relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::labelledby,
+                                                  kNameSpaceID_WAIProperties,
                                                   kAncestorLevelsToSearch);
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_LABELLED_BY:
     {
       content->GetAttr(kNameSpaceID_WAIProperties,
                        nsAccessibilityAtoms::labelledby, relatedID);
@@ -2607,53 +2609,57 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_DESCRIPTION_FOR:
     {
       const PRUint32 kAncestorLevelsToSearch = 3;
       relatedNode =
         FindNeighbourPointingToThis(nsAccessibilityAtoms::describedby,
+                                    kNameSpaceID_WAIProperties,
                                     kAncestorLevelsToSearch);
 
       if (!relatedNode && content->Tag() == nsAccessibilityAtoms::description &&
           content->IsNodeOfType(nsINode::eXUL)) {
         // This affectively adds an optional control attribute to xul:description,
         // which only affects accessibility, by allowing the description to be
         // tied to a control.
         content->GetAttr(kNameSpaceID_None,
                          nsAccessibilityAtoms::control, relatedID);
       }
       break;
     }
   case nsIAccessibleRelation::RELATION_NODE_CHILD_OF:
     {
-      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::owns);
+      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::owns,
+                                                kNameSpaceID_WAIProperties);
       break;
     }
   case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
     {
-      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::controls);
+      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::controls,
+                                                kNameSpaceID_WAIProperties);
       break;
     }
   case nsIAccessibleRelation::RELATION_CONTROLLER_FOR:
     {
       content->GetAttr(kNameSpaceID_WAIProperties,
                        nsAccessibilityAtoms::controls, relatedID);
       break;
     }
   case nsIAccessibleRelation::RELATION_FLOWS_TO:
     {
       content->GetAttr(kNameSpaceID_WAIProperties,
                        nsAccessibilityAtoms::flowto, relatedID);
       break;
     }
   case nsIAccessibleRelation::RELATION_FLOWS_FROM:
     {
-      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::flowto);
+      relatedNode = FindNeighbourPointingToThis(nsAccessibilityAtoms::flowto,
+                                                kNameSpaceID_WAIProperties);
       break;
     }
 
   case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON:
     {
       if (content->IsNodeOfType(nsINode::eHTML)) {
         nsCOMPtr<nsIForm> form;
         while ((form = do_QueryInterface(content)) == nsnull &&
@@ -2717,19 +2723,19 @@ NS_IMETHODIMP nsAccessible::GetAccessibl
     domDoc->GetElementById(relatedID, getter_AddRefs(relatedEl));
     relatedNode = do_QueryInterface(relatedEl);
   }
 
   // Return the corresponding accessible if the related DOM node is found
   if (relatedNode) {
     nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
     NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
-    return accService->GetAccessibleInWeakShell(relatedNode, mWeakShell, aRelated);
+    accService->GetAccessibleInWeakShell(relatedNode, mWeakShell, aRelated);
   }
-  return NS_ERROR_FAILURE;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessible::GetRelationsCount(PRUint32 *aCount)
 {
   NS_ENSURE_ARG_POINTER(aCount);
   *aCount = 0;
 
@@ -2799,17 +2805,17 @@ NS_IMETHODIMP nsAccessible::GetNativeInt
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 void nsAccessible::DoCommandCallback(nsITimer *aTimer, void *aClosure)
 {
   NS_ASSERTION(gDoCommandTimer, "How did we get here if there was no gDoCommandTimer?");
   NS_RELEASE(gDoCommandTimer);
 
-  nsIContent *content = NS_REINTERPRET_CAST(nsIContent*, aClosure);
+  nsIContent *content = reinterpret_cast<nsIContent*>(aClosure);
   nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(content));
   if (xulElement) {
     xulElement->Click();
   }
   else {
     nsIDocument *doc = content->GetDocument();
     if (!doc) {
       return;
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -63,17 +63,17 @@ struct nsRect;
 class nsIContent;
 class nsIFrame;
 class nsIPresShell;
 class nsIDOMNode;
 class nsIAtom;
 class nsIView;
 
 // When mNextSibling is set to this, it indicates there ar eno more siblings
-#define DEAD_END_ACCESSIBLE NS_STATIC_CAST(nsIAccessible*, (void*)1)
+#define DEAD_END_ACCESSIBLE static_cast<nsIAccessible*>((void*)1)
 
 // Saves a data member -- if child count equals this value we haven't
 // cached children or child count yet
 enum { eChildCountUninitialized = -1 };
 
 class nsAccessibleDOMStringList : public nsIDOMDOMStringList
 {
 public:
@@ -162,54 +162,71 @@ public:
 protected:
   PRBool MappedAttrState(nsIContent *aContent, PRUint32 *aStateInOut, nsStateMapEntry *aStateMapEntry);
   virtual nsIFrame* GetBoundsFrame();
   virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame);
   PRBool IsVisible(PRBool *aIsOffscreen); 
 
   // Relation helpers
   nsresult GetTextFromRelationID(nsIAtom *aIDAttrib, nsString &aName);
+
+  /**
+   * Search element in neighborhood of the given element by tag name and
+   * attribute value that equals to ID attribute of the current element.
+   * ID attribute can be either 'id' attribute or 'anonid' if the element is
+   * anonymous.
+   *
+   * @param aRelationAttr - attribute name of searched element
+   * @param aRelationNamespaceID - namespace id of searched attribute, by default
+   *                               empty namespace
+   * @param aAncestorLevelsToSearch - points how is the neighborhood of the
+   *                                  given element big.
+   */
   already_AddRefed<nsIDOMNode> FindNeighbourPointingToThis(nsIAtom *aRelationAttr,
+                                                           PRUint32 aRelationNameSpaceID = kNameSpaceID_None,
                                                            PRUint32 aAncestorLevelsToSearch = 0);
 
   /**
    * Search element in neighborhood of the given element by tag name and
    * attribute value that equals to ID attribute of the given element.
    * ID attribute can be either 'id' attribute or 'anonid' if the element is
    * anonymous.
    *
    * @param aForNode - the given element the search is performed for
    * @param aTagName - tag name of searched element
-   * @param aAttr - attribute name of searched element
+   * @param aRelationAttr - attribute name of searched element
+   * @param aRelationNamespaceID - namespace id of searched attribute, by default
+   *                               empty namespace
    * @param aAncestorLevelsToSearch - points how is the neighborhood of the
    *                                  given element big.
    */
   static nsIContent *FindNeighbourPointingToNode(nsIContent *aForNode,
                                                  nsIAtom *aTagName,
-                                                 nsIAtom *aAttr,
+                                                 nsIAtom *aRelationAttr,
+                                                 PRUint32 aRelationNameSpaceID = kNameSpaceID_None,
                                                  PRUint32 aAncestorLevelsToSearch = 5);
 
   /**
    * Search for element that satisfies the requirements in subtree of the given
    * element. The requirements are tag name, attribute name and value of
    * attribute.
    *
    * @param aId - value of searched attribute
    * @param aLookContent - element that search is performed inside
-   * @param aForAttrib - searched attribute
+   * @param aRelationAttr - searched attribute
+   * @param aRelationNamespaceID - namespace id of searched attribute, by default
+   *                               empty namespace
    * @param aExcludeContent - element that is skiped for search
-   * @param aForAttribNamespace - namespace id of searched attribute, by default
-   *                              empty namespace
    * @param aTagType - tag name of searched element, by default it is 'label'
    */
   static nsIContent *FindDescendantPointingToID(const nsAString *aId,
                                                 nsIContent *aLookContent,
-                                                nsIAtom *forAttrib,
+                                                nsIAtom *aRelationAttr,
+                                                PRUint32 aRelationNamespaceID = kNameSpaceID_None,
                                                 nsIContent *aExcludeContent = nsnull,
-                                                PRUint32 aForAttribNamespace = kNameSpaceID_None,
                                                 nsIAtom *aTagType = nsAccessibilityAtoms::label);
 
   static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
   static nsIContent *GetLabelContent(nsIContent *aForNode);
   static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
 
   // Name helpers
   nsresult GetHTMLName(nsAString& _retval, PRBool aCanAggregateSubtree = PR_TRUE);
--- a/accessible/src/base/nsAccessibleEventData.cpp
+++ b/accessible/src/base/nsAccessibleEventData.cpp
@@ -35,16 +35,20 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAccessibleEventData.h"
 #include "nsIAccessibilityService.h"
 #include "nsIAccessNode.h"
 #include "nsIServiceManager.h"
+#ifdef MOZ_XUL
+#include "nsIDOMXULMultSelectCntrlEl.h"
+#include "nsXULTreeAccessible.h"
+#endif
 
 NS_IMPL_ISUPPORTS1(nsAccEvent, nsIAccessibleEvent)
 
 nsAccEvent::nsAccEvent(PRUint32 aEventType, nsIAccessible *aAccessible,
                        void *aEventData):
   mEventType(aEventType), mAccessible(aAccessible), mEventData(aEventData)
 {
 }
@@ -120,16 +124,47 @@ nsAccEvent::GetAccessibleByNode()
 
   nsCOMPtr<nsIAccessibilityService> accService = 
     do_GetService("@mozilla.org/accessibilityService;1");
   if (!accService)
     return nsnull;
 
   nsIAccessible *accessible = nsnull;
   accService->GetAccessibleFor(mDOMNode, &accessible);
+#ifdef MOZ_XUL
+  // hack for xul tree table. We need a better way for firing delayed event
+  // against xul tree table. see bug 386821.
+  // There will be problem if some day we want to fire delayed event against
+  // the xul tree itself or an unselected treeitem.
+  nsAutoString localName;
+  mDOMNode->GetLocalName(localName);
+  if (localName.EqualsLiteral("tree")) {
+    nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
+      do_QueryInterface(mDOMNode);
+    if (multiSelect) {
+      PRInt32 treeIndex = -1;
+      multiSelect->GetCurrentIndex(&treeIndex);
+      if (treeIndex >= 0) {
+        nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(accessible));
+        NS_IF_RELEASE(accessible);
+        nsCOMPtr<nsIAccessible> treeItemAccessible;
+        if (!treeCache ||
+            NS_FAILED(treeCache->GetCachedTreeitemAccessible(
+                      treeIndex,
+                      nsnull,
+                      getter_AddRefs(treeItemAccessible))) ||
+                      !treeItemAccessible) {
+          return nsnull;
+        }
+        NS_IF_ADDREF(accessible = treeItemAccessible);
+      }
+    }
+  }
+#endif
+
   return accessible;
 }
 
 
 // nsAccStateChangeEvent
 NS_IMPL_ISUPPORTS_INHERITED1(nsAccStateChangeEvent, nsAccEvent,
                              nsIAccessibleStateChangeEvent)
 
@@ -220,8 +255,35 @@ nsAccTextChangeEvent::GetLength(PRUint32
 
 NS_IMETHODIMP
 nsAccTextChangeEvent::IsInserted(PRBool *aIsInserted)
 {
   *aIsInserted = mIsInserted;
   return NS_OK;
 }
 
+// nsAccCaretMoveEvent
+NS_IMPL_ISUPPORTS_INHERITED1(nsAccCaretMoveEvent, nsAccEvent,
+                             nsIAccessibleCaretMoveEvent)
+
+nsAccCaretMoveEvent::
+  nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset) :
+  nsAccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aAccessible, nsnull),
+  mCaretOffset(aCaretOffset)
+{
+}
+
+nsAccCaretMoveEvent::
+  nsAccCaretMoveEvent(nsIDOMNode *aNode) :
+  nsAccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aNode, nsnull),
+  mCaretOffset(-1)
+{
+}
+
+NS_IMETHODIMP
+nsAccCaretMoveEvent::GetCaretOffset(PRInt32* aCaretOffset)
+{
+  NS_ENSURE_ARG_POINTER(aCaretOffset);
+
+  *aCaretOffset = mCaretOffset;
+  return NS_OK;
+}
+
--- a/accessible/src/base/nsAccessibleEventData.h
+++ b/accessible/src/base/nsAccessibleEventData.h
@@ -17,16 +17,17 @@
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Kyle Yuan (kyle.yuan@sun.com)
  *   John Sun (john.sun@sun.com)
+ *   Alexander Surkov <surkov.alexander@gmail.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -108,23 +109,33 @@ public:
   NS_DECL_NSIACCESSIBLETEXTCHANGEEVENT
 
 private:
   PRInt32 mStart;
   PRUint32 mLength;
   PRBool mIsInserted;
 };
 
-// XXX todo: We might want to use XPCOM interfaces instead of structs
-//     e.g., nsAccessibleTextChangeEvent: public nsIAccessibleTextChangeEvent
+class nsAccCaretMoveEvent: public nsAccEvent,
+                           public nsIAccessibleCaretMoveEvent
+{
+public:
+  nsAccCaretMoveEvent(nsIAccessible *aAccessible, PRInt32 aCaretOffset);
+  nsAccCaretMoveEvent(nsIDOMNode *aNode);
 
-struct AtkChildrenChange {
-  PRInt32      index;  // index of child in parent 
-  nsIAccessible *child;   
-  PRBool        add;    // true for add, false for delete
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_FORWARD_NSIACCESSIBLEEVENT(nsAccEvent::)
+  NS_DECL_NSIACCESSIBLECARETMOVEEVENT
+
+private:
+  PRInt32 mCaretOffset;
 };
 
+// XXX todo: We might want to use XPCOM interfaces instead of struct
+//     e.g., nsAccessibleTableChangeEvent: public nsIAccessibleTableChangeEvent
+
 struct AtkTableChange {
   PRUint32 index;   // the start row/column after which the rows are inserted/deleted.
   PRUint32 count;   // the number of inserted/deleted rows/columns
 };
 
-#endif  
+#endif
+
--- a/accessible/src/base/nsApplicationAccessible.cpp
+++ b/accessible/src/base/nsApplicationAccessible.cpp
@@ -138,17 +138,17 @@ nsApplicationAccessible::GetChildAt(PRIn
   PRUint32 count = 0;
   nsresult rv = NS_OK;
 
   if (mChildren) {
     rv = mChildren->GetLength(&count);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  if (aChildNum >= NS_STATIC_CAST(PRInt32, count) || count == 0)
+  if (aChildNum >= static_cast<PRInt32>(count) || count == 0)
     return NS_ERROR_INVALID_ARG;
 
   if (aChildNum < 0)
     aChildNum = count - 1;
 
   nsCOMPtr<nsIWeakReference> childWeakRef;
   rv = mChildren->QueryElementAt(aChildNum, NS_GET_IID(nsIWeakReference),
                                  getter_AddRefs(childWeakRef));
@@ -208,17 +208,17 @@ nsApplicationAccessible::CacheChildren()
 
         previousAccessible = do_QueryInterface(accessible);
         previousAccessible->SetParent(this);
       }
     }
 
     PRUint32 count = 0;
     mChildren->GetLength(&count);
-    mAccChildCount = NS_STATIC_CAST(PRInt32, count);
+    mAccChildCount = static_cast<PRInt32>(count);
   }
 }
 
 // nsApplicationAccessible
 
 nsresult
 nsApplicationAccessible::AddRootAccessible(nsIAccessible *aRootAccessible)
 {
--- a/accessible/src/base/nsBaseWidgetAccessible.cpp
+++ b/accessible/src/base/nsBaseWidgetAccessible.cpp
@@ -238,17 +238,17 @@ void nsLinkableAccessible::CacheActionCo
         link->GetHrefURI(getter_AddRefs(uri));
         if (uri) {
           mActionContent = walkUpContent;
           mIsLink = PR_TRUE;
           break;
         }
       }
     }
-    if (nsAccessibilityUtils::HasListener(walkUpContent, NS_LITERAL_STRING("click"))) {
+    if (nsAccUtils::HasListener(walkUpContent, NS_LITERAL_STRING("click"))) {
       mActionContent = walkUpContent;
       mIsOnclick = PR_TRUE;
       break;
     }
   }
 }
 
 // nsIAccessibleHyperLink::GetURI()
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -212,18 +212,21 @@ NS_IMETHODIMP nsCaretAccessible::NotifyS
     textAcc->GetSelectionCount(&selectionCount);   // Don't swallow similar events when selecting text
     if (!selectionCount) {
       return NS_OK;  // Swallow duplicate caret event
     }
   }
   mLastCaretOffset = caretOffset;
   mLastTextAccessible = textAcc;
 
-  return mRootAccessible->FireDelayedToolkitEvent(nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED,
-                                                  focusNode, nsnull, PR_FALSE);
+  nsCOMPtr<nsIAccessibleCaretMoveEvent> event =
+    new nsAccCaretMoveEvent(focusNode);
+  NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
+
+  return mRootAccessible->FireDelayedAccessibleEvent(event, PR_FALSE);
 }
 
 nsRect
 nsCaretAccessible::GetCaretRect(nsIWidget **aOutWidget)
 {
   nsRect caretRect;
   NS_ENSURE_TRUE(aOutWidget, caretRect);
   *aOutWidget = nsnull;
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -196,16 +196,23 @@ NS_IMETHODIMP nsDocAccessible::GetRole(P
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocAccessible::GetValue(nsAString& aValue)
 {
   return GetURL(aValue);
 }
 
+NS_IMETHODIMP 
+nsDocAccessible::GetDescription(nsAString& aDescription)
+{
+  aDescription.Truncate();
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 nsDocAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
 {
   // nsAccessible::GetState() always fail for document accessible.
   nsAccessible::GetState(aState, aExtraState);
 
   nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
   if (!xulDoc) {
@@ -504,17 +511,17 @@ NS_IMETHODIMP nsDocAccessible::Init()
 
   return rv;
 }
 
 
 NS_IMETHODIMP nsDocAccessible::Destroy()
 {
   if (mWeakShell) {
-    gGlobalDocAccessibleCache.Remove(NS_STATIC_CAST(void*, mWeakShell));
+    gGlobalDocAccessibleCache.Remove(static_cast<void*>(mWeakShell));
   }
   return Shutdown();
 }
 
 NS_IMETHODIMP nsDocAccessible::Shutdown()
 {
   if (!mWeakShell) {
     return NS_OK;  // Already shutdown
@@ -745,18 +752,18 @@ NS_IMETHODIMP nsDocAccessible::FireAncho
   if (currentAnchor.Equals(lastAnchor)) {
     mIsAnchorJumped = PR_FALSE;
   } else {
     mIsAnchorJumped = PR_TRUE;
     lastAnchor.Assign(currentAnchor);
   }
 
   if (mIsAnchorJumped) {
-    FireToolkitEvent(nsIAccessibleEvent::EVENT_DOCUMENT_ATTRIBUTES_CHANGED,
-                     this, nsnull);
+    nsAccUtils::
+      FireAccEvent(nsIAccessibleEvent::EVENT_DOCUMENT_ATTRIBUTES_CHANGED, this);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocAccessible::FireDocLoadEvents(PRUint32 aEventType)
 {
   if (!mDocument || !mWeakShell) {
@@ -804,32 +811,32 @@ NS_IMETHODIMP nsDocAccessible::FireDocLo
 
     // Loading document: fire EVENT_STATE_CHANGE to set STATE_BUSY
     nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
       new nsAccStateChangeEvent(this, nsIAccessibleStates::STATE_BUSY,
                                 PR_FALSE, PR_TRUE);
     FireAccessibleEvent(accEvent);
   }
 
-  FireToolkitEvent(aEventType, this, nsnull);
+  nsAccUtils::FireAccEvent(aEventType, this);
   return NS_OK;
 }
 
 void nsDocAccessible::ScrollTimerCallback(nsITimer *aTimer, void *aClosure)
 {
-  nsDocAccessible *docAcc = NS_REINTERPRET_CAST(nsDocAccessible*, aClosure);
+  nsDocAccessible *docAcc = reinterpret_cast<nsDocAccessible*>(aClosure);
 
   if (docAcc && docAcc->mScrollPositionChangedTicks &&
       ++docAcc->mScrollPositionChangedTicks > 2) {
     // Whenever scroll position changes, mScrollPositionChangeTicks gets reset to 1
     // We only want to fire accessibilty scroll event when scrolling stops or pauses
     // Therefore, we wait for no scroll events to occur between 2 ticks of this timer
     // That indicates a pause in scrolling, so we fire the accessibilty scroll event
-    docAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SCROLLING_END, docAcc,
-                             nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SCROLLING_END, docAcc);
+
     docAcc->mScrollPositionChangedTicks = 0;
     if (docAcc->mScrollWatchTimer) {
       docAcc->mScrollWatchTimer->Cancel();
       docAcc->mScrollWatchTimer = nsnull;
     }
   }
 }
 
@@ -1223,17 +1230,17 @@ nsDocAccessible::FireDelayedAccessibleEv
     }
   }
 
   mEventsToFire.AppendObject(aEvent);
   if (!isTimerStarted) {
     // This is be the first delayed event in queue, start timer
     // so that event gets fired via FlushEventsCallback
     mFireEventTimer->InitWithFuncCallback(FlushEventsCallback,
-                                          NS_STATIC_CAST(nsPIAccessibleDocument*, this),
+                                          static_cast<nsPIAccessibleDocument*>(this),
                                           0, nsITimer::TYPE_ONE_SHOT);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocAccessible::FlushPendingEvents()
 {
@@ -1257,82 +1264,81 @@ NS_IMETHODIMP nsDocAccessible::FlushPend
         if (docAccessible) {
           docAccessible->FireDocLoadEvents(nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE);
         }
       }
       else if (eventType == nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED) {
         nsCOMPtr<nsIAccessibleText> accessibleText = do_QueryInterface(accessible);
         PRInt32 caretOffset;
         if (accessibleText && NS_SUCCEEDED(accessibleText->GetCaretOffset(&caretOffset))) {
-          FireToolkitEvent(nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED,
-                           accessible, &caretOffset);
+          nsCOMPtr<nsIAccessibleCaretMoveEvent> caretMoveEvent =
+            new nsAccCaretMoveEvent(accessible, caretOffset);
+          NS_ENSURE_TRUE(caretMoveEvent, NS_ERROR_OUT_OF_MEMORY);
+
+          FireAccessibleEvent(caretMoveEvent);
+
           PRInt32 selectionCount;
           accessibleText->GetSelectionCount(&selectionCount);
           if (selectionCount) {  // There's a selection so fire selection change as well
-            FireToolkitEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED,
-                                                 accessible, nsnull);
+            nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED,
+                                     accessible);
           }
         } 
       }
       else {
         FireAccessibleEvent(accessibleEvent);
       }
     }
   }
   mEventsToFire.Clear(); // Clear out array
   return NS_OK;
 }
 
 void nsDocAccessible::FlushEventsCallback(nsITimer *aTimer, void *aClosure)
 {
-  nsPIAccessibleDocument *accessibleDoc = NS_STATIC_CAST(nsPIAccessibleDocument*, aClosure);
+  nsPIAccessibleDocument *accessibleDoc = static_cast<nsPIAccessibleDocument*>(aClosure);
   NS_ASSERTION(accessibleDoc, "How did we get here without an accessible document?");
   accessibleDoc->FlushPendingEvents();
 }
 
 void nsDocAccessible::RefreshNodes(nsIDOMNode *aStartNode, PRUint32 aChangeEvent)
 {
+  NS_ASSERTION(aChangeEvent != nsIAccessibleEvent::EVENT_SHOW,
+               "nsDocAccessible::RefreshNodes isn't supposed to work with show event.");
+
   nsCOMPtr<nsIDOMNode> iterNode(aStartNode), nextNode;
   nsCOMPtr<nsIAccessNode> accessNode;
 
   do {
     GetCachedAccessNode(iterNode, getter_AddRefs(accessNode));
     if (accessNode) {
       // Accessibles that implement their own subtrees,
       // like html combo boxes and xul trees must shutdown all of their own
       // children when they override Shutdown()
 
       // Don't shutdown our doc object!
-      if (accessNode != NS_STATIC_CAST(nsIAccessNode*, this)) {
-        if (aChangeEvent != nsIAccessibleEvent::EVENT_SHOW) {
-          nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
-          if (accessible) {
-            // Fire menupopupend events for menu popups that go away
-            PRUint32 role, event = 0;
-            accessible->GetFinalRole(&role);
-            if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
-              nsCOMPtr<nsIDOMNode> domNode;
-              accessNode->GetDOMNode(getter_AddRefs(domNode));
-              nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(domNode));
-              if (!popup) {
-                // Popup elements already fire these via DOMMenuInactive
-                // handling in nsRootAccessible::HandleEvent
-                event = nsIAccessibleEvent::EVENT_MENUPOPUP_END;
-              }
-            }
-            else if (role == nsIAccessibleRole::ROLE_PROGRESSBAR &&
-                     iterNode != aStartNode) {
-              // Make sure EVENT_HIDE gets fired for progress meters
-              event = nsIAccessibleEvent::EVENT_HIDE;
-            }
-            if (event) {
-              FireToolkitEvent(event, accessible, nsnull);
+      if (accessNode != static_cast<nsIAccessNode*>(this)) {
+
+        nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
+        if (accessible) {
+          // Fire menupopupend events for menu popups that go away
+          PRUint32 role = Role(accessible);
+          if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
+            nsCOMPtr<nsIDOMNode> domNode;
+            accessNode->GetDOMNode(getter_AddRefs(domNode));
+            nsCOMPtr<nsIDOMXULPopupElement> popup(do_QueryInterface(domNode));
+            if (!popup) {
+              // Popup elements already fire these via DOMMenuInactive
+              // handling in nsRootAccessible::HandleEvent
+              nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
+                                       accessible);
             }
           }
         }
+
         void *uniqueID;
         accessNode->GetUniqueID(&uniqueID);
         nsCOMPtr<nsPIAccessNode> privateAccessNode(do_QueryInterface(accessNode));
         privateAccessNode->Shutdown();
         // Remove from hash table as well
         mAccessNodeCache.Remove(uniqueID);
       }
     }
@@ -1378,109 +1384,99 @@ NS_IMETHODIMP nsDocAccessible::Invalidat
   // instead of just the accessible tree, although that would be faster
   // Otherwise we might miss the nsAccessNode's that are not nsAccessible's.
 
   NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE);
   nsCOMPtr<nsIDOMNode> childNode = aChild ? do_QueryInterface(aChild) : mDOMNode;
   if (!IsNodeRelevant(childNode)) {
     return NS_OK;  // Don't fire event unless it can be for an attached accessible
   }
-  if (!mIsContentLoaded && mAccessNodeCache.Count() <= 1 &&
-      mAccChildCount == eChildCountUninitialized) {
-    return NS_OK; // Still loading and nothing to invalidate yet
+  if (!mIsContentLoaded && mAccessNodeCache.Count() <= 1) {
+    // Still loading and no accessibles has yet been created other than this
+    // doc accessible. In this case we optimize
+    // by not firing SHOW/HIDE/REORDER events for every document mutation
+    // caused by page load, since AT is not going to want to grab the
+    // document and listen to these changes until after the page is first loaded
+    // Leave early, and ensure mAccChildCount stays uninitialized instead of 0,
+    // which it is if anyone asks for its children right now.
+    return InvalidateChildren();
   }
 
   nsCOMPtr<nsIAccessNode> childAccessNode;
   GetCachedAccessNode(childNode, getter_AddRefs(childAccessNode));
   nsCOMPtr<nsIAccessible> childAccessible = do_QueryInterface(childAccessNode);
-  if (!childAccessible && mIsContentLoaded && aChangeEventType != nsIAccessibleEvent::EVENT_HIDE) {
+  if (!childAccessible && aChangeEventType != nsIAccessibleEvent::EVENT_HIDE) {
     // If not about to hide it, make sure there's an accessible so we can fire an
     // event for it
     GetAccService()->GetAccessibleFor(childNode, getter_AddRefs(childAccessible));
   }
-  nsCOMPtr<nsPIAccessible> privateChildAccessible =
-    do_QueryInterface(childAccessible);
+
 #ifdef DEBUG_A11Y
   nsAutoString localName;
   childNode->GetLocalName(localName);
   const char *hasAccessible = childAccessible ? " (acc)" : "";
   if (aChangeEventType == nsIAccessibleEvent::EVENT_HIDE) {
     printf("[Hide %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   }
   else if (aChangeEventType == nsIAccessibleEvent::EVENT_SHOW) {
     printf("[Show %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   }
   else if (aChangeEventType == nsIAccessibleEvent::EVENT_REORDER) {
     printf("[Reorder %s %s]\n", NS_ConvertUTF16toUTF8(localName).get(), hasAccessible);
   }
 #endif
 
-  if (aChangeEventType == nsIAccessibleEvent::EVENT_HIDE) {
-    // Fire EVENT_HIDE or EVENT_MENUPOPUP_END if previous accessible existed
-    // for node being hidden. Fire this before the accessible goes away
-    if (privateChildAccessible) {
-      privateChildAccessible->FireToolkitEvent(nsIAccessibleEvent::EVENT_HIDE,
-                                               childAccessible, nsnull);
-    }
+  if (aChangeEventType == nsIAccessibleEvent::EVENT_HIDE ||
+      aChangeEventType == nsIAccessibleEvent::EVENT_REORDER) {
+    // Fire EVENT_HIDE if previous accessible existed for node being hidden.
+    // Fire this before the accessible goes away.
+    if (childAccessible)
+      nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_HIDE, childAccessible);
   }
 
   // Shutdown nsIAccessNode's or nsIAccessibles for any DOM nodes in this subtree
   if (aChangeEventType != nsIAccessibleEvent::EVENT_SHOW) {
     RefreshNodes(childNode, aChangeEventType);
   }
 
   // We need to get an accessible for the mutation event's container node
   // If there is no accessible for that node, we need to keep moving up the parent
   // chain so there is some accessible.
   // We will use this accessible to fire the accessible mutation event.
   // We're guaranteed success, because we will eventually end up at the doc accessible,
   // and there is always one of those.
 
   nsCOMPtr<nsIAccessible> containerAccessible;
-  if (childNode == mDOMNode) {
-    // Don't get parent accessible if already at the root of a docshell chain like UI or content
-    // Don't fire any other events if doc is still loading
-    nsCOMPtr<nsISupports> container = mDocument->GetContainer();
-    nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(container));
-    NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
-    nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
-    docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
-    if (sameTypeRoot == docShellTreeItem) {
-      containerAccessible = this;  // At the root of UI or content
-    }
-  }
+  GetAccessibleInParentChain(childNode, getter_AddRefs(containerAccessible));
   if (!containerAccessible) {
-    GetAccessibleInParentChain(childNode, mIsContentLoaded, getter_AddRefs(containerAccessible));
+    containerAccessible = this;
   }
   nsCOMPtr<nsPIAccessible> privateContainerAccessible =
     do_QueryInterface(containerAccessible);
   if (privateContainerAccessible) {
     privateContainerAccessible->InvalidateChildren();
   }
 
-  if (!mIsContentLoaded) {
-    return NS_OK;
-  }
-
   // Fire an event so the assistive technology knows the objects it is holding onto
   // in this part of the subtree are no longer useful and should be released.
   // However, they still won't crash if the AT tries to use them, because a stub of the
   // object still exists as long as it is refcounted, even from outside of Gecko.
   nsCOMPtr<nsIAccessNode> containerAccessNode =
     do_QueryInterface(containerAccessible);
   if (containerAccessNode) {
     nsCOMPtr<nsIDOMNode> containerNode;
     containerAccessNode->GetDOMNode(getter_AddRefs(containerNode));
     if (containerNode) {
       FireDelayedToolkitEvent(nsIAccessibleEvent::EVENT_REORDER,
                               containerNode, nsnull);
     }
   }
 
-  if (aChangeEventType == nsIAccessibleEvent::EVENT_SHOW && aChild) {
+  if (aChild && (aChangeEventType == nsIAccessibleEvent::EVENT_SHOW ||
+      aChangeEventType == nsIAccessibleEvent::EVENT_REORDER)) {
     // Fire EVENT_SHOW, EVENT_MENUPOPUP_START for newly visible content.
     // Fire after a short timer, because we want to make sure the view has been
     // updated to make this accessible content visible. If we don't wait,
     // the assistive technology may receive the event and then retrieve
     // nsIAccessibleStates::STATE_INVISIBLE for the event's accessible object.
     FireDelayedToolkitEvent(nsIAccessibleEvent::EVENT_SHOW, childNode, nsnull);
     nsAutoString role;
     if (GetRoleAttribute(aChild, role) &&
@@ -1504,17 +1500,17 @@ NS_IMETHODIMP nsDocAccessible::Invalidat
       ancestor = ancestor->GetParent();
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDocAccessible::GetAccessibleInParentChain(nsIDOMNode *aNode, PRBool aCanCreate,
+nsDocAccessible::GetAccessibleInParentChain(nsIDOMNode *aNode,
                                             nsIAccessible **aAccessible)
 {
   // Find accessible in parent chain of DOM nodes, or return null
   *aAccessible = nsnull;
   nsCOMPtr<nsIDOMNode> currentNode(aNode), parentNode;
   nsCOMPtr<nsIAccessNode> accessNode;
 
   nsIAccessibilityService *accService = GetAccService();
@@ -1529,52 +1525,32 @@ nsDocAccessible::GetAccessibleInParentCh
       break;
     }
 
     nsCOMPtr<nsIDOMNode> relevantNode;
     if (NS_SUCCEEDED(accService->GetRelevantContentNodeFor(currentNode, getter_AddRefs(relevantNode))) && relevantNode) {
       currentNode = relevantNode;
     }
 
-    if (aCanCreate) {
-      accService->GetAccessibleInWeakShell(currentNode, mWeakShell, aAccessible);
-    }
-    else {
-      accService->GetCachedAccessible(currentNode, mWeakShell, aAccessible);
-    }
+    accService->GetAccessibleInWeakShell(currentNode, mWeakShell, aAccessible);
   } while (!*aAccessible);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDocAccessible::FireToolkitEvent(PRUint32 aEvent, nsIAccessible *aTarget,
-                                  void * aData)
-{
-  // Don't fire event for accessible that has been shut down.
-  if (!mWeakShell)
-    return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIAccessibleEvent> accEvent =
-    new nsAccEvent(aEvent, aTarget, aData);
-  NS_ENSURE_TRUE(accEvent, NS_ERROR_OUT_OF_MEMORY);
-
-  return FireAccessibleEvent(accEvent);
-}
-
 void nsDocAccessible::DocLoadCallback(nsITimer *aTimer, void *aClosure)
 {
   // Doc has finished loading, fire "load finished" event
   // By using short timer we can wait make the window visible, 
   // which it does asynchronously. This avoids confusing the screen reader with a
   // hidden window. Waiting also allows us to see of the document has focus,
   // which is important because we only fire doc loaded events for focused documents.
 
   nsDocAccessible *docAcc =
-    NS_REINTERPRET_CAST(nsDocAccessible*, aClosure);
+    reinterpret_cast<nsDocAccessible*>(aClosure);
   if (!docAcc) {
     return;
   }
 
   // Fire doc finished event
   nsCOMPtr<nsIDOMNode> docDomNode;
   docAcc->GetDOMNode(getter_AddRefs(docDomNode));
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(docDomNode));
--- a/accessible/src/base/nsDocAccessible.h
+++ b/accessible/src/base/nsDocAccessible.h
@@ -71,32 +71,30 @@ class nsDocAccessible : public nsHyperTe
 
   public:
     nsDocAccessible(nsIDOMNode *aNode, nsIWeakReference* aShell);
     virtual ~nsDocAccessible();
 
     NS_IMETHOD GetRole(PRUint32 *aRole);
     NS_IMETHOD GetName(nsAString& aName);
     NS_IMETHOD GetValue(nsAString& aValue);
+    NS_IMETHOD GetDescription(nsAString& aDescription);
     NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
     NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
     NS_IMETHOD GetParent(nsIAccessible **aParent);
     NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
     NS_IMETHOD TakeFocus(void);
 
     // ----- nsIScrollPositionListener ---------------------------
     NS_IMETHOD ScrollPositionWillChange(nsIScrollableView *aView, nscoord aX, nscoord aY);
     NS_IMETHOD ScrollPositionDidChange(nsIScrollableView *aView, nscoord aX, nscoord aY);
 
     // nsIDocumentObserver
     NS_DECL_NSIDOCUMENTOBSERVER
 
-    NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible,
-                                void* aData);
-
     static void FlushEventsCallback(nsITimer *aTimer, void *aClosure);
 
     // nsIAccessNode
     NS_IMETHOD Shutdown();
     NS_IMETHOD Init();
 
     // nsPIAccessNode
     NS_IMETHOD_(nsIFrame *) GetFrame(void);
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -57,16 +57,17 @@
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDOMXULPopupElement.h"
 #include "nsIDocument.h"
 #include "nsIEventListenerManager.h"
 #include "nsIFocusController.h"
 #include "nsIFrame.h"
+#include "nsIMenuFrame.h"
 #include "nsIHTMLDocument.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIMenuParent.h"
 #include "nsIScrollableView.h"
 #include "nsISelectionPrivate.h"
 #include "nsIServiceManager.h"
 #include "nsIViewManager.h"
 #include "nsPIDOMWindow.h"
@@ -88,17 +89,17 @@
 #include "nsApplicationAccessibleWrap.h"
 #endif
 
 // Expanded version of NS_IMPL_ISUPPORTS_INHERITED2 
 // so we can QI directly to concrete nsRootAccessible
 NS_IMPL_QUERY_HEAD(nsRootAccessible)
 NS_IMPL_QUERY_BODY(nsIDOMEventListener)
 if (aIID.Equals(NS_GET_IID(nsRootAccessible)))
-  foundInterface = NS_REINTERPRET_CAST(nsISupports*, this);
+  foundInterface = reinterpret_cast<nsISupports*>(this);
 else
 NS_IMPL_QUERY_TAIL_INHERITING(nsDocAccessible)
 
 NS_IMPL_ADDREF_INHERITED(nsRootAccessible, nsDocAccessible) 
 NS_IMPL_RELEASE_INHERITED(nsRootAccessible, nsDocAccessible)
 
 //-----------------------------------------------------
 // construction 
@@ -471,64 +472,50 @@ PRBool nsRootAccessible::FireAccessibleF
     }
   }
 
   // Fire focus only if it changes, but always fire focus events when aForceEvent == PR_TRUE
   if (gLastFocusedNode == finalFocusNode && !aForceEvent) {
     return PR_FALSE;
   }
 
-  nsCOMPtr<nsPIAccessible> privateAccessible =
-    do_QueryInterface(finalFocusAccessible);
-  NS_ASSERTION(privateAccessible , "No nsPIAccessible for nsIAccessible");
-  if (!privateAccessible) {
-    return PR_FALSE;
-  }
-
   PRUint32 role = Role(finalFocusAccessible);
   if (role == nsIAccessibleRole::ROLE_MENUITEM) {
     if (!mIsInDHTMLMenu) {  // Entering menus
       PRUint32 naturalRole; // The natural role is the role that this type of element normally has
       finalFocusAccessible->GetRole(&naturalRole);
       if (role != naturalRole) { // Must be a DHTML menuitem
-         FireToolkitEvent(nsIAccessibleEvent::EVENT_MENU_START, this, nsnull);
+         nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENU_START, this);
          mIsInDHTMLMenu = nsIAccessibleRole::ROLE_MENUITEM;
       }
     }
   }
   else if (mIsInDHTMLMenu) {
-    FireToolkitEvent(nsIAccessibleEvent::EVENT_MENU_END, this, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENU_END, this);
     mIsInDHTMLMenu = PR_FALSE;
   }
 
   NS_IF_RELEASE(gLastFocusedNode);
   gLastFocusedNode = finalFocusNode;
   NS_IF_ADDREF(gLastFocusedNode);
 
-  nsCOMPtr<nsIAccessibleDocument> docAccessible = do_QueryInterface(privateAccessible);
+  nsCOMPtr<nsIAccessibleDocument> docAccessible = do_QueryInterface(finalFocusAccessible);
   if (docAccessible) {
     // Doc is gaining focus, but actual focus may be on an element within document
     nsCOMPtr<nsIDOMNode> realFocusedNode = GetCurrentFocus();
     if (realFocusedNode != aNode || realFocusedNode == mDOMNode) {
       // Suppress document focus, because real DOM focus will be fired next,
       // and that's what we care about
       // Make sure we never fire focus for the nsRootAccessible (mDOMNode)
       return PR_FALSE;
     }
   }
 
-  privateAccessible->FireToolkitEvent(nsIAccessibleEvent::EVENT_FOCUS,
-                                      finalFocusAccessible, nsnull);
-
-  // Fire state change event for focus
-  nsCOMPtr<nsIAccessibleStateChangeEvent> accEvent =
-    new nsAccStateChangeEvent(finalFocusAccessible,
-                              nsIAccessibleStates::STATE_FOCUSED,
-                              PR_FALSE, PR_TRUE);
-  FireAccessibleEvent(accEvent);
+  FireDelayedToolkitEvent(nsIAccessibleEvent::EVENT_FOCUS,
+                          finalFocusNode, nsnull);
 
   return PR_TRUE;
 }
 
 void nsRootAccessible::FireCurrentFocusEvent()
 {
   nsCOMPtr<nsIDOMNode> focusedNode = GetCurrentFocus();
   if (!focusedNode) {
@@ -712,22 +699,22 @@ nsresult nsRootAccessible::HandleEventWi
         do_QueryInterface(aTargetNode);
       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();
-        return privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
-                                         accessible, nsnull);
+        return nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
+                                        accessible);
       }
 
-      return privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION,
-                                       treeItemAccessible, nsnull);
+      return nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SELECTION,
+                                      treeItemAccessible);
     }
   }
   else
 #endif
   if (eventType.EqualsLiteral("focus")) {
     // Keep a reference to the target node. We might want to change
     // it to the individual radio button or selected item, and send
     // the focus event to that.
@@ -755,39 +742,37 @@ nsresult nsRootAccessible::HandleEventWi
           if (!accessible)
             return NS_OK;
         }
       }
     }
     FireAccessibleFocusEvent(accessible, focusedItem, aEvent);
   }
   else if (eventType.EqualsLiteral("NameChange")) {
-    privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE,
-                              accessible, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, accessible);
   }
   else if (eventType.EqualsLiteral("AlertActive")) { 
-    privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_ALERT, 
-                              accessible, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_ALERT, accessible);
   }
   else if (eventType.EqualsLiteral("popupshown")) {
     // Don't fire menupopup events for combobox and autocomplete lists
     PRUint32 role = Role(accessible);
     PRInt32 event = 0;
     if (role == nsIAccessibleRole::ROLE_MENUPOPUP) {
       event = nsIAccessibleEvent::EVENT_MENUPOPUP_START;
     }
     else if (role == nsIAccessibleRole::ROLE_TOOLTIP) {
       // There is a single <xul:tooltip> node which Mozilla moves around.
       // The accessible for it stays the same no matter where it moves. 
       // AT's expect to get an EVENT_SHOW for the tooltip. 
       // In event callback the tooltip's accessible will be ready.
       event = nsIAccessibleEvent::EVENT_SHOW;
     }
     if (event) {
-      privAcc->FireToolkitEvent(event, accessible, nsnull);
+      nsAccUtils::FireAccEvent(event, accessible);
     }
   }
 
   else if (eventType.EqualsLiteral("popuphiding")) {
     // If accessible focus was on or inside popup that closes,
     // then restore it to true current focus.
     // This is the case when we've been getting DOMMenuItemActive events
     // inside of a combo box that closes. The real focus is on the combo box.
@@ -804,69 +789,56 @@ nsresult nsRootAccessible::HandleEventWi
         return NS_OK;  // And was not focused on an item inside the popup
       }
     }
     // Focus was on or inside of a popup that's being hidden
     FireCurrentFocusEvent();
   }
   else if (eventType.EqualsLiteral("DOMMenuInactive")) {
     if (Role(accessible) == nsIAccessibleRole::ROLE_MENUPOPUP) {
-      privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
-                                accessible, nsnull);
+      nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
+                               accessible);
     }
   }
   else if (eventType.EqualsLiteral("DOMMenuItemActive")) {
     if (!treeItemAccessible) {
-      nsCOMPtr<nsIAccessible> containerAccessible;
-      accessible->GetParent(getter_AddRefs(containerAccessible));
-      NS_ENSURE_TRUE(containerAccessible, NS_OK);
-      if (Role(containerAccessible) == nsIAccessibleRole::ROLE_MENUBAR) {
-        nsCOMPtr<nsPIAccessNode> menuBarAccessNode(do_QueryInterface(containerAccessible));
-        NS_ENSURE_TRUE(menuBarAccessNode, NS_ERROR_FAILURE);
-        nsCOMPtr<nsIMenuParent> menuParent = do_QueryInterface(menuBarAccessNode->GetFrame());
-        NS_ENSURE_TRUE(menuParent, NS_ERROR_FAILURE);
-        PRBool isActive;
-        menuParent->GetIsActive(isActive);
-        if (!isActive) {
+      nsCOMPtr<nsPIAccessNode> menuAccessNode = do_QueryInterface(accessible);
+      NS_ENSURE_TRUE(menuAccessNode, NS_ERROR_FAILURE);
+      nsIFrame* menuFrame = menuAccessNode->GetFrame();
+      NS_ENSURE_TRUE(menuFrame, NS_ERROR_FAILURE);
+      nsIMenuFrame* imenuFrame;
+      CallQueryInterface(menuFrame, &imenuFrame);
+      NS_ENSURE_TRUE(imenuFrame, NS_ERROR_FAILURE);
+      if (imenuFrame->IsOnMenuBar()) {
+        if (!imenuFrame->IsOnActiveMenuBar()) {
           // It is a top level menuitem. Only fire a focus event when the menu bar
           // is active.
           return NS_OK;
         }
       } else {
+        nsCOMPtr<nsIAccessible> containerAccessible;
+        accessible->GetParent(getter_AddRefs(containerAccessible));
+        NS_ENSURE_TRUE(containerAccessible, NS_ERROR_FAILURE);
         // It is not top level menuitem
         // Only fire focus event if it is not inside collapsed popup
         if (State(containerAccessible) & nsIAccessibleStates::STATE_COLLAPSED)
           return NS_OK;
       }
     }
     FireAccessibleFocusEvent(accessible, aTargetNode, aEvent, PR_TRUE);
   }
   else if (eventType.EqualsLiteral("DOMMenuBarActive")) {
-    privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENU_START,
-                              accessible, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENU_START, accessible);
   }
   else if (eventType.EqualsLiteral("DOMMenuBarInactive")) {
-    privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENU_END,
-                              accessible, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_MENU_END, accessible);
     FireCurrentFocusEvent();
   }
   else if (eventType.EqualsLiteral("ValueChange")) {
-    PRUint32 role;
-    accessible->GetFinalRole(&role);
-    if (role == nsIAccessibleRole::ROLE_PROGRESSBAR) {
-      // For progressmeter, fire EVENT_SHOW on 1st value change
-      nsAutoString value;
-      accessible->GetValue(value);
-      if (value.EqualsLiteral("0%")) {
-        privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SHOW, 
-                                  accessible, nsnull);
-      }
-    }
-    privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE, 
-                              accessible, nsnull);
+    nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE, accessible);
   }
   return NS_OK;
 }
 
 void nsRootAccessible::GetTargetNode(nsIDOMEvent *aEvent, nsIDOMNode **aTargetNode)
 {
   *aTargetNode = nsnull;
 
@@ -889,17 +861,17 @@ void nsRootAccessible::GetTargetNode(nsI
       return;
   }
 
   NS_ADDREF(*aTargetNode = eventTarget);
 }
 
 void nsRootAccessible::FireFocusCallback(nsITimer *aTimer, void *aClosure)
 {
-  nsRootAccessible *rootAccessible = NS_STATIC_CAST(nsRootAccessible*, aClosure);
+  nsRootAccessible *rootAccessible = static_cast<nsRootAccessible*>(aClosure);
   NS_ASSERTION(rootAccessible, "How did we get here without a root accessible?");
   rootAccessible->FireCurrentFocusEvent();
 }
 
 NS_IMETHODIMP
 nsRootAccessible::Init()
 {
   nsresult rv = nsDocAccessibleWrap::Init();
--- a/accessible/src/html/nsHTMLFormControlAccessible.cpp
+++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp
@@ -202,18 +202,17 @@ nsHTMLRadioButtonAccessible::GetAttribut
 
       count++;
 
       if (itemNode == mDOMNode)
         indexOf = count;
     }
   }
 
-  nsAccessibilityUtils::
-    SetAccGroupAttrs(aAttributes, 0, indexOf, count);
+  nsAccUtils::SetAccGroupAttrs(aAttributes, 0, indexOf, count);
 
   return  NS_OK;
 }
 
 // ----- Button -----
 
 nsHTMLButtonAccessible::nsHTMLButtonAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
 nsHyperTextAccessibleWrap(aNode, aShell)
@@ -567,94 +566,123 @@ void nsHTMLTextFieldAccessible::CheckFor
 
 // --- groupbox  -----
 
 /*
  * The HTML for this is <fieldset> <legend>box-title</legend> form elements </fieldset> 
  */
 
 nsHTMLGroupboxAccessible::nsHTMLGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
-nsAccessibleWrap(aNode, aShell)
+nsHyperTextAccessibleWrap(aNode, aShell)
 { 
 }
 
 NS_IMETHODIMP nsHTMLGroupboxAccessible::GetRole(PRUint32 *_retval)
 {
   *_retval = nsIAccessibleRole::ROLE_GROUPING;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsHTMLGroupboxAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
+nsIContent* nsHTMLGroupboxAccessible::GetLegend()
 {
-  // Groupbox doesn't support any states!
-  *aState = 0;
-  if (aExtraState)
-    *aExtraState = 0;
+  nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
+  NS_ENSURE_TRUE(content, nsnull);
 
-  return NS_OK;
+  nsresult count = 0;
+  nsIContent *testLegendContent;
+  while ((testLegendContent = content->GetChildAt(count ++ )) != nsnull) {
+    if (testLegendContent->NodeInfo()->Equals(nsAccessibilityAtoms::legend,
+                                              content->GetNameSpaceID())) {
+      // Either XHTML namespace or no namespace
+      return testLegendContent;
+    }
+  }
+
+  return nsnull;
 }
 
 NS_IMETHODIMP nsHTMLGroupboxAccessible::GetName(nsAString& aName)
 {
+  if (!mDOMNode) {
+    return NS_ERROR_FAILURE;
+  }
+  aName.Truncate();
   if (mRoleMapEntry) {
     nsAccessible::GetName(aName);
     if (!aName.IsEmpty()) {
       return NS_OK;
     }
   }
 
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
-  if (element) {
-    nsCOMPtr<nsIDOMNodeList> legends;
-    nsAutoString nameSpaceURI;
-    element->GetNamespaceURI(nameSpaceURI);
-    element->GetElementsByTagNameNS(nameSpaceURI, NS_LITERAL_STRING("legend"),
-                                  getter_AddRefs(legends));
-    if (legends) {
-      nsCOMPtr<nsIDOMNode> legendNode;
-      legends->Item(0, getter_AddRefs(legendNode));
-      nsCOMPtr<nsIContent> legendContent(do_QueryInterface(legendNode));
-      if (legendContent) {
-        aName.Truncate();  // Default name is blank 
-        return AppendFlatStringFromSubtree(legendContent, &aName);
-      }
+  nsIContent *legendContent = GetLegend();
+  if (legendContent) {
+    return AppendFlatStringFromSubtree(legendContent, &aName);
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHTMLGroupboxAccessible::GetAccessibleRelated(PRUint32 aRelationType,
+                                               nsIAccessible **aRelated)
+{
+  if (!mDOMNode) {
+    return NS_ERROR_FAILURE;
+  }
+  NS_ENSURE_ARG_POINTER(aRelated);
+
+  *aRelated = nsnull;
+
+  nsresult rv = nsHyperTextAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
+  if (NS_FAILED(rv) || *aRelated) {
+    // Either the node is shut down, or another relation mechanism has been used
+    return rv;
+  }
+
+  if (aRelationType == nsIAccessibleRelation::RELATION_LABELLED_BY) {
+    // No override for label, so use <legend> for this <fieldset>
+    nsCOMPtr<nsIDOMNode> legendNode = do_QueryInterface(GetLegend());
+    if (legendNode) {
+      GetAccService()->GetAccessibleInWeakShell(legendNode, mWeakShell, aRelated);
     }
   }
+
   return NS_OK;
 }
 
-void nsHTMLGroupboxAccessible::CacheChildren()
+nsHTMLLegendAccessible::nsHTMLLegendAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
+nsHyperTextAccessibleWrap(aNode, aShell)
+{ 
+}
+
+NS_IMETHODIMP
+nsHTMLLegendAccessible::GetAccessibleRelated(PRUint32 aRelationType,
+                                             nsIAccessible **aRelated)
 {
-  if (!mWeakShell) {
-    // This node has been shut down
-    mAccChildCount = eChildCountUninitialized;
-    return;
+  *aRelated = nsnull;
+
+  nsresult rv = nsHyperTextAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
+  if (NS_FAILED(rv) || *aRelated) {
+    // Either the node is shut down, or another relation mechanism has been used
+    return rv;
   }
 
-  if (mAccChildCount == eChildCountUninitialized) {
-    PRBool allowsAnonChildren = PR_FALSE;
-    GetAllowsAnonChildAccessibles(&allowsAnonChildren);
-    nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
-    walker.mState.frame = GetFrame();
-    PRInt32 childCount = 0;
-    walker.GetFirstChild();
-    // Check for <legend> and skip it if it's there
-    if (walker.mState.accessible && walker.mState.domNode) {
-      nsCOMPtr<nsIDOMNode> mightBeLegendNode;
-      walker.mState.domNode->GetParentNode(getter_AddRefs(mightBeLegendNode));
-      nsCOMPtr<nsIDOMHTMLLegendElement> legend(do_QueryInterface(mightBeLegendNode));
-      if (legend) {
-        walker.GetNextSibling();      // Skip the legend
+  if (aRelationType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
+    // Look for groupbox parent
+    nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
+    if (!content) {
+      return NS_ERROR_FAILURE;  // Node already shut down
+    }
+    nsCOMPtr<nsIAccessible> groupboxAccessible = GetParent();
+    if (groupboxAccessible &&
+        Role(groupboxAccessible) == nsIAccessibleRole::ROLE_GROUPING) {
+      nsCOMPtr<nsIAccessible> testLabelAccessible;
+      groupboxAccessible->GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABELLED_BY,
+                                               getter_AddRefs(testLabelAccessible));
+      if (testLabelAccessible == this) {
+        // We're the first child of the parent groupbox
+        NS_ADDREF(*aRelated = groupboxAccessible);
       }
     }
-    SetFirstChild(walker.mState.accessible);
-    nsCOMPtr<nsPIAccessible> privatePrevAccessible;
-    while (walker.mState.accessible) {
-      ++ childCount;
-      privatePrevAccessible = do_QueryInterface(walker.mState.accessible);
-      privatePrevAccessible->SetParent(this);
-      walker.GetNextSibling();
-      privatePrevAccessible->SetNextSibling(walker.mState.accessible);
-    }
-    mAccChildCount = childCount;
   }
+
+  return NS_OK;
 }
--- a/accessible/src/html/nsHTMLFormControlAccessible.h
+++ b/accessible/src/html/nsHTMLFormControlAccessible.h
@@ -119,19 +119,28 @@ public:
 protected:
   // Editor helpers, subclasses of nsHyperTextAccessible may have editor
   virtual void SetEditor(nsIEditor *aEditor);
   virtual already_AddRefed<nsIEditor> GetEditor() { nsIEditor *editor = mEditor; NS_IF_ADDREF(editor); return editor; }
   void CheckForEditor();
   nsCOMPtr<nsIEditor> mEditor;
 };
 
-class nsHTMLGroupboxAccessible : public nsAccessibleWrap
+class nsHTMLGroupboxAccessible : public nsHyperTextAccessibleWrap
 {
 public:
   nsHTMLGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
-  NS_IMETHOD GetRole(PRUint32 *_retval); 
-  NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
-  NS_IMETHOD GetName(nsAString& _retval);
-  void CacheChildren();
+  NS_IMETHOD GetRole(PRUint32 *aRole); 
+  NS_IMETHOD GetName(nsAString& aName);
+  NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated);
+protected:
+  nsIContent* GetLegend();
+};
+
+class nsHTMLLegendAccessible : public nsHyperTextAccessibleWrap
+{
+public:
+  nsHTMLLegendAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
+  NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated);
+  NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_LABEL; return NS_OK; }
 };
 
 #endif  
--- a/accessible/src/html/nsHTMLLinkAccessible.cpp
+++ b/accessible/src/html/nsHTMLLinkAccessible.cpp
@@ -38,17 +38,17 @@
 
 #include "nsHTMLLinkAccessible.h"
 #include "nsAccessibilityAtoms.h"
 #include "nsIAccessibleEvent.h"
 #include "nsINameSpaceManager.h"
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLLinkAccessible, nsLinkableAccessible)
 
-nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell, nsIFrame *aFrame):
+nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
 nsLinkableAccessible(aDomNode, aShell)
 { 
 }
 
 /* wstring getName (); */
 NS_IMETHODIMP nsHTMLLinkAccessible::GetName(nsAString& aName)
 { 
   if (!mActionContent)
--- a/accessible/src/html/nsHTMLLinkAccessible.h
+++ b/accessible/src/html/nsHTMLLinkAccessible.h
@@ -41,17 +41,17 @@
 
 #include "nsBaseWidgetAccessible.h"
 
 class nsHTMLLinkAccessible : public nsLinkableAccessible
 {
   NS_DECL_ISUPPORTS_INHERITED
 
 public:
-  nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell, nsIFrame *aFrame);
+  nsHTMLLinkAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
   
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& _retval); 
   NS_IMETHOD GetRole(PRUint32 *_retval); 
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
 };
 
 #endif  
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -127,17 +127,17 @@ void nsHTMLSelectableAccessible::iterato
     mOption->GetSelected(&isSelected);
     if (isSelected) {
       nsCOMPtr<nsIDOMNode> optionNode(do_QueryInterface(mOption));
       aAccService->GetAccessibleInWeakShell(optionNode, mWeakShell, getter_AddRefs(tempAccess));
     }
   }
 
   if (tempAccess)
-    aSelectedAccessibles->AppendElement(NS_STATIC_CAST(nsISupports*, tempAccess), PR_FALSE);
+    aSelectedAccessibles->AppendElement(static_cast<nsISupports*>(tempAccess), PR_FALSE);
 }
 
 PRBool nsHTMLSelectableAccessible::iterator::GetAccessibleIfSelected(PRInt32 aIndex, 
                                                                      nsIAccessibilityService *aAccService, 
                                                                      nsPresContext *aContext, 
                                                                      nsIAccessible **aAccessible)
 {
   PRBool isSelected = PR_FALSE;
@@ -559,18 +559,18 @@ nsHTMLSelectOptionAccessible::GetAttribu
     siblings->GetLength(&setSize);
     nsCOMPtr<nsIDOMNode> itemNode;
     while (NS_SUCCEEDED(siblings->Item(posInSet ++, getter_AddRefs(itemNode))) &&
            itemNode != mDOMNode) {
       // Keep looping, to increment posInSet
     }
   }
 
-  nsAccessibilityUtils::
-    SetAccGroupAttrs(aAttributes, level, posInSet, NS_STATIC_CAST(PRInt32, setSize));
+  nsAccUtils::SetAccGroupAttrs(aAttributes, level, posInSet,
+                               static_cast<PRInt32>(setSize));
   return  NS_OK;
 }
 
 nsIFrame* nsHTMLSelectOptionAccessible::GetBoundsFrame()
 {
   PRUint32 state;
   nsCOMPtr<nsIContent> content = GetSelectState(&state);
   if (state & nsIAccessibleStates::STATE_COLLAPSED) {
@@ -814,27 +814,29 @@ void nsHTMLSelectOptionAccessible::Selec
   nsCOMPtr<nsIAccessibilityService> accService = 
     do_GetService("@mozilla.org/accessibilityService;1");
   nsCOMPtr<nsIAccessible> optionAccessible;
   accService->GetAccessibleFor(optionNode, getter_AddRefs(optionAccessible));
   if (!optionAccessible) {
     return;
   }
 
-  privateMultiSelect->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
-                      multiSelect, nsnull);
+  nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
+                           multiSelect);
+
   PRUint32 state = State(optionAccessible);
   PRUint32 eventType;
   if (state & nsIAccessibleStates::STATE_SELECTED) {
     eventType = nsIAccessibleEvent::EVENT_SELECTION_ADD;
   }
   else {
     eventType = nsIAccessibleEvent::EVENT_SELECTION_REMOVE;
-  } 
-  privateMultiSelect->FireToolkitEvent(eventType, optionAccessible, nsnull);
+  }
+
+  nsAccUtils::FireAccEvent(eventType, optionAccessible);
 }
 
 nsIContent* nsHTMLSelectOptionAccessible::GetSelectState(PRUint32* aState,
                                                          PRUint32* aExtraState)
 {
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   while (content && content->Tag() != nsAccessibilityAtoms::select) {
     content = content->GetParent();
@@ -1163,17 +1165,17 @@ nsHTMLComboboxTextFieldAccessible::nsHTM
                                                                      nsIWeakReference* aShell):
 nsHTMLTextFieldAccessible(aDOMNode, aShell)
 {
 }
 
 NS_IMETHODIMP nsHTMLComboboxTextFieldAccessible::GetUniqueID(void **aUniqueID)
 {
   // Since mDOMNode is same as for our parent, use |this| pointer as the unique Id
-  *aUniqueID = NS_STATIC_CAST(void*, this);
+  *aUniqueID = static_cast<void*>(this);
   return NS_OK;
 }
 
 /**
   * Gets the bounds for the BlockFrame.
   *     Walks the Frame tree and checks for proper frames.
   */
 void nsHTMLComboboxTextFieldAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame)
@@ -1283,17 +1285,17 @@ NS_IMETHODIMP nsHTMLComboboxButtonAccess
     aName.AssignLiteral("open");
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLComboboxButtonAccessible::GetUniqueID(void **aUniqueID)
 {
   // Since mDOMNode is same for all tree item, use |this| pointer as the unique Id
-  *aUniqueID = NS_STATIC_CAST(void*, this);
+  *aUniqueID = static_cast<void*>(this);
   return NS_OK;
 }
 
 /**
   * Gets the bounds for the gfxButtonControlFrame.
   *     Walks the Frame tree and checks for proper frames.
   */
 void nsHTMLComboboxButtonAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame)
@@ -1415,17 +1417,17 @@ NS_IMETHODIMP nsHTMLComboboxListAccessib
 {
   NS_IF_ADDREF(*aParent = mParent);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLComboboxListAccessible::GetUniqueID(void **aUniqueID)
 {
   // Since mDOMNode is same for all tree item, use |this| pointer as the unique Id
-  *aUniqueID = NS_STATIC_CAST(void*, this);
+  *aUniqueID = static_cast<void*>(this);
   return NS_OK;
 }
 
 /**
   * Gets the bounds for the areaFrame.
   *     Walks the Frame tree and checks for proper frames.
   */
 void nsHTMLComboboxListAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame)
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -44,17 +44,16 @@
 #include "nsIDOMDocumentRange.h"
 #include "nsIDOMRange.h"
 #include "nsISelection2.h"
 #include "nsISelectionPrivate.h"
 #include "nsINameSpaceManager.h"
 #include "nsIAccessibilityService.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsIDOMHTMLCollection.h"
-#include "nsIDOMHTMLTableCaptionElem.h"
 #include "nsIDOMHTMLTableCellElement.h"
 #include "nsIDOMHTMLTableElement.h"
 #include "nsIDOMHTMLTableRowElement.h"
 #include "nsIDOMHTMLTableSectionElem.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsIServiceManager.h"
 #include "nsITableLayout.h"
@@ -87,71 +86,56 @@ nsHTMLTableCellAccessible::GetState(PRUi
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableAccessible, nsAccessible, nsIAccessibleTable)
 
 nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
 nsAccessibleWrap(aDomNode, aShell)
 { 
-  mHasCaption = PR_FALSE;
 }
 
 void nsHTMLTableAccessible::CacheChildren()
 {
   if (!mWeakShell) {
     // This node has been shut down
     mAccChildCount = eChildCountUninitialized;
     return;
   }
-
+  
   if (mAccChildCount == eChildCountUninitialized) {
-    PRInt32 childCount = 0;
-    nsCOMPtr<nsPIAccessible> privatePrevAccessible;
+    nsAccessible::CacheChildren();
     nsCOMPtr<nsIAccessible> captionAccessible;
-    GetCaption(getter_AddRefs(captionAccessible));
-    if (captionAccessible) {
-      mHasCaption = PR_TRUE;
-      SetFirstChild(captionAccessible);
-      ++ childCount;
-      privatePrevAccessible = do_QueryInterface(captionAccessible);
-      privatePrevAccessible->SetParent(this);
-    }
-    else {
-      mHasCaption = PR_FALSE;
+    while (NextChild(captionAccessible)) {
+      if (Role(captionAccessible) == nsIAccessibleRole::ROLE_CAPTION) {
+        nsCOMPtr<nsIAccessible> captionParentAccessible;
+        captionAccessible->GetParent(getter_AddRefs(captionParentAccessible));
+        if (captionParentAccessible != this) {
+          NS_WARNING("Should not happen: parser ensures caption is the table's child, not the tbody's");
+          return;
+        }
+        nsCOMPtr<nsIAccessible> beforeCaptionAccessible;
+        captionAccessible->GetPreviousSibling(getter_AddRefs(beforeCaptionAccessible));
+        if (beforeCaptionAccessible) {
+          // Move caption accessible so that it's the first child
+          nsCOMPtr<nsIAccessible> afterCaptionAccessible;
+          captionAccessible->GetNextSibling(getter_AddRefs(afterCaptionAccessible));
+          nsCOMPtr<nsPIAccessible> privateAcc = do_QueryInterface(beforeCaptionAccessible);
+          privateAcc->SetNextSibling(afterCaptionAccessible);
+          GetFirstChild(getter_AddRefs(afterCaptionAccessible));
+          SetFirstChild(captionAccessible);
+          privateAcc = do_QueryInterface(captionAccessible);
+          privateAcc->SetNextSibling(afterCaptionAccessible);        
+        }
+        // Don't check for more captions, because nsAccessibilityService ensures
+        // we don't create accessibles for the other captions, since only the
+        // first is actually visible
+        break;
+      }
     }
-
-    PRBool allowsAnonChildren = PR_FALSE;
-    GetAllowsAnonChildAccessibles(&allowsAnonChildren);
-    nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
-    walker.mState.frame = GetFrame();
-
-    walker.GetFirstChild();
-    while (walker.mState.accessible) {
-      nsCOMPtr<nsIContent> content(do_QueryInterface(walker.mState.domNode));
-      NS_ASSERTION(content, "Creating accessible for node in HTMLTable with no content");
-      if (content && content->IsNodeOfType(nsINode::eHTML) &&
-          content->Tag() == nsAccessibilityAtoms::caption) {
-        // We have already dealt with caption, ignore this one
-        walker.GetNextSibling();
-        continue;
-      }
-
-      ++ childCount;
-      if (privatePrevAccessible) {
-        privatePrevAccessible->SetNextSibling(walker.mState.accessible);
-      }
-      else {
-        SetFirstChild(walker.mState.accessible);
-      }
-      privatePrevAccessible = do_QueryInterface(walker.mState.accessible);
-      privatePrevAccessible->SetParent(this);
-      walker.GetNextSibling();
-    }
-    mAccChildCount = childCount;
   }
 }
 
 /* unsigned long getRole (); */
 NS_IMETHODIMP nsHTMLTableAccessible::GetRole(PRUint32 *aResult)
 {
   *aResult = nsIAccessibleRole::ROLE_TABLE;
   return NS_OK;
@@ -168,44 +152,24 @@ nsHTMLTableAccessible::GetState(PRUint32
   *aState &= ~nsIAccessibleStates::STATE_FOCUSABLE;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLTableAccessible::GetName(nsAString& aName)
 {
   aName.Truncate();  // Default name is blank
 
-  if (mRoleMapEntry) {
-    nsAccessible::GetName(aName);
-    if (!aName.IsEmpty()) {
-      return NS_OK;
+  nsAccessible::GetName(aName);
+  if (aName.IsEmpty()) {
+    nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
+    if (content) { 
+      content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::summary, aName);
     }
   }
 
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
-  if (element) {
-    nsCOMPtr<nsIDOMNodeList> captions;
-    nsAutoString nameSpaceURI;
-    element->GetNamespaceURI(nameSpaceURI);
-    element->GetElementsByTagNameNS(nameSpaceURI, NS_LITERAL_STRING("caption"), 
-                                    getter_AddRefs(captions));
-    if (captions) {
-      nsCOMPtr<nsIDOMNode> captionNode;
-      captions->Item(0, getter_AddRefs(captionNode));
-      if (captionNode) {
-        nsCOMPtr<nsIContent> captionContent(do_QueryInterface(captionNode));
-        AppendFlatStringFromSubtree(captionContent, &aName);
-      }
-    }
-    if (aName.IsEmpty()) {
-      nsCOMPtr<nsIContent> content(do_QueryInterface(element));
-      NS_ASSERTION(content, "No content for DOM element");
-      content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::summary, aName);
-    }
-  }
   return NS_OK;
 }
 
 nsresult
 nsHTMLTableAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;  // Node already shut down
@@ -221,96 +185,61 @@ nsHTMLTableAccessible::GetAttributesInte
     aAttributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
                                    NS_LITERAL_STRING("true"), oldValueUnused);
   }
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsHTMLTableAccessible::GetCaption(nsIAccessible **aCaption)
+nsHTMLTableAccessible::GetAccessibleRelated(PRUint32 aRelationType,
+                                            nsIAccessible **aRelated)
 {
-  *aCaption = nsnull;
-  nsresult rv = NS_OK;
-
-  nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
-  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
+  NS_ENSURE_ARG_POINTER(aRelated);
+  *aRelated = nsnull;
 
-  nsCOMPtr<nsIDOMHTMLTableCaptionElement> caption;
-  rv = table->GetCaption(getter_AddRefs(caption));
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (!mDOMNode) {
+    return NS_ERROR_FAILURE;
+  }
 
-  nsCOMPtr<nsIDOMNode> captionNode(do_QueryInterface(caption));
-  if (!captionNode) {
-    return NS_OK;
+  nsresult rv = nsAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
+  if (NS_FAILED(rv) || *aRelated) {
+    // Either the node is shut down, or another relation mechanism has been used
+    return rv;
   }
 
-  nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
-  NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
-
-  accService->GetCachedAccessible(captionNode, mWeakShell, aCaption);
-  if (*aCaption)
-    return NS_OK;
+  if (aRelationType == nsIAccessibleRelation::RELATION_DESCRIBED_BY) {
+    return GetCaption(aRelated);
+  }
 
-  nsCOMPtr<nsIPresShell> presShell(GetPresShell());
-  nsCOMPtr<nsIContent> content(do_QueryInterface(captionNode));
-  NS_ENSURE_TRUE(presShell && content, NS_ERROR_FAILURE);
-  nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
-  if (!frame) {
-    return NS_OK;
-  }
-  accService->CreateHyperTextAccessible(frame, aCaption);
-  nsCOMPtr<nsPIAccessNode> accessNode(do_QueryInterface(*aCaption));
-  return accessNode ? accessNode->Init() : NS_ERROR_FAILURE;
+  return NS_OK;
 }
 
+
 NS_IMETHODIMP
-nsHTMLTableAccessible::SetCaption(nsIAccessible *aCaption)
+nsHTMLTableAccessible::GetCaption(nsIAccessible **aCaption)
 {
-  nsresult rv = NS_OK;
-
-  nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
-  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(aCaption));
-  NS_ASSERTION(accessNode, "Unable to QI to nsIAccessNode");
-  nsCOMPtr<nsIDOMNode> domNode;
-  rv = accessNode->GetDOMNode(getter_AddRefs(domNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMNode> newDOMNode;
-  rv = domNode->CloneNode(PR_TRUE, getter_AddRefs(newDOMNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMHTMLTableCaptionElement>
-    captionElement(do_QueryInterface(newDOMNode));
-  NS_ENSURE_TRUE(captionElement, NS_ERROR_FAILURE);
-
-  return table->SetCaption(captionElement);
+  nsCOMPtr<nsIAccessible> firstChild;
+  GetFirstChild(getter_AddRefs(firstChild));
+  if (firstChild && Role(firstChild) == nsIAccessibleRole::ROLE_CAPTION) {
+    NS_ADDREF(*aCaption = firstChild);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLTableAccessible::GetSummary(nsAString &aSummary)
 {
   nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
   NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
 
   return table->GetSummary(aSummary);
 }
 
 NS_IMETHODIMP
-nsHTMLTableAccessible::SetSummary(const nsAString &aSummary)
-{
-  nsCOMPtr<nsIDOMHTMLTableElement> table(do_QueryInterface(mDOMNode));
-  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
-
-  return table->SetSummary(aSummary);
-}
-
-NS_IMETHODIMP
 nsHTMLTableAccessible::GetColumns(PRInt32 *aColumns)
 {
   nsITableLayout *tableLayout;
   nsresult rv = GetTableLayout(&tableLayout);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRInt32 rows;
   return tableLayout->GetTableSize(rows, *aColumns);
@@ -815,30 +744,49 @@ nsHTMLTableAccessible::GetCellAt(PRInt32
 
   return tableLayout->GetCellDataAt(aRowIndex, aColIndex, aCell,
                                     startRowIndex, startColIndex,
                                     rowSpan, colSpan,
                                     actualRowSpan, actualColSpan,
                                     isSelected);
 }
 
-#ifdef SHOW_LAYOUT_HEURISTIC
 NS_IMETHODIMP nsHTMLTableAccessible::GetDescription(nsAString& aDescription)
 {
   // Helpful for debugging layout vs. data tables
   aDescription.Truncate();
-  PRBool isProbablyForLayout;
-  IsProbablyForLayout(&isProbablyForLayout);
-  aDescription = mLayoutHeuristic;
+  nsAccessible::GetDescription(aDescription);
+  if (!aDescription.IsEmpty()) {
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsIAccessible> captionAccessible;
+  GetCaption(getter_AddRefs(captionAccessible));
+  nsCOMPtr<nsIAccessNode> captionAccessNode = do_QueryInterface(captionAccessible);
+  if (captionAccessNode) {
+    nsCOMPtr<nsIDOMNode> captionNode;
+    captionAccessNode->GetDOMNode(getter_AddRefs(captionNode));
+    nsCOMPtr<nsIContent> captionContent = do_QueryInterface(captionNode);
+    if (captionContent) {
+      AppendFlatStringFromSubtree(captionContent, &aDescription);
+    }
+  }
+#ifdef SHOW_LAYOUT_HEURISTIC
+  if (aDescription.IsEmpty()) {
+    PRBool isProbablyForLayout;
+    IsProbablyForLayout(&isProbablyForLayout);
+    aDescription = mLayoutHeuristic;
+  }
 #ifdef DEBUG_A11Y
   printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get());
 #endif
+#endif
+
   return NS_OK;
 }
-#endif
 
 PRBool nsHTMLTableAccessible::HasDescendant(char *aTagName, PRBool aAllowEmpty)
 {
   nsCOMPtr<nsIDOMElement> tableElt(do_QueryInterface(mDOMNode));
   NS_ENSURE_TRUE(tableElt, PR_FALSE);
 
   nsCOMPtr<nsIDOMNodeList> nodeList;
   nsAutoString tagName;
@@ -1055,34 +1003,22 @@ nsHTMLTableHeadAccessible::GetRole(PRUin
 
 NS_IMETHODIMP
 nsHTMLTableHeadAccessible::GetCaption(nsIAccessible **aCaption)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsHTMLTableHeadAccessible::SetCaption(nsIAccessible *aCaption)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
 nsHTMLTableHeadAccessible::GetSummary(nsAString &aSummary)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsHTMLTableHeadAccessible::SetSummary(const nsAString &aSummary)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
 nsHTMLTableHeadAccessible::GetColumnHeader(nsIAccessibleTable **aColumnHeader)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsHTMLTableHeadAccessible::GetRows(PRInt32 *aRows)
 {
@@ -1093,8 +1029,34 @@ nsHTMLTableHeadAccessible::GetRows(PRInt
 
   nsCOMPtr<nsIDOMHTMLCollection> rows;
   rv = head->GetRows(getter_AddRefs(rows));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return rows->GetLength((PRUint32 *)aRows);
 }
 
+NS_IMETHODIMP
+nsHTMLCaptionAccessible::GetAccessibleRelated(PRUint32 aRelationType,
+                                              nsIAccessible **aRelated)
+{
+  NS_ENSURE_ARG_POINTER(aRelated);
+  *aRelated = nsnull;
+
+  if (!mDOMNode) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsresult rv = nsHyperTextAccessible::GetAccessibleRelated(aRelationType, aRelated);
+  if (NS_FAILED(rv) || *aRelated) {
+    // Either the node is shut down, or another relation mechanism has been used
+    return rv;
+  }
+
+  if (aRelationType == nsIAccessibleRelation::RELATION_DESCRIPTION_FOR) {
+    return GetParent(aRelated);
+  }
+
+  return NS_OK;
+}
+
+
+
--- a/accessible/src/html/nsHTMLTableAccessible.h
+++ b/accessible/src/html/nsHTMLTableAccessible.h
@@ -66,19 +66,18 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLETABLE
 
   nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
   NS_IMETHOD GetRole(PRUint32 *aResult); 
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetName(nsAString& aResult);
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
-#ifdef SHOW_LAYOUT_HEURISTIC
   NS_IMETHOD GetDescription(nsAString& aDescription);
-#endif
+  NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated);
 
 protected:
 
   /**
    * Selects or unselects row or column.
    *
    * @param aIndex - index of row or column to be selected
    * @param aTarget - indicates what should be selected, either row or column
@@ -101,17 +100,16 @@ protected:
 
   virtual void CacheChildren();
   nsresult GetTableNode(nsIDOMNode **_retval);
   nsresult GetTableLayout(nsITableLayout **aLayoutObject);
   nsresult GetCellAt(PRInt32        aRowIndex,
                      PRInt32        aColIndex,
                      nsIDOMElement* &aCell);
   PRBool HasDescendant(char *aTagName, PRBool aAllowEmpty = PR_TRUE);
-  PRBool mHasCaption;
 #ifdef SHOW_LAYOUT_HEURISTIC
   nsAutoString mLayoutHeuristic;
 #endif
 };
 
 class nsHTMLTableHeadAccessible : public nsHTMLTableAccessible
 {
 public:
@@ -119,16 +117,26 @@ public:
 
   nsHTMLTableHeadAccessible(nsIDOMNode *aDomNode, nsIWeakReference *aShell);
 
   /* nsIAccessible */
   NS_IMETHOD GetRole(PRUint32 *aResult);
 
   /* nsIAccessibleTable */
   NS_IMETHOD GetCaption(nsIAccessible **aCaption);
-  NS_IMETHOD SetCaption(nsIAccessible *aCaption);
   NS_IMETHOD GetSummary(nsAString &aSummary);
-  NS_IMETHOD SetSummary(const nsAString &aSummary);
   NS_IMETHOD GetColumnHeader(nsIAccessibleTable **aColumnHeader);
   NS_IMETHOD GetRows(PRInt32 *aRows);
 };
 
+class nsHTMLCaptionAccessible : public nsHyperTextAccessibleWrap
+{
+public:
+  nsHTMLCaptionAccessible(nsIDOMNode *aDomNode, nsIWeakReference *aShell) :
+    nsHyperTextAccessibleWrap(aDomNode, aShell) { }
+
+  // nsIAccessible
+  NS_IMETHOD GetRole(PRUint32 *aRole)
+    { *aRole = nsIAccessibleRole::ROLE_CAPTION; return NS_OK; }
+  NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated);
+};
+
 #endif  
--- a/accessible/src/html/nsHTMLTextAccessible.cpp
+++ b/accessible/src/html/nsHTMLTextAccessible.cpp
@@ -34,27 +34,26 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsHTMLTextAccessible.h"
 #include "nsAccessibleTreeWalker.h"
-#include "nsBulletFrame.h"
 #include "nsIAccessibleDocument.h"
 #include "nsIAccessibleEvent.h"
 #include "nsIFrame.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsISelection.h"
 #include "nsISelectionController.h"
 #include "nsComponentManagerUtils.h"
 
-nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell, nsIFrame *aFrame):
+nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
 nsTextAccessibleWrap(aDomNode, aShell)
 { 
 }
 
 NS_IMETHODIMP nsHTMLTextAccessible::GetName(nsAString& aName)
 {
   aName.Truncate();
   if (!mDOMNode) {
@@ -163,17 +162,17 @@ NS_IMETHODIMP
 nsHTMLBRAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
 {
   *aState = nsIAccessibleStates::STATE_READONLY;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLBRAccessible::GetName(nsAString& aName)
 {
-  aName = NS_STATIC_CAST(PRUnichar, '\n');    // Newline char
+  aName = static_cast<PRUnichar>('\n');    // Newline char
   return NS_OK;
 }
 
 nsHTMLLabelAccessible::nsHTMLLabelAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):
 nsTextAccessible(aDomNode, aShell)
 { 
 }
 
@@ -228,22 +227,22 @@ NS_IMETHODIMP nsHTMLLabelAccessible::Get
 /* readonly attribute long accChildCount; */
 NS_IMETHODIMP nsHTMLLabelAccessible::GetChildCount(PRInt32 *aAccChildCount) 
 {
   // A <label> is not necessarily a leaf!
   return nsAccessible::GetChildCount(aAccChildCount);
 }
 
 nsHTMLLIAccessible::nsHTMLLIAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell, 
-                   nsIFrame *aBulletFrame, const nsAString& aBulletText):
+                                       const nsAString& aBulletText):
   nsLinkableAccessible(aDOMNode, aShell)
 {
   if (!aBulletText.IsEmpty()) {
     mBulletAccessible = new nsHTMLListBulletAccessible(mDOMNode, mWeakShell, 
-                                                       aBulletFrame, aBulletText);
+                                                       aBulletText);
     nsCOMPtr<nsPIAccessNode> bulletANode(mBulletAccessible);
     if (bulletANode) {
       bulletANode->Init();
     }
   }
 }
 
 NS_IMETHODIMP nsHTMLLIAccessible::Shutdown()
@@ -252,16 +251,26 @@ NS_IMETHODIMP nsHTMLLIAccessible::Shutdo
     // Ensure that weak pointer to this is nulled out
     mBulletAccessible->Shutdown();
   }
   nsresult rv = nsLinkableAccessible::Shutdown();
   mBulletAccessible = nsnull;
   return rv;
 }
 
+NS_IMETHODIMP
+nsHTMLLIAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
+{
+  nsresult rv = nsAccessibleWrap::GetState(aState, aExtraState);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  *aState |= nsIAccessibleStates::STATE_READONLY;
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsHTMLLIAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
 {
   nsresult rv = nsAccessibleWrap::GetBounds(x, y, width, height);
   if (NS_FAILED(rv) || !mBulletAccessible) {
     return rv;
   }
 
   PRInt32 bulletX, bulletY, bulletWidth, bulletHeight;
@@ -288,28 +297,28 @@ void nsHTMLLIAccessible::CacheChildren()
     ++ mAccChildCount;
   }
 }
 
 
 // nsHTMLListBulletAccessible
 nsHTMLListBulletAccessible::
   nsHTMLListBulletAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell,
-                             nsIFrame *aFrame, const nsAString& aBulletText) :
+                             const nsAString& aBulletText) :
     nsLeafAccessible(aDomNode, aShell), mWeakParent(nsnull),
     mBulletText(aBulletText)
 {
   mBulletText += ' '; // Otherwise bullets are jammed up against list text
 }
 
 NS_IMETHODIMP
 nsHTMLListBulletAccessible::GetUniqueID(void **aUniqueID)
 {
   // Since mDOMNode is same as for list item, use |this| pointer as the unique Id
-  *aUniqueID = NS_STATIC_CAST(void*, this);
+  *aUniqueID = static_cast<void*>(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLListBulletAccessible::Shutdown()
 {
   mBulletText.Truncate();
   mWeakParent = nsnull;
@@ -371,20 +380,8 @@ nsHTMLListAccessible::GetState(PRUint32 
 {
   nsresult rv = nsHyperTextAccessibleWrap::GetState(aState, aExtraState);
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aState |= nsIAccessibleStates::STATE_READONLY;
   return NS_OK;
 }
 
-// nsHTMLLIAccessible
-
-NS_IMETHODIMP
-nsHTMLLIAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
-{
-  nsresult rv = nsAccessibleWrap::GetState(aState, aExtraState);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aState |= nsIAccessibleStates::STATE_READONLY;
-  return NS_OK;
-}
-
--- a/accessible/src/html/nsHTMLTextAccessible.h
+++ b/accessible/src/html/nsHTMLTextAccessible.h
@@ -44,17 +44,17 @@
 #include "nsAutoPtr.h"
 #include "nsBaseWidgetAccessible.h"
 
 class nsIWeakReference;
 
 class nsHTMLTextAccessible : public nsTextAccessibleWrap
 {
 public:
-  nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell, nsIFrame *aFrame);
+  nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
   
   // nsIAccessible
   NS_IMETHOD GetName(nsAString& _retval);
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetRole(PRUint32 *aRole);
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 };
 
@@ -86,17 +86,17 @@ public:
   NS_IMETHOD GetLastChild(nsIAccessible **aLastChild);
   NS_IMETHOD GetChildCount(PRInt32 *aAccChildCount);
 };
 
 class nsHTMLListBulletAccessible : public nsLeafAccessible
 {
 public:
   nsHTMLListBulletAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell,
-                             nsIFrame *aFrame, const nsAString& aBulletText);
+                             const nsAString& aBulletText);
 
   // nsIAccessNode
   NS_IMETHOD GetUniqueID(void **aUniqueID);
 
   // nsPIAccessNode
   NS_IMETHOD Shutdown();
 
   // nsIAccessible
@@ -132,17 +132,17 @@ public:
   NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_LIST; return NS_OK; }
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
 };
 
 class nsHTMLLIAccessible : public nsLinkableAccessible
 {
 public:
   nsHTMLLIAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell, 
-                     nsIFrame *aBulletFrame, const nsAString& aBulletText);
+                     const nsAString& aBulletText);
   NS_IMETHOD Shutdown();
   NS_IMETHOD GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_LISTITEM; return NS_OK; }
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetName(nsAString& aName) { aName.SetIsVoid(PR_TRUE); return mRoleMapEntry ? nsAccessible::GetName(aName) : NS_OK; }
   NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
   void CacheChildren();  // Include bullet accessible
 protected:
   nsRefPtr<nsHTMLListBulletAccessible> mBulletAccessible;
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -76,39 +76,39 @@ nsresult nsHyperTextAccessible::QueryInt
     // in order for HTML document accessibles to get support for these interfaces
     // However at some point we may push <body> to implement the interfaces and
     // return nsDocAccessible to inherit from nsAccessibleWrap
     if (aIID.Equals(NS_GET_IID(nsIAccessibleText))) {
       // If |this| contains any children
       PRInt32 numChildren;
       GetChildCount(&numChildren);
       if (numChildren > 0) {
-        *aInstancePtr = NS_STATIC_CAST(nsIAccessibleText*, this);
+        *aInstancePtr = static_cast<nsIAccessibleText*>(this);
         NS_ADDREF_THIS();
         return NS_OK;
       }
       return NS_ERROR_NO_INTERFACE;
     }
 
     if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperText))) {
       if (IsHyperText()) {
         // If |this| contains text and embedded objects
-        *aInstancePtr = NS_STATIC_CAST(nsIAccessibleHyperText*, this);
+        *aInstancePtr = static_cast<nsIAccessibleHyperText*>(this);
         NS_ADDREF_THIS();
         return NS_OK;
       }
       return NS_ERROR_NO_INTERFACE;
     }
 
     if (aIID.Equals(NS_GET_IID(nsIAccessibleEditableText))) {
       // If this contains editable text
       PRUint32 state, extState;
       GetState(&state, &extState);
       if (extState & nsIAccessibleStates::EXT_STATE_EDITABLE) {
-        *aInstancePtr = NS_STATIC_CAST(nsIAccessibleEditableText*, this);
+        *aInstancePtr = static_cast<nsIAccessibleEditableText*>(this);
         NS_ADDREF_THIS();
         return NS_OK;
       }
       return NS_ERROR_NO_INTERFACE;
     }
   }
 
   return nsAccessible::QueryInterface(aIID, aInstancePtr);
@@ -135,20 +135,17 @@ NS_IMETHODIMP nsHyperTextAccessible::Get
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
   if (!content) {
     return NS_ERROR_FAILURE;
   }
 
   nsIAtom *tag = content->Tag();
 
-  if (tag == nsAccessibilityAtoms::caption) {
-    *aRole = nsIAccessibleRole::ROLE_CAPTION;
-  }
-  else if (tag == nsAccessibilityAtoms::form) {
+  if (tag == nsAccessibilityAtoms::form) {
     *aRole = nsIAccessibleRole::ROLE_FORM;
   }
   else if (tag == nsAccessibilityAtoms::div ||
            tag == nsAccessibilityAtoms::blockquote) {
     *aRole = nsIAccessibleRole::ROLE_SECTION;
   }
   else if (tag == nsAccessibilityAtoms::h1 ||
            tag == nsAccessibilityAtoms::h2 ||
@@ -846,19 +843,18 @@ nsHyperTextAccessible::GetAttributesInte
   else if (tag == nsAccessibilityAtoms::h5)
     headLevel = 5;
   else if (tag == nsAccessibilityAtoms::h6)
     headLevel = 6;
 
   if (headLevel) {
     nsAutoString strHeadLevel;
     strHeadLevel.AppendInt(headLevel);
-    nsAccessibilityUtils::SetAccAttr(aAttributes,
-                                     nsAccessibilityAtoms::level,
-                                     strHeadLevel);
+    nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::level,
+                           strHeadLevel);
   }
 
   return  NS_OK;
 }
 
 /*
  * Given an offset, the x, y, width, and height values are filled appropriately.
  */
@@ -1133,16 +1129,27 @@ NS_IMETHODIMP nsHyperTextAccessible::Pas
 {
   nsCOMPtr<nsIEditor> editor = GetEditor();
   if (editor && NS_SUCCEEDED(SetCaretOffset(aPosition)))
     return editor->Paste(nsIClipboard::kGlobalClipboard);
 
   return NS_ERROR_FAILURE;
 }
 
+NS_IMETHODIMP
+nsHyperTextAccessible::GetEditor(nsIEditor **aEditor)
+{
+  NS_ENSURE_ARG_POINTER(aEditor);
+
+  nsCOMPtr<nsIEditor> editor(GetEditor());
+  NS_IF_ADDREF(*aEditor = editor);
+
+  return NS_OK;
+}
+
 /**
   * nsIEditActionListener impl.
   */
 NS_IMETHODIMP nsHyperTextAccessible::WillCreateNode(const nsAString& aTag,
                                                     nsIDOMNode *aParent, PRInt32 aPosition)
 {
   return NS_OK;
 }
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -323,17 +323,17 @@ GetNativeFromGeckoAccessible(nsIAccessib
   }
   
   // GetUnignoredParent() returns null when there is no unignored accessible all the way up to
   // the root accessible. so we'll have to return whatever native accessible is above our root accessible 
   // (which might be the owning NSWindow in the application, for example).
   //
   // get the native root accessible, and tell it to return its first parent unignored accessible.
   nsRefPtr<nsRootAccessible> root(mGeckoAccessible->GetRootAccessible());
-  id nativeParent = GetNativeFromGeckoAccessible(NS_STATIC_CAST(nsIAccessible*, root));
+  id nativeParent = GetNativeFromGeckoAccessible(static_cast<nsIAccessible*>(root));
   NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);
   
   return GetClosestInterestingAccessible(nativeParent);
 }
 
 - (BOOL)hasRepresentedView
 {
   return NO;
@@ -505,17 +505,17 @@ GetNativeFromGeckoAccessible(nsIAccessib
 #endif
   NSAssert1(![self accessibilityIsIgnored], @"trying to set focus to ignored element! (%@)", self);
   NSAccessibilityPostNotification(GetObjectOrRepresentedView(self),
                                   NSAccessibilityFocusedUIElementChangedNotification);
 }
 
 - (NSWindow*)window
 {
-  nsAccessibleWrap *accWrap = NS_STATIC_CAST (nsAccessibleWrap*, mGeckoAccessible);
+  nsAccessibleWrap *accWrap = static_cast<nsAccessibleWrap*>(mGeckoAccessible);
   NSWindow *nativeWindow = nil;
   accWrap->GetNativeWindow ((void**)&nativeWindow);
   
   NSAssert1(nativeWindow, @"Could not get native window for %@", self);
   return nativeWindow;
 }
 
 - (void)invalidateChildren
--- a/accessible/src/mac/mozDocAccessible.mm
+++ b/accessible/src/mac/mozDocAccessible.mm
@@ -39,17 +39,17 @@
 #include "nsRootAccessibleWrap.h"
 
 #import "mozDocAccessible.h"
 
 #import "mozView.h"
 
 static id <mozAccessible, mozView> getNativeViewFromRootAccessible (nsAccessible *accessible)
 {
-  nsRootAccessibleWrap *root = NS_STATIC_CAST (nsRootAccessibleWrap*, accessible);
+  nsRootAccessibleWrap *root = static_cast<nsRootAccessibleWrap*>(accessible);
   id <mozAccessible, mozView> nativeView = nil;
   root->GetNativeWidget ((void**)&nativeView);
   return nativeView;
 }
 
 #pragma mark -
 
 @implementation mozRootAccessible
--- a/accessible/src/mac/nsAccessibleWrap.h
+++ b/accessible/src/mac/nsAccessibleWrap.h
@@ -71,17 +71,19 @@ class nsAccessibleWrap : public nsAccess
     // right type for this accessible's associated native object.
     virtual objc_class* GetNativeType ();
     
     // returns a pointer to the native window for this accessible tree.
     void GetNativeWindow (void **aOutNativeWindow);
     
     virtual nsresult Shutdown ();
     virtual nsresult InvalidateChildren ();
-    
+
+    NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
+
     // we'll flatten buttons and checkboxes. usually they have a text node
     // child, that is their title. Works in conjunction with IsPruned() below.
     PRBool IsFlat() {
       PRUint32 role = Role(this);
       return (role == nsIAccessibleRole::ROLE_CHECKBUTTON ||
               role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
               role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
               role == nsIAccessibleRole::ROLE_SPLITBUTTON ||
@@ -110,20 +112,20 @@ class nsAccessibleWrap : public nsAccess
       // we don't create a native object if we're child of a "flat" accessible; for example, on OS X buttons 
       // shouldn't have any children, because that makes the OS confused. 
       //
       // to maintain a scripting environment where the XPCOM accessible hierarchy look the same 
       // on all platforms, we still let the C++ objects be created though.
       
       nsCOMPtr<nsIAccessible> curParent = GetParent();
       while (curParent) {
-        nsAccessibleWrap *ancestorWrap = NS_STATIC_CAST(nsAccessibleWrap*, (nsIAccessible*)curParent.get());
+        nsAccessibleWrap *ancestorWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)curParent.get());
         if (ancestorWrap->IsFlat())
           return PR_TRUE;
-        curParent = NS_STATIC_CAST(nsAccessibleWrap*, (nsIAccessible*)curParent.get())->GetParent();
+        curParent = static_cast<nsAccessibleWrap*>((nsIAccessible*)curParent.get())->GetParent();
       }
       // no parent was flat
       return PR_FALSE;
     }
 
     // Wrapper around our native object.
     AccessibleWrapper *mNativeWrapper;
 };
--- a/accessible/src/mac/nsAccessibleWrap.mm
+++ b/accessible/src/mac/nsAccessibleWrap.mm
@@ -149,16 +149,53 @@ nsAccessibleWrap::Shutdown ()
   if (mNativeWrapper) {
     delete mNativeWrapper;
     mNativeWrapper = nsnull;
   }
   
   return nsAccessible::Shutdown();
 }
 
+nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
+{
+  NS_ENSURE_ARG_POINTER(aEvent);
+
+  nsresult rv = nsAccessible::FireAccessibleEvent(aEvent);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRUint32 eventType;
+  rv = aEvent->GetEventType(&eventType);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // ignore everything but focus-changed and value-changed events for now.
+  if (eventType != nsIAccessibleEvent::EVENT_FOCUS &&
+      eventType != nsIAccessibleEvent::EVENT_VALUE_CHANGE)
+    return NS_OK;
+
+  nsCOMPtr<nsIAccessible> accessible;
+  rv = aEvent->GetAccessible(getter_AddRefs(accessible));
+  NS_ENSURE_STATE(accessible);
+
+  mozAccessible *nativeAcc = nil;
+  accessible->GetNativeInterface((void**)&nativeAcc);
+  if (!nativeAcc)
+    return NS_ERROR_FAILURE;
+
+  switch (eventType) {
+    case nsIAccessibleEvent::EVENT_FOCUS:
+      [nativeAcc didReceiveFocus];
+      break;
+    case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
+      [nativeAcc valueDidChange];
+      break;
+  }
+
+  return NS_OK;
+}
+
 nsresult
 nsAccessibleWrap::InvalidateChildren ()
 {
   if (mNativeWrapper) {
     mozAccessible *object = mNativeWrapper->getNativeObject();
     [object invalidateChildren];
   }
   return nsAccessible::InvalidateChildren();
@@ -172,17 +209,17 @@ nsAccessibleWrap::GetUnignoredChildCount
     return 0;
   
   PRInt32 childCount = 0;
   GetChildCount(&childCount);
   
   nsCOMPtr<nsIAccessible> curAcc;
   
   while (NextChild(curAcc)) {
-    nsAccessibleWrap *childWrap = NS_STATIC_CAST(nsAccessibleWrap*, (nsIAccessible*)curAcc.get());
+    nsAccessibleWrap *childWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)curAcc.get());
     
     // if the current child is not ignored, count it.
     if (!childWrap->IsIgnored())
       ++childCount;
       
     // if it's flat, we don't care to inspect its children.
     if (childWrap->IsFlat())
       continue;
@@ -214,17 +251,17 @@ nsAccessibleWrap::GetUnignoredChildren(n
 {
   nsCOMPtr<nsIAccessible> curAcc;
   
   // we're flat; there are no children.
   if (IsFlat())
     return;
   
   while (NextChild(curAcc)) {
-    nsAccessibleWrap *childWrap = NS_STATIC_CAST(nsAccessibleWrap*, (nsIAccessible*)curAcc.get());
+    nsAccessibleWrap *childWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)curAcc.get());
     if (childWrap->IsIgnored()) {
       // element is ignored, so try adding its children as substitutes, if it has any.
       if (!childWrap->IsFlat()) {
         nsTArray<nsRefPtr<nsAccessibleWrap> > children;
         childWrap->GetUnignoredChildren(children);
         if (!children.IsEmpty()) {
           // add the found unignored descendants to the array.
           aChildrenArray.AppendElements(children);
@@ -235,17 +272,17 @@ nsAccessibleWrap::GetUnignoredChildren(n
       aChildrenArray.AppendElement(childWrap);
   }
 }
 
 already_AddRefed<nsIAccessible>
 nsAccessibleWrap::GetUnignoredParent()
 {
   nsCOMPtr<nsIAccessible> parent(GetParent());
-  nsAccessibleWrap *parentWrap = NS_STATIC_CAST(nsAccessibleWrap*, (nsIAccessible*)parent.get());
+  nsAccessibleWrap *parentWrap = static_cast<nsAccessibleWrap*>((nsIAccessible*)parent.get());
   if (!parentWrap)
     return nsnull;
     
   // recursively return the parent, until we find one that is not ignored.
   if (parentWrap->IsIgnored())
     return parentWrap->GetUnignoredParent();
   
   nsIAccessible *outValue = nsnull;
--- a/accessible/src/mac/nsDocAccessibleWrap.h
+++ b/accessible/src/mac/nsDocAccessibleWrap.h
@@ -36,22 +36,12 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _nsDocAccessibleWrap_H_
 #define _nsDocAccessibleWrap_H_
 
 #include "nsDocAccessible.h"
 
-struct objc_class;
-
-class nsDocAccessibleWrap: public nsDocAccessible
-{
-  public:
-    nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell);
-    virtual ~nsDocAccessibleWrap();
-    
-    NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, 
-                                void* aData);
-};
+typedef nsDocAccessible nsDocAccessibleWrap;
 
 #endif
 
--- a/accessible/src/msaa/CAccessibleAction.cpp
+++ b/accessible/src/msaa/CAccessibleAction.cpp
@@ -51,18 +51,18 @@
 // IUnknown
 
 STDMETHODIMP
 CAccessibleAction::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleAction == iid) {
-    *ppv = NS_STATIC_CAST(IAccessibleAction*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleAction*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleAction
 
@@ -84,33 +84,33 @@ CAccessibleAction::nActions(long *aNumAc
 
 STDMETHODIMP
 CAccessibleAction::doAction(long aActionIndex)
 {
   nsCOMPtr<nsIAccessible> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
-  PRUint8 index = NS_STATIC_CAST(PRUint8, aActionIndex);
+  PRUint8 index = static_cast<PRUint8>(aActionIndex);
   if (NS_SUCCEEDED(acc->DoAction(index)))
     return S_OK;
   return E_FAIL;
 }
 
 STDMETHODIMP
 CAccessibleAction::get_description(long aActionIndex, BSTR *aDescription)
 {
   *aDescription = NULL;
 
   nsCOMPtr<nsIAccessible> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
   nsAutoString description;
-  PRUint8 index = NS_STATIC_CAST(PRUint8, aActionIndex);
+  PRUint8 index = static_cast<PRUint8>(aActionIndex);
   if (NS_FAILED(acc->GetActionDescription(index, description)))
     return E_FAIL;
 
   if (!description.IsVoid()) {
     return ::SysReAllocStringLen(aDescription, description.get(),
                                  description.Length());
   }
 
@@ -125,27 +125,27 @@ CAccessibleAction::get_keyBinding(long a
   *aKeyBinding = NULL;
   aNumBinding = 0;
 
   nsCOMPtr<nsIAccessible> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
   nsCOMPtr<nsIDOMDOMStringList> keys;
-  PRUint8 index = NS_STATIC_CAST(PRUint8, aActionIndex);
+  PRUint8 index = static_cast<PRUint8>(aActionIndex);
   nsresult rv = acc->GetKeyBindings(index, getter_AddRefs(keys));
   if (NS_FAILED(rv))
     return E_FAIL;
 
   PRUint32 length = 0;
   keys->GetLength(&length);
 
-  PRBool aUseNumMaxBinding = length > NS_STATIC_CAST(PRUint32, aNumMaxBinding);
+  PRBool aUseNumMaxBinding = length > static_cast<PRUint32>(aNumMaxBinding);
 
-  PRUint32 maxBinding = NS_STATIC_CAST(PRUint32, aNumMaxBinding);
+  PRUint32 maxBinding = static_cast<PRUint32>(aNumMaxBinding);
 
   PRUint32 numBinding = length > maxBinding ? maxBinding : length;
   *aNumBinding = numBinding;
 
   *aKeyBinding = new BSTR[numBinding];
   if (!*aKeyBinding)
     return E_OUTOFMEMORY;
 
@@ -166,17 +166,17 @@ CAccessibleAction::get_name(long aAction
 {
   *aName = NULL;
 
   nsCOMPtr<nsIAccessible> acc(do_QueryInterface(this));
   if (!acc)
     return E_FAIL;
 
   nsAutoString name;
-  PRUint8 index = NS_STATIC_CAST(PRUint8, aActionIndex);
+  PRUint8 index = static_cast<PRUint8>(aActionIndex);
   if (NS_FAILED(acc->GetActionName(index, name)))
     return E_FAIL;
 
   if (!name.IsVoid())
     return ::SysReAllocStringLen(aName, name.get(), name.Length());
 
   return S_OK;
 }
--- a/accessible/src/msaa/CAccessibleComponent.cpp
+++ b/accessible/src/msaa/CAccessibleComponent.cpp
@@ -62,18 +62,18 @@ enum {
 // IUnknown
 
 STDMETHODIMP
 CAccessibleComponent::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleComponent == iid) {
-    *ppv = NS_STATIC_CAST(IAccessibleComponent*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleComponent*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleComponent
 
--- a/accessible/src/msaa/CAccessibleEditableText.cpp
+++ b/accessible/src/msaa/CAccessibleEditableText.cpp
@@ -59,18 +59,18 @@ STDMETHODIMP
 CAccessibleEditableText::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleEditableText == iid) {
     nsCOMPtr<nsIAccessibleEditableText> editTextAcc(do_QueryInterface(this));
     if (!editTextAcc)
       return E_NOINTERFACE;
-    *ppv = NS_STATIC_CAST(IAccessibleEditableText*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef(); 
+    *ppv = static_cast<IAccessibleEditableText*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleEditableText
 
--- a/accessible/src/msaa/CAccessibleHyperlink.cpp
+++ b/accessible/src/msaa/CAccessibleHyperlink.cpp
@@ -60,18 +60,18 @@ CAccessibleHyperlink::QueryInterface(REF
 {
   *ppv = NULL;
 
   if (IID_IAccessibleHyperlink == iid) {
     nsCOMPtr<nsIAccessibleHyperLink> acc(do_QueryInterface(this));
     if (!acc)
       return E_NOINTERFACE;
 
-    *ppv = NS_STATIC_CAST(IAccessibleHyperlink*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleHyperlink*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return CAccessibleAction::QueryInterface(iid, ppv);
 }
 
 // IAccessibleHyperlink
 
@@ -94,17 +94,17 @@ CAccessibleHyperlink::get_anchor(long aI
     return E_FAIL;
 
   void *instancePtr = NULL;
   nsresult rv =  winAccessNode->QueryNativeInterface(IID_IUnknown,
                                                      &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  IUnknown *unknownPtr = NS_STATIC_CAST(IUnknown*, instancePtr);
+  IUnknown *unknownPtr = static_cast<IUnknown*>(instancePtr);
   aAnchor->ppunkVal = &unknownPtr;
   aAnchor->vt = VT_UNKNOWN;
 
   return S_OK;
 }
 
 STDMETHODIMP
 CAccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT *aAnchorTarget)
--- a/accessible/src/msaa/CAccessibleHypertext.cpp
+++ b/accessible/src/msaa/CAccessibleHypertext.cpp
@@ -54,18 +54,18 @@ CAccessibleHypertext::QueryInterface(REF
 {
   *ppv = NULL;
 
   if (IID_IAccessibleHypertext == iid) {
     nsCOMPtr<nsIAccessibleHyperText> hyperAcc(do_QueryInterface(this));
     if (!hyperAcc)
       return E_NOINTERFACE;
 
-    *ppv = NS_STATIC_CAST(IAccessibleHypertext*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleHypertext*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return CAccessibleText::QueryInterface(iid, ppv);
 }
 
 // IAccessibleHypertext
 
@@ -102,17 +102,17 @@ CAccessibleHypertext::get_hyperlink(long
 
   nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(hyperLink));
   if (!winAccessNode)
     return E_FAIL;
 
   void *instancePtr = NULL;
   nsresult rv =  winAccessNode->QueryNativeInterface(IID_IAccessibleHyperlink,
                                                      &instancePtr);
-  *aHyperlink = NS_STATIC_CAST(IAccessibleHyperlink*, instancePtr);
+  *aHyperlink = static_cast<IAccessibleHyperlink*>(instancePtr);
 
   return NS_FAILED(rv) ? E_FAIL : S_OK;
 }
 
 STDMETHODIMP
 CAccessibleHypertext::get_hyperlinkIndex(long aCharIndex, long *aHyperlinkIndex)
 {
   *aHyperlinkIndex = 0;
--- a/accessible/src/msaa/CAccessibleImage.cpp
+++ b/accessible/src/msaa/CAccessibleImage.cpp
@@ -55,18 +55,18 @@ CAccessibleImage::QueryInterface(REFIID 
 {
   *ppv = NULL;
 
   if (IID_IAccessibleImage == iid) {
     nsCOMPtr<nsIAccessibleImage> imageAcc(do_QueryInterface(this));
     if (!imageAcc)
       return E_FAIL;
 
-    *ppv = NS_STATIC_CAST(IAccessibleImage*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleImage*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleImage
 
--- a/accessible/src/msaa/CAccessibleTable.cpp
+++ b/accessible/src/msaa/CAccessibleTable.cpp
@@ -56,18 +56,18 @@
 // IUnknown
 
 STDMETHODIMP
 CAccessibleTable::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleTable == iid) {
-    *ppv = NS_STATIC_CAST(IAccessibleTable*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleTable*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleTable
 
@@ -90,17 +90,17 @@ CAccessibleTable::get_accessibleAt(long 
     return E_FAIL;
 
   void *instancePtr = NULL;
   nsresult rv = winAccessNode->QueryNativeInterface(IID_IAccessible2,
                                                     &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aAccessible = NS_STATIC_CAST(IUnknown*, instancePtr);
+  *aAccessible = static_cast<IUnknown*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 CAccessibleTable::get_caption(IUnknown **aAccessible)
 {
   *aAccessible = NULL;
 
@@ -117,17 +117,17 @@ CAccessibleTable::get_caption(IUnknown *
     return E_FAIL;
 
   void *instancePtr = NULL;
   nsresult rv = winAccessNode->QueryNativeInterface(IID_IAccessible2,
                                                     &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aAccessible = NS_STATIC_CAST(IUnknown*, instancePtr);
+  *aAccessible = static_cast<IUnknown*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 CAccessibleTable::get_childIndex(long aRowIndex, long aColumnIndex,
                                  long *aChildIndex)
 {
   *aChildIndex = 0;
@@ -203,17 +203,17 @@ CAccessibleTable::get_columnHeader(IAcce
   if (!winAccessNode)
     return E_FAIL;
 
   void *instancePtr = NULL;
   rv = winAccessNode->QueryNativeInterface(IID_IAccessibleTable, &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aAccessibleTable = NS_STATIC_CAST(IAccessibleTable*, instancePtr);
+  *aAccessibleTable = static_cast<IAccessibleTable*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 CAccessibleTable::get_columnIndex(long aChildIndex, long *aColumnIndex)
 {
   *aColumnIndex = 0;
 
@@ -343,17 +343,17 @@ CAccessibleTable::get_rowHeader(IAccessi
     return E_FAIL;
 
   void *instancePtr = NULL;
   rv = winAccessNode->QueryNativeInterface(IID_IAccessibleTable,
                                            &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aAccessibleTable = NS_STATIC_CAST(IAccessibleTable*, instancePtr);
+  *aAccessibleTable = static_cast<IAccessibleTable*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 CAccessibleTable::get_rowIndex(long aChildIndex, long *aRowIndex)
 {
   *aRowIndex = 0;
 
--- a/accessible/src/msaa/CAccessibleText.cpp
+++ b/accessible/src/msaa/CAccessibleText.cpp
@@ -65,18 +65,18 @@ CAccessibleText::QueryInterface(REFIID i
 {
   *ppv = NULL;
 
   if (IID_IAccessibleText == iid) {
     nsCOMPtr<nsIAccessibleText> textAcc(do_QueryInterface(this));
     if (!textAcc) {
       return E_NOINTERFACE;
     }
-    *ppv = NS_STATIC_CAST(IAccessibleText*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleText*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleText
 
@@ -106,17 +106,17 @@ CAccessibleText::get_attributes(long aOf
   if (!winAccessNode)
     return E_FAIL;
 
   void **instancePtr = 0;
   winAccessNode->QueryNativeInterface(IID_IAccessible2, instancePtr);
   if (!instancePtr)
     return E_FAIL;
 
-  IAccessible2 *pAccessible2 = NS_STATIC_CAST(IAccessible2*, *instancePtr);
+  IAccessible2 *pAccessible2 = static_cast<IAccessible2*>(*instancePtr);
   HRESULT hr = pAccessible2->get_attributes(aTextAttributes);
   pAccessible2->Release();
 
   *aStartOffset = startOffset;
   *aEndOffset = endOffset;
 
   return hr;
 }
@@ -373,17 +373,17 @@ CAccessibleText::scrollSubstringTo(long 
   if (!winAccessNode)
     return E_FAIL;
 
   void **instancePtr = 0;
   winAccessNode->QueryNativeInterface(IID_IAccessible2, instancePtr);
   if (!instancePtr)
     return E_FAIL;
 
-  IAccessible2 *pAccessible2 = NS_STATIC_CAST(IAccessible2*, *instancePtr);
+  IAccessible2 *pAccessible2 = static_cast<IAccessible2*>(*instancePtr);
   HRESULT hr = pAccessible2->scrollTo(aScrollType);
   pAccessible2->Release();
 
   return hr;
 }
 
 STDMETHODIMP
 CAccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex,
@@ -405,17 +405,17 @@ CAccessibleText::scrollSubstringToPoint(
   if (!winAccessNode)
     return E_FAIL;
 
   void **instancePtr = 0;
   winAccessNode->QueryNativeInterface(IID_IAccessible2, instancePtr);
   if (!instancePtr)
     return E_FAIL;
 
-  IAccessible2 *pAccessible2 = NS_STATIC_CAST(IAccessible2*, *instancePtr);
+  IAccessible2 *pAccessible2 = static_cast<IAccessible2*>(*instancePtr);
   HRESULT hr = pAccessible2->scrollToPoint(aCoordinateType, aX, aY);
   pAccessible2->Release();
 
   return hr;
 }
 
 STDMETHODIMP
 CAccessibleText::get_newText(IA2TextSegment *aNewText)
--- a/accessible/src/msaa/CAccessibleValue.cpp
+++ b/accessible/src/msaa/CAccessibleValue.cpp
@@ -53,18 +53,18 @@ CAccessibleValue::QueryInterface(REFIID 
 {
   *ppv = NULL;
 
   if (IID_IAccessibleValue == iid) {
     nsCOMPtr<nsIAccessibleValue> valueAcc(do_QueryInterface(this));
     if (!valueAcc)
       return E_NOINTERFACE;
 
-    *ppv = NS_STATIC_CAST(IAccessibleValue*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleValue*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleValue
 
--- a/accessible/src/msaa/nsAccessNodeWrap.cpp
+++ b/accessible/src/msaa/nsAccessNodeWrap.cpp
@@ -112,22 +112,22 @@ nsAccessNodeWrap::QueryNativeInterface(R
 // IUnknown interface methods - see iunknown.h for documentation
 //-----------------------------------------------------
 
 STDMETHODIMP nsAccessNodeWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = nsnull;
 
   if (IID_IUnknown == iid || IID_ISimpleDOMNode == iid)
-    *ppv = NS_STATIC_CAST(ISimpleDOMNode*, this);
+    *ppv = static_cast<ISimpleDOMNode*>(this);
 
   if (nsnull == *ppv)
     return E_NOINTERFACE;      //iid not supported.
    
-  (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef(); 
+  (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 
   return S_OK;
 }
 
 //-----------------------------------------------------
 // ISimpleDOMNode methods
 //-----------------------------------------------------
 
 STDMETHODIMP nsAccessNodeWrap::get_nodeInfo( 
@@ -143,44 +143,44 @@ STDMETHODIMP nsAccessNodeWrap::get_nodeI
 
   if (!mDOMNode)
     return E_FAIL;
  
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
 
   PRUint16 nodeType = 0;
   mDOMNode->GetNodeType(&nodeType);
-  *aNodeType=NS_STATIC_CAST(unsigned short, nodeType);
+  *aNodeType=static_cast<unsigned short>(nodeType);
 
   if (*aNodeType !=  NODETYPE_TEXT) {
     nsAutoString nodeName;
     mDOMNode->GetNodeName(nodeName);
     *aNodeName =   ::SysAllocString(nodeName.get());
   }
 
   nsAutoString nodeValue;
 
   mDOMNode->GetNodeValue(nodeValue);
   *aNodeValue = ::SysAllocString(nodeValue.get());
-  *aNameSpaceID = content ? NS_STATIC_CAST(short, content->GetNameSpaceID()) : 0;
+  *aNameSpaceID = content ? static_cast<short>(content->GetNameSpaceID()) : 0;
 
   // This is a unique ID for every content node.  The 3rd party
   // accessibility application can compare this to the childID we
   // return for events such as focus events, to correlate back to
   // data nodes in their internal object model.
   void *uniqueID;
   GetUniqueID(&uniqueID);
   *aUniqueID = - NS_PTR_TO_INT32(uniqueID);
 
   *aNumChildren = 0;
   PRUint32 numChildren = 0;
   nsCOMPtr<nsIDOMNodeList> nodeList;
   mDOMNode->GetChildNodes(getter_AddRefs(nodeList));
   if (nodeList && NS_OK == nodeList->GetLength(&numChildren))
-    *aNumChildren = NS_STATIC_CAST(unsigned int, numChildren);
+    *aNumChildren = static_cast<unsigned int>(numChildren);
 
   return S_OK;
 }
 
 
        
 STDMETHODIMP nsAccessNodeWrap::get_attributes( 
     /* [in] */ unsigned short aMaxAttribs,
@@ -194,25 +194,25 @@ STDMETHODIMP nsAccessNodeWrap::get_attri
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   if (!content) 
     return E_FAIL;
 
   PRUint32 numAttribs = content->GetAttrCount();
 
   if (numAttribs > aMaxAttribs)
     numAttribs = aMaxAttribs;
-  *aNumAttribs = NS_STATIC_CAST(unsigned short, numAttribs);
+  *aNumAttribs = static_cast<unsigned short>(numAttribs);
 
   for (PRUint32 index = 0; index < numAttribs; index++) {
     aNameSpaceIDs[index] = 0; aAttribValues[index] = aAttribNames[index] = nsnull;
     nsAutoString attributeValue;
     const char *pszAttributeName; 
 
     const nsAttrName* name = content->GetAttrNameAt(index);
-    aNameSpaceIDs[index] = NS_STATIC_CAST(short, name->NamespaceID());
+    aNameSpaceIDs[index] = static_cast<short>(name->NamespaceID());
     name->LocalName()->GetUTF8String(&pszAttributeName);
     aAttribNames[index] = ::SysAllocString(NS_ConvertUTF8toUTF16(pszAttributeName).get());
     content->GetAttr(name->NamespaceID(), name->LocalName(), attributeValue);
     aAttribValues[index] = ::SysAllocString(attributeValue.get());
   }
 
   return S_OK; 
 }
@@ -237,17 +237,17 @@ STDMETHODIMP nsAccessNodeWrap::get_attri
     do_GetService(NS_NAMESPACEMANAGER_CONTRACTID);
 
   PRInt32 index;
 
   for (index = 0; index < aNumAttribs; index++) {
     aAttribValues[index] = nsnull;
     if (aAttribNames[index]) {
       nsAutoString attributeValue, nameSpaceURI;
-      nsAutoString attributeName(nsDependentString(NS_STATIC_CAST(PRUnichar*,aAttribNames[index])));
+      nsAutoString attributeName(nsDependentString(static_cast<PRUnichar*>(aAttribNames[index])));
       nsresult rv;
 
       if (aNameSpaceID[index]>0 && 
         NS_SUCCEEDED(nameSpaceManager->GetNameSpaceURI(aNameSpaceID[index], nameSpaceURI)))
           rv = domElement->GetAttributeNS(nameSpaceURI, attributeName, attributeValue);
       else 
         rv = domElement->GetAttribute(attributeName, attributeValue);
 
@@ -285,17 +285,17 @@ STDMETHODIMP nsAccessNodeWrap::get_compu
     if (NS_SUCCEEDED(cssDecl->Item(index, property)) && property.CharAt(0) != '-')  // Ignore -moz-* properties
       cssDecl->GetPropertyValue(property, value);  // Get property value
     if (!value.IsEmpty()) {
       aStyleProperties[realIndex] =   ::SysAllocString(property.get());
       aStyleValues[realIndex]     =   ::SysAllocString(value.get());
       ++realIndex;
     }
   }
-  *aNumStyleProperties = NS_STATIC_CAST(unsigned short, realIndex);
+  *aNumStyleProperties = static_cast<unsigned short>(realIndex);
 
   return S_OK;
 }
 
 
 STDMETHODIMP nsAccessNodeWrap::get_computedStyleForProperties( 
     /* [in] */ unsigned short aNumStyleProperties,
     /* [in] */ boolean aUseAlternateView,
@@ -309,17 +309,17 @@ STDMETHODIMP nsAccessNodeWrap::get_compu
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
   GetComputedStyleDeclaration(EmptyString(), domElement, getter_AddRefs(cssDecl));
   NS_ENSURE_TRUE(cssDecl, E_FAIL);
 
   PRUint32 index;
   for (index = 0; index < aNumStyleProperties; index ++) {
     nsAutoString value;
     if (aStyleProperties[index])
-      cssDecl->GetPropertyValue(nsDependentString(NS_STATIC_CAST(PRUnichar*,aStyleProperties[index])), value);  // Get property value
+      cssDecl->GetPropertyValue(nsDependentString(static_cast<PRUnichar*>(aStyleProperties[index])), value);  // Get property value
     aStyleValues[index] = ::SysAllocString(value.get());
   }
 
   return S_OK;
 }
 
 STDMETHODIMP nsAccessNodeWrap::scrollTo(/* [in] */ boolean aScrollTopLeft)
 {
@@ -371,17 +371,17 @@ ISimpleDOMNode* nsAccessNodeWrap::MakeAc
     msaaAccessible->Release(); // Release IAccessible
   }
   else {
     newNode = new nsAccessNodeWrap(node, mWeakShell);
     if (!newNode)
       return NULL;
 
     newNode->Init();
-    iNode = NS_STATIC_CAST(ISimpleDOMNode*, newNode);
+    iNode = static_cast<ISimpleDOMNode*>(newNode);
     iNode->AddRef();
   }
 
   return iNode;
 }
 
 
 STDMETHODIMP nsAccessNodeWrap::get_parentNode(ISimpleDOMNode __RPC_FAR *__RPC_FAR *aNode)
@@ -493,17 +493,17 @@ nsAccessNodeWrap::get_language(BSTR __RP
   *aLanguage = ::SysAllocString(language.get());
   return S_OK;
 }
 
 STDMETHODIMP 
 nsAccessNodeWrap::get_localInterface( 
     /* [out] */ void __RPC_FAR *__RPC_FAR *localInterface)
 {
-  *localInterface = NS_STATIC_CAST(nsIAccessNode*, this);
+  *localInterface = static_cast<nsIAccessNode*>(this);
   NS_ADDREF_THIS();
   return S_OK;
 }
  
 void nsAccessNodeWrap::InitAccessibility()
 {
   if (gIsAccessibilityActive) {
     return;
--- a/accessible/src/msaa/nsAccessibleRelationWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleRelationWrap.cpp
@@ -66,18 +66,18 @@ nsAccessibleRelationWrap::QueryNativeInt
 // IUnknown
 
 STDMETHODIMP
 nsAccessibleRelationWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleRelation == iid || IID_IUnknown == iid) {
-    *ppv = NS_STATIC_CAST(IAccessibleRelation*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleRelation*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return E_NOINTERFACE;
 }
 
 // IAccessibleRelation
 
@@ -170,17 +170,17 @@ nsAccessibleRelationWrap::get_target(lon
   if (!winAccessNode)
     return E_FAIL;
 
   void *instancePtr = NULL;
   rv = winAccessNode->QueryNativeInterface(IID_IUnknown, &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aTarget = NS_STATIC_CAST(IUnknown*, instancePtr);
+  *aTarget = static_cast<IUnknown*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 nsAccessibleRelationWrap::get_targets(long aMaxTargets, IUnknown **aTarget,
                                       long *aNTargets)
 {
   *aNTargets = 0;
@@ -204,17 +204,17 @@ nsAccessibleRelationWrap::get_targets(lo
       break;
 
     void *instancePtr = NULL;
     nsresult rv =  winAccessNode->QueryNativeInterface(IID_IUnknown,
                                                        &instancePtr);
     if (NS_FAILED(rv))
       break;
 
-    aTarget[index] = NS_STATIC_CAST(IUnknown*, instancePtr);
+    aTarget[index] = static_cast<IUnknown*>(instancePtr);
   }
 
   if (NS_FAILED(rv)) {
     for (PRUint32 index2 = 0; index2 < index; index2++) {
       aTarget[index2]->Release();
       aTarget[index2] = NULL;
     }
     return E_FAIL;
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -101,26 +101,26 @@ NS_IMPL_ISUPPORTS_INHERITED0(nsAccessibl
 //-----------------------------------------------------
 
 // Microsoft COM QueryInterface
 STDMETHODIMP nsAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid)
-    *ppv = NS_STATIC_CAST(IAccessible*, this);
+    *ppv = static_cast<IAccessible*>(this);
   else if (IID_IEnumVARIANT == iid && !gIsEnumVariantSupportDisabled) {
     long numChildren;
     get_accChildCount(&numChildren);
     if (numChildren > 0)  // Don't support this interface for leaf elements
-      *ppv = NS_STATIC_CAST(IEnumVARIANT*, this);
+      *ppv = static_cast<IEnumVARIANT*>(this);
   } else if (IID_IServiceProvider == iid)
-    *ppv = NS_STATIC_CAST(IServiceProvider*, this);
+    *ppv = static_cast<IServiceProvider*>(this);
   else if (IID_IAccessible2 == iid)
-    *ppv = NS_STATIC_CAST(IAccessible2*, this);
+    *ppv = static_cast<IAccessible2*>(this);
 
   if (NULL == *ppv) {
     HRESULT hr = CAccessibleComponent::QueryInterface(iid, ppv);
     if (SUCCEEDED(hr))
       return hr;
   }
 
   if (NULL == *ppv) {
@@ -133,17 +133,17 @@ STDMETHODIMP nsAccessibleWrap::QueryInte
     HRESULT hr = CAccessibleValue::QueryInterface(iid, ppv);
     if (SUCCEEDED(hr))
       return hr;
   }
 
   if (NULL == *ppv)
     return nsAccessNodeWrap::QueryInterface(iid, ppv);
 
-  (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+  (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
   return S_OK;
 }
 
 //-----------------------------------------------------
 // IAccessible methods
 //-----------------------------------------------------
 
 
@@ -255,17 +255,17 @@ STDMETHODIMP nsAccessibleWrap::get_accCh
       /* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispChild)
 {
   *ppdispChild = NULL;
 
   if (!mWeakShell || varChild.vt != VT_I4)
     return E_FAIL;
 
   if (varChild.lVal == CHILDID_SELF) {
-    *ppdispChild = NS_STATIC_CAST(IDispatch*, this);
+    *ppdispChild = static_cast<IDispatch*>(this);
     AddRef();
     return S_OK;
   }
 
   nsCOMPtr<nsIAccessible> childAccessible;
   if (!MustPrune(this)) {
     GetChildAt(varChild.lVal - 1, getter_AddRefs(childAccessible));
     if (childAccessible) {
@@ -435,16 +435,27 @@ STDMETHODIMP nsAccessibleWrap::get_accRo
                "MSAA role map skewed");
 
   // Special case, not a great place for this, but it's better than adding extra role buttonmenu role to ARIA
   // Other APIs do not have a special role for this.
   // Really the HASPOPUP state should have been enough for MSAA, but this avoids asking vendors for a fix.
   if (msaaRole == ROLE_SYSTEM_PUSHBUTTON && (State(xpAccessible) & nsIAccessibleStates::STATE_HASPOPUP)) {
     msaaRole = ROLE_SYSTEM_BUTTONMENU;
   }
+  
+  // Special case, if there is a ROLE_ROW inside of a ROLE_TREE_TABLE, then call the MSAA role
+  // a ROLE_OUTLINEITEM for consistency and compatibility.
+  // We need this because ARIA has a role of "row" for both grid and treegrid
+  if (xpRole == nsIAccessibleRole::ROLE_ROW) {
+    nsCOMPtr<nsIAccessible> parent = GetParent();
+    if (parent && Role(parent) == nsIAccessibleRole::ROLE_TREE_TABLE) {
+      msaaRole = ROLE_SYSTEM_OUTLINEITEM;
+    }
+  }
+  
   // -- Try enumerated role
   if (msaaRole != USE_ROLE_STRING) {
     pvarRole->vt = VT_I4;
     pvarRole->lVal = msaaRole;  // Normal enumerated role
     return S_OK;
   }
 
   // -- Try BSTR role
@@ -712,17 +723,17 @@ AccessibleEnumerator::Skip(unsigned long
   *  - the object is not the type that can have children selected
   */
 STDMETHODIMP nsAccessibleWrap::get_accSelection(VARIANT __RPC_FAR *pvarChildren)
 {
   VariantInit(pvarChildren);
   pvarChildren->vt = VT_EMPTY;
 
   nsCOMPtr<nsIAccessibleSelectable> 
-    select(do_QueryInterface(NS_STATIC_CAST(nsIAccessible*, this)));
+    select(do_QueryInterface(static_cast<nsIAccessible*>(this)));
 
   if (select) {  // do we have an nsIAccessibleSelectable?
     // we have an accessible that can have children selected
     nsCOMPtr<nsIArray> selectedOptions;
     // gets the selected options as nsIAccessibles.
     select->GetSelectedChildren(getter_AddRefs(selectedOptions));
     if (selectedOptions) { // false if the select has no children or none are selected
       // 1) Create and initialize the enumeration
@@ -943,17 +954,17 @@ STDMETHODIMP nsAccessibleWrap::accHitTes
   }
   else {
     GetChildAtPoint(xLeft, yTop, getter_AddRefs(xpAccessible));
   }
 
   // if we got a child
   if (xpAccessible) {
     // if the child is us
-    if (xpAccessible == NS_STATIC_CAST(nsIAccessible*, this)) {
+    if (xpAccessible == static_cast<nsIAccessible*>(this)) {
       pvarChild->vt = VT_I4;
       pvarChild->lVal = CHILDID_SELF;
     } else { // its not create an Accessible for it.
       pvarChild->vt = VT_DISPATCH;
       pvarChild->pdispVal = NativeAccessible(xpAccessible);
       nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(xpAccessible));
       NS_ASSERTION(accessNode, "Unable to QI to nsIAccessNode");
       nsCOMPtr<nsIDOMNode> domNode;
@@ -1045,37 +1056,37 @@ nsAccessibleWrap::Next(ULONG aNumElement
   varStart.lVal = CHILDID_SELF;
   varStart.vt = VT_I4;
 
   accNavigate(NAVDIR_FIRSTCHILD, varStart, &pvar[0]);
 
   for (long childIndex = 0; pvar[*aNumElementsFetched].vt == VT_DISPATCH; ++childIndex) {
     PRBool wasAccessibleFetched = PR_FALSE;
     nsAccessibleWrap *msaaAccessible =
-      NS_STATIC_CAST(nsAccessibleWrap*, pvar[*aNumElementsFetched].pdispVal);
+      static_cast<nsAccessibleWrap*>(pvar[*aNumElementsFetched].pdispVal);
     if (!msaaAccessible)
       break;
     if (childIndex >= mEnumVARIANTPosition) {
       if (++*aNumElementsFetched >= aNumElementsRequested)
         break;
       wasAccessibleFetched = PR_TRUE;
     }
     msaaAccessible->accNavigate(NAVDIR_NEXT, varStart, &pvar[*aNumElementsFetched] );
     if (!wasAccessibleFetched)
       msaaAccessible->nsAccessNode::Release(); // this accessible will not be received by the caller
   }
 
-  mEnumVARIANTPosition += NS_STATIC_CAST(PRUint16, *aNumElementsFetched);
+  mEnumVARIANTPosition += static_cast<PRUint16>(*aNumElementsFetched);
   return NOERROR;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::Skip(ULONG aNumElements)
 {
-  mEnumVARIANTPosition += NS_STATIC_CAST(PRUint16, aNumElements);
+  mEnumVARIANTPosition += static_cast<PRUint16>(aNumElements);
 
   PRInt32 numChildren;
   GetChildCount(&numChildren);
 
   if (mEnumVARIANTPosition > numChildren)
   {
     mEnumVARIANTPosition = numChildren;
     return S_FALSE;
@@ -1117,17 +1128,17 @@ nsAccessibleWrap::get_relation(long aRel
     return E_FAIL;
 
   void *instancePtr = NULL;
   rv =  winAccessNode->QueryNativeInterface(IID_IAccessibleRelation,
                                             &instancePtr);
   if (NS_FAILED(rv))
     return E_FAIL;
 
-  *aRelation = NS_STATIC_CAST(IAccessibleRelation*, instancePtr);
+  *aRelation = static_cast<IAccessibleRelation*>(instancePtr);
   return S_OK;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_relations(long aMaxRelations,
                                 IAccessibleRelation **aRelation,
                                 long *aNRelations)
 {
@@ -1152,17 +1163,17 @@ nsAccessibleWrap::get_relations(long aMa
       break;
 
     void *instancePtr = NULL;
     nsresult rv =  winAccessNode->QueryNativeInterface(IID_IAccessibleRelation,
                                                        &instancePtr);
     if (NS_FAILED(rv))
       break;
 
-    aRelation[index] = NS_STATIC_CAST(IAccessibleRelation*, instancePtr);
+    aRelation[index] = static_cast<IAccessibleRelation*>(instancePtr);
   }
 
   if (NS_FAILED(rv)) {
     for (PRUint32 index2 = 0; index2 < index; index2++) {
       aRelation[index2]->Release();
       aRelation[index2] = NULL;
     }
     return E_FAIL;
@@ -1310,28 +1321,28 @@ nsAccessibleWrap::get_localizedExtendedS
   return E_NOTIMPL;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_uniqueID(long *uniqueID)
 {
   void *id;
   if (NS_SUCCEEDED(GetUniqueID(&id))) {
-    *uniqueID = NS_REINTERPRET_POINTER_CAST(long, id);
+    *uniqueID = reinterpret_cast<long>(id);
     return S_OK;
   }
   return E_FAIL;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_windowHandle(HWND *windowHandle)
 {
   void **handle = nsnull;
   if (NS_SUCCEEDED(GetOwnerWindow(handle))) {
-    *windowHandle = NS_REINTERPRET_POINTER_CAST(HWND, *handle);
+    *windowHandle = reinterpret_cast<HWND>(*handle);
     return S_OK;
   }
   return E_FAIL;
 }
 
 STDMETHODIMP
 nsAccessibleWrap::get_indexInParent(long *indexInParent)
 {
@@ -1418,17 +1429,17 @@ nsAccessibleWrap::Clone(IEnumVARIANT FAR
   // Clone could be bad, the cloned items aren't tracked for shutdown
   // Then again, as long as the client releases the items in time, we're okay
   *ppenum = nsnull;
 
   nsAccessibleWrap *accessibleWrap = new nsAccessibleWrap(mDOMNode, mWeakShell);
   if (!accessibleWrap)
     return E_FAIL;
 
-  IAccessible *msaaAccessible = NS_STATIC_CAST(IAccessible*, accessibleWrap);
+  IAccessible *msaaAccessible = static_cast<IAccessible*>(accessibleWrap);
   msaaAccessible->AddRef();
   QueryInterface(IID_IEnumVARIANT, (void**)ppenum);
   if (*ppenum)
     (*ppenum)->Skip(mEnumVARIANTPosition); // QI addrefed
   msaaAccessible->Release();
 
   return NOERROR;
 }
@@ -1463,17 +1474,17 @@ STDMETHODIMP nsAccessibleWrap::Invoke(DI
     VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
 {
   return E_NOTIMPL;
 }
 
 
 NS_IMETHODIMP nsAccessibleWrap::GetNativeInterface(void **aOutAccessible)
 {
-  *aOutAccessible = NS_STATIC_CAST(IAccessible*, this);
+  *aOutAccessible = static_cast<IAccessible*>(this);
   NS_ADDREF_THIS();
   return NS_OK;
 }
 
 // nsPIAccessible
 
 NS_IMETHODIMP
 nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
@@ -1524,52 +1535,19 @@ nsAccessibleWrap::FireAccessibleEvent(ns
   nsCOMPtr<nsIAccessible> newAccessible;
   if (eventType == nsIAccessibleEvent::EVENT_HIDE) {
     // Don't use frame from current accessible when we're hiding that
     // accessible.
     accessible->GetParent(getter_AddRefs(newAccessible));
   } else {
     newAccessible = accessible;
   }
-  
-  HWND hWnd = 0;
-  nsCOMPtr<nsPIAccessNode> privateAccessNode =
-    do_QueryInterface(newAccessible);
-  if (privateAccessNode) {
-    nsIFrame *frame = privateAccessNode->GetFrame();
-    if (frame) {
-      nsIWidget *window = frame->GetWindow();
-      PRBool isVisible;
-      window->IsVisible(isVisible);
-      if (isVisible) {
-        // Short explanation:
-        // If HWND for frame is inside a hidden window, fire the event on the 
-        // containing document's visible window.
-        //
-        // Long explanation:
-        // This is really just to fix combo boxes with JAWS. Window-Eyes already worked with
-        // combo boxes because they use the value change event in the closed combo box
-        // case. JAWS will only pay attention to the focus events on the list items.
-        // The JAWS developers haven't fixed that, so we'll use the focus events to make JAWS work.
-        // However, JAWS is ignoring events on a hidden window. So, in order to fix the bug where
-        // JAWS doesn't echo the current option as it changes in a closed combo box, we need to use an
-        // ensure that we never fire an event with an HWND for a hidden window.
-        hWnd = (HWND)frame->GetWindow()->GetNativeData(NS_NATIVE_WINDOW);
-      }
-    }
-  }
 
-  if (!hWnd) {
-    void* handle = nsnull;
-    nsCOMPtr<nsIAccessibleDocument> accessibleDoc;
-    accessNode->GetAccessibleDocument(getter_AddRefs(accessibleDoc));
-    NS_ENSURE_STATE(accessibleDoc);
-    accessibleDoc->GetWindowHandle(&handle);
-    hWnd = (HWND)handle;
-  }
+  HWND hWnd = GetHWNDFor(accessible);
+  NS_ENSURE_TRUE(hWnd, NS_ERROR_FAILURE);
 
   // Gecko uses two windows for every scrollable area. One window contains
   // scrollbars and the child window contains only the client area.
   // Details of the 2 window system:
   // * Scrollbar window: caret drawing window & return value for WindowFromAccessibleObject()
   // * Client area window: text drawing window & MSAA event window
 
   // Fire MSAA event for client area window.
@@ -1593,51 +1571,99 @@ PRInt32 nsAccessibleWrap::GetChildIDFor(
   }
   accessNode->GetUniqueID(&uniqueID);
 
   // Yes, this means we're only compatibible with 32 bit
   // MSAA is only available for 32 bit windows, so it's okay
   return - NS_PTR_TO_INT32(uniqueID);
 }
 
+HWND
+nsAccessibleWrap::GetHWNDFor(nsIAccessible *aAccessible)
+{
+  nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(aAccessible));
+  nsCOMPtr<nsPIAccessNode> privateAccessNode(do_QueryInterface(accessNode));
+  if (!privateAccessNode)
+    return 0;
+
+  HWND hWnd = 0;
+
+  nsIFrame *frame = privateAccessNode->GetFrame();
+  if (frame) {
+    nsIWidget *window = frame->GetWindow();
+    PRBool isVisible;
+    window->IsVisible(isVisible);
+    if (isVisible) {
+      // Short explanation:
+      // If HWND for frame is inside a hidden window, fire the event on the
+      // containing document's visible window.
+      //
+      // Long explanation:
+      // This is really just to fix combo boxes with JAWS. Window-Eyes already
+      // worked with combo boxes because they use the value change event in
+      // the closed combo box case. JAWS will only pay attention to the focus
+      // events on the list items. The JAWS developers haven't fixed that, so
+      // we'll use the focus events to make JAWS work. However, JAWS is
+      // ignoring events on a hidden window. So, in order to fix the bug where
+      // JAWS doesn't echo the current option as it changes in a closed
+      // combo box, we need to use an ensure that we never fire an event with
+      // an HWND for a hidden window.
+      hWnd = (HWND)frame->GetWindow()->GetNativeData(NS_NATIVE_WINDOW);
+    }
+  }
+
+  if (!hWnd) {
+    void* handle = nsnull;
+    nsCOMPtr<nsIAccessibleDocument> accessibleDoc;
+    accessNode->GetAccessibleDocument(getter_AddRefs(accessibleDoc));
+    if (!accessibleDoc)
+      return 0;
+
+    accessibleDoc->GetWindowHandle(&handle);
+    hWnd = (HWND)handle;
+  }
+
+  return hWnd;
+}
+
 IDispatch *nsAccessibleWrap::NativeAccessible(nsIAccessible *aXPAccessible)
 {
   if (!aXPAccessible) {
    NS_WARNING("Not passing in an aXPAccessible");
    return NULL;
   }
 
   nsCOMPtr<nsIAccessibleWin32Object> accObject(do_QueryInterface(aXPAccessible));
   if (accObject) {
     void* hwnd;
     accObject->GetHwnd(&hwnd);
     if (hwnd) {
       IDispatch *retval = nsnull;
-      AccessibleObjectFromWindow(NS_REINTERPRET_CAST(HWND, hwnd),
+      AccessibleObjectFromWindow(reinterpret_cast<HWND>(hwnd),
         OBJID_WINDOW, IID_IAccessible, (void **) &retval);
       return retval;
     }
   }
 
   IAccessible *msaaAccessible;
   aXPAccessible->GetNativeInterface((void**)&msaaAccessible);
 
-  return NS_STATIC_CAST(IDispatch*, msaaAccessible);
+  return static_cast<IDispatch*>(msaaAccessible);
 }
 
 
 void nsAccessibleWrap::GetXPAccessibleFor(const VARIANT& aVarChild, nsIAccessible **aXPAccessible)
 {
   *aXPAccessible = nsnull;
   if (!mWeakShell)
     return; // Fail, we don't want to do anything after we've shut down
 
   // if its us real easy - this seems to always be the case
   if (aVarChild.lVal == CHILDID_SELF) {
-    *aXPAccessible = NS_STATIC_CAST(nsIAccessible*, this);
+    *aXPAccessible = static_cast<nsIAccessible*>(this);
   }
   else if (MustPrune(this)) {
     return;
   }
   else {
     // XXX It is rare to use a VARIANT with a child num
     // so optimizing this is not a priority
     // We can come back it do it later, if there are perf problems
--- a/accessible/src/msaa/nsAccessibleWrap.h
+++ b/accessible/src/msaa/nsAccessibleWrap.h
@@ -290,16 +290,17 @@ class nsAccessibleWrap : public nsAccess
         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
 
   // nsPIAccessible
   NS_IMETHOD FireAccessibleEvent(nsIAccessibleEvent *aEvent);
 
   // Helper methods
   static PRInt32 GetChildIDFor(nsIAccessible* aAccessible);
+  static HWND GetHWNDFor(nsIAccessible *aAccessible);
 
   /**
    * System caret support: update the Windows caret position. 
    * The system caret works more universally than the MSAA caret
    * For example, Window-Eyes, JAWS, ZoomText and Windows Tablet Edition use it
    * We will use an invisible system caret.
    * Gecko is still responsible for drawing its own caret
    */
--- a/accessible/src/msaa/nsApplicationAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsApplicationAccessibleWrap.cpp
@@ -37,61 +37,103 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsApplicationAccessibleWrap.h"
 
 #include "AccessibleApplication_i.c"
 
+#include "nsServiceManagerUtils.h"
+
+nsIXULAppInfo* nsApplicationAccessibleWrap::sAppInfo = nsnull;
+
 // nsISupports
 NS_IMPL_ISUPPORTS_INHERITED0(nsApplicationAccessibleWrap,
                              nsApplicationAccessible)
 
 // IUnknown
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_IAccessibleApplication == iid) {
-    *ppv = NS_STATIC_CAST(IAccessibleApplication*, this);
-    (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+    *ppv = static_cast<IAccessibleApplication*>(this);
+    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
     return S_OK;
   }
 
   return nsAccessibleWrap::QueryInterface(iid, ppv);
 }
 
 // IAccessibleApplication
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_appName(BSTR *aName)
 {
-  return E_NOTIMPL;
+  if (!sAppInfo)
+    return E_FAIL;
+
+  nsCAutoString cname;
+  nsresult rv = sAppInfo->GetName(cname);
+
+  if (NS_FAILED(rv))
+    return E_FAIL;
+
+  NS_ConvertUTF8toUTF16 name(cname);
+  return ::SysReAllocStringLen(aName, name.get(), name.Length());
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_appVersion(BSTR *aVersion)
 {
-  return E_NOTIMPL;
+  if (!sAppInfo)
+    return E_FAIL;
+
+  nsCAutoString cversion;
+  nsresult rv = sAppInfo->GetVersion(cversion);
+
+  if (NS_FAILED(rv))
+    return E_FAIL;
+
+  NS_ConvertUTF8toUTF16 version(cversion);
+  return ::SysReAllocStringLen(aVersion, version.get(), version.Length());
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_toolkitName(BSTR *aName)
 {
-  return E_NOTIMPL;
+  return ::SysReAllocString(aName, L"Gecko");
 }
 
 STDMETHODIMP
 nsApplicationAccessibleWrap::get_toolkitVersion(BSTR *aVersion)
 {
-  return E_NOTIMPL;
+  if (!sAppInfo)
+    return E_FAIL;
+
+  nsCAutoString cversion;
+  nsresult rv = sAppInfo->GetPlatformVersion(cversion);
+
+  if (NS_FAILED(rv))
+    return E_FAIL;
+
+  NS_ConvertUTF8toUTF16 version(cversion);
+  return ::SysReAllocStringLen(aVersion, version.get(), version.Length());
 }
 
 // nsApplicationAccessibleWrap
 
 void
 nsApplicationAccessibleWrap::PreCreate()
 {
+  nsresult rv = CallGetService("@mozilla.org/xre/app-info;1", &sAppInfo);
+  NS_ASSERTION(NS_SUCCEEDED(rv), "No XUL application info service");
 }
 
+void
+nsApplicationAccessibleWrap::Unload()
+{
+  NS_IF_RELEASE(sAppInfo);
+}
+
--- a/accessible/src/msaa/nsApplicationAccessibleWrap.h
+++ b/accessible/src/msaa/nsApplicationAccessibleWrap.h
@@ -40,16 +40,18 @@
 
 #ifndef __NS_APPLICATION_ACCESSIBLE_WRAP_H__
 #define __NS_APPLICATION_ACCESSIBLE_WRAP_H__
 
 #include "nsApplicationAccessible.h"
 
 #include "AccessibleApplication.h"
 
+#include "nsIXULAppInfo.h"
+
 class nsApplicationAccessibleWrap: public nsApplicationAccessible,
                                    public IAccessibleApplication
 {
 public:
   // nsISupporst
   NS_DECL_ISUPPORTS_INHERITED
 
   // IUnknown
@@ -65,12 +67,16 @@ public:
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_toolkitName(
       /* [retval][out] */ BSTR *name);
 
   virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_toolkitVersion(
           /* [retval][out] */ BSTR *version);
 
 public:
   static void PreCreate();
+  static void Unload();
+
+private:
+  static nsIXULAppInfo* sAppInfo;
 };
 
 #endif
 
--- a/accessible/src/msaa/nsDocAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsDocAccessibleWrap.cpp
@@ -80,22 +80,22 @@ STDMETHODIMP_(ULONG) nsDocAccessibleWrap
 }
 
 // Microsoft COM QueryInterface
 STDMETHODIMP nsDocAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = NULL;
 
   if (IID_ISimpleDOMDocument == iid)
-    *ppv = NS_STATIC_CAST(ISimpleDOMDocument*, this);
+    *ppv = static_cast<ISimpleDOMDocument*>(this);
 
   if (NULL == *ppv)
     return nsHyperTextAccessibleWrap::QueryInterface(iid, ppv);
     
-  (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
+  (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
   return S_OK;
 }
 
 void nsDocAccessibleWrap::GetXPAccessibleFor(const VARIANT& aVarChild, nsIAccessible **aXPAccessible)
 {
   *aXPAccessible = nsnull;
   if (!mWeakShell)
     return; // This document has been shut down
@@ -122,17 +122,17 @@ STDMETHODIMP nsDocAccessibleWrap::get_ac
   if (varChild.vt == VT_I4 && varChild.lVal < 0) {
     // AccessibleObjectFromEvent() being called
     // that's why the lVal < 0
     nsCOMPtr<nsIAccessible> xpAccessible;
     GetXPAccessibleFor(varChild, getter_AddRefs(xpAccessible));
     if (xpAccessible) {
       IAccessible *msaaAccessible;
       xpAccessible->GetNativeInterface((void**)&msaaAccessible);
-      *ppdispChild = NS_STATIC_CAST(IDispatch*, msaaAccessible);
+      *ppdispChild = static_cast<IDispatch*>(msaaAccessible);
       return S_OK;
     }
     else if (mDocument) {
       // If child ID from event can't be found in this window, ask parent.
       // This is especially relevant for times when a xul menu item
       // has focus, but the system thinks the content window has focus.
       nsIDocument* parentDoc = mDocument->GetParentDocument();
       if (parentDoc) {
@@ -189,21 +189,19 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireA
     }
     domSel->GetFocusNode(getter_AddRefs(focusNode));
   }
   else {
     focusNode = mDOMNode; // Moved to top, so event is for 1st leaf after root
   }
 
   nsCOMPtr<nsIAccessible> accessible = GetFirstAvailableAccessible(focusNode, PR_TRUE);
-  nsCOMPtr<nsPIAccessible> privateAccessible = do_QueryInterface(accessible);
-  if (privateAccessible) {
-    privateAccessible->FireToolkitEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
-                                        accessible, nsnull);
-  }
+  nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
+                           accessible);
+
   return NS_OK;
 }
 
 STDMETHODIMP nsDocAccessibleWrap::get_URL(/* [out] */ BSTR __RPC_FAR *aURL)
 {
   *aURL = NULL;
   nsAutoString URL;
   if (NS_SUCCEEDED(GetURL(URL))) {
--- a/accessible/src/msaa/nsHyperTextAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsHyperTextAccessibleWrap.cpp
@@ -62,17 +62,17 @@ nsHyperTextAccessibleWrap::FireAccessibl
       if (winAccessNode) {
         void *instancePtr = NULL;
         nsresult rv = winAccessNode->QueryNativeInterface(IID_IAccessibleText,
                                                           &instancePtr);
         if (NS_SUCCEEDED(rv)) {
           NS_IF_RELEASE(gTextEvent);
 
           CallQueryInterface(aEvent, &gTextEvent);
-          (NS_STATIC_CAST(IUnknown*, instancePtr))->Release();
+          (static_cast<IUnknown*>(instancePtr))->Release();
         }
       }
     }
   }
 
   return nsHyperTextAccessible::FireAccessibleEvent(aEvent);
 }
 
--- a/accessible/src/msaa/nsTextAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsTextAccessibleWrap.cpp
@@ -73,22 +73,22 @@ STDMETHODIMP_(ULONG) nsTextAccessibleWra
   return nsAccessNode::Release();
 }
 
 STDMETHODIMP nsTextAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
 {
   *ppv = nsnull;
 
   if (IID_IUnknown == iid || IID_ISimpleDOMText == iid)
-    *ppv = NS_STATIC_CAST(ISimpleDOMText*, this);
+    *ppv = static_cast<ISimpleDOMText*>(this);
 
   if (nsnull == *ppv)
     return nsAccessibleWrap::QueryInterface(iid, ppv);
    
-  (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef(); 
+  (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); 
   return S_OK;
 }
 
 STDMETHODIMP nsTextAccessibleWrap::get_domText( 
     /* [retval][out] */ BSTR __RPC_FAR *aDomText)
 {
   *aDomText = nsnull;
 
--- a/accessible/src/other/nsDocAccessibleWrap.h
+++ b/accessible/src/other/nsDocAccessibleWrap.h
@@ -40,17 +40,11 @@
  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
  */
 
 #ifndef _nsDocAccessibleWrap_H_
 #define _nsDocAccessibleWrap_H_
 
 #include "nsDocAccessible.h"
 
-class nsDocAccessibleWrap: public nsDocAccessible
-{
-public:
-    nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell);
-    virtual ~nsDocAccessibleWrap();
-    NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, void* aData);
-};
+typedef nsDocAccessible nsDocAccessibleWrap;
 
 #endif
--- a/accessible/src/xul/nsXULFormControlAccessible.cpp
+++ b/accessible/src/xul/nsXULFormControlAccessible.cpp
@@ -395,61 +395,69 @@ nsXULCheckboxAccessible::GetState(PRUint
   * XUL groupbox
   */
 
 nsXULGroupboxAccessible::nsXULGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
 nsAccessibleWrap(aNode, aShell)
 { 
 }
 
-NS_IMETHODIMP nsXULGroupboxAccessible::GetRole(PRUint32 *_retval)
+NS_IMETHODIMP nsXULGroupboxAccessible::GetRole(PRUint32 *aRole)
 {
-  *_retval = nsIAccessibleRole::ROLE_GROUPING;
+  *aRole = nsIAccessibleRole::ROLE_GROUPING;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXULGroupboxAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
+nsXULGroupboxAccessible::GetName(nsAString& aName)
 {
-  // Groupbox doesn't support focusable state!
-  nsresult rv = nsAccessible::GetState(aState, aExtraState);
-  NS_ENSURE_SUCCESS(rv, rv);
+  aName.Truncate();
 
-  *aState &= ~nsIAccessibleStates::STATE_FOCUSABLE;
+  nsCOMPtr<nsIAccessible> label;
+  GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABELLED_BY,
+                       getter_AddRefs(label));
+  if (label) {
+    return label->GetName(aName);
+  }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsXULGroupboxAccessible::GetName(nsAString& aName)
+NS_IMETHODIMP
+nsXULGroupboxAccessible::GetAccessibleRelated(PRUint32 aRelationType,
+                                              nsIAccessible **aRelated)
 {
-  aName.Truncate();  // Default name is blank 
+  *aRelated = nsnull;
 
-  if (mRoleMapEntry) {
-    nsAccessible::GetName(aName);
-    if (!aName.IsEmpty()) {
-      return NS_OK;
-    }
+  nsresult rv = nsAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
+  if (NS_FAILED(rv) || *aRelated) {
+    // Either the node is shut down, or another relation mechanism has been used
+    return rv;
   }
-  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
-  if (element) {
-    nsCOMPtr<nsIDOMNodeList> captions;
-    nsAutoString nameSpaceURI;
-    element->GetNamespaceURI(nameSpaceURI);
-    element->GetElementsByTagNameNS(nameSpaceURI, NS_LITERAL_STRING("caption"), 
-                                    getter_AddRefs(captions));
-    if (captions) {
-      nsCOMPtr<nsIDOMNode> captionNode;
-      captions->Item(0, getter_AddRefs(captionNode));
-      if (captionNode) {
-        element = do_QueryInterface(captionNode);
-        NS_ASSERTION(element, "No nsIDOMElement for caption node!");
-        element->GetAttribute(NS_LITERAL_STRING("label"), aName) ;
+
+  if (aRelationType == nsIAccessibleRelation::RELATION_LABELLED_BY) {
+    // The label for xul:groupbox is generated from xul:label that is
+    // inside the anonymous content of the xul:caption.
+    // The xul:label has an accessible object but the xul:caption does not
+    nsCOMPtr<nsIAccessible> testLabelAccessible;
+    while (NextChild(testLabelAccessible)) {
+      if (Role(testLabelAccessible) == nsIAccessibleRole::ROLE_LABEL) {
+        // Ensure that it's our label
+        nsCOMPtr<nsIAccessible> testGroupboxAccessible;
+        testLabelAccessible->GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABEL_FOR,
+                                                  getter_AddRefs(testGroupboxAccessible));
+        if (testGroupboxAccessible == this) {
+          // The <label> points back to this groupbox
+          NS_ADDREF(*aRelated = testLabelAccessible);
+          return NS_OK;
+        }
       }
     }
   }
+
   return NS_OK;
 }
 
 /**
   * progressmeter
   */
 NS_IMPL_ISUPPORTS_INHERITED1(nsXULProgressMeterAccessible, nsFormControlAccessible, nsIAccessibleValue)
 
@@ -568,18 +576,17 @@ nsresult
 nsXULRadioButtonAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);
   NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE);
 
   nsresult rv = nsFormControlAccessible::GetAttributesInternal(aAttributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAccessibilityUtils::
-    SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
+  nsAccUtils::SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
 
   return NS_OK;
 }
 
 /**
   * XUL Radio Group
   *   The Radio Group proxies for the Radio Buttons themselves. The Group gets
   *   focus whereas the Buttons do not. So we only have an accessible object for
--- a/accessible/src/xul/nsXULFormControlAccessible.h
+++ b/accessible/src/xul/nsXULFormControlAccessible.h
@@ -87,18 +87,18 @@ private:
   PRBool DropmarkerOpen(PRBool aToggleOpen);
 };
 
 class nsXULGroupboxAccessible : public nsAccessibleWrap
 {
 public:
   nsXULGroupboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
   NS_IMETHOD GetRole(PRUint32 *_retval); 
-  NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetName(nsAString& _retval);
+  NS_IMETHOD GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated);
 };
 
 class nsXULProgressMeterAccessible : public nsFormControlAccessible
 {
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIACCESSIBLEVALUE
 
 public:
--- a/accessible/src/xul/nsXULMenuAccessible.cpp
+++ b/accessible/src/xul/nsXULMenuAccessible.cpp
@@ -486,18 +486,17 @@ nsXULMenuitemAccessible::GetAttributesIn
   NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE);
 
   nsresult rv = nsAccessible::GetAttributesInternal(aAttributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // XXX: we don't support xul:menuitem inside xul:menu element now until
   // bug 372552 is fixed.
 
-  nsAccessibilityUtils::
-    SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
+  nsAccUtils::SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULMenuitemAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
 {
   // That indicates we don't walk anonymous children for menuitems
--- a/accessible/src/xul/nsXULTabAccessible.cpp
+++ b/accessible/src/xul/nsXULTabAccessible.cpp
@@ -133,18 +133,17 @@ nsresult
 nsXULTabAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);
   NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE);
 
   nsresult rv = nsLeafAccessible::GetAttributesInternal(aAttributes);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAccessibilityUtils::
-    SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
+  nsAccUtils::SetAccAttrsForXULSelectControlItem(mDOMNode, aAttributes);
 
   return NS_OK;
 }
 
 /**
   * XUL TabBox
   *  to facilitate naming of the tabPanels object we will give this the name
   *   of the selected tab in the tabs object.
--- a/accessible/src/xul/nsXULTextAccessible.cpp
+++ b/accessible/src/xul/nsXULTextAccessible.cpp
@@ -165,13 +165,13 @@ void nsXULLinkAccessible::CacheActionCon
   }
 
   // not a link if there is no href attribute or not on a <link> tag
   if (mTempContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::href) ||
       mTempContent->Tag() == nsAccessibilityAtoms::link) {
     mIsLink = PR_TRUE;
     mActionContent = mTempContent;
   }
-  else if (nsAccessibilityUtils::HasListener(mTempContent, NS_LITERAL_STRING("click"))) {
+  else if (nsAccUtils::HasListener(mTempContent, NS_LITERAL_STRING("click"))) {
     mIsOnclick = PR_TRUE;
     mActionContent = mTempContent;
   }
 }
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -562,17 +562,17 @@ NS_IMETHODIMP nsXULTreeitemAccessible::G
   }
   
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeitemAccessible::GetUniqueID(void **aUniqueID)
 {
   // Since mDOMNode is same for all tree item, use |this| pointer as the unique Id
-  *aUniqueID = NS_STATIC_CAST(void*, this);
+  *aUniqueID = static_cast<void*>(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeitemAccessible::GetRole(PRUint32 *aRole)
 {
   PRInt32 colCount = 0;
   if (NS_SUCCEEDED(nsXULTreeAccessible::GetColumnCount(mTree, &colCount)) && colCount > 1)
     *aRole = nsIAccessibleRole::ROLE_CELL;
@@ -729,26 +729,24 @@ nsXULTreeitemAccessible::GetAttributesIn
   for (;endIndex - 1 > 0 &&
         NS_SUCCEEDED(view->GetLevel(endIndex - 1, &lvl)) && lvl != level;
         endIndex--);
 
   PRInt32 setSize = endIndex - startIndex + 1;
   PRInt32 posInSet = mRow - startIndex + 1;
 
   // set the group attributes
-  nsAccessibilityUtils::
-    SetAccGroupAttrs(aAttributes, level + 1, posInSet, setSize);
+  nsAccUtils::SetAccGroupAttrs(aAttributes, level + 1, posInSet, setSize);
 
   // set the "cycles" attribute
   PRBool isCycler;
   mColumn->GetCycler(&isCycler);
   if (isCycler) {
-    nsAccessibilityUtils::SetAccAttr(aAttributes, 
-          nsAccessibilityAtoms::cycles,
-          NS_LITERAL_STRING("true"));
+    nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::cycles,
+                           NS_LITERAL_STRING("true"));
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeitemAccessible::GetParent(nsIAccessible **aParent)
 {
   *aParent = nsnull;
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -150,18 +150,16 @@ gc/boehm/leaksoup/Makefile
 "
 
 MAKEFILES_gfx="
 gfx/Makefile
 gfx/idl/Makefile
 gfx/public/Makefile
 gfx/src/Makefile
 gfx/src/beos/Makefile
-gfx/src/gtk/Makefile
-gfx/src/ps/Makefile
 gfx/src/psshared/Makefile
 gfx/src/photon/Makefile
 gfx/src/mac/Makefile
 gfx/src/os2/Makefile
 gfx/src/windows/Makefile
 gfx/src/thebes/Makefile
 gfx/tests/Makefile
 "
@@ -495,16 +493,17 @@ MAKEFILES_rdf="
 rdf/Makefile
 rdf/base/Makefile
 rdf/base/idl/Makefile
 rdf/base/public/Makefile
 rdf/base/src/Makefile
 rdf/util/Makefile
 rdf/util/public/Makefile
 rdf/util/src/Makefile
+rdf/util/src/internal/Makefile
 rdf/build/Makefile
 rdf/datasource/Makefile
 rdf/datasource/public/Makefile
 rdf/datasource/src/Makefile
 rdf/tests/Makefile
 rdf/tests/rdfcat/Makefile
 rdf/tests/rdfpoll/Makefile
 "
@@ -635,20 +634,16 @@ xpcom/tests/dynamic/Makefile
 xpcom/tests/services/Makefile
 xpcom/tests/windows/Makefile
 "
 
 MAKEFILES_string="$MAKEFILES_xpcom"
 
 MAKEFILES_xpinstall="
 xpinstall/Makefile
-xpinstall/packager/Makefile
-xpinstall/packager/unix/Makefile
-xpinstall/packager/windows/Makefile
-xpinstall/packager/os2/Makefile
 xpinstall/public/Makefile
 xpinstall/res/Makefile
 xpinstall/src/Makefile
 xpinstall/stub/Makefile
 xpinstall/wizard/libxpnet/Makefile
 xpinstall/wizard/libxpnet/src/Makefile
 xpinstall/wizard/libxpnet/test/Makefile
 xpinstall/wizard/unix/src2/Makefile
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -60,45 +60,35 @@ AB_CD = en-US
 
 DEFINES += -DAB_CD=$(AB_CD)
 
 APP_VERSION = $(shell cat $(srcdir)/../config/version.txt)
 DEFINES += -DAPP_VERSION="$(APP_VERSION)"
 APP_UA_NAME = $(shell echo $(MOZ_APP_DISPLAYNAME) | sed -e's/[^A-Za-z]//g')
 DEFINES += -DAPP_UA_NAME="$(APP_UA_NAME)"
 
-ifdef LIBXUL_SDK
-# Build application.ini for a XULRunner app
-
 DIST_FILES = application.ini
 
-# GRE_BUILD_ID is only available in nsBuildID.h in a form that we can't use
-# directly. So munge it. Beware makefile and shell escaping
-AWK_EXPR = '/\#define GRE_BUILD_ID/ { gsub(/"/, "", $$3); print $$3 }'
-AWK_CMD = awk $(AWK_EXPR) < $(LIBXUL_DIST)/include/nsBuildID.h
-
-GRE_BUILD_ID = $(shell $(AWK_CMD))
+GRE_MILESTONE = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build Milestone)
+GRE_BUILDID = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build BuildID)
 
-DEFINES += -DGRE_BUILD_ID=$(GRE_BUILD_ID)
-
-include $(topsrcdir)/config/rules.mk
+DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DGRE_BUILDID=$(GRE_BUILDID)
 
-else
+ifndef LIBXUL_SDK
 # Build a binary bootstrapping with XRE_main
 
-MOZILLA_INTERNAL_API = 1
-
 ifeq ($(USE_SHORT_LIBNAME), 1)
 PROGRAM = $(MOZ_APP_NAME)$(BIN_SUFFIX)
 else
 PROGRAM = $(MOZ_APP_NAME)-bin$(BIN_SUFFIX)
 endif
 
 REQUIRES = \
 	xpcom \
+	string \
 	xulapp \
 	$(NULL)
 
 CPPSRCS = nsBrowserApp.cpp
 
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
 
 ifdef BUILD_STATIC_LIBS
@@ -115,21 +105,28 @@ else
 EXTRA_DSO_LIBS += xul
 endif
 endif
 
 ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 TK_LIBS := -framework Cocoa $(TK_LIBS)
 endif
 
+ifdef MOZ_ENABLE_LIBXUL
+APP_XPCOM_LIBS = $(XPCOM_GLUE_LDOPTS)
+else
+MOZILLA_INTERNAL_API = 1
+APP_XPCOM_LIBS = $(XPCOM_LIBS)
+endif
+
 LIBS += \
 	$(STATIC_COMPONENTS_LINKER_PATH) \
 	$(EXTRA_DSO_LIBS) \
 	$(MOZ_JS_LIBS) \
-	$(XPCOM_LIBS) \
+	$(APP_XPCOM_LIBS) \
 	$(NSPR_LIBS) \
 	$(TK_LIBS) \
 	$(NULL)
 
 # Add explicit X11 dependency when building against X11 toolkits
 ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
 LIBS += $(XLDFLAGS) $(XLIBS)
 ifdef MOZ_ENABLE_CAIRO_GFX
@@ -271,17 +268,16 @@ ifdef BUILD_STATIC_LIBS
 LDFLAGS += -Zlinker /NOE
 endif
 endif
 
 ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
 
 $(MOZ_APP_NAME):: mozilla.in Makefile.in Makefile $(DEPTH)/config/autoconf.mk
 	cat $< | sed -e "s|%MOZAPPDIR%|$(mozappdir)|" \
-                -e "s|%MOZ_USER_DIR%|.mozilla/firefox|" \
 		-e "s|%MREDIR%|$(mredir)|" > $@
 	chmod +x $@
 
 libs:: $(MOZ_APP_NAME)
 	$(INSTALL) $< $(DIST)/bin
 
 install:: $(MOZ_APP_NAME)
 	$(SYSINSTALL) $< $(DESTDIR)$(bindir)
--- a/browser/app/application.ini
+++ b/browser/app/application.ini
@@ -35,23 +35,25 @@
 ;
 ; ***** END LICENSE BLOCK *****
 
 #filter substitution
 [App]
 Vendor=Mozilla
 Name=Firefox
 Version=@APP_VERSION@
-BuildID=@BUILD_ID@
+BuildID=@GRE_BUILDID@
 Copyright=Copyright (c) 1998 - 2007 mozilla.org
 ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
 
 [Gecko]
-MinVersion=@GRE_BUILD_ID@
-MaxVersion=@GRE_BUILD_ID@
+MinVersion=@GRE_MILESTONE@
+MaxVersion=@GRE_MILESTONE@
 
 [XRE]
 EnableProfileMigrator=1
 EnableExtensionManager=1
 
 [Crash Reporter]
-Enabled=0
+#if MOZILLA_OFFICIAL
+Enabled=1
+#endif
 ServerURL=https://crash-reports.mozilla.com/submit
--- a/browser/app/module.ver
+++ b/browser/app/module.ver
@@ -1,8 +1,8 @@
 WIN32_MODULE_COMPANYNAME=Mozilla Corporation
 WIN32_MODULE_COPYRIGHT=©Firefox and Mozilla Developers, according to the MPL 1.1/GPL 2.0/LGPL 2.1 licenses, as applicable.
 WIN32_MODULE_PRODUCTVERSION=3,0,0,0
-WIN32_MODULE_PRODUCTVERSION_STRING=3.0a6pre
+WIN32_MODULE_PRODUCTVERSION_STRING=3.0a7pre
 WIN32_MODULE_TRADEMARKS=Firefox is a Trademark of The Mozilla Foundation.
 WIN32_MODULE_DESCRIPTION=Firefox
 WIN32_MODULE_PRODUCTNAME=Firefox
 WIN32_MODULE_NAME=Firefox
--- a/browser/app/mozilla.in
+++ b/browser/app/mozilla.in
@@ -31,69 +31,29 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
-## $Id: mozilla.in,v 1.13 2005/09/20 21:11:34 dbaron%dbaron.org Exp $
+## $Id: mozilla.in,v 1.14 2007/06/23 05:30:29 ajschult%verizon.net Exp $
 ## 
 ## Usage:
 ##
 ## $ mozilla [args]
 ##
 ## This script is meant to run the mozilla-bin binary from either 
 ## mozilla/xpfe/bootstrap or mozilla/dist/bin.
 ##
 ## The script will setup all the environment voodoo needed to make
 ## the mozilla-bin binary to work.
 ##
 
-moz_pis_startstop_scripts()
-{
-  MOZ_USER_DIR="%MOZ_USER_DIR%"
-  # MOZ_PIS_ is the name space for "Mozilla Plugable Init Scripts"
-  # These variables and there meaning are specified in
-  # mozilla/xpfe/bootstrap/init.d/README
-  MOZ_PIS_API=2
-  MOZ_PIS_MOZBINDIR="${dist_bin}"
-  MOZ_PIS_SESSION_PID="$$"
-  MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
-  export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
-  
-  case "${1}" in
-    "start")
-      for curr_pis in "${dist_bin}/init.d"/S* "${HOME}/${MOZ_USER_DIR}/init.d"/S* ; do
-        if [ -x "${curr_pis}" ] ; then
-          case "${curr_pis}" in
-            *.sh) .  "${curr_pis}"         ;;
-            *)       "${curr_pis}" "start" ;;
-          esac
-        fi
-      done
-      ;;
-    "stop")
-      for curr_pis in "${HOME}/${MOZ_USER_DIR}/init.d"/K* "${dist_bin}/init.d"/K* ; do
-        if [ -x "${curr_pis}" ] ; then
-          case "${curr_pis}" in
-            *.sh) . "${curr_pis}"        ;;
-            *)      "${curr_pis}" "stop" ;;
-          esac
-        fi
-      done
-      ;;
-    *)
-      echo 1>&2 "$0: Internal error in moz_pis_startstop_scripts."
-      exit 1
-      ;;
-  esac
-}
-
 #uncomment for debugging
 #set -x
 
 moz_libdir=%MOZAPPDIR%
 MRE_HOME=%MREDIR%
 
 # Use run-mozilla.sh in the current dir if it exists
 # If not, then start resolving symlinks until we find run-mozilla.sh
@@ -168,23 +128,17 @@ do
       set -- "$@" "$arg"
       pass_arg_count=`expr $pass_arg_count + 1`
       ;;
   esac
 done
 
 export MRE_HOME
 
-## Start addon scripts
-moz_pis_startstop_scripts "start"
-
 if [ $debugging = 1 ]
 then
   echo $dist_bin/run-mozilla.sh $script_args $dist_bin/$MOZILLA_BIN "$@"
 fi
 "$dist_bin/run-mozilla.sh" $script_args "$dist_bin/$MOZILLA_BIN" "$@"
 exitcode=$?
 
-## Stop addon scripts
-moz_pis_startstop_scripts "stop"
-
 exit $exitcode
 # EOF.
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -36,42 +36,62 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXULAppAPI.h"
 #ifdef XP_WIN
 #include <windows.h>
 #include <stdlib.h>
 #endif
-#include "nsBuildID.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "nsCOMPtr.h"
+#include "nsILocalFile.h"
+#include "nsStringGlue.h"
+
+static void Output(const char *fmt, ... )
+{
+  va_list ap;
+  va_start(ap, fmt);
 
-static const nsXREAppData kAppData = {
-  sizeof(nsXREAppData),
-  nsnull,
-  "Mozilla",
-  "Firefox",
-  NS_STRINGIFY(APP_VERSION),
-  NS_STRINGIFY(BUILD_ID),
-  "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
-  "Copyright (c) 1998 - 2007 mozilla.org",
-  NS_XRE_ENABLE_PROFILE_MIGRATOR |
-  NS_XRE_ENABLE_EXTENSION_MANAGER
-#if defined(MOZILLA_OFFICIAL) && (defined(XP_WIN) || defined(XP_MACOSX))
-  | NS_XRE_ENABLE_CRASH_REPORTER
+#if defined(XP_WIN) && !MOZ_WINCONSOLE
+  char msg[2048];
+
+  vsnprintf(msg, sizeof(msg), fmt, ap);
+
+  MessageBox(NULL, msg, "XULRunner", MB_OK | MB_ICONERROR);
+#else
+  vfprintf(stderr, fmt, ap);
 #endif
-,
-  nsnull, // xreDirectory
-  nsnull, // minVersion
-  nsnull, // maxVersion
-  "https://crash-reports.mozilla.com/submit"
-};
+
+  va_end(ap);
+}
 
 int main(int argc, char* argv[])
 {
-  return XRE_main(argc, argv, &kAppData);
+  nsCOMPtr<nsILocalFile> appini;
+  nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini));
+  if (NS_FAILED(rv)) {
+    Output("Couldn't calculate the application directory.");
+    return 255;
+  }
+  appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini"));
+
+  nsXREAppData *appData;
+  rv = XRE_CreateAppData(appini, &appData);