From 9716b65fba42348c2192d17d5aecd97bd6ee94c3 Mon Sep 17 00:00:00 2001 From: arkis Date: Sat, 7 Nov 2026 12:16:57 +0100 Subject: [PATCH] macOS a11y: let other apps set values on accessibility elements AquaA11yWrapper is an NSAccessibilityElement and overrides the NSAccessibility protocol's getters (accessibilityValue etc.), but none of its setters. When another process sets an attribute with AXUIElementSetAttributeValue(), AppKit calls the protocol setter, e.g. -setAccessibilityValue:, and NSAccessibilityElement's own implementation drops the value. -accessibilitySetValue:forAttribute:, which dispatches to the component, text, selection and value wrappers, is never reached. Since isAccessibilitySelectorAllowed: allows the setters for settable attributes, the caller is told the attribute is settable and the write succeeds, but nothing changes. Measured on macOS 26 with Calc: setting a cell's AXValue to a string, to 42 and to 3.5, and setting its AXSelectedText, all returned kAXErrorSuccess, and the cell stayed empty. A standalone NSAccessibilityElement subclass built the same way shows the same on macOS 26: AXValue reported settable, the write returned success, and -accessibilitySetValue:forAttribute: was not called until -setAccessibilityValue: was overridden to forward to it. So: - Add the setters for the attributes the wrappers can set (AXValue, AXFocused, AXSelectedText, AXSelectedTextRange, AXSelectedChildren), each forwarding to -accessibilitySetValue:forAttribute:. - AquaA11yValueWrapper passed Any( [ number longValue ] ). long is 64 bit on macOS, so that Any is a hyper, from which neither a sal_Int32 (scroll bars, check boxes, ...) nor a double (Calc and Writer cells, numeric fields) can be extracted, so setCurrentValue() never took it. Use the type of the current value instead, as the Qt backend does in QtAccessibleWidget::setCurrentValue(), and double otherwise. A number set as a Calc cell's AXValue then reaches ScAccessibleCellBase::setCurrentValue(). - AquaA11yTextWrapper's AXValue setter was an empty TODO, while isAttributeSettable: reports AXValue settable for every non static text element. Implement it with XAccessibleEditableText::setText() when the element has editable text, like the AXSelectedText setter next to it does with replaceText(). Elements without XAccessibleEditableText (e.g. Calc cells, whose text is AccessibleStaticTextBase) still report AXValue and AXSelectedText settable through the text wrapper and ignore a string; that is left as it is here. Co-Authored-By: Claude Opus 5.5 Change-Id: I32ea2c26baa6afe4bb77ac7f7bbc0e18462b8ebe --- vcl/osx/a11ytextwrapper.mm | 10 +++++++--- vcl/osx/a11yvaluewrapper.mm | 24 ++++++++++++++++++++---- vcl/osx/a11ywrapper.mm | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/vcl/osx/a11ytextwrapper.mm b/vcl/osx/a11ytextwrapper.mm index 5a932d38a2318..dbeb761e23c69 100644 --- a/vcl/osx/a11ytextwrapper.mm +++ b/vcl/osx/a11ytextwrapper.mm @@ -47,9 +47,13 @@ +(id)valueAttributeForElement:(AquaA11yWrapper *)wrapper { +(void)setValueAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value { - // TODO - (void)wrapper; - (void)value; + if ( [ wrapper accessibleEditableText ] && [ value isKindOfClass: [ NSString class ] ] ) { + try { + [ wrapper accessibleEditableText ] -> setText ( GetOUString ( static_cast(value) ) ); + } catch ( const Exception & ) { + // empty + } + } } +(id)numberOfCharactersAttributeForElement:(AquaA11yWrapper *)wrapper { diff --git a/vcl/osx/a11yvaluewrapper.mm b/vcl/osx/a11yvaluewrapper.mm index 0cf3786fbe6e8..8274669b0642c 100644 --- a/vcl/osx/a11yvaluewrapper.mm +++ b/vcl/osx/a11yvaluewrapper.mm @@ -59,12 +59,28 @@ +(id)maxValueAttributeForElement:(AquaA11yWrapper *)wrapper { } +(void)setValueAttributeForElement:(AquaA11yWrapper *)wrapper to:(id)value { - // TODO: Detect Type from NSNumber - if ( [ value isKindOfClass: [ NSNumber class ] ] + if ( [ value isKindOfClass: [ NSNumber class ] ] && [ wrapper accessibleValue ] ) { NSNumber * number = static_cast(value); - Any numberAny ( [ number longValue ] ); - [ wrapper accessibleValue ] -> setCurrentValue ( numberAny ); + try { + // Different types of numerical values for XAccessibleValue are possible. + // If the current value has an integer type, also use that for the new + // value, so that implementations expecting it can handle the value. + // Otherwise use double, which is what e.g. Calc and Writer cells expect. + // Note: Any ( long ) would be a hyper, which neither a sal_Int32 nor + // a double can be extracted from. + const Any aCurrentValue = [ wrapper accessibleValue ] -> getCurrentValue(); + Any numberAny; + if ( aCurrentValue.getValueTypeClass() == TypeClass_LONG ) + numberAny <<= static_cast( [ number intValue ] ); + else if ( aCurrentValue.getValueTypeClass() == TypeClass_HYPER ) + numberAny <<= static_cast( [ number longLongValue ] ); + else + numberAny <<= [ number doubleValue ]; + [ wrapper accessibleValue ] -> setCurrentValue ( numberAny ); + } catch ( const Exception & ) { + // empty + } } } diff --git a/vcl/osx/a11ywrapper.mm b/vcl/osx/a11ywrapper.mm index d268d8668143d..d3b78cdea0cc5 100644 --- a/vcl/osx/a11ywrapper.mm +++ b/vcl/osx/a11ywrapper.mm @@ -1500,6 +1500,36 @@ - (NSRange)accessibilitySelectedTextRange return NSMakeRange( NSNotFound, 0 ); } +// Setters of the NSAccessibility protocol. AppKit calls these when another +// process sets an attribute, and NSAccessibilityElement's own implementations +// ignore the value, so forward them to -accessibilitySetValue:forAttribute:. +// isAccessibilitySelectorAllowed: only allows them for settable attributes. + +- (void)setAccessibilityValue:(id)value +{ + [ self accessibilitySetValue: value forAttribute: NSAccessibilityValueAttribute ]; +} + +- (void)setAccessibilityFocused:(BOOL)bFocused +{ + [ self accessibilitySetValue: [ NSNumber numberWithBool: bFocused ] forAttribute: NSAccessibilityFocusedAttribute ]; +} + +- (void)setAccessibilitySelectedText:(NSString *)pSelectedText +{ + [ self accessibilitySetValue: pSelectedText forAttribute: NSAccessibilitySelectedTextAttribute ]; +} + +- (void)setAccessibilitySelectedTextRange:(NSRange)aRange +{ + [ self accessibilitySetValue: [ NSValue valueWithRange: aRange ] forAttribute: NSAccessibilitySelectedTextRangeAttribute ]; +} + +- (void)setAccessibilitySelectedChildren:(NSArray *)pSelectedChildren +{ + [ self accessibilitySetValue: pSelectedChildren forAttribute: NSAccessibilitySelectedChildrenAttribute ]; +} + - (NSAttributedString *)accessibilityAttributedStringForRange:(NSRange)aRange { return [ self accessibilityAttributeValue: NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter: [ NSValue valueWithRange: aRange ] ];