JDK-8076554 : [macosx] Custom Swing text components need to allow standard accessibility
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.accessibility
  • Affected Version: 7u4,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2015-04-02
  • Updated: 2018-02-08
  • Resolved: 2016-04-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u121Fixed 9 b117Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Java platform support for accessibility features in Swing text components on
Mac OS X is tailored for JTextComponent's subclasses. 

For custom components implementing text input, it's impossible to use standard accessibility features, such as automatic reading of text under cursor and reading of selected text (using VoiceOver Mac OS functionality).

On Mac OS accessibility features are supported by Java platform directly, without the need for additional bridge software or third-party accessibility drivers (like Java Access Bridge and NVDA on Windows).

The issue is due to details of sun.lwawt.macosx.CAccessible class's
implementation - it listens to JTextComponent's document and caret events,
instead of listening to AccessibleContext's property change events.

It is thought that this is not a regression and the issue existed since Apple's Java 6.
I tagged this with noreg-hard. The way I tested it was to start VoiceOver and then run the two tests at http://cr.openjdk.java.net/~ptbrunet/JDK-8076554/test side by side to ensure the behavior was the same.

The problem is that the code is currently hardcoded to only support text accessibility for JTextComponent using the DocumentListener, CaretListener interfaces. This eliminates the ability to provide accessibility for a custom text components. The resolution is to remove the JTextComponent gate and use the PropertyChangeListener listener interface with its ACCESSIBLE_CARET_PROPERTY and ACCESSIBLE_TEXT_PROPERTY properties.

Changed this to 9 because needed by Google Android Studio and JetBrains.

Review: http://cr.openjdk.java.net/~ptbrunet/JDK-8076554/

This was reported by Tor Norbye <tnorbye@google.com> of the Google Android Studio team. He requested that this be backported to 8u after fixed in 9.

See http://tools.android.com/tech-docs/accessibility/editor https://android-review.googlesource.com/#/c/158200/1

In the case of caret updates, the problem is that CAccessible.addNotificationListeners only adds a caret listener if the object is a JTextComponent. What should be done is to use introspection to see if the object has an addCaretListener method. In the case of document updates, use introspection to see if can obtain the getDocument method. If so use it and then call its addDocumentListener method. If this change is made and if the custom control has an addCaretListener and its "Document" has an addDocumentListener then there would be no need for the custom control to subclass from JTextComponent.

Based on current implementation, notification listener in CAccessible only added for JTextComponent, JProgressBar and JSlider. Which are actually Java Accessibility fixes made by Apple through OS X v10.6 Update 2 - details see release notes:https://developer.apple.com/library/mac/releasenotes/CrossPlatform/JavaSnowLeopardUpdate2LeopardUpdate7RN/ResolvedIssues/ResolvedIssues.html So for java app to support accessibility on Mac with text editor, either need to use JTextComponent or to extend from JTextComponent for customized text editor based on current Swing Accessible code. Need further research to find out how to have better accessibility support with Swing on Mac, especially how do Swing, CAccessible.java/CAccessibleText.java interact with NSAccessibility interface on Mac.