diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2021-09-08 14:37:53 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2021-09-08 20:06:00 +0200 |
commit | 97a88e30e2e084ab860635ff4e0a03442d8a12af (patch) | |
tree | 85ae0393778842078b95b75c648d605a28f71022 /winaccessibility | |
parent | 839dbf9ecf9f8fbec7de983d1a2e16d7de6f868c (diff) |
tdf#100086 tdf#124832 wina11y: Implement IAccessibleTableCell
Add a new class 'AccTableCell' that implements the
IAccessibleTableCell interface from the IAccessible2 spec
and add what's needed to expose it to accessibility tools
via COM.
Since there's no specific XInterface for table cells
that an XAccessible's context could be queried for,
make use of the fact that a table cell's
parent is a table, i.e. its accessible context implements
XAccessibleTable.
AccTableCell keeps a reference to that table and remembers the
cell's index in the parent to retrieve information
on the cell from there.
This addresses the
> At least for LibreOffice Table Cells don't implement
> IAccessibleTableCell, and therefore there's no way to get the row and
> column span. LibreOffice itself also does not expose the merged state in
> the accessible name of the cell.
comment from [1] (which is the NVDA counterpart for LO's
tdf#124832) and may also help for tdf#100086,
though more work will be needed on LibreOffice and/or NVDA
side for both issues.
[1] https://github.com/nvaccess/nvda/issues/9310
Change-Id: I0f53212d14ee17c760b9e6c91be2154a1b25d862
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121821
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'winaccessibility')
-rw-r--r-- | winaccessibility/Library_uacccom.mk | 1 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccTableCell.cxx | 168 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccTableCell.h | 87 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/MAccessible.cxx | 30 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/UAccCOM.cxx | 2 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOMIDL/UAccCOM.idl | 8 |
6 files changed, 296 insertions, 0 deletions
diff --git a/winaccessibility/Library_uacccom.mk b/winaccessibility/Library_uacccom.mk index 9fbb3b7b5bc6..8c3d3c1596e5 100644 --- a/winaccessibility/Library_uacccom.mk +++ b/winaccessibility/Library_uacccom.mk @@ -38,6 +38,7 @@ $(eval $(call gb_Library_add_exception_objects,UAccCOM,\ winaccessibility/source/UAccCOM/AccImage \ winaccessibility/source/UAccCOM/AccRelation \ winaccessibility/source/UAccCOM/AccTable \ + winaccessibility/source/UAccCOM/AccTableCell \ winaccessibility/source/UAccCOM/AccText \ winaccessibility/source/UAccCOM/AccTextBase \ winaccessibility/source/UAccCOM/AccValue \ diff --git a/winaccessibility/source/UAccCOM/AccTableCell.cxx b/winaccessibility/source/UAccCOM/AccTableCell.cxx new file mode 100644 index 000000000000..2cc9a2963ff2 --- /dev/null +++ b/winaccessibility/source/UAccCOM/AccTableCell.cxx @@ -0,0 +1,168 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "AccTableCell.h" + +#include <vcl/svapp.hxx> +#include <com/sun/star/accessibility/XAccessible.hpp> + +using namespace com::sun::star::accessibility; +using namespace com::sun::star::uno; + +CAccTableCell::CAccTableCell() + : m_nIndexInParent(0) +{ +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::put_XInterface(hyper pXInterface) +{ + // internal IUNOXWrapper - no mutex meeded + + ENTER_PROTECTED_BLOCK + + CUNOXWrapper::put_XInterface(pXInterface); + if (pUNOInterface == nullptr) + return E_INVALIDARG; + + Reference<XAccessibleContext> xContext = pUNOInterface->getAccessibleContext(); + if (!xContext.is()) + return E_FAIL; + + // retrieve reference to table (parent of the cell) + Reference<XAccessibleContext> xParentContext + = xContext->getAccessibleParent()->getAccessibleContext(); + Reference<XAccessibleTable> xTable(xParentContext, UNO_QUERY); + + if (!xTable.is()) + { + m_xTable.clear(); + return E_FAIL; + } + + m_xTable = xTable; + m_nIndexInParent = xContext->getAccessibleIndexInParent(); + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnExtent(long* pColumnsSpanned) +{ + SolarMutexGuard g; + + ENTER_PROTECTED_BLOCK + + if (pColumnsSpanned == nullptr) + return E_INVALIDARG; + + if (!m_xTable.is()) + return E_FAIL; + + long nRow = 0, nColumn = 0; + get_rowIndex(&nRow); + get_columnIndex(&nColumn); + + *pColumnsSpanned = m_xTable->getAccessibleColumnExtentAt(nRow, nColumn); + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnIndex(long* pColumnIndex) +{ + SolarMutexGuard g; + + ENTER_PROTECTED_BLOCK + + if (pColumnIndex == nullptr) + return E_INVALIDARG; + + if (!m_xTable.is()) + return E_FAIL; + + *pColumnIndex = m_xTable->getAccessibleColumn(m_nIndexInParent); + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowExtent(long* pRowsSpanned) +{ + SolarMutexGuard g; + + ENTER_PROTECTED_BLOCK + + if (pRowsSpanned == nullptr) + return E_INVALIDARG; + + if (!m_xTable.is()) + return E_FAIL; + + long nRow = 0, nColumn = 0; + get_rowIndex(&nRow); + get_columnIndex(&nColumn); + + *pRowsSpanned = m_xTable->getAccessibleRowExtentAt(nRow, nColumn); + + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowIndex(long* pRowIndex) +{ + SolarMutexGuard g; + + ENTER_PROTECTED_BLOCK + + if (pRowIndex == nullptr) + return E_INVALIDARG; + + if (!m_xTable.is()) + return E_FAIL; + + *pRowIndex = m_xTable->getAccessibleRow(m_nIndexInParent); + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_isSelected(boolean* pIsSelected) +{ + SolarMutexGuard g; + + ENTER_PROTECTED_BLOCK + + if (pIsSelected == nullptr) + return E_INVALIDARG; + + if (!m_xTable.is()) + return E_FAIL; + + long nRow = 0, nColumn = 0; + get_rowIndex(&nRow); + get_columnIndex(&nColumn); + + *pIsSelected = m_xTable->isAccessibleSelected(nRow, nColumn); + return S_OK; + + LEAVE_PROTECTED_BLOCK +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/winaccessibility/source/UAccCOM/AccTableCell.h b/winaccessibility/source/UAccCOM/AccTableCell.h new file mode 100644 index 000000000000..9b9315d5ca47 --- /dev/null +++ b/winaccessibility/source/UAccCOM/AccTableCell.h @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include "Resource.h" + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/accessibility/XAccessibleTable.hpp> +#include "UNOXWrapper.h" + +/** + * CAccTableCell implements the IAccessibleTableCell interface. + */ +class ATL_NO_VTABLE CAccTableCell : public CComObjectRoot, + public CComCoClass<CAccTableCell, &CLSID_AccTableCell>, + public IAccessibleTableCell, + public CUNOXWrapper + +{ +public: + CAccTableCell(); + virtual ~CAccTableCell() {} + + BEGIN_COM_MAP(CAccTableCell) + COM_INTERFACE_ENTRY(IAccessibleTableCell) + COM_INTERFACE_ENTRY(IUNOXWrapper) + COM_INTERFACE_ENTRY_FUNC_BLIND(NULL, SmartQI_) +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif + END_COM_MAP() +#if defined __clang__ +#pragma clang diagnostic pop +#endif + + static HRESULT WINAPI SmartQI_(void* pv, REFIID iid, void** ppvObject, DWORD_PTR) + { + return static_cast<CAccTableCell*>(pv)->SmartQI(iid, ppvObject); + } + + HRESULT SmartQI(REFIID iid, void** ppvObject) + { + if (m_pOuterUnknown) + return OuterQueryInterface(iid, ppvObject); + return E_FAIL; + } + + DECLARE_NO_REGISTRY() + +public: + STDMETHOD(put_XInterface)(hyper pXInterface) override; + + // IAccessibleTableCell interfaces + STDMETHOD(get_columnExtent)(long*) override; + STDMETHOD(get_columnHeaderCells)(IUnknown***, long*) override { return E_FAIL; } + STDMETHOD(get_columnIndex)(long*) override; + STDMETHOD(get_rowExtent)(long*) override; + STDMETHOD(get_rowHeaderCells)(IUnknown***, long*) override { return E_FAIL; } + STDMETHOD(get_rowIndex)(long*) override; + STDMETHOD(get_isSelected)(boolean*) override; + STDMETHOD(get_rowColumnExtents)(long*, long*, long*, long*, boolean*) { return E_FAIL; } + STDMETHOD(get_table)(IUnknown**) { return E_FAIL; } + +private: + css::uno::Reference<css::accessibility::XAccessibleTable> m_xTable; + sal_Int32 m_nIndexInParent; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx b/winaccessibility/source/UAccCOM/MAccessible.cxx index 9c100ea5fc4a..ed0796c43ec1 100644 --- a/winaccessibility/source/UAccCOM/MAccessible.cxx +++ b/winaccessibility/source/UAccCOM/MAccessible.cxx @@ -38,6 +38,7 @@ #include "AccEditableText.h" #include "AccImage.h" #include "AccTable.h" +#include "AccTableCell.h" #include "AccValue.h" #include "AccHypertext.h" #include "AccHyperLink.h" @@ -77,6 +78,7 @@ enum class XInterfaceType { XI_COMPONENT, XI_TEXT, XI_TABLE, + XI_TABLECELL, XI_EDITABLETEXT, XI_IMAGE, XI_SELECTION, @@ -107,6 +109,30 @@ bool queryXInterface(XAccessible* pXAcc, XInterface** ppXI) return true; } +// Since there's no specific XInterface for table cells, this +// method checks that the accessible's parent is a table +// (implements XAccessibleTable) and pXAcc's context implements +// XAccessibleComponent. +bool queryTableCell(XAccessible* pXAcc, XInterface** ppXI) +{ + XInterface* pXInterface = nullptr; + + const bool bSupportsInterface = queryXInterface<XAccessibleComponent>(pXAcc, &pXInterface); + if (!bSupportsInterface) + return false; + + // check whether parent is a table (its accessible context implements XAccessibleTable) + XInterface* pParentXInterface = nullptr; + Reference<XAccessible> xParentAcc = pXAcc->getAccessibleContext()->getAccessibleParent(); + const bool bParentIsTable = queryXInterface<XAccessibleTable>(xParentAcc.get(), &pParentXInterface); + + if (!bParentIsTable) + return false; + + *ppXI = pXInterface; + return true; +} + } // IA2 states mapping, and name @@ -2498,6 +2524,9 @@ bool CMAccessible::GetXInterfaceFromXAccessible(XAccessible* pXAcc, XInterface** return queryXInterface<XAccessibleEditableText>(pXAcc, ppXI); case XInterfaceType::XI_TABLE: return queryXInterface<XAccessibleTable>(pXAcc, ppXI); + case XInterfaceType::XI_TABLECELL: + // needs specific handling, since there's no XInterface for table cells + return queryTableCell(pXAcc, ppXI); case XInterfaceType::XI_SELECTION: return queryXInterface<XAccessibleSelection>(pXAcc, ppXI); case XInterfaceType::XI_EXTENDEDCOMP: @@ -2551,6 +2580,7 @@ static AggMapEntry g_CMAccessible_AggMap[] = { { &IID_IAccessibleImage, &createAggInstance<CAccImage>, XInterfaceType::XI_IMAGE }, { &IID_IAccessibleTable, &createAggInstance<CAccTable>, XInterfaceType::XI_TABLE }, { &IID_IAccessibleTable2, &createAggInstance<CAccTable>, XInterfaceType::XI_TABLE }, + { &IID_IAccessibleTableCell, &createAggInstance<CAccTableCell>, XInterfaceType::XI_TABLECELL }, { &IID_IAccessibleAction, &createAggInstance<CAccAction>, XInterfaceType::XI_ACTION }, { &IID_IAccessibleValue, &createAggInstance<CAccValue>, XInterfaceType::XI_VALUE }, { &IID_IAccessibleHypertext, &createAggInstance<CAccHypertext>, XInterfaceType::XI_HYPERTEXT }, diff --git a/winaccessibility/source/UAccCOM/UAccCOM.cxx b/winaccessibility/source/UAccCOM/UAccCOM.cxx index 0a981541cc3a..944db5c94c10 100644 --- a/winaccessibility/source/UAccCOM/UAccCOM.cxx +++ b/winaccessibility/source/UAccCOM/UAccCOM.cxx @@ -53,6 +53,7 @@ #include "AccImage.h" #include "AccValue.h" #include "AccTable.h" +#include "AccTableCell.h" #include "AccHyperLink.h" #include "AccHypertext.h" @@ -69,6 +70,7 @@ OBJECT_ENTRY(CLSID_AccEditableText, CAccEditableText) OBJECT_ENTRY(CLSID_AccImage, CAccImage) OBJECT_ENTRY(CLSID_AccValue, CAccValue) OBJECT_ENTRY(CLSID_AccTable, CAccTable) +OBJECT_ENTRY(CLSID_AccTableCell, CAccTableCell) OBJECT_ENTRY(CLSID_AccHyperLink, CAccHyperLink) OBJECT_ENTRY(CLSID_AccHypertext, CAccHypertext) #if defined __clang__ diff --git a/winaccessibility/source/UAccCOMIDL/UAccCOM.idl b/winaccessibility/source/UAccCOMIDL/UAccCOM.idl index 72c43c92dab9..1a0705754114 100644 --- a/winaccessibility/source/UAccCOMIDL/UAccCOM.idl +++ b/winaccessibility/source/UAccCOMIDL/UAccCOM.idl @@ -192,6 +192,14 @@ library UACCCOMLib { [default] interface IAccessibleTable; }; + [ + uuid(77948F17-05C8-4DAA-93D4-BCCD16ADC660), + helpstring("AccTableCell Class") + ] + coclass AccTableCell + { + [default] interface IAccessibleTableCell; + }; [ uuid(519A64CD-F6A6-4793-BE50-4E36C4C593EF), |