-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBR-6808 Don't create AccessibleJTreeNode for the tree root if it's n…
…ot visible * This fixes an issue with AccessibleJTreeNode#getBounds, which adjusts the node's bounds according to the parent node. For nodes whose parent is the invisible root, getBounds was returning null, and it caused issues with assistive technology like macOS Accessibility Zoom. * Additionally, NVDA will now report correct tree depth levels because the root node won't add to the levels count (JDK-8249806). (cherry picked from commit f7c47bf)
- Loading branch information
1 parent
14b289a
commit 487c23b
Showing
3 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
test/jdk/javax/accessibility/8249806/AccessibleJTreeNodeAccessibleParentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2024, JetBrains s.r.o.. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8249806 | ||
* @summary Tests that JTree's root is not set as accessible parent of top-level tree nodes (direct children of root) | ||
* when the JTree has setRootVisible(false). | ||
* @run main AccessibleJTreeNodeAccessibleParentTest | ||
*/ | ||
|
||
import java.awt.Robot; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javax.accessibility.Accessible; | ||
import javax.accessibility.AccessibleContext; | ||
import javax.swing.*; | ||
import javax.swing.tree.DefaultMutableTreeNode; | ||
|
||
public class AccessibleJTreeNodeAccessibleParentTest { | ||
private static JTree jTree; | ||
private static JFrame jFrame; | ||
|
||
private static void createGUI() { | ||
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); | ||
DefaultMutableTreeNode node = new DefaultMutableTreeNode("node"); | ||
root.add(node); | ||
|
||
jTree = new JTree(root); | ||
jTree.setRootVisible(false); | ||
|
||
jFrame = new JFrame(); | ||
jFrame.setBounds(100, 100, 300, 300); | ||
jFrame.getContentPane().add(jTree); | ||
jFrame.setVisible(true); | ||
} | ||
|
||
private static void doTest() throws Exception { | ||
try { | ||
SwingUtilities.invokeAndWait(() -> createGUI()); | ||
Robot robot = new Robot(); | ||
robot.waitForIdle(); | ||
|
||
AtomicBoolean accessibleNodeInitialized = new AtomicBoolean(false); | ||
|
||
SwingUtilities.invokeAndWait(() -> { | ||
jTree.getAccessibleContext().addPropertyChangeListener(evt -> { | ||
// When an AccessibleJTreeNode is created for the active descendant change event, | ||
// its parent is not set on initialization but calculated on the first access. | ||
// This imitates the way assistive tools obtain AccessibleJTreeNode objects. | ||
if (AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY.equals(evt.getPropertyName()) && | ||
evt.getNewValue() instanceof Accessible accessibleNode) { | ||
// Check that the parent of the top-level node is the tree itself instead of the invisible root. | ||
if (!jTree.equals(accessibleNode.getAccessibleContext().getAccessibleParent())) { | ||
throw new RuntimeException("Accessible parent of the top-level node is not the tree."); | ||
} | ||
accessibleNodeInitialized.set(true); | ||
} | ||
}); | ||
|
||
jTree.setSelectionRow(0); | ||
}); | ||
robot.waitForIdle(); | ||
|
||
if (!accessibleNodeInitialized.get()) { | ||
throw new RuntimeException("The active descendant property change event wasn't fired, " + | ||
"or the accessible node wasn't initialized properly."); | ||
} | ||
} finally { | ||
SwingUtilities.invokeAndWait(() -> jFrame.dispose()); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
doTest(); | ||
System.out.println("Test Passed"); | ||
} | ||
} | ||
|