Bug 445510 - Support ARIA-based text attributes, r=tbsaunde

--HG--
rename : accessible/tests/mochitest/attributes/test_text.html => accessible/tests/mochitest/textattrs/test_general.html
This commit is contained in:
Alexander Surkov 2013-02-09 13:36:34 +09:00
parent 9622013d21
commit 176065e86a
8 changed files with 202 additions and 1 deletions

View File

@ -83,6 +83,9 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes,
// "language" text attribute
LangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
// "aria-invalid" text attribute
InvalidTextAttr invalidTextAttr(hyperTextElm, offsetNode);
// "background-color" text attribute
BGColorTextAttr bgColorTextAttr(rootFrame, frame);
@ -113,6 +116,7 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes,
TextAttr* attrArray[] =
{
&langTextAttr,
&invalidTextAttr,
&bgColorTextAttr,
&colorTextAttr,
&fontFamilyTextAttr,
@ -226,6 +230,88 @@ TextAttrsMgr::LangTextAttr::
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::language, aValue);
}
////////////////////////////////////////////////////////////////////////////////
// InvalidTextAttr
////////////////////////////////////////////////////////////////////////////////
TextAttrsMgr::InvalidTextAttr::
InvalidTextAttr(nsIContent* aRootElm, nsIContent* aElm) :
TTextAttr<uint32_t>(!aElm), mRootElm(aRootElm)
{
mIsRootDefined = GetValue(mRootElm, &mRootNativeValue);
if (aElm)
mIsDefined = GetValue(aElm, &mNativeValue);
}
bool
TextAttrsMgr::InvalidTextAttr::
GetValueFor(Accessible* aAccessible, uint32_t* aValue)
{
nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent());
return elm ? GetValue(elm, aValue) : false;
}
void
TextAttrsMgr::InvalidTextAttr::
ExposeValue(nsIPersistentProperties* aAttributes, const uint32_t& aValue)
{
switch (aValue) {
case eFalse:
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid,
NS_LITERAL_STRING("false"));
break;
case eGrammar:
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid,
NS_LITERAL_STRING("grammar"));
break;
case eSpelling:
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid,
NS_LITERAL_STRING("spelling"));
break;
case eTrue:
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid,
NS_LITERAL_STRING("true"));
break;
}
}
bool
TextAttrsMgr::InvalidTextAttr::
GetValue(nsIContent* aElm, uint32_t* aValue)
{
nsIContent* elm = aElm;
do {
if (nsAccUtils::HasDefinedARIAToken(elm, nsGkAtoms::aria_invalid)) {
static nsIContent::AttrValuesArray tokens[] =
{ &nsGkAtoms::_false, &nsGkAtoms::grammar, &nsGkAtoms::spelling,
nullptr };
int32_t idx = elm->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::aria_invalid, tokens,
eCaseMatters);
switch (idx) {
case 0:
*aValue = eFalse;
return true;
case 1:
*aValue = eGrammar;
return true;
case 2:
*aValue = eSpelling;
return true;
default:
*aValue = eTrue;
return true;
}
}
} while ((elm = elm->GetParent()) && elm != mRootElm);
return false;
}
////////////////////////////////////////////////////////////////////////////////
// BGColorTextAttr

View File

@ -212,6 +212,38 @@ protected:
};
/**
* Class is used for the 'invalid' text attribute. Note, it calculated
* the attribute from aria-invalid attribute only; invalid:spelling attribute
* calculated from misspelled text in the editor is managed by
* HyperTextAccessible and applied on top of the value from aria-invalid.
*/
class InvalidTextAttr : public TTextAttr<uint32_t>
{
public:
InvalidTextAttr(nsIContent* aRootElm, nsIContent* aElm);
virtual ~InvalidTextAttr() { };
protected:
enum {
eFalse,
eGrammar,
eSpelling,
eTrue
};
// TextAttr
virtual bool GetValueFor(Accessible* aAccessible, uint32_t* aValue);
virtual void ExposeValue(nsIPersistentProperties* aAttributes,
const uint32_t& aValue);
private:
bool GetValue(nsIContent* aElm, uint32_t* aValue);
nsIContent* mRootElm;
};
/**
* Class is used for the work with 'background-color' text attribute.
*/

View File

@ -29,6 +29,7 @@ DIRS = \
states \
table \
text \
textattrs \
textcaret \
textselection \
tree \

View File

@ -19,7 +19,6 @@ MOCHITEST_A11Y_FILES =\
test_obj_group.xul \
test_obj_group_tree.xul \
test_tag.html \
test_text.html \
test_xml-roles.html \
$(NULL)

View File

@ -0,0 +1,19 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = accessible/textattrs
include $(DEPTH)/config/autoconf.mk
MOCHITEST_A11Y_FILES =\
test_general.html \
test_invalid.html \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,62 @@
<html>
<head>
<title>Invalid text attribute</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="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../role.js"></script>
<script type="application/javascript"
src="../states.js"></script>
<script type="application/javascript"
src="../events.js"></script>
<script type="application/javascript"
src="../attributes.js"></script>
<script type="application/javascript">
function doTests()
{
testDefaultTextAttrs("aria_invalid_empty", {}, true);
testDefaultTextAttrs("aria_invalid_true", { "invalid": "true" }, true);
testDefaultTextAttrs("aria_invalid_false", { "invalid": "false" }, true);
testDefaultTextAttrs("aria_invalid_grammar", { "invalid": "grammar" }, true);
testDefaultTextAttrs("aria_invalid_spelling", { "invalid": "spelling" }, true);
testDefaultTextAttrs("aria_invalid_erroneous", { "invalid": "true" }, true);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTests);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=445510"
title="Support ARIA-based text attributes">
Mozilla Bug 445510
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="aria_invalid_empty" aria-invalid="">no invalid</div>
<div id="aria_invalid_true" aria-invalid="true">invalid:true</div>
<div id="aria_invalid_false" aria-invalid="false">invalid:false</div>
<div id="aria_invalid_grammar" aria-invalid="grammar">invalid:grammar</div>
<div id="aria_invalid_spelling" aria-invalid="spelling">invalid:spelling</div>
<div id="aria_invalid_erroneous" aria-invalid="erroneous">invalid:true</div>
</body>
</html>

View File

@ -2100,6 +2100,7 @@ GK_ATOM(datatable, "datatable")
GK_ATOM(directory, "directory")
GK_ATOM(droppable, "droppable")
GK_ATOM(eventFromInput, "event-from-input")
GK_ATOM(grammar, "grammar")
GK_ATOM(gridcell, "gridcell")
GK_ATOM(heading, "heading")
GK_ATOM(InlineBlockFrame, "InlineBlockFrame")
@ -2127,6 +2128,7 @@ GK_ATOM(rowgroup, "rowgroup")
GK_ATOM(rowheader, "rowheader")
GK_ATOM(select1, "select1")
GK_ATOM(setsize, "setsize")
GK_ATOM(spelling, "spelling")
GK_ATOM(spinbutton, "spinbutton")
GK_ATOM(status, "status")
GK_ATOM(tableCellIndex, "table-cell-index")