Add CODE_CAPSLOCK for long press shift key

This change utilizes the no panel auto more key feature to implement
long press shift key for shift lock.

Change-Id: I3995d25dc35aea3c67b5aa29299815462eff9cad
diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml
index 6b06ce7..a2d2fd8 100644
--- a/java/res/xml-sw600dp/key_styles_common.xml
+++ b/java/res/xml-sw600dp/key_styles_common.xml
@@ -36,34 +36,38 @@
         </default>
     </switch>
     <!-- Functional key styles -->
+    <!-- Base style for shift key. A single space is used for dummy label in moreKeys. -->
+    <key-style
+        latin:styleName="baseForShiftKeyStyle"
+        latin:code="!code/key_shift"
+        latin:keyActionFlags="noKeyPreview"
+        latin:keyLabelFlags="preserveCase"
+        latin:moreKeys="!noPanelAutoMoreKey!, |!code/key_capslock" />
     <switch>
         <case
             latin:keyboardLayoutSetElement="alphabetManualShifted|alphabetAutomaticShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <case
             latin:keyboardLayoutSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOn" />
+                latin:backgroundType="stickyOn"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <default>
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </default>
     </switch>
     <key-style
diff --git a/java/res/xml-sw768dp/key_styles_common.xml b/java/res/xml-sw768dp/key_styles_common.xml
index 4d10f5b..e69bc30 100644
--- a/java/res/xml-sw768dp/key_styles_common.xml
+++ b/java/res/xml-sw768dp/key_styles_common.xml
@@ -35,34 +35,38 @@
                 latin:keyLabelFlags="hasShiftedLetterHint" />
         </default>
     </switch>
+    <!-- Base style for shift key. A single space is used for dummy label in moreKeys. -->
+    <key-style
+        latin:styleName="baseForShiftKeyStyle"
+        latin:code="!code/key_shift"
+        latin:keyActionFlags="noKeyPreview"
+        latin:keyLabelFlags="preserveCase"
+        latin:moreKeys="!noPanelAutoMoreKey!, |!code/key_capslock" />
     <switch>
         <case
             latin:keyboardLayoutSetElement="alphabetManualShifted|alphabetAutomaticShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <case
             latin:keyboardLayoutSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOn" />
+                latin:backgroundType="stickyOn"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <default>
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </default>
     </switch>
     <key-style
diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml
index 0834adf..6590d0a 100644
--- a/java/res/xml/key_styles_common.xml
+++ b/java/res/xml/key_styles_common.xml
@@ -25,34 +25,38 @@
     <include
         latin:keyboardLayout="@xml/key_styles_f1" />
     <!-- Functional key styles -->
+    <!-- Base style for shift key. A single space is used for dummy label in moreKeys. -->
+    <key-style
+        latin:styleName="baseForShiftKeyStyle"
+        latin:code="!code/key_shift"
+        latin:keyActionFlags="noKeyPreview"
+        latin:keyLabelFlags="preserveCase"
+        latin:moreKeys="!noPanelAutoMoreKey!, |!code/key_capslock" />
     <switch>
         <case
             latin:keyboardLayoutSetElement="alphabetManualShifted|alphabetAutomaticShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <case
             latin:keyboardLayoutSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
         >
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key_shifted"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOn" />
+                latin:backgroundType="stickyOn"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </case>
         <default>
             <key-style
                 latin:styleName="shiftKeyStyle"
-                latin:code="!code/key_shift"
                 latin:keyIcon="!icon/shift_key"
-                latin:keyActionFlags="noKeyPreview"
-                latin:backgroundType="stickyOff" />
+                latin:backgroundType="stickyOff"
+                latin:parentStyle="baseForShiftKeyStyle" />
         </default>
     </switch>
     <key-style
diff --git a/java/res/xml/rows_number_normal.xml b/java/res/xml/rows_number_normal.xml
index b77544b..291018a 100644
--- a/java/res/xml/rows_number_normal.xml
+++ b/java/res/xml/rows_number_normal.xml
@@ -117,7 +117,7 @@
                 <Key
                     latin:code="0x002F"
                     latin:keyLabel="/ :"
