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 13 matching lines...) Expand all Loading... | |
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, 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); |
87 mTabModelWrapper = mTabModelSelector.getTabModelWrapper(); | |
83 mContentViewRenderView = new ContentViewRenderView(getContext()) { | 88 mContentViewRenderView = new ContentViewRenderView(getContext()) { |
84 @Override | 89 @Override |
85 protected void onReadyToRender() { | 90 protected void onReadyToRender() { |
86 if (mCurrentTab == null) createTab(mStartupUrl, TabLaunchType.FR OM_RESTORE); | 91 if (mCurrentTab == null) createTab(mStartupUrl, TabLaunchType.FR OM_RESTORE); |
87 } | 92 } |
88 }; | 93 }; |
89 mContentViewRenderView.onNativeLibraryLoaded(window); | 94 mContentViewRenderView.onNativeLibraryLoaded(window); |
90 mContentViewHolder.addView(mContentViewRenderView, | 95 mContentViewHolder.addView(mContentViewRenderView, |
91 new FrameLayout.LayoutParams( | 96 new FrameLayout.LayoutParams( |
92 FrameLayout.LayoutParams.MATCH_PARENT, | 97 FrameLayout.LayoutParams.MATCH_PARENT, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 181 |
177 private void setupContent() { | 182 private void setupContent() { |
178 View view = mCurrentTab.getView(); | 183 View view = mCurrentTab.getView(); |
179 ContentViewCore contentViewCore = mCurrentTab.getContentViewCore(); | 184 ContentViewCore contentViewCore = mCurrentTab.getContentViewCore(); |
180 mContentViewHolder.addView(view); | 185 mContentViewHolder.addView(view); |
181 mContentViewRenderView.setCurrentContentViewCore(contentViewCore); | 186 mContentViewRenderView.setCurrentContentViewCore(contentViewCore); |
182 view.requestFocus(); | 187 view.requestFocus(); |
183 contentViewCore.onShow(); | 188 contentViewCore.onShow(); |
184 } | 189 } |
185 | 190 |
191 /* | |
192 * Hide the tab switcher. | |
193 */ | |
194 public void hideTabSwitcher() { | |
195 if (mTabModelWrapper == null) return; | |
196 mToolbar.showAddButton(false); | |
Bernhard Bauer
2014/11/10 13:58:33
Is there some method to where these calls appear?
divya.bansal
2014/11/11 05:18:19
Done.
| |
197 ViewParent parent = mTabModelWrapper.getParent(); | |
198 if (parent != null) { | |
199 assert parent == mContentViewHolder; | |
200 mContentViewHolder.removeView(mTabModelWrapper); | |
201 } | |
202 } | |
203 | |
204 private void showTabSwitcher() { | |
205 if (mTabModelWrapper == null) { | |
206 mTabModelWrapper = (AccessibilityTabModelWrapper) LayoutInflater.fro m( | |
207 mContentViewHolder.getContext()).inflate( | |
208 R.layout.accessibility_tab_switcher, null); | |
209 mTabModelWrapper.setup(null); | |
210 mTabModelWrapper.setTabModelSelector(mTabModelSelector); | |
211 } | |
212 | |
213 if (mTabModelWrapper.getParent() == null) { | |
214 mContentViewHolder.addView(mTabModelWrapper); | |
215 } | |
216 mToolbar.showAddButton(true); | |
217 } | |
218 | |
219 public boolean isTabSwitcherVisible() { | |
220 return mTabModelWrapper != null && mTabModelWrapper.getParent() == mCont entViewHolder; | |
221 } | |
222 | |
186 /** | 223 /** |
187 * Toggles the tab switcher visibility. | 224 * Toggles the tab switcher visibility. |
188 */ | 225 */ |
189 public void toggleTabSwitcher() { | 226 public void toggleTabSwitcher() { |
190 mTabModelSelector.toggleTabSwitcher(); | 227 if (!isTabSwitcherVisible()) { |
191 } | 228 showTabSwitcher(); |
192 | 229 } else { |
193 public boolean isTabSwitcherVisible() { | 230 hideTabSwitcher(); |
194 return mTabModelSelector.isTabSwitcherVisible(); | 231 } |
195 } | |
196 | |
197 public void hideTabSwitcher() { | |
198 mTabModelSelector.hideTabSwitcher(); | |
199 } | 232 } |
200 | 233 |
201 /** | 234 /** |
202 * Opens a URL in the current tab if one exists, or in a new tab otherwise. | 235 * Opens a URL in the current tab if one exists, or in a new tab otherwise. |
203 * @param url The URL to open. | 236 * @param url The URL to open. |
204 * @return The tab used to open the provided URL. | 237 * @return The tab used to open the provided URL. |
205 */ | 238 */ |
206 public Tab openUrl(String url) { | 239 public Tab openUrl(String url) { |
207 LoadUrlParams loadUrlParams = new LoadUrlParams(url); | 240 LoadUrlParams loadUrlParams = new LoadUrlParams(url); |
208 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR OM_ADDRESS_BAR); | 241 loadUrlParams.setTransitionType(PageTransition.TYPED | PageTransition.FR OM_ADDRESS_BAR); |
209 Tab tab = mTabModelSelector.getCurrentTab(); | 242 Tab tab = mTabModelSelector.getCurrentTab(); |
210 if (tab != null) { | 243 if (tab != null) { |
211 tab.loadUrl(loadUrlParams); | 244 tab.loadUrl(loadUrlParams); |
212 return tab; | 245 return tab; |
213 } | 246 } |
214 return createTab(url, TabLaunchType.FROM_KEYBOARD); | 247 return createTab(url, TabLaunchType.FROM_KEYBOARD); |
215 } | 248 } |
216 } | 249 } |
OLD | NEW |