use screenshots for tab switcher

    also removed the old tab switcher code

Change-Id: Id84ff64e42e5e1f70f55e136efdf84270c1a4b7b
diff --git a/res/layout/active_tabs.xml b/res/layout/active_tabs.xml
deleted file mode 100644
index f9bd6b0..0000000
--- a/res/layout/active_tabs.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
-
-    <LinearLayout
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content">
-
-        <Button
-            android:id="@+id/new_tab"
-            android:text="@string/new_tab"
-            android:layout_width="0dip"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:singleLine="true"
-            android:textAppearance="?android:attr/textAppearanceSmall" />
-
-        <Button
-            android:id="@+id/new_incognito_tab"
-            android:text="@string/new_incognito_tab"
-            android:layout_width="0dip"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:singleLine="true"
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:paddingLeft="0dip"
-            android:paddingRight="0dip" />
-
-    </LinearLayout>
-
-    <ListView
-        android:id="@android:id/list"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:listSelector="@drawable/bookmark_thumb_selector"
-        android:drawSelectorOnTop="true"
-        android:focusable="true"
-        android:focusableInTouchMode="true" />
-
-</merge>
diff --git a/res/layout/nav_tab_view.xml b/res/layout/nav_tab_view.xml
index 543c26e..05c91a0 100644
--- a/res/layout/nav_tab_view.xml
+++ b/res/layout/nav_tab_view.xml
@@ -48,11 +48,10 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content" />
     </LinearLayout>
-    <FrameLayout
+    <ImageView
         android:id="@+id/tab_view"
         android:layout_width="@dimen/nav_tab_width"
         android:layout_height="@dimen/nav_tab_height"
         android:layout_gravity="center_horizontal"
-        android:focusable="false">
-    </FrameLayout>
+        android:focusable="false" />
 </LinearLayout>
diff --git a/res/menu/browser.xml b/res/menu/browser.xml
index 630bb87..b5d80c5 100644
--- a/res/menu/browser.xml
+++ b/res/menu/browser.xml
@@ -30,11 +30,6 @@
                 android:alphabeticShortcut="b"
                 android:icon="@drawable/ic_bookmarks_holo_dark" />
             <item
-                android:id="@+id/active_tabs_menu_id"
-                android:title="@string/active_tabs"
-                android:icon="@drawable/ic_windows_holo_dark"
-                android:alphabeticShortcut="t" />
-            <item
                 android:id="@+id/stop_reload_menu_id"
                 android:alphabeticShortcut="r" />
             <item
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 253d811..d7f2934 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -26,8 +26,6 @@
     <!-- Name of menu item of a new incognito tab.  Also used in the
          title bar when displaying a new tab [CHAR LIMIT=30] -->
     <string name="new_incognito_tab">New incognito window</string>
-    <!-- Name of menu item which brings up a list of the currently active tabs -->
-    <string name="active_tabs">Windows</string>
     <!-- Name of tab containing bookmarks -->
     <string name="tab_bookmarks">Bookmarks</string>
     <!-- Name of tab containing the user's most visited websites, organized by number of visits -->