-                    latin:moreKeys="!embeddedMoreKey!,:"
+                    latin:moreKeys="!noPanelAutoMoreKey!,:"
                     latin:keyStyle="numKeyStyle" />
             </case>
             <default>
diff --git a/java/res/xml/rows_phone.xml b/java/res/xml/rows_phone.xml
index 9299c2a..d8dcfbd 100644
--- a/java/res/xml/rows_phone.xml
+++ b/java/res/xml/rows_phone.xml
@@ -70,7 +70,7 @@
             latin:keyStyle="num0KeyStyle"
             latin:code="0x0030"
             latin:keyLabel="0 +"
-            latin:moreKeys="!embeddedMoreKey!,+" />
+            latin:moreKeys="!noPanelAutoMoreKey!,+" />
         <Key
             latin:keyStyle="numSpaceKeyStyle" />
         <Key
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index ae72b4a..4ef8653 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -113,12 +113,12 @@
     private static final int MORE_KEYS_FLAGS_FIXED_COLUMN_ORDER = 0x80000000;
     private static final int MORE_KEYS_FLAGS_HAS_LABELS = 0x40000000;
     private static final int MORE_KEYS_FLAGS_NEEDS_DIVIDERS = 0x20000000;
-    private static final int MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY = 0x10000000;
+    private static final int MORE_KEYS_FLAGS_NO_PANEL_AUTO_MORE_KEY = 0x10000000;
     private static final String MORE_KEYS_AUTO_COLUMN_ORDER = "!autoColumnOrder!";
     private static final String MORE_KEYS_FIXED_COLUMN_ORDER = "!fixedColumnOrder!";
     private static final String MORE_KEYS_HAS_LABELS = "!hasLabels!";
     private static final String MORE_KEYS_NEEDS_DIVIDERS = "!needsDividers!";
-    private static final String MORE_KEYS_EMBEDDED_MORE_KEY = "!embeddedMoreKey!";
+    private static final String MORE_KEYS_NO_PANEL_AUTO_MORE_KEY = "!noPanelAutoMoreKey!";
 
     /** Background type that represents different key background visual than normal one. */
     public final int mBackgroundType;
@@ -281,8 +281,8 @@
         if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NEEDS_DIVIDERS)) {
             moreKeysColumn |= MORE_KEYS_FLAGS_NEEDS_DIVIDERS;
         }
-        if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_EMBEDDED_MORE_KEY)) {
-            moreKeysColumn |= MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY;
+        if (KeySpecParser.getBooleanValue(moreKeys, MORE_KEYS_NO_PANEL_AUTO_MORE_KEY)) {
+            moreKeysColumn |= MORE_KEYS_FLAGS_NO_PANEL_AUTO_MORE_KEY;
         }
         mMoreKeysColumnAndFlags = moreKeysColumn;
 
@@ -657,8 +657,8 @@
         return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NEEDS_DIVIDERS) != 0;
     }
 
-    public final boolean hasEmbeddedMoreKey() {
-        return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0;
+    public final boolean hasNoPanelAutoMoreKey() {
+        return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_NO_PANEL_AUTO_MORE_KEY) != 0;
     }
 
     public final String getOutputText() {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 7295efa..4323f71 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -32,7 +32,6 @@
 import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
 import com.android.inputmethod.keyboard.internal.KeyboardState;
 import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
-import com.android.inputmethod.latin.Constants;
 import com.android.inputmethod.latin.InputView;
 import com.android.inputmethod.latin.LatinIME;
 import com.android.inputmethod.latin.LatinImeLogger;
@@ -300,26 +299,6 @@
                 ? keyboardView.getTimerProxy().isInDoubleTapShiftKeyTimeout() : false;
     }
 
