Bug 802280 - Send Layerview focus change events to js. r=blassey
authorEitan Isaacson <eitan@monotonous.org>
Fri, 19 Oct 2012 10:06:08 -0700
changeset 110924 4693be1c6bef109e841bbea9fd54990800f81b2a
parent 110923 f2b0c3499456f6b3fa76ca725450612d4201aa7c
child 110925 a79ae6b8454775ce7dffef60c9df71fad3782743
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersblassey
bugs802280
milestone19.0a1
Bug 802280 - Send Layerview focus change events to js. r=blassey
mobile/android/base/GeckoAccessibility.java
mobile/android/base/gfx/LayerView.java
--- a/mobile/android/base/GeckoAccessibility.java
+++ b/mobile/android/base/GeckoAccessibility.java
@@ -25,48 +25,49 @@ import java.util.List;
 import org.json.*;
 
 public class GeckoAccessibility {
     private static final String LOGTAG = "GeckoAccessibility";
     private static final int VIRTUAL_CURSOR_PREVIOUS = 1;
     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 final HashSet<String> ServiceWhitelist =
+    private static final HashSet<String> sServiceWhitelist =
         new HashSet<String>(Arrays.asList(new String[] {
                     "com.google.android.marvin.talkback.TalkBackService", // Google Talkback screen reader
                     "com.mot.readout.ScreenReader", // Motorola screen reader
                     "info.spielproject.spiel.SpielService", // Spiel screen reader
                     "es.codefactory.android.app.ma.MAAccessibilityService" // Codefactory Mobile Accessibility screen reader
                 }));
 
     public static void updateAccessibilitySettings () {
         GeckoAppShell.getHandler().post(new Runnable() {
                 public void run() {
                     JSONObject ret = new JSONObject();
-                    boolean enabled = false;
+                    mEnabled = false;
                     AccessibilityManager accessibilityManager =
                         (AccessibilityManager) GeckoApp.mAppContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
                     if (accessibilityManager.isEnabled()) {
                         ActivityManager activityManager =
                             (ActivityManager) GeckoApp.mAppContext.getSystemService(Context.ACTIVITY_SERVICE);
                         List<RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
 
                         for (RunningServiceInfo runningServiceInfo : runningServices) {
-                            enabled = ServiceWhitelist.contains(runningServiceInfo.service.getClassName());
-                            if (enabled)
+                            mEnabled = sServiceWhitelist.contains(runningServiceInfo.service.getClassName());
+                            if (mEnabled)
                                 break;
                         }
                     }
 
                     try {
-                        ret.put("enabled", enabled);
+                        ret.put("enabled", mEnabled);
                     } catch (Exception ex) {
                         Log.e(LOGTAG, "Error building JSON arguments for Accessibility:Settings:", ex);
                     }
 
                     GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Accessibility:Settings",
                                                                                    ret.toString()));
                 }
             });
@@ -180,16 +181,22 @@ public class GeckoAccessibility {
     public static void setDelegate(LayerView layerview) {
         // Only use this delegate in Jelly Bean.
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
             layerview.setAccessibilityDelegate(new GeckoAccessibilityDelegate());
             layerview.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
         }
     }
 
+    public static void onLayerViewFocusChanged(LayerView layerview, boolean gainFocus) {
+        if (mEnabled)
+            GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Accessibility:Focus",
+                                                                           gainFocus ? "true" : "false"));
+    }
+
     public static class GeckoAccessibilityDelegate extends View.AccessibilityDelegate {
         AccessibilityNodeProvider mAccessibilityNodeProvider;
 
         @Override
         public void onPopulateAccessibilityEvent (View host, AccessibilityEvent event) {
             super.onPopulateAccessibilityEvent(host, event);
             if (mEventMessage != null)
                 populateEventFromJSON(event, mEventMessage);
--- a/mobile/android/base/gfx/LayerView.java
+++ b/mobile/android/base/gfx/LayerView.java
@@ -12,16 +12,17 @@ import org.mozilla.gecko.util.EventDispa
 import org.mozilla.gecko.GeckoAccessibility;
 
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Color;
 import android.graphics.PixelFormat;
 import android.graphics.PointF;
+import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
 import android.os.Build;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
@@ -399,9 +400,15 @@ public class LayerView extends FrameLayo
     }
 
     @Override
     public int getOverScrollMode() {
         if (mLayerClient != null)
             return mLayerClient.getPanZoomController().getOverScrollMode();
         return super.getOverScrollMode();
     }
+
+    @Override
+    public void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+        GeckoAccessibility.onLayerViewFocusChanged(this, gainFocus);
+    }
 }