Bug 988143 - Enable Gecko Touch in Fennec, TextSelection mods, r=margaret
authorMark Capella <markcapella@twcny.rr.com>
Thu, 14 May 2015 22:06:13 -0400
changeset 244026 9ed6f32334e8c20ecff5091518dce646f4e6ef76
parent 244025 b672dd2d3693644514b2180fa0072af94be6a1a1
child 244027 a0eeba30549dcdffe897cb9a711863bfc45a5a6b
push id59820
push usercbook@mozilla.com
push dateFri, 15 May 2015 15:41:47 +0000
treeherdermozilla-inbound@5943d32f3515 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs988143
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 988143 - Enable Gecko Touch in Fennec, TextSelection mods, r=margaret
mobile/android/base/TextSelection.java
--- a/mobile/android/base/TextSelection.java
+++ b/mobile/android/base/TextSelection.java
@@ -32,16 +32,17 @@ import org.json.JSONObject;
 import java.util.Timer;
 import java.util.TimerTask;
 
 import android.util.Log;
 import android.view.View;
 
 class TextSelection extends Layer implements GeckoEventListener {
     private static final String LOGTAG = "GeckoTextSelection";
+    private static final int SHUTDOWN_DELAY_MS = 250;
 
     private final TextSelectionHandle anchorHandle;
     private final TextSelectionHandle caretHandle;
     private final TextSelectionHandle focusHandle;
 
     private final DrawListener mDrawListener;
     private boolean mDraggingHandles;
 
@@ -86,26 +87,32 @@ class TextSelection extends Layer implem
             }
         };
 
         // Only register listeners if we have valid start/middle/end handles
         if (anchorHandle == null || caretHandle == null || focusHandle == null) {
             Log.e(LOGTAG, "Failed to initialize text selection because at least one handle is null");
         } else {
             EventDispatcher.getInstance().registerGeckoThreadListener(this,
+                "TextSelection:ActionbarInit",
+                "TextSelection:ActionbarStatus",
+                "TextSelection:ActionbarUninit",
                 "TextSelection:ShowHandles",
                 "TextSelection:HideHandles",
                 "TextSelection:PositionHandles",
                 "TextSelection:Update",
                 "TextSelection:DraggingHandle");
         }
     }
 
     void destroy() {
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
+            "TextSelection:ActionbarInit",
+            "TextSelection:ActionbarStatus",
+            "TextSelection:ActionbarUninit",
             "TextSelection:ShowHandles",
             "TextSelection:HideHandles",
             "TextSelection:PositionHandles",
             "TextSelection:Update",
             "TextSelection:DraggingHandle");
     }
 
     private TextSelectionHandle getHandle(String name) {
@@ -162,17 +169,17 @@ class TextSelection extends Layer implem
                         // Remove draw-listener and text selection layer
                         LayerView layerView = GeckoAppShell.getLayerView();
                         if (layerView != null) {
                             layerView.removeDrawListener(mDrawListener);
                             layerView.removeLayer(TextSelection.this);
                         }
 
                         mActionModeTimerTask = new ActionModeTimerTask();
-                        mActionModeTimer.schedule(mActionModeTimerTask, 250);
+                        mActionModeTimer.schedule(mActionModeTimerTask, SHUTDOWN_DELAY_MS);
 
                         anchorHandle.setVisibility(View.GONE);
                         caretHandle.setVisibility(View.GONE);
                         focusHandle.setVisibility(View.GONE);
 
                     } else if (event.equals("TextSelection:PositionHandles")) {
                         final JSONArray positions = message.getJSONArray("positions");
                         for (int i=0; i < positions.length(); i++) {
@@ -180,17 +187,38 @@ class TextSelection extends Layer implem
                             final int left = position.getInt("left");
                             final int top = position.getInt("top");
                             final boolean rtl = position.getBoolean("rtl");
 
                             TextSelectionHandle handle = getHandle(position.getString("handle"));
                             handle.setVisibility(position.getBoolean("hidden") ? View.GONE : View.VISIBLE);
                             handle.positionFromGecko(left, top, rtl);
                         }
+
+                    } else if (event.equals("TextSelection:ActionbarInit")) {
+                        // Init / Open the action bar. Note the current selectionID,
+                        // cancel any pending actionBar close.
+                        selectionID = message.getString("selectionID");
+                        mCurrentItems = null;
+                        if (mActionModeTimerTask != null) {
+                            mActionModeTimerTask.cancel();
+                        }
+
+                    } else if (event.equals("TextSelection:ActionbarStatus")) {
+                        // Update the actionBar actions as provided by Gecko.
+                        showActionMode(message.getJSONArray("actions"));
+
+                    } else if (event.equals("TextSelection:ActionbarUninit")) {
+                        // Uninit the actionbar. Schedule a cancellable close
+                        // action to avoid UI jank. (During SelectionAll for ex).
+                        mCurrentItems = null;
+                        mActionModeTimerTask = new ActionModeTimerTask();
+                        mActionModeTimer.schedule(mActionModeTimerTask, SHUTDOWN_DELAY_MS);
                     }
+
                 } catch (JSONException e) {
                     Log.e(LOGTAG, "JSON exception", e);
                 }
             }
         });
     }
 
     private void showActionMode(final JSONArray items) {