Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.shell; | 5 package org.chromium.chrome.shell; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.util.AttributeSet; | 8 import android.util.AttributeSet; |
| 9 import android.view.LayoutInflater; | |
| 9 import android.view.View; | 10 import android.view.View; |
| 10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 12 import android.view.ViewParent; | |
| 11 import android.widget.FrameLayout; | 13 import android.widget.FrameLayout; |
| 12 import android.widget.LinearLayout; | 14 import android.widget.LinearLayout; |
| 13 | 15 |
| 14 import org.chromium.chrome.browser.EmptyTabObserver; | 16 import org.chromium.chrome.browser.EmptyTabObserver; |
| 15 import org.chromium.chrome.browser.Tab; | 17 import org.chromium.chrome.browser.Tab; |
| 16 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; | 18 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| 17 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 19 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 18 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 20 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
| 21 import org.chromium.chrome.browser.widget.accessibility.AccessibilityTabModelWra pper; | |
| 19 import org.chromium.content.browser.ContentVideoViewClient; | 22 import org.chromium.content.browser.ContentVideoViewClient; |
| 20 import org.chromium.content.browser.ContentViewCore; | 23 import org.chromium.content.browser.ContentViewCore; |
| 21 import org.chromium.content.browser.ContentViewRenderView; | 24 import org.chromium.content.browser.ContentViewRenderView; |
| 22 import org.chromium.content_public.browser.LoadUrlParams; | 25 import org.chromium.content_public.browser.LoadUrlParams; |
| 23 import org.chromium.ui.base.PageTransition; | 26 import org.chromium.ui.base.PageTransition; |
| 24 import org.chromium.ui.base.WindowAndroid; | 27 import org.chromium.ui.base.WindowAndroid; |
| 25 | 28 |
| 26 /** | 29 /** |
| 27 * The TabManager hooks together all of the related {@link View}s that are used to represent | 30 * The TabManager hooks together all of the related {@link View}s that are used to represent |
| 28 * a {@link ChromeShellTab}. It properly builds a {@link ChromeShellTab} and ma kes sure that the | 31 * a {@link ChromeShellTab}. It properly builds a {@link ChromeShellTab} and ma kes sure that the |
| 29 * {@link ChromeShellToolbar} and {@link ContentViewRenderView} show the proper content. | 32 * {@link ChromeShellToolbar} and {@link ContentViewRenderView} show the proper content. |
| 30 */ | 33 */ |
| 31 public class TabManager extends LinearLayout { | 34 public class TabManager extends LinearLayout { |
| 32 private static final String DEFAULT_URL = "http://www.google.com"; | 35 private static final String DEFAULT_URL = "http://www.google.com"; |
| 33 | 36 |
| 34 private ViewGroup mContentViewHolder; | 37 private ViewGroup mContentViewHolder; |
| 35 private ContentViewRenderView mContentViewRenderView; | 38 private ContentViewRenderView mContentViewRenderView; |
| 36 private ChromeShellToolbar mToolbar; | 39 private ChromeShellToolbar mToolbar; |
| 37 | 40 |
| 38 private ChromeShellTab mCurrentTab; | 41 private ChromeShellTab mCurrentTab; |
| 39 | 42 |
| 40 private String mStartupUrl = DEFAULT_URL; | 43 private String mStartupUrl = DEFAULT_URL; |
| 41 | 44 |
| 42 private ChromeShellTabModelSelector mTabModelSelector; | 45 private ChromeShellTabModelSelector mTabModelSelector; |
| 46 private AccessibilityTabModelWrapper mTabModelWrapper; | |
| 43 | 47 |
| 44 private final EmptyTabModelObserver mTabModelObserver = new EmptyTabModelObs erver() { | 48 private final EmptyTabModelObserver mTabModelObserver = new EmptyTabModelObs erver() { |
| 45 @Override | 49 @Override |
| 46 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { | 50 public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { |
| 47 assert tab instanceof ChromeShellTab; | 51 assert tab instanceof ChromeShellTab; |
| 48 setCurrentTab((ChromeShellTab) tab); | 52 setCurrentTab((ChromeShellTab) tab); |
| 49 mTabModelSelector.hideTabSwitcher(); | 53 hideTabSwitcher(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 @Override | 56 @Override |
| 53 public void willCloseTab(Tab tab, boolean animate) { | 57 public void willCloseTab(Tab tab, boolean animate) { |
| 54 if (tab == mCurrentTab) setCurrentTab(null); | 58 if (tab == mCurrentTab) setCurrentTab(null); |
| 55 } | 59 } |
| 56 }; | 60 }; |
| 57 | 61 |
| 58 /** | 62 /** |
| 59 * @param context The Context the view is running in. | 63 * @param context The Context the view is running in. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 | 180 |
| 177 private void setupContent() { | 181 private void setupContent() { |
| 178 View view = mCurrentTab.getView(); | 182 View view = mCurrentTab.getView(); |
| 179 ContentViewCore contentViewCore = mCurrentTab.getContentViewCore(); | 183 ContentViewCore contentViewCore = mCurrentTab.getContentViewCore(); |
| 180 mContentViewHolder.addView(view); | 184 mContentViewHolder.addView(view); |
| 181 mContentViewRenderView.setCurrentContentViewCore(contentViewCore); | 185 mContentViewRenderView.setCurrentContentViewCore(contentViewCore); |
| 182 view.requestFocus(); | 186 view.requestFocus(); |
| 183 contentViewCore.onShow(); | 187 contentViewCore.onShow(); |
| 184 } | 188 } |
| 185 | 189 |
| 190 /* | |
|
Bernhard Bauer
2014/11/11 09:08:22
Add a second asterisk here to make this a Javadoc
divya.bansal
2014/11/11 09:29:51
Done.
| |
| 191 * Hide the tab switcher. | |
| 192 */ | |
| 193 public void hideTabSwitcher() { | |
| 194 if (mTabModelWrapper == null) return; | |
| 195 ViewParent parent = mTabModelWrapper.getParent(); | |
| 196 if (parent != null) { | |
| 197 assert parent == mContentViewHolder; | |
| 198 mContentViewHolder.removeView(mTabModelWrapper); | |
| 199 } | |
| 200 mToolbar.showAddButton(false); | |
| 201 } | |
| 202 | |
| 203 private void showTabSwitcher() { | |
| 204 if (mTabModelWrapper == null) { | |
| 205 mTabModelWrapper = (AccessibilityTabModelWrapper) LayoutInflater.fro m( | |
| 206 mContentViewHolder.getContext()).inflate( | |
| 207 R.layout.accessibility_tab_switcher, null); | |
| 208 mTabModelWrapper.setup(null); | |
| 209 mTabModelWrapper.setTabModelSelector(mTabModelSelector); | |
| 210 } | |
| 211 | |
| 212 if (mTabModelWrapper.getParent() == null) { | |
| 213 mContentViewHolder.addView(mTabModelWrapper); | |
| 214 } | |
| 215 mToolbar.showAddButton(true); | |
| 216 } | |
| 217 | |
| 218 public boolean isTabSwitcherVisible() { | |
|
Bernhard Bauer
2014/11/11 09:08:22
Please add a Javadoc comment.
divya.bansal
2014/11/11 09:29:51
Done.
| |
| 219 return mTabModelWrapper != null && mTabModelWrapper.getParent() == mCont entViewHolder; | |
| 220 } | |
| 221 | |
| 186 /** | 222 /** |
| 187 * Toggles the tab switcher visibility. | 223 * Toggles the tab switcher visibility. |
| 188 */ | 224 */ |
| 189 public void toggleTabSwitcher() { | 225 public void toggleTabSwitcher() { |
| 190 mTabModelSelector.toggleTabSwitcher(); | 226 if (!isTabSwitcherVisible()) { |
| 191 } | 227 showTabSwitcher(); |
| 192 | 228 } else { |
| 193 public boolean isTabSwitcherVisible() { | 229 hideTabSwitcher(); |
| 194 return mTabModelSelector.isTabSwitcherVisible(); | 230 } |
| 195 } | |
| 196 | |
| 197 public void hideTabSwitcher() { | |
| 198 mTabModelSelector.hideTabSwitcher(); | |
| 199 } | 231 } |
| 200 | 232 |
| 201 /** | 233 /** |
| 202 * Opens a URL in the current tab if one exists, or in a new tab otherwise. | 234 * Opens a URL in the current tab if one exists, or in a new tab otherwise. |
| 203 * @param url The URL to open. | 235 * @param url The URL to open. |
| 204 * @return The tab used to open the provided URL. | 236 * @return The tab used to open the provided URL. |
| 205 */ | 237 */ |
| 206 public Tab openUrl(String url) { | 238 public Tab openUrl(String url) { |
| 207 LoadUrlParams loadUrlParams = new LoadUrlParams(url); | 239 LoadUrlParams loadUrlParams = new LoadUrlParams(url); |
| 208 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR OM_ADDRESS_BAR); | 240 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR OM_ADDRESS_BAR); |
| 209 Tab tab = mTabModelSelector.getCurrentTab(); | 241 Tab tab = mTabModelSelector.getCurrentTab(); |
| 210 if (tab != null) { | 242 if (tab != null) { |
| 211 tab.loadUrl(loadUrlParams); | 243 tab.loadUrl(loadUrlParams); |
| 212 return tab; | 244 return tab; |
| 213 } | 245 } |
| 214 return createTab(url, TabLaunchType.FROM_KEYBOARD); | 246 return createTab(url, TabLaunchType.FROM_KEYBOARD); |
| 215 } | 247 } |
| 216 } | 248 } |
| OLD | NEW |