Visitar URL original
macOS a11y: let other apps set values on accessibility elements by kayakthedev · Pull Request #69 · LibreOffice/core · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions vcl/osx/a11ytextwrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *>(value) ) );
} catch ( const Exception & ) {
// empty
}
}
}

+(id)numberOfCharactersAttributeForElement:(AquaA11yWrapper *)wrapper {
Expand Down
24 changes: 20 additions & 4 deletions vcl/osx/a11yvaluewrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber *>(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<sal_Int32>( [ number intValue ] );
else if ( aCurrentValue.getValueTypeClass() == TypeClass_HYPER )
numberAny <<= static_cast<sal_Int64>( [ number longLongValue ] );
else
numberAny <<= [ number doubleValue ];
[ wrapper accessibleValue ] -> setCurrentValue ( numberAny );
} catch ( const Exception & ) {
// empty
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions vcl/osx/a11ywrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] ];
Expand Down
Loading