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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/compositor/layouts/ContextualSearchSupportedLayout.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.graphics.Rect;
9 import android.view.View;
10 import android.view.ViewGroup;
11
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 ualSearchPanelHost;
15 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
16 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
17 import org.chromium.chrome.browser.compositor.scene_layer.ContextualSearchSceneL ayer;
18 import org.chromium.chrome.browser.compositor.scene_layer.SceneLayer;
19 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
20 import org.chromium.content.browser.ContentViewCore;
21 import org.chromium.ui.resources.ResourceManager;
22
23 import java.util.List;
24
25 /**
26 * A {@link Layout} that can show a Contextual Search overlay that shows at the
27 * bottom and can be swiped upwards.
28 */
29 public abstract class ContextualSearchSupportedLayout extends Layout {
30 /**
31 * The {@link ContextualSearchPanelHost} that allows the {@link ContextualSe archPanel} to
32 * communicate back to the Layout.
33 */
34 protected final ContextualSearchPanelHost mContextualSearchPanelHost;
35
36 /**
37 * The {@link ContextualSearchPanel} that represents the Contextual Search U I.
38 */
39 protected final ContextualSearchPanel mSearchPanel;
40
41 /**
42 * The {@link SceneLayer} that renders contextual search UI.
43 */
44 private final ContextualSearchSceneLayer mContextualSearchSceneLayer;
45
46 /**
47 * Size of half pixel in dps.
48 */
49 private final float mHalfPixelDp;
50
51 /**
52 * @param context The current Android context.
53 * @param updateHost The {@link LayoutUpdateHost} view for this layout.
54 * @param renderHost The {@link LayoutRenderHost} view for this layout.
55 * @param eventFilter The {@link EventFilter} that is needed for this view.
56 * @param panel The {@link ContextualSearchPanel} that represents the Contex tual Search UI.
57 */
58 public ContextualSearchSupportedLayout(Context context, LayoutUpdateHost upd ateHost,
59 LayoutRenderHost renderHost, EventFilter eventFilter, ContextualSear chPanel panel) {
60 super(context, updateHost, renderHost, eventFilter);
61
62 mContextualSearchPanelHost = new ContextualSearchPanelHost() {
63 @Override
64 public void hideLayout(boolean immediately) {
65 ContextualSearchSupportedLayout.this.hideContextualSearch(immedi ately);
66 }
67 };
68
69 mSearchPanel = panel;
70 float dpToPx = context.getResources().getDisplayMetrics().density;
71 mHalfPixelDp = 0.5f / dpToPx;
72 mContextualSearchSceneLayer = new ContextualSearchSceneLayer(dpToPx, pan el);
73 }
74
75 @Override
76 public void attachViews(ViewGroup container) {
77 mSearchPanel.setContainerView(container);
78 }
79
80 @Override
81 public void getAllViews(List<View> views) {
82 // TODO(dtrainor): If we move ContextualSearch to an overlay, pull the v iews from there
83 // instead in Layout.java.
84 if (mSearchPanel != null && mSearchPanel.getManagementDelegate() != null ) {
85 ContentViewCore content =
86 mSearchPanel.getManagementDelegate().getSearchContentViewCor e();
87 if (content != null) views.add(content.getContainerView());
88 }
89 super.getAllViews(views);
90 }
91
92 @Override
93 public void getAllContentViewCores(List<ContentViewCore> contents) {
94 // TODO(dtrainor): If we move ContextualSearch to an overlay, pull the c ontent from there
95 // instead in Layout.java.
96 if (mSearchPanel != null && mSearchPanel.getManagementDelegate() != null ) {
97 ContentViewCore content =
98 mSearchPanel.getManagementDelegate().getSearchContentViewCor e();
99 if (content != null) contents.add(content);
100 }
101 super.getAllContentViewCores(contents);
102 }
103
104 @Override
105 public void show(long time, boolean animate) {
106 mSearchPanel.setHost(mContextualSearchPanelHost);
107 super.show(time, animate);
108 }
109
110 /**
111 * Hides the Contextual Search Supported Layout.
112 * @param immediately Whether it should be hidden immediately.
113 */
114 protected void hideContextualSearch(boolean immediately) {
115 // NOTE(pedrosimonetti): To be implemented by a supported Layout.
116 }
117
118 @Override
119 protected void notifySizeChanged(float width, float height, int orientation) {
120 super.notifySizeChanged(width, height, orientation);
121
122 // NOTE(pedrosimonetti): Due to some floating point madness, getHeight() and
123 // getHeightMinusTopControls() might not always be the same when the Too lbar is
124 // visible. For this reason, we're comparing to see if the difference be tween them
125 // is less than half pixel. If so, it means the Toolbar is visible.
126 final boolean isToolbarVisible = getHeight() - getHeightMinusTopControls () <= mHalfPixelDp;
127 mSearchPanel.onSizeChanged(width, height, isToolbarVisible);
128 }
129
130 @Override
131 protected boolean onUpdateAnimation(long time, boolean jumpToEnd) {
132 boolean parentAnimating = super.onUpdateAnimation(time, jumpToEnd);
133 boolean panelAnimating = mSearchPanel.onUpdateAnimation(time, jumpToEnd) ;
134 return panelAnimating || parentAnimating;
135 }
136
137 @Override
138 protected SceneLayer getSceneLayer() {
139 return mContextualSearchSceneLayer;
140 }
141
142 @Override
143 protected void updateSceneLayer(Rect viewport, Rect contentViewport,
144 LayerTitleCache layerTitleCache, TabContentManager tabContentManager ,
145 ResourceManager resourceManager, ChromeFullscreenManager fullscreenM anager) {
146 super.updateSceneLayer(viewport, contentViewport, layerTitleCache, tabCo ntentManager,
147 resourceManager, fullscreenManager);
148 if (mContextualSearchSceneLayer == null || mSearchPanel.getManagementDel egate() == null) {
149 return;
150 }
151
152 ContentViewCore contentViewCore =
153 mSearchPanel.getManagementDelegate().getSearchContentViewCore();
154 mContextualSearchSceneLayer.update(contentViewCore, resourceManager);
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698