[java-atk-wrapper] Delegate getAccessibleRole call to EDT
- From: Samuel Thibault <sthibaul src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [java-atk-wrapper] Delegate getAccessibleRole call to EDT
- Date: Mon, 17 Jun 2019 22:11:04 +0000 (UTC)
commit 49344747c645bc75fcdf164555338dc201f3faaa
Author: Giuseppe <giuseppecapaldo93 gmail com>
Date: Tue Jun 18 00:10:31 2019 +0200
Delegate getAccessibleRole call to EDT
jni/src/jawobject.c | 7 +--
jni/src/jawutil.c | 84 +++++---------------------
jni/src/jawutil.h | 2 +-
wrapper/org/GNOME/Accessibility/AtkObject.java | 9 +++
4 files changed, 29 insertions(+), 73 deletions(-)
---
diff --git a/jni/src/jawobject.c b/jni/src/jawobject.c
index e9ff8ca..d485956 100644
--- a/jni/src/jawobject.c
+++ b/jni/src/jawobject.c
@@ -436,10 +436,9 @@ jaw_object_get_role (AtkObject *atk_obj)
JawObject *jaw_obj = JAW_OBJECT(atk_obj);
JNIEnv *jniEnv = jaw_util_get_jni_env();
jobject ac = (*jniEnv)->NewGlobalRef(jniEnv, jaw_obj->acc_context);
- if (!ac) {
- return 0;
- }
- atk_obj->role = jaw_util_get_atk_role_from_jobj(ac);
+ if (!ac)
+ return ATK_ROLE_INVALID;
+ atk_obj->role = jaw_util_get_atk_role_from_AccessibleContext(ac);
(*jniEnv)->DeleteGlobalRef(jniEnv, ac);
return atk_obj->role;
}
diff --git a/jni/src/jawutil.c b/jni/src/jawutil.c
index b25c38e..3c41fea 100644
--- a/jni/src/jawutil.c
+++ b/jni/src/jawutil.c
@@ -415,34 +415,16 @@ jaw_util_is_java_acc_role (JNIEnv *jniEnv, jobject acc_role, const gchar* roleNa
}
AtkRole
-jaw_util_get_atk_role_from_jobj (jobject jobj)
+jaw_util_get_atk_role_from_AccessibleContext (jobject jAccessibleContext)
{
- jobject ac;
JNIEnv *jniEnv = jaw_util_get_jni_env();
- jclass classAccessibleContext = (*jniEnv)->FindClass(jniEnv,
- "javax/accessibility/AccessibleContext");
- jclass classAccessible = (*jniEnv)->FindClass(jniEnv,
- "javax/accessibility/Accessible");
- jmethodID jmidGetContext;
- jmidGetContext = (*jniEnv)->GetMethodID(jniEnv,
- classAccessible,
- "getAccessibleContext",
- "()Ljavax/accessibility/AccessibleContext;");
- if( (*jniEnv)->IsInstanceOf(jniEnv, jobj, classAccessibleContext))
- {
- ac = jobj;
- } else if ((*jniEnv)->IsInstanceOf(jniEnv, jobj, classAccessible))
- {
- ac = (*jniEnv)->CallObjectMethod(jniEnv, jobj, jmidGetContext);
- } else {
- return ATK_ROLE_INVALID;
- }
+ jclass atkObject = (*jniEnv)->FindClass (jniEnv, "org/GNOME/Accessibility/AtkObject");
+ jmethodID jmidgar = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "getAccessibleRole",
"(Ljavax/accessibility/AccessibleContext;)Ljavax/accessibility/AccessibleRole;");
+ jobject ac_role = (*jniEnv)->CallStaticObjectMethod (jniEnv, atkObject, jmidgar, jAccessibleContext);
+ jclass classAccessibleRole = (*jniEnv)->FindClass(jniEnv,"javax/accessibility/AccessibleRole");
- jmethodID jmidGetRole = (*jniEnv)->GetMethodID(jniEnv,
- classAccessibleContext,
- "getAccessibleRole",
- "()Ljavax/accessibility/AccessibleRole;");
- jobject ac_role = (*jniEnv)->CallObjectMethod(jniEnv, ac, jmidGetRole);
+ if( !(*jniEnv)->IsInstanceOf (jniEnv, ac_role, classAccessibleRole) )
+ return ATK_ROLE_INVALID;
if (jaw_util_is_java_acc_role(jniEnv, ac_role, "ALERT"))
return ATK_ROLE_ALERT;
@@ -519,7 +501,6 @@ jaw_util_get_atk_role_from_jobj (jobject jobj)
if (jaw_util_is_java_acc_role(jniEnv, ac_role, "INTERNAL_FRAME"))
return ATK_ROLE_INTERNAL_FRAME;
-
if (jaw_util_is_java_acc_role(jniEnv, ac_role, "LABEL"))
return ATK_ROLE_LABEL;
@@ -570,17 +551,11 @@ jaw_util_get_atk_role_from_jobj (jobject jobj)
if (jaw_util_is_java_acc_role(jniEnv, ac_role, "RADIO_BUTTON"))
{
- jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
- classAccessibleContext,
- "getAccessibleParent",
- "()Ljavax/accessibility/Accessible;");
-
- jobject parent_obj = (*jniEnv)->CallObjectMethod(jniEnv, ac, jmid);
- if (!parent_obj)
+ jmethodID jmidgap = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "getAccessibleParent",
"(Ljavax/accessibility/AccessibleContext;)Ljavax/accessibility/AccessibleContext;");
+ jobject jparent = (*jniEnv)->CallStaticObjectMethod (jniEnv, atkObject, jmidgap, jAccessibleContext);
+ if (!jparent)
return ATK_ROLE_RADIO_BUTTON;
-
- jobject parent_ac = (*jniEnv)->CallObjectMethod(jniEnv, parent_obj, jmidGetContext);
- jobject parent_role = (*jniEnv)->CallObjectMethod(jniEnv, parent_ac, jmidGetRole);
+ jobject parent_role = (*jniEnv)->CallStaticObjectMethod(jniEnv, atkObject, jmidgar, jparent);
if (jaw_util_is_java_acc_role(jniEnv, parent_role, "MENU"))
return ATK_ROLE_RADIO_MENU_ITEM;
@@ -641,13 +616,10 @@ jaw_util_get_atk_role_from_jobj (jobject jobj)
if ( jaw_util_is_java_acc_role(jniEnv, ac_role, "UNKNOWN"))
{
- jmethodID jmid = (*jniEnv)->GetMethodID(jniEnv,
- classAccessibleContext,
- "getAccessibleParent",
- "()Ljavax/accessibility/Accessible;");
- jobject parent_obj = (*jniEnv)->CallObjectMethod(jniEnv, ac, jmid);
+ jmethodID jmidgap = (*jniEnv)->GetStaticMethodID (jniEnv, atkObject, "getAccessibleParent",
"(Ljavax/accessibility/AccessibleContext;)Ljavax/accessibility/AccessibleContext;");
+ jobject jparent = (*jniEnv)->CallStaticObjectMethod (jniEnv, atkObject, jmidgap, jAccessibleContext);
- if (parent_obj == NULL)
+ if (jparent == NULL)
return ATK_ROLE_APPLICATION;
return ATK_ROLE_UNKNOWN;
@@ -659,32 +631,8 @@ jaw_util_get_atk_role_from_jobj (jobject jobj)
if ( jaw_util_is_java_acc_role(jniEnv, ac_role, "WINDOW"))
return ATK_ROLE_WINDOW;
- jclass classAccessibleRole = (*jniEnv)->FindClass(jniEnv,
- "javax/accessibility/AccessibleRole");
- jmethodID jmidToDisplayString = (*jniEnv)->GetMethodID(jniEnv,
- classAccessibleRole,
- "toDisplayString",
- "(Ljava/util/Locale;)Ljava/lang/String;");
-
- jclass classLocale = (*jniEnv)->FindClass(jniEnv, "java/util/Locale");
- jfieldID jfidUS = (*jniEnv)->GetStaticFieldID(jniEnv,
- classLocale,
- "US",
- "Ljava/util/Locale;");
- jobject jobjUS = (*jniEnv)->GetStaticObjectField(jniEnv, classLocale, jfidUS);
- jobject jobjString = (*jniEnv)->CallObjectMethod(jniEnv,
- ac_role,
- jmidToDisplayString,
- jobjUS);
-
- jclass classString = (*jniEnv)->FindClass(jniEnv, "java/lang/String");
- jmethodID jmidEqualsIgnoreCase = (*jniEnv)->GetMethodID(jniEnv,
- classString,
- "equalsIgnoreCase",
- "(Ljava/lang/String;)Z");
-
- jstring jstr = (*jniEnv)->NewStringUTF(jniEnv, "paragraph");
- if ((*jniEnv)->CallBooleanMethod(jniEnv, jobjString, jmidEqualsIgnoreCase, jstr))
+ jmethodID jmideic = (*jniEnv)->GetMethodID(jniEnv, atkObject, "equalsIgnoreCaseLocaleWithRole",
"(Ljavax/accessibility/AccessibleRole;)Z");
+ if ( (*jniEnv)->CallStaticBooleanMethod(jniEnv, atkObject, jmideic, ac_role) )
return ATK_ROLE_PARAGRAPH;
return ATK_ROLE_UNKNOWN; /* ROLE_EXTENDED */
diff --git a/jni/src/jawutil.h b/jni/src/jawutil.h
index 14397a6..aecfaa2 100644
--- a/jni/src/jawutil.h
+++ b/jni/src/jawutil.h
@@ -64,7 +64,7 @@ struct _JawUtilClass
guint jaw_util_get_tflag_from_jobj(JNIEnv *jniEnv, jobject jObj);
gboolean jaw_util_is_same_jobject(gconstpointer a, gconstpointer b);
JNIEnv* jaw_util_get_jni_env(void);
-AtkRole jaw_util_get_atk_role_from_jobj(jobject jobj);
+AtkRole jaw_util_get_atk_role_from_AccessibleContext(jobject jobj);
AtkStateType jaw_util_get_atk_state_type_from_java_state(JNIEnv *jniEnv, jobject jobj);
void jaw_util_get_rect_info(JNIEnv *jniEnv,
jobject jrect,
diff --git a/wrapper/org/GNOME/Accessibility/AtkObject.java b/wrapper/org/GNOME/Accessibility/AtkObject.java
index f59c83d..2516508 100644
--- a/wrapper/org/GNOME/Accessibility/AtkObject.java
+++ b/wrapper/org/GNOME/Accessibility/AtkObject.java
@@ -71,6 +71,15 @@ public class AtkObject{
return AtkUtil.invokeInSwing( () -> { return ac.getAccessibleIndexInParent(); }, -1);
}
+ public static AccessibleRole getAccessibleRole(AccessibleContext ac){
+ return AtkUtil.invokeInSwing( () -> { return ac.getAccessibleRole(); }, AccessibleRole.UNKNOWN);
+ }
+
+ public static boolean equalsIgnoreCaseLocaleWithRole(AccessibleRole role){
+ String displayString = role.toDisplayString(Locale.US);
+ return displayString.equalsIgnoreCase("paragraph");
+ }
+
public static int hashCode(AccessibleContext ac){
return AtkUtil.invokeInSwing( () -> { return ac.hashCode(); }, 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]