add select text to context menu

Long pressing near a link may select the link even if
the intent was to select text. Add an entry to
the context menu to permit selecting text when the hit
is an non-image anchor or a synthetic link.

depends on companion change to frameworks/base

bug:3214410
Change-Id: Ib444cc95c513aa474c289e22687bf6579a7207e8
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index aabdb26..83bbc63 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -1193,7 +1193,15 @@
         menu.setGroupVisible(R.id.ANCHOR_MENU,
                 type == WebView.HitTestResult.SRC_ANCHOR_TYPE
                 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
-
+        boolean hitText = type == WebView.HitTestResult.SRC_ANCHOR_TYPE
+                || type == WebView.HitTestResult.PHONE_TYPE
+                || type == WebView.HitTestResult.EMAIL_TYPE
+                || type == WebView.HitTestResult.GEO_TYPE;
+        menu.setGroupVisible(R.id.SELECT_TEXT_MENU, hitText);
+        if (hitText) {
+            menu.findItem(R.id.select_text_menu_id)
+                    .setOnMenuItemClickListener(new SelectText(webview));
+        }
         // Setup custom handling depending on the type
         switch (type) {
             case WebView.HitTestResult.PHONE_TYPE:
@@ -1884,6 +1892,22 @@
         }
     }
 
+    private static class SelectText implements OnMenuItemClickListener {
+        private WebView mWebView;
+
+        public boolean onMenuItemClick(MenuItem item) {
+            if (mWebView != null) {
+                return mWebView.selectText();
+            }
+            return false;
+        }
+
+        public SelectText(WebView webView) {
+            mWebView = webView;
+        }
+
+    }
+
     /********************** TODO: UI stuff *****************************/
 
     // these methods have been copied, they still need to be cleaned up