fix tab switcher close/refresh issue

    Bug: 5015810
    Also fixes the case when closing a tab without changing the
    selected position the list would be empty.

Change-Id: Ibf4de0b33c696d14e15b82c07e697b1f1736565a
diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java
index 1c35b45..6a51e87 100644
--- a/src/com/android/browser/NavScreen.java
+++ b/src/com/android/browser/NavScreen.java
@@ -156,8 +156,11 @@
 
     private void onCloseTab(Tab tab) {
         if (tab != null) {
-            switchToSelected();
-            mUiController.closeCurrentTab();
+            if (tab == mUiController.getCurrentTab()) {
+                mUiController.closeCurrentTab();
+            } else {
+                mUiController.closeTab(tab);
+            }
             mAdapter.notifyDataSetChanged();
         }
     }
@@ -229,8 +232,10 @@
                 @Override
                 public void onClick(View v) {
                     if (tabview.isClose(v)) {
-                        onCloseTab((Tab) (mScroller.getSelectedItem()));
+                        onCloseTab(tab);
                     } else if (tabview.isTitle(v)) {
+                        mScroller.setSelection(position);
+                        switchToSelected();
                         mUi.getTitleBar().setSkipTitleBarAnimations(true);
                         close(false);
                         mUi.editUrl(false);
@@ -238,7 +243,6 @@
                     } else if (tabview.isWebView(v)) {
                         mScroller.setSelection(position);
                         close();
-
                     }
                 }
             });