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