Bug 423224 ��� Expose object attribute on cell accessible for html:td to provide cell index, r=evan.yan, a=mtschrep

This commit is contained in:
surkov.alexander%gmail.com 2008-04-15 03:38:32 +00:00
Родитель e6250440aa
Коммит f9e27d4083
4 изменённых файлов: 125 добавлений и 89 удалений

Просмотреть файл

@ -231,12 +231,13 @@ ACCESSIBILITY_ATOM(aria_valuetext, "aria-valuetext")
ACCESSIBILITY_ATOM(defaultLabel, "defaultLabel")
// Object attributes
ACCESSIBILITY_ATOM(level, "level")
ACCESSIBILITY_ATOM(posinset, "posinset")
ACCESSIBILITY_ATOM(setsize, "setsize")
ACCESSIBILITY_ATOM(lineNumber, "line-number")
ACCESSIBILITY_ATOM(containerRelevant, "container-relevant")
ACCESSIBILITY_ATOM(containerLive, "container-live")
ACCESSIBILITY_ATOM(containerChannel, "container-channel")
ACCESSIBILITY_ATOM(cellIndex, "cell-index")
ACCESSIBILITY_ATOM(containerAtomic, "container-atomic")
ACCESSIBILITY_ATOM(containerBusy, "container-busy")
ACCESSIBILITY_ATOM(containerChannel, "container-channel")
ACCESSIBILITY_ATOM(containerLive, "container-live")
ACCESSIBILITY_ATOM(containerRelevant, "container-relevant")
ACCESSIBILITY_ATOM(level, "level")
ACCESSIBILITY_ATOM(lineNumber, "line-number")
ACCESSIBILITY_ATOM(posinset, "posinset")
ACCESSIBILITY_ATOM(setsize, "setsize")

Просмотреть файл

@ -60,6 +60,8 @@
#include "nsITableCellLayout.h"
#include "nsLayoutErrors.h"
////////////////////////////////////////////////////////////////////////////////
// nsHTMLTableCellAccessible
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTableCellAccessible, nsHyperTextAccessible)
@ -75,6 +77,66 @@ NS_IMETHODIMP nsHTMLTableCellAccessible::GetRole(PRUint32 *aResult)
return NS_OK;
}
nsresult
nsHTMLTableCellAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
{
if (IsDefunct())
return NS_ERROR_FAILURE;
nsresult rv = nsHyperTextAccessibleWrap::GetAttributesInternal(aAttributes);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
nsCOMPtr<nsIPresShell> shell = GetPresShell();
NS_ENSURE_STATE(shell);
nsIFrame *frame = shell->GetPrimaryFrameFor(content);
nsITableCellLayout *cellLayout = nsnull;
CallQueryInterface(frame, &cellLayout);
NS_ENSURE_STATE(cellLayout);
PRInt32 rowIdx = -1, cellIdx = -1;
rv = cellLayout->GetCellIndexes(rowIdx, cellIdx);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAccessible> childAcc(this);
nsCOMPtr<nsIAccessible> parentAcc;
rv = childAcc->GetParent(getter_AddRefs(parentAcc));
NS_ENSURE_SUCCESS(rv, rv);
while (parentAcc) {
if (Role(parentAcc) == nsIAccessibleRole::ROLE_TABLE) {
// Table accessible must implement nsIAccessibleTable interface but if
// it isn't happen (for example because of ARIA usage) we shouldn't fail
// on getting other attributes.
nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(parentAcc));
if (!tableAcc)
return NS_OK;
PRInt32 idx = -1;
rv = tableAcc->GetIndexAt(rowIdx, cellIdx, &idx);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString stringIdx;
stringIdx.AppendInt(idx);
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::cellIndex,
stringIdx);
return NS_OK;
}
parentAcc.swap(childAcc);
rv = childAcc->GetParent(getter_AddRefs(parentAcc));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLTableAccessible
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTableAccessible, nsAccessible, nsIAccessibleTable)
nsHTMLTableAccessible::nsHTMLTableAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell):

Просмотреть файл

@ -45,10 +45,15 @@
class nsHTMLTableCellAccessible : public nsHyperTextAccessibleWrap
{
public:
nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_DECL_ISUPPORTS_INHERITED
nsHTMLTableCellAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
NS_IMETHOD GetRole(PRUint32 *aResult);
// nsIAccessible
NS_IMETHOD GetRole(PRUint32 *aRole);
// nsAccessible
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
};
class nsITableLayout;

Просмотреть файл

