Commit 82b329f0 authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Add StackLayoutBase#setTabLists()

I'm splitting most of StackLayout into a base class in
https://chromium-review.googlesource.com/c/chromium/src/+/957875 to support
building UI prototypes on top of the tab switcher UI.

This CL cleans up the interface for child classes so that they don't have to
manually manage the list of Stacks. Instead, they can call a setTabList() method
with a list of TabLists, and StackLayoutBase will set up the Stacks accordingly.

Bug: 648314
Change-Id: I627da998baaf9d74e3fa14da3cf392097a6e0944
Reviewed-on: https://chromium-review.googlesource.com/961442Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543438}
parent 15302e6a
......@@ -9,13 +9,14 @@ import android.content.Context;
import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost;
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.compositor.layouts.phone.stack.Stack;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabList;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import java.util.ArrayList;
/**
* Layout that displays all normal tabs in one stack and all incognito tabs in a second.
*/
......@@ -36,22 +37,15 @@ public class StackLayout extends StackLayoutBase {
*/
public StackLayout(Context context, LayoutUpdateHost updateHost, LayoutRenderHost renderHost) {
super(context, updateHost, renderHost);
for (int i = 0; i < NUM_STACKS; i++) {
mStacks.add(new Stack(context, this));
}
}
@Override
public void setTabModelSelector(TabModelSelector modelSelector, TabContentManager manager) {
super.setTabModelSelector(modelSelector, manager);
mStacks.get(NORMAL_STACK_INDEX).setTabList(modelSelector.getModel(false));
mStacks.get(INCOGNITO_STACK_INDEX).setTabList(modelSelector.getModel(true));
}
@Override
protected TabList getTabList(int index) {
return mTabModelSelector.getModel(index == INCOGNITO_STACK_INDEX);
ArrayList<TabList> tabLists = new ArrayList<TabList>();
tabLists.add(modelSelector.getModel(false));
tabLists.add(modelSelector.getModel(true));
setTabLists(tabLists);
}
@Override
......
......@@ -49,6 +49,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
* Base class for layouts that show one or more stacks of tabs.
......@@ -96,7 +97,7 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
*/
private static final float SWITCH_STACK_FLING_DT = 1.0f / 30.0f;
/** The array of potentially visible stacks. */
/** The list of potentially visible stacks. */
protected final ArrayList<Stack> mStacks;
/** Rectangles that defines the area where each stack need to be laid out. */
......@@ -129,6 +130,10 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
private float mLastOnDownY;
private long mLastOnDownTimeStamp;
private float mWidth;
private float mHeight;
private int mOrientation;
// Pre-allocated temporary arrays that store id of visible tabs.
// They can be used to call populatePriorityVisibilityList.
// We use StackTab[] instead of ArrayList<StackTab> because the sorting function does
......@@ -310,6 +315,28 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
mSceneLayer = new TabListSceneLayer();
}
/**
* Updates this layout to show one tab stack for each of the passed-in TabLists. Takes a
* reference to the lists param and expects it not to change.
* @param lists The list of TabLists to use.
*/
protected void setTabLists(List<TabList> lists) {
if (mStacks.size() > lists.size()) {
mStacks.subList(lists.size(), lists.size()).clear();
}
while (mStacks.size() < lists.size()) {
Stack stack = new Stack(getContext(), this);
stack.notifySizeChanged(mWidth, mHeight, mOrientation);
mStacks.add(stack);
}
for (int i = 0; i < lists.size(); i++) {
mStacks.get(i).setTabList(lists.get(i));
}
// mStackRects will get updated in updateLayout()
}
@Override
public boolean forceShowBrowserControlsAndroidView() {
return true;
......@@ -352,8 +379,6 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
resetScrollData();
}
protected abstract TabList getTabList(int index);
/**
* Get the tab stack at the specified index.
*
......@@ -728,6 +753,9 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
@Override
public void notifySizeChanged(float width, float height, int orientation) {
mWidth = width;
mHeight = height;
mOrientation = orientation;
mCachedLandscapeViewport = null;
mCachedPortraitViewport = null;
for (Stack stack : mStacks) {
......@@ -1089,7 +1117,8 @@ public abstract class StackLayoutBase extends Layout implements Animatable<Stack
final float stackFocus = MathUtils.clamp(1 - scrollDistance, 0, 1);
mStacks.get(i).setStackFocusInfo(stackFocus,
mSortingComparator == mOrderComparator ? getTabList(i).index() : -1);
mSortingComparator == mOrderComparator ? mStacks.get(i).getTabList().index()
: -1);
}
// Compute position and visibility
......
......@@ -19,7 +19,7 @@ import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.compositor.layouts.Layout.Orientation;
import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.ScrollDirection;
import org.chromium.chrome.browser.compositor.layouts.phone.StackLayout;
import org.chromium.chrome.browser.compositor.layouts.phone.StackLayoutBase;
import org.chromium.chrome.browser.compositor.layouts.phone.stack.StackAnimation.OverviewAnimationType;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabList;
......@@ -231,7 +231,7 @@ public class Stack {
private Animator mViewAnimations;
// The parent Layout
private final StackLayout mLayout;
private final StackLayoutBase mLayout;
// Border values
private float mBorderTransparentTop;
......@@ -257,7 +257,7 @@ public class Stack {
/**
* @param layout The parent layout.
*/
public Stack(Context context, StackLayout layout) {
public Stack(Context context, StackLayoutBase layout) {
mLayout = layout;
contextChanged(context);
}
......@@ -269,6 +269,13 @@ public class Stack {
mTabList = tabList;
}
/**
* @return The TabList associated with this stack.
*/
public TabList getTabList() {
return mTabList;
}
/**
* @return The {@link StackTab}s currently being rendered by the tab stack.
* @VisibleForTesting
......@@ -2273,7 +2280,7 @@ public class Stack {
*/
public float getMaxTabHeight() {
if (FeatureUtilities.isChromeHomeEnabled() && mCurrentMode == Orientation.PORTRAIT) {
return mLayout.getHeightMinusBrowserControls() - StackLayout.MODERN_TOP_MARGIN_DP;
return mLayout.getHeightMinusBrowserControls() - StackLayoutBase.MODERN_TOP_MARGIN_DP;
}
return mLayout.getHeightMinusBrowserControls();
}
......
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