diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp index 355effda1b5e..a0511f38a1d1 100644 --- a/accessible/src/base/nsRootAccessible.cpp +++ b/accessible/src/base/nsRootAccessible.cpp @@ -574,6 +574,59 @@ nsRootAccessible::Shutdown() nsDocAccessibleWrap::Shutdown(); } +// nsRootAccessible protected member +already_AddRefed +nsRootAccessible::GetContentDocShell(nsIDocShellTreeItem *aStart) +{ + if (!aStart) { + return nsnull; + } + + PRInt32 itemType; + aStart->GetItemType(&itemType); + if (itemType == nsIDocShellTreeItem::typeContent) { + nsDocAccessible *accDoc = nsAccUtils::GetDocAccessibleFor(aStart); + + // Hidden documents don't have accessibles (like SeaMonkey's sidebar), + // they are of no interest for a11y. + if (!accDoc) + return nsnull; + + // If ancestor chain of accessibles is not completely visible, + // don't use this one. This happens for example if it's inside + // a background tab (tabbed browsing) + nsAccessible* parent = accDoc->Parent(); + while (parent) { + if (parent->State() & states::INVISIBLE) + return nsnull; + + if (parent == this) + break; // Don't check past original root accessible we started with + + parent = parent->Parent(); + } + + NS_ADDREF(aStart); + return aStart; + } + nsCOMPtr treeNode(do_QueryInterface(aStart)); + if (treeNode) { + PRInt32 subDocuments; + treeNode->GetChildCount(&subDocuments); + for (PRInt32 count = 0; count < subDocuments; count ++) { + nsCOMPtr treeItemChild, contentTreeItem; + treeNode->GetChildAt(count, getter_AddRefs(treeItemChild)); + NS_ENSURE_TRUE(treeItemChild, nsnull); + contentTreeItem = GetContentDocShell(treeItemChild); + if (contentTreeItem) { + NS_ADDREF(aStart = contentTreeItem); + return aStart; + } + } + } + return nsnull; +} + // nsIAccessible method Relation nsRootAccessible::RelationByType(PRUint32 aType) @@ -581,25 +634,14 @@ nsRootAccessible::RelationByType(PRUint32 aType) if (!mDocument || aType != nsIAccessibleRelation::RELATION_EMBEDS) return nsDocAccessibleWrap::RelationByType(aType); - nsIDOMWindow* rootWindow = mDocument->GetWindow(); - if (rootWindow) { - nsCOMPtr contentWindow; - rootWindow->GetContent(getter_AddRefs(contentWindow)); - if (contentWindow) { - nsCOMPtr contentDOMDocument; - contentWindow->GetDocument(getter_AddRefs(contentDOMDocument)); - nsCOMPtr contentDocumentNode = - do_QueryInterface(contentDOMDocument); - if (contentDocumentNode) { - nsDocAccessible* contentDocument = - GetAccService()->GetDocAccessible(contentDocumentNode); - if (contentDocument) - return Relation(contentDocument); - } - } - } + nsCOMPtr treeItem = + nsCoreUtils::GetDocShellTreeItemFor(mDocument); + nsCOMPtr contentTreeItem = GetContentDocShell(treeItem); + // there may be no content area, so we need a null check + if (!contentTreeItem) + return Relation(); - return Relation(); + return Relation(nsAccUtils::GetDocAccessibleFor(contentTreeItem)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/accessible/src/base/nsRootAccessible.h b/accessible/src/base/nsRootAccessible.h index b7f02ffddbca..6feb79a91005 100644 --- a/accessible/src/base/nsRootAccessible.h +++ b/accessible/src/base/nsRootAccessible.h @@ -127,7 +127,8 @@ protected: PRUint32 GetChromeFlags(); #endif - + already_AddRefed + GetContentDocShell(nsIDocShellTreeItem *aStart); nsRefPtr mCaretAccessible; }; diff --git a/accessible/tests/mochitest/relations/Makefile.in b/accessible/tests/mochitest/relations/Makefile.in index 5fc8bf6d8789..5a7654412d37 100644 --- a/accessible/tests/mochitest/relations/Makefile.in +++ b/accessible/tests/mochitest/relations/Makefile.in @@ -48,7 +48,6 @@ include $(topsrcdir)/config/rules.mk # test_tabbrowser.xul disabled for misusing (bug 715857) _TEST_FILES =\ - test_embeds.xul \ test_general.html \ test_general.xul \ test_tree.xul \ diff --git a/accessible/tests/mochitest/relations/test_embeds.xul b/accessible/tests/mochitest/relations/test_embeds.xul deleted file mode 100644 index 5d0ddcfa9990..000000000000 --- a/accessible/tests/mochitest/relations/test_embeds.xul +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - - - - - - - - - - - Mozilla Bug 707654 - -

- -
-    
- -
-
diff --git a/accessible/tests/mochitest/relations/test_general.html b/accessible/tests/mochitest/relations/test_general.html index d487f349ade2..71bf6f8600d2 100644 --- a/accessible/tests/mochitest/relations/test_general.html +++ b/accessible/tests/mochitest/relations/test_general.html @@ -126,6 +126,19 @@ testRelation("legend", RELATION_LABEL_FOR, "fieldset"); testRelation("fieldset", RELATION_LABELLED_BY, "legend"); + // 'embeds' relation for root accessible + var docAcc = null; + var parentOfDocAcc = null; + var parentDocAcc = getAccessible(document); + do { + docAcc = parentDocAcc; + parentOfDocAcc = getAccessible(docAcc.parent, [nsIAccessNode]); + parentDocAcc = getAccessible(parentOfDocAcc.document, + [nsIAccessible]); + } while (getRole(parentDocAcc) != ROLE_CHROME_WINDOW) + + testRelation(parentDocAcc, RELATION_EMBEDS, docAcc); + // finish test SimpleTest.finish(); } diff --git a/accessible/tests/mochitest/relations/test_general.xul b/accessible/tests/mochitest/relations/test_general.xul index 23bf7276b28b..ca288d1bf6c1 100644 --- a/accessible/tests/mochitest/relations/test_general.xul +++ b/accessible/tests/mochitest/relations/test_general.xul @@ -103,6 +103,19 @@ // 'default button' relation testRelation("textbox", RELATION_DEFAULT_BUTTON, "submit"); + // 'embeds' relation for root accessible + var docAcc = null; + var parentOfDocAcc = null; + var parentDocAcc = getAccessible(document); + do { + docAcc = parentDocAcc; + parentOfDocAcc = getAccessible(docAcc.parent, [nsIAccessNode]); + parentDocAcc = getAccessible(parentOfDocAcc.document, + [nsIAccessible]); + } while (getRole(parentDocAcc) != ROLE_CHROME_WINDOW) + + testRelation(parentDocAcc, RELATION_EMBEDS, docAcc); + // 'labelled by'/'label for' relation for xul:goupbox and xul:label of // xul:caption var groupboxAcc = getAccessible("groupbox");