@ -11,122 +11,90 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=410052
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessibleTable = Components.interfaces.nsIAccessibleTable;
var gAccService = null;
function doTest()
{
const nsIAccessibleRetrieval =
Components.interfaces.nsIAccessibleRetrieval;
const nsIAccessibleTable = Components.interfaces.nsIAccessibleTable;
var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
gAccService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
//////////////////////////////////////////////////////////////////////////
// table
var table = document.getElementById("table");
var tableAcc = accService.getAccessibleFor(table).
QueryInterface(nsIAccessibleTable);
var row, column, index;
var tRow = new Array(0,0,0,1,1,1,2,2,3,3);
var tCol = new Array(0,1,2,0,1,2,0,1,1,2);
for (var i = 0; i < 10; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(tRow[i], tCol[i]);
is(row, tRow[i], "table: row for index " + i +" is nor correct");
is(column, tCol[i], "table: column for index " + i +"is nor correct");
is(index, i,
"table: row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
}
testTable("table", 10, tRow, tCol);
//////////////////////////////////////////////////////////////////////////
// tableinsane1
table = document.getElementById("tableinsane1");
tableAcc = accService.getAccessibleFor(table).
QueryInterface(nsIAccessibleTable);
tRow = [0,0,0,1,1,1,2,2,3,3];
tCol = [0,1,2,0,1,2,0,1,1,2];
for (var i = 0; i < 10; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(tRow[i], tCol[i]);
is(row, tRow[i],
"tableinsane1: row for index " + i +" is nor correct");
is(column, tCol[i],
"tableinsane1: column for index " + i +"is nor correct");
is(index, i,
"tableinsane1: row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
}
testTable("tableinsane1", 10, tRow, tCol);
//////////////////////////////////////////////////////////////////////////
// tableinsane2
table = document.getElementById("tableinsane2");
tableAcc = accService.getAccessibleFor(table).
QueryInterface(nsIAccessibleTable);
tRow = [0,0,0,1,1,1,2,2,3,3,4,4,4];
tCol = [0,1,2,0,1,2,0,1,1,2,1,3,4];
for (var i = 0; i < 13; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(tRow[i], tCol[i]);
is(row, tRow[i],
"tableinsane2: row for index " + i +" is nor correct");
is(column, tCol[i],
"tableinsane2: column for index " + i +"is nor correct");
is(index, i,
"tableinsane2: row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
}
testTable("tableinsane2", 13, tRow, tCol);
//////////////////////////////////////////////////////////////////////////
// tableinsane4
table = document.getElementById("tableinsane4");
tableAcc = accService.getAccessibleFor(table).
QueryInterface(Components.interfaces.nsIAccessibleTable);
tRow = [0,0,0,1,1,1,2,2,3,4];
tCol = [0,1,2,0,1,2,0,2,0,0];
for (var i = 0; i < 10; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(tRow[i], tCol[i]);
is(row, tRow[i],
"tableinsane4: row for index " + i +" is nor correct");
is(column, tCol[i],
"tableinsane4: column for index " + i +"is nor correct");
is(index, i,
"tableinsane4: row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
}
testTable("tableinsane4", 10, tRow, tCol);
//////////////////////////////////////////////////////////////////////////
// tableborder
var table = document.getElementById("tableborder");
var tableAcc = accService.getAccessibleFor(table).
QueryInterface(nsIAccessibleTable);
tRow = [0,0,0,1,1,1,2,2,3,3];
tCol = [0,1,2,0,1,2,0,1,1,2];
for (var i = 0; i < 10; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(tRow[i], tCol[i]);
is(row, tRow[i],
"tableborder: row for index " + i +" is nor correct");
is(column, tCol[i],
"tableborder: column for index " + i +"is nor correct");
is(index, i,
"tableborder: row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
}
testTable("tableborder", 10, tRow, tCol);
SimpleTest.finish();
}
function testTable(aId, aLen, aRowIdxes, aColIdxes)
{
var table = document.getElementById(aId);
var tableAcc = gAccService.getAccessibleFor(table).
QueryInterface(nsIAccessibleTable);
var row, column, index;
var cellAcc;
for (var i = 0; i < aLen; i++) {
row = tableAcc.getRowAtIndex(i);
column = tableAcc.getColumnAtIndex(i);
index = tableAcc.getIndexAt(aRowIdxes[i], aColIdxes[i]);
is(row, aRowIdxes[i], aId + ": row for index " + i +" is nor correct");
is(column, aColIdxes[i],
aId + ": column for index " + i +"is nor correct");
is(index, i,
aId + ": row " + row + " /column " + column + " and index " + index + " aren't inconsistent.");
try {
cellAcc = null;
cellAcc = tableAcc.cellRefAt(row, column);
} catch (e) { }
ok(cellAcc,
aId + ": Can't get cell accessible at row = " + row + ", column = " + column);
if (cellAcc) {
var attrs = cellAcc.attributes;
is (parseInt(attrs.getStringProperty("cell-index")), index,
aId + ": cell index from object attributes of cell accessible isn't corrent.");
}
}
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>