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.
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_MARGIN;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewGroup;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -37,20 +37,17 @@ class SecondaryTasksSurfaceViewBinder {
&& !model.get(IS_SHOWING_STACK_TAB_SWITCHER);
if (isShowing && viewHolder.tasksSurfaceView.getParent() == null) {
viewHolder.parentView.addView(viewHolder.tasksSurfaceView);
MarginLayoutParams layoutParams =
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
layoutParams.topMargin = model.get(TOP_MARGIN);
setTopBarHeight(viewHolder, model.get(TOP_MARGIN));
}
viewHolder.tasksSurfaceView.setVisibility(isShowing ? View.VISIBLE : View.GONE);
}
private static void setTopBarHeight(TasksSurfaceViewBinder.ViewHolder viewHolder, int height) {
MarginLayoutParams layoutParams =
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
if (layoutParams == null) return;
ViewGroup.LayoutParams lp = viewHolder.topToolbarPlaceholderView.getLayoutParams();
if (lp == null) return;
layoutParams.topMargin = height;
viewHolder.tasksSurfaceView.setLayoutParams(layoutParams);
lp.height = height;
viewHolder.topToolbarPlaceholderView.setLayoutParams(lp);
}
}
......@@ -320,11 +320,11 @@ public class StartSurfaceCoordinator implements StartSurface {
hasTrendyTerms);
mTasksSurface.getView().setId(R.id.primary_tasks_surface_view);
mTasksSurfacePropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(
mActivity.getCompositorViewHolder(), mTasksSurface.getView()),
TasksSurfaceViewBinder::bind);
mTasksSurfacePropertyModelChangeProcessor = PropertyModelChangeProcessor.create(
mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mActivity.getCompositorViewHolder(),
mTasksSurface.getView(), mTasksSurface.getTopToolbarPlaceholderView()),
TasksSurfaceViewBinder::bind);
// There is nothing else to do for SurfaceMode.TASKS_ONLY, SurfaceMode.OMNIBOX_ONLY and
// SurfaceMode.TRENDY_TERMS.
......@@ -363,7 +363,8 @@ public class StartSurfaceCoordinator implements StartSurface {
mSecondaryTasksSurfacePropertyModelChangeProcessor =
PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mActivity.getCompositorViewHolder(),
mSecondaryTasksSurface.getView()),
mSecondaryTasksSurface.getView(),
mSecondaryTasksSurface.getTopToolbarPlaceholderView()),
SecondaryTasksSurfaceViewBinder::bind);
if (mOnTabSelectingListener != null) {
mSecondaryTasksSurface.setOnTabSelectingListener(mOnTabSelectingListener);
......
......@@ -27,10 +27,12 @@ class TasksSurfaceViewBinder {
public static class ViewHolder {
public final ViewGroup parentView;
public final View tasksSurfaceView;
public final View topToolbarPlaceholderView;
ViewHolder(ViewGroup parentView, View tasksSurfaceView) {
ViewHolder(ViewGroup parentView, View tasksSurfaceView, View topToolbarPlaceholderView) {
this.parentView = parentView;
this.tasksSurfaceView = tasksSurfaceView;
this.topToolbarPlaceholderView = topToolbarPlaceholderView;
}
}
......@@ -54,7 +56,7 @@ class TasksSurfaceViewBinder {
MarginLayoutParams layoutParams =
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
layoutParams.bottomMargin = model.get(BOTTOM_BAR_HEIGHT);
layoutParams.topMargin = model.get(TOP_MARGIN);
setTopBarHeight(viewHolder, model.get(TOP_MARGIN));
}
View taskSurfaceView = viewHolder.tasksSurfaceView;
......@@ -79,11 +81,10 @@ class TasksSurfaceViewBinder {
}
private static void setTopBarHeight(ViewHolder viewHolder, int height) {
MarginLayoutParams layoutParams =
(MarginLayoutParams) viewHolder.tasksSurfaceView.getLayoutParams();
if (layoutParams == null) return;
ViewGroup.LayoutParams lp = viewHolder.topToolbarPlaceholderView.getLayoutParams();
if (lp == null) return;
layoutParams.topMargin = height;
viewHolder.tasksSurfaceView.setLayoutParams(layoutParams);
lp.height = height;
viewHolder.topToolbarPlaceholderView.setLayoutParams(lp);
}
}
......@@ -16,7 +16,6 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.FrameLayout;
import androidx.test.filters.SmallTest;
......@@ -35,7 +34,8 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase;
@RunWith(ChromeJUnit4ClassRunner.class)
public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
private ViewGroup mParentView;
private View mTasksSurfaceView;
private ViewGroup mTasksSurfaceView;
private View mTopToolbarPlaceholderView;
private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
......@@ -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
// for the SecondaryTasksSurfaceViewBinderTest.
mParentView = new FrameLayout(getActivity());
mTasksSurfaceView = new View(getActivity());
mTasksSurfaceView = new FrameLayout(getActivity());
mTopToolbarPlaceholderView = new View(getActivity());
mTasksSurfaceView.addView(mTopToolbarPlaceholderView);
getActivity().setContentView(mParentView);
});
mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS);
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mParentView, mTasksSurfaceView),
new TasksSurfaceViewBinder.ViewHolder(
mParentView, mTasksSurfaceView, mTopToolbarPlaceholderView),
SecondaryTasksSurfaceViewBinder::bind);
}
......@@ -159,8 +162,8 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
assertNotNull(mTasksSurfaceView.getParent());
assertEquals(mTasksSurfaceView.getVisibility(), View.VISIBLE);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(20, layoutParams.topMargin);
ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams.height);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, false);
assertNotNull(mTasksSurfaceView.getParent());
......@@ -178,7 +181,6 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
assertFalse(mPropertyModel.get(IS_SHOWING_OVERVIEW));
assertFalse(mPropertyModel.get(IS_SECONDARY_SURFACE_VISIBLE));
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
// null, since this should be handled in the *ViewBinder.
......@@ -186,11 +188,11 @@ public class SecondaryTasksSurfaceViewBinderTest extends DummyUiActivityTestCase
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
mPropertyModel.set(IS_SECONDARY_SURFACE_VISIBLE, true);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals("Top margin isn't initialized correctly.", 20, layoutParams.topMargin);
ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals("Top margin isn't initialized correctly.", 20, layoutParams.height);
layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
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;
@RunWith(ChromeJUnit4ClassRunner.class)
public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
private ViewGroup mParentView;
private View mTasksSurfaceView;
private ViewGroup mTasksSurfaceView;
private View mTopToolbarPlaceholderView;
private PropertyModel mPropertyModel;
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private PropertyModelChangeProcessor mPropertyModelChangeProcessor;
......@@ -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
// for the TasksSurfaceViewBinder.
mParentView = new FrameLayout(getActivity());
mTasksSurfaceView = new View(getActivity());
mTasksSurfaceView = new FrameLayout(getActivity());
mTopToolbarPlaceholderView = new View(getActivity());
mTasksSurfaceView.addView(mTopToolbarPlaceholderView);
getActivity().setContentView(mParentView);
});
mPropertyModel = new PropertyModel(StartSurfaceProperties.ALL_KEYS);
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(mPropertyModel,
new TasksSurfaceViewBinder.ViewHolder(mParentView, mTasksSurfaceView),
new TasksSurfaceViewBinder.ViewHolder(
mParentView, mTasksSurfaceView, mTopToolbarPlaceholderView),
TasksSurfaceViewBinder::bind);
}
......@@ -74,7 +78,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
assertNotNull(mTasksSurfaceView.getParent());
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(10, layoutParams.bottomMargin);
assertEquals(20, layoutParams.topMargin);
ViewGroup.LayoutParams layoutParams1 = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams1.height);
mPropertyModel.set(IS_SHOWING_OVERVIEW, false);
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
......@@ -97,7 +102,8 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
assertNotNull(mTasksSurfaceView.getParent());
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
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);
assertEquals(mTasksSurfaceView.getVisibility(), View.GONE);
......@@ -132,11 +138,11 @@ public class TasksSurfaceViewBinderTest extends DummyUiActivityTestCase {
public void testSetTopBarHeight() {
mPropertyModel.set(TOP_MARGIN, 10);
mPropertyModel.set(IS_SHOWING_OVERVIEW, true);
MarginLayoutParams layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(10, layoutParams.topMargin);
ViewGroup.LayoutParams layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(10, layoutParams.height);
mPropertyModel.set(TOP_MARGIN, 20);
layoutParams = (MarginLayoutParams) mTasksSurfaceView.getLayoutParams();
assertEquals(20, layoutParams.topMargin);
layoutParams = mTopToolbarPlaceholderView.getLayoutParams();
assertEquals(20, layoutParams.height);
}
}
......@@ -15,6 +15,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
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
android:id="@+id/scroll_component_container"
android:layout_width="wrap_content"
......
......@@ -65,6 +65,11 @@ public interface TasksSurface {
*/
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
* require native initialization should be constructed here.
......
......@@ -142,6 +142,11 @@ public class TasksSurfaceCoordinator implements TasksSurface {
return mView;
}
@Override
public View getTopToolbarPlaceholderView() {
return mView != null ? mView.findViewById(R.id.top_toolbar_placeholder) : null;
}
@Override
public void onFinishNativeInitialization(Context context, FakeboxDelegate fakeboxDelegate) {
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