author | ptbrunet |
Mon, 18 Jul 2016 15:43:30 -0500 | |
changeset 39873 | 76907ae1b680 |
parent 37787 | de878aeb7ed2 |
child 40719 | 4ae72a69bd3b |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
37787 | 2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.lwawt.macosx; |
|
27 |
||
37787 | 28 |
import sun.lwawt.LWWindowPeer; |
29 |
||
12047 | 30 |
import java.awt.*; |
31 |
import java.beans.*; |
|
32 |
import java.lang.reflect.Field; |
|
33 |
import java.lang.reflect.InvocationTargetException; |
|
34 |
import java.util.*; |
|
35 |
import java.util.concurrent.Callable; |
|
37787 | 36 |
import sun.awt.AWTAccessor; |
12047 | 37 |
|
38 |
import javax.accessibility.*; |
|
39 |
import javax.swing.*; |
|
40 |
||
41 |
class CAccessibility implements PropertyChangeListener { |
|
42 |
private static Set<String> ignoredRoles; |
|
43 |
||
44 |
static { |
|
45 |
// Need to load the native library for this code. |
|
12559
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
46 |
java.security.AccessController.doPrivileged( |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
47 |
new java.security.PrivilegedAction<Void>() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
48 |
public Void run() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
49 |
System.loadLibrary("awt"); |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
50 |
return null; |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
51 |
} |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
52 |
}); |
12047 | 53 |
} |
54 |
||
55 |
static CAccessibility sAccessibility; |
|
56 |
static synchronized CAccessibility getAccessibility(final String[] roles) { |
|
57 |
if (sAccessibility != null) return sAccessibility; |
|
58 |
sAccessibility = new CAccessibility(); |
|
59 |
||
60 |
if (roles != null) { |
|
61 |
ignoredRoles = new HashSet<String>(roles.length); |
|
62 |
for (final String role : roles) ignoredRoles.add(role); |
|
63 |
} else { |
|
64 |
ignoredRoles = new HashSet<String>(); |
|
65 |
} |
|
66 |
||
67 |
return sAccessibility; |
|
68 |
} |
|
69 |
||
70 |
private CAccessibility() { |
|
71 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", this); |
|
72 |
} |
|
73 |
||
74 |
public void propertyChange(final PropertyChangeEvent evt) { |
|
75 |
if (evt.getNewValue() == null) return; |
|
76 |
focusChanged(); |
|
77 |
} |
|
78 |
||
79 |
private native void focusChanged(); |
|
80 |
||
81 |
static <T> T invokeAndWait(final Callable<T> callable, final Component c) { |
|
82 |
try { |
|
83 |
return LWCToolkit.invokeAndWait(callable, c); |
|
84 |
} catch (final Exception e) { e.printStackTrace(); } |
|
85 |
return null; |
|
86 |
} |
|
87 |
||
88 |
static void invokeLater(final Runnable runnable, final Component c) { |
|
89 |
try { |
|
90 |
LWCToolkit.invokeLater(runnable, c); |
|
91 |
} catch (InvocationTargetException e) { e.printStackTrace(); } |
|
92 |
} |
|
93 |
||
94 |
public static String getAccessibleActionDescription(final AccessibleAction aa, final int index, final Component c) { |
|
95 |
if (aa == null) return null; |
|
96 |
||
97 |
return invokeAndWait(new Callable<String>() { |
|
98 |
public String call() throws Exception { |
|
99 |
return aa.getAccessibleActionDescription(index); |
|
100 |
} |
|
101 |
}, c); |
|
102 |
} |
|
103 |
||
104 |
public static void doAccessibleAction(final AccessibleAction aa, final int index, final Component c) { |
|
105 |
// We make this an invokeLater because we don't need a reply. |
|
106 |
if (aa == null) return; |
|
107 |
||
108 |
invokeLater(new Runnable() { |
|
109 |
public void run() { |
|
110 |
aa.doAccessibleAction(index); |
|
111 |
} |
|
112 |
}, c); |
|
113 |
} |
|
114 |
||
115 |
public static Dimension getSize(final AccessibleComponent ac, final Component c) { |
|
116 |
if (ac == null) return null; |
|
117 |
||
118 |
return invokeAndWait(new Callable<Dimension>() { |
|
119 |
public Dimension call() throws Exception { |
|
120 |
return ac.getSize(); |
|
121 |
} |
|
122 |
}, c); |
|
123 |
} |
|
124 |
||
125 |
public static AccessibleSelection getAccessibleSelection(final AccessibleContext ac, final Component c) { |
|
126 |
if (ac == null) return null; |
|
127 |
||
128 |
return invokeAndWait(new Callable<AccessibleSelection>() { |
|
129 |
public AccessibleSelection call() throws Exception { |
|
130 |
return ac.getAccessibleSelection(); |
|
131 |
} |
|
132 |
}, c); |
|
133 |
} |
|
134 |
||
135 |
public static Accessible ax_getAccessibleSelection(final AccessibleContext ac, final int index, final Component c) { |
|
136 |
if (ac == null) return null; |
|
137 |
||
138 |
return invokeAndWait(new Callable<Accessible>() { |
|
139 |
public Accessible call() throws Exception { |
|
140 |
final AccessibleSelection as = ac.getAccessibleSelection(); |
|
141 |
if (as == null) return null; |
|
142 |
return as.getAccessibleSelection(index); |
|
143 |
} |
|
144 |
}, c); |
|
145 |
} |
|
146 |
||
147 |
// KCH - can we make this a postEvent? |
|
148 |
public static void addAccessibleSelection(final AccessibleContext ac, final int index, final Component c) { |
|
149 |
if (ac == null) return; |
|
150 |
||
151 |
invokeLater(new Runnable() { |
|
152 |
public void run() { |
|
153 |
final AccessibleSelection as = ac.getAccessibleSelection(); |
|
154 |
if (as == null) return; |
|
155 |
as.addAccessibleSelection(index); |
|
156 |
} |
|
157 |
}, c); |
|
158 |
} |
|
159 |
||
160 |
public static AccessibleContext getAccessibleContext(final Accessible a, final Component c) { |
|
161 |
if (a == null) return null; |
|
162 |
||
163 |
return invokeAndWait(new Callable<AccessibleContext>() { |
|
164 |
public AccessibleContext call() throws Exception { |
|
165 |
return a.getAccessibleContext(); |
|
166 |
} |
|
167 |
}, c); |
|
168 |
} |
|
169 |
||
170 |
public static boolean isAccessibleChildSelected(final Accessible a, final int index, final Component c) { |
|
171 |
if (a == null) return false; |
|
172 |
||
173 |
return invokeAndWait(new Callable<Boolean>() { |
|
174 |
public Boolean call() throws Exception { |
|
175 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
176 |
if (ac == null) return Boolean.FALSE; |
|
177 |
||
178 |
final AccessibleSelection as = ac.getAccessibleSelection(); |
|
179 |
if (as == null) return Boolean.FALSE; |
|
180 |
||
33514
fbf20d4efe68
8139754: Change Boolean constructor use to the use of Boolean factorymethods. For the macosx-port-dev area
sebastian
parents:
32865
diff
changeset
|
181 |
return as.isAccessibleChildSelected(index); |
12047 | 182 |
} |
183 |
}, c); |
|
184 |
} |
|
185 |
||
186 |
public static AccessibleStateSet getAccessibleStateSet(final AccessibleContext ac, final Component c) { |
|
187 |
if (ac == null) return null; |
|
188 |
||
189 |
return invokeAndWait(new Callable<AccessibleStateSet>() { |
|
190 |
public AccessibleStateSet call() throws Exception { |
|
191 |
return ac.getAccessibleStateSet(); |
|
192 |
} |
|
193 |
}, c); |
|
194 |
} |
|
195 |
||
196 |
public static boolean contains(final AccessibleContext ac, final AccessibleState as, final Component c) { |
|
197 |
if (ac == null || as == null) return false; |
|
198 |
||
199 |
return invokeAndWait(new Callable<Boolean>() { |
|
200 |
public Boolean call() throws Exception { |
|
201 |
final AccessibleStateSet ass = ac.getAccessibleStateSet(); |
|
202 |
if (ass == null) return null; |
|
203 |
return ass.contains(as); |
|
204 |
} |
|
205 |
}, c); |
|
206 |
} |
|
207 |
||
208 |
static Field getAccessibleBundleKeyFieldWithReflection() { |
|
209 |
try { |
|
210 |
final Field fieldKey = AccessibleBundle.class.getDeclaredField("key"); |
|
211 |
fieldKey.setAccessible(true); |
|
212 |
return fieldKey; |
|
213 |
} catch (final SecurityException e) { |
|
214 |
e.printStackTrace(); |
|
215 |
} catch (final NoSuchFieldException e) { |
|
216 |
e.printStackTrace(); |
|
217 |
} |
|
218 |
return null; |
|
219 |
} |
|
220 |
private static final Field FIELD_KEY = getAccessibleBundleKeyFieldWithReflection(); |
|
221 |
||
222 |
static String getAccessibleRoleFor(final Accessible a) { |
|
223 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
224 |
if (ac == null) return null; |
|
225 |
||
226 |
final AccessibleRole role = ac.getAccessibleRole(); |
|
227 |
try { |
|
228 |
return (String)FIELD_KEY.get(role); |
|
229 |
} catch (final IllegalArgumentException e) { |
|
230 |
e.printStackTrace(); |
|
231 |
} catch (final IllegalAccessException e) { |
|
232 |
e.printStackTrace(); |
|
233 |
} |
|
234 |
return null; |
|
235 |
} |
|
236 |
||
237 |
public static String getAccessibleRole(final Accessible a, final Component c) { |
|
238 |
if (a == null) return null; |
|
239 |
||
240 |
return invokeAndWait(new Callable<String>() { |
|
241 |
public String call() throws Exception { |
|
242 |
final Accessible sa = CAccessible.getSwingAccessible(a); |
|
243 |
final String role = getAccessibleRoleFor(a); |
|
244 |
||
245 |
if (!"text".equals(role)) return role; |
|
246 |
if (sa instanceof JTextArea || sa instanceof JEditorPane) { |
|
247 |
return "textarea"; |
|
248 |
} |
|
249 |
return role; |
|
250 |
} |
|
251 |
}, c); |
|
252 |
} |
|
253 |
||
254 |
public static Point getLocationOnScreen(final AccessibleComponent ac, final Component c) { |
|
255 |
if (ac == null) return null; |
|
256 |
||
257 |
return invokeAndWait(new Callable<Point>() { |
|
258 |
public Point call() throws Exception { |
|
259 |
return ac.getLocationOnScreen(); |
|
260 |
} |
|
261 |
}, c); |
|
262 |
} |
|
263 |
||
264 |
public static int getCharCount(final AccessibleText at, final Component c) { |
|
265 |
if (at == null) return 0; |
|
266 |
||
267 |
return invokeAndWait(new Callable<Integer>() { |
|
268 |
public Integer call() throws Exception { |
|
269 |
return at.getCharCount(); |
|
270 |
} |
|
271 |
}, c); |
|
272 |
} |
|
273 |
||
274 |
// Accessibility Threadsafety for JavaComponentAccessibility.m |
|
275 |
public static Accessible getAccessibleParent(final Accessible a, final Component c) { |
|
276 |
if (a == null) return null; |
|
277 |
||
278 |
return invokeAndWait(new Callable<Accessible>() { |
|
279 |
public Accessible call() throws Exception { |
|
280 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
281 |
if (ac == null) return null; |
|
282 |
return ac.getAccessibleParent(); |
|
283 |
} |
|
284 |
}, c); |
|
285 |
} |
|
286 |
||
287 |
public static int getAccessibleIndexInParent(final Accessible a, final Component c) { |
|
39873
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
288 |
if (a == null) return -1; |
12047 | 289 |
|
290 |
return invokeAndWait(new Callable<Integer>() { |
|
291 |
public Integer call() throws Exception { |
|
292 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
293 |
if (ac == null) return null; |
|
294 |
return ac.getAccessibleIndexInParent(); |
|
295 |
} |
|
296 |
}, c); |
|
297 |
} |
|
298 |
||
299 |
public static AccessibleComponent getAccessibleComponent(final Accessible a, final Component c) { |
|
300 |
if (a == null) return null; |
|
301 |
||
302 |
return invokeAndWait(new Callable<AccessibleComponent>() { |
|
303 |
public AccessibleComponent call() throws Exception { |
|
304 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
305 |
if (ac == null) return null; |
|
306 |
return ac.getAccessibleComponent(); |
|
307 |
} |
|
308 |
}, c); |
|
309 |
} |
|
310 |
||
311 |
public static AccessibleValue getAccessibleValue(final Accessible a, final Component c) { |
|
312 |
if (a == null) return null; |
|
313 |
||
314 |
return invokeAndWait(new Callable<AccessibleValue>() { |
|
315 |
public AccessibleValue call() throws Exception { |
|
316 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
317 |
if (ac == null) return null; |
|
318 |
||
319 |
AccessibleValue accessibleValue = ac.getAccessibleValue(); |
|
320 |
return accessibleValue; |
|
321 |
} |
|
322 |
}, c); |
|
323 |
} |
|
324 |
||
325 |
public static String getAccessibleName(final Accessible a, final Component c) { |
|
326 |
if (a == null) return null; |
|
327 |
||
328 |
return invokeAndWait(new Callable<String>() { |
|
329 |
public String call() throws Exception { |
|
330 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
331 |
if (ac == null) return null; |
|
332 |
||
333 |
final String accessibleName = ac.getAccessibleName(); |
|
334 |
if (accessibleName == null) { |
|
335 |
return ac.getAccessibleDescription(); |
|
336 |
} |
|
337 |
return accessibleName; |
|
338 |
} |
|
339 |
}, c); |
|
340 |
} |
|
341 |
||
342 |
public static AccessibleText getAccessibleText(final Accessible a, final Component c) { |
|
343 |
if (a == null) return null; |
|
344 |
||
345 |
return invokeAndWait(new Callable<AccessibleText>() { |
|
346 |
public AccessibleText call() throws Exception { |
|
347 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
348 |
if (ac == null) return null; |
|
349 |
||
350 |
AccessibleText accessibleText = ac.getAccessibleText(); |
|
351 |
return accessibleText; |
|
352 |
} |
|
353 |
}, c); |
|
354 |
} |
|
355 |
||
356 |
public static String getAccessibleDescription(final Accessible a, final Component c) { |
|
357 |
if (a == null) return null; |
|
358 |
||
359 |
return invokeAndWait(new Callable<String>() { |
|
360 |
public String call() throws Exception { |
|
361 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
362 |
if (ac == null) return null; |
|
363 |
||
364 |
final String accessibleDescription = ac.getAccessibleDescription(); |
|
365 |
if (accessibleDescription == null) { |
|
366 |
if (c instanceof JComponent) { |
|
367 |
String toolTipText = ((JComponent)c).getToolTipText(); |
|
368 |
if (toolTipText != null) { |
|
369 |
return toolTipText; |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
return accessibleDescription; |
|
375 |
} |
|
376 |
}, c); |
|
377 |
} |
|
378 |
||
379 |
public static boolean isFocusTraversable(final Accessible a, final Component c) { |
|
380 |
if (a == null) return false; |
|
381 |
||
382 |
return invokeAndWait(new Callable<Boolean>() { |
|
383 |
public Boolean call() throws Exception { |
|
384 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
385 |
if (ac == null) return null; |
|
386 |
||
387 |
final AccessibleComponent aComp = ac.getAccessibleComponent(); |
|
388 |
if (aComp == null) return null; |
|
389 |
||
390 |
return aComp.isFocusTraversable(); |
|
391 |
} |
|
392 |
}, c); |
|
393 |
} |
|
394 |
||
395 |
public static Accessible accessibilityHitTest(final Container parent, final float hitPointX, final float hitPointY) { |
|
396 |
return invokeAndWait(new Callable<Accessible>() { |
|
397 |
public Accessible call() throws Exception { |
|
398 |
final Point p = parent.getLocationOnScreen(); |
|
399 |
||
400 |
// Make it into local coords |
|
401 |
final Point localPoint = new Point((int)(hitPointX - p.getX()), (int)(hitPointY - p.getY())); |
|
402 |
||
403 |
final Component component = parent.findComponentAt(localPoint); |
|
404 |
if (component == null) return null; |
|
405 |
||
406 |
final AccessibleContext axContext = component.getAccessibleContext(); |
|
407 |
if (axContext == null) return null; |
|
408 |
||
409 |
final AccessibleComponent axComponent = axContext.getAccessibleComponent(); |
|
410 |
if (axComponent == null) return null; |
|
411 |
||
412 |
final int numChildren = axContext.getAccessibleChildrenCount(); |
|
413 |
if (numChildren > 0) { |
|
414 |
// It has children, check to see which one is hit. |
|
415 |
final Point p2 = axComponent.getLocationOnScreen(); |
|
416 |
final Point localP2 = new Point((int)(hitPointX - p2.getX()), (int)(hitPointY - p2.getY())); |
|
417 |
return CAccessible.getCAccessible(axComponent.getAccessibleAt(localP2)); |
|
418 |
} |
|
419 |
||
420 |
if (!(component instanceof Accessible)) return null; |
|
421 |
return CAccessible.getCAccessible((Accessible)component); |
|
422 |
} |
|
423 |
}, parent); |
|
424 |
} |
|
425 |
||
426 |
public static AccessibleAction getAccessibleAction(final Accessible a, final Component c) { |
|
37787 | 427 |
if (a == null) return null; |
428 |
||
12047 | 429 |
return invokeAndWait(new Callable<AccessibleAction>() { |
430 |
public AccessibleAction call() throws Exception { |
|
431 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
432 |
if (ac == null) return null; |
|
433 |
return ac.getAccessibleAction(); |
|
434 |
} |
|
435 |
}, c); |
|
436 |
} |
|
437 |
||
438 |
public static boolean isEnabled(final Accessible a, final Component c) { |
|
439 |
if (a == null) return false; |
|
440 |
||
441 |
return invokeAndWait(new Callable<Boolean>() { |
|
442 |
public Boolean call() throws Exception { |
|
443 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
444 |
if (ac == null) return null; |
|
445 |
||
446 |
final AccessibleComponent aComp = ac.getAccessibleComponent(); |
|
447 |
if (aComp == null) return null; |
|
448 |
||
449 |
return aComp.isEnabled(); |
|
450 |
} |
|
451 |
}, c); |
|
452 |
} |
|
453 |
||
454 |
// KCH - can we make this a postEvent instead? |
|
455 |
public static void requestFocus(final Accessible a, final Component c) { |
|
456 |
if (a == null) return; |
|
457 |
||
458 |
invokeLater(new Runnable() { |
|
459 |
public void run() { |
|
460 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
461 |
if (ac == null) return; |
|
462 |
||
463 |
final AccessibleComponent aComp = ac.getAccessibleComponent(); |
|
464 |
if (aComp == null) return; |
|
465 |
||
466 |
aComp.requestFocus(); |
|
467 |
} |
|
468 |
}, c); |
|
469 |
} |
|
470 |
||
39873
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
471 |
public static void requestSelection(final Accessible a, final Component c) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
472 |
if (a == null) return; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
473 |
invokeLater(new Runnable() { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
474 |
public void run() { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
475 |
AccessibleContext ac = a.getAccessibleContext(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
476 |
if (ac == null) return; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
477 |
int i = ac.getAccessibleIndexInParent(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
478 |
if (i == -1) return; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
479 |
Accessible parent = ac.getAccessibleParent(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
480 |
AccessibleContext pac = parent.getAccessibleContext(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
481 |
if (pac == null) return; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
482 |
AccessibleSelection as = pac.getAccessibleSelection(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
483 |
if (as == null) return; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
484 |
as.addAccessibleSelection(i); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
485 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
486 |
}, c); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
487 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
488 |
|
12047 | 489 |
public static Number getMaximumAccessibleValue(final Accessible a, final Component c) { |
490 |
if (a == null) return null; |
|
491 |
||
492 |
return invokeAndWait(new Callable<Number>() { |
|
493 |
public Number call() throws Exception { |
|
494 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
495 |
if (ac == null) return null; |
|
496 |
||
497 |
final AccessibleValue av = ac.getAccessibleValue(); |
|
498 |
if (av == null) return null; |
|
499 |
||
500 |
return av.getMaximumAccessibleValue(); |
|
501 |
} |
|
502 |
}, c); |
|
503 |
} |
|
504 |
||
505 |
public static Number getMinimumAccessibleValue(final Accessible a, final Component c) { |
|
506 |
if (a == null) return null; |
|
507 |
||
508 |
return invokeAndWait(new Callable<Number>() { |
|
509 |
public Number call() throws Exception { |
|
510 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
511 |
if (ac == null) return null; |
|
512 |
||
513 |
final AccessibleValue av = ac.getAccessibleValue(); |
|
514 |
if (av == null) return null; |
|
515 |
||
516 |
return av.getMinimumAccessibleValue(); |
|
517 |
} |
|
518 |
}, c); |
|
519 |
} |
|
520 |
||
521 |
public static String getAccessibleRoleDisplayString(final Accessible a, final Component c) { |
|
522 |
if (a == null) return null; |
|
523 |
||
524 |
return invokeAndWait(new Callable<String>() { |
|
525 |
public String call() throws Exception { |
|
526 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
527 |
if (ac == null) return null; |
|
528 |
||
529 |
final AccessibleRole ar = ac.getAccessibleRole(); |
|
530 |
if (ar == null) return null; |
|
531 |
||
532 |
return ar.toDisplayString(); |
|
533 |
} |
|
534 |
}, c); |
|
535 |
} |
|
536 |
||
537 |
public static Number getCurrentAccessibleValue(final AccessibleValue av, final Component c) { |
|
538 |
if (av == null) return null; |
|
539 |
||
540 |
return invokeAndWait(new Callable<Number>() { |
|
541 |
public Number call() throws Exception { |
|
542 |
Number currentAccessibleValue = av.getCurrentAccessibleValue(); |
|
543 |
return currentAccessibleValue; |
|
544 |
} |
|
545 |
}, c); |
|
546 |
} |
|
547 |
||
548 |
public static Accessible getFocusOwner(final Component c) { |
|
549 |
return invokeAndWait(new Callable<Accessible>() { |
|
550 |
public Accessible call() throws Exception { |
|
551 |
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); |
|
552 |
if (c == null || !(c instanceof Accessible)) return null; |
|
553 |
return CAccessible.getCAccessible((Accessible)c); |
|
554 |
} |
|
555 |
}, c); |
|
556 |
} |
|
557 |
||
558 |
public static boolean[] getInitialAttributeStates(final Accessible a, final Component c) { |
|
559 |
final boolean[] ret = new boolean[7]; |
|
560 |
if (a == null) return ret; |
|
561 |
||
562 |
return invokeAndWait(new Callable<boolean[]>() { |
|
563 |
public boolean[] call() throws Exception { |
|
564 |
final AccessibleContext aContext = a.getAccessibleContext(); |
|
565 |
if (aContext == null) return ret; |
|
566 |
||
567 |
final AccessibleComponent aComponent = aContext.getAccessibleComponent(); |
|
568 |
ret[0] = (aComponent != null); |
|
569 |
ret[1] = ((aComponent != null) && (aComponent.isFocusTraversable())); |
|
570 |
ret[2] = (aContext.getAccessibleValue() != null); |
|
571 |
ret[3] = (aContext.getAccessibleText() != null); |
|
572 |
||
573 |
final AccessibleStateSet aStateSet = aContext.getAccessibleStateSet(); |
|
574 |
ret[4] = (aStateSet.contains(AccessibleState.HORIZONTAL) || aStateSet.contains(AccessibleState.VERTICAL)); |
|
575 |
ret[5] = (aContext.getAccessibleName() != null); |
|
576 |
ret[6] = (aContext.getAccessibleChildrenCount() > 0); |
|
577 |
return ret; |
|
578 |
} |
|
579 |
}, c); |
|
580 |
} |
|
581 |
||
582 |
// Duplicated from JavaComponentAccessibility |
|
583 |
// Note that values >=0 are indexes into the child array |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30942
diff
changeset
|
584 |
static final int JAVA_AX_ALL_CHILDREN = -1; |
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30942
diff
changeset
|
585 |
static final int JAVA_AX_SELECTED_CHILDREN = -2; |
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30942
diff
changeset
|
586 |
static final int JAVA_AX_VISIBLE_CHILDREN = -3; |
12047 | 587 |
|
588 |
// Each child takes up two entries in the array: one for itself and one for its role |
|
589 |
public static Object[] getChildrenAndRoles(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored) { |
|
590 |
if (a == null) return null; |
|
591 |
return invokeAndWait(new Callable<Object[]>() { |
|
592 |
public Object[] call() throws Exception { |
|
39873
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
593 |
ArrayList<Object> childrenAndRoles = new ArrayList<Object>(); |
12047 | 594 |
_addChildren(a, whichChildren, allowIgnored, childrenAndRoles); |
595 |
||
39873
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
596 |
/* In the case of fetching a selection, need to check to see if |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
597 |
* the active descendant is at the beginning of the list. If it |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
598 |
* is not it needs to be moved to the beginning of the list so |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
599 |
* VoiceOver will annouce it correctly. The list returned |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
600 |
* from Java is always in order from top to bottom, but when shift |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
601 |
* selecting downward (extending the list) or multi-selecting using |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
602 |
* the VO keys control+option+command+return the active descendant |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
603 |
* is not at the top of the list in the shift select down case and |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
604 |
* may not be in the multi select case. |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
605 |
*/ |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
606 |
if (whichChildren == JAVA_AX_SELECTED_CHILDREN) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
607 |
if (!childrenAndRoles.isEmpty()) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
608 |
AccessibleContext activeDescendantAC = |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
609 |
CAccessible.getActiveDescendant(a); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
610 |
if (activeDescendantAC != null) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
611 |
String activeDescendantName = |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
612 |
activeDescendantAC.getAccessibleName(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
613 |
AccessibleRole activeDescendantRole = |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
614 |
activeDescendantAC.getAccessibleRole(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
615 |
// Move active descendant to front of list. |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
616 |
// List contains pairs of each selected item's |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
617 |
// Accessible and AccessibleRole. |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
618 |
ArrayList<Object> newArray = new ArrayList<Object>(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
619 |
int count = childrenAndRoles.size(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
620 |
Accessible currentAccessible = null; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
621 |
AccessibleContext currentAC = null; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
622 |
String currentName = null; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
623 |
AccessibleRole currentRole = null; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
624 |
for (int i = 0; i < count; i+=2) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
625 |
// Is this the active descendant? |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
626 |
currentAccessible = (Accessible)childrenAndRoles.get(i); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
627 |
currentAC = currentAccessible.getAccessibleContext(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
628 |
currentName = currentAC.getAccessibleName(); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
629 |
currentRole = (AccessibleRole)childrenAndRoles.get(i+1); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
630 |
if ( currentName.equals(activeDescendantName) && |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
631 |
currentRole.equals(activeDescendantRole) ) { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
632 |
newArray.add(0, currentAccessible); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
633 |
newArray.add(1, currentRole); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
634 |
} else { |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
635 |
newArray.add(currentAccessible); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
636 |
newArray.add(currentRole); |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
637 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
638 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
639 |
childrenAndRoles = newArray; |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
640 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
641 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
642 |
} |
76907ae1b680
8145207: [macosx] JList, VO can't access non-visible list items
ptbrunet
parents:
37787
diff
changeset
|
643 |
|
12047 | 644 |
if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) { |
645 |
return childrenAndRoles.toArray(); |
|
646 |
} |
|
647 |
||
648 |
return new Object[] { childrenAndRoles.get(whichChildren * 2), childrenAndRoles.get((whichChildren * 2) + 1) }; |
|
649 |
} |
|
650 |
}, c); |
|
651 |
} |
|
652 |
||
653 |
private static AccessibleRole getAccessibleRoleForLabel(JLabel l, AccessibleRole fallback) { |
|
654 |
String text = l.getText(); |
|
655 |
if (text != null && text.length() > 0) { |
|
656 |
return fallback; |
|
657 |
} |
|
658 |
Icon icon = l.getIcon(); |
|
659 |
if (icon != null) { |
|
660 |
return AccessibleRole.ICON; |
|
661 |
} |
|
662 |
return fallback; |
|
663 |
} |
|
664 |
||
665 |
private static AccessibleRole getAccessibleRole(Accessible a) { |
|
666 |
AccessibleContext ac = a.getAccessibleContext(); |
|
667 |
AccessibleRole role = ac.getAccessibleRole(); |
|
668 |
Object component = CAccessible.getSwingAccessible(a); |
|
669 |
if (role == null) return null; |
|
670 |
String roleString = role.toString(); |
|
671 |
if ("label".equals(roleString) && component instanceof JLabel) { |
|
672 |
return getAccessibleRoleForLabel((JLabel) component, role); |
|
673 |
} |
|
674 |
return role; |
|
675 |
} |
|
676 |
||
677 |
||
678 |
// Either gets the immediate children of a, or recursively gets all unignored children of a |
|
679 |
private static void _addChildren(final Accessible a, final int whichChildren, final boolean allowIgnored, final ArrayList<Object> childrenAndRoles) { |
|
680 |
if (a == null) return; |
|
681 |
||
682 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
683 |
if (ac == null) return; |
|
684 |
||
685 |
final int numChildren = ac.getAccessibleChildrenCount(); |
|
686 |
||
687 |
// each child takes up two entries in the array: itself, and its role |
|
688 |
// so the array holds alternating Accessible and AccessibleRole objects |
|
689 |
for (int i = 0; i < numChildren; i++) { |
|
690 |
final Accessible child = ac.getAccessibleChild(i); |
|
691 |
if (child == null) continue; |
|
692 |
||
693 |
final AccessibleContext context = child.getAccessibleContext(); |
|
694 |
if (context == null) continue; |
|
695 |
||
696 |
if (whichChildren == JAVA_AX_VISIBLE_CHILDREN) { |
|
697 |
if (!context.getAccessibleComponent().isVisible()) continue; |
|
698 |
} else if (whichChildren == JAVA_AX_SELECTED_CHILDREN) { |
|
699 |
if (!ac.getAccessibleSelection().isAccessibleChildSelected(i)) continue; |
|
700 |
} |
|
701 |
||
702 |
if (!allowIgnored) { |
|
703 |
final AccessibleRole role = context.getAccessibleRole(); |
|
30942
d0c43f9f5ed5
8078408: Java version applet hangs with Voice over turned on
ptbrunet
parents:
25859
diff
changeset
|
704 |
if (role != null && ignoredRoles != null && ignoredRoles.contains(roleKey(role))) { |
12047 | 705 |
// Get the child's unignored children. |
706 |
_addChildren(child, whichChildren, false, childrenAndRoles); |
|
707 |
} else { |
|
708 |
childrenAndRoles.add(child); |
|
709 |
childrenAndRoles.add(getAccessibleRole(child)); |
|
710 |
} |
|
711 |
} else { |
|
712 |
childrenAndRoles.add(child); |
|
713 |
childrenAndRoles.add(getAccessibleRole(child)); |
|
714 |
} |
|
715 |
||
716 |
// If there is an index, and we are beyond it, time to finish up |
|
717 |
if ((whichChildren >= 0) && (childrenAndRoles.size() / 2) >= (whichChildren + 1)) { |
|
718 |
return; |
|
719 |
} |
|
720 |
} |
|
721 |
} |
|
722 |
||
723 |
private static native String roleKey(AccessibleRole aRole); |
|
724 |
||
725 |
public static Object[] getChildren(final Accessible a, final Component c) { |
|
726 |
if (a == null) return null; |
|
727 |
return invokeAndWait(new Callable<Object[]>() { |
|
728 |
public Object[] call() throws Exception { |
|
729 |
final AccessibleContext ac = a.getAccessibleContext(); |
|
730 |
if (ac == null) return null; |
|
731 |
||
732 |
final int numChildren = ac.getAccessibleChildrenCount(); |
|
733 |
final Object[] children = new Object[numChildren]; |
|
734 |
for (int i = 0; i < numChildren; i++) { |
|
735 |
children[i] = ac.getAccessibleChild(i); |
|
736 |
} |
|
737 |
return children; |
|
738 |
} |
|
739 |
}, c); |
|
740 |
} |
|
37787 | 741 |
|
742 |
/** |
|
743 |
* @return AWTView ptr, a peer of the CPlatformView associated with the toplevel container of the Accessible, if any |
|
744 |
*/ |
|
745 |
private static long getAWTView(Accessible a) { |
|
746 |
Accessible ax = CAccessible.getSwingAccessible(a); |
|
747 |
if (!(ax instanceof Component)) return 0; |
|
748 |
||
749 |
return invokeAndWait(new Callable<Long>() { |
|
750 |
public Long call() throws Exception { |
|
751 |
Component cont = (Component) ax; |
|
752 |
while (cont != null && !(cont instanceof Window)) { |
|
753 |
cont = cont.getParent(); |
|
754 |
} |
|
755 |
if (cont != null) { |
|
756 |
LWWindowPeer peer = (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(cont); |
|
757 |
if (peer != null) { |
|
758 |
return ((CPlatformWindow) peer.getPlatformWindow()).getContentView().getAWTView(); |
|
759 |
} |
|
760 |
} |
|
761 |
return 0L; |
|
762 |
} |
|
763 |
}, (Component)ax); |
|
764 |
} |
|
12047 | 765 |
} |