fix ComboPage dialog/popup/IME bug

    Bug 3166409
    Put the tab in background while ComboPage is up
    this prevents dialogs from getting displayed

    Bug 3215897
    make sure the IME is closed before ComboPage is displayed

Change-Id: If832e040e2fa9acb12f45a3e9f681d1fd333f3b0
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 6ae6f1b..b39cb43 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -38,6 +38,7 @@
 import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
 import android.webkit.WebChromeClient;
 import android.webkit.WebHistoryItem;
 import android.webkit.WebView;
@@ -70,6 +71,7 @@
     UiController mUiController;
     TabControl mTabControl;
     private Tab mActiveTab;
+    private InputMethodManager mInputManager;
 
     private Drawable mSecLockIcon;
     private Drawable mMixLockIcon;
@@ -107,6 +109,8 @@
         mUiController = controller;
         mTabControl = controller.getTabControl();
         Resources res = mActivity.getResources();
+        mInputManager = (InputMethodManager)
+                browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
         mSecLockIcon = res.getDrawable(R.drawable.ic_secure);
         mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
 
@@ -583,6 +587,11 @@
                 extras);
         mTitleBar.setVisibility(View.GONE);
         hideFakeTitleBar();
+        dismissIME();
+        if (mActiveTab != null) {
+            WebView web = mActiveTab.getWebView();
+            mActiveTab.putInBackground();
+        }
         mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
     }
 
@@ -596,6 +605,9 @@
             mTitleBar.setVisibility(View.VISIBLE);
             mComboView = null;
         }
+        if (mActiveTab != null) {
+            mActiveTab.putInForeground();
+        }
     }
 
     @Override
@@ -658,6 +670,13 @@
         mFakeTitleBar.setDisplayTitle(url);
     }
 
+    private void dismissIME() {
+        if (mInputManager.isActive()) {
+            mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
+                    0);
+        }
+    }
+
     // -------------------------------------------------------------------------
 
     @Override
@@ -745,8 +764,6 @@
 
     /**
      * Remove the active tabs page.
-     * @param needToAttach If true, the active tabs page did not attach a tab
-     *                     to the content view, so we need to do that here.
      */
     public void removeActiveTabsPage() {
         mContentView.removeView(mActiveTabsPage);