OSDN Git Service

disable mr stretchy, but leave the support code around for now
[android-x86/packages-apps-Browser.git] / src / com / android / browser / TabControl.java
index 4089cac..c03fdf4 100644 (file)
 package com.android.browser;
 
 import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
+import android.graphics.Paint;
 import android.graphics.Picture;
+import android.graphics.Shader;
 import android.net.http.SslError;
 import android.os.Bundle;
 import android.os.Message;
@@ -159,20 +164,16 @@ class TabControl {
     public static class PickerData {
         String  mUrl;
         String  mTitle;
+        Bitmap  mFavicon;
         float   mScale;
         int     mScrollX;
         int     mScrollY;
-        int     mWidth;
-        Picture mPicture;
-        // This can be null. When a new picture comes in, this view should be
-        // invalidated to show the new picture.
-        FakeWebView mFakeWebView;
     }
 
     /**
      * Private class for maintaining Tabs with a main WebView and a subwindow.
      */
-    public class Tab implements WebView.PictureListener {
+    public class Tab {
         // The Geolocation permissions prompt
         private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
         private View mContainer;
@@ -224,10 +225,6 @@ class TabControl {
 
             // The tab consists of a container view, which contains the main
             // WebView, as well as any other UI elements associated with the tab.
-            //
-            // FIXME: Fix the interaction between this layout and the animation
-            // used when switching to and from the tab picker. This may not be
-            // required if the tab selection UI is redesigned.
             LayoutInflater factory = LayoutInflater.from(context);
             mContainer = factory.inflate(R.layout.tab, null);
 
@@ -240,7 +237,7 @@ class TabControl {
 
         /**
          * Sets the WebView for this tab, correctly removing the old WebView
-         * from, and inserting the new WebView into, the container view.
+         * from the container view.
          */
         public void setWebView(WebView w) {
             if (mMainView == w) {
@@ -250,13 +247,65 @@ class TabControl {
             // permission requests are void.
             mGeolocationPermissionsPrompt.hide();
 
-            FrameLayout wrapper = (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
-            if (mMainView != null) {
-                wrapper.removeView(mMainView);
-            }
+            // Just remove the old one.
+            FrameLayout wrapper =
+                    (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
+            wrapper.removeView(mMainView);
             mMainView = w;
-            if (mMainView != null) {
-                wrapper.addView(mMainView);
+        }
+
+        /**
+         * This method attaches both the WebView and any sub window to the
+         * given content view.
+         */
+        public void attachTabToContentView(ViewGroup content) {
+            if (mMainView == null) {
+                return;
+            }
+
+            // Attach the WebView to the container and then attach the
+            // container to the content view.
+            FrameLayout wrapper =
+                    (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
+            wrapper.addView(mMainView);
+            content.addView(mContainer, BrowserActivity.COVER_SCREEN_PARAMS);
+            attachSubWindow(content);
+        }
+
+        /**
+         * Remove the WebView and any sub window from the given content view.
+         */
+        public void removeTabFromContentView(ViewGroup content) {
+            if (mMainView == null) {
+                return;
+            }
+
+            // Remove the container from the content and then remove the
+            // WebView from the container. This will trigger a focus change
+            // needed by WebView.
+            FrameLayout wrapper =
+                    (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
+            wrapper.removeView(mMainView);
+            content.removeView(mContainer);
+            removeSubWindow(content);
+        }
+
+        /**
+         * Attach the sub window to the content view.
+         */
+        public void attachSubWindow(ViewGroup content) {
+            if (mSubView != null) {
+                content.addView(mSubViewContainer,
+                        BrowserActivity.COVER_SCREEN_PARAMS);
+            }
+        }
+
+        /**
+         * Remove the sub window from the content view.
+         */
+        public void removeSubWindow(ViewGroup content) {
+            if (mSubView != null) {
+                content.removeView(mSubViewContainer);
             }
         }
 
@@ -283,13 +332,6 @@ class TabControl {
         }
 
         /**
-         * @return The container for this tab.
-         */
-        public View getContainer() {
-            return mContainer;
-        }
-
-        /**
          * @return The geolocation permissions prompt for this tab.
          */
         public GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
@@ -305,15 +347,6 @@ class TabControl {
         }
 
         /**
-         * Return the subwindow container of this tab or null if there is no
-         * subwindow.
-         * @return The subwindow's container View.
-         */
-        public View getSubWebViewContainer() {
-            return mSubViewContainer;
-        }
-
-        /**
          * Get the url of this tab.  Valid after calling populatePickerData, but
          * before calling wipePickerData, or if the webview has been destroyed.
          * 
@@ -340,11 +373,11 @@ class TabControl {
             return null;
         }
 
-        /**
-         * Returns the picker data.
-         */
-        public PickerData getPickerData() {
-            return mPickerData;
+        public Bitmap getFavicon() {
+            if (mPickerData != null) {
+                return mPickerData.mFavicon;
+            }
+            return null;
         }
 
         private void setParentTab(Tab parent) {
@@ -407,18 +440,6 @@ class TabControl {
             return mCloseOnExit;
         }
 
-        public void onNewPicture(WebView view, Picture p) {
-            if (mPickerData == null) {
-                return;
-            }
-
-            mPickerData.mPicture = p;
-            // Tell the FakeWebView to redraw.
-            if (mPickerData.mFakeWebView != null) {
-                mPickerData.mFakeWebView.invalidate();
-            }
-        }
-
         void setLockIconType(int type) {
             mSavedLockIconType = type;
         }
@@ -612,9 +633,10 @@ class TabControl {
             // observers.
             BrowserSettings.getInstance().deleteObserver(
                     t.mMainView.getSettings());
-            // Destroy the main view and subview
-            t.mMainView.destroy();
+            WebView w = t.mMainView;
             t.setWebView(null);
+            // Destroy the main view
+            w.destroy();
         }
         // clear it's references to parent and children
         t.removeFromTree();
@@ -674,8 +696,9 @@ class TabControl {
             if (t.mMainView != null) {
                 dismissSubWindow(t);
                 s.deleteObserver(t.mMainView.getSettings());
-                t.mMainView.destroy();
+                WebView w = t.mMainView;
                 t.setWebView(null);
+                w.destroy();
             }
         }
         mTabs.clear();
@@ -696,7 +719,6 @@ class TabControl {
     private static final String CURRTAB = "currentTab";
     private static final String CURRURL = "currentUrl";
     private static final String CURRTITLE = "currentTitle";
-    private static final String CURRWIDTH = "currentWidth";
     private static final String CURRPICTURE = "currentPicture";
     private static final String CLOSEONEXIT = "closeonexit";
     private static final String PARENTTAB = "parentTab";
@@ -845,8 +867,9 @@ class TabControl {
         // Remove the WebView's settings from the BrowserSettings list of
         // observers.
         BrowserSettings.getInstance().deleteObserver(t.mMainView.getSettings());
-        t.mMainView.destroy();
+        WebView w = t.mMainView;
         t.setWebView(null);
+        w.destroy();
     }
 
     /**
@@ -1003,6 +1026,8 @@ class TabControl {
     private WebView createNewWebView() {
         // Create a new WebView
         WebView w = new WebView(mActivity);
+        w.setScrollbarFadingEnabled(true);
+        w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
         w.setMapTrackballToArrowKeys(false); // use trackball directly
         // Enable the built-in zoom
         w.getSettings().setBuiltInZoomControls(true);
@@ -1010,6 +1035,18 @@ class TabControl {
         // settings
         final BrowserSettings s = BrowserSettings.getInstance();
         s.addObserver(w.getSettings()).update(s, null);
+
+        // pick a default
+        if (false) {
+            MeshTracker mt = new MeshTracker(2);
+            Paint paint = new Paint();
+            Bitmap bm = BitmapFactory.decodeResource(mActivity.getResources(),
+                                         R.drawable.pattern_carbon_fiber_dark);
+            paint.setShader(new BitmapShader(bm, Shader.TileMode.REPEAT,
+                                             Shader.TileMode.REPEAT));
+            mt.setBGPaint(paint);
+            w.setDragTracker(mt);
+        }
         return w;
     }
 
@@ -1159,15 +1196,6 @@ class TabControl {
         final WebHistoryItem item =
                 list != null ? list.getCurrentItem() : null;
         populatePickerData(t, item);
-
-        // This method is only called during the tab picker creation. At this
-        // point we need to listen for new pictures since the WebView is still
-        // active.
-        final WebView w = t.getTopWindow();
-        w.setPictureListener(t);
-        // Capture the picture here instead of populatePickerData since it can
-        // be called when saving the state of a tab.
-        t.mPickerData.mPicture = w.capturePicture();
     }
 
     // Create the PickerData and populate it using the saved state of the tab.
@@ -1180,25 +1208,12 @@ class TabControl {
         final Bundle state = t.mSavedState;
         data.mUrl = state.getString(CURRURL);
         data.mTitle = state.getString(CURRTITLE);
-        data.mWidth = state.getInt(CURRWIDTH, 0);
         // XXX: These keys are from WebView.savePicture so if they change, this
         // will break.
         data.mScale = state.getFloat("scale", 1.0f);
         data.mScrollX = state.getInt("scrollX", 0);
         data.mScrollY = state.getInt("scrollY", 0);
 
-        if (state.containsKey(CURRPICTURE)) {
-            final File f = new File(t.mSavedState.getString(CURRPICTURE));
-            try {
-                final FileInputStream in = new FileInputStream(f);
-                data.mPicture = Picture.createFromStream(in);
-                in.close();
-            } catch (Exception ex) {
-                // Ignore any problems with inflating the picture. We just
-                // won't draw anything.
-            }
-        }
-
         // Set the tab's picker data.
         t.mPickerData = data;
     }
@@ -1210,6 +1225,7 @@ class TabControl {
         if (item != null) {
             data.mUrl = item.getUrl();
             data.mTitle = item.getTitle();
+            data.mFavicon = item.getFavicon();
             if (data.mTitle == null) {
                 data.mTitle = data.mUrl;
             }
@@ -1217,15 +1233,10 @@ class TabControl {
         // We want to display the top window in the tab picker but use the url
         // and title of the main window.
         final WebView w = t.getTopWindow();
-        data.mWidth = w.getWidth();
         data.mScale = w.getScale();
         data.mScrollX = w.getScrollX();
         data.mScrollY = w.getScrollY();
 
-        // Remember the old picture if possible.
-        if (t.mPickerData != null) {
-            data.mPicture = t.mPickerData.mPicture;
-        }
         t.mPickerData = data;
     }
     
@@ -1239,13 +1250,6 @@ class TabControl {
             if (t != null && t.mSavedState == null) {
                 t.mPickerData = null;
             }
-            if (t.mMainView != null) {
-                // Clear the picture listeners.
-                t.mMainView.setPictureListener(null);
-                if (t.mSubView != null) {
-                    t.mSubView.setPictureListener(null);
-                }
-            }
         }
     }
 
@@ -1284,7 +1288,6 @@ class TabControl {
             if (data.mTitle != null) {
                 b.putString(CURRTITLE, data.mTitle);
             }
-            b.putInt(CURRWIDTH, data.mWidth);
             b.putBoolean(CLOSEONEXIT, t.mCloseOnExit);
             if (t.mAppId != null) {
                 b.putString(APPID, t.mAppId);