diff --git a/src/com/android/browser/ActiveTabsPage.java b/src/com/android/browser/ActiveTabsPage.java
deleted file mode 100644
index 0feba9a..0000000
--- a/src/com/android/browser/ActiveTabsPage.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.browser;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.AbsListView;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
-import android.widget.ImageView.ScaleType;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-interface OnCloseTab {
-    void onCloseTab(int position);
-}
-
-public class ActiveTabsPage extends LinearLayout implements OnClickListener,
-        OnItemClickListener, OnCloseTab {
-
-    private Context mContext;
-    private UiController mController;
-    private TabControl mTabControl;
-    private View mNewTab, mNewIncognitoTab;
-    private TabAdapter mAdapter;
-    private AbsListView mTabsList;
-
-    public ActiveTabsPage(Context context, UiController controller) {
-        super(context);
-        mContext = context;
-        mController = controller;
-        mTabControl = mController.getTabControl();
-        setOrientation(VERTICAL);
-        setBackgroundResource(R.drawable.bg_browser);
-        LayoutInflater inflate = LayoutInflater.from(mContext);
-        inflate.inflate(R.layout.active_tabs, this, true);
-        mNewTab = findViewById(R.id.new_tab);
-        mNewIncognitoTab = findViewById(R.id.new_incognito_tab);
-        mNewTab.setOnClickListener(this);
-        mNewIncognitoTab.setOnClickListener(this);
-        int visibility = mTabControl.canCreateNewTab() ? View.VISIBLE : View.GONE;
-        mNewTab.setVisibility(visibility);
-        mNewIncognitoTab.setVisibility(visibility);
-        mTabsList = (AbsListView) findViewById(android.R.id.list);
-        mAdapter = new TabAdapter(mContext, mTabControl);
-        mAdapter.setOnCloseListener(this);
-        mTabsList.setAdapter(mAdapter);
-        mTabsList.setOnItemClickListener(this);
-    }
-
-    @Override
-    public void onClick(View v) {
-        if (v == mNewTab) {
-            mController.openTabToHomePage();
-        } else if (v == mNewIncognitoTab) {
-            mController.openIncognitoTab();
-        }
-        mController.removeActiveTabsPage(false);
-    }
-
-    @Override
-    public void onItemClick(
-            AdapterView<?> parent, View view, int position, long id) {
-        final Tab tab = mTabControl.getTab(position);
-        boolean needToAttach = !mController.switchToTab(tab);
-        mController.removeActiveTabsPage(needToAttach);
-    }
-
-    @Override
-    public void onCloseTab(int position) {
-        Tab tab = mTabControl.getTab(position);
-        if (tab != null) {
-            mController.closeTab(tab);
-            if (mTabControl.getTabCount() == 0) {
-                mController.openTabToHomePage();
-                mController.removeActiveTabsPage(false);
-            } else {
-                mAdapter.notifyDataSetChanged();
-            }
-        }
-    }
-
-    /**
-     * Special class to hold the close drawable.  Its sole purpose is to allow
-     * the parent to be pressed without being pressed itself.  This way the line
-     * of a tab can be pressed, but the close button itself is not.
-     */
-    public static class CloseHolder extends ImageView {
-        public CloseHolder(Context context, AttributeSet attrs) {
-            super(context, attrs);
-        }
-
-        @Override
-        public void setPressed(boolean pressed) {
-            // If the parent is pressed, do not set to pressed.
-            if (pressed && ((View) getParent()).isPressed()) {
-                return;
-            }
-            super.setPressed(pressed);
-        }
-    }
-
-    static class TabAdapter extends BaseAdapter implements OnClickListener {
-
-        LayoutInflater mInflater;
-        OnCloseTab mCloseListener;
-        TabControl mTabControl;
-
-        TabAdapter(Context context, TabControl tabs) {
-            mInflater = LayoutInflater.from(context);
-            mTabControl = tabs;
-        }
-
-        void setOnCloseListener(OnCloseTab listener) {
-            mCloseListener = listener;
-        }
-
-        @Override
-        public View getView(int position, View view, ViewGroup parent) {
-            if (view == null) {
-                view = mInflater.inflate(R.layout.tab_view, parent, false);
-            }
-            ImageView favicon = (ImageView) view.findViewById(R.id.favicon);
-            ImageView thumbnail = (ImageView) view.findViewById(R.id.thumb);
-            TextView title = (TextView) view.findViewById(R.id.label);
-            Tab tab = getItem(position);
-
-            String label = tab.getTitle();
-            if (TextUtils.isEmpty(label)) {
-                label = tab.getUrl();
-            }
-            title.setText(label);
-            Bitmap thumbnailBitmap = tab.getScreenshot();
-            if (thumbnailBitmap == null) {
-                thumbnail.setImageResource(R.drawable.browser_thumbnail);
-            } else {
-                thumbnail.setImageBitmap(thumbnailBitmap);
-            }
-            Bitmap faviconBitmap = tab.getFavicon();
-            if (tab.isPrivateBrowsingEnabled()) {
-                favicon.setImageResource(R.drawable.ic_incognito_holo_dark);
-            } else {
-                if (faviconBitmap == null) {
-                    favicon.setImageResource(R.drawable.app_web_browser_sm);
-                } else {
-                    favicon.setImageBitmap(faviconBitmap);
-                }
-            }
-            View close = view.findViewById(R.id.close);
-            close.setTag(position);
-            close.setOnClickListener(this);
-            return view;
-        }
-
-        @Override
-        public void onClick(View v) {
-            int position = (Integer) v.getTag();
-            if (mCloseListener != null) {
-                mCloseListener.onCloseTab(position);
-            }
-        }
-
-        @Override
-        public int getCount() {
-            return mTabControl.getTabCount();
-        }
-
-        @Override
-        public Tab getItem(int position) {
-            return mTabControl.getTab(position);
-        }
-
-        @Override
-        public long getItemId(int position) {
-            return position;
-        }
-    }
-}
diff --git a/src/com/android/browser/BrowserWebView.java b/src/com/android/browser/BrowserWebView.java
index cd29135..8ea1123 100644
--- a/src/com/android/browser/BrowserWebView.java
+++ b/src/com/android/browser/BrowserWebView.java
@@ -17,14 +17,10 @@
 package com.android.browser;
 
 import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
 import android.util.AttributeSet;
 import android.view.View;
 import android.webkit.WebView;
 
