diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index aef8071c99c2..3016e0e9d34e 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -1024,8 +1024,21 @@ nsDocAccessible::AttributeChangedImpl(nsIContent* aContent, PRInt32 aNameSpaceID } } - if (aAttribute == nsAccessibilityAtoms::role || - aAttribute == nsAccessibilityAtoms::href || + if (aAttribute == nsAccessibilityAtoms::role) { + if (mContent == aContent) { + // It is common for js libraries to set the role of the body element after + // the doc has loaded. In this case we just update the role map entry. + SetRoleMapEntry(nsAccUtils::GetRoleMapEntry(aContent)); + } + else { + // Recreate the accessible when role is changed because we might require a + // different accessible class for the new role or the accessible may + // expose a different sets of interfaces (COM restriction). + RecreateAccessible(aContent); + } + } + + if (aAttribute == nsAccessibilityAtoms::href || aAttribute == nsAccessibilityAtoms::onclick) { // Not worth the expense to ensure which namespace these are in // It doesn't kill use to recreate the accessible even if the attribute was used diff --git a/accessible/tests/mochitest/test_aria_roles.html b/accessible/tests/mochitest/test_aria_roles.html index 4716e2007bd9..cdab67e4c4e6 100644 --- a/accessible/tests/mochitest/test_aria_roles.html +++ b/accessible/tests/mochitest/test_aria_roles.html @@ -71,6 +71,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=529289 testRole("scrollbar", ROLE_SCROLLBAR); testRole("dir", ROLE_LIST); + // test document role map update + var testDoc = getAccessible(document, [nsIAccessibleDocument]); + testRole(testDoc, ROLE_DOCUMENT); + document.body.setAttribute("role", "application"); + testRole(testDoc, ROLE_APPLICATION); + SimpleTest.finish(); } @@ -84,6 +90,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=529289 Mozilla Bug 469688 Mozilla Bug 520188 Mozilla Bug 529289 + Mozilla Bug 607219