Commit 0b360c78 authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Straightforward generalizations in StackLayout to support more than two stacks

I have a series of CLs in progress to allow StackLayout to support more than two
tab stacks. This CL contains easy generalizations (e.g. adding loops) of
existing logic that currently assumes there will always be exactly two tab
stacks.

Updating the geometry logic is more involved, so I will do that in a separate
CL.

Bug: 648314
Change-Id: I8613cdd5ec345dfa868d992575c5d8d560ca5b04
Reviewed-on: https://chromium-review.googlesource.com/940570Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542181}
parent 07b983e8
...@@ -418,8 +418,9 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -418,8 +418,9 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
* @param time The current time of the app in ms. * @param time The current time of the app in ms.
*/ */
public void commitOutstandingModelState(long time) { public void commitOutstandingModelState(long time) {
mStacks.get(1).ensureCleaningUpDyingTabs(time); for (int i = 0; i < mStacks.size(); i++) {
mStacks.get(0).ensureCleaningUpDyingTabs(time); mStacks.get(i).ensureCleaningUpDyingTabs(time);
}
} }
@Override @Override
...@@ -568,15 +569,21 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -568,15 +569,21 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
@Override @Override
public boolean onUpdateAnimation(long time, boolean jumpToEnd) { public boolean onUpdateAnimation(long time, boolean jumpToEnd) {
boolean animationsWasDone = super.onUpdateAnimation(time, jumpToEnd); boolean animationsWasDone = super.onUpdateAnimation(time, jumpToEnd);
boolean finishedView0 = mStacks.get(0).onUpdateViewAnimation(time, jumpToEnd);
boolean finishedView1 = mStacks.get(1).onUpdateViewAnimation(time, jumpToEnd); boolean finishedAllViews = true;
boolean finishedCompositor0 = mStacks.get(0).onUpdateCompositorAnimations(time, jumpToEnd); for (int i = 0; i < mStacks.size(); i++) {
boolean finishedCompositor1 = mStacks.get(1).onUpdateCompositorAnimations(time, jumpToEnd); finishedAllViews &= mStacks.get(i).onUpdateViewAnimation(time, jumpToEnd);
if (animationsWasDone && finishedView0 && finishedView1 && finishedCompositor0 }
&& finishedCompositor1) {
boolean finishedAllCompositors = true;
for (int i = 0; i < mStacks.size(); i++) {
finishedAllCompositors &= mStacks.get(i).onUpdateCompositorAnimations(time, jumpToEnd);
}
if (animationsWasDone && finishedAllViews && finishedAllCompositors) {
return true; return true;
} else { } else {
if (!animationsWasDone || !finishedCompositor0 || !finishedCompositor1) { if (!animationsWasDone || !finishedAllCompositors) {
requestStackUpdate(); requestStackUpdate();
} }
...@@ -773,18 +780,19 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -773,18 +780,19 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
} }
private void requestStackUpdate() { private void requestStackUpdate() {
// TODO(jgreenwald): It isn't always necessary to invalidate both // TODO(jgreenwald): It isn't always necessary to invalidate all stacks.
// stacks. for (int i = 0; i < mStacks.size(); i++) {
mStacks.get(0).requestUpdate(); mStacks.get(i).requestUpdate();
mStacks.get(1).requestUpdate(); }
} }
@Override @Override
public void notifySizeChanged(float width, float height, int orientation) { public void notifySizeChanged(float width, float height, int orientation) {
mCachedLandscapeViewport = null; mCachedLandscapeViewport = null;
mCachedPortraitViewport = null; mCachedPortraitViewport = null;
mStacks.get(0).notifySizeChanged(width, height, orientation); for (Stack stack : mStacks) {
mStacks.get(1).notifySizeChanged(width, height, orientation); stack.notifySizeChanged(width, height, orientation);
}
resetScrollData(); resetScrollData();
requestStackUpdate(); requestStackUpdate();
} }
...@@ -793,8 +801,9 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -793,8 +801,9 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
public void contextChanged(Context context) { public void contextChanged(Context context) {
super.contextChanged(context); super.contextChanged(context);
StackTab.resetDimensionConstants(context); StackTab.resetDimensionConstants(context);
mStacks.get(0).contextChanged(context); for (Stack stack : mStacks) {
mStacks.get(1).contextChanged(context); stack.contextChanged(context);
}
requestStackUpdate(); requestStackUpdate();
} }
...@@ -1049,16 +1058,28 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -1049,16 +1058,28 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
super.updateLayout(time, dt); super.updateLayout(time, dt);
boolean needUpdate = false; boolean needUpdate = false;
if (mStackRects.size() > mStacks.size()) {
mStackRects.subList(mStacks.size(), mStackRects.size()).clear();
}
while (mStackRects.size() < mStacks.size()) mStackRects.add(new RectF());
final PortraitViewport viewport = getViewportParameters(); final PortraitViewport viewport = getViewportParameters();
if (!mStackRects.isEmpty()) {
mStackRects.get(0).left = viewport.getStack0Left(); mStackRects.get(0).left = viewport.getStack0Left();
mStackRects.get(0).right = mStackRects.get(0).left + viewport.getWidth(); mStackRects.get(0).right = mStackRects.get(0).left + viewport.getWidth();
mStackRects.get(0).top = viewport.getStack0Top(); mStackRects.get(0).top = viewport.getStack0Top();
mStackRects.get(0).bottom = mStackRects.get(0).top + viewport.getHeight(); mStackRects.get(0).bottom = mStackRects.get(0).top + viewport.getHeight();
mStackRects.get(1).left = }
mStackRects.get(0).left + viewport.getStack0ToStack1TranslationX();
mStackRects.get(1).right = mStackRects.get(1).left + viewport.getWidth(); for (int i = 1; i < mStackRects.size(); i++) {
mStackRects.get(1).top = mStackRects.get(0).top + viewport.getStack0ToStack1TranslationY(); mStackRects.get(i).left =
mStackRects.get(1).bottom = mStackRects.get(1).top + viewport.getHeight(); mStackRects.get(i - 1).left + viewport.getStack0ToStack1TranslationX();
mStackRects.get(i).right = mStackRects.get(i).left + viewport.getWidth();
mStackRects.get(i).top =
mStackRects.get(i - 1).top + viewport.getStack0ToStack1TranslationY();
mStackRects.get(i).bottom = mStackRects.get(i).top + viewport.getHeight();
}
mStacks.get(0).setStackFocusInfo(1.0f + mRenderedScrollOffset, mStacks.get(0).setStackFocusInfo(1.0f + mRenderedScrollOffset,
mSortingComparator == mOrderComparator ? mTabModelSelector.getModel(false).index() mSortingComparator == mOrderComparator ? mTabModelSelector.getModel(false).index()
...@@ -1068,13 +1089,16 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -1068,13 +1089,16 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
: -1); : -1);
// Compute position and visibility // Compute position and visibility
mStacks.get(0).computeTabPosition(time, mStackRects.get(0)); for (int i = 0; i < mStacks.size(); i++) {
mStacks.get(1).computeTabPosition(time, mStackRects.get(1)); mStacks.get(i).computeTabPosition(time, mStackRects.get(i));
}
// Pre-allocate/resize {@link #mLayoutTabs} before it get populated by // Pre-allocate/resize {@link #mLayoutTabs} before it get populated by
// computeTabPositionAndAppendLayoutTabs. // computeTabPositionAndAppendLayoutTabs.
final int tabVisibleCount = int tabVisibleCount = 0;
mStacks.get(0).getVisibleCount() + mStacks.get(1).getVisibleCount(); for (int i = 0; i < mStacks.size(); i++) {
tabVisibleCount += mStacks.get(i).getVisibleCount();
}
int layoutTabCount = tabVisibleCount + (mNewTabLayoutTab == null ? 0 : 1); int layoutTabCount = tabVisibleCount + (mNewTabLayoutTab == null ? 0 : 1);
...@@ -1085,13 +1109,12 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -1085,13 +1109,12 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
} }
int index = 0; int index = 0;
if (getTabStackIndex() == 1) { for (int i = 0; i < mStacks.size(); i++) {
index = appendVisibleLayoutTabs(time, 0, mLayoutTabs, index); // Append tabs for the current stack last so they get priority in rendering.
index = appendVisibleLayoutTabs(time, 1, mLayoutTabs, index); if (getTabStackIndex() == i) continue;
} else { index = appendVisibleLayoutTabs(time, i, mLayoutTabs, index);
index = appendVisibleLayoutTabs(time, 1, mLayoutTabs, index);
index = appendVisibleLayoutTabs(time, 0, mLayoutTabs, index);
} }
index = appendVisibleLayoutTabs(time, getTabStackIndex(), mLayoutTabs, index);
assert index == tabVisibleCount : "index should be incremented up to tabVisibleCount"; assert index == tabVisibleCount : "index should be incremented up to tabVisibleCount";
// Update tab snapping // Update tab snapping
...@@ -1191,15 +1214,26 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper ...@@ -1191,15 +1214,26 @@ public class StackLayout extends Layout implements Animatable<StackLayout.Proper
} }
} }
/**
* Updates mSortedPriorityArray, which stores the list of StackTabs to render, sorted by
* rendering priority.
*
* @param comparator The comparator used to sort the StackTabs.
* @return True if at least one Stack has a tab, false if there are no tabs.
*/
private boolean updateSortedPriorityArray(Comparator<StackTab> comparator) { private boolean updateSortedPriorityArray(Comparator<StackTab> comparator) {
final int allTabsCount = mStacks.get(0).getCount() + mStacks.get(1).getCount(); int allTabsCount = 0;
for (int i = 0; i < mStacks.size(); i++) {
allTabsCount += mStacks.get(i).getCount();
}
if (allTabsCount == 0) return false; if (allTabsCount == 0) return false;
if (mSortedPriorityArray == null || mSortedPriorityArray.length != allTabsCount) { if (mSortedPriorityArray == null || mSortedPriorityArray.length != allTabsCount) {
mSortedPriorityArray = new StackTab[allTabsCount]; mSortedPriorityArray = new StackTab[allTabsCount];
} }
int sortedOffset = 0; int sortedOffset = 0;
sortedOffset = addAllTabs(mStacks.get(0), mSortedPriorityArray, sortedOffset); for (int i = 0; i < mStacks.size(); i++) {
sortedOffset = addAllTabs(mStacks.get(1), mSortedPriorityArray, sortedOffset); sortedOffset = addAllTabs(mStacks.get(i), mSortedPriorityArray, sortedOffset);
}
assert sortedOffset == mSortedPriorityArray.length; assert sortedOffset == mSortedPriorityArray.length;
Arrays.sort(mSortedPriorityArray, comparator); Arrays.sort(mSortedPriorityArray, comparator);
return true; return true;
......
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