Commit 208cecbe authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Polish tab-to-grid transition animation in StartSurface (1)

Originally, the TabListSceneLayer that shows during tab-to-grid
transition puts the tab switcher bitmap right below the top toolbar.
This looks correct for normal layout but is no longer true for
StartSurface, because for StartSurface there are components that locate
above tab switcher. This CL adds a top offset so that we can adjust the
position of the tab switcher bitmap based on the real position of
tab switcher within the layout.

Bug: 995423
Change-Id: I23bf25d3c01a20410a921dcef9a9de947d554c29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1921704
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718379}
parent 5a8043a6
...@@ -446,7 +446,7 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM ...@@ -446,7 +446,7 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM
layerTitleCache, tabContentManager, resourceManager, fullscreenManager, layerTitleCache, tabContentManager, resourceManager, fullscreenManager,
TabFeatureUtilities.isTabToGtsAnimationEnabled() ? mTabListDelegate.getResourceId() TabFeatureUtilities.isTabToGtsAnimationEnabled() ? mTabListDelegate.getResourceId()
: 0, : 0,
mBackgroundAlpha); mBackgroundAlpha, mStartSurface.getTabListDelegate().getTabListTopOffset());
mFrameCount++; mFrameCount++;
if (mLastFrameTime != 0) { if (mLastFrameTime != 0) {
long elapsed = SystemClock.elapsedRealtime() - mLastFrameTime; long elapsed = SystemClock.elapsedRealtime() - mLastFrameTime;
......
...@@ -8,6 +8,7 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties. ...@@ -8,6 +8,7 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW; import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.IS_SHOWING_OVERVIEW;
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_BAR_HEIGHT; import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_BAR_HEIGHT;
import android.animation.ObjectAnimator;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.MarginLayoutParams;
...@@ -17,6 +18,8 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -17,6 +18,8 @@ import org.chromium.ui.modelutil.PropertyModel;
/** The binder controls the display of the {@link TasksView} in its parent. */ /** The binder controls the display of the {@link TasksView} in its parent. */
class TasksSurfaceViewBinder { class TasksSurfaceViewBinder {
private static final long FADE_IN_DURATION_MS = 50;
/** /**
* The view holder holds the parent view and the tasks surface view. * The view holder holds the parent view and the tasks surface view.
*/ */
...@@ -48,7 +51,19 @@ class TasksSurfaceViewBinder { ...@@ -48,7 +51,19 @@ class TasksSurfaceViewBinder {
layoutParams.topMargin = model.get(TOP_BAR_HEIGHT); layoutParams.topMargin = model.get(TOP_BAR_HEIGHT);
} }
viewHolder.tasksSurfaceView.setVisibility(isShowing ? View.VISIBLE : View.GONE); View taskSurfaceView = viewHolder.tasksSurfaceView;
if (!isShowing) {
taskSurfaceView.setVisibility(View.GONE);
} else {
// TODO(yuezhanggg): Figure out why there is a blink in the tab switcher part when
// showing overview mode. (crbug.com/995423)
taskSurfaceView.setAlpha(0f);
taskSurfaceView.setVisibility(View.VISIBLE);
final ObjectAnimator taskSurfaceFadeInAnimator =
ObjectAnimator.ofFloat(taskSurfaceView, View.ALPHA, 0f, 1f);
taskSurfaceFadeInAnimator.setDuration(FADE_IN_DURATION_MS);
taskSurfaceFadeInAnimator.start();
}
} }
private static void setBottomBarHeight(ViewHolder viewHolder, int height) { private static void setBottomBarHeight(ViewHolder viewHolder, int height) {
......
...@@ -22,6 +22,8 @@ import androidx.annotation.IntDef; ...@@ -22,6 +22,8 @@ import androidx.annotation.IntDef;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.browser.lifecycle.Destroyable; import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -71,6 +73,7 @@ public class TabListCoordinator implements Destroyable { ...@@ -71,6 +73,7 @@ public class TabListCoordinator implements Destroyable {
private final SimpleRecyclerViewAdapter mAdapter; private final SimpleRecyclerViewAdapter mAdapter;
private final @TabListMode int mMode; private final @TabListMode int mMode;
private final Rect mThumbnailLocationOfCurrentTab = new Rect(); private final Rect mThumbnailLocationOfCurrentTab = new Rect();
private final Context mContext;
/** /**
* Construct a coordinator for UI that shows a list of tabs. * Construct a coordinator for UI that shows a list of tabs.
...@@ -109,6 +112,7 @@ public class TabListCoordinator implements Destroyable { ...@@ -109,6 +112,7 @@ public class TabListCoordinator implements Destroyable {
@NonNull ViewGroup parentView, @Nullable DynamicResourceLoader dynamicResourceLoader, @NonNull ViewGroup parentView, @Nullable DynamicResourceLoader dynamicResourceLoader,
boolean attachToParent, String componentName) { boolean attachToParent, String componentName) {
mMode = mode; mMode = mode;
mContext = context;
TabListModel modelList = new TabListModel(); TabListModel modelList = new TabListModel();
mAdapter = new SimpleRecyclerViewAdapter(modelList); mAdapter = new SimpleRecyclerViewAdapter(modelList);
RecyclerView.RecyclerListener recyclerListener = null; RecyclerView.RecyclerListener recyclerListener = null;
...@@ -258,10 +262,28 @@ public class TabListCoordinator implements Destroyable { ...@@ -258,10 +262,28 @@ public class TabListCoordinator implements Destroyable {
Rect rect = mRecyclerView.getRectOfCurrentThumbnail( Rect rect = mRecyclerView.getRectOfCurrentThumbnail(
mMediator.indexOfTab(mMediator.selectedTabId()), mMediator.selectedTabId()); mMediator.indexOfTab(mMediator.selectedTabId()), mMediator.selectedTabId());
if (rect == null) return false; if (rect == null) return false;
rect.offset(0, getTabListTopOffset());
mThumbnailLocationOfCurrentTab.set(rect); mThumbnailLocationOfCurrentTab.set(rect);
return true; return true;
} }
/**
* @return The top offset from top toolbar to the tab list recycler view. Used to adjust the
* animations for tab switcher.
*/
int getTabListTopOffset() {
if (!FeatureUtilities.isStartSurfaceEnabled()) return 0;
Rect tabListRect = getRecyclerViewLocation();
Rect parentRect = new Rect();
((ChromeActivity) mContext).getCompositorViewHolder().getGlobalVisibleRect(parentRect);
// Offset by CompositeViewHolder top offset and top toolbar height.
tabListRect.offset(0,
-parentRect.top
- (int) mContext.getResources().getDimension(
R.dimen.toolbar_height_no_shadow));
return tabListRect.top;
}
/** /**
* @return The container {@link android.support.v7.widget.RecyclerView} that is showing the * @return The container {@link android.support.v7.widget.RecyclerView} that is showing the
* tab list UI. * tab list UI.
......
...@@ -180,6 +180,12 @@ public interface TabSwitcher { ...@@ -180,6 +180,12 @@ public interface TabSwitcher {
*/ */
@VisibleForTesting @VisibleForTesting
int getCleanupDelayForTesting(); int getCleanupDelayForTesting();
/**
* @return The top offset from top toolbar to tab list. Used to adjust the animations for
* tab switcher.
*/
int getTabListTopOffset();
} }
/** /**
......
...@@ -198,6 +198,11 @@ public class TabSwitcherCoordinator ...@@ -198,6 +198,11 @@ public class TabSwitcherCoordinator
return this; return this;
} }
@Override
public int getTabListTopOffset() {
return mTabListCoordinator.getTabListTopOffset();
}
@Override @Override
public boolean prepareOverview() { public boolean prepareOverview() {
boolean quick = mMediator.prepareOverview(); boolean quick = mMediator.prepareOverview();
......
...@@ -404,7 +404,7 @@ public class ToolbarSwipeLayout extends Layout { ...@@ -404,7 +404,7 @@ public class ToolbarSwipeLayout extends Layout {
// contentViewport is intentionally passed for both parameters below. // contentViewport is intentionally passed for both parameters below.
mSceneLayer.pushLayers(getContext(), contentViewport, contentViewport, this, mSceneLayer.pushLayers(getContext(), contentViewport, contentViewport, this,
layerTitleCache, tabContentManager, resourceManager, fullscreenManager, layerTitleCache, tabContentManager, resourceManager, fullscreenManager,
SceneLayer.INVALID_RESOURCE_ID, 0); SceneLayer.INVALID_RESOURCE_ID, 0, 0);
} }
/** /**
......
...@@ -457,6 +457,6 @@ public class SimpleAnimationLayout extends Layout { ...@@ -457,6 +457,6 @@ public class SimpleAnimationLayout extends Layout {
// The content viewport is intentionally sent as both params below. // The content viewport is intentionally sent as both params below.
mSceneLayer.pushLayers(getContext(), contentViewport, contentViewport, this, mSceneLayer.pushLayers(getContext(), contentViewport, contentViewport, this,
layerTitleCache, tabContentManager, resourceManager, fullscreenManager, layerTitleCache, tabContentManager, resourceManager, fullscreenManager,
SceneLayer.INVALID_RESOURCE_ID, 0); SceneLayer.INVALID_RESOURCE_ID, 0, 0);
} }
} }
...@@ -1590,7 +1590,7 @@ public abstract class StackLayoutBase extends Layout { ...@@ -1590,7 +1590,7 @@ public abstract class StackLayoutBase extends Layout {
mSceneLayer.pushLayers(getContext(), viewport, contentViewport, this, layerTitleCache, mSceneLayer.pushLayers(getContext(), viewport, contentViewport, this, layerTitleCache,
tabContentManager, resourceManager, fullscreenManager, tabContentManager, resourceManager, fullscreenManager,
SceneLayer.INVALID_RESOURCE_ID, 0); SceneLayer.INVALID_RESOURCE_ID, 0, 0);
} }
/** /**
......
...@@ -55,11 +55,14 @@ public class TabListSceneLayer extends SceneLayer { ...@@ -55,11 +55,14 @@ public class TabListSceneLayer extends SceneLayer {
* @param fullscreenManager The fullscreen manager for browser controls information. * @param fullscreenManager The fullscreen manager for browser controls information.
* @param backgroundResourceId The resource ID for background. {@link #INVALID_RESOURCE_ID} if * @param backgroundResourceId The resource ID for background. {@link #INVALID_RESOURCE_ID} if
* none. Only used in GridTabSwitcher. * none. Only used in GridTabSwitcher.
* @param backgroundAlpha The alpha of the background. Only used in GridTabSwitcher.
* @param backgroundTopOffset The top offset of the background. Only used in GridTabSwitcher.
*
*/ */
public void pushLayers(Context context, RectF viewport, RectF contentViewport, Layout layout, public void pushLayers(Context context, RectF viewport, RectF contentViewport, Layout layout,
LayerTitleCache layerTitleCache, TabContentManager tabContentManager, LayerTitleCache layerTitleCache, TabContentManager tabContentManager,
ResourceManager resourceManager, ChromeFullscreenManager fullscreenManager, ResourceManager resourceManager, ChromeFullscreenManager fullscreenManager,
int backgroundResourceId, float backgroundAlpha) { int backgroundResourceId, float backgroundAlpha, int backgroundTopOffset) {
if (mNativePtr == 0) return; if (mNativePtr == 0) return;
Resources res = context.getResources(); Resources res = context.getResources();
...@@ -76,8 +79,8 @@ public class TabListSceneLayer extends SceneLayer { ...@@ -76,8 +79,8 @@ public class TabListSceneLayer extends SceneLayer {
tabContentManager, resourceManager); tabContentManager, resourceManager);
if (backgroundResourceId != INVALID_RESOURCE_ID) { if (backgroundResourceId != INVALID_RESOURCE_ID) {
TabListSceneLayerJni.get().putBackgroundLayer( TabListSceneLayerJni.get().putBackgroundLayer(mNativePtr, TabListSceneLayer.this,
mNativePtr, TabListSceneLayer.this, backgroundResourceId, backgroundAlpha); backgroundResourceId, backgroundAlpha, backgroundTopOffset);
} }
boolean isHTSEnabled = boolean isHTSEnabled =
...@@ -213,6 +216,6 @@ public class TabListSceneLayer extends SceneLayer { ...@@ -213,6 +216,6 @@ public class TabListSceneLayer extends SceneLayer {
float sideBorderScale, boolean insetVerticalBorder); float sideBorderScale, boolean insetVerticalBorder);
void putBackgroundLayer(long nativeTabListSceneLayer, TabListSceneLayer caller, void putBackgroundLayer(long nativeTabListSceneLayer, TabListSceneLayer caller,
int resourceId, float alpha); int resourceId, float alpha, int topOffset);
} }
} }
...@@ -203,7 +203,8 @@ void TabListSceneLayer::PutBackgroundLayer( ...@@ -203,7 +203,8 @@ void TabListSceneLayer::PutBackgroundLayer(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& jobj, const base::android::JavaParamRef<jobject>& jobj,
jint resource_id, jint resource_id,
jfloat alpha) { jfloat alpha,
jint top_offset) {
int ui_resource_id = resource_manager_->GetUIResourceId( int ui_resource_id = resource_manager_->GetUIResourceId(
ui::ANDROID_RESOURCE_TYPE_DYNAMIC, resource_id); ui::ANDROID_RESOURCE_TYPE_DYNAMIC, resource_id);
if (ui_resource_id == 0) if (ui_resource_id == 0)
...@@ -222,6 +223,7 @@ void TabListSceneLayer::PutBackgroundLayer( ...@@ -222,6 +223,7 @@ void TabListSceneLayer::PutBackgroundLayer(
->size(); ->size();
background_layer_->SetBounds(size); background_layer_->SetBounds(size);
background_layer_->SetOpacity(alpha); background_layer_->SetOpacity(alpha);
background_layer_->SetPosition(gfx::PointF(0, top_offset));
} }
void TabListSceneLayer::OnDetach() { void TabListSceneLayer::OnDetach() {
......
...@@ -111,7 +111,8 @@ class TabListSceneLayer : public SceneLayer { ...@@ -111,7 +111,8 @@ class TabListSceneLayer : public SceneLayer {
void PutBackgroundLayer(JNIEnv* env, void PutBackgroundLayer(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jobj, const base::android::JavaParamRef<jobject>& jobj,
jint resource_id, jint resource_id,
jfloat alpha); jfloat alpha,
jint top_offset);
void OnDetach() override; void OnDetach() override;
bool ShouldShowBackground() override; bool ShouldShowBackground() override;
......
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