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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/compositor/layouts/phone/ContextualSearchLayout.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.phone;
6
7 import android.content.Context;
8 import android.graphics.Rect;
9 import android.view.View;
10
11 import org.chromium.chrome.browser.Tab;
12 import org.chromium.chrome.browser.compositor.LayerTitleCache;
13 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel;
14 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel.StateChangeReason;
15 import org.chromium.chrome.browser.compositor.layouts.ContextualSearchSupportedL ayout;
16 import org.chromium.chrome.browser.compositor.layouts.Layout;
17 import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost;
18 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
19 import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab;
20 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
21 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeEvent Filter.ScrollDirection;
22 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
23 import org.chromium.chrome.browser.compositor.scene_layer.SceneLayer;
24 import org.chromium.chrome.browser.compositor.scene_layer.TabListSceneLayer;
25 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
26 import org.chromium.chrome.browser.util.MathUtils;
27 import org.chromium.content.browser.ContentViewCore;
28 import org.chromium.content_public.common.TopControlsState;
29 import org.chromium.ui.resources.ResourceManager;
30
31 /**
32 * A {@link Layout} that shows a Contextual Search overlay at the bottom.
33 */
34 public class ContextualSearchLayout extends ContextualSearchSupportedLayout {
35 /**
36 * The height of the Toolbar in dps.
37 * TODO(pedrosimonetti): Get this value from the Toolbar code.
38 */
39 private static final float TOOLBAR_HEIGHT_DP = 56.f;
40
41 /**
42 * The initial Y position of the touch event.
43 */
44 private float mInitialPanelTouchY;
45
46 /**
47 * The base Tab.
48 */
49 private LayoutTab mBaseTab;
50
51 private final TabListSceneLayer mTabListSceneLayer;
52
53 /**
54 * @param context The current Android context.
55 * @param updateHost The {@link LayoutUpdateHost} view for this layout.
56 * @param renderHost The {@link LayoutRenderHost} view for this layout.
57 * @param eventFilter The {@link EventFilter} that is needed for this view.
58 */
59 public ContextualSearchLayout(Context context, LayoutUpdateHost updateHost,
60 LayoutRenderHost renderHost, EventFilter eventFilter, ContextualSear chPanel panel) {
61 super(context, updateHost, renderHost, eventFilter, panel);
62 mTabListSceneLayer = new TabListSceneLayer();
63 // TODO(changwan): use SceneOverlayTree's setContentTree() instead once we refactor
64 // ContextualSearchSupportedLayout into LayoutHelper.
65 mTabListSceneLayer.setContentTree(super.getSceneLayer());
66 }
67
68 @Override
69 public View getViewForInteraction() {
70 ContentViewCore content = mSearchPanel.getManagementDelegate().getSearch ContentViewCore();
71 if (content != null) return content.getContainerView();
72 return super.getViewForInteraction();
73 }
74
75 @Override
76 public int getSizingFlags() {
77 return SizingFlags.HELPER_SUPPORTS_FULLSCREEN;
78 }
79
80 @Override
81 public float getTopControlsOffset(float currentOffsetDp) {
82 return MathUtils.clamp(mBaseTab.getY(), -TOOLBAR_HEIGHT_DP, Math.min(cur rentOffsetDp, 0f));
83 }
84
85 @Override
86 protected void updateLayout(long time, long dt) {
87 super.updateLayout(time, dt);
88 if (mBaseTab == null) return;
89
90 mBaseTab.setY(mSearchPanel.getBasePageY());
91 mBaseTab.setBrightness(mSearchPanel.getBasePageBrightness());
92
93 boolean needUpdate = mBaseTab.updateSnap(dt);
94 if (needUpdate) requestUpdate();
95 }
96
97 @Override
98 public boolean handlesTabCreating() {
99 // Prevents the new Tab animation from happening when promoting to a new Tab.
100 startHiding(mBaseTab.getId(), false);
101 doneHiding();
102 // Updates TopControls' State so the Toolbar becomes visible.
103 // TODO(pedrosimonetti): The transition when promoting to a new tab is o nly smooth
104 // if the SearchContentView's vertical scroll position is zero. Otherwis e the
105 // ContentView will appear to jump in the screen. Coordinate with @dtrai nor to solve
106 // this problem.
107 mSearchPanel.getManagementDelegate().updateTopControlsState(TopControlsS tate.BOTH, false);
108 return true;
109 }
110
111 @Override
112 public void show(long time, boolean animate) {
113 super.show(time, animate);
114
115 resetLayout();
116 createBaseLayoutTab(mBaseTab);
117
118 mSearchPanel.createSearchPromo();
119 }
120
121 /**
122 * Resets the Layout.
123 */
124 private void resetLayout() {
125 mLayoutTabs = null;
126 mBaseTab = null;
127 }
128
129 /**
130 * Creates the Base Page's LayoutTab to be presented in the screen.
131 *
132 * @param layoutTab The {@link Layout} instance.
133 */
134 private void createBaseLayoutTab(LayoutTab layoutTab) {
135 if (mTabModelSelector == null) return;
136
137 int baseTabId = mTabModelSelector.getCurrentTabId();
138 if (baseTabId == Tab.INVALID_TAB_ID) return;
139
140 mBaseTab = createLayoutTab(
141 baseTabId, mTabModelSelector.isIncognitoSelected(), NO_CLOSE_BUT TON, NO_TITLE);
142
143 assert mBaseTab != null;
144 mBaseTab.setScale(1.f);
145 mBaseTab.setBorderScale(1.f);
146 mBaseTab.setBorderAlpha(0.f);
147
148 mLayoutTabs = new LayoutTab[] {mBaseTab};
149 }
150
151 // ========================================================================= ===================
152 // Panel Host
153 // ========================================================================= ===================
154
155 @Override
156 protected void hideContextualSearch(boolean immediately) {
157 if (isActive() && mBaseTab != null) {
158 startHiding(mBaseTab.getId(), false);
159 if (immediately) doneHiding();
160 }
161 }
162
163 // ========================================================================= ===================
164 // cc::Layer Events
165 // ========================================================================= ===================
166
167 @Override
168 public void onDown(long time, float x, float y) {
169 mInitialPanelTouchY = y;
170 mSearchPanel.handleSwipeStart();
171 }
172
173 @Override
174 public void drag(long time, float x, float y, float deltaX, float deltaY) {
175 final float ty = y - mInitialPanelTouchY;
176
177 mSearchPanel.handleSwipeMove(ty);
178 }
179
180 @Override
181 public void onUpOrCancel(long time) {
182 mSearchPanel.handleSwipeEnd();
183 }
184
185 @Override
186 public void fling(long time, float x, float y, float velocityX, float veloci tyY) {
187 mSearchPanel.handleFling(velocityY);
188 }
189
190 @Override
191 public void click(long time, float x, float y) {
192 mSearchPanel.handleClick(time, x, y);
193 }
194
195 // ========================================================================= ===================
196 // Android View Events
197 // ========================================================================= ===================
198
199 @Override
200 public void swipeStarted(long time, ScrollDirection direction, float x, floa t y) {
201 mSearchPanel.handleSwipeStart();
202 }
203
204 @Override
205 public void swipeUpdated(long time, float x, float y, float dx, float dy, fl oat tx, float ty) {
206 mSearchPanel.handleSwipeMove(ty);
207 }
208
209 @Override
210 public void swipeFlingOccurred(
211 long time, float x, float y, float tx, float ty, float vx, float vy) {
212 mSearchPanel.handleFling(vy);
213 }
214
215 @Override
216 public void swipeFinished(long time) {
217 mSearchPanel.handleSwipeEnd();
218 }
219
220 @Override
221 public void swipeCancelled(long time) {
222 swipeFinished(time);
223 }
224
225 @Override
226 public boolean onBackPressed() {
227 mSearchPanel.closePanel(StateChangeReason.BACK_PRESS, true);
228 return true;
229 }
230
231 @Override
232 protected SceneLayer getSceneLayer() {
233 return mTabListSceneLayer;
234 }
235
236 @Override
237 protected void updateSceneLayer(Rect viewport, Rect contentViewport,
238 LayerTitleCache layerTitleCache, TabContentManager tabContentManager ,
239 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM anager) {
240 super.updateSceneLayer(viewport, contentViewport, layerTitleCache, tabCo ntentManager,
241 resourceManager, fullscreenManager);
242 assert mTabListSceneLayer != null;
243 mTabListSceneLayer.pushLayers(getContext(), viewport, contentViewport, t his,
244 layerTitleCache, tabContentManager, resourceManager);
245 }
246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698