diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2021-07-28 09:39:07 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2021-07-28 15:44:58 +0200 |
commit | 349a8801b9ee98f4f9ee1d35f7d28e17baedf7cc (patch) | |
tree | 2bd6dd20f7618a812f550867515f4bfa9a2cc553 /accessibility | |
parent | 9ceb47ce712157019ca06ee11c66515ea7cc16ec (diff) |
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.weghorn@posteo.de>
Diffstat (limited to 'accessibility')
-rw-r--r-- | accessibility/Library_acc.mk | 1 | ||||
-rw-r--r-- | accessibility/inc/standard/svtaccessiblenumericfield.hxx | 50 | ||||
-rw-r--r-- | accessibility/inc/standard/vclxaccessibleedit.hxx | 5 | ||||
-rw-r--r-- | accessibility/source/helper/acc_factory.cxx | 8 | ||||
-rw-r--r-- | accessibility/source/standard/svtaccessiblenumericfield.cxx | 93 |
5 files changed, 155 insertions, 2 deletions
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> @@ -106,6 +107,8 @@ public: 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 > createAccessible( Menu* _pMenu, bool _bIsMenuBar ) override; @@ -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: */ |