Skip to content

Commit

Permalink
Bug 1001637 - Make math tables implement the nsIAccessibleTable inter…
Browse files Browse the repository at this point in the history
…face. r=surkov
  • Loading branch information
fred-wang committed Mar 19, 2015
1 parent 2de1821 commit f5e4a8f
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 12 deletions.
8 changes: 4 additions & 4 deletions accessible/base/MarkupMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,22 @@ MARKUPMAP(mmultiscripts_,
roles::MATHML_MULTISCRIPTS)

MARKUPMAP(mtable_,
New_HyperText,
New_HTMLTableAccessible,
roles::MATHML_TABLE,
AttrFromDOM(align, align),
AttrFromDOM(columnlines_, columnlines_),
AttrFromDOM(rowlines_, rowlines_))

MARKUPMAP(mlabeledtr_,
New_HyperText,
New_HTMLTableRowAccessible,
roles::MATHML_LABELED_ROW)

MARKUPMAP(mtr_,
New_HyperText,
New_HTMLTableRowAccessible,
roles::MATHML_TABLE_ROW)

MARKUPMAP(mtd_,
New_HyperText,
New_HTMLTableCellAccessible,
roles::MATHML_CELL)

MARKUPMAP(maction_,
Expand Down
12 changes: 12 additions & 0 deletions accessible/base/nsAccessibilityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ static Accessible* New_HTMLOutput(nsIContent* aContent, Accessible* aContext)
static Accessible* New_HTMLProgress(nsIContent* aContent, Accessible* aContext)
{ return new HTMLProgressMeterAccessible(aContent, aContext->Document()); }

static Accessible*
New_HTMLTableAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableAccessible(aContent, aContext->Document()); }

static Accessible*
New_HTMLTableRowAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableRowAccessible(aContent, aContext->Document()); }

static Accessible*
New_HTMLTableCellAccessible(nsIContent* aContent, Accessible* aContext)
{ return new HTMLTableCellAccessible(aContent, aContext->Document()); }

static Accessible*
New_HTMLTableHeaderCell(nsIContent* aContent, Accessible* aContext)
{
Expand Down
19 changes: 17 additions & 2 deletions accessible/html/HTMLTableAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableCellAccessible, HyperTextAccessible)
role
HTMLTableCellAccessible::NativeRole()
{
if (mContent->IsMathMLElement(nsGkAtoms::mtd_)) {
return roles::MATHML_CELL;
}
return roles::CELL;
}

Expand Down Expand Up @@ -148,8 +151,7 @@ HTMLTableCellAccessible::Table() const
{
Accessible* parent = const_cast<HTMLTableCellAccessible*>(this);
while ((parent = parent->Parent())) {
roles::Role role = parent->Role();
if (role == roles::TABLE || role == roles::TREE_TABLE)
if (parent->IsTable())
return parent->AsTable();
}

Expand Down Expand Up @@ -349,6 +351,11 @@ NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableRowAccessible, Accessible)
role
HTMLTableRowAccessible::NativeRole()
{
if (mContent->IsMathMLElement(nsGkAtoms::mtr_)) {
return roles::MATHML_TABLE_ROW;
} else if (mContent->IsMathMLElement(nsGkAtoms::mlabeledtr_)) {
return roles::MATHML_LABELED_ROW;
}
return roles::ROW;
}

Expand Down Expand Up @@ -384,6 +391,9 @@ HTMLTableAccessible::CacheChildren()
role
HTMLTableAccessible::NativeRole()
{
if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) {
return roles::MATHML_TABLE;
}
return roles::TABLE;
}

Expand Down Expand Up @@ -421,6 +431,11 @@ HTMLTableAccessible::NativeAttributes()
{
nsCOMPtr<nsIPersistentProperties> attributes =
AccessibleWrap::NativeAttributes();

if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) {
GetAccService()->MarkupAttributes(mContent, attributes);
}

