From 8ce475eea02919bb638c969232b755de99800315 Mon Sep 17 00:00:00 2001
From: jdduke <jdduke@chromium.org>
Date: Fri, 19 Dec 2014 12:35:29 -0800
Subject: [Android] Use the TextInputType enum in ImeAdapater

Use the auto-generated TextInputType Java enum class directly, rather
than the static constants previously piped to ImeAdapater.

Review URL: https://codereview.chromium.org/818493004

Cr-Commit-Position: refs/heads/master@{#309247}
---
 .../browser/renderer_host/ime_adapter_android.cc   | 22 +++-------
 .../chromium/content/browser/ContentViewCore.java  |  5 ++-
 .../browser/input/AdapterInputConnection.java      | 19 ++++----
 .../chromium/content/browser/input/ImeAdapter.java | 51 ++++------------------
 4 files changed, 28 insertions(+), 69 deletions(-)

diff --git a/content/browser/renderer_host/ime_adapter_android.cc b/content/browser/renderer_host/ime_adapter_android.cc
index 077e625..d780d0c 100644
--- a/content/browser/renderer_host/ime_adapter_android.cc
+++ b/content/browser/renderer_host/ime_adapter_android.cc
@@ -57,6 +57,8 @@ NativeWebKeyboardEvent NativeWebKeyboardEventFromKeyEvent(
     type = blink::WebInputEvent::RawKeyDown;
   else if (action == AKEY_EVENT_ACTION_UP)
     type = blink::WebInputEvent::KeyUp;
+  else
+    NOTREACHED() << "Invalid Android key event action: " << action;
   return NativeWebKeyboardEvent(java_key_event, type, modifiers,
       time_ms / 1000.0, key_code, unicode_char, is_system_key);
 }
@@ -76,18 +78,6 @@ bool RegisterImeAdapter(JNIEnv* env) {
                                            blink::WebInputEvent::ControlKey,
                                            blink::WebInputEvent::CapsLockOn,
                                            blink::WebInputEvent::NumLockOn);
-  Java_ImeAdapter_initializeTextInputTypes(
-      env,
-      ui::TEXT_INPUT_TYPE_NONE,
-      ui::TEXT_INPUT_TYPE_TEXT,
-      ui::TEXT_INPUT_TYPE_TEXT_AREA,
-      ui::TEXT_INPUT_TYPE_PASSWORD,
-      ui::TEXT_INPUT_TYPE_SEARCH,
-      ui::TEXT_INPUT_TYPE_URL,
-      ui::TEXT_INPUT_TYPE_EMAIL,
-      ui::TEXT_INPUT_TYPE_TELEPHONE,
-      ui::TEXT_INPUT_TYPE_NUMBER,
-      ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
   Java_ImeAdapter_initializeTextInputFlags(
       env,
       blink::WebTextInputFlagAutocompleteOn,
@@ -107,8 +97,8 @@ void AppendBackgroundColorSpan(JNIEnv*,
                                jint start,
                                jint end,
                                jint background_color) {
-  DCHECK(start >= 0);
-  DCHECK(end >= 0);
+  DCHECK_GE(start, 0);
+  DCHECK_GE(end, 0);
   // Do not check |background_color|.
   std::vector<blink::WebCompositionUnderline>* underlines =
       reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>(
@@ -128,8 +118,8 @@ void AppendUnderlineSpan(JNIEnv*,
                          jlong underlines_ptr,
                          jint start,
                          jint end) {
-  DCHECK(start >= 0);
-  DCHECK(end >= 0);
+  DCHECK_GE(start, 0);
+  DCHECK_GE(end, 0);
   std::vector<blink::WebCompositionUnderline>* underlines =
       reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>(
           underlines_ptr);
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 4b8da05..becb3c6 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -80,6 +80,7 @@ import org.chromium.ui.base.DeviceFormFactor;
 import org.chromium.ui.base.ViewAndroid;
 import org.chromium.ui.base.ViewAndroidDelegate;
 import org.chromium.ui.base.WindowAndroid;
+import org.chromium.ui.base.ime.TextInputType;
 import org.chromium.ui.gfx.DeviceDisplayInfo;
 import org.chromium.ui.touch_selection.SelectionEventType;
 
@@ -1502,7 +1503,7 @@ public class ContentViewCore
             if (newConfig.keyboard != Configuration.KEYBOARD_NOKEYS) {
                 if (mNativeContentViewCore != 0) {
                     mImeAdapter.attach(nativeGetNativeImeAdapter(mNativeContentViewCore),
-                            ImeAdapter.getTextInputTypeNone(), 0 /* no flags */);
+                            TextInputType.NONE, 0 /* no flags */);
                 }
                 mInputMethodManagerWrapper.restartInput(mContainerView);
             }
@@ -2270,7 +2271,7 @@ public class ContentViewCore
             boolean isNonImeChange) {
         try {
             TraceEvent.begin("ContentViewCore.updateImeAdapter");
-            mFocusedNodeEditable = (textInputType != ImeAdapter.getTextInputTypeNone());
+            mFocusedNodeEditable = (textInputType != TextInputType.NONE);
             if (!mFocusedNodeEditable) hidePastePopup();
 
             mImeAdapter.updateKeyboardVisibility(
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java b/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java
index 092ffbe..c1691f9 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/AdapterInputConnection.java
@@ -19,6 +19,7 @@ import android.view.inputmethod.ExtractedText;
 import android.view.inputmethod.ExtractedTextRequest;
 
 import org.chromium.base.VisibleForTesting;
+import org.chromium.ui.base.ime.TextInputType;
 
 /**
  * InputConnection is created by ContentView.onCreateInputConnection.
@@ -72,14 +73,14 @@ public class AdapterInputConnection extends BaseInputConnection {
             outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
         }
 
-        if (inputType == ImeAdapter.sTextInputTypeText) {
+        if (inputType == TextInputType.TEXT) {
             // Normal text field
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
             if ((inputFlags & imeAdapter.sTextInputFlagAutocorrectOff) == 0) {
                 outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
             }
-        } else if (inputType == ImeAdapter.sTextInputTypeTextArea
-                || inputType == ImeAdapter.sTextInputTypeContentEditable) {
+        } else if (inputType == TextInputType.TEXT_AREA
+                || inputType == TextInputType.CONTENT_EDITABLE) {
             // TextArea or contenteditable.
             outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
                     | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES;
@@ -88,31 +89,31 @@ public class AdapterInputConnection extends BaseInputConnection {
             }
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
             mSingleLine = false;
-        } else if (inputType == ImeAdapter.sTextInputTypePassword) {
+        } else if (inputType == TextInputType.PASSWORD) {
             // Password
             outAttrs.inputType = InputType.TYPE_CLASS_TEXT
                     | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
-        } else if (inputType == ImeAdapter.sTextInputTypeSearch) {
+        } else if (inputType == TextInputType.SEARCH) {
             // Search
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
-        } else if (inputType == ImeAdapter.sTextInputTypeUrl) {
+        } else if (inputType == TextInputType.URL) {
             // Url
             outAttrs.inputType = InputType.TYPE_CLASS_TEXT
                     | InputType.TYPE_TEXT_VARIATION_URI;
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
-        } else if (inputType == ImeAdapter.sTextInputTypeEmail) {
+        } else if (inputType == TextInputType.EMAIL) {
             // Email
             outAttrs.inputType = InputType.TYPE_CLASS_TEXT
                     | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
-        } else if (inputType == ImeAdapter.sTextInputTypeTel) {
+        } else if (inputType == TextInputType.TELEPHONE) {
             // Telephone
             // Number and telephone do not have both a Tab key and an
             // action in default OSK, so set the action to NEXT
             outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
             outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
-        } else if (inputType == ImeAdapter.sTextInputTypeNumber) {
+        } else if (inputType == TextInputType.NUMBER) {
             // Number
             outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
                     | InputType.TYPE_NUMBER_VARIATION_NORMAL
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
index 33c8e8d..3d81e1e 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
@@ -20,6 +20,7 @@ import android.view.inputmethod.EditorInfo;
 import org.chromium.base.CalledByNative;
 import org.chromium.base.JNINamespace;
 import org.chromium.base.VisibleForTesting;
+import org.chromium.ui.base.ime.TextInputType;
 import org.chromium.ui.picker.InputDialogContainer;
 
 import java.lang.CharSequence;
@@ -88,7 +89,7 @@ public class ImeAdapter {
         @Override
         public void run() {
             if (mNativeImeAdapter != 0) {
-                attach(mNativeImeAdapter, sTextInputTypeNone, sTextInputFlagNone);
+                attach(mNativeImeAdapter, TextInputType.NONE, sTextInputFlagNone);
             }
             dismissInput(true);
         }
@@ -108,16 +109,6 @@ public class ImeAdapter {
     static int sEventTypeRawKeyDown;
     static int sEventTypeKeyUp;
     static int sEventTypeChar;
-    static int sTextInputTypeNone;
-    static int sTextInputTypeText;
-    static int sTextInputTypeTextArea;
-    static int sTextInputTypePassword;
-    static int sTextInputTypeSearch;
-    static int sTextInputTypeUrl;
-    static int sTextInputTypeEmail;
-    static int sTextInputTypeTel;
-    static int sTextInputTypeNumber;
-    static int sTextInputTypeContentEditable;
     static int sTextInputFlagNone = 0;
     static int sTextInputFlagAutocompleteOn;
     static int sTextInputFlagAutocompleteOff;
@@ -214,13 +205,6 @@ public class ImeAdapter {
         return mTextInputFlags;
     }
 
-    /**
-     * @return Constant representing that a focused node is not an input field.
-     */
-    public static int getTextInputTypeNone() {
-        return sTextInputTypeNone;
-    }
-
     private static int getModifiers(int metaState) {
         int modifiers = 0;
         if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
@@ -253,14 +237,14 @@ public class ImeAdapter {
 
         // If current input type is none and showIfNeeded is false, IME should not be shown
         // and input type should remain as none.
-        if (mTextInputType == sTextInputTypeNone && !showIfNeeded) {
+        if (mTextInputType == TextInputType.NONE && !showIfNeeded) {
             return;
         }
 
         if (mNativeImeAdapterAndroid != nativeImeAdapter || mTextInputType != textInputType) {
             // Set a delayed task to perform unfocus. This avoids hiding the keyboard when tabbing
             // through text inputs or when JS rapidly changes focus to another text element.
-            if (textInputType == sTextInputTypeNone) {
+            if (textInputType == TextInputType.NONE) {
                 mDismissInput = new DelayedDismissInput(nativeImeAdapter);
                 mHandler.postDelayed(mDismissInput, INPUT_DISMISS_DELAY);
                 return;
@@ -288,7 +272,7 @@ public class ImeAdapter {
         if (nativeImeAdapter != 0) {
             nativeAttachImeAdapter(mNativeImeAdapterAndroid);
         }
-        if (mTextInputType == sTextInputTypeNone) {
+        if (mTextInputType == TextInputType.NONE) {
             dismissInput(false);
         }
     }
@@ -299,7 +283,7 @@ public class ImeAdapter {
      * @param nativeImeAdapter The pointer to the native ImeAdapter object.
      */
     public void attach(long nativeImeAdapter) {
-        attach(nativeImeAdapter, sTextInputTypeNone, sTextInputFlagNone);
+        attach(nativeImeAdapter, TextInputType.NONE, sTextInputFlagNone);
     }
 
     private void showKeyboard() {
@@ -319,11 +303,11 @@ public class ImeAdapter {
     }
 
     private boolean hasInputType() {
-        return mTextInputType != sTextInputTypeNone;
+        return mTextInputType != TextInputType.NONE;
     }
 
     private static boolean isTextInputType(int type) {
-        return type != sTextInputTypeNone && !InputDialogContainer.isDialogInputType(type);
+        return type != TextInputType.NONE && !InputDialogContainer.isDialogInputType(type);
     }
 
     public boolean hasTextInputType() {
@@ -334,7 +318,7 @@ public class ImeAdapter {
      * @return true if the selected text is of password.
      */
     public boolean isSelectionPassword() {
-        return mTextInputType == sTextInputTypePassword;
+        return mTextInputType == TextInputType.PASSWORD;
     }
 
     public boolean dispatchKeyEvent(KeyEvent event) {
@@ -645,23 +629,6 @@ public class ImeAdapter {
     }
 
     @CalledByNative
-    private static void initializeTextInputTypes(int textInputTypeNone, int textInputTypeText,
-            int textInputTypeTextArea, int textInputTypePassword, int textInputTypeSearch,
-            int textInputTypeUrl, int textInputTypeEmail, int textInputTypeTel,
-            int textInputTypeNumber, int textInputTypeContentEditable) {
-        sTextInputTypeNone = textInputTypeNone;
-        sTextInputTypeText = textInputTypeText;
-        sTextInputTypeTextArea = textInputTypeTextArea;
-        sTextInputTypePassword = textInputTypePassword;
-        sTextInputTypeSearch = textInputTypeSearch;
-        sTextInputTypeUrl = textInputTypeUrl;
-        sTextInputTypeEmail = textInputTypeEmail;
-        sTextInputTypeTel = textInputTypeTel;
-        sTextInputTypeNumber = textInputTypeNumber;
-        sTextInputTypeContentEditable = textInputTypeContentEditable;
-    }
-
-    @CalledByNative
     private static void initializeTextInputFlags(
             int textInputFlagAutocompleteOn, int textInputFlagAutocompleteOff,
             int textInputFlagAutocorrectOn, int textInputFlagAutocorrectOff,
-- 
cgit v1.1