Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
8226253: JAWS reports wrong number of radio buttons when buttons are …
Browse files Browse the repository at this point in the history
…hidden

Reviewed-by: kizune, pbansal
  • Loading branch information
arapte committed Mar 14, 2020
1 parent 23fda7e commit 3a7389f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/java.desktop/share/classes/javax/swing/JList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -3317,6 +3317,7 @@ public AccessibleStateSet getAccessibleStateSet() {
}

s.add(AccessibleState.SELECTABLE);
s.add(AccessibleState.VISIBLE);
if (parent.isFocusOwner()
&& (indexInParent == parent.getLeadSelectionIndex())) {
s.add(AccessibleState.ACTIVE);
Expand All @@ -3329,11 +3330,6 @@ public AccessibleStateSet getAccessibleStateSet() {
} else if (s.contains(AccessibleState.SHOWING)) {
s.remove(AccessibleState.SHOWING);
}
if (this.isVisible()) {
s.add(AccessibleState.VISIBLE);
} else if (s.contains(AccessibleState.VISIBLE)) {
s.remove(AccessibleState.VISIBLE);
}
s.add(AccessibleState.TRANSIENT); // cell-rendered
return s;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -1457,6 +1457,38 @@ public AccessibleStateSet call() throws Exception {
return null;
}

private int getNonVisibleChildrenCountTillIndex(AccessibleContext parentAC, int index) {
if (parentAC != null && index >= 0 && index < parentAC.getAccessibleChildrenCount()) {
int nonVisibleChildrenCount = 0;
for (int i = 0; i <= index; i++) {
if (!parentAC.getAccessibleChild(i).getAccessibleContext().getAccessibleStateSet().contains(AccessibleState.VISIBLE)) {
nonVisibleChildrenCount++;
}
}
return nonVisibleChildrenCount;
}
return 0;
}

private Accessible getVisibleChildAtIndex(AccessibleContext parentAC, int index) {
if (parentAC != null && index >= 0 && index < parentAC.getAccessibleChildrenCount()) {
int visibleIndex = -1;
int childrenCount = parentAC.getAccessibleChildrenCount();
for (int i = 0; i <= childrenCount; i++) {
Accessible child = parentAC.getAccessibleChild(i);
if (child != null) {
AccessibleContext ac = child.getAccessibleContext();
if (ac != null && ac.getAccessibleStateSet().contains(AccessibleState.VISIBLE)) {
visibleIndex++;
}
if (visibleIndex == index) {
return child;
}
}
}
}
return null;
}
/**
* returns the AccessibleParent from an AccessibleContext
*/
Expand Down Expand Up @@ -1487,7 +1519,12 @@ private int getAccessibleIndexInParentFromContext(final AccessibleContext ac) {
return InvocationUtils.invokeAndWait(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return ac.getAccessibleIndexInParent();
int indexInParent = ac.getAccessibleIndexInParent();
Accessible parent = ac.getAccessibleParent();
if (parent != null) {
indexInParent -= getNonVisibleChildrenCountTillIndex(parent.getAccessibleContext(), indexInParent);
}
return indexInParent;
}
}, ac);
}
Expand All @@ -1501,7 +1538,8 @@ private int getAccessibleChildrenCountFromContext(final AccessibleContext ac) {
return InvocationUtils.invokeAndWait(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return ac.getAccessibleChildrenCount();
int childrenCount = ac.getAccessibleChildrenCount();
return childrenCount - getNonVisibleChildrenCountTillIndex(ac, childrenCount - 1);
}
}, ac);
}
Expand Down Expand Up @@ -1537,7 +1575,7 @@ public JTable call() throws Exception {
return InvocationUtils.invokeAndWait(new Callable<AccessibleContext>() {
@Override
public AccessibleContext call() throws Exception {
Accessible a = ac.getAccessibleChild(index);
Accessible a = getVisibleChildAtIndex(ac, index);
if (a != null) {
return a.getAccessibleContext();
}
Expand Down Expand Up @@ -3517,7 +3555,11 @@ public Integer call() throws Exception {
AccessibleRelation[] relations = ars.toArray();
if (relations != null && i >= 0 && i < relations.length) {
Object[] targets = relations[i].getTarget();
return targets.length;
if (targets != null) {
int targetCount = targets.length -
getNonVisibleTargetCountTillIndex(targets, targets.length - 1);
return targetCount;
}
}
}
}
Expand All @@ -3543,7 +3585,7 @@ public AccessibleContext call() throws Exception {
if (relations != null && i >= 0 && i < relations.length) {
Object[] targets = relations[i].getTarget();
if (targets != null && j >= 0 & j < targets.length) {
Object o = targets[j];
Object o = getVisibleTargetAtIndex(targets, j);
if (o instanceof Accessible) {
return ((Accessible) o).getAccessibleContext();
}
Expand All @@ -3556,6 +3598,40 @@ public AccessibleContext call() throws Exception {
}, ac);
}

private Object getVisibleTargetAtIndex(Object[] targets, int index) {
if (index >= 0 && index < targets.length) {
int visibleTargetIndex = -1;
for (int i = 0; i < targets.length; i++) {
if (targets[i] instanceof Accessible) {
AccessibleContext ac = ((Accessible) targets[i]).getAccessibleContext();
if (ac != null && ac.getAccessibleStateSet().contains(AccessibleState.VISIBLE)) {
visibleTargetIndex++;
}
if (visibleTargetIndex == index) {
return targets[i];
}
}
}
}
return null;
}

private int getNonVisibleTargetCountTillIndex(Object[] targets, int index) {
if (index >= 0 && index < targets.length) {
int nonVisibleTargetsCount = 0;
for (int i = 0; i <= index; i++) {
if (targets[i] instanceof Accessible) {
AccessibleContext ac = ((Accessible) targets[i]).getAccessibleContext();
if (ac != null && !ac.getAccessibleStateSet().contains(AccessibleState.VISIBLE)) {
nonVisibleTargetsCount++;
}
}
}
return nonVisibleTargetsCount;
}
return 0;
}

// ========= AccessibleHypertext =========

private Map<AccessibleHypertext, AccessibleContext> hyperTextContextMap = new WeakHashMap<>();
Expand Down

0 comments on commit 3a7389f

Please sign in to comment.