Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/compositor/layouts/LayoutManagerChromePhone.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.compositor.layouts;
6
7 import android.content.Context;
8 import android.view.ViewGroup;
9
10 import org.chromium.chrome.browser.Tab;
11 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
12 import org.chromium.chrome.browser.compositor.layouts.phone.SimpleAnimationLayou t;
13 import org.chromium.chrome.browser.compositor.overlays.SceneOverlay;
14 import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDe legate;
15 import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
16 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
17 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
18 import org.chromium.chrome.browser.tabmodel.TabModelUtils;
19 import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
20
21 /**
22 * {@link LayoutManagerChromePhone} is the specialization of {@link LayoutManage rChrome} for the
23 * phone.
24 */
25 public class LayoutManagerChromePhone extends LayoutManagerChrome {
26 // Layouts
27 private final Layout mSimpleAnimationLayout;
28
29 /**
30 * Creates an instance of a {@link LayoutManagerChromePhone}.
31 * @param host A {@link LayoutManagerHost} instance.
32 * @param overviewLayoutFactoryDelegate A {@link OverviewLayoutFactoryDelega te} instance.
33 */
34 public LayoutManagerChromePhone(
35 LayoutManagerHost host, OverviewLayoutFactoryDelegate overviewLayout FactoryDelegate) {
36 super(host, overviewLayoutFactoryDelegate);
37 Context context = host.getContext();
38 LayoutRenderHost renderHost = host.getLayoutRenderHost();
39
40 // Build Layouts
41 mSimpleAnimationLayout =
42 new SimpleAnimationLayout(context, this, renderHost, mBlackHoleE ventFilter);
43
44 // Set up layout parameters
45 mStaticLayout.setLayoutHandlesTabLifecycles(false);
46 mToolbarSwipeLayout.setMovesToolbar(true);
47 }
48
49 @Override
50 public void init(TabModelSelector selector, TabCreatorManager creator,
51 TabContentManager content, ViewGroup androidContentContainer,
52 ContextualSearchManagementDelegate contextualSearchDelegate,
53 DynamicResourceLoader dynamicResourceLoader) {
54 // Initialize Layouts
55 mSimpleAnimationLayout.setTabModelSelector(selector, content);
56
57 super.init(selector, creator, content, androidContentContainer, contextu alSearchDelegate,
58 dynamicResourceLoader);
59 }
60
61 @Override
62 protected LayoutManagerTabModelObserver createTabModelObserver() {
63 return new LayoutManagerTabModelObserver() {
64 @Override
65 public void willCloseTab(Tab tab, boolean animate) {
66 super.willCloseTab(tab, animate);
67 if (animate) tabClosing(tab.getId());
68 }
69 };
70 }
71
72 @Override
73 protected void addGlobalSceneOverlay(SceneOverlay helper) {
74 super.addGlobalSceneOverlay(helper);
75 mSimpleAnimationLayout.addSceneOverlay(helper);
76 }
77
78 @Override
79 protected void emptyCachesExcept(int tabId) {
80 super.emptyCachesExcept(tabId);
81 if (mTitleCache != null) mTitleCache.clearExcept(tabId);
82 }
83
84 private void tabClosing(int id) {
85 Tab closedTab = getTabById(id);
86 if (closedTab == null) return;
87
88 if (getActiveLayout().handlesTabClosing()) {
89 // The user is currently interacting with the {@code LayoutHost}.
90 // Allow the foreground layout to animate the tab closing.
91 getActiveLayout().onTabClosing(time(), id);
92 } else if (mEnableAnimations) {
93 startShowing(mSimpleAnimationLayout, false);
94 getActiveLayout().onTabClosing(time(), id);
95 }
96 }
97
98 @Override
99 protected void tabClosed(int id, int nextId, boolean incognito) {
100 boolean showOverview = nextId == Tab.INVALID_TAB_ID;
101 Layout overviewLayout = useAccessibilityLayout() ? mOverviewListLayout : mOverviewLayout;
102 if (getActiveLayout() != overviewLayout && showOverview) {
103 // Since there will be no 'next' tab to display, switch to
104 // overview mode when the animation is finished.
105 setNextLayout(overviewLayout);
106 }
107 getActiveLayout().onTabClosed(time(), id, nextId, incognito);
108 Tab nextTab = getTabById(nextId);
109 if (nextTab != null) nextTab.requestFocus();
110 if (getActiveLayout() != overviewLayout && showOverview && !mEnableAnima tions) {
111 startShowing(overviewLayout, false);
112 }
113 }
114
115 @Override
116 protected void tabCreating(int sourceId, String url, boolean isIncognito) {
117 if (!getActiveLayout().isHiding() && getActiveLayout().handlesTabCreatin g()) {
118 // If the current layout in the foreground, let it handle the tab cr eation animation.
119 // This check allows us to switch from the StackLayout to the Simple AnimationLayout
120 // smoothly.
121 getActiveLayout().onTabCreating(sourceId);
122 } else if (mEnableAnimations) {
123 if (getActiveLayout() != null && getActiveLayout().isHiding()) {
124 setNextLayout(mSimpleAnimationLayout);
125 // The method Layout#doneHiding() will automatically show the ne xt layout.
126 getActiveLayout().doneHiding();
127 } else {
128 startShowing(mSimpleAnimationLayout, false);
129 }
130 getActiveLayout().onTabCreating(sourceId);
131 }
132 }
133
134 @Override
135 protected void tabCreated(int id, int sourceId, TabLaunchType launchType, bo olean isIncognito,
136 boolean willBeSelected, float originX, float originY) {
137 super.tabCreated(id, sourceId, launchType, isIncognito, willBeSelected, originX, originY);
138
139 if (willBeSelected) {
140 Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel (isIncognito), id);
141 if (newTab != null) newTab.requestFocus();
142 }
143 }
144
145 @Override
146 public void releaseTabLayout(int id) {
147 mTitleCache.remove(id);
148 super.releaseTabLayout(id);
149 }
150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698