Bug 1396951 - 4. Pass in GeckoView instance when sending a11y event; r=snorp

Pass in a `GeckoView` instance when sending a11y events so we're not
dependent on `GeckoAppShell.getLayerView()`. However, there's likely
more work to be done to make a11y work for any GeckoView.

MozReview-Commit-ID: DBeDOX5c3qY

--HG--
extra : rebase_source : 0c6c76d326b755671d2d29109823ceaf1aa627ba
This commit is contained in:
Jim Chen 2017-09-21 17:36:07 -04:00
parent e552b01260
commit 4440c1fbc9
2 changed files with 13 additions and 12 deletions

View File

@ -673,7 +673,7 @@ public abstract class GeckoApp extends GeckoActivity
GeckoAccessibility.updateAccessibilitySettings(this);
} else if ("Accessibility:Event".equals(event)) {
GeckoAccessibility.sendAccessibilityEvent(message);
GeckoAccessibility.sendAccessibilityEvent(mLayerView, message);
} else if ("Bookmark:Insert".equals(event)) {
final BrowserDB db = BrowserDB.from(getProfile());

View File

@ -7,8 +7,6 @@ package org.mozilla.gecko;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;
@ -110,7 +108,8 @@ public class GeckoAccessibility {
return sEnabled;
}
public static void sendAccessibilityEvent(final GeckoBundle message) {
public static void sendAccessibilityEvent(final GeckoView view,
final GeckoBundle message) {
if (!sEnabled)
return;
@ -120,10 +119,11 @@ public class GeckoAccessibility {
return;
}
sendAccessibilityEvent(message, eventType);
sendAccessibilityEvent(view, message, eventType);
}
public static void sendAccessibilityEvent(final GeckoBundle message, final int eventType) {
public static void sendAccessibilityEvent(final GeckoView view, final GeckoBundle message,
final int eventType) {
if (!sEnabled)
return;
@ -148,10 +148,6 @@ public class GeckoAccessibility {
} else {
// In Jelly Bean we populate an AccessibilityNodeInfo with the minimal amount of data to have
// it work with TalkBack.
final LayerView view = GeckoAppShell.getLayerView();
if (view == null)
return;
if (sVirtualCursorNode == null) {
sVirtualCursorNode = AccessibilityNodeInfo.obtain(view, VIRTUAL_CURSOR_POSITION);
}
@ -266,7 +262,12 @@ public class GeckoAccessibility {
AccessibilityNodeProvider mAccessibilityNodeProvider;
@Override
public AccessibilityNodeProvider getAccessibilityNodeProvider(final View host) {
public AccessibilityNodeProvider getAccessibilityNodeProvider(final View hostView) {
if (!(hostView instanceof GeckoView)) {
return super.getAccessibilityNodeProvider(hostView);
}
final GeckoView host = (GeckoView) hostView;
if (mAccessibilityNodeProvider == null)
// The accessibility node structure for web content consists of 3 LayerView child nodes:
// 1. VIRTUAL_ENTRY_POINT_BEFORE: Represents the entry point before the LayerView.
@ -319,7 +320,7 @@ public class GeckoAccessibility {
// The accessibility focus is permanently on the middle node, VIRTUAL_CURSOR_POSITION.
// When we enter the view forward or backward we just ask Gecko to get focus, keeping the current position.
if (virtualViewId == VIRTUAL_CURSOR_POSITION && sHoverEnter != null) {
GeckoAccessibility.sendAccessibilityEvent(sHoverEnter, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
GeckoAccessibility.sendAccessibilityEvent(host, sHoverEnter, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
} else {
final GeckoBundle data = new GeckoBundle(1);
data.putBoolean("gainFocus", true);