зеркало из https://github.com/mozilla/gecko-dev.git
Bug 459357 - Support accessible name computation for SVG, r=tbsaunde
This commit is contained in:
Родитель
e1a410c7ea
Коммит
2571318e83
|
@ -264,6 +264,16 @@ Accessible::Name(nsString& aName)
|
|||
aName.CompressWhitespace();
|
||||
return eNameFromTooltip;
|
||||
}
|
||||
} else if (mContent->IsSVG()) {
|
||||
// If user agents need to choose among multiple ‘desc’ or ‘title’ elements
|
||||
// for processing, the user agent shall choose the first one.
|
||||
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
||||
childElm = childElm->GetNextSibling()) {
|
||||
if (childElm->IsSVG(nsGkAtoms::title)) {
|
||||
nsTextEquivUtils::AppendTextEquivFromContent(this, childElm, &aName);
|
||||
return eNameFromTooltip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nameFlag != eNoNameOnPurpose)
|
||||
|
@ -307,25 +317,40 @@ Accessible::Description(nsString& aDescription)
|
|||
// Try XUL <description control="[id]">description text</description>
|
||||
XULDescriptionIterator iter(Document(), mContent);
|
||||
Accessible* descr = nullptr;
|
||||
while ((descr = iter.Next()))
|
||||
while ((descr = iter.Next())) {
|
||||
nsTextEquivUtils::AppendTextEquivFromContent(this, descr->GetContent(),
|
||||
&aDescription);
|
||||
}
|
||||
}
|
||||
|
||||
if (aDescription.IsEmpty()) {
|
||||
nsIAtom *descAtom = isXUL ? nsGkAtoms::tooltiptext :
|
||||
nsGkAtoms::title;
|
||||
if (mContent->GetAttr(kNameSpaceID_None, descAtom, aDescription)) {
|
||||
nsAutoString name;
|
||||
Name(name);
|
||||
if (name.IsEmpty() || aDescription == name)
|
||||
// Don't use tooltip for a description if this object
|
||||
// has no name or the tooltip is the same as the name
|
||||
aDescription.Truncate();
|
||||
if (aDescription.IsEmpty()) {
|
||||
// Keep the Name() method logic.
|
||||
if (mContent->IsHTML()) {
|
||||
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aDescription);
|
||||
} else if (mContent->IsXUL()) {
|
||||
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, aDescription);
|
||||
} else if (mContent->IsSVG()) {
|
||||
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
||||
childElm = childElm->GetNextSibling()) {
|
||||
if (childElm->IsSVG(nsGkAtoms::title)) {
|
||||
nsTextEquivUtils::AppendTextEquivFromContent(this, childElm,
|
||||
&aDescription);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!aDescription.IsEmpty()) {
|
||||
nsAutoString name;
|
||||
ENameValueFlag nameFlag = Name(name);
|
||||
|
||||
// Don't use tooltip for a description if it was used for a name.
|
||||
if (nameFlag == eNameFromTooltip)
|
||||
aDescription.Truncate();
|
||||
}
|
||||
}
|
||||
aDescription.CompressWhitespace();
|
||||
}
|
||||
aDescription.CompressWhitespace();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -2494,6 +2519,18 @@ Accessible::NativeName(nsString& aName)
|
|||
if (mContent->IsXUL())
|
||||
return GetXULName(aName);
|
||||
|
||||
if (mContent->IsSVG()) {
|
||||
// If user agents need to choose among multiple ‘desc’ or ‘title’ elements
|
||||
// for processing, the user agent shall choose the first one.
|
||||
for (nsIContent* childElm = mContent->GetFirstChild(); childElm;
|
||||
childElm = childElm->GetNextSibling()) {
|
||||
if (childElm->IsSVG(nsGkAtoms::desc)) {
|
||||
nsTextEquivUtils::AppendTextEquivFromContent(this, childElm, &aName);
|
||||
return eNameOK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eNameOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,3 +17,16 @@ function testName(aAccOrElmOrID, aName, aMsg)
|
|||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test accessible description for the given accessible.
|
||||
*/
|
||||
function testDescr(aAccOrElmOrID, aDescr)
|
||||
{
|
||||
var acc = getAccessible(aAccOrElmOrID);
|
||||
if (!acc)
|
||||
return;
|
||||
|
||||
is(acc.description, aDescr,
|
||||
"Wrong description for " + prettyName(aAccOrElmOrID));
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ MOCHITEST_A11Y_FILES =\
|
|||
test_link.html \
|
||||
test_list.html \
|
||||
test_markup.html \
|
||||
test_svg.html \
|
||||
test_browserui.xul \
|
||||
test_tree.xul \
|
||||
markuprules.xml \
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>Accessible name and description for SVG elements</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<script type="application/javascript"
|
||||
src="../common.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="../name.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
|
||||
function doTest()
|
||||
{
|
||||
testName("svg1", "A name");
|
||||
testDescr("svg1", "A description");
|
||||
testName("svg2", "A tooltip");
|
||||
testDescr("svg2", "");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addA11yLoadEvent(doTest);
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=459357"
|
||||
title="Support accessible name computation for SVG">
|
||||
Mozilla Bug 459357
|
||||
</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="svg1">
|
||||
<title>A description</title>
|
||||
<desc>A name</desc>
|
||||
</svg>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="svg2">
|
||||
<title>A tooltip</title>
|
||||
</svg>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -8,18 +8,10 @@
|
|||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="common.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="name.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
function testDescr(aAccOrElmOrID, aDescr)
|
||||
{
|
||||
var acc = getAccessible(aAccOrElmOrID);
|
||||
if (!acc)
|
||||
return;
|
||||
|
||||
is(acc.description, aDescr,
|
||||
"Wrong description for " + prettyName(aAccOrElmOrID));
|
||||
}
|
||||
|
||||
function doTest()
|
||||
{
|
||||
// Description from aria-describedby attribute
|
||||
|
|
Загрузка…
Ссылка в новой задаче