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