mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 823423 - Don't send a11y scroll or announcement events if we a11y is not officially enabled. r=blassey
This commit is contained in:
parent
5f9aca5aed
commit
f3358bb47b
@ -29,9 +29,9 @@ public class GeckoAccessibility {
|
||||
private static final int VIRTUAL_CURSOR_POSITION = 2;
|
||||
private static final int VIRTUAL_CURSOR_NEXT = 3;
|
||||
|
||||
private static boolean mEnabled = false;
|
||||
private static JSONObject mEventMessage = null;
|
||||
private static AccessibilityNodeInfo mVirtualCursorNode = null;
|
||||
private static boolean sEnabled = false;
|
||||
private static JSONObject sEventMessage = null;
|
||||
private static AccessibilityNodeInfo sVirtualCursorNode = null;
|
||||
|
||||
private static final HashSet<String> sServiceWhitelist =
|
||||
new HashSet<String>(Arrays.asList(new String[] {
|
||||
@ -45,7 +45,7 @@ public class GeckoAccessibility {
|
||||
GeckoAppShell.getHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
JSONObject ret = new JSONObject();
|
||||
mEnabled = false;
|
||||
sEnabled = false;
|
||||
AccessibilityManager accessibilityManager =
|
||||
(AccessibilityManager) GeckoApp.mAppContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
|
||||
if (accessibilityManager.isEnabled()) {
|
||||
@ -54,14 +54,14 @@ public class GeckoAccessibility {
|
||||
List<RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
|
||||
|
||||
for (RunningServiceInfo runningServiceInfo : runningServices) {
|
||||
mEnabled = sServiceWhitelist.contains(runningServiceInfo.service.getClassName());
|
||||
if (mEnabled)
|
||||
sEnabled = sServiceWhitelist.contains(runningServiceInfo.service.getClassName());
|
||||
if (sEnabled)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ret.put("enabled", mEnabled);
|
||||
ret.put("enabled", sEnabled);
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOGTAG, "Error building JSON arguments for Accessibility:Settings:", ex);
|
||||
}
|
||||
@ -116,6 +116,9 @@ public class GeckoAccessibility {
|
||||
}
|
||||
|
||||
public static void sendAccessibilityEvent (final JSONObject message) {
|
||||
if (!sEnabled)
|
||||
return;
|
||||
|
||||
final int eventType = message.optInt("eventType", -1);
|
||||
if (eventType < 0) {
|
||||
Log.e(LOGTAG, "No accessibility event type provided");
|
||||
@ -137,25 +140,25 @@ public class GeckoAccessibility {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
if (mVirtualCursorNode == null)
|
||||
mVirtualCursorNode = AccessibilityNodeInfo.obtain(view, VIRTUAL_CURSOR_POSITION);
|
||||
mVirtualCursorNode.setEnabled(message.optBoolean("enabled", true));
|
||||
mVirtualCursorNode.setChecked(message.optBoolean("checked"));
|
||||
mVirtualCursorNode.setPassword(message.optBoolean("password"));
|
||||
if (sVirtualCursorNode == null)
|
||||
sVirtualCursorNode = AccessibilityNodeInfo.obtain(view, VIRTUAL_CURSOR_POSITION);
|
||||
sVirtualCursorNode.setEnabled(message.optBoolean("enabled", true));
|
||||
sVirtualCursorNode.setChecked(message.optBoolean("checked"));
|
||||
sVirtualCursorNode.setPassword(message.optBoolean("password"));
|
||||
JSONObject bounds = message.optJSONObject("bounds");
|
||||
if (bounds != null) {
|
||||
Rect relativeBounds = new Rect(bounds.optInt("left"), bounds.optInt("top"),
|
||||
bounds.optInt("right"), bounds.optInt("bottom"));
|
||||
mVirtualCursorNode.setBoundsInParent(relativeBounds);
|
||||
sVirtualCursorNode.setBoundsInParent(relativeBounds);
|
||||
int[] locationOnScreen = new int[2];
|
||||
view.getLocationOnScreen(locationOnScreen);
|
||||
Rect screenBounds = new Rect(relativeBounds);
|
||||
screenBounds.offset(locationOnScreen[0], locationOnScreen[1]);
|
||||
mVirtualCursorNode.setBoundsInScreen(screenBounds);
|
||||
sVirtualCursorNode.setBoundsInScreen(screenBounds);
|
||||
}
|
||||
|
||||
// Store the JSON message and use it to populate the event later in the code path.
|
||||
mEventMessage = message;
|
||||
sEventMessage = message;
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
// If this is an accessibility focus, a lot of internal voodoo happens so we perform an
|
||||
@ -190,7 +193,7 @@ public class GeckoAccessibility {
|
||||
}
|
||||
|
||||
public static void onLayerViewFocusChanged(LayerView layerview, boolean gainFocus) {
|
||||
if (mEnabled)
|
||||
if (sEnabled)
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Accessibility:Focus",
|
||||
gainFocus ? "true" : "false"));
|
||||
}
|
||||
@ -201,11 +204,11 @@ public class GeckoAccessibility {
|
||||
@Override
|
||||
public void onPopulateAccessibilityEvent (View host, AccessibilityEvent event) {
|
||||
super.onPopulateAccessibilityEvent(host, event);
|
||||
if (mEventMessage != null)
|
||||
populateEventFromJSON(event, mEventMessage);
|
||||
if (sEventMessage != null)
|
||||
populateEventFromJSON(event, sEventMessage);
|
||||
// We save the hover enter event so that we could reuse it for a subsequent accessibility focus event.
|
||||
if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_HOVER_ENTER)
|
||||
mEventMessage = null;
|
||||
sEventMessage = null;
|
||||
// No matter where the a11y focus is requested, we always force it back to the current vc position.
|
||||
event.setSource(host, VIRTUAL_CURSOR_POSITION);
|
||||
}
|
||||
@ -221,8 +224,8 @@ public class GeckoAccessibility {
|
||||
mAccessibilityNodeProvider = new AccessibilityNodeProvider() {
|
||||
@Override
|
||||
public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualDescendantId) {
|
||||
AccessibilityNodeInfo info = (virtualDescendantId == VIRTUAL_CURSOR_POSITION && mVirtualCursorNode != null) ?
|
||||
AccessibilityNodeInfo.obtain(mVirtualCursorNode) :
|
||||
AccessibilityNodeInfo info = (virtualDescendantId == VIRTUAL_CURSOR_POSITION && sVirtualCursorNode != null) ?
|
||||
AccessibilityNodeInfo.obtain(sVirtualCursorNode) :
|
||||
AccessibilityNodeInfo.obtain(host, virtualDescendantId);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user