-    // Implements {@link KeyboardState.SwitchActions}.
-    @Override
-    public void startLongPressTimer(final int code) {
-        final MainKeyboardView keyboardView = getMainKeyboardView();
-        if (keyboardView != null) {
-            final TimerProxy timer = keyboardView.getTimerProxy();
-            timer.startLongPressTimer(code);
-        }
-    }
-
-    // Implements {@link KeyboardState.SwitchActions}.
-    @Override
-    public void cancelLongPressTimer() {
-        final MainKeyboardView keyboardView = getMainKeyboardView();
-        if (keyboardView != null) {
-            final TimerProxy timer = keyboardView.getTimerProxy();
-            timer.cancelLongPressTimer();
-        }
-    }
-
     private void hapticAndAudioFeedback(final int code) {
         if (mKeyboardView == null || mKeyboardView.isInSlidingKeyInput()) {
             return;
@@ -327,14 +306,6 @@
         AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, mKeyboardView);
     }
 
-    public void onLongPressTimeout(final int code) {
-        mState.onLongPressTimeout(code);
-        final Keyboard keyboard = getKeyboard();
-        if (keyboard != null && keyboard.mId.isAlphabetKeyboard() && code == Constants.CODE_SHIFT) {
-            hapticAndAudioFeedback(code);
-        }
-    }
-
     /**
      * Updates state machine to figure out when to automatically switch back to the previous mode.
      */
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 435adb6..2e87726 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -248,11 +248,7 @@
                 }
                 break;
             case MSG_LONGPRESS_KEY:
-                if (tracker != null) {
-                    keyboardView.onLongPress(tracker);
-                } else {
-                    KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1);
-                }
+                keyboardView.onLongPress(tracker);
                 break;
             case MSG_UPDATE_BATCH_INPUT:
                 tracker.updateBatchInputByTimer(SystemClock.uptimeMillis());
@@ -284,23 +280,6 @@
         }
 
         @Override
