JetBrains / JetBrainsRuntime

Runtime environment based on OpenJDK for running IntelliJ Platform-based products on Windows, macOS, and Linux
GNU General Public License v2.0
1.26k stars 192 forks source link

JBR-6808 Don't create AccessibleJTreeNode for the tree root if it's not visible #336

Closed dmitrii-drobotov closed 3 months ago

dmitrii-drobotov commented 5 months ago

This fixes an issue with AccessibleJTreeNode#getBounds, which adjusts the node's bounds according to the parent node: https://github.com/JetBrains/JetBrainsRuntime/blob/ce6f4d023beef597cb670072e093eeb0fb25dfd5/src/java.desktop/share/classes/javax/swing/JTree.java#L5425-L5437

For nodes whose parent is the invisible root, getBounds was returning null, and it caused issues with assistive technology like macOS Accessibility Zoom.

This also matches behavior in AccessibleJTree#getAccessibleChild which creates accessible node for the root only if it's visible:

https://github.com/JetBrains/JetBrainsRuntime/blob/ce6f4d023beef597cb670072e093eeb0fb25dfd5/src/java.desktop/share/classes/javax/swing/JTree.java#L4541-L4575

Before

Invisible root has an item in the hierarchy:

Accessibility hierarchy for JTree showing an item for the root, which is not visible in UI

In IntelliJ it caused issues with macOS Accessibility Zoom when selecting top level nodes:

https://github.com/JetBrains/JetBrainsRuntime/assets/102954094/e689c409-19a2-4341-a92d-b7b78e1a03ae

After

No item in the hierarchy for the invisible root:

Screenshot 2024-03-11 at 12 20 25

Issues with macOS Accessibility Zoom when selecting top level nodes are fixed:

https://github.com/JetBrains/JetBrainsRuntime/assets/102954094/002daa88-6c8a-48d1-ad69-c27e3f67b3fd

dmitrii-drobotov commented 5 months ago

I've added the test, and also ported the change to the copy of AccessibleJTreeNode in AccessBridge.java. Turns out it's used instead of the normal AccessibleJTreeNode in case when tree is the parent of the node: https://github.com/JetBrains/JetBrainsRuntime/blob/b3cd00363f3e6022b6fb47823c0128c7f5d86798/src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java#L5469-L5479

It passes null as accessible parent argument, so needs to be fixed it the same way. With this additional fix in AccessBridge, the JDK-8249806 is completely fixed.

Before fix: NVDA reads tree levels starting from 2

After: NVDA reads tree levels starting from 1