Commit be910707 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] Add setUrlFocusChangeFraction to LocationBar interface

LocationBarPhone and LocationBarTablet independently implement method
setUrlFocusChangePercent(float) which modified a protected
LocationBarLayout field. This is one of the simplest changes that
reduces the differences between Phone and Tablet LocationBar APIs.

Bug: 1133482
Change-Id: I4e9379786bb20009a10be2f812c15323d2c5c1b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438883
Commit-Queue: who/bttk <bttk@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812999}
parent 40e6324b
......@@ -842,6 +842,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText,
@LocationBar.OmniboxFocusReason int reason) {}
@Override
public void setUrlFocusChangeFraction(float fraction) {}
@Override
public boolean isCurrentPage(NativePage nativePage) {
return false;
......
......@@ -90,6 +90,13 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate {
*/
void updateVisualsForState();
/**
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
void setUrlFocusChangeFraction(float fraction);
/**
* Sets the displayed URL to be the URL of the page currently showing.
*
......
......@@ -24,6 +24,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.view.MarginLayoutParamsCompat;
......@@ -131,7 +132,7 @@ public class LocationBarLayout extends FrameLayout
private OmniboxPrerender mOmniboxPrerender;
protected float mUrlFocusChangePercent;
protected float mUrlFocusChangeFraction;
protected LinearLayout mUrlActionContainer;
private VoiceRecognitionHandler mVoiceRecognitionHandler;
......@@ -392,6 +393,12 @@ public class LocationBarLayout extends FrameLayout
setProfile(mProfileSupplier.get());
}
@Override
@CallSuper
public void setUrlFocusChangeFraction(float fraction) {
mUrlFocusChangeFraction = fraction;
}
private void registerTemplateUrlObserver() {
final TemplateUrlService templateUrlService = TemplateUrlServiceFactory.get();
assert mTemplateUrlObserver == null;
......@@ -1213,7 +1220,7 @@ public class LocationBarLayout extends FrameLayout
protected void updateMicButtonVisibility() {
boolean visible = !shouldShowDeleteButton();
boolean showMicButton = mVoiceSearchEnabled && visible
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangePercent > 0f
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangeFraction > 0f
|| mShouldShowMicButtonWhenUnfocused);
mMicButton.setVisibility(showMicButton ? VISIBLE : GONE);
}
......
......@@ -211,15 +211,17 @@ public class LocationBarPhone extends LocationBarLayout {
}
/**
* Updates percentage of current the URL focus change animation.
* @param percent 1.0 is 100% focused, 0 is completely unfocused.
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
public void setUrlFocusChangePercent(float percent) {
mUrlFocusChangePercent = percent;
@Override
public void setUrlFocusChangeFraction(float fraction) {
super.setUrlFocusChangeFraction(fraction);
if (percent > 0f) {
if (fraction > 0f) {
mUrlActionContainer.setVisibility(VISIBLE);
} else if (percent == 0f && !isUrlFocusChangeInProgress()) {
} else if (fraction == 0f && !isUrlFocusChangeInProgress()) {
// If a URL focus change is in progress, then it will handle setting the visibility
// correctly after it completes. If done here, it would cause the URL to jump due
// to a badly timed layout call.
......@@ -227,7 +229,7 @@ public class LocationBarPhone extends LocationBarLayout {
}
updateButtonVisibility();
mStatusCoordinator.setUrlFocusChangePercent(percent);
mStatusCoordinator.setUrlFocusChangePercent(fraction);
}
@Override
......
......@@ -37,29 +37,29 @@ public class LocationBarTablet extends LocationBarLayout {
private static final int WIDTH_CHANGE_ANIMATION_DURATION_MS = 225;
private static final int WIDTH_CHANGE_ANIMATION_DELAY_MS = 75;
private final Property<LocationBarTablet, Float> mUrlFocusChangePercentProperty =
private final Property<LocationBarTablet, Float> mUrlFocusChangeFractionProperty =
new Property<LocationBarTablet, Float>(Float.class, "") {
@Override
public Float get(LocationBarTablet object) {
return object.mUrlFocusChangePercent;
return object.mUrlFocusChangeFraction;
}
@Override
public void set(LocationBarTablet object, Float value) {
setUrlFocusChangePercent(value);
setUrlFocusChangeFraction(value);
}
};
private final Property<LocationBarTablet, Float> mWidthChangePercentProperty =
private final Property<LocationBarTablet, Float> mWidthChangeFractionProperty =
new Property<LocationBarTablet, Float>(Float.class, "") {
@Override
public Float get(LocationBarTablet object) {
return object.mWidthChangePercent;
return object.mWidthChangeFraction;
}
@Override
public void set(LocationBarTablet object, Float value) {
setWidthChangeAnimationPercent(value);
setWidthChangeAnimationFraction(value);
}
};
......@@ -78,7 +78,7 @@ public class LocationBarTablet extends LocationBarLayout {
private final int mToolbarButtonsWidth;
private final int mMicButtonWidth;
private boolean mAnimatingWidthChange;
private float mWidthChangePercent;
private float mWidthChangeFraction;
private float mLayoutLeft;
private float mLayoutRight;
private int mToolbarStartPaddingDifference;
......@@ -165,7 +165,7 @@ public class LocationBarTablet extends LocationBarLayout {
float screenSizeRatio = (rootViewBounds.height()
/ (float) (Math.max(rootViewBounds.height(), rootViewBounds.width())));
mUrlFocusChangeAnimator =
ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, hasFocus ? 1f : 0f);
ObjectAnimator.ofFloat(this, mUrlFocusChangeFractionProperty, hasFocus ? 1f : 0f);
mUrlFocusChangeAnimator.setDuration(
(long) (MAX_NTP_KEYBOARD_FOCUS_DURATION_MS * screenSizeRatio));
mUrlFocusChangeAnimator.addListener(new CancelAwareAnimatorListener() {
......@@ -193,14 +193,16 @@ public class LocationBarTablet extends LocationBarLayout {
}
/**
* Updates percentage of current the URL focus change animation.
* @param percent 1.0 is 100% focused, 0 is completely unfocused.
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
private void setUrlFocusChangePercent(float percent) {
mUrlFocusChangePercent = percent;
@Override
public void setUrlFocusChangeFraction(float fraction) {
super.setUrlFocusChangeFraction(fraction);
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (ntp != null) ntp.setUrlFocusChangeAnimationPercent(percent);
if (ntp != null) ntp.setUrlFocusChangeAnimationPercent(fraction);
}
@Override
......@@ -256,7 +258,7 @@ public class LocationBarTablet extends LocationBarLayout {
mLayoutRight = right;
if (mAnimatingWidthChange) {
setWidthChangeAnimationPercent(mWidthChangePercent);
setWidthChangeAnimationFraction(mWidthChangeFraction);
}
}
......@@ -303,7 +305,7 @@ public class LocationBarTablet extends LocationBarLayout {
ArrayList<Animator> animators = new ArrayList<>();
Animator widthChangeAnimator =
ObjectAnimator.ofFloat(this, mWidthChangePercentProperty, 0f);
ObjectAnimator.ofFloat(this, mWidthChangeFractionProperty, 0f);
widthChangeAnimator.setDuration(WIDTH_CHANGE_ANIMATION_DURATION_MS);
widthChangeAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
widthChangeAnimator.addListener(new AnimatorListenerAdapter() {
......@@ -317,7 +319,7 @@ public class LocationBarTablet extends LocationBarLayout {
public void onAnimationEnd(Animator animation) {
// Only reset values if the animation is ending because it's completely finished
// and not because it was canceled.
if (mWidthChangePercent == 0.f) {
if (mWidthChangeFraction == 0.f) {
mAnimatingWidthChange = false;
resetValuesAfterAnimation();
}
......@@ -357,7 +359,7 @@ public class LocationBarTablet extends LocationBarLayout {
ArrayList<Animator> animators = new ArrayList<>();
Animator widthChangeAnimator =
ObjectAnimator.ofFloat(this, mWidthChangePercentProperty, 1f);
ObjectAnimator.ofFloat(this, mWidthChangeFractionProperty, 1f);
widthChangeAnimator.setStartDelay(WIDTH_CHANGE_ANIMATION_DELAY_MS);
widthChangeAnimator.setDuration(WIDTH_CHANGE_ANIMATION_DURATION_MS);
widthChangeAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
......@@ -371,7 +373,7 @@ public class LocationBarTablet extends LocationBarLayout {
public void onAnimationEnd(Animator animation) {
// Only reset values if the animation is ending because it's completely finished
// and not because it was canceled.
if (mWidthChangePercent == 1.f) {
if (mWidthChangeFraction == 1.f) {
mAnimatingWidthChange = false;
resetValuesAfterAnimation();
setShouldShowButtonsWhenUnfocused(false);
......@@ -420,15 +422,16 @@ public class LocationBarTablet extends LocationBarLayout {
}
/**
* Updates completion percentage for the location bar width change animation.
* @param percent How complete the animation is, where 0 represents the normal width (toolbar
* buttons fully visible) and 1.f represents the expanded width (toolbar buttons
* fully hidden).
* Updates completion progress for the location bar width change animation.
*
* @param fraction How complete the animation is, where 0 represents the normal width (toolbar
* buttons fully visible) and 1.f represents the expanded width (toolbar buttons fully
* hidden).
*/
private void setWidthChangeAnimationPercent(float percent) {
mWidthChangePercent = percent;
private void setWidthChangeAnimationFraction(float fraction) {
mWidthChangeFraction = fraction;
float offset = (mToolbarButtonsWidth + mToolbarStartPaddingDifference) * percent;
float offset = (mToolbarButtonsWidth + mToolbarStartPaddingDifference) * fraction;
if (LocalizationUtils.isLayoutRtl()) {
// The location bar's right edge is its regular layout position when toolbar buttons are
......@@ -445,7 +448,7 @@ public class LocationBarTablet extends LocationBarLayout {
// As the location bar's right edge moves right (increases) or left edge moves left
// (decreases), the child views' translation X increases, keeping them visually in the same
// location for the duration of the animation.
int deleteOffset = (int) (mMicButtonWidth * percent);
int deleteOffset = (int) (mMicButtonWidth * fraction);
setChildTranslationsForWidthChangeAnimation((int) offset, deleteOffset);
}
......
......@@ -1034,7 +1034,7 @@ public class ToolbarPhone extends ToolbarLayout
if (!mOptionalButtonAnimationRunning) {
mUrlActionContainer.setTranslationX(getUrlActionsTranslationXForExpansionAnimation(
isLocationBarRtl, locationBarBaseTranslationX));
mLocationBar.setUrlFocusChangePercent(mUrlExpansionFraction);
mLocationBar.setUrlFocusChangeFraction(mUrlExpansionFraction);
// Only transition theme colors if in static tab mode that is not the NTP. In practice
// this only runs when you focus the omnibox on a web page.
......
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