From 6cd89897a1b8c62445dfeffc0c558ec3d8b3b7bf Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Fri, 23 Apr 2010 12:46:37 +0900 Subject: [PATCH] Bug 560239 - no children of application accessible for open windows before accessibility was started, r=marcoz, davidb, sr=neil, a=dholbert --- .../src/base/nsApplicationAccessible.cpp | 41 +++++++++- accessible/tests/mochitest/tree/Makefile.in | 2 + .../mochitest/tree/test_applicationacc.xul | 76 +++++++++++++++++++ accessible/tests/mochitest/tree/wnd.xul | 8 ++ 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 accessible/tests/mochitest/tree/test_applicationacc.xul create mode 100644 accessible/tests/mochitest/tree/wnd.xul diff --git a/accessible/src/base/nsApplicationAccessible.cpp b/accessible/src/base/nsApplicationAccessible.cpp index 231d27b4f8f..b553d2fb6f7 100644 --- a/accessible/src/base/nsApplicationAccessible.cpp +++ b/accessible/src/base/nsApplicationAccessible.cpp @@ -45,6 +45,9 @@ #include "nsAccessibilityService.h" #include "nsIComponentManager.h" +#include "nsIDOMDocument.h" +#include "nsIDOMWindow.h" +#include "nsIWindowMediator.h" #include "nsServiceManagerUtils.h" nsApplicationAccessible::nsApplicationAccessible() : @@ -258,8 +261,42 @@ nsApplicationAccessible::InvalidateChildren() void nsApplicationAccessible::CacheChildren() { - // Nothing to do. Children are keeped up to dated by Add/RemoveRootAccessible - // method calls. + // CacheChildren is called only once for application accessible when its + // children are requested because empty InvalidateChldren() prevents its + // repeated calls. + + // Basicly children are kept updated by Add/RemoveRootAccessible method + // calls. However if there are open windows before accessibility was started + // then we need to make sure root accessibles for open windows are created so + // that all root accessible are stored in application accessible children + // array. + + nsCOMPtr windowMediator = + do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); + + nsCOMPtr windowEnumerator; + nsresult rv = windowMediator->GetEnumerator(nsnull, + getter_AddRefs(windowEnumerator)); + if (NS_FAILED(rv)) + return; + + PRBool hasMore = PR_FALSE; + windowEnumerator->HasMoreElements(&hasMore); + while (hasMore) { + nsCOMPtr window; + windowEnumerator->GetNext(getter_AddRefs(window)); + nsCOMPtr DOMWindow = do_QueryInterface(window); + if (DOMWindow) { + nsCOMPtr DOMDocument; + DOMWindow->GetDocument(getter_AddRefs(DOMDocument)); + if (DOMDocument) { + nsCOMPtr accessible; + GetAccService()->GetAccessibleFor(DOMDocument, + getter_AddRefs(accessible)); + } + } + windowEnumerator->HasMoreElements(&hasMore); + } } nsAccessible* diff --git a/accessible/tests/mochitest/tree/Makefile.in b/accessible/tests/mochitest/tree/Makefile.in index f536668856b..a3b1da2fb51 100644 --- a/accessible/tests/mochitest/tree/Makefile.in +++ b/accessible/tests/mochitest/tree/Makefile.in @@ -46,6 +46,7 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk _TEST_FILES =\ + $(warning test_applicationacc.xul temporarily disabled) \ test_aria_globals.html \ test_aria_imgmap.html \ test_button.xul \ @@ -70,6 +71,7 @@ _TEST_FILES =\ test_txtcntr.html \ test_txtctrl.html \ test_txtctrl.xul \ + wnd.xul \ $(NULL) libs:: $(_TEST_FILES) diff --git a/accessible/tests/mochitest/tree/test_applicationacc.xul b/accessible/tests/mochitest/tree/test_applicationacc.xul new file mode 100644 index 00000000000..4a30d59d264 --- /dev/null +++ b/accessible/tests/mochitest/tree/test_applicationacc.xul @@ -0,0 +1,76 @@ + + + + + + + + + + + + Mozilla Bug 560239 +
+

+ +
+      
+ +
+ +
+ diff --git a/accessible/tests/mochitest/tree/wnd.xul b/accessible/tests/mochitest/tree/wnd.xul new file mode 100644 index 00000000000..3b87cb5e0d3 --- /dev/null +++ b/accessible/tests/mochitest/tree/wnd.xul @@ -0,0 +1,8 @@ + + + + + + +