Bug 1130793 - wrong class is used for ARIA grid cell contained by HTML tr@role='row', r=yzen

This commit is contained in:
Alexander Surkov 2015-02-13 20:09:51 -05:00
parent babb280125
commit 077031b551
6 changed files with 102 additions and 40 deletions

View File

@ -970,51 +970,50 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode,
}
if (!newAcc && isHTML) { // HTML accessibles
if (roleMapEntry) {
// Create pure ARIA grid/treegrid related accessibles if they weren't used
// on accessible HTML table elements.
if ((roleMapEntry->accTypes & eTableCell)) {
if (aContext->IsTableRow() &&
(frame->AccessibleType() != eHTMLTableCellType ||
aContext->GetContent() != content->GetParent())) {
newAcc = new ARIAGridCellAccessibleWrap(content, document);
}
bool isARIATableOrCell = roleMapEntry &&
(roleMapEntry->accTypes & (eTableCell | eTable));
} else if ((roleMapEntry->IsOfType(eTable)) &&
frame->AccessibleType() != eHTMLTableType) {
if (!isARIATableOrCell ||
frame->AccessibleType() == eHTMLTableCellType ||
frame->AccessibleType() == eHTMLTableType) {
// Prefer to use markup (mostly tag name, perhaps attributes) to decide if
// and what kind of accessible to create,
newAcc = CreateHTMLAccessibleByMarkup(frame, content, aContext);
if (!newAcc) // try by frame accessible type.
newAcc = CreateAccessibleByFrameType(frame, content, aContext);
}
// In case of ARIA grids use grid-specific classes if it's not native table
// based.
if (isARIATableOrCell && (!newAcc || newAcc->IsGenericHyperText())) {
if ((roleMapEntry->accTypes & eTableCell)) {
if (aContext->IsTableRow())
newAcc = new ARIAGridCellAccessibleWrap(content, document);
} else if (roleMapEntry->IsOfType(eTable)) {
newAcc = new ARIAGridAccessibleWrap(content, document);
}
}
if (!newAcc) {
// Prefer to use markup (mostly tag name, perhaps attributes) to decide if
// and what kind of accessible to create.
newAcc = CreateHTMLAccessibleByMarkup(frame, content, aContext);
// Try using frame to do it.
if (!newAcc)
newAcc = CreateAccessibleByFrameType(frame, content, aContext);
// If table has strong ARIA role then all table descendants shouldn't
// expose their native roles.
if (!roleMapEntry && newAcc && aContext->HasStrongARIARole()) {
if (frame->AccessibleType() == eHTMLTableRowType) {
nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eTable))
roleMapEntry = &aria::gEmptyRoleMap;
} else if (frame->AccessibleType() == eHTMLTableCellType &&
aContext->ARIARoleMap() == &aria::gEmptyRoleMap) {
// If table has strong ARIA role then all table descendants shouldn't
// expose their native roles.
if (!roleMapEntry && newAcc && aContext->HasStrongARIARole()) {
if (frame->AccessibleType() == eHTMLTableRowType) {
nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eTable))
roleMapEntry = &aria::gEmptyRoleMap;
} else if (content->Tag() == nsGkAtoms::dt ||
content->Tag() == nsGkAtoms::li ||
content->Tag() == nsGkAtoms::dd ||
frame->AccessibleType() == eHTMLLiType) {
nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eList))
roleMapEntry = &aria::gEmptyRoleMap;
}
} else if (frame->AccessibleType() == eHTMLTableCellType &&
aContext->ARIARoleMap() == &aria::gEmptyRoleMap) {
roleMapEntry = &aria::gEmptyRoleMap;
} else if (content->Tag() == nsGkAtoms::dt ||
content->Tag() == nsGkAtoms::li ||
content->Tag() == nsGkAtoms::dd ||
frame->AccessibleType() == eHTMLLiType) {
nsRoleMapEntry* contextRoleMap = aContext->ARIARoleMap();
if (!contextRoleMap->IsOfType(eList))
roleMapEntry = &aria::gEmptyRoleMap;
}
}
}

View File

@ -604,5 +604,12 @@ ARIAGridCellAccessible::NativeAttributes()
stringIdx.AppendInt(rowIdx * colCount + colIdx);
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::tableCellIndex, stringIdx);
#ifdef DEBUG
nsAutoString unused;
attributes->SetStringProperty(NS_LITERAL_CSTRING("cppclass"),
NS_LITERAL_STRING("ARIAGridCellAccessible"),
unused);
#endif
return attributes.forget();
}

View File

@ -579,6 +579,7 @@ public:
bool IsDoc() const { return HasGenericType(eDocument); }
DocAccessible* AsDoc();
bool IsGenericHyperText() const { return mType == eHyperTextType; }
bool IsHyperText() const { return HasGenericType(eHyperText); }
HyperTextAccessible* AsHyperText();

View File

@ -50,6 +50,7 @@ HyperTextAccessible::
HyperTextAccessible(nsIContent* aNode, DocAccessible* aDoc) :
AccessibleWrap(aNode, aDoc)
{
mType = eHyperTextType;
mGenericTypes |= eHyperText;
}

View File

@ -48,6 +48,7 @@ HTMLTableCellAccessible::
HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
HyperTextAccessibleWrap(aContent, aDoc)
{
mType = eHTMLTableCellType;
mGenericTypes |= eTableCell;
}
@ -129,6 +130,13 @@ HTMLTableCellAccessible::NativeAttributes()
if (!axisText.IsEmpty())
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::axis, axisText);
#ifdef DEBUG
nsAutoString unused;
attributes->SetStringProperty(NS_LITERAL_CSTRING("cppclass"),
NS_LITERAL_STRING("HTMLTableCellAccessible"),
unused);
#endif
return attributes.forget();
}

View File

@ -62,13 +62,13 @@
headerInfoMap = [
{
// not focusable cell (nsARIAGridCellAccessible is used)
// not focusable cell (ARIAGridCellAccessible is used)
cell: "table2_dc_1",
rowHeaderCells: [],
columnHeaderCells: [ "table2_ch_1" ]
},
{
// focusable cell (nsARIAGridCellAccessible is used)
// focusable cell (ARIAGridCellAccessible is used)
cell: "table2_dc_2",
rowHeaderCells: [],
columnHeaderCells: [ "table2_ch_2" ]
@ -77,6 +77,27 @@
testHeaderCells(headerInfoMap);
//////////////////////////////////////////////////////////////////////////
// column and row headers from markup for one more crazy grid.
headerInfoMap = [
{
// ARIAGridCellAccessible is used
cell: "t3_dc_1",
rowHeaderCells: [ "t3_rh_1" ],
columnHeaderCells: [ ]
},
{
// ARIAGridCellAccessible is used (inside rowgroup)
cell: "t3_dc_2",
rowHeaderCells: [ "t3_rh_2" ],
columnHeaderCells: [ ]
}
];
testHeaderCells(headerInfoMap);
SimpleTest.finish();
}
@ -135,5 +156,30 @@
</div>
</div>
<div role="grid">
<table role="presentation">
<tbody role="presentation">
<tr role="row">
<th id="t3_rh_1" role="rowheader">Row 1</th>
<td id="t3_dc_1" role="gridcell" tabindex="-1">
Apple Inc.
</td>
</tr>
</tbody>
</table>
<div role="rowgroup" tabindex="0">
<table role="presentation">
<tbody role="presentation">
<tr role="row">
<th id="t3_rh_2" role="rowheader">Row 2</th>
<td id="t3_dc_2" role="gridcell" tabindex="-1">
Apple-Shmapple Inc.
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>