bug 453417 - Implement new aria-label property, r=surkov

This commit is contained in:
Marco Zehe 2008-09-04 16:11:40 +02:00
parent 0cb7388535
commit 5136734521
11 changed files with 83 additions and 65 deletions

View File

@ -213,6 +213,7 @@ ACCESSIBILITY_ATOM(aria_flowto, "aria-flowto")
ACCESSIBILITY_ATOM(aria_grab, "aria-grab")
ACCESSIBILITY_ATOM(aria_haspopup, "aria-haspopup")
ACCESSIBILITY_ATOM(aria_invalid, "aria-invalid")
ACCESSIBILITY_ATOM(aria_label, "aria-label")
ACCESSIBILITY_ATOM(aria_labelledby, "aria-labelledby")
ACCESSIBILITY_ATOM(aria_level, "aria-level")
ACCESSIBILITY_ATOM(aria_live, "aria-live")

View File

@ -1628,6 +1628,7 @@ nsAccessibilityService::HasUniversalAriaProperty(nsIContent *aContent,
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_grab) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_haspopup) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_invalid) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_live) ||
aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_owns) ||

View File

@ -1843,8 +1843,14 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre
return NS_ERROR_FAILURE; // Node shut down
}
// Check for DHTML accessibility labelledby relationship property
// Check for aria-label property
nsAutoString label;
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) {
aLabel = label;
return NS_OK;
}
// Check for aria-labelledby relationship property
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label);
if (NS_SUCCEEDED(rv)) {
aLabel = label;
@ -1894,8 +1900,14 @@ nsresult nsAccessible::GetXULName(nsAString& aLabel, PRBool aCanAggregateSubtree
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
NS_ASSERTION(content, "No nsIContent for DOM node");
// First check for label override via accessibility labelledby relationship
// First check for label override via aria-label property
nsAutoString label;
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) {
aLabel = label;
return NS_OK;
}
// Second check for label override via aria-labelledby relationship
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label);
if (NS_SUCCEEDED(rv)) {
aLabel = label;

View File

@ -288,6 +288,8 @@ nsHTMLButtonAccessible::GetName(nsAString& aName)
nsAutoString name;
// Prefer aria-labelledby attribute for name
if (content->HasAttr(kNameSpaceID_None,
nsAccessibilityAtoms::aria_label) ||
content->HasAttr(kNameSpaceID_None,
nsAccessibilityAtoms::aria_labelledby)) {
GetHTMLName(name, PR_FALSE);
}

View File

@ -143,8 +143,9 @@ NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& aName)
PRBool hasAltAttrib =
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName);
if (aName.IsEmpty()) {
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby)) {
// Use HTML label or DHTML accessibility's labelledby attribute for name
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label) ||
content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby)) {
// Use HTML label or DHTML accessibility's label or labelledby attribute for name
// GetHTMLName will also try title attribute as a last resort
GetHTMLName(aName, PR_FALSE);
}

View File

@ -224,7 +224,19 @@ nsXFormsAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
NS_IMETHODIMP
nsXFormsAccessible::GetName(nsAString& aName)
{
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (!content) {
return NS_ERROR_FAILURE; // Node shut down
}
// Check for ARIA label property
nsAutoString name;
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, name)) {
aName = name;
return NS_OK;
}
// Check for ARIA labelledby relationship property
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, name);
if (NS_SUCCEEDED(rv) && !name.IsEmpty()) {
aName = name;

View File

@ -58,6 +58,7 @@ nsXFormsLabelAccessible::GetRole(PRUint32 *aRole)
NS_IMETHODIMP
nsXFormsLabelAccessible::GetName(nsAString& aName)
{
// XXX Correct name calculation for this, see bug 453594.
nsAutoString name;
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, name);
aName = name;

View File

@ -51,6 +51,7 @@ _TEST_FILES =\
common.js \
nsIAccessible_actions.js \
nsIAccessible_name.css \
nsIAccessible_name.js \
nsIAccessible_name.xbl \
nsIAccessibleEditableText.js \
test_aria_activedescendant.html \

View File

@ -0,0 +1,10 @@
function testName(aID, aName)
{
var acc = getAccessible(aID);
if (!acc) {
ok(false, "No accessible for " + aID + "!");
}
is(acc.name, aName, "Wrong name of the accessible for " + aID);
return acc;
}

View File

@ -4,42 +4,25 @@
<title>nsIAccessible::name calculation</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"
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"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/nsIAccessible_name.js"></script>
<script type="application/javascript">
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessibleRole = Components.interfaces.nsIAccessibleRole;
var gAccRetrieval = null;
function testName(aID, aName)
{
var elm = document.getElementById(aID);
if (!elm) {
ok(false, "There is no element with ID " + aID);
return;
}
var acc = null;
try {
acc = gAccRetrieval.getAccessibleFor(elm);
} catch(e) {
}
if (!acc) {
ok(false, "There is no accessible for " + aID);
return;
}
is(acc.name, aName, "Wrong name of the accessible for " + aID);
}
function doTest()
{
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
// aria-label
// Simple label provided via ARIA
testName("btn_simple_aria_label", "I am a button");
// aria-label and aria-labelledby, expect aria-label
testName("btn_both_aria_labels", "I am a button, two");
//////////////////////////////////////////////////////////////////////////
// aria-labelledby
@ -153,6 +136,14 @@
<pre id="test">
</pre>
<!-- aria-label, simple label -->
<span id="btn_simple_aria_label" role="button" aria-label="I am a button"/>
<br/>
<!-- aria-label plus aria-labelledby -->
<span id="btn_both_aria_labels" role="button" aria-label="I am a button, two"
aria-labelledby="labelledby_text"/>
<br/>
<!-- aria-labelledby, single relation -->
<span id="labelledby_text">text</span>
<button id="btn_labelledby_text"

View File

@ -13,41 +13,21 @@
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/nsIAccessible_name.js"></script>
<script type="application/javascript">
<![CDATA[
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessibleRole = Components.interfaces.nsIAccessibleRole;
var gAccRetrieval = null;
function testName(aID, aName)
{
var elm = document.getElementById(aID);
if (!elm) {
ok(false, "There is no element with ID " + aID);
return null;
}
var acc = null;
try {
acc = gAccRetrieval.getAccessibleFor(elm);
} catch(e) {
}
if (!acc) {
ok(false, "There is no accessible for " + aID);
return null;
}
is(acc.name, aName, "Wrong name of the accessible for " + aID);
return acc;
}
function doTest()
{
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
// aria-label
// Simple label provided via ARIA
testName("btn_simple_aria_label", "I am a button");
// aria-label and aria-labelledby, expect aria-label
testName("btn_both_aria_labels", "I am a button, two");
//////////////////////////////////////////////////////////////////////////
// aria-labelledby
@ -198,6 +178,12 @@
</pre>
</body>
<!-- aria-label, simple label -->
<button id="btn_simple_aria_label" aria-label="I am a button"/>
<!-- aria-label plus aria-labelledby -->
<button id="btn_both_aria_labels" aria-label="I am a button, two"
aria-labelledby="labelledby_text"/>
<!-- aria-labelledby, single relation -->
<description id="labelledby_text">text</description>
<button id="btn_labelledby_text"