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. |
60 * @param attrs The attributes of the XML tag that is inflating the view. | 64 * @param attrs The attributes of the XML tag that is inflating the view. |
61 */ | 65 */ |
62 public TabManager(Context context, AttributeSet attrs) { | 66 public TabManager(Context context, AttributeSet attrs) { |
63 super(context, attrs); | 67 super(context, attrs); |
64 } | 68 } |
65 | 69 |
66 /** | 70 /** |
67 * Initialize the components required for Tab creation. | 71 * Initialize the components required for Tab creation. |
68 * @param window The window used to generate all ContentViews. | 72 * @param window The window used to generate all ContentViews. |
69 * @param videoViewClient The client to handle interactions from ContentVide
oViews. | 73 * @param videoViewClient The client to handle interactions from ContentVide
oViews. |
70 */ | 74 */ |
71 public void initialize(WindowAndroid window, ContentVideoViewClient videoVie
wClient) { | 75 public void initialize(WindowAndroid window, ContentVideoViewClient videoVie
wClient) { |
72 assert window != null; | 76 assert window != null; |
73 assert videoViewClient != null; | 77 assert videoViewClient != null; |
74 | 78 |
75 mContentViewHolder = (ViewGroup) findViewById(R.id.content_container); | 79 mContentViewHolder = (ViewGroup) findViewById(R.id.content_container); |
76 | 80 |
77 mTabModelSelector = new ChromeShellTabModelSelector( | 81 mTabModelSelector = new ChromeShellTabModelSelector( |
78 window, videoViewClient, mContentViewHolder, this); | 82 window, videoViewClient, mContentViewHolder.getContext(), this); |
79 mTabModelSelector.getModel(false).addObserver(mTabModelObserver); | 83 mTabModelSelector.getModel(false).addObserver(mTabModelObserver); |
80 | 84 |
81 mToolbar = (ChromeShellToolbar) findViewById(R.id.toolbar); | 85 mToolbar = (ChromeShellToolbar) findViewById(R.id.toolbar); |
82 mToolbar.setTabManager(this); | 86 mToolbar.setTabManager(this); |
83 mContentViewRenderView = new ContentViewRenderView(getContext()) { | 87 mContentViewRenderView = new ContentViewRenderView(getContext()) { |
84 @Override | 88 @Override |
85 protected void onReadyToRender() { | 89 protected void onReadyToRender() { |
86 if (mCurrentTab == null) createTab(mStartupUrl, TabLaunchType.FR
OM_RESTORE); | 90 if (mCurrentTab == null) createTab(mStartupUrl, TabLaunchType.FR
OM_RESTORE); |
87 } | 91 } |
88 }; | 92 }; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
186 /** | 190 /** |
| 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 /** |
| 204 * Shows the tab switcher. |
| 205 */ |
| 206 private void showTabSwitcher() { |
| 207 if (mTabModelWrapper == null) { |
| 208 mTabModelWrapper = (AccessibilityTabModelWrapper) LayoutInflater.fro
m( |
| 209 mContentViewHolder.getContext()).inflate( |
| 210 R.layout.accessibility_tab_switcher, null); |
| 211 mTabModelWrapper.setup(null); |
| 212 mTabModelWrapper.setTabModelSelector(mTabModelSelector); |
| 213 } |
| 214 |
| 215 if (mTabModelWrapper.getParent() == null) { |
| 216 mContentViewHolder.addView(mTabModelWrapper); |
| 217 } |
| 218 mToolbar.showAddButton(true); |
| 219 } |
| 220 |
| 221 /** |
| 222 * Returns the visibility status of the tab switcher. |
| 223 */ |
| 224 public boolean isTabSwitcherVisible() { |
| 225 return mTabModelWrapper != null && mTabModelWrapper.getParent() == mCont
entViewHolder; |
| 226 } |
| 227 |
| 228 /** |
187 * Toggles the tab switcher visibility. | 229 * Toggles the tab switcher visibility. |
188 */ | 230 */ |
189 public void toggleTabSwitcher() { | 231 public void toggleTabSwitcher() { |
190 mTabModelSelector.toggleTabSwitcher(); | 232 if (!isTabSwitcherVisible()) { |
191 } | 233 showTabSwitcher(); |
192 | 234 } else { |
193 public boolean isTabSwitcherVisible() { | 235 hideTabSwitcher(); |
194 return mTabModelSelector.isTabSwitcherVisible(); | 236 } |
195 } | |
196 | |
197 public void hideTabSwitcher() { | |
198 mTabModelSelector.hideTabSwitcher(); | |
199 } | 237 } |
200 | 238 |
201 /** | 239 /** |
202 * Opens a URL in the current tab if one exists, or in a new tab otherwise. | 240 * Opens a URL in the current tab if one exists, or in a new tab otherwise. |
203 * @param url The URL to open. | 241 * @param url The URL to open. |
204 * @return The tab used to open the provided URL. | 242 * @return The tab used to open the provided URL. |
205 */ | 243 */ |
206 public Tab openUrl(String url) { | 244 public Tab openUrl(String url) { |
207 LoadUrlParams loadUrlParams = new LoadUrlParams(url); | 245 LoadUrlParams loadUrlParams = new LoadUrlParams(url); |
208 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR
OM_ADDRESS_BAR); | 246 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR
OM_ADDRESS_BAR); |
209 Tab tab = mTabModelSelector.getCurrentTab(); | 247 Tab tab = mTabModelSelector.getCurrentTab(); |
210 if (tab != null) { | 248 if (tab != null) { |
211 tab.loadUrl(loadUrlParams); | 249 tab.loadUrl(loadUrlParams); |
212 return tab; | 250 return tab; |
213 } | 251 } |
214 return createTab(url, TabLaunchType.FROM_KEYBOARD); | 252 return createTab(url, TabLaunchType.FROM_KEYBOARD); |
215 } | 253 } |
216 } | 254 } |
OLD | NEW |