-import com.android.browser.NavTabView.WebProxyView;
-
 import java.util.Map;
 
 /**
@@ -34,9 +30,6 @@
 
     private boolean mBackgroundRemoved = false;
     private TitleBar mTitleBar;
-    private int mCaptureSize;
-    private Bitmap mCapture;
-    private WebProxyView mProxyView;
 
     /**
      * @param context
@@ -57,7 +50,6 @@
     public BrowserWebView(
             Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
         super(context, attrs, defStyle, privateBrowsing);
-        init();
     }
 
     /**
@@ -66,7 +58,6 @@
      */
     public BrowserWebView(Context context, AttributeSet attrs) {
         super(context, attrs);
-        init();
     }
 
     /**
@@ -74,25 +65,6 @@
      */
     public BrowserWebView(Context context) {
         super(context);
-        init();
-    }
-
-    private void init() {
-        mCaptureSize = mContext.getResources().getDimensionPixelSize(R.dimen.tab_capture_size);
-        mCapture = Bitmap.createBitmap(mCaptureSize, mCaptureSize,
-                Bitmap.Config.RGB_565);
-    }
-
-    protected void setProxyView(WebProxyView p) {
-        mProxyView = p;
-    }
-
-    @Override
-    public void invalidate() {
-        super.invalidate();
-        if (mProxyView != null) {
-            mProxyView.invalidate();
-        }
     }
 
     @Override
@@ -114,18 +86,6 @@
         return (mTitleBar != null);
     }
 
-    protected Bitmap capture() {
-        if (mCapture == null) return null;
-        Canvas c = new Canvas(mCapture);
-        final int left = getScrollX();
-        final int top = getScrollY() + getVisibleTitleHeight();
-        c.translate(-left, -top);
-        float scale = mCaptureSize / (float) Math.max(getWidth(), getHeight());
-        c.scale(scale, scale, left, top);
-        onDraw(c);
-        return mCapture;
-    }
-
     @Override
     protected void onDraw(android.graphics.Canvas c) {
         super.onDraw(c);
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 116f0e0..bba49c2 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -1223,28 +1223,6 @@
         mUi.hideComboView();
     }
 
