bug 429285 - Propagate aria-disabled to descendants, patch by aaronlev, test by me, r=surkov

This commit is contained in:
Marco Zehe 2008-06-16 07:45:58 +02:00
parent 617a618bca
commit 508ce96717
3 changed files with 130 additions and 13 deletions

View File

@ -2468,24 +2468,39 @@ nsAccessible::GetARIAState(PRUint32 *aState)
++ index;
}
if (!mRoleMapEntry)
return NS_OK;
if (mRoleMapEntry) {
// Once DHTML role is used, we're only readonly if DHTML readonly used
*aState &= ~nsIAccessibleStates::STATE_READONLY;
// Once DHTML role is used, we're only readonly if DHTML readonly used
*aState &= ~nsIAccessibleStates::STATE_READONLY;
if (content->HasAttr(kNameSpaceID_None, content->GetIDAttributeName())) {
// If has a role & ID and aria-activedescendant on the container, assume focusable
nsIContent *ancestorContent = content;
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
if (ancestorContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant)) {
// ancestor has activedescendant property, this content could be active
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
break;
if (content->HasAttr(kNameSpaceID_None, content->GetIDAttributeName())) {
// If has a role & ID and aria-activedescendant on the container, assume focusable
nsIContent *ancestorContent = content;
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
if (ancestorContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant)) {
// ancestor has activedescendant property, this content could be active
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
break;
}
}
}
}
if (*aState & nsIAccessibleStates::STATE_FOCUSABLE) {
// Special case: aria-disabled propagates from ancestors down to any focusable descendant
nsIContent *ancestorContent = content;
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
if (ancestorContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_disabled,
nsAccessibilityAtoms::_true, eCaseMatters)) {
// ancestor has aria-disabled property, this is disabled
*aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
break;
}
}
}
if (!mRoleMapEntry)
return NS_OK;
*aState |= mRoleMapEntry->state;
if (MappedAttrState(content, aState, &mRoleMapEntry->attributeMap1) &&
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap2) &&

View File

@ -62,6 +62,7 @@ _TEST_FILES =\
test_nsIAccessibleHyperText.html \
test_nsIAccessibleImage.html \
test_bug428479.html \
test_bug429285.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,101 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=429285
-->
<head>
<title>Propagate aria-disabled state to descendants chrome tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
// Mapping needed state flags for easier handling.
const state_disabled =
Components.interfaces.nsIAccessibleStates.STATE_UNAVAILABLE;
const state_focusable =
Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessible = Components.interfaces.nsIAccessible;
var gAccRetrieval = null;
function testChildren(aID, aAcc)
{
// Check state of aAcc first.
var state = {}, extraState = {};
aAcc.getFinalState(state, extraState);
if (state.value & state_focusable) {
is(state.value & state_disabled, state_disabled,
"Wrong disabled state bit for " + aID + "!");
}
// Iterate over its children to see if they are disabled, too.
var children = null;
try {
children = aAcc.children;
} catch(e) {}
ok(children, "Could not get children for " + aID +"!");
if (children) {
for (var i=0; i<children.length; i++) {
var childAcc = children.queryElementAt(i, nsIAccessible);
// Test and recurse over its children as well.
testChildren(childAcc.name, childAcc);
}
}
}
function doTest()
{
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
var groupItem = document.getElementById("group");
var groupAcc = null;
try {
groupAcc = gAccRetrieval.getAccessibleFor(groupItem);
} catch (e) {}
ok (groupAcc,
"No accessible for group element!");
if (groupAcc) {
var state = {}, extraState = {};
groupAcc.getFinalState(state, extraState);
is(state.value & state_disabled, state_disabled,
"Wrong disabled state bit for Group element!");
testChildren("group", groupAcc);
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=429285"
title="Propagate aria-disabled to descendants">
Mozilla Bug 429285
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="group" role="group" aria-disabled="true">
<button>hi</button>
<div tabindex="0" role="listbox" aria-activedescendant="item1">
<div role="option" id="item1">Item 1</div>
<div role="option" id="item2">Item 2</div>
<div role="option" id="item3">Item 3</div>
<div role="option" id="item4">Item 4</div>
</div>
<div role="slider" tabindex="0">A slider</div>
</div>
</body>
</html>