From e33f660697824683d306d85d70c4040ee46e0073 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Wed, 13 May 2009 13:13:12 +0800 Subject: [PATCH] Bug 492530 - allow aria-labelledby to work in anonymous content, r=marcoz, davidb --HG-- rename : accessible/tests/mochitest/nsIAccessible_name.css => accessible/tests/mochitest/name.css rename : accessible/tests/mochitest/nsIAccessible_name.js => accessible/tests/mochitest/name.js rename : accessible/tests/mochitest/nsIAccessible_name.xbl => accessible/tests/mochitest/name.xbl rename : accessible/tests/mochitest/test_nsIAccessible_name.html => accessible/tests/mochitest/test_name.html rename : accessible/tests/mochitest/test_nsIAccessible_name.xul => accessible/tests/mochitest/test_name.xul rename : accessible/tests/mochitest/test_nsIAccessible_name_button.html => accessible/tests/mochitest/test_name_button.html rename : accessible/tests/mochitest/test_nsIAccessible_name_link.html => accessible/tests/mochitest/test_name_link.html --- accessible/src/base/nsCoreUtils.cpp | 24 +++++++++++++++---- accessible/tests/mochitest/Makefile.in | 14 +++++------ .../{nsIAccessible_name.css => name.css} | 6 ++--- .../{nsIAccessible_name.js => name.js} | 5 ++-- .../{nsIAccessible_name.xbl => name.xbl} | 8 +++++++ ...nsIAccessible_name.html => test_name.html} | 6 +++-- ...t_nsIAccessible_name.xul => test_name.xul} | 18 ++++++++++++-- ...name_button.html => test_name_button.html} | 3 ++- ...ble_name_link.html => test_name_link.html} | 3 ++- .../tests/mochitest/test_name_markup.html | 3 ++- 10 files changed, 67 insertions(+), 23 deletions(-) rename accessible/tests/mochitest/{nsIAccessible_name.css => name.css} (70%) rename accessible/tests/mochitest/{nsIAccessible_name.js => name.js} (98%) rename accessible/tests/mochitest/{nsIAccessible_name.xbl => name.xbl} (67%) rename accessible/tests/mochitest/{test_nsIAccessible_name.html => test_name.html} (98%) rename accessible/tests/mochitest/{test_nsIAccessible_name.xul => test_name.xul} (96%) rename accessible/tests/mochitest/{test_nsIAccessible_name_button.html => test_name_button.html} (98%) rename accessible/tests/mochitest/{test_nsIAccessible_name_link.html => test_name_link.html} (96%) diff --git a/accessible/src/base/nsCoreUtils.cpp b/accessible/src/base/nsCoreUtils.cpp index 0dd6c492352..2a0577749c8 100644 --- a/accessible/src/base/nsCoreUtils.cpp +++ b/accessible/src/base/nsCoreUtils.cpp @@ -749,18 +749,22 @@ nsCoreUtils::GetElementsByIDRefsAttr(nsIContent *aContent, nsIAtom *aAttr, nsIArray **aRefElements) { *aRefElements = nsnull; - + nsAutoString ids; if (!aContent->GetAttr(kNameSpaceID_None, aAttr, ids)) return; - + ids.CompressWhitespace(PR_TRUE, PR_TRUE); - + nsCOMPtr document = do_QueryInterface(aContent->GetOwnerDoc()); NS_ASSERTION(document, "The given node is not in document!"); if (!document) return; + nsCOMPtr xblDocument; + if (aContent->IsInAnonymousSubtree()) + xblDocument = do_QueryInterface(document); + nsCOMPtr refElms = do_CreateInstance(NS_ARRAY_CONTRACTID); while (!ids.IsEmpty()) { @@ -777,8 +781,20 @@ nsCoreUtils::GetElementsByIDRefsAttr(nsIContent *aContent, nsIAtom *aAttr, ids.Cut(0, idLength + 1); } + // If content is anonymous subtree then use "anonid" attribute to get + // elements, otherwise search elements in DOM by ID attribute. nsCOMPtr refElement; - document->GetElementById(id, getter_AddRefs(refElement)); + if (xblDocument) { + nsCOMPtr elm = + do_QueryInterface(aContent->GetBindingParent()); + xblDocument->GetAnonymousElementByAttribute(elm, + NS_LITERAL_STRING("anonid"), + id, + getter_AddRefs(refElement)); + } else { + document->GetElementById(id, getter_AddRefs(refElement)); + } + if (!refElement) continue; diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 94cc209ab3e..be2fa53d2ce 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -56,10 +56,10 @@ _TEST_FILES =\ events.js \ grid.js \ layout.js \ + name.css \ + name.js \ + name.xbl \ namerules.xml \ - nsIAccessible_name.css \ - nsIAccessible_name.js \ - nsIAccessible_name.xbl \ nsIAccessible_selects.js \ nsIAccessible_states.js \ nsIAccessibleEditableText.js \ @@ -88,14 +88,14 @@ _TEST_FILES =\ test_events_tree.xul \ test_groupattrs.xul \ test_groupattrs.html \ + test_name.html \ + test_name.xul \ + test_name_button.html \ + test_name_link.html \ test_name_markup.html \ $(warning test_table_indexes.html temporarily disabled) \ test_nsIAccessible_applicationAccessible.html \ $(warning test_nsIAccessible_comboboxes.xul temporarily disabled) \ - test_nsIAccessible_name.html \ - test_nsIAccessible_name_button.html \ - test_nsIAccessible_name_link.html \ - test_nsIAccessible_name.xul \ test_nsIAccessible_selects.html \ test_nsIAccessible_focus.html \ test_nsIAccessibleDocument.html \ diff --git a/accessible/tests/mochitest/nsIAccessible_name.css b/accessible/tests/mochitest/name.css similarity index 70% rename from accessible/tests/mochitest/nsIAccessible_name.css rename to accessible/tests/mochitest/name.css index 252132631a5..c54b3b434b9 100644 --- a/accessible/tests/mochitest/nsIAccessible_name.css +++ b/accessible/tests/mochitest/name.css @@ -1,11 +1,11 @@ box.first { - -moz-binding: url('chrome://mochikit/content/a11y/accessible/nsIAccessible_name.xbl#first'); + -moz-binding: url('chrome://mochikit/content/a11y/accessible/name.xbl#first'); } .second { - -moz-binding: url('chrome://mochikit/content/a11y/accessible/nsIAccessible_name.xbl#second'); + -moz-binding: url('chrome://mochikit/content/a11y/accessible/name.xbl#second'); } .third { - -moz-binding: url('chrome://mochikit/content/a11y/accessible/nsIAccessible_name.xbl#third'); + -moz-binding: url('chrome://mochikit/content/a11y/accessible/name.xbl#third'); } \ No newline at end of file diff --git a/accessible/tests/mochitest/nsIAccessible_name.js b/accessible/tests/mochitest/name.js similarity index 98% rename from accessible/tests/mochitest/nsIAccessible_name.js rename to accessible/tests/mochitest/name.js index ba5ad487c31..fcb3d9b3698 100644 --- a/accessible/tests/mochitest/nsIAccessible_name.js +++ b/accessible/tests/mochitest/name.js @@ -6,10 +6,11 @@ function testName(aAccOrElmOrID, aName, aMsg) if (!acc) return; + var txtID = prettyName(aAccOrElmOrID); try { - is(acc.name, aName, msg + "Wrong name of the accessible for " + aAccOrElmOrID); + is(acc.name, aName, msg + "Wrong name of the accessible for " + txtID); } catch (e) { - ok(false, msg + "Can't get name of the accessible for " + aAccOrElmOrID); + ok(false, msg + "Can't get name of the accessible for " + txtID); } return acc; } diff --git a/accessible/tests/mochitest/nsIAccessible_name.xbl b/accessible/tests/mochitest/name.xbl similarity index 67% rename from accessible/tests/mochitest/nsIAccessible_name.xbl rename to accessible/tests/mochitest/name.xbl index 8e95e8d012f..07489f5f4ed 100644 --- a/accessible/tests/mochitest/nsIAccessible_name.xbl +++ b/accessible/tests/mochitest/name.xbl @@ -21,4 +21,12 @@ + + + + + + + diff --git a/accessible/tests/mochitest/test_nsIAccessible_name.html b/accessible/tests/mochitest/test_name.html similarity index 98% rename from accessible/tests/mochitest/test_nsIAccessible_name.html rename to accessible/tests/mochitest/test_name.html index 223d155bab2..c50b5dbf0d4 100644 --- a/accessible/tests/mochitest/test_nsIAccessible_name.html +++ b/accessible/tests/mochitest/test_name.html @@ -2,16 +2,18 @@ nsIAccessible::name calculation - + + + src="chrome://mochikit/content/a11y/accessible/name.js"> + src="chrome://mochikit/content/a11y/accessible/name.js"> + + + + +