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;
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;
// 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);
/**
* 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) {
// 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);
}
}
}
/**
- * @return The container for this tab.
- */
- public View getContainer() {
- return mContainer;
- }
-
- /**
* @return The geolocation permissions prompt for this tab.
*/
public GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
}
/**
- * 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.
*
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) {
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;
}
// 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();
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();
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";
// 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();
}
/**
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);
// 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;
}
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.
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;
}
if (item != null) {
data.mUrl = item.getUrl();
data.mTitle = item.getTitle();
+ data.mFavicon = item.getFavicon();
if (data.mTitle == null) {
data.mTitle = data.mUrl;
}
// 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;
}
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);
- }
- }
}
}
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);