vcl/qt5/QtAccessibleWidget.cxx |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

New commits:
commit d2daaedf2e3b30ff28f4a9a33b6b70738273f9e3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Oct 24 12:01:05 2023 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Tue Oct 24 14:55:24 2023 +0200

    qt a11y: Take current type into account when setting new value
    
    As the `XAccessibleValue` documentation [1] describes,
    the underlying implementations can used different types
    of numerical values.
    
    Qt's `QAccessibleValueInterface` uses `QVariant`, so could
    in theory also support different numerical types.
    
    The AT-SPI Value interface however always uses double. [2]
    
    So far, `QtAccessibleWidget::setCurrentValue` was also always
    extracting a double value from the `QVariant` param and
    creating an `Any` from that.
    
    This however would result in any `XAccessibleValue::setCurrentValue`
    implementations assuming to be passed an integer would fail to
    extract a proper new value from the Any.
    
    As an example, selecting a currently checked checkbox
    (e.g. the "Automatic" checkbox in Writer's "Paragraph"
    formatting dialog, "Indents & Spacing" tab) in Accerciser's
    treeview of LO's a11y hierarchy woul result in the checkbox
    to be unchecked, because Accerciser reads the current and then
    sets the same value again when selecting an item with its
    "Interface View" tab active.
    
    Prevent that from happening by passing a `sal_Int32`/`sal_Int64`
    value again if the current value is also using that type.
    
    [1] offapi/com/sun/star/accessibility/XAccessibleValue.idl
    [2] 
https://gitlab.gnome.org/GNOME/at-spi2-core/-/blob/7cc4cee53ddbd22631fd110f0e5ce045dec2e411/xml/Value.xml
    
    Change-Id: I8674fc37798491fd0b57543acb491edbd4a5a056
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158380
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtAccessibleWidget.cxx b/vcl/qt5/QtAccessibleWidget.cxx
index 3407eb574d5c..cec049340f07 100644
--- a/vcl/qt5/QtAccessibleWidget.cxx
+++ b/vcl/qt5/QtAccessibleWidget.cxx
@@ -1282,7 +1282,17 @@ void QtAccessibleWidget::setCurrentValue(const QVariant& 
value)
     Reference<XAccessibleValue> xValue(xAc, UNO_QUERY);
     if (!xValue.is())
         return;
-    xValue->setCurrentValue(Any(value.toDouble()));
+
+    // Different types of numerical values for XAccessibleValue are possible.
+    // If current value has an integer type, also use that for the new value, 
to make
+    // sure underlying implementations expecting that can handle the value 
properly.
+    const Any aCurrentValue = xValue->getCurrentValue();
+    if (aCurrentValue.getValueTypeClass() == 
css::uno::TypeClass::TypeClass_LONG)
+        xValue->setCurrentValue(Any(static_cast<sal_Int32>(value.toInt())));
+    else if (aCurrentValue.getValueTypeClass() == 
css::uno::TypeClass::TypeClass_HYPER)
+        
xValue->setCurrentValue(Any(static_cast<sal_Int64>(value.toLongLong())));
+    else
+        xValue->setCurrentValue(Any(value.toDouble()));
 }
 
 // QAccessibleTableInterface

Reply via email to