Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8287740: NSAccessibilityShowMenuAction not working for text editors
Backport-of: b6cdfd685d0cea308b15558e2dc607a680c89dc0
  • Loading branch information
rgithubli authored and Paul Hohensee committed Nov 2, 2022
1 parent b37d7df commit 092be50
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 9 deletions.
Expand Up @@ -615,8 +615,11 @@ - (void)getActionsWithEnv:(JNIEnv *)env
[fActions setObject:action forKey:NSAccessibilityPickAction];
[fActionSelectors addObject:[sActionSelectors objectForKey:NSAccessibilityPickAction]];
} else {
[fActions setObject:action forKey:[sActions objectForKey:[action getDescription]]];
[fActionSelectors addObject:[sActionSelectors objectForKey:[sActions objectForKey:[action getDescription]]]];
NSString *nsActionName = [sActions objectForKey:[action getDescription]];
if (nsActionName != nil) {
[fActions setObject:action forKey:nsActionName];
[fActionSelectors addObject:[sActionSelectors objectForKey:nsActionName]];
}
}
[action release];
}
Expand Down
103 changes: 96 additions & 7 deletions test/jdk/java/awt/a11y/AccessibleActionsTest.java
Expand Up @@ -40,6 +40,8 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;

Expand Down Expand Up @@ -92,6 +94,32 @@ void createTree() {
super.createUI(panel, "AccessibleActionsTest");
}

private void createEditableTextArea() {
AccessibleComponentTest.INSTRUCTIONS = "INSTRUCTIONS:\n"
+ "Check a11y show context menu in editable JTextArea.\n\n"
+ "Turn screen reader on and press Tab to move to the text area\n"
+ "Perform the VO action \"Open a shortcut menu\" (VO+Shift+m)\n\n"
+ "If the menu appears tab further and press PASS, otherwise press FAIL.";

JTextArea textArea = new MyTextArea("some text to edit");
JLabel label = new JLabel(textArea.getText().length() + " chars");
label.setLabelFor(textArea);
textArea.setEditable(true);
textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
label.setText(String.valueOf(textArea.getText().length()) + " chars");
}
});

JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(textArea);
panel.add(label);
exceptionString = "Editable text area test failed!";
super.createUI(panel, "AccessibleTextTest");
}

public static void main(String[] args) throws Exception {
AccessibleActionsTest test = new AccessibleActionsTest();

Expand All @@ -110,6 +138,14 @@ public static void main(String[] args) throws Exception {
if (!testResult) {
throw new RuntimeException(a11yTest.exceptionString);
}

countDownLatch = test.createCountDownLatch();
SwingUtilities.invokeLater(test::createEditableTextArea);
countDownLatch.await();

if (!testResult) {
throw new RuntimeException(a11yTest.exceptionString);
}
}

private class AccessibleActionsTestFrame extends JPanel {
Expand Down Expand Up @@ -167,17 +203,70 @@ public boolean doAccessibleAction(int i) {
}
}

private static JPopupMenu createPopup() {
JPopupMenu popup = new JPopupMenu("MENU");
popup.add("One");
popup.add("Two");
popup.add("Three");
return popup;
}


private static void changeText(JLabel label, String text) {
label.setText(text);
}

}

private static class MyTextArea extends JTextArea {

public MyTextArea(String some_text_to_edit) {
}

@Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new MyAccessibleJTextArea();
}
return accessibleContext;
}

private class MyAccessibleJTextArea extends JTextArea.AccessibleJTextArea {
@Override
public AccessibleAction getAccessibleAction() {
return new AccessibleAction() {
@Override
public int getAccessibleActionCount() {
AccessibleAction aa = MyAccessibleJTextArea.super.getAccessibleAction();
if (aa == null) {
return 1;
}
int count = aa.getAccessibleActionCount();
return aa.getAccessibleActionCount() + 1;
}

@Override
public String getAccessibleActionDescription(int i) {
AccessibleAction aa = MyAccessibleJTextArea.super.getAccessibleAction();
if ((aa != null) && (i >= 0) && (i < aa.getAccessibleActionCount())) {
return aa.getAccessibleActionDescription(i);
}
return AccessibleAction.TOGGLE_POPUP;
}

@Override
public boolean doAccessibleAction(int i) {
AccessibleAction aa = MyAccessibleJTextArea.super.getAccessibleAction();
if ((aa != null) && (i >= 0) && (i < aa.getAccessibleActionCount())) {
return aa.doAccessibleAction(i);
}
JPopupMenu popup = createPopup();
popup.show(MyTextArea.this, 0, 0);
return true;
}
};
}
}
}

private static JPopupMenu createPopup() {
JPopupMenu popup = new JPopupMenu("MENU");
popup.add("One");
popup.add("Two");
popup.add("Three");
return popup;
}
}

1 comment on commit 092be50

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.