private void attachTabToContentView(TabControl.Tab t) {
// Attach the container that contains the main WebView and any other UI
// associated with the tab.
- mContentView.addView(t.getContainer(), COVER_SCREEN_PARAMS);
+ t.attachTabToContentView(mContentView);
if (mShouldShowErrorConsole) {
ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(true);
WebView view = t.getWebView();
view.setEmbeddedTitleBar(mTitleBar);
- // Attach the sub window if necessary
- attachSubWindow(t);
// Request focus on the top window.
t.getTopWindow().requestFocus();
}
// Attach a sub window to the main WebView of the given tab.
private void attachSubWindow(TabControl.Tab t) {
- // If a sub window exists, attach it to the content view.
- final WebView subView = t.getSubWebView();
- if (subView != null) {
- final View container = t.getSubWebViewContainer();
- mContentView.addView(container, COVER_SCREEN_PARAMS);
- subView.requestFocus();
- }
+ t.attachSubWindow(mContentView);
+ getTopWindow().requestFocus();
}
// Remove the given tab from the content view.
private void removeTabFromContentView(TabControl.Tab t) {
// Remove the container that contains the main WebView.
- mContentView.removeView(t.getContainer());
+ t.removeTabFromContentView(mContentView);
if (mTabControl.getCurrentErrorConsole(false) != null) {
mErrorConsoleContainer.removeView(mTabControl.getCurrentErrorConsole(false));
view.setEmbeddedTitleBar(null);
}
- // Remove the sub window if it exists.
- if (t.getSubWebView() != null) {
- mContentView.removeView(t.getSubWebViewContainer());
- }
-
if (t == mTabControl.getCurrentTab()) {
t.setLockIconType(getLockIconType());
t.setPrevLockIconType(getPrevLockType());
// Remove the sub window if it exists. Also called by TabControl when the
// user clicks the 'X' to dismiss a sub window.
/* package */ void dismissSubWindow(TabControl.Tab t) {
- final WebView mainView = t.getWebView();
- if (t.getSubWebView() != null) {
- // Remove the container view and request focus on the main WebView.
- mContentView.removeView(t.getSubWebViewContainer());
- mainView.requestFocus();
- // Tell the TabControl to dismiss the subwindow. This will destroy
- // the WebView.
- mTabControl.dismissSubWindow(t);
- }
+ t.removeSubWindow(mContentView);
+ // Tell the TabControl to dismiss the subwindow. This will destroy
+ // the WebView.
+ mTabControl.dismissSubWindow(t);
+ getTopWindow().requestFocus();
}
// A wrapper function of {@link #openTabAndShow(UrlData, boolean, String)}
// 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.
*
// 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();
// 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();
}
/**