Commit 873d6630 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

[Home] Fix location bar layout translation X

Changes the location bar translation X when the location bar is RTL, and
uses #getLeftPositionOfLocationBarBackground() directly rather than
relying on a variable. Previously the variable was set when
an #onDraw() called #getLeftPositionOfLocationBarBackground(); this
resulted in #updateToolbarButtonVisibility() using a stale value.

BUG=740058

Change-Id: I410dd20b7ddb0ff796935e854fd4fbd17b703d37
Reviewed-on: https://chromium-review.googlesource.com/565025Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485316}
parent 9c85ac23
......@@ -159,12 +159,6 @@ public class BottomToolbarPhone extends ToolbarPhone {
/** Whether the disappearance of the toolbar buttons is currently animating. */
private boolean mAnimatingToolbarButtonDisappearance;
/** The current left position of the location bar background. */
private int mLocationBarBackgroundLeftPosition;
/** The current right position of the location bar background. */
private int mLocationBarBackgroundRightPosition;
/**
* Constructs a BottomToolbarPhone object.
* @param context The Context in which this View object is created.
......@@ -356,31 +350,25 @@ public class BottomToolbarPhone extends ToolbarPhone {
@Override
protected int getLeftPositionOfLocationBarBackground(VisualState visualState) {
if (!mAnimatingToolbarButtonAppearance && !mAnimatingToolbarButtonDisappearance) {
mLocationBarBackgroundLeftPosition =
super.getLeftPositionOfLocationBarBackground(visualState);
return super.getLeftPositionOfLocationBarBackground(visualState);
} else {
int targetPosition = getViewBoundsLeftOfLocationBar(visualState);
int currentPosition = targetPosition + getLocationBarBackgroundLeftOffset();
mLocationBarBackgroundLeftPosition = (int) MathUtils.interpolate(
return (int) MathUtils.interpolate(
targetPosition, currentPosition, mToolbarButtonVisibilityPercent);
}
return mLocationBarBackgroundLeftPosition;
}
@Override
protected int getRightPositionOfLocationBarBackground(VisualState visualState) {
if (!mAnimatingToolbarButtonAppearance && !mAnimatingToolbarButtonDisappearance) {
mLocationBarBackgroundRightPosition =
super.getRightPositionOfLocationBarBackground(visualState);
return super.getRightPositionOfLocationBarBackground(visualState);
} else {
int targetPosition = getViewBoundsRightOfLocationBar(visualState);
int currentPosition = targetPosition - getLocationBarBackgroundRightOffset();
mLocationBarBackgroundRightPosition = (int) MathUtils.interpolate(
return (int) MathUtils.interpolate(
targetPosition, currentPosition, mToolbarButtonVisibilityPercent);
}
return mLocationBarBackgroundRightPosition;
}
private int getLocationBarBackgroundLeftOffset() {
......@@ -733,18 +721,28 @@ public class BottomToolbarPhone extends ToolbarPhone {
float locationBarTranslationX;
boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar);
int currentLeftMargin = locationBarLayoutParams.leftMargin;
int currentWidth = locationBarLayoutParams.width;
if (isLocationBarRtl) {
locationBarTranslationX = mLocationBarBackgroundRightPosition
- mUnfocusedLocationBarLayoutWidth - mUnfocusedLocationBarLayoutLeft;
} else {
// The location bar contents should be aligned with the right side of the toolbar.
// If RTL text is displayed in an LTR toolbar, the right position of the location bar
// background will change as the location bar background expands/contracts.
locationBarTranslationX =
mUnfocusedLocationBarLayoutLeft + mLocationBarBackgroundLeftPosition;
-currentWidth + getRightPositionOfLocationBarBackground(mVisualState);
if (!mHasVisibleViewPriorToUrlBar) locationBarTranslationX -= mToolbarSidePadding;
} else {
// The location bar contents should be aligned with the left side of the location bar
// background. If LTR text is displayed in an RTL toolbar, the current left position of
// the location bar background will change as the location bar background
// expands/contracts.
locationBarTranslationX = mUnfocusedLocationBarLayoutLeft
+ getLeftPositionOfLocationBarBackground(mVisualState) - mToolbarSidePadding;
}
FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar);
int currentLeftMargin = locationBarLayoutParams.leftMargin;
locationBarTranslationX -= (currentLeftMargin + mToolbarSidePadding);
locationBarTranslationX -= currentLeftMargin;
// Get the padding straight from the location bar instead of
// |mLocationBarBackgroundPadding|, because it might be different in incognito mode.
......
......@@ -188,6 +188,8 @@ public class ToolbarPhone extends ToolbarLayout
protected boolean mLayoutLocationBarInFocusedMode;
protected int mUnfocusedLocationBarLayoutWidth;
protected int mUnfocusedLocationBarLayoutLeft;
protected int mUnfocusedLocationBarLayoutRight;
protected boolean mHasVisibleViewPriorToUrlBar;
private boolean mUnfocusedLocationBarUsesTransparentBg;
private int mLocationBarBackgroundAlpha = 255;
......@@ -260,7 +262,7 @@ public class ToolbarPhone extends ToolbarLayout
NEW_TAB_NORMAL
}
private VisualState mVisualState = VisualState.NORMAL;
protected VisualState mVisualState = VisualState.NORMAL;
private VisualState mOverlayDrawablesVisualState;
protected boolean mUseLightToolbarDrawables;
......@@ -529,12 +531,12 @@ public class ToolbarPhone extends ToolbarLayout
}
private void updateUnfocusedLocationBarLayoutParams() {
boolean hasVisibleViewPriorToUrlBar = false;
mHasVisibleViewPriorToUrlBar = false;
for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View child = mLocationBar.getChildAt(i);
if (child == mUrlBar) break;
if (child.getVisibility() != GONE) {
hasVisibleViewPriorToUrlBar = true;
mHasVisibleViewPriorToUrlBar = true;
break;
}
}
......@@ -542,7 +544,7 @@ public class ToolbarPhone extends ToolbarLayout
int leftViewBounds = getViewBoundsLeftOfLocationBar(mVisualState);
int rightViewBounds = getViewBoundsRightOfLocationBar(mVisualState);
if (!hasVisibleViewPriorToUrlBar) {
if (!mHasVisibleViewPriorToUrlBar) {
if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
rightViewBounds -= mToolbarSidePadding;
} else {
......@@ -561,6 +563,7 @@ public class ToolbarPhone extends ToolbarLayout
mUnfocusedLocationBarLayoutWidth = rightViewBounds - leftViewBounds;
mUnfocusedLocationBarLayoutLeft = leftViewBounds;
mUnfocusedLocationBarLayoutRight = rightViewBounds;
}
/**
......
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