Remove web mode and add webInput boolean

Bug: 4490948
Change-Id: I6fe23c9ab4918eab6806cc621c4d6821c2e1baf9
Cherry-Pick: I4cd1af0b
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 0e5b38b..feb955e 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -184,9 +184,10 @@
             <enum name="url" value="1" />
             <enum name="email" value="2" />
             <enum name="im" value="3" />
-            <enum name="web" value="4" />
-            <enum name="phone" value="5" />
+            <enum name="phone" value="4" />
+            <enum name="number" value="5" />
         </attr>
+        <attr name="webInput" format="boolean" />
         <attr name="passwordInput" format="boolean" />
         <attr name="hasSettingsKey" format="string" />
         <attr name="voiceKeyEnabled" format="string" />
diff --git a/java/res/xml/kbd_qwerty_f1.xml b/java/res/xml/kbd_qwerty_f1.xml
index d0e2884..e89d02d 100644
--- a/java/res/xml/kbd_qwerty_f1.xml
+++ b/java/res/xml/kbd_qwerty_f1.xml
@@ -46,7 +46,7 @@
                 </case>
                 <!-- latin:hasVoiceKey="false" -->
                 <case
-                    latin:mode="web"
+                    latin:webInput="true"
                 >
                     <Key
                         latin:keyLabel="."
diff --git a/java/res/xml/kbd_qwerty_row4.xml b/java/res/xml/kbd_qwerty_row4.xml
index 82f5a4a..a8d150e 100644
--- a/java/res/xml/kbd_qwerty_row4.xml
+++ b/java/res/xml/kbd_qwerty_row4.xml
@@ -40,7 +40,7 @@
                     latin:keyWidth="40%p" />
                 <switch>
                     <case
-                        latin:mode="web"
+                        latin:webInput="true"
                     >
                          <Key
                             latin:keyHintIcon="@drawable/hint_popup"
@@ -90,7 +90,7 @@
                     latin:keyWidth="30%p" />
                 <switch>
                     <case
-                        latin:mode="web"
+                        latin:webInput="true"
                     >
                          <Key
                             latin:keyHintIcon="@drawable/hint_popup"
diff --git a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java b/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java
index d851741..6684f6a 100644
--- a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java
@@ -37,6 +37,7 @@
             (Integer) CompatUtils.getFieldValue(null, null,
                     FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD);
     private static final int WEB_TEXT_PASSWORD_INPUT_TYPE;
+    private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
     private static final int NUMBER_PASSWORD_INPUT_TYPE;
     private static final int TEXT_PASSWORD_INPUT_TYPE =
             InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
@@ -45,9 +46,14 @@
 
     static {
         WEB_TEXT_PASSWORD_INPUT_TYPE =
-                OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD != null
-                        ? InputType.TYPE_CLASS_TEXT | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD
-                        : 0;
+            OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD != null
+                    ? InputType.TYPE_CLASS_TEXT | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD
+                    : 0;
+        WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE =
+            OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null
+                    ? InputType.TYPE_CLASS_TEXT
+                            | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
+                    : 0;
         NUMBER_PASSWORD_INPUT_TYPE =
                 OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD != null
                         ? InputType.TYPE_CLASS_NUMBER | OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD
@@ -59,6 +65,11 @@
                 && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
     }
 
+    private static boolean isWebEmailAddressInputType(int inputType) {
+        return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
+                && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
+    }
+
     private static boolean isNumberPasswordInputType(int inputType) {
         return NUMBER_PASSWORD_INPUT_TYPE != 0
                 && inputType == NUMBER_PASSWORD_INPUT_TYPE;
@@ -78,6 +89,14 @@
                 || isWebEmailAddressVariation(variation);
     }
 
+    public static boolean isWebInputType(int inputType) {
+        final int maskedInputType =
+                inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
+        return maskedInputType == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT
+                || isWebPasswordInputType(maskedInputType)
+                || isWebEmailAddressInputType(maskedInputType);
+    }
+
     // Please refer to TextView.isPasswordInputType
     public static boolean isPasswordInputType(int inputType) {
         final int maskedInputType =
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 2a5e177..88d2398 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -34,9 +34,8 @@
     public static final int MODE_URL = 1;
     public static final int MODE_EMAIL = 2;
     public static final int MODE_IM = 3;
-    public static final int MODE_WEB = 4;
-    public static final int MODE_PHONE = 5;
-    public static final int MODE_NUMBER = 6;
+    public static final int MODE_PHONE = 4;
+    public static final int MODE_NUMBER = 5;
 
     public final Locale mLocale;
     public final int mOrientation;
@@ -44,6 +43,7 @@
     public final int mMode;
     public final int mXmlId;
     public final int mColorScheme;
+    public final boolean mWebInput;
     public final boolean mPasswordInput;
     public final boolean mHasSettingsKey;
     public final boolean mVoiceKeyEnabled;
@@ -67,6 +67,7 @@
         this.mMode = mode;
         this.mXmlId = xmlId;
         this.mColorScheme = colorScheme;
+        this.mWebInput = InputTypeCompatUtils.isWebInputType(inputType);
         this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType)
                 || InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
         this.mHasSettingsKey = hasSettingsKey;
