Fix bugs around overlay action modes.

Multiple focusable windows cause undesired behavior around selection
modes. TextView isn't sure how to behave when it loses window focus
with regard to selection handles and action modes need to be focusable
for WebView find on page since it uses an EditText as a custom view.

For now:

* Use a layered window decor for overlay action mode when there is no
  action bar requested. This eliminates an extra window and avoids the
  issue described for full-screen UIs.

* Disable WebView's find-on-page mode when the action mode's UI will
  not be focusable. This only affects WebViews in floating windows.

Also remove the "Text Selection" title for WebView's selection mode at
UX's request, as it is inconsistent with TextView's selection mode and
the string does not fit on phones in portrait even on wide
devices. This now uses the same mechanism used in TextView to decide
whether to use title text.

Change-Id: I80caeecea9b47728cf26bb0a388153ca0bdeafe1
diff --git a/core/java/android/webkit/SelectActionModeCallback.java b/core/java/android/webkit/SelectActionModeCallback.java
index 104deb1..8c174aa 100644
--- a/core/java/android/webkit/SelectActionModeCallback.java
+++ b/core/java/android/webkit/SelectActionModeCallback.java
@@ -17,13 +17,12 @@
 package android.webkit;
 
 import android.app.SearchManager;
+import android.content.Context;
 import android.content.Intent;
 import android.provider.Browser;
-import android.webkit.WebView;
 import android.view.ActionMode;
 import android.view.Menu;
 import android.view.MenuItem;
-import android.view.View;
 
 class SelectActionModeCallback implements ActionMode.Callback {
     private WebView mWebView;
@@ -45,9 +44,25 @@
 
     @Override
     public boolean onCreateActionMode(ActionMode mode, Menu menu) {
-        mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy,
-                menu);
-        mode.setTitle(com.android.internal.R.string.textSelectionCABTitle);
+        mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_copy, menu);
+
+        final Context context = mWebView.getContext();
+        boolean allowText = context.getResources().getBoolean(
+                com.android.internal.R.bool.config_allowActionMenuItemTextWithIcon);
+        mode.setTitle(allowText ?
+                context.getString(com.android.internal.R.string.textSelectionCABTitle) : null);
+
+        if (!mode.isUiFocusable()) {
+            // If the action mode UI we're running in isn't capable of taking window focus
+            // the user won't be able to type into the find on page UI. Disable this functionality.
+            // (Note that this should only happen in floating dialog windows.)
+            // This can be removed once we can handle multiple focusable windows at a time
+            // in a better way.
+            final MenuItem findOnPageItem = menu.findItem(com.android.internal.R.id.find);
+            if (findOnPageItem != null) {
+                findOnPageItem.setVisible(false);
+            }
+        }
         mActionMode = mode;
         return true;
     }