Commit 893e2438 authored by spdonghao's avatar spdonghao Committed by Commit Bot

Add a transparent view above in tasks_surface_header.

Bug: 1113852
Change-Id: Ic5a75d929b1ee4b62b3925a7d47a8c05886d87b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426566Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812935}
parent 72c3fd50
...@@ -10,7 +10,7 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties. ...@@ -10,7 +10,7 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_MARGIN; import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_MARGIN;
import android.view.View; import android.view.View;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -37,20 +37,17 @@ class SecondaryTasksSurfaceViewBinder { ...@@ -37,20 +37,17 @@ class SecondaryTasksSurfaceViewBinder {
&& !model.get(IS_SHOWING_STACK_TAB_SWITCHER); && !model.get(IS_SHOWING_STACK_TAB_SWITCHER);
if (isShowing && viewHolder.tasksSurfaceView.getParent() == null) { if (isShowing && viewHolder.tasksSurfaceView.getParent() == null) {
viewHolder.parentView.addView(viewHolder.tasksSurfaceView); viewHolder.parentView.addView(viewHolder.tasksSurfaceView);
MarginLayoutParams layoutParams = setTopBarHeight(viewHolder, model.get(TOP_MARGIN));
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
layoutParams.topMargin = model.get(TOP_MARGIN);
} }
viewHolder.tasksSurfaceView.setVisibility(isShowing ? View.VISIBLE : View.GONE); viewHolder.tasksSurfaceView.setVisibility(isShowing ? View.VISIBLE : View.GONE);
} }
private static void setTopBarHeight(TasksSurfaceViewBinder.ViewHolder viewHolder, int height) { private static void setTopBarHeight(TasksSurfaceViewBinder.ViewHolder viewHolder, int height) {
MarginLayoutParams layoutParams = ViewGroup.LayoutParams lp = viewHolder.topToolbarPlaceholderView.getLayoutParams();
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams(); if (lp == null) return;
if (layoutParams == null) return;
layoutParams.topMargin = height; lp.height = height;
viewHolder.tasksSurfaceView.setLayoutParams(layoutParams); viewHolder.topToolbarPlaceholderView.setLayoutParams(lp);
} }
} }
...@@ -320,11 +320,11 @@ public class StartSurfaceCoordinator implements StartSurface { ...@@ -320,11 +320,11 @@ public class StartSurfaceCoordinator implements StartSurface {
hasTrendyTerms); hasTrendyTerms);
mTasksSurface.getView().setId(R.id.primary_tasks_surface_view); mTasksSurface.getView().setId(R.id.primary_tasks_surface_view);
mTasksSurfacePropertyModelChangeProcessor = mTasksSurfacePropertyModelChangeProcessor = PropertyModelChangeProcessor.create(
PropertyModelChangeProcessor.create(mPropertyModel, mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder( new TasksSurfaceViewBinder.ViewHolder(mActivity.getCompositorViewHolder(),
mActivity.getCompositorViewHolder(), mTasksSurface.getView()), mTasksSurface.getView(), mTasksSurface.getTopToolbarPlaceholderView()),
TasksSurfaceViewBinder::bind); TasksSurfaceViewBinder::bind);
// There is nothing else to do for SurfaceMode.TASKS_ONLY, SurfaceMode.OMNIBOX_ONLY and // There is nothing else to do for SurfaceMode.TASKS_ONLY, SurfaceMode.OMNIBOX_ONLY and
// SurfaceMode.TRENDY_TERMS. // SurfaceMode.TRENDY_TERMS.
...@@ -363,7 +363,8 @@ public class StartSurfaceCoordinator implements StartSurface { ...@@ -363,7 +363,8 @@ public class StartSurfaceCoordinator implements StartSurface {
mSecondaryTasksSurfacePropertyModelChangeProcessor = mSecondaryTasksSurfacePropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mPropertyModel, PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mActivity.getCompositorViewHolder(), new TasksSurfaceViewBinder.ViewHolder(mActivity.getCompositorViewHolder(),
mSecondaryTasksSurface.getView()), mSecondaryTasksSurface.getView(),
mSecondaryTasksSurface.getTopToolbarPlaceholderView()),
SecondaryTasksSurfaceViewBinder::bind); SecondaryTasksSurfaceViewBinder::bind);
if (mOnTabSelectingListener != null) { if (mOnTabSelectingListener != null) {
mSecondaryTasksSurface.setOnTabSelectingListener(mOnTabSelectingListener); mSecondaryTasksSurface.setOnTabSelectingListener(mOnTabSelectingListener);
......
...@@ -27,10 +27,12 @@ class TasksSurfaceViewBinder { ...@@ -27,10 +27,12 @@ class TasksSurfaceViewBinder {
public static class ViewHolder { public static class ViewHolder {
public final ViewGroup parentView; public final ViewGroup parentView;
public final View tasksSurfaceView; public final View tasksSurfaceView;
public final View topToolbarPlaceholderView;
ViewHolder(ViewGroup parentView, View tasksSurfaceView) { ViewHolder(ViewGroup parentView, View tasksSurfaceView, View topToolbarPlaceholderView) {
this.parentView = parentView; this.parentView = parentView;
this.tasksSurfaceView = tasksSurfaceView; this.tasksSurfaceView = tasksSurfaceView;
this.topToolbarPlaceholderView = topToolbarPlaceholderView;
} }
} }
...@@ -54,7 +56,7 @@ class TasksSurfaceViewBinder { ...@@ -54,7 +56,7 @@ class TasksSurfaceViewBinder {
MarginLayoutParams layoutParams = MarginLayoutParams layoutParams =
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams(); (MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
layoutParams.bottomMargin = model.get(BOTTOM_BAR_HEIGHT); layoutParams.bottomMargin = model.get(BOTTOM_BAR_HEIGHT);
layoutParams.topMargin = model.get(TOP_MARGIN); setTopBarHeight(viewHolder, model.get(TOP_MARGIN));
} }
View taskSurfaceView = viewHolder.tasksSurfaceView; View taskSurfaceView = viewHolder.tasksSurfaceView;
...@@ -79,11 +81,10 @@ class TasksSurfaceViewBinder { ...@@ -79,11 +81,10 @@ class TasksSurfaceViewBinder {
} }
private static void setTopBarHeight(ViewHolder viewHolder, int height) { private static void setTopBarHeight(ViewHolder viewHolder, int height) {
MarginLayoutParams layoutParams = ViewGroup.LayoutParams lp = viewHolder.topToolbarPlaceholderView.getLayoutParams();
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams(); if (lp == null) return;
if (layoutParams == null) return;
layoutParams.topMargin = height; lp.height = height;
viewHolder.tasksSurfaceView.setLayoutParams(layoutParams); viewHolder.topToolbarPlaceholderView.setLayoutParams(lp);
} }
} }
...@@ -16,7 +16,6 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties. ...@@ -16,7 +16,6 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
...@@ -35,7 +34,8 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase; ...@@ -35,7 +34,8 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase { public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
private ViewGroup mParentView; private ViewGroup mParentView;
private View mTasksSurfaceView; private ViewGroup mTasksSurfaceView;
private View mTopToolbarPlaceholderView;
private PropertyModel mPropertyModel; private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"}) @SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor; private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
...@@ -48,13 +48,16 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase ...@@ -48,13 +48,16 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
// Note that the specific type of the parent view and tasks surface view do not matter // Note that the specific type of the parent view and tasks surface view do not matter
// for the SecondaryTasksSurfaceViewBinderTest. // for the SecondaryTasksSurfaceViewBinderTest.
mParentView = new FrameLayout(getActivity()); mParentView = new FrameLayout(getActivity());
mTasksSurfaceView = new View(getActivity()); mTasksSurfaceView = new FrameLayout(getActivity());
mTopToolbarPlaceholderView = new View(getActivity());
mTasksSurfaceView.addView(mTopToolbarPlaceholderView);
getActivity().setContentView(mParentView); getActivity().setContentView(mParentView);
}); });
mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS); mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS);
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel, mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mParentView, mTasksSurfaceView), new TasksSurfaceViewBinder.ViewHolder(
mParentView, mTasksSurfaceView, mTopToolbarPlaceholderView),
SecondaryTasksSurfaceViewBinder::bind); SecondaryTasksSurfaceViewBinder::bind);
} }
...@@ -159,8 +162,8 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase ...@@ -159,8 +162,8 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true); mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
assertNotNull(mTasksSurfaceView.getParent()); assertNotNull(mTasksSurfaceView.getParent());
assertEquals(mTasksSurfaceView.getVisibility(), View.VISIBLE); assertEquals(mTasksSurfaceView.getVisibility(), View.VISIBLE);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams.topMargin); assertEquals(20, layoutParams.height);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, false); mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, false);
assertNotNull(mTasksSurfaceView.getParent()); assertNotNull(mTasksSurfaceView.getParent());
...@@ -178,7 +181,6 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase ...@@ -178,7 +181,6 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW)); assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE)); assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE));
assertFalse(mPropertyModel.get(IS_SHOWING_STACK_TAB_SWITCHER)); assertFalse(mPropertyModel.get(IS_SHOWING_STACK_TAB_SWITCHER));
assertNull(mTasksSurfaceView.getParent());
// Setting the top margin shouldn't cause a NullPointerException when the layout params are // Setting the top margin shouldn't cause a NullPointerException when the layout params are
// null, since this should be handled in the *ViewBinder. // null, since this should be handled in the *ViewBinder.
...@@ -186,11 +188,11 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase ...@@ -186,11 +188,11 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
mPropertyModel.set(IS_SHOWING_OVERVIEW, true); mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true); mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals("Top margin isn't initialized correctly.", 20, layoutParams.topMargin); assertEquals("Top margin isn't initialized correctly.", 20, layoutParams.height);
layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
mPropertyModel.set(TOP_MARGIN, 40); mPropertyModel.set(TOP_MARGIN, 40);
assertEquals("Wrong top margin.", 40, layoutParams.topMargin); assertEquals("Wrong top margin.", 40, layoutParams.height);
} }
} }
...@@ -35,7 +35,8 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase; ...@@ -35,7 +35,8 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase { public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
private ViewGroup mParentView; private ViewGroup mParentView;
private View mTasksSurfaceView; private ViewGroup mTasksSurfaceView;
private View mTopToolbarPlaceholderView;
private PropertyModel mPropertyModel; private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"}) @SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor; private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
...@@ -48,13 +49,16 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase { ...@@ -48,13 +49,16 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
// Note that the specific type of the parent view and tasks surface view do not matter // Note that the specific type of the parent view and tasks surface view do not matter
// for the TasksSurfaceViewBinder. // for the TasksSurfaceViewBinder.
mParentView = new FrameLayout(getActivity()); mParentView = new FrameLayout(getActivity());
mTasksSurfaceView = new View(getActivity()); mTasksSurfaceView = new FrameLayout(getActivity());
mTopToolbarPlaceholderView = new View(getActivity());
mTasksSurfaceView.addView(mTopToolbarPlaceholderView);
getActivity().setContentView(mParentView); getActivity().setContentView(mParentView);
}); });
mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS); mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS);
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel, mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mParentView, mTasksSurfaceView), new TasksSurfaceViewBinder.ViewHolder(
mParentView, mTasksSurfaceView, mTopToolbarPlaceholderView),
TasksSurfaceViewBinder::bind); TasksSurfaceViewBinder::bind);
} }
...@@ -74,7 +78,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase { ...@@ -74,7 +78,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
assertNotNull(mTasksSurfaceView.getParent()); assertNotNull(mTasksSurfaceView.getParent());
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(10, layoutParams.bottomMargin); assertEquals(10, layoutParams.bottomMargin);
assertEquals(20, layoutParams.topMargin); ViewGroup.LayoutParams layoutParams1 = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams1.height);
mPropertyModel.set(IS_SHOWING_OVERVIEW, false); mPropertyModel.set(IS_SHOWING_OVERVIEW, false);
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE); assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
...@@ -97,7 +102,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase { ...@@ -97,7 +102,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
assertNotNull(mTasksSurfaceView.getParent()); assertNotNull(mTasksSurfaceView.getParent());
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(10, layoutParams.bottomMargin); assertEquals(10, layoutParams.bottomMargin);
assertEquals(20, layoutParams.topMargin); ViewGroup.LayoutParams layoutParams1 = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams1.height);
mPropertyModel.set(IS_SHOWING_STACK_TAB_SWITCHER, true); mPropertyModel.set(IS_SHOWING_STACK_TAB_SWITCHER, true);
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE); assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
...@@ -132,11 +138,11 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase { ...@@ -132,11 +138,11 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
public void testSetTopBarHeight() { public void testSetTopBarHeight() {
mPropertyModel.set(TOP_MARGIN, 10); mPropertyModel.set(TOP_MARGIN, 10);
mPropertyModel.set(IS_SHOWING_OVERVIEW, true); mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(10, layoutParams.topMargin); assertEquals(10, layoutParams.height);
mPropertyModel.set(TOP_MARGIN, 20); mPropertyModel.set(TOP_MARGIN, 20);
layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams(); layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams.topMargin); assertEquals(20, layoutParams.height);
} }
} }
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:elevation="0dp"> app:elevation="0dp">
<LinearLayout
android:id="@+id/top_toolbar_placeholder"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow"
android:background="@android:color/transparent"
android:orientation="vertical"
app:layout_scrollFlags="scroll">
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/scroll_component_container" android:id="@+id/scroll_component_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -65,6 +65,11 @@ public interface TasksSurface { ...@@ -65,6 +65,11 @@ public interface TasksSurface {
*/ */
View getView(); View getView();
/**
* Get the view {@link View} of the top transparent placeholder on start surface.
*/
View getTopToolbarPlaceholderView();
/** /**
* Called when the native initialization is completed. Anything to construct a TasksSurface but * Called when the native initialization is completed. Anything to construct a TasksSurface but
* require native initialization should be constructed here. * require native initialization should be constructed here.
......
...@@ -142,6 +142,11 @@ public class TasksSurfaceCoordinator implements TasksSurface { ...@@ -142,6 +142,11 @@ public class TasksSurfaceCoordinator implements TasksSurface {
return mView; return mView;
} }
@Override
public View getTopToolbarPlaceholderView() {
return mView != null ? mView.findViewById(R.id.top_toolbar_placeholder) : null;
}
@Override @Override
public void onFinishNativeInitialization(Context context, FakeboxDelegate fakeboxDelegate) { public void onFinishNativeInitialization(Context context, FakeboxDelegate fakeboxDelegate) {
if (mTabSwitcher != null) { if (mTabSwitcher != null) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment