diff options
| author | Patrick Scott <phanna@android.com> | 2009-09-17 08:00:31 -0400 |
|---|---|---|
| committer | Patrick Scott <phanna@android.com> | 2009-09-17 09:56:23 -0400 |
| commit | d0119535d0c490e087be114ae8fd1639bb1945dc (patch) | |
| tree | c305c7928c6f751992427868d4f9f03683091ebc /src/com/android/browser/TabControl.java | |
| parent | eb6ab2aeeccb5ddfba7faefd9c1b5fe14ee8d885 (diff) | |
Remove the WebView from its container to change focus.
When the container is removed from the content view, its child views do not lose
focus. Removing the WebView from the container as well will trigger a focus
change from the WebView. Move the attach/remove logic to TabControl since it
knows all about the containers.
Diffstat (limited to 'src/com/android/browser/TabControl.java')
| -rw-r--r-- | src/com/android/browser/TabControl.java | 97 |
1 files changed, 66 insertions, 31 deletions
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index 4089cac8..6e4bae2e 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -224,10 +224,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 +236,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 +246,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 +331,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 +346,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. * @@ -612,9 +644,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 +707,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(); @@ -845,8 +879,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(); } /** |
