466 aComp.requestFocus(); |
466 aComp.requestFocus(); |
467 } |
467 } |
468 }, c); |
468 }, c); |
469 } |
469 } |
470 |
470 |
|
471 public static void requestSelection(final Accessible a, final Component c) { |
|
472 if (a == null) return; |
|
473 invokeLater(new Runnable() { |
|
474 public void run() { |
|
475 AccessibleContext ac = a.getAccessibleContext(); |
|
476 if (ac == null) return; |
|
477 int i = ac.getAccessibleIndexInParent(); |
|
478 if (i == -1) return; |
|
479 Accessible parent = ac.getAccessibleParent(); |
|
480 AccessibleContext pac = parent.getAccessibleContext(); |
|
481 if (pac == null) return; |
|
482 AccessibleSelection as = pac.getAccessibleSelection(); |
|
483 if (as == null) return; |
|
484 as.addAccessibleSelection(i); |
|
485 } |
|
486 }, c); |
|
487 } |
|
488 |
471 public static Number getMaximumAccessibleValue(final Accessible a, final Component c) { |
489 public static Number getMaximumAccessibleValue(final Accessible a, final Component c) { |
472 if (a == null) return null; |
490 if (a == null) return null; |
473 |
491 |
474 return invokeAndWait(new Callable<Number>() { |
492 return invokeAndWait(new Callable<Number>() { |
475 public Number call() throws Exception { |
493 public Number call() throws Exception { |
570 // Each child takes up two entries in the array: one for itself and one for its role |
588 // Each child takes up two entries in the array: one for itself and one for its role |
571 public static Object[] getChildrenAndRoles(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored) { |
589 public static Object[] getChildrenAndRoles(final Accessible a, final Component c, final int whichChildren, final boolean allowIgnored) { |
572 if (a == null) return null; |
590 if (a == null) return null; |
573 return invokeAndWait(new Callable<Object[]>() { |
591 return invokeAndWait(new Callable<Object[]>() { |
574 public Object[] call() throws Exception { |
592 public Object[] call() throws Exception { |
575 final ArrayList<Object> childrenAndRoles = new ArrayList<Object>(); |
593 ArrayList<Object> childrenAndRoles = new ArrayList<Object>(); |
576 _addChildren(a, whichChildren, allowIgnored, childrenAndRoles); |
594 _addChildren(a, whichChildren, allowIgnored, childrenAndRoles); |
|
595 |
|
596 /* In the case of fetching a selection, need to check to see if |
|
597 * the active descendant is at the beginning of the list. If it |
|
598 * is not it needs to be moved to the beginning of the list so |
|
599 * VoiceOver will annouce it correctly. The list returned |
|
600 * from Java is always in order from top to bottom, but when shift |
|
601 * selecting downward (extending the list) or multi-selecting using |
|
602 * the VO keys control+option+command+return the active descendant |
|
603 * is not at the top of the list in the shift select down case and |
|
604 * may not be in the multi select case. |
|
605 */ |
|
606 if (whichChildren == JAVA_AX_SELECTED_CHILDREN) { |
|
607 if (!childrenAndRoles.isEmpty()) { |
|
608 AccessibleContext activeDescendantAC = |
|
609 CAccessible.getActiveDescendant(a); |
|
610 if (activeDescendantAC != null) { |
|
611 String activeDescendantName = |
|
612 activeDescendantAC.getAccessibleName(); |
|
613 AccessibleRole activeDescendantRole = |
|
614 activeDescendantAC.getAccessibleRole(); |
|
615 // Move active descendant to front of list. |
|
616 // List contains pairs of each selected item's |
|
617 // Accessible and AccessibleRole. |
|
618 ArrayList<Object> newArray = new ArrayList<Object>(); |
|
619 int count = childrenAndRoles.size(); |
|
620 Accessible currentAccessible = null; |
|
621 AccessibleContext currentAC = null; |
|
622 String currentName = null; |
|
623 AccessibleRole currentRole = null; |
|
624 for (int i = 0; i < count; i+=2) { |
|
625 // Is this the active descendant? |
|
626 currentAccessible = (Accessible)childrenAndRoles.get(i); |
|
627 currentAC = currentAccessible.getAccessibleContext(); |
|
628 currentName = currentAC.getAccessibleName(); |
|
629 currentRole = (AccessibleRole)childrenAndRoles.get(i+1); |
|
630 if ( currentName.equals(activeDescendantName) && |
|
631 currentRole.equals(activeDescendantRole) ) { |
|
632 newArray.add(0, currentAccessible); |
|
633 newArray.add(1, currentRole); |
|
634 } else { |
|
635 newArray.add(currentAccessible); |
|
636 newArray.add(currentRole); |
|
637 } |
|
638 } |
|
639 childrenAndRoles = newArray; |
|
640 } |
|
641 } |
|
642 } |
577 |
643 |
578 if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) { |
644 if ((whichChildren < 0) || (whichChildren * 2 >= childrenAndRoles.size())) { |
579 return childrenAndRoles.toArray(); |
645 return childrenAndRoles.toArray(); |
580 } |
646 } |
581 |
647 |