From 8383c8fbdd51ce81a030f783625229cecf08ce89 Mon Sep 17 00:00:00 2001 From: "divya.bansal" Date: Wed, 12 Nov 2014 04:03:56 -0800 Subject: [PATCH] Adding option for adding new tab in tab manager for chrome shell. Currently in order to open a new tab, option from menu is used. These changes add new tab button in tabswitcher mode in place of reload/stop button. In this mode reload/stop button is not required. Signed-off-by: divyabansal BUG=428660 Review URL: https://codereview.chromium.org/683203006 Cr-Commit-Position: refs/heads/master@{#303820} --- .../chrome/shell/ChromeShellTabModelSelector.java | 56 +++------------------- .../chromium/chrome/shell/ChromeShellToolbar.java | 21 ++++++++ .../src/org/chromium/chrome/shell/TabManager.java | 54 +++++++++++++++++---- .../shell/res/layout/chrome_shell_activity.xml | 7 +++ 4 files changed, 80 insertions(+), 58 deletions(-) diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellTabModelSelector.java b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellTabModelSelector.java index 3d54c086b832..28e3532c9941 100644 --- a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellTabModelSelector.java +++ b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellTabModelSelector.java @@ -4,9 +4,7 @@ package org.chromium.chrome.shell; -import android.view.LayoutInflater; -import android.view.ViewGroup; -import android.view.ViewParent; +import android.content.Context; import org.chromium.chrome.browser.Tab; import org.chromium.chrome.browser.tabmodel.EmptyTabModel; @@ -16,7 +14,6 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabModelDelegate; import org.chromium.chrome.browser.tabmodel.TabModelOrderController; import org.chromium.chrome.browser.tabmodel.TabModelSelectorBase; -import org.chromium.chrome.browser.widget.accessibility.AccessibilityTabModelWrapper; import org.chromium.content.browser.ContentVideoViewClient; import org.chromium.content.browser.ContentViewClient; import org.chromium.content_public.browser.LoadUrlParams; @@ -30,18 +27,17 @@ class ChromeShellTabModelSelector extends TabModelSelectorBase { private final WindowAndroid mWindow; private final ContentVideoViewClient mContentVideoViewClient; - private final ViewGroup mParent; + private final Context mContext; private final TabModelOrderController mOrderController; - private AccessibilityTabModelWrapper mTabModelWrapper; private TabManager mTabManager; public ChromeShellTabModelSelector( - WindowAndroid window, ContentVideoViewClient videoViewClient, ViewGroup parent, + WindowAndroid window, ContentVideoViewClient videoViewClient, Context context, TabManager tabManager) { mWindow = window; mContentVideoViewClient = videoViewClient; - mParent = parent; + mContext = context; mOrderController = new TabModelOrderController(this); mTabManager = tabManager; @@ -68,7 +64,7 @@ class ChromeShellTabModelSelector extends TabModelSelectorBase { @Override public boolean isInOverviewMode() { - return isTabSwitcherVisible(); + return mTabManager.isTabSwitcherVisible(); } @Override @@ -96,7 +92,7 @@ class ChromeShellTabModelSelector extends TabModelSelectorBase { } }; ChromeShellTab tab = new ChromeShellTab( - mParent.getContext(), loadUrlParams.getUrl(), mWindow, client, mTabManager); + mContext, loadUrlParams.getUrl(), mWindow, client, mTabManager); int index = mOrderController.determineInsertionIndex(type, tab); TabModel tabModel = getCurrentModel(); tabModel.addTab(tab, index, type); @@ -104,44 +100,4 @@ class ChromeShellTabModelSelector extends TabModelSelectorBase { return tab; } - /** - * Toggles the tab switcher visibility. - */ - public void toggleTabSwitcher() { - if (!isTabSwitcherVisible()) { - showTabSwitcher(); - } else { - hideTabSwitcher(); - } - } - - /* - * Hide the tab switcher. - */ - public void hideTabSwitcher() { - if (mTabModelWrapper == null) return; - ViewParent parent = mTabModelWrapper.getParent(); - if (parent != null) { - assert parent == mParent; - mParent.removeView(mTabModelWrapper); - } - } - - private void showTabSwitcher() { - if (mTabModelWrapper == null) { - mTabModelWrapper = (AccessibilityTabModelWrapper) LayoutInflater.from( - mParent.getContext()).inflate(R.layout.accessibility_tab_switcher, null); - mTabModelWrapper.setup(null); - mTabModelWrapper.setTabModelSelector(this); - } - - if (mTabModelWrapper.getParent() == null) { - mParent.addView(mTabModelWrapper); - } - } - - public boolean isTabSwitcherVisible() { - return mTabModelWrapper != null && mTabModelWrapper.getParent() == mParent; - } - } diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellToolbar.java b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellToolbar.java index 4e0eefd4949e..74619f9173f9 100644 --- a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellToolbar.java +++ b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellToolbar.java @@ -73,6 +73,7 @@ public class ChromeShellToolbar extends LinearLayout { private SuggestionPopup mSuggestionPopup; private ImageButton mStopReloadButton; + private ImageButton mAddButton; private int mProgress = 0; private boolean mLoading = true; @@ -144,6 +145,7 @@ public class ChromeShellToolbar extends LinearLayout { initializeTabSwitcherButton(); initializeMenuButton(); initializeStopReloadButton(); + initializeAddButton(); } void setMenuHandler(AppMenuHandler menuHandler) { @@ -247,6 +249,25 @@ public class ChromeShellToolbar extends LinearLayout { }); } + private void initializeAddButton() { + mAddButton = (ImageButton) findViewById(R.id.add_button); + mAddButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mTabManager.createNewTab(); + } + }); + } + + /** + * Shows or hides the add and the stop/reload button . + * @param visibility The visibility status of the add button. + */ + public void showAddButton(boolean visibility) { + mAddButton.setVisibility(visibility ? VISIBLE : GONE); + mStopReloadButton.setVisibility(visibility ? GONE : VISIBLE); + } + /** * @return Current tab that is shown by ChromeShell. */ diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/TabManager.java b/chrome/android/shell/java/src/org/chromium/chrome/shell/TabManager.java index 183d6770c60e..fa25a1a4b96c 100644 --- a/chrome/android/shell/java/src/org/chromium/chrome/shell/TabManager.java +++ b/chrome/android/shell/java/src/org/chromium/chrome/shell/TabManager.java @@ -6,8 +6,10 @@ package org.chromium.chrome.shell; import android.content.Context; import android.util.AttributeSet; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -16,6 +18,7 @@ import org.chromium.chrome.browser.Tab; import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; +import org.chromium.chrome.browser.widget.accessibility.AccessibilityTabModelWrapper; import org.chromium.content.browser.ContentVideoViewClient; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewRenderView; @@ -40,13 +43,14 @@ public class TabManager extends LinearLayout { private String mStartupUrl = DEFAULT_URL; private ChromeShellTabModelSelector mTabModelSelector; + private AccessibilityTabModelWrapper mTabModelWrapper; private final EmptyTabModelObserver mTabModelObserver = new EmptyTabModelObserver() { @Override public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { assert tab instanceof ChromeShellTab; setCurrentTab((ChromeShellTab) tab); - mTabModelSelector.hideTabSwitcher(); + hideTabSwitcher(); } @Override @@ -75,7 +79,7 @@ public class TabManager extends LinearLayout { mContentViewHolder = (ViewGroup) findViewById(R.id.content_container); mTabModelSelector = new ChromeShellTabModelSelector( - window, videoViewClient, mContentViewHolder, this); + window, videoViewClient, mContentViewHolder.getContext(), this); mTabModelSelector.getModel(false).addObserver(mTabModelObserver); mToolbar = (ChromeShellToolbar) findViewById(R.id.toolbar); @@ -184,18 +188,52 @@ public class TabManager extends LinearLayout { } /** - * Toggles the tab switcher visibility. + * Hide the tab switcher. */ - public void toggleTabSwitcher() { - mTabModelSelector.toggleTabSwitcher(); + public void hideTabSwitcher() { + if (mTabModelWrapper == null) return; + ViewParent parent = mTabModelWrapper.getParent(); + if (parent != null) { + assert parent == mContentViewHolder; + mContentViewHolder.removeView(mTabModelWrapper); + } + mToolbar.showAddButton(false); } + /** + * Shows the tab switcher. + */ + private void showTabSwitcher() { + if (mTabModelWrapper == null) { + mTabModelWrapper = (AccessibilityTabModelWrapper) LayoutInflater.from( + mContentViewHolder.getContext()).inflate( + R.layout.accessibility_tab_switcher, null); + mTabModelWrapper.setup(null); + mTabModelWrapper.setTabModelSelector(mTabModelSelector); + } + + if (mTabModelWrapper.getParent() == null) { + mContentViewHolder.addView(mTabModelWrapper); + } + mToolbar.showAddButton(true); + } + + /** + * Returns the visibility status of the tab switcher. + */ public boolean isTabSwitcherVisible() { - return mTabModelSelector.isTabSwitcherVisible(); + return mTabModelWrapper != null && mTabModelWrapper.getParent() == mContentViewHolder; } - public void hideTabSwitcher() { - mTabModelSelector.hideTabSwitcher(); + /** + * Toggles the tab switcher visibility. + */ + public void toggleTabSwitcher() { + if (!isTabSwitcherVisible()) { + showTabSwitcher(); + } else { + hideTabSwitcher(); + } } /** diff --git a/chrome/android/shell/res/layout/chrome_shell_activity.xml b/chrome/android/shell/res/layout/chrome_shell_activity.xml index d457ca20efdd..ab9c94fd8de1 100644 --- a/chrome/android/shell/res/layout/chrome_shell_activity.xml +++ b/chrome/android/shell/res/layout/chrome_shell_activity.xml @@ -17,6 +17,13 @@ android:orientation="horizontal" android:background="@drawable/progress"> +