@@ -88,6 +89,7 @@
                 mode,
                 xmlId,
                 colorScheme,
+                mWebInput,
                 mPasswordInput,
                 hasSettingsKey,
                 voiceKeyEnabled,
@@ -141,6 +143,7 @@
             && other.mMode == this.mMode
             && other.mXmlId == this.mXmlId
             && other.mColorScheme == this.mColorScheme
+            && other.mWebInput == this.mWebInput
             && other.mPasswordInput == this.mPasswordInput
             && other.mHasSettingsKey == this.mHasSettingsKey
             && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled
@@ -156,18 +159,19 @@
 
     @Override
     public String toString() {
-        return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s]",
+        return String.format("[%s.xml %s %s%d %s %s %s %s%s%s%s%s%s]",
                 mXmlName,
                 mLocale,
                 (mOrientation == 1 ? "port" : "land"), mWidth,
                 modeName(mMode),
                 EditorInfoCompatUtils.imeOptionsName(mImeAction),
+                colorSchemeName(mColorScheme),
+                (mWebInput ? " webInput" : ""),
                 (mPasswordInput ? " passwordInput" : ""),
                 (mHasSettingsKey ? " hasSettingsKey" : ""),
                 (mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
                 (mHasVoiceKey ? " hasVoiceKey" : ""),
-                (mEnableShiftLock ? " enableShiftLock" : ""),
-                colorSchemeName(mColorScheme)
+                (mEnableShiftLock ? " enableShiftLock" : "")
         );
     }
 
@@ -177,7 +181,6 @@
         case MODE_URL: return "url";
         case MODE_EMAIL: return "email";
         case MODE_IM: return "im";
-        case MODE_WEB: return "web";
         case MODE_PHONE: return "phone";
         case MODE_NUMBER: return "number";
         }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
index 5980f02..43d9f27 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
@@ -456,6 +456,8 @@
         try {
             final boolean modeMatched = matchInteger(a,
                     R.styleable.Keyboard_Case_mode, id.mMode);
+            final boolean webInputMatched = matchBoolean(a,
+                    R.styleable.Keyboard_Case_webInput, id.mWebInput);
             final boolean passwordInputMatched = matchBoolean(a,
                     R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput);
             final boolean settingsKeyMatched = matchBoolean(a,
@@ -476,16 +478,18 @@
                     R.styleable.Keyboard_Case_languageCode, id.mLocale.getLanguage());
             final boolean countryCodeMatched = matchString(a,
                     R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry());
-            final boolean selected = modeMatched && passwordInputMatched && settingsKeyMatched
-                    && voiceEnabledMatched && voiceKeyMatched && colorSchemeMatched
-                    && imeActionMatched && languageCodeMatched && countryCodeMatched;
+            final boolean selected = modeMatched && webInputMatched && passwordInputMatched
+                    && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched
+                    && colorSchemeMatched && imeActionMatched && languageCodeMatched
+                    && countryCodeMatched;
 
-            if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE,
+            if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE,
                     textAttr(KeyboardId.modeName(
                             a.getInt(R.styleable.Keyboard_Case_mode, -1)), "mode"),
                     textAttr(KeyboardId.colorSchemeName(
                             viewAttr.getInt(
                                     R.styleable.KeyboardView_colorScheme, -1)), "colorSchemeName"),
+                    booleanAttr(a, R.styleable.Keyboard_Case_webInput, "webInput"),
                     booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"),
                     booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"),
                     booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"),
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d625951..fd6c478 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -81,7 +81,7 @@
     private static final String TAG = LatinIME.class.getSimpleName();
     private static final boolean PERF_DEBUG = false;
     private static final boolean TRACE = false;
-    private static boolean DEBUG = LatinImeLogger.sDBG;
+    private static boolean DEBUG;
 
     /**
      * The private IME option used to indicate that no microphone should be
@@ -357,6 +357,7 @@
         mSubtypeSwitcher = SubtypeSwitcher.getInstance();
         mKeyboardSwitcher = KeyboardSwitcher.getInstance();
         mRecorrection = Recorrection.getInstance();
+        DEBUG = LatinImeLogger.sDBG;
 
         loadSettings();
 
@@ -506,7 +507,8 @@
         LatinKeyboardView inputView = switcher.getKeyboardView();
 
         if (DEBUG) {
-            Log.d(TAG, "onStartInputView: " + inputView);
+            Log.d(TAG, "onStartInputView: inputType=" + ((attribute == null) ? "none"
+                    : String.format("0x%08x", attribute.inputType)));
         }
         // In landscape mode, this method gets called without the input view being created.
         if (inputView == null) {
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 5207f38..66a6d16 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -538,8 +538,6 @@
                 return KeyboardId.MODE_IM;
             } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
                 return KeyboardId.MODE_TEXT;
-            } else if (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
-                return KeyboardId.MODE_WEB;
             } else {
                 return KeyboardId.MODE_TEXT;
             }