if (IsProbablyLayoutTable()) {
nsAutoString unused;
attributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"),
Expand Down
29 changes: 24 additions & 5 deletions accessible/tests/mochitest/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const kNoColumnHeader = 0;
const kListboxColumnHeader = 1;
const kTreeColumnHeader = 2;

/**
* Constants to define table type.
*/
const kTable = 0;
const kTreeTable = 1;
const kMathTable = 2;

/**
* Test table structure and related methods.
*
Expand All @@ -37,10 +44,11 @@ const kTreeColumnHeader = 2;
* arranged into the list.
* @param aCaption [in] caption text if any
* @param aSummary [in] summary text if any
* @param aIsTreeTable [in] specifies whether given table is tree table
* @param aTableType [in] specifies the table type.
* @param aRowRoles [in] array of row roles.
*/
function testTableStruct(aIdentifier, aCellsArray, aColHeaderType,
aCaption, aSummary, aIsTreeTable)
aCaption, aSummary, aTableType, aRowRoles)
{
var tableNode = getNode(aIdentifier);
var isGrid = tableNode.getAttribute("role") == "grid" ||
Expand All @@ -52,9 +60,19 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType,

// Test table accessible tree.
var tableObj = {
role: aIsTreeTable ? ROLE_TREE_TABLE : ROLE_TABLE,
children: []
};
switch (aTableType) {
case kTable:
tableObj.role = ROLE_TABLE;
break;
case kTreeTable:
tableObj.role = ROLE_TREE_TABLE;
break;
case kMathTable:
tableObj.role = ROLE_MATHML_TABLE;
break;
}

// caption accessible handling
if (aCaption) {
Expand Down Expand Up @@ -99,7 +117,7 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType,
// rows and cells accessibles
for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) {
var rowObj = {
role: ROLE_ROW,
role: aRowRoles ? aRowRoles[rowIdx] : ROLE_ROW,
children: []
};

Expand All @@ -109,7 +127,8 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType,
var role = ROLE_NOTHING;
switch (celltype) {
case kDataCell:
role = (isGrid ? ROLE_GRID_CELL : ROLE_CELL);
role = (aTableType == kMathTable ? ROLE_MATHML_CELL :
(isGrid ? ROLE_GRID_CELL : ROLE_CELL));
break;
case kRowHeaderCell:
role = ROLE_ROWHEADER;
Expand Down
1 change: 1 addition & 0 deletions accessible/tests/mochitest/table/a11y.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[test_indexes_table.html]
[test_indexes_tree.xul]
[test_layoutguess.html]
[test_mtable.html]
[test_sels_ariagrid.html]
[test_sels_listbox.xul]
[test_sels_table.html]
Expand Down
128 changes: 128 additions & 0 deletions accessible/tests/mochitest/table/test_mtable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<!DOCTYPE html>
<html>
<head>
<title>MathML table tests</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="../role.js"></script>
<script type="application/javascript"
src="../table.js"></script>

<script type="application/javascript">
function doTest()
{
// 'Simple' table
var idxes = [
[0, 1],
[2, 3]
];
testTableIndexes("simple", idxes);
var cellsArray = [
[kDataCell, kDataCell],
[kDataCell, kDataCell]
];
var rowsArray = [ROLE_MATHML_TABLE_ROW, ROLE_MATHML_TABLE_ROW];
testTableStruct("simple", cellsArray, kNoColumnHeader,
"", "", kMathTable, rowsArray);

// 'Complex' table
idxes = [
[0, 0, 0],
[1, 1, 2],
[1, 1, 3]
];
testTableIndexes("complex", idxes);
cellsArray = [
[kDataCell, kColSpanned, kColSpanned],
[kDataCell, kColSpanned, kDataCell],
[kRowSpanned, kSpanned, kDataCell],
];
rowsArray = [
ROLE_MATHML_TABLE_ROW,
ROLE_MATHML_TABLE_ROW,
ROLE_MATHML_TABLE_ROW
];
testTableStruct("complex", cellsArray, kNoColumnHeader,
"", "", kMathTable, rowsArray);

// 'Simple' table with mlabeledtr
// At the moment we do not implement mlabeledtr but just hide the label
// with display: none. Thus we just test the role for now. See bug 689641.
var idxes = [[0]];
testTableIndexes("simple_label", idxes);
var cellsArray = [[kDataCell]];
rowsArray = [ROLE_MATHML_LABELED_ROW];
testTableStruct("simple_label", cellsArray, kNoColumnHeader,
"", "", kMathTable, rowsArray);

SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>

<math>
<mtable id="simple">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>

<mtable id="complex">
<mtr>
<mtd columnspan="3">
<mtext>1 x 3</mtext>
</mtd>
</mtr>
<mtr>
<mtd rowspan="2" columnspan="2">
<mtext>2 x 2</mtext>
</mtd>
<mtd>
<mtext>1 x 1</mtext>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext>1 x 1</mtext>
</mtd>
</mtr>
</mtable>

<mtable id="simple_label">
<mlabeledtr>
<mtd><mtext>1</mtext></mtd>
<mtd><mtext>label</mtext></mtd>
</mlabeledtr>
</mtable>
</math>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
[kDataCell, kDataCell, kDataCell]
];

testTableStruct("treegrid", cellsArray, kNoColumnHeader, "", "", true);
testTableStruct("treegrid", cellsArray, kNoColumnHeader, "", "",
kTreeTable);

SimpleTest.finish();
}
Expand Down

0 comments on commit f5e4a8f

Please sign in to comment.