Detect when keyboard has been dismissed by Back Key

The browser now knows for sure if the keyboard is visible

Change-Id: I8c9a91f23bac565703382ade06b8fde3b2550c1e
diff --git a/src/com/android/browser/BrowserWebView.java b/src/com/android/browser/BrowserWebView.java
index 75f595b..0159cb7 100644
--- a/src/com/android/browser/BrowserWebView.java
+++ b/src/com/android/browser/BrowserWebView.java
@@ -20,6 +20,7 @@
 import android.graphics.Canvas;
 import android.content.res.Resources;
 import android.util.AttributeSet;
+import android.view.KeyEvent;
 import android.view.View;
 import org.codeaurora.swe.WebChromeClient;
 import org.codeaurora.swe.WebView;
@@ -186,4 +187,16 @@
         super.destroy();
     }
 
+    @Override
+    public boolean dispatchKeyEventPreIme(KeyEvent event) {
+        Tab currentTab = mTitleBar.getUiController().getCurrentTab();
+        if (currentTab != null && currentTab.isKeyboardShowing()){
+            // Try to detect the "back" key that dismisses the keyboard
+            if(event.getAction() == KeyEvent.ACTION_DOWN &&
+                    event.getKeyCode() == KeyEvent.KEYCODE_BACK)
+                mWebViewClient.onKeyboardStateChange(false);
+        }
+        return super.dispatchKeyEventPreIme(event);
+    }
+
 }
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index e331cd9..0a4bc34 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -578,14 +578,15 @@
             }
             KeyChain.choosePrivateKeyAlias(
                     mWebViewController.getActivity(), new KeyChainAliasCallback() {
-                @Override public void alias(String alias) {
-                    if (alias == null) {
-                        handler.cancel();
-                        return;
-                    }
-                    new KeyChainLookup(mContext, handler, alias).execute();
-                }
-            }, null, null, host, port, null);
+                        @Override
+                        public void alias(String alias) {
+                            if (alias == null) {
+                                handler.cancel();
+                                return;
+                            }
+                            new KeyChainLookup(mContext, handler, alias).execute();
+                        }
+                    }, null, null, host, port, null);
         }
 
         /**
@@ -671,7 +672,7 @@
             }
 
             int index = getCaptureIndex(view.getLastCommittedHistoryIndex());
-            view.captureSnapshot(index , null);
+            view.captureSnapshot(index, null);
         }
 
         @Override