OSDN Git Service

Do not merge
authorPatrick Scott <phanna@android.com>
Tue, 21 Jul 2009 19:09:50 +0000 (15:09 -0400)
committerPatrick Scott <phanna@android.com>
Tue, 21 Jul 2009 19:11:26 +0000 (15:11 -0400)
When opening a new tab from the context menu, treat the new tab as a child of
the current tab. This change was cherry-picked from master.

src/com/android/browser/BrowserActivity.java

index 1a91462..b444d0f 100644 (file)
@@ -1985,9 +1985,9 @@ public class BrowserActivity extends Activity
 
     // A wrapper function of {@link #openTabAndShow(UrlData, Message, boolean, String)}
     // that accepts url as string.
-    private void openTabAndShow(String url, final Message msg,
+    private TabControl.Tab openTabAndShow(String url, final Message msg,
             boolean closeOnExit, String appId) {
-        openTabAndShow(new UrlData(url), msg, closeOnExit, appId);
+        return openTabAndShow(new UrlData(url), msg, closeOnExit, appId);
     }
 
     // This method does a ton of stuff. It will attempt to create a new tab
@@ -1998,7 +1998,7 @@ public class BrowserActivity extends Activity
     // the given Message. If the tab overview is already showing (i.e. this
     // method is called from TabListener.onClick(), the method will animate
     // away from the tab overview.
-    private void openTabAndShow(UrlData urlData, final Message msg,
+    private TabControl.Tab openTabAndShow(UrlData urlData, final Message msg,
             boolean closeOnExit, String appId) {
         final boolean newTab = mTabControl.getTabCount() != TabControl.MAX_TABS;
         final TabControl.Tab currentTab = mTabControl.getCurrentTab();
@@ -2027,9 +2027,10 @@ public class BrowserActivity extends Activity
                 }
                 // Animate from the Tab overview after any animations have
                 // finished.
-                sendAnimateFromOverview(
-                        mTabControl.createNewTab(closeOnExit, appId, urlData.mUrl), true,
-                        urlData, delay, msg);
+                final TabControl.Tab tab = mTabControl.createNewTab(
+                        closeOnExit, appId, urlData.mUrl);
+                sendAnimateFromOverview(tab, true, urlData, delay, msg);
+                return tab;
             }
         } else if (!urlData.isEmpty()) {
             // We should not have a msg here.
@@ -2044,6 +2045,7 @@ public class BrowserActivity extends Activity
                 urlData.loadIn(currentTab.getWebView());
             }
         }
+        return currentTab;
     }
 
     private Animation createTabAnimation(final AnimatingView view,
@@ -2265,14 +2267,15 @@ public class BrowserActivity extends Activity
         mTabListener = null;
     }
 
-    private void openTab(String url) {
+    private TabControl.Tab openTab(String url) {
         if (mSettings.openInBackground()) {
             TabControl.Tab t = mTabControl.createNewTab();
             if (t != null) {
                 t.getWebView().loadUrl(url);
             }
+            return t;
         } else {
-            openTabAndShow(url, null, false, null);
+            return openTabAndShow(url, null, false, null);
         }
     }
 
@@ -2711,7 +2714,12 @@ public class BrowserActivity extends Activity
                             loadURL(getTopWindow(), url);
                             break;
                         case R.id.open_newtab_context_menu_id:
-                            openTab(url);
+                            final TabControl.Tab parent = mTabControl
+                                    .getCurrentTab();
+                            final TabControl.Tab newTab = openTab(url);
+                            if (newTab != parent) {
+                                parent.addChildTab(newTab);
+                            }
                             break;
                         case R.id.bookmark_context_menu_id:
                             Intent intent = new Intent(BrowserActivity.this,
@@ -3396,8 +3404,11 @@ public class BrowserActivity extends Activity
                 // openTabAndShow will dispatch the message after creating the
                 // new WebView. This will prevent another request from coming
                 // in during the animation.
-                openTabAndShow(EMPTY_URL_DATA, msg, false, null);
-                parent.addChildTab(mTabControl.getCurrentTab());
+                final TabControl.Tab newTab =
+                        openTabAndShow(EMPTY_URL_DATA, msg, false, null);
+                if (newTab != parent) {
+                    parent.addChildTab(newTab);
+                }
                 WebView.WebViewTransport transport =
                         (WebView.WebViewTransport) msg.obj;
                 transport.setWebView(mTabControl.getCurrentWebView());