Commit 76aa2e6f authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Replace screen height usage with parent view height in tab_ui

http://crrev.com/c/2012901 this CL uses DisplayAndroid to get screen
height as preparation for upcoming android R. However, the new way of
fetching screen height includes the top and bottom bar height, which is
different from the setup we use in tab_ui. This CL fixes this issue.

Bug: 1046395
Change-Id: If0bf151a90147b237cf8f41806e1d42b0ff70d1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2023250
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747788}
parent 0e23387a
...@@ -39,7 +39,6 @@ import org.chromium.base.ContextUtils; ...@@ -39,7 +39,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.widget.ScrimView; import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.components.browser_ui.widget.animation.Interpolators; import org.chromium.components.browser_ui.widget.animation.Interpolators;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.ui.interpolators.BakedBezierInterpolator; import org.chromium.ui.interpolators.BakedBezierInterpolator;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -63,37 +62,12 @@ public class TabGridDialogParent ...@@ -63,37 +62,12 @@ public class TabGridDialogParent
int NUM_ENTRIES = 3; int NUM_ENTRIES = 3;
} }
/** Params that define information about the origin tab grid card of the show/hide animation. */
public static class AnimationParams {
/**
* The {@link Rect} of origin tab grid card of the current tab, relative to the
* {@link TabListRecyclerView} coordinates.
*/
public final Rect sourceRect;
/**
* The {@link View} that is the item view of origin tab grid card in the {@link
* TabListRecyclerView}.
*/
public final View sourceView;
/**
* Build a new set of params to setup the animation.
* @param sourceRect The {@link Rect} that is the origin rect relative to the {@link
* TabListRecyclerView} coordinates.
* @param sourceView The {@link View} that is the item view of origin tab grid card in the
* {@link TabListRecyclerView}.
*/
AnimationParams(Rect sourceRect, View sourceView) {
this.sourceRect = sourceRect;
this.sourceView = sourceView;
}
}
private final ComponentCallbacks mComponentCallbacks; private final ComponentCallbacks mComponentCallbacks;
private final FrameLayout.LayoutParams mContainerParams; private final FrameLayout.LayoutParams mContainerParams;
private final ViewGroup mParent; private final ViewGroup mParent;
private final int mToolbarHeight; private final int mToolbarHeight;
private final int mScreenHeight; private final int mParentViewHeight;
private final int mScreenWidth; private final int mParentViewWidth;
private final int mUngroupBarHeight; private final int mUngroupBarHeight;
private final float mTabGridCardPadding; private final float mTabGridCardPadding;
private PopupWindow mPopupWindow; private PopupWindow mPopupWindow;
...@@ -119,8 +93,8 @@ public class TabGridDialogParent ...@@ -119,8 +93,8 @@ public class TabGridDialogParent
private AnimatorListenerAdapter mHideDialogAnimationListener; private AnimatorListenerAdapter mHideDialogAnimationListener;
private int mSideMargin; private int mSideMargin;
private int mTopMargin; private int mTopMargin;
private int mCurrentScreenHeight; private int mParentViewCurrentHeight;
private int mCurrentScreenWidth; private int mParentViewCurrentWidth;
private int mOrientation; private int mOrientation;
private int mUngroupBarStatus = UngroupBarStatus.HIDE; private int mUngroupBarStatus = UngroupBarStatus.HIDE;
private int mUngroupBarBackgroundColorResourceId = R.color.tab_grid_dialog_background_color; private int mUngroupBarBackgroundColorResourceId = R.color.tab_grid_dialog_background_color;
...@@ -139,10 +113,9 @@ public class TabGridDialogParent ...@@ -139,10 +113,9 @@ public class TabGridDialogParent
(int) context.getResources().getDimension(R.dimen.bottom_sheet_peek_height); (int) context.getResources().getDimension(R.dimen.bottom_sheet_peek_height);
mContainerParams = new FrameLayout.LayoutParams( mContainerParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
DisplayAndroid display = DisplayAndroid.getNonMultiDisplay(context); // Parent view height and width when in portrait mode.
// Screen height and width when in portrait mode. mParentViewHeight = Math.max(mParent.getHeight(), mParent.getWidth());
mScreenHeight = Math.max(display.getDisplayHeight(), display.getDisplayWidth()); mParentViewWidth = Math.min(mParent.getHeight(), mParent.getWidth());
mScreenWidth = Math.min(display.getDisplayHeight(), display.getDisplayWidth());
mComponentCallbacks = new ComponentCallbacks() { mComponentCallbacks = new ComponentCallbacks() {
@Override @Override
...@@ -302,9 +275,8 @@ public class TabGridDialogParent ...@@ -302,9 +275,8 @@ public class TabGridDialogParent
updateAnimationCardView(mItemView); updateAnimationCardView(mItemView);
// Calculate dialog size. // Calculate dialog size.
int statusBarHeight = mCurrentScreenHeight - mParent.getHeight(); int dialogHeight = mParent.getHeight() - 2 * mTopMargin;
int dialogHeight = mCurrentScreenHeight - 2 * mTopMargin - statusBarHeight; int dialogWidth = mParent.getWidth() - 2 * mSideMargin;
int dialogWidth = mCurrentScreenWidth - 2 * mSideMargin;
// Calculate position and size info about the original tab grid card. // Calculate position and size info about the original tab grid card.
float sourceLeft = rect.left + mTabGridCardPadding; float sourceLeft = rect.left + mTabGridCardPadding;
...@@ -554,15 +526,15 @@ public class TabGridDialogParent ...@@ -554,15 +526,15 @@ public class TabGridDialogParent
(int) context.getResources().getDimension(R.dimen.tab_grid_dialog_side_margin); (int) context.getResources().getDimension(R.dimen.tab_grid_dialog_side_margin);
mTopMargin = mTopMargin =
(int) context.getResources().getDimension(R.dimen.tab_grid_dialog_top_margin); (int) context.getResources().getDimension(R.dimen.tab_grid_dialog_top_margin);
mCurrentScreenHeight = mScreenHeight; mParentViewCurrentHeight = mParentViewHeight;
mCurrentScreenWidth = mScreenWidth; mParentViewCurrentWidth = mParentViewWidth;
} else { } else {
mSideMargin = mSideMargin =
(int) context.getResources().getDimension(R.dimen.tab_grid_dialog_top_margin); (int) context.getResources().getDimension(R.dimen.tab_grid_dialog_top_margin);
mTopMargin = mTopMargin =
(int) context.getResources().getDimension(R.dimen.tab_grid_dialog_side_margin); (int) context.getResources().getDimension(R.dimen.tab_grid_dialog_side_margin);
mCurrentScreenWidth = mScreenHeight; mParentViewCurrentWidth = mParentViewHeight;
mCurrentScreenHeight = mScreenWidth; mParentViewCurrentHeight = mParentViewWidth;
} }
mContainerParams.setMargins(mSideMargin, mTopMargin, mSideMargin, mTopMargin); mContainerParams.setMargins(mSideMargin, mTopMargin, mSideMargin, mTopMargin);
mOrientation = orientation; mOrientation = orientation;
...@@ -671,8 +643,8 @@ public class TabGridDialogParent ...@@ -671,8 +643,8 @@ public class TabGridDialogParent
// Get the status bar height as offset. // Get the status bar height as offset.
Rect parentRect = new Rect(); Rect parentRect = new Rect();
mParent.getGlobalVisibleRect(parentRect); mParent.getGlobalVisibleRect(parentRect);
return new Rect(mSideMargin, mTopMargin + parentRect.top, mCurrentScreenWidth - mSideMargin, return new Rect(mSideMargin, mTopMargin + parentRect.top,
mCurrentScreenHeight - mTopMargin); mParentViewCurrentWidth - mSideMargin, mParentViewCurrentHeight - mTopMargin);
} }
/** /**
......
...@@ -25,7 +25,6 @@ import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat; ...@@ -25,7 +25,6 @@ import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
import org.chromium.chrome.browser.widget.ScrimView; import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.ui.display.DisplayAndroid;
/** /**
* Represents a parent component for TabGridIph related UIs. * Represents a parent component for TabGridIph related UIs.
...@@ -145,12 +144,12 @@ public class TabGridIphDialogParent { ...@@ -145,12 +144,12 @@ public class TabGridIphDialogParent {
} }
private void updateMargins(int orientation) { private void updateMargins(int orientation) {
int screenHeight = DisplayAndroid.getNonMultiDisplay(mContext).getDisplayHeight(); int parentViewHeight = mParentView.getHeight();
int dialogHeight = int dialogHeight =
(int) mContext.getResources().getDimension(R.dimen.tab_grid_iph_dialog_height); (int) mContext.getResources().getDimension(R.dimen.tab_grid_iph_dialog_height);
// Dynamically setup the top margin base on screen height, the minimum top margin is // Dynamically setup the top margin base on parent view height, the minimum top margin is
// specified in case the screen height is smaller than or too close to dialog height. // specified in case the parent view height is smaller than or too close to dialog height.
int updatedDialogTopMargin = Math.max((screenHeight - dialogHeight) / 2, int updatedDialogTopMargin = Math.max((parentViewHeight - dialogHeight) / 2,
(int) mContext.getResources().getDimension(R.dimen.tab_grid_iph_dialog_top_margin)); (int) mContext.getResources().getDimension(R.dimen.tab_grid_iph_dialog_top_margin));
int dialogTopMargin; int dialogTopMargin;
......
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