a11y: Get UnoControl accessible without implementing XAccessible
By now, almost all a11y implementations implement both, the XAccessible and XAccessibleContext interfaces themselves, and they do so via the OAccessible base class. One remaining case that only implements the XAccessible interface directly is UnoControl. XAccessible::getAccessibleContext is used from within AccessibleControlShape::Init to get the accessible context. That accessible context however is an OAccessible and implements both, the XAccessible and XAccessibleContext interfaces again. Stop requiring that UnoControl implements XAccessible by instead adding a dedicated new method UnoControl::getAccessible to directly get the OAccessible without relying on the XAccessible interface being implemented by UnoControl. In AccessibleControlShape::Init, cast to UnoControl instead of querying for the XAccessible interface and call the new method directly. Stop implementing the XAccessible interface in UnoControl as it is no longer needed now. This aligns the UnoControl a11y logic more with how a11y is implemented elsewhere across the code base. Sample steps to trigger the modified code when using the gtk3 vcl plugin on Linux: * start the Orca screen reader * start Writer * insert a few push button controls using "Form" -> "Push Button" and then clicking into the document and dragging to insert * disable design mode using "Form" -> "Design Mode" * focus one of the controls by clicking on it * press the Tab key to move focus between the controls No differences in behavior were observed when doing this with or without this change in place. Side note: Announcement of the controls when they receive focus didn't work (reliably) when opening an existing document containing form controls instead of inserting them into a new one, but that is preexisting and unrelated to this commit. Also adjust test AccessibleFixedTextTest::testFixedText of the CppunitTest_toolkit_a11y test suite accordingly that was assuming that it can query the XAccessible interface directly from the UNO control. Change-Id: I8cc3902a8de725eda3d810920f1da2d390c06f73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210464 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
#include <tools/long.hxx>
|
||||
#include <comphelper/interfacecontainer3.hxx>
|
||||
#include <comphelper/OAccessible.hxx>
|
||||
#include <cppuhelper/implbase9.hxx>
|
||||
#include <cppuhelper/implbase8.hxx>
|
||||
#include <unotools/weakref.hxx>
|
||||
#include <com/sun/star/util/XModeChangeBroadcaster.hpp>
|
||||
#include <memory>
|
||||
@@ -61,12 +61,11 @@ struct UnoControlComponentInfos
|
||||
struct UnoControl_Data;
|
||||
|
||||
|
||||
typedef ::cppu::WeakAggImplHelper9 < css::awt::XControl
|
||||
typedef ::cppu::WeakAggImplHelper8 < css::awt::XControl
|
||||
, css::awt::XWindow2
|
||||
, css::awt::XView
|
||||
, css::beans::XPropertiesChangeListener
|
||||
, css::lang::XServiceInfo
|
||||
, css::accessibility::XAccessible
|
||||
, css::util::XModeChangeBroadcaster
|
||||
, css::awt::XUnitConversion
|
||||
, css::awt::XStyleSettingsSupplier
|
||||
@@ -199,9 +198,6 @@ public:
|
||||
sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
|
||||
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
|
||||
|
||||
// XAccessible
|
||||
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override;
|
||||
|
||||
// XModeChangeBroadcaster
|
||||
virtual void SAL_CALL addModeChangeListener( const css::uno::Reference< css::util::XModeChangeListener >& _rxListener ) override;
|
||||
virtual void SAL_CALL removeModeChangeListener( const css::uno::Reference< css::util::XModeChangeListener >& _rxListener ) override;
|
||||
@@ -217,6 +213,7 @@ public:
|
||||
// XStyleSettingsSupplier
|
||||
virtual css::uno::Reference< css::awt::XStyleSettings > SAL_CALL getStyleSettings() override;
|
||||
|
||||
rtl::Reference<comphelper::OAccessible> getAccessible();
|
||||
css::uno::Reference< css::awt::XVclWindowPeer > getVclWindowPeer();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -201,10 +201,9 @@ void AccessibleControlShape::Init()
|
||||
else
|
||||
{
|
||||
Reference< XModeChangeBroadcaster > xControlModes( m_xUnoControl, UNO_QUERY );
|
||||
Reference< XAccessible > xControlAccessible( xControlModes, UNO_QUERY );
|
||||
Reference< XAccessibleContext > xNativeControlContext;
|
||||
if ( xControlAccessible.is() )
|
||||
xNativeControlContext = xControlAccessible->getAccessibleContext();
|
||||
if (UnoControl* pUnoControl = dynamic_cast<UnoControl*>(xControlModes.get()))
|
||||
xNativeControlContext = pUnoControl->getAccessible();
|
||||
OSL_ENSURE( xNativeControlContext.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
|
||||
m_aControlContext = WeakReference< XAccessibleContext >( xNativeControlContext );
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <test/a11y/XAccessibleEventBroadcasterTester.hxx>
|
||||
#include <test/a11y/XAccessibleTextTester.hxx>
|
||||
#include <test/a11y/accessibletestbase.hxx>
|
||||
#include <toolkit/controls/unocontrol.hxx>
|
||||
#include <vcl/scheduler.hxx>
|
||||
|
||||
using namespace css;
|
||||
@@ -101,7 +102,10 @@ void AccessibleFixedTextTest::testFixedText()
|
||||
|
||||
Scheduler::ProcessEventsToIdle();
|
||||
|
||||
css::uno::Reference<css::accessibility::XAccessible> xRoot(xWinDlg, css::uno::UNO_QUERY_THROW);
|
||||
UnoControl* pControl = dynamic_cast<UnoControl*>(xWinDlg.get());
|
||||
CPPUNIT_ASSERT(pControl);
|
||||
|
||||
css::uno::Reference<css::accessibility::XAccessible> xRoot = pControl->getAccessible();
|
||||
test::AccessibleTestBase::dumpA11YTree(xRoot);
|
||||
|
||||
css::uno::Reference<css::accessibility::XAccessibleContext> xContext
|
||||
|
||||
@@ -1461,7 +1461,7 @@ Sequence< OUString > UnoControl::getSupportedServiceNames( )
|
||||
}
|
||||
|
||||
|
||||
Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( )
|
||||
rtl::Reference<comphelper::OAccessible> UnoControl::getAccessible()
|
||||
{
|
||||
// creation of the context will certainly require the SolarMutex ...
|
||||
SolarMutexGuard aSolarGuard;
|
||||
@@ -1485,7 +1485,7 @@ Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( )
|
||||
pCurrentAccessible = ::toolkit::OAccessibleControlContext::create(this);
|
||||
|
||||
DBG_ASSERT(pCurrentAccessible.is(),
|
||||
"UnoControl::getAccessibleContext: invalid context (invalid peer?)!");
|
||||
"UnoControl::getAccessible: invalid context (invalid peer?)!");
|
||||
mpAccessible = unotools::WeakReference<comphelper::OAccessible>(pCurrentAccessible);
|
||||
|
||||
// get notified when the accessible is disposed
|
||||
|
||||
Reference in New Issue
Block a user