Bug 1628236 - Add cell getter and column headers attribute to tables. r=morgan

Differential Revision: https://phabricator.services.mozilla.com/D84249
This commit is contained in:
Eitan Isaacson 2020-07-21 20:58:36 +00:00
Родитель 58d8d9dc4a
Коммит cfcad506f6
4 изменённых файлов: 126 добавлений и 0 удалений

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

@ -301,6 +301,9 @@
// AttributedStringForRange
- (NSAttributedString* _Nullable)moxAttributedStringForRange:(NSValue* _Nonnull)range;
// AXCellForColumnAndRow
- (id _Nullable)moxCellForColumnAndRow:(NSArray* _Nonnull)columnAndRow;
@end
// This protocol maps text marker and text marker range parameters to

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

@ -80,6 +80,12 @@
// override
- (NSArray*)moxChildren;
// override
- (NSArray*)moxColumnHeaderUIElements;
// override
- (id)moxCellForColumnAndRow:(NSArray*)columnAndRow;
@end
@interface mozTableRowAccessible : mozTablePartAccessible

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

@ -210,6 +210,62 @@
return [[super moxChildren] arrayByAddingObjectsFromArray:[self moxColumns]];
}
- (NSArray*)moxColumnHeaderUIElements {
MOZ_ASSERT(!mGeckoAccessible.IsNull());
uint32_t numCols = 0;
TableAccessible* table = nullptr;
if (Accessible* acc = mGeckoAccessible.AsAccessible()) {
table = mGeckoAccessible.AsAccessible()->AsTable();
numCols = table->ColCount();
} else {
numCols = mGeckoAccessible.AsProxy()->TableColumnCount();
}
NSMutableArray* colHeaders = [[NSMutableArray alloc] initWithCapacity:numCols];
for (uint32_t i = 0; i < numCols; i++) {
AccessibleOrProxy cell;
if (table) {
cell = table->CellAt(0, i);
} else {
cell = mGeckoAccessible.AsProxy()->TableCellAt(0, i);
}
if (!cell.IsNull() && cell.Role() == roles::COLUMNHEADER) {
mozAccessible* colHeader = GetNativeFromGeckoAccessible(cell);
[colHeaders addObject:colHeader];
}
}
return colHeaders;
}
- (id)moxCellForColumnAndRow:(NSArray*)columnAndRow {
if (columnAndRow == nil || [columnAndRow count] != 2) {
return nil;
}
uint32_t col = [[columnAndRow objectAtIndex:0] unsignedIntValue];
uint32_t row = [[columnAndRow objectAtIndex:1] unsignedIntValue];
MOZ_ASSERT(!mGeckoAccessible.IsNull());
AccessibleOrProxy cell;
if (mGeckoAccessible.IsAccessible()) {
cell = mGeckoAccessible.AsAccessible()->AsTable()->CellAt(row, col);
} else {
cell = mGeckoAccessible.AsProxy()->TableCellAt(row, col);
}
if (cell.IsNull()) {
return nil;
}
return GetNativeFromGeckoAccessible(cell);
}
- (void)invalidateColumns {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if (mColContainers) {

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

@ -148,3 +148,64 @@ addAccessibleTask(
);
}
);
addAccessibleTask(
`<table id="table">
<tr>
<th colspan="2" id="header1">Header 1</th>
<th id="header2">Header 2</th>
</tr>
<tr>
<td id="cell1">one</td>
<td id="cell2" rowspan="2">two</td>
<td id="cell3">three</td>
</tr>
<tr>
<td id="cell4">four</td>
<td id="cell5">five</td>
</tr>
</table>`,
(browser, accDoc) => {
let table = getNativeInterface(accDoc, "table");
let getCellAt = (col, row) =>
table.getParameterizedAttributeValue("AXCellForColumnAndRow", [col, row]);
function testCell(cell, expectedId, expectedColRange, expectedRowRange) {
is(
cell.getAttributeValue("AXDOMIdentifier"),
expectedId,
"Correct DOM Identifier"
);
Assert.deepEqual(
cell.getAttributeValue("AXColumnIndexRange"),
expectedColRange,
"Correct column range"
);
Assert.deepEqual(
cell.getAttributeValue("AXRowIndexRange"),
expectedRowRange,
"Correct row range"
);
}
testCell(getCellAt(0, 0), "header1", [0, 2], [0, 1]);
testCell(getCellAt(1, 0), "header1", [0, 2], [0, 1]);
testCell(getCellAt(2, 0), "header2", [2, 1], [0, 1]);
testCell(getCellAt(0, 1), "cell1", [0, 1], [1, 1]);
testCell(getCellAt(1, 1), "cell2", [1, 1], [1, 2]);
testCell(getCellAt(2, 1), "cell3", [2, 1], [1, 1]);
testCell(getCellAt(0, 2), "cell4", [0, 1], [2, 1]);
testCell(getCellAt(1, 2), "cell2", [1, 1], [1, 2]);
testCell(getCellAt(2, 2), "cell5", [2, 1], [2, 1]);
let colHeaders = table.getAttributeValue("AXColumnHeaderUIElements");
Assert.deepEqual(
colHeaders.map(c => c.getAttributeValue("AXDOMIdentifier")),
["header1", "header1", "header2"],
"Correct column headers"
);
}
);