-    // active tabs page handling
-
-    protected void showActiveTabsPage() {
-        mMenuState = EMPTY_MENU;
-        mUi.showActiveTabsPage();
-    }
-
-    /**
-     * 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.
-     */
-    @Override
-    public void removeActiveTabsPage(boolean needToAttach) {
-        mMenuState = R.id.MAIN_MENU;
-        mUi.removeActiveTabsPage();
-        if (needToAttach) {
-            setActiveTab(mTabControl.getCurrentTab());
-        }
-        getCurrentTopWebView().requestFocus();
-    }
-
     // key handling
     protected void onBackKey() {
         if (!mUi.onBackKey()) {
@@ -1572,10 +1550,6 @@
                 bookmarksOrHistoryPicker(false);
                 break;
 
-            case R.id.active_tabs_menu_id:
-                showActiveTabsPage();
-                break;
-
             case R.id.add_bookmark_menu_id:
                 bookmarkCurrentPage(false);
                 break;
diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java
index 43a38e0..9486a19 100644
--- a/src/com/android/browser/NavScreen.java
+++ b/src/com/android/browser/NavScreen.java
@@ -28,7 +28,6 @@
 import android.webkit.WebView;
 import android.widget.BaseAdapter;
 import android.widget.FrameLayout;
-import android.widget.Gallery;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -58,9 +57,6 @@
     ImageButton mCloseTab;
 
     NavTabGallery mScroller;
-    float mTabAspect = 0.66f;
-    int mTabWidth;
-    int mTabHeight;
     TabAdapter mAdapter;
     int mOrientation;
 
@@ -200,25 +196,6 @@
         mUi.hideNavScreen(animate);
     }
 
-    class TabGallery extends Gallery {
-
-        public TabGallery(Context ctx) {
-            super(ctx);
-            setUnselectedAlpha(0.3f);
-        }
-
-       @Override
-       protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
-           return new Gallery.LayoutParams(mTabWidth, mTabHeight);
-       }
-
-       @Override
-       protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
-           return generateDefaultLayoutParams();
-       }
-
-    }
-
     class TabAdapter extends BaseAdapter {
 
         Context context;
@@ -247,7 +224,6 @@
         public View getView(final int position, View convertView, ViewGroup parent) {
             final NavTabView tabview = new NavTabView(mActivity);
             final Tab tab = getItem(position);
-            final BrowserWebView web = (BrowserWebView) tab.getWebView();
             tabview.setWebView(mUi, tab);
             tabview.setOnClickListener(new OnClickListener() {
                 @Override
diff --git a/src/com/android/browser/NavTabView.java b/src/com/android/browser/NavTabView.java
index 7b547b8..23ad2f1 100644
--- a/src/com/android/browser/NavTabView.java
+++ b/src/com/android/browser/NavTabView.java
@@ -17,16 +17,10 @@
 package com.android.browser;
 
 import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
+import android.graphics.Bitmap;
 import android.util.AttributeSet;
-import android.util.TypedValue;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -34,12 +28,10 @@
 public class NavTabView extends LinearLayout {
 
     private Tab mTab;
-    private BrowserWebView mWebView;
-    private WebProxyView mProxy;
     private ImageView mClose;
-    private FrameLayout mContainer;
     private TextView mTitle;
     private View mTitleBar;
+    private ImageView mImage;
     private OnClickListener mClickListener;
     private boolean mHighlighted;
 
@@ -60,10 +52,10 @@
 
     private void init() {
         LayoutInflater.from(mContext).inflate(R.layout.nav_tab_view, this);
-        mContainer = (FrameLayout) findViewById(R.id.tab_view);
         mClose = (ImageView) findViewById(R.id.closetab);
         mTitle = (TextView) findViewById(R.id.title);
         mTitleBar = findViewById(R.id.titlebar);
+        mImage = (ImageView) findViewById(R.id.tab_view);
     }
 
     protected boolean isClose(View v) {
@@ -75,7 +67,7 @@
     }
 
     protected boolean isWebView(View v) {
-        return v == mProxy;
+        return v == mImage;
     }
 
     protected void setHighlighted(boolean highlighted) {
@@ -103,12 +95,9 @@
     protected void setWebView(PhoneUi ui, Tab tab) {
         mTab = tab;
         setTitle();
-        BrowserWebView web = (BrowserWebView) tab.getWebView();
-        if (web != null) {
-            mWebView = web;
-            removeFromParent(mWebView);
-            mProxy = new WebProxyView(mContext, mWebView);
-            mContainer.addView(mProxy, 0);
+        Bitmap image = tab.getScreenshot();
+        if (image != null) {
+            mImage.setImageBitmap(image);
         }
     }
 
@@ -121,52 +110,9 @@
         mClickListener = listener;
         mTitleBar.setOnClickListener(mClickListener);
         mClose.setOnClickListener(mClickListener);
-        if (mProxy != null) {
-            mProxy.setOnClickListener(mClickListener);
+        if (mImage != null) {
+            mImage.setOnClickListener(mClickListener);
         }
     }
 
-    @Override
-    public void onDetachedFromWindow() {
-        if (mWebView != null) {
-            mWebView.setProxyView(null);
-        }
-    }
-
-    @Override
-    public void onAttachedToWindow() {
-        if (mWebView != null) {
-            mWebView.invalidate();
-        }
-    }
-
-    private static void removeFromParent(View v) {
-        if (v.getParent() != null) {
-            ((ViewGroup) v.getParent()).removeView(v);
-        }
-    }
-
-    static class WebProxyView extends View {
-
-        private BrowserWebView mWeb;
-
-        public WebProxyView(Context context, BrowserWebView web) {
-            super(context);
-            setWillNotDraw(false);
-            mWeb = web;
-            mWeb.setProxyView(this);
-
-        }
-
-        public void onDraw(Canvas c) {
-            float scale = 0.7f;
-            int sx = mWeb.getScrollX();
-            int sy = mWeb.getScrollY();
-            c.scale(scale, scale);
-            c.translate(-sx, -sy);
-            mWeb.onDraw(c);
-        }
-
-    }
-
 }
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index f32308d..f2d5da0 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -34,7 +34,6 @@
 
     private static final String LOGTAG = "PhoneUi";
 
-    private ActiveTabsPage mActiveTabsPage;
     private PieControlPhone mPieControl;
     private NavScreen mNavScreen;
     private NavigationBarPhone mNavigationBar;
@@ -60,20 +59,6 @@
         mActivity.getActionBar().hide();
     }
 
-    // lifecycle
-
-    @Override
-    public void onPause() {
-        // FIXME: This removes the active tabs page and resets the menu to
-        // MAIN_MENU.  A better solution might be to do this work in onNewIntent
-        // but then we would need to save it in onSaveInstanceState and restore
-        // it in onCreate/onRestoreInstanceState
-        if (mActiveTabsPage != null) {
-            mUiController.removeActiveTabsPage(true);
-        }
-        super.onPause();
-    }
-
     @Override
     public void onDestroy() {
         hideTitleBar();
@@ -89,11 +74,7 @@
 
     @Override
     public boolean onBackKey() {
-        if (mActiveTabsPage != null) {
-            // if tab page is showing, hide it
-            mUiController.removeActiveTabsPage(true);
-            return true;
-        } else if (mNavScreen != null) {
+        if (mNavScreen != null) {
             mNavScreen.close();
             return true;
         }
@@ -147,7 +128,6 @@
 
     @Override
     public void setActiveTab(final Tab tab) {
-        captureTab(mActiveTab);
         super.setActiveTab(tab);
         BrowserWebView view = (BrowserWebView) tab.getWebView();
         // TabControl.setCurrentTab has been called before this,
@@ -186,28 +166,6 @@
         }
     }
 
-    // active tabs page
-
-    @Override
-    public void showActiveTabsPage() {
-        captureTab(mActiveTab);
-        mActiveTabsPage = new ActiveTabsPage(mActivity, mUiController);
-        mTitleBar.setVisibility(View.GONE);
-        hideTitleBar();
-        mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS);
-        mActiveTabsPage.requestFocus();
-    }
-
-    /**
-     * Remove the active tabs page.
-     */
-    @Override
-    public void removeActiveTabsPage() {
-        mContentView.removeView(mActiveTabsPage);
-        mTitleBar.setVisibility(View.VISIBLE);
-        mActiveTabsPage = null;
-    }
-
     @Override
     public void showComboView(ComboViews startWith, Bundle extras) {
         if (mNavScreen != null) {
@@ -216,11 +174,6 @@
         super.showComboView(startWith, extras);
     }
 
-    @Override
-    public boolean showsWeb() {
-        return super.showsWeb() && mActiveTabsPage == null;
-    }
-
     // menu handling callbacks
 
     @Override
@@ -292,15 +245,6 @@
         }
     }
 
-    @Override
-    protected void captureTab(final Tab tab) {
-        if (tab == null) return;
-        BrowserWebView web = (BrowserWebView) tab.getWebView();
-        if (web != null) {
-            tab.setScreenshot(web.capture());
-        }
-    }
-
     void showNavScreen() {
         detachTab(mActiveTab);
         mNavScreen = new NavScreen(mActivity, mUiController, this);
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 62b574d..4558717 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -26,11 +26,14 @@
 import android.content.DialogInterface.OnCancelListener;
 import android.content.Intent;
 import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
 import android.graphics.Bitmap.CompressFormat;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Picture;
 import android.net.Uri;
 import android.net.http.SslError;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.Message;
 import android.os.SystemClock;
 import android.security.KeyChain;
@@ -57,6 +60,7 @@
 import android.webkit.WebResourceResponse;
 import android.webkit.WebStorage;
 import android.webkit.WebView;
+import android.webkit.WebView.PictureListener;
 import android.webkit.WebViewClient;
 import android.widget.CheckBox;
 import android.widget.LinearLayout;
@@ -79,7 +83,7 @@
 /**
  * Class for maintaining Tabs with a main WebView and a subwindow.
  */
-class Tab {
+class Tab implements PictureListener {
 
     // Log Tag
     private static final String LOGTAG = "Tab";
@@ -88,6 +92,9 @@
     // of the browser.
     private static final String CONSOLE_LOGTAG = "browser";
 
+    private static final int MSG_CAPTURE = 42;
+    private static final int CAPTURE_DELAY = 500;
+
     public enum LockIcon {
         LOCK_ICON_UNSECURE,
         LOCK_ICON_SECURE,
@@ -148,8 +155,12 @@
     // AsyncTask for downloading touch icons
     DownloadTouchIcon mTouchIconLoader;
 
-    private Bitmap mScreenshot;
     private BrowserSettings mSettings;
+    private int mCaptureWidth;
+    private int mCaptureHeight;
+    private Bitmap mCapture;
+    private Handler mHandler;
+
 
     // All the state needed for a page
     protected static class PageState {
@@ -1383,6 +1394,16 @@
         };
 
         setWebView(w);
+        mCaptureWidth = mContext.getResources().getDimensionPixelSize(R.dimen.nav_tab_width);
+        mCaptureHeight = mContext.getResources().getDimensionPixelSize(R.dimen.nav_tab_height);
+        mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
+                Bitmap.Config.RGB_565);
+        mHandler = new Handler() {
+            public void handleMessage(Message m) {
+                Tab.this.capture();
+            }
+        };
+
     }
 
     public void setController(WebViewController ctl) {
@@ -1426,6 +1447,7 @@
             // switched to another tab while waiting for the download to start.
             mMainView.setDownloadListener(mDownloadListener);
             mMainView.setWebBackForwardListClient(mWebBackForwardListClient);
+            mMainView.setPictureListener(this);
         }
     }
 
@@ -1780,9 +1802,9 @@
     }
 
     Bundle getSavedState(boolean saveImages) {
-        if (saveImages && mScreenshot != null) {
+        if (saveImages && mCapture != null) {
             Bundle b = new Bundle(mSavedState);
-            b.putParcelable(SCREENSHOT, mScreenshot);
+            b.putParcelable(SCREENSHOT, mCapture);
             return b;
         }
         return mSavedState;
@@ -1841,7 +1863,10 @@
         mSavedState = null;
         mId = b.getLong(ID);
         mAppId = b.getString(APPID);
-        mScreenshot = b.getParcelable(SCREENSHOT);
+        final Bitmap sshot = b.getParcelable(SCREENSHOT);
+        if (sshot != null) {
+            mCapture = sshot;
+        }
         if (b.getBoolean(USERAGENT)
                 != mSettings.hasDesktopUseragent(getWebView())) {
             mSettings.toggleDesktopUseragent(getWebView());
@@ -1870,11 +1895,11 @@
     };
 
     public void setScreenshot(Bitmap screenshot) {
-        mScreenshot = screenshot;
+        mCapture = screenshot;
     }
 
     public Bitmap getScreenshot() {
-        return mScreenshot;
+        return mCapture;
     }
 
     public boolean isSnapshot() {
@@ -1927,4 +1952,23 @@
         }
     }
 
+    protected void capture() {
+        if (mMainView == null || mCapture == null) return;
+        Canvas c = new Canvas(mCapture);
+        final int left = mMainView.getScrollX();
+        final int top = mMainView.getScrollY() + mMainView.getVisibleTitleHeight();
+        c.translate(-left, -top);
+        float scale = mCaptureWidth / (float) mMainView.getWidth();
+        c.scale(scale, scale, left, top);
+        mMainView.draw(c);
+    }
+
+    @Override
+    public void onNewPicture(WebView view, Picture picture) {
+        //update screenshot
+        if (!mHandler.hasMessages(MSG_CAPTURE)) {
+            mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
+        }
+    }
+
 }
diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java
index 6045d86..58fdb93 100644
--- a/src/com/android/browser/UiController.java
+++ b/src/com/android/browser/UiController.java
@@ -69,8 +69,6 @@
 
     void editUrl();
 
-    void removeActiveTabsPage(boolean attach);
-
     void handleNewIntent(Intent intent);
 
     boolean shouldShowErrorConsole();
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index a868331..73375e0 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -167,11 +167,6 @@
     public void setActiveTab(final Tab tab) {
         mTitleBar.cancelTitleBarAnimation(true);
         mTitleBar.setSkipTitleBarAnimations(true);
-        if (mUseQuickControls) {
-            if (mActiveTab != null) {
-                captureTab(mActiveTab);
-            }
-        }
         super.setActiveTab(tab);
         BrowserWebView view = (BrowserWebView) tab.getWebView();
         // TabControl.setCurrentTab has been called before this,
diff --git a/src/com/android/browser/view/Gallery.java b/src/com/android/browser/view/Gallery.java
index fa3f97a..5ab78b4 100644
--- a/src/com/android/browser/view/Gallery.java
+++ b/src/com/android/browser/view/Gallery.java
@@ -261,9 +261,7 @@
 
     @Override
     protected boolean getChildStaticTransformation(View child, Transformation t) {
-        t.clear();
-        t.setAlpha(child == mSelectedChild ? 1.0f : mUnselectedAlpha);
-        return true;
+        return false;
     }
 
     @Override
@@ -393,8 +391,6 @@
             // Similarly, empty space on the left
             fillToGalleryLeft();
         }
-        // Clear unused views
-        mRecycler.clear();
         setSelectionToCenterChild();
         invalidate();
     }