-        public void startLongPressTimer(final int code) {
-            cancelLongPressTimer();
-            final int delay;
-            switch (code) {
-            case Constants.CODE_SHIFT:
-                delay = mLongPressShiftLockTimeout;
-                break;
-            default:
-                delay = 0;
-                break;
-            }
-            if (delay > 0) {
-                sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, code, 0), delay);
-            }
-        }
-
-        @Override
         public void startLongPressTimer(final PointerTracker tracker) {
             cancelLongPressTimer();
             if (tracker == null) {
@@ -1002,7 +981,7 @@
             ResearchLogger.mainKeyboardView_onLongPress();
         }
         final int code = key.mCode;
-        if (key.hasEmbeddedMoreKey()) {
+        if (key.hasNoPanelAutoMoreKey()) {
             final int embeddedCode = key.mMoreKeys[0].mCode;
             tracker.onLongPressed();
             invokeCodeInput(embeddedCode);
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index a28bd1a..958aaf5 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -92,7 +92,6 @@
         public boolean isTypingState();
         public void startKeyRepeatTimer(PointerTracker tracker);
         public void startLongPressTimer(PointerTracker tracker);
-        public void startLongPressTimer(int code);
         public void cancelLongPressTimer();
         public void startDoubleTapShiftKeyTimer();
         public void cancelDoubleTapShiftKeyTimer();
@@ -112,8 +111,6 @@
             @Override
             public void startLongPressTimer(PointerTracker tracker) {}
             @Override
-            public void startLongPressTimer(int code) {}
-            @Override
             public void cancelLongPressTimer() {}
             @Override
             public void startDoubleTapShiftKeyTimer() {}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
index 3e25c3b..a9e04bc 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java
@@ -43,6 +43,7 @@
         "key_enter",
         "key_space",
         "key_shift",
+        "key_capslock",
         "key_switch_alpha_symbol",
         "key_output_text",
         "key_delete",
@@ -79,6 +80,7 @@
         Constants.CODE_ENTER,
         Constants.CODE_SPACE,
         Constants.CODE_SHIFT,
+        Constants.CODE_CAPSLOCK,
         Constants.CODE_SWITCH_ALPHA_SYMBOL,
         Constants.CODE_OUTPUT_TEXT,
         Constants.CODE_DELETE,
@@ -116,6 +118,7 @@
         DEFAULT[12],
         DEFAULT[13],
         DEFAULT[14],
+        DEFAULT[15],
         CODE_RIGHT_PARENTHESIS,
         CODE_LEFT_PARENTHESIS,
         CODE_GREATER_THAN_SIGN,
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index bb6dec6..e1cee42 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -30,7 +30,7 @@
  * The input events are {@link #onLoadKeyboard()}, {@link #onSaveKeyboardState()},
  * {@link #onPressKey(int,boolean,int)}, {@link #onReleaseKey(int,boolean)},
  * {@link #onCodeInput(int,int)}, {@link #onFinishSlidingInput()}, {@link #onCancelInput()},
- * {@link #onUpdateShiftState(int,int)}, {@link #onLongPressTimeout(int)}.
+ * {@link #onUpdateShiftState(int,int)}.
  *
  * The actions are {@link SwitchActions}'s methods.
  */
@@ -56,8 +56,6 @@
         public void startDoubleTapShiftKeyTimer();
         public boolean isInDoubleTapShiftKeyTimeout();
         public void cancelDoubleTapShiftKeyTimer();
-        public void startLongPressTimer(int code);
-        public void cancelLongPressTimer();
     }
 
     private final SwitchActions mSwitchActions;
@@ -320,13 +318,16 @@
             Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code)
                    + " single=" + isSinglePointer + " autoCaps=" + autoCaps + " " + this);
         }
+        if (code != Constants.CODE_SHIFT) {
+            // Because the double tap shift key timer is to detect two consecutive shift key press,
+            // it should be canceled when a non-shift key is pressed.
+            mSwitchActions.cancelDoubleTapShiftKeyTimer();
+        }
         if (code == Constants.CODE_SHIFT) {
             onPressShift();
         } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
             onPressSymbol();
         } else {
-            mSwitchActions.cancelDoubleTapShiftKeyTimer();
-            mSwitchActions.cancelLongPressTimer();
             mLongPressShiftLockFired = false;
             mShiftKeyState.onOtherKeyPressed();
             mSymbolKeyState.onOtherKeyPressed();
@@ -380,15 +381,6 @@
         mSymbolKeyState.onRelease();
     }
 
-    public void onLongPressTimeout(final int code) {
-        if (DEBUG_EVENT) {
-            Log.d(TAG, "onLongPressTimeout: code=" + Constants.printableCode(code) + " " + this);
-        }
-        if (mIsAlphabetMode && code == Constants.CODE_SHIFT) {
-            mLongPressShiftLockFired = true;
-        }
-    }
-
     public void onUpdateShiftState(final int autoCaps, final int recapitalizeMode) {
         if (DEBUG_EVENT) {
             Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + ", recapitalizeMode="
@@ -448,7 +440,9 @@
         mLongPressShiftLockFired = false;
         // If we are recapitalizing, we don't do any of the normal processing, including
         // importantly the double tap timer.
-        if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) return;
+        if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
+            return;
+        }
         if (mIsAlphabetMode) {
             mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapShiftKeyTimeout();
             if (!mIsInDoubleTapShiftKey) {
@@ -484,7 +478,6 @@
                     setShifted(MANUAL_SHIFT);
                     mShiftKeyState.onPress();
                 }
-                mSwitchActions.startLongPressTimer(Constants.CODE_SHIFT);
             }
         } else {
             // In symbol mode, just toggle symbol and symbol more keyboard.
@@ -617,6 +610,12 @@
             break;
         }
 
+        if (code == Constants.CODE_CAPSLOCK) {
+            // Changing shift lock state will be handled at {@link #onPressShift()} when the shift
+            // key is released.
+            mLongPressShiftLockFired = true;
+        }
+
         // If the code is a letter, update keyboard shift state.
         if (Constants.isLetterCode(code)) {
             updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java
index 64c14d3..bb4a42e 100644
--- a/java/src/com/android/inputmethod/latin/Constants.java
+++ b/java/src/com/android/inputmethod/latin/Constants.java
@@ -172,22 +172,23 @@
 
     /**
      * Special keys code. Must be negative.
-     * These should be aligned with KeyboardCodesSet.ID_TO_NAME[],
-     * KeyboardCodesSet.DEFAULT[] and KeyboardCodesSet.RTL[]
+     * These should be aligned with {@link KeyboardCodesSet#ID_TO_NAME},
+     * {@link KeyboardCodesSet#DEFAULT}, and {@link KeyboardCodesSet#RTL}.
      */
     public static final int CODE_SHIFT = -1;
-    public static final int CODE_SWITCH_ALPHA_SYMBOL = -2;
-    public static final int CODE_OUTPUT_TEXT = -3;
-    public static final int CODE_DELETE = -4;
-    public static final int CODE_SETTINGS = -5;
-    public static final int CODE_SHORTCUT = -6;
-    public static final int CODE_ACTION_NEXT = -7;
-    public static final int CODE_ACTION_PREVIOUS = -8;
-    public static final int CODE_LANGUAGE_SWITCH = -9;
-    public static final int CODE_RESEARCH = -10;
-    public static final int CODE_SHIFT_ENTER = -11;
+    public static final int CODE_CAPSLOCK = -2;
+    public static final int CODE_SWITCH_ALPHA_SYMBOL = -3;
+    public static final int CODE_OUTPUT_TEXT = -4;
+    public static final int CODE_DELETE = -5;
+    public static final int CODE_SETTINGS = -6;
+    public static final int CODE_SHORTCUT = -7;
+    public static final int CODE_ACTION_NEXT = -8;
+    public static final int CODE_ACTION_PREVIOUS = -9;
+    public static final int CODE_LANGUAGE_SWITCH = -10;
+    public static final int CODE_RESEARCH = -11;
+    public static final int CODE_SHIFT_ENTER = -12;
     // Code value representing the code is not specified.
-    public static final int CODE_UNSPECIFIED = -12;
+    public static final int CODE_UNSPECIFIED = -13;
 
     public static boolean isLetterCode(final int code) {
         return code >= CODE_SPACE;
@@ -196,6 +197,7 @@
     public static String printableCode(final int code) {
         switch (code) {
         case CODE_SHIFT: return "shift";
+        case CODE_CAPSLOCK: return "capslock";
         case CODE_SWITCH_ALPHA_SYMBOL: return "symbol";
         case CODE_OUTPUT_TEXT: return "text";
         case CODE_DELETE: return "delete";
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 70f8d0d..6ac5474 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1420,8 +1420,8 @@
             LatinImeLogger.logOnDelete(x, y);
             break;
         case Constants.CODE_SHIFT:
-            // Note: calling back to the keyboard on Shift key is handled in onPressKey()
-            // and onReleaseKey().
+            // Note: Calling back to the keyboard on Shift key is handled in
+            // {@link #onPressKey(int,boolean)} and {@link #onReleaseKey(int,boolean)}.
             final Keyboard currentKeyboard = switcher.getKeyboard();
             if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
                 // TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
@@ -1429,9 +1429,13 @@
                 handleRecapitalize();
             }
             break;
+        case Constants.CODE_CAPSLOCK:
+            // Note: Changing keyboard to shift lock state is handled in
+            // {@link KeyboardSwitcher#onCodeInput(int)}.
+            break;
         case Constants.CODE_SWITCH_ALPHA_SYMBOL:
-            // Note: calling back to the keyboard on symbol key is handled in onPressKey()
-            // and onReleaseKey().
+            // Note: Calling back to the keyboard on symbol key is handled in
+            // {@link #onPressKey(int,boolean)} and {@link #onReleaseKey(int,boolean)}.
             break;
         case Constants.CODE_SETTINGS:
             onSettingsKeyPressed();
@@ -1484,8 +1488,9 @@
             break;
         }
         switcher.onCodeInput(primaryCode);
-        // Reset after any single keystroke, except shift and symbol-shift
+        // Reset after any single keystroke, except shift, capslock, and symbol-shift
         if (!didAutoCorrect && primaryCode != Constants.CODE_SHIFT
+                && primaryCode != Constants.CODE_CAPSLOCK
                 && primaryCode != Constants.CODE_SWITCH_ALPHA_SYMBOL)
             mLastComposedWord.deactivate();
         if (Constants.CODE_DELETE != primaryCode) {