diff options
author | Noel Grandin <noel@peralex.com> | 2013-05-16 11:39:40 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2013-05-20 09:21:20 +0200 |
commit | d702dd4396161f8e2e7396f5c24554088b752fcb (patch) | |
tree | d7c6f9a56a093e82ddc555f46af958e4d859ff48 /qadevOOo/runner | |
parent | 784e472aa24d2f2cb9c240b91af4a184c6fcb949 (diff) |
Java cleanup, AccessibilityTools..
was using a global variable. Yuck.
Fix it to use a local variable. Not perfect, but better.
Change-Id: I27bbbb2ddc89402da53be7f19d2cd963b03b1a83
Diffstat (limited to 'qadevOOo/runner')
-rw-r--r-- | qadevOOo/runner/util/AccessibilityTools.java | 100 |
1 files changed, 86 insertions, 14 deletions
diff --git a/qadevOOo/runner/util/AccessibilityTools.java b/qadevOOo/runner/util/AccessibilityTools.java index 85cd442a3b84..c7cb483674c9 100644 --- a/qadevOOo/runner/util/AccessibilityTools.java +++ b/qadevOOo/runner/util/AccessibilityTools.java @@ -17,6 +17,7 @@ */ package util; +import com.sun.star.accessibility.AccessibleStateType; import com.sun.star.accessibility.XAccessible; import com.sun.star.accessibility.XAccessibleComponent; import com.sun.star.accessibility.XAccessibleContext; @@ -32,7 +33,7 @@ import java.io.PrintWriter; public class AccessibilityTools { - public static XAccessible SearchedAccessible = null; + private XAccessible SearchedAccessible = null; private static boolean debug = false; public AccessibilityTools() { @@ -91,15 +92,12 @@ public class AccessibilityTools { public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, short role) { - SearchedAccessible = null; return getAccessibleObjectForRole_(xacc, role); } public static XAccessibleContext getAccessibleObjectForRole(XAccessible xacc, short role, boolean ignoreShowing) { - SearchedAccessible = null; - if (ignoreShowing) { return getAccessibleObjectForRoleIgnoreShowing_(xacc, role); } else { @@ -107,12 +105,49 @@ public class AccessibilityTools { } } + public XAccessible getSearchedAccessibleObjectForRole(XAccessible xacc, + short role, + boolean ignoreShowing) { + SearchedAccessible = null; + getSearchedAccessibleObjectForRole_(xacc, role, ignoreShowing); + return SearchedAccessible; + } + + private XAccessibleContext getSearchedAccessibleObjectForRole_(XAccessible xacc, + short role, boolean ignoreShowing) { + XAccessibleContext ac = xacc.getAccessibleContext(); + boolean isShowing = isShowing(ac); + + if ((ac.getAccessibleRole() == role) && (!ignoreShowing || isShowing)) { + SearchedAccessible = xacc; + return ac; + } else { + int k = ac.getAccessibleChildCount(); + + if (ac.getAccessibleChildCount() > 100) { + k = 50; + } + + for (int i = 0; i < k; i++) { + try { + XAccessibleContext ac2 = getSearchedAccessibleObjectForRole_(ac.getAccessibleChild(i), role, ignoreShowing); + + if (ac2 != null) { + return ac2; + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.out.println("Couldn't get Child"); + } + } + return null; + } + } + public static XAccessibleContext getAccessibleObjectForRoleIgnoreShowing_(XAccessible xacc, short role) { XAccessibleContext ac = xacc.getAccessibleContext(); if (ac.getAccessibleRole() == role) { - SearchedAccessible = xacc; return ac; } else { int k = ac.getAccessibleChildCount(); @@ -140,11 +175,9 @@ public class AccessibilityTools { public static XAccessibleContext getAccessibleObjectForRole_(XAccessible xacc, short role) { XAccessibleContext ac = xacc.getAccessibleContext(); - boolean isShowing = ac.getAccessibleStateSet() - .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); + boolean isShowing = isShowing(ac); if ((ac.getAccessibleRole() == role) && isShowing) { - SearchedAccessible = xacc; return ac; } else { int k = ac.getAccessibleChildCount(); @@ -194,7 +227,6 @@ public class AccessibilityTools { if ((ac.getAccessibleRole() == role) && (ac.getAccessibleName().indexOf(name) > -1) && (utils.getImplName(ac).indexOf(implName) > -1)) { - SearchedAccessible = xacc; //System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing); return ac; @@ -228,8 +260,7 @@ public class AccessibilityTools { String name, String implName) { XAccessibleContext ac = xacc.getAccessibleContext(); - boolean isShowing = ac.getAccessibleStateSet() - .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); + boolean isShowing = isShowing(ac); // hotfix for i91828: // if role to search is 0 then ignore the role. @@ -237,7 +268,6 @@ public class AccessibilityTools { (ac.getAccessibleName().indexOf(name) > -1) && (utils.getImplName(ac).indexOf(implName) > -1) && isShowing) { - SearchedAccessible = xacc; //System.out.println("FOUND the desired component -- "+ ac.getAccessibleName() +isShowing); return ac; } else { @@ -265,6 +295,45 @@ public class AccessibilityTools { return null; } + public XAccessible getSearchedAccessibleObjectForRole(XAccessible xacc, + short role, + String name, + String implName) { + XAccessibleContext ac = xacc.getAccessibleContext(); + boolean isShowing = isShowing(ac); + + // hotfix for i91828: + // if role to search is 0 then ignore the role. + if ( (role == 0 || ac.getAccessibleRole() == role) && + (ac.getAccessibleName().indexOf(name) > -1) && + (utils.getImplName(ac).indexOf(implName) > -1) && + isShowing) { + SearchedAccessible = xacc; + } else { + int k = ac.getAccessibleChildCount(); + + if (ac.getAccessibleChildCount() > 100) { + k = 50; + } + + for (int i = 0; i < k; i++) { + try { + XAccessibleContext ac1 = getAccessibleObjectForRole( + ac.getAccessibleChild(i), + role, name, implName); + + if (ac1 != null) { + break; + } + } catch (com.sun.star.lang.IndexOutOfBoundsException e) { + System.out.println("Couldn't get Child"); + } + } + } + + return SearchedAccessible; + } + /** * This methods retunrs the <CODE>XAccessibleContext</CODE> of a named Sheet-Cell like "G5".<p> * @param xSheetAcc The <CODE>XAccessibleContext</CODE> of a Sheet @@ -345,8 +414,7 @@ public class AccessibilityTools { logging(log,indent + indent + bounds); } - boolean isShowing = ac.getAccessibleStateSet() - .contains(com.sun.star.accessibility.AccessibleStateType.SHOWING); + boolean isShowing = isShowing(ac); logging(log,indent + indent + "StateType contains SHOWING: " + isShowing); @@ -443,4 +511,8 @@ public class AccessibilityTools { private static void logging(PrintWriter log, String content){ if (debug) log.println(content); } + + private static boolean isShowing(XAccessibleContext ac) { + return ac.getAccessibleStateSet().contains(AccessibleStateType.SHOWING); + } }
\ No newline at end of file |