Bug 1887799 part 4: Implement the UIA TableItem pattern. r=nlapre

Differential Revision: https://phabricator.services.mozilla.com/D208277
This commit is contained in:
James Teh 2024-04-23 06:07:44 +00:00
parent 8985774454
commit 979b3a6c2c
5 changed files with 84 additions and 2 deletions

View File

@ -45,6 +45,22 @@ async function testGridItemProps(id, row, col, rowSpan, colSpan, gridId) {
);
}
async function testTableItemProps(id, rowHeaders, colHeaders) {
await assignPyVarToUiaWithId(id);
await definePyVar("pattern", `getUiaPattern(${id}, "TableItem")`);
ok(await runPython(`bool(pattern)`), `${id} has TableItem pattern`);
await isUiaElementArray(
`pattern.GetCurrentRowHeaderItems()`,
rowHeaders,
`${id} has correct RowHeaderItems`
);
await isUiaElementArray(
`pattern.GetCurrentColumnHeaderItems()`,
colHeaders,
`${id} has correct ColumnHeaderItems`
);
}
/**
* Test the Grid pattern.
*/
@ -90,3 +106,20 @@ addUiaTask(SNIPPET, async function testGridItem() {
await testPatternAbsent("button", "GridItem");
});
/**
* Test the TableItem pattern.
*/
addUiaTask(SNIPPET, async function testTableItem() {
await definePyVar("doc", `getDocUia()`);
await testTableItemProps("a", [], []);
await testTableItemProps("b", [], []);
await testTableItemProps("c", [], []);
await testTableItemProps("dg", [], ["a"]);
await testTableItemProps("ef", ["dg"], ["b", "c"]);
await testTableItemProps("h", ["dg"], ["b"]);
await testTableItemProps("i", ["dg", "h"], ["c"]);
await testTableItemProps("jkl", [], ["a", "b", "c"]);
await testPatternAbsent("button", "TableItem");
});

View File

@ -28,6 +28,7 @@ TableCellAccessible* ia2AccessibleTableCell::CellAcc() {
IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleTableCell)
IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleTableCell)
IMPL_IUNKNOWN_QUERY_IFACE(IGridItemProvider)
IMPL_IUNKNOWN_QUERY_IFACE(ITableItemProvider)
IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(ia2AccessibleHypertext)
////////////////////////////////////////////////////////////////////////////////

View File

@ -94,3 +94,37 @@ UiaGridItem::get_ContainingGrid(
uia.forget(aRetVal);
return S_OK;
}
// ITableItemProvider methods
STDMETHODIMP
UiaGridItem::GetRowHeaderItems(__RPC__deref_out_opt SAFEARRAY** aRetVal) {
if (!aRetVal) {
return E_INVALIDARG;
}
*aRetVal = nullptr;
TableCellAccessible* cell = CellAcc();
if (!cell) {
return CO_E_OBJNOTCONNECTED;
}
AutoTArray<Accessible*, 10> cells;
cell->RowHeaderCells(&cells);
*aRetVal = AccessibleArrayToUiaArray(cells);
return S_OK;
}
STDMETHODIMP
UiaGridItem::GetColumnHeaderItems(__RPC__deref_out_opt SAFEARRAY** aRetVal) {
if (!aRetVal) {
return E_INVALIDARG;
}
*aRetVal = nullptr;
TableCellAccessible* cell = CellAcc();
if (!cell) {
return CO_E_OBJNOTCONNECTED;
}
AutoTArray<Accessible*, 10> cells;
cell->ColHeaderCells(&cells);
*aRetVal = AccessibleArrayToUiaArray(cells);
return S_OK;
}

View File

@ -14,9 +14,9 @@ namespace mozilla::a11y {
class TableCellAccessible;
/**
* IGridItemProvider implementation.
* IGridItemProvider and ITableItemProvider implementations.
*/
class UiaGridItem : public IGridItemProvider {
class UiaGridItem : public IGridItemProvider, public ITableItemProvider {
public:
// IGridItemProvider
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Row(
@ -35,6 +35,13 @@ class UiaGridItem : public IGridItemProvider {
/* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple**
aRetVal);
// ITableItemProvider
virtual HRESULT STDMETHODCALLTYPE GetRowHeaderItems(
/* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal);
virtual HRESULT STDMETHODCALLTYPE GetColumnHeaderItems(
/* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal);
private:
TableCellAccessible* CellAcc();
};

View File

@ -313,6 +313,13 @@ uiaRawElmProvider::GetPatternProvider(
scroll.forget(aPatternProvider);
return S_OK;
}
case UIA_TableItemPatternId:
if (acc->IsTableCell()) {
auto item =
GetPatternFromDerived<ia2AccessibleTableCell, ITableItemProvider>();
item.forget(aPatternProvider);
}
return S_OK;
case UIA_TogglePatternId:
if (HasTogglePattern()) {
RefPtr<IToggleProvider> toggle = this;