Skip to content

Commit

Permalink
Remove StackLayout#canScrollLinearly()
Browse files Browse the repository at this point in the history
This method has two call sites. I was stuck for a while trying to understand
how they work, but it appears this method is actually completely unnecessary. I
can't find any change in behavior after removing it and cleaning up its call
sites.

Change-Id: I7ac62a9dbce34caba5f69da13427e7ef827c1074
Reviewed-on: https://chromium-review.googlesource.com/933061
Reviewed-by: David Trainor <dtrainor@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539317}
  • Loading branch information
rlanday authored and Commit Bot committed Feb 27, 2018
1 parent 1af4c93 commit c9385c0
Showing 1 changed file with 1 addition and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,18 +950,12 @@ private void scrollStacks(float delta) {
float fullDistance = getFullScrollDistance();
mScrollIndexOffset += MathUtils.flipSignIf(delta / fullDistance,
getOrientation() == Orientation.PORTRAIT && LocalizationUtils.isLayoutRtl());
if (canScrollLinearly(getTabStackIndex())) {
mRenderedScrollOffset = mScrollIndexOffset;
} else {
mRenderedScrollOffset = (int) MathUtils.clamp(
mScrollIndexOffset, 0, mStacks[1].isDisplayable() ? -1 : 0);
}
mRenderedScrollOffset = MathUtils.clamp(mScrollIndexOffset, 0, -1);
requestStackUpdate();
}

private void flingStacks(boolean toIncognito) {
// velocityX is measured in pixel per second.
if (!canScrollLinearly(toIncognito ? 0 : 1)) return;
setActiveStackState(toIncognito);
finishScrollStacks();
requestStackUpdate();
Expand Down Expand Up @@ -1105,22 +1099,6 @@ private void resetScrollData() {
mRenderedScrollOffset = mScrollIndexOffset;
}

/**
* Based on the current position, determine if we will map mScrollDistance linearly to
* mRenderedScrollDistance. The logic is, if there is only stack, we will not map linearly;
* if we are scrolling two the boundary of either of the stacks, we will not map linearly;
* otherwise yes.
*/
private boolean canScrollLinearly(int fromStackIndex) {
int count = mStacks.length;
if (!(mScrollIndexOffset <= 0 && -mScrollIndexOffset <= (count - 1))) {
return false;
}
// since we only have two stacks now, we have a shortcut to calculate
// empty stacks
return mStacks[fromStackIndex ^ 0x01].isDisplayable();
}

private float getFullScrollDistance() {
float distance = getOrientation() == Orientation.PORTRAIT ? getWidth()
: getHeightMinusBrowserControls();
Expand Down

0 comments on commit c9385c0

Please sign in to comment.