accessibility/Library_acc.mk | 1 accessibility/inc/standard/svtaccessiblenumericfield.hxx | 50 ++++++ accessibility/inc/standard/vclxaccessibleedit.hxx | 5 accessibility/source/helper/acc_factory.cxx | 8 + accessibility/source/standard/svtaccessiblenumericfield.cxx | 93 ++++++++++++ include/toolkit/awt/vclxwindows.hxx | 4 include/toolkit/helper/accessiblefactory.hxx | 6 toolkit/source/awt/vclxwindows.cxx | 7 toolkit/source/helper/accessibilityclient.cxx | 5 toolkit/source/helper/unowrapper.cxx | 2 10 files changed, 177 insertions(+), 4 deletions(-)
New commits: commit 349a8801b9ee98f4f9ee1d35f7d28e17baedf7cc Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Jul 28 09:39:07 2021 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Jul 28 15:44:58 2021 +0200 a11y: Expose FormattedField as spinbox This adds a new accessibility class 'SVTXAccessibleNumericField' that implements 'XAccessibleValue' and reports having an a11y role of 'AccessibleRole::SPIN_BOX'. An object of that class is returned by 'SVTXNumericField::CreateAccessibleContext'. Create an 'SVTXNumericField' XWindow peer for windows of type 'WindowType::FORMATTEDFIELD' (instead of a 'VCLXNumericField' one), so the newly introduced accessibility class gets used for 'FormattedField'. This way, FormattedFields are now exposed to a11y tools as spinboxes. Previously, since no specific accessibility class had been implemented for VCLXNumericField (then used as XWindow peer class for FormattedField), the one for VCLXEdit, i.e. VCLXAccessibleEdit, was used. While VCLXNumericField implements XNumericField and thus in general offers the relevant methods to implement an accessible class that implements XAccessibleValue as well, it uses the Formatter from the VCLXFormattedSpinField base class to get/set values. However, that doesn't work for the FormattedField case, since FormattedField has its own formatter of a different type and the 'mpFormatter' member in the VCLXFormattedSpinField base class is a nullptr, resulting in the corresponding getter methods always returning 0 and the setters doing nothing. With this commit in place, Accerciser now reports role "spin box" instead of just "text" for FormattedFields and displays the current value as well as allows to change it via the "Value" interface when using the qt5/kf5 VCL plugin. Note: For non-integer values, Accerciser doesn't show the actual decimal value, but an integer, e.g. when the value for "Height" spinbox in Writer's "Page Style" -> "Page" dialog (section "Paper format") is set to "29.70cm", Accerciser shows "30" instead of "29.70", despite 'Qt5AccessibleWidget::currentValue' returning the exact value. This is because Accerciser appears to rely on the value for the minimum increment being reported (as a corresponding decimal value) by a call to 'atspi_value_get_minimum_increment', s.[1]. However, there is currently no corresponding method in the 'XAccesibleValue' interface for that at-spi method which 'Qt5AccessibleWidget::currentValue' could call to retrieve the value. The NVDA screen reader on Windows now also says e.g. "Width: (Type = 344) spin button editable Alt+W selected 8.50″" instead of "Width: (Type = 344) edit Alt+W selected 8.50″". [1] https://developer.gnome.org/libatspi/stable/libatspi-atspi-value.html#atspi-value-get-minimum-increment Change-Id: I8af326c2d24c1801147a56ea2e2a886ab42ac634 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119590 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/accessibility/Library_acc.mk b/accessibility/Library_acc.mk index caf3d612330b..fe88dafe10da 100644 --- a/accessibility/Library_acc.mk +++ b/accessibility/Library_acc.mk @@ -78,6 +78,7 @@ $(eval $(call gb_Library_add_exception_objects,acc,\ accessibility/source/standard/accessiblemenucomponent \ accessibility/source/standard/accessiblemenuitemcomponent \ accessibility/source/standard/floatingwindowaccessible \ + accessibility/source/standard/svtaccessiblenumericfield \ accessibility/source/standard/vclxaccessiblebox \ accessibility/source/standard/vclxaccessiblebutton \ accessibility/source/standard/vclxaccessiblecheckbox \ diff --git a/accessibility/inc/standard/svtaccessiblenumericfield.hxx b/accessibility/inc/standard/svtaccessiblenumericfield.hxx new file mode 100644 index 000000000000..940f72fa03f2 --- /dev/null +++ b/accessibility/inc/standard/svtaccessiblenumericfield.hxx @@ -0,0 +1,50 @@ +/* -*- 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 <cppuhelper/implbase1.hxx> +#include <standard/vclxaccessibleedit.hxx> + +#include <com/sun/star/accessibility/XAccessibleValue.hpp> + +typedef ::cppu::ImplHelper1<css::accessibility::XAccessibleValue> SVTXAccessibleNumericField_BASE; + +class SVTXAccessibleNumericField : public VCLXAccessibleEdit, public SVTXAccessibleNumericField_BASE +{ +public: + SVTXAccessibleNumericField(VCLXWindow* pVCLXindow); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XAccessibleContext + virtual sal_Int16 SAL_CALL getAccessibleRole() override; + + // XAccessibleValue + virtual ::css::uno::Any SAL_CALL getCurrentValue() override; + virtual ::sal_Bool SAL_CALL setCurrentValue(const css::uno::Any& aNumber) override; + virtual ::css::uno::Any SAL_CALL getMaximumValue() override; + virtual ::css::uno::Any SAL_CALL getMinimumValue() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/accessibility/inc/standard/vclxaccessibleedit.hxx b/accessibility/inc/standard/vclxaccessibleedit.hxx index a02d03319e8a..2f2ee88cc29b 100644 --- a/accessibility/inc/standard/vclxaccessibleedit.hxx +++ b/accessibility/inc/standard/vclxaccessibleedit.hxx @@ -33,14 +33,15 @@ typedef ::cppu::ImplHelper2< css::accessibility::XAccessibleAction, css::accessibility::XAccessibleEditableText > VCLXAccessibleEdit_BASE; -class VCLXAccessibleEdit final : public VCLXAccessibleTextComponent, - public VCLXAccessibleEdit_BASE +class VCLXAccessibleEdit : public VCLXAccessibleTextComponent, + public VCLXAccessibleEdit_BASE { friend class VCLXAccessibleBox; private: sal_Int32 m_nCaretPosition; +protected: virtual ~VCLXAccessibleEdit() override = default; virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override; diff --git a/accessibility/source/helper/acc_factory.cxx b/accessibility/source/helper/acc_factory.cxx index 720ecda1808b..51adeaca8d21 100644 --- a/accessibility/source/helper/acc_factory.cxx +++ b/accessibility/source/helper/acc_factory.cxx @@ -22,6 +22,7 @@ #include <toolkit/awt/vclxwindows.hxx> #include <toolkit/helper/accessiblefactory.hxx> #include <vcl/accessiblefactory.hxx> +#include <standard/svtaccessiblenumericfield.hxx> #include <standard/vclxaccessiblebutton.hxx> #include <standard/vclxaccessiblecheckbox.hxx> #include <standard/vclxaccessibledropdowncombobox.hxx> @@ -105,6 +106,8 @@ public: createAccessibleContext( VCLXToolBox* _pXWindow ) override; virtual css::uno::Reference< css::accessibility::XAccessibleContext > createAccessibleContext( VCLXHeaderBar* _pXWindow ) override; + virtual css::uno::Reference< css::accessibility::XAccessibleContext > + createAccessibleContext( SVTXNumericField* _pXWindow ) override; virtual css::uno::Reference< css::accessibility::XAccessibleContext > createAccessibleContext( VCLXWindow* _pXWindow ) override; virtual css::uno::Reference< css::accessibility::XAccessible > @@ -352,6 +355,11 @@ Reference< XAccessibleContext > AccessibleFactory::createAccessibleContext( VCLX return new VCLXAccessibleHeaderBar(_pXWindow); } +Reference< XAccessibleContext > AccessibleFactory::createAccessibleContext( SVTXNumericField* _pXWindow ) +{ + return new SVTXAccessibleNumericField( _pXWindow ); +} + vcl::IAccessibleTabListBox* AccessibleFactory::createAccessibleTabListBox( const Reference< XAccessible >& rxParent, SvHeaderTabListBox& rBox ) const { diff --git a/accessibility/source/standard/svtaccessiblenumericfield.cxx b/accessibility/source/standard/svtaccessiblenumericfield.cxx new file mode 100644 index 000000000000..114bf71802fe --- /dev/null +++ b/accessibility/source/standard/svtaccessiblenumericfield.cxx @@ -0,0 +1,93 @@ +/* -*- 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 <standard/svtaccessiblenumericfield.hxx> +#include <toolkit/awt/vclxwindows.hxx> + +#include <com/sun/star/accessibility/AccessibleRole.hpp> + +using namespace ::com::sun::star::accessibility; +using namespace ::comphelper; + +SVTXAccessibleNumericField::SVTXAccessibleNumericField(VCLXWindow* pVCLWindow) + : VCLXAccessibleEdit(pVCLWindow) +{ +} + +// XInterface +IMPLEMENT_FORWARD_XINTERFACE2(SVTXAccessibleNumericField, VCLXAccessibleTextComponent, + SVTXAccessibleNumericField_BASE) + +// XTypeProvider +IMPLEMENT_FORWARD_XTYPEPROVIDER2(SVTXAccessibleNumericField, VCLXAccessibleTextComponent, + SVTXAccessibleNumericField_BASE) + +sal_Int16 SVTXAccessibleNumericField::getAccessibleRole() { return AccessibleRole::SPIN_BOX; } + +css::uno::Any SAL_CALL SVTXAccessibleNumericField::getCurrentValue() +{ + OExternalLockGuard aGuard(this); + + double dValue = 0; + SVTXNumericField* pField = static_cast<SVTXNumericField*>(GetVCLXWindow()); + if (pField) + dValue = pField->getValue(); + + return css::uno::Any(dValue); +} + +sal_Bool SVTXAccessibleNumericField::setCurrentValue(const css::uno::Any& aNumber) +{ + OExternalLockGuard aGuard(this); + + SVTXNumericField* pField = static_cast<SVTXNumericField*>(GetVCLXWindow()); + if (!pField) + return false; + + double dValue = 0; + aNumber >>= dValue; + pField->setValue(dValue); + return true; +} + +css::uno::Any SAL_CALL SVTXAccessibleNumericField::getMaximumValue() +{ + OExternalLockGuard aGuard(this); + + double dValue = 0; + SVTXNumericField* pField = static_cast<SVTXNumericField*>(GetVCLXWindow()); + if (pField) + dValue = pField->getMax(); + + return css::uno::Any(dValue); +} + +css::uno::Any SAL_CALL SVTXAccessibleNumericField::getMinimumValue() +{ + OExternalLockGuard aGuard(this); + + double dValue = 0; + SVTXNumericField* pField = static_cast<SVTXNumericField*>(GetVCLXWindow()); + if (pField) + dValue = pField->getMin(); + + return css::uno::Any(dValue); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/toolkit/awt/vclxwindows.hxx b/include/toolkit/awt/vclxwindows.hxx index 99f8fea450fa..9e365eeb6d3f 100644 --- a/include/toolkit/awt/vclxwindows.hxx +++ b/include/toolkit/awt/vclxwindows.hxx @@ -542,7 +542,7 @@ protected: virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); } }; -class SVTXNumericField final : public css::awt::XNumericField, public SVTXFormattedField +class TOOLKIT_DLLPUBLIC SVTXNumericField final : public css::awt::XNumericField, public SVTXFormattedField { public: SVTXNumericField(); @@ -576,6 +576,8 @@ public: sal_Bool SAL_CALL isStrictFormat( ) override; virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override; + + virtual css::uno::Reference< css::accessibility::XAccessibleContext > CreateAccessibleContext() override; }; // class VCLXListBox diff --git a/include/toolkit/helper/accessiblefactory.hxx b/include/toolkit/helper/accessiblefactory.hxx index 109e1cbea038..bd7ae90976d4 100644 --- a/include/toolkit/helper/accessiblefactory.hxx +++ b/include/toolkit/helper/accessiblefactory.hxx @@ -27,6 +27,7 @@ namespace com::sun::star::accessibility { class XAccessible; class XAccessibleContext; } +class SVTXNumericField; class VCLXButton; class VCLXCheckBox; class VCLXRadioButton; @@ -116,6 +117,11 @@ namespace toolkit virtual css::uno::Reference< css::accessibility::XAccessibleContext > createAccessibleContext( VCLXHeaderBar* _pXWindow ) = 0; + /** creates an accessible context for a numeric field + */ + virtual css::uno::Reference< css::accessibility::XAccessibleContext > + createAccessibleContext( SVTXNumericField* _pXWindow ) = 0; + /** creates an accessible context for a generic window */ virtual css::uno::Reference< css::accessibility::XAccessibleContext > diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index caf63ba3b5d0..02bd6b8799e8 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -7665,6 +7665,13 @@ css::uno::Sequence< css::uno::Type > SVTXNumericField::getTypes() return aTypeList.getTypes(); } + +css::uno::Reference<accessibility::XAccessibleContext> SVTXNumericField::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext(this); +} + + void SVTXNumericField::setValue( double Value ) { SolarMutexGuard aGuard; diff --git a/toolkit/source/helper/accessibilityclient.cxx b/toolkit/source/helper/accessibilityclient.cxx index 9d795ac620e4..7136dc5a3a8d 100644 --- a/toolkit/source/helper/accessibilityclient.cxx +++ b/toolkit/source/helper/accessibilityclient.cxx @@ -119,6 +119,11 @@ namespace toolkit { return nullptr; } + css::uno::Reference< css::accessibility::XAccessibleContext > + createAccessibleContext( SVTXNumericField* /*_pXWindow*/ ) override + { + return nullptr; + } css::uno::Reference< css::accessibility::XAccessibleContext > createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) override { diff --git a/toolkit/source/helper/unowrapper.cxx b/toolkit/source/helper/unowrapper.cxx index aa32d1b86aa6..4f3f3b22b604 100644 --- a/toolkit/source/helper/unowrapper.cxx +++ b/toolkit/source/helper/unowrapper.cxx @@ -55,8 +55,8 @@ static rtl::Reference<VCLXWindow> CreateXWindow( vcl::Window const * pWindow ) // corresponding accessibility API. case WindowType::METRICBOX: case WindowType::COMBOBOX: return new VCLXComboBox; + case WindowType::FORMATTEDFIELD: return new SVTXNumericField; case WindowType::SPINFIELD: - case WindowType::FORMATTEDFIELD: case WindowType::CURRENCYFIELD: return new VCLXNumericField; case WindowType::DATEFIELD: return new VCLXDateField; case WindowType::MULTILINEEDIT: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits