Commit db9c5f91 authored by Brandon Wylie's avatar Brandon Wylie Committed by Chromium LUCI CQ

Move LocationBar offset calculations to Toolbar

Bug: 1156401
Change-Id: I5a86a197f8d35cd0ae2c5e4878f4070fc844434e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580003
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarbttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835869}
parent 45dcb02f
......@@ -412,6 +412,11 @@ public final class LocationBarCoordinator implements LocationBar, NativeInitObse
mLocationBarMediator.setUnfocusedWidth(unfocusedWidth);
}
/** Returns the {@link StatusCoordiantor} for the LocationBar. */
public StatusCoordinator getStatusCoordinator() {
return mStatusCoordinator;
}
public void setVoiceRecognitionHandlerForTesting(
VoiceRecognitionHandler voiceRecognitionHandler) {
mLocationBarMediator.setVoiceRecognitionHandlerForTesting(voiceRecognitionHandler);
......
......@@ -46,34 +46,6 @@ public class LocationBarCoordinatorPhone implements LocationBarCoordinator.SubCo
mLocationBarPhone.populateFadeAnimations(animators, startDelayMs, durationMs, targetAlpha);
}
/**
* Calculates the offset required for the focused LocationBar to appear as it's still
* unfocused so it can animate to a focused state.
*
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the DSE/loupe icon.
*/
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
return mLocationBarPhone.getLocationBarOffsetForFocusAnimation(hasFocus);
}
/**
* Function used to position the URL bar inside the location bar during omnibox animation.
*
* @param urlExpansionFraction The current expansion progress, 1 is fully focused and 0 is
* completely unfocused.
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The number of pixels of horizontal translation for the URL bar, used in the
* toolbar animation.
*/
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionFraction, boolean hasFocus) {
return mLocationBarPhone.getUrlBarTranslationXForToolbarAnimation(
urlExpansionFraction, hasFocus);
}
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
......
......@@ -251,95 +251,6 @@ class LocationBarPhone extends LocationBarLayout {
return (FrameLayout.LayoutParams) getLayoutParams();
}
/**
* Calculates the offset required for the focused LocationBar to appear as it's still unfocused
* so it can animate to a focused state.
*
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the dse icon.
*/
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
if (mStatusCoordinator == null) return 0;
// No offset is required if the experiment is disabled.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mLocationBarDataProvider.isIncognito())) {
return 0;
}
// On non-NTP pages, there will always be an icon when unfocused.
if (!mLocationBarDataProvider.getNewTabPageDelegate().isCurrentlyVisible()) return 0;
// This offset is only required when the focus animation is running.
if (!hasFocus) return 0;
// We're on the NTP with the fakebox showing.
// The value returned changes based on if the layout is LTR OR RTL.
// For LTR, the value is negative because we are making space on the left-hand side.
// For RTL, the value is positive because we are pushing the icon further to the
// right-hand side.
int offset = mStatusCoordinator.getStatusIconWidth() - getAdditionalOffsetForNTP();
return getLayoutDirection() == LAYOUT_DIRECTION_RTL ? offset : -offset;
}
/**
* Function used to position the url bar inside the location bar during omnibox animation.
*
* @param urlExpansionPercent The current expansion percent, 1 is fully focused and 0 is
* completely unfocused.
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The X translation for the URL bar, used in the toolbar animation.
*/
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) {
// This will be called before status view is ready.
if (mStatusCoordinator == null) return 0;
// No offset is required if the experiment is disabled.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mLocationBarDataProvider.isIncognito())) {
return 0;
}
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
// The calculation here is: the difference in padding between the focused vs unfocused
// states and also accounts for the translation that the status icon will do. In the end,
// this translation will be the distance that the url bar needs to travel to arrive at the
// desired padding when focused.
float translation =
urlExpansionPercent * mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
if (!hasFocus && mStatusCoordinator.isSearchEngineStatusIconVisible()
&& SearchEngineLogoUtils.currentlyOnNTP(mLocationBarDataProvider)) {
// When:
// 1. unfocusing the LocationBar on the NTP.
// 2. scrolling the fakebox to the LocationBar on the NTP.
// The status icon and the URL bar text overlap in the animation.
//
// This branch calculates the negative distance the URL bar needs to travel to
// completely overlap the status icon and end up in a state that matches the fakebox.
float overStatusIconTranslation = translation
- (1f - urlExpansionPercent)
* (mStatusCoordinator.getStatusIconWidth()
- getAdditionalOffsetForNTP());
// The value returned changes based on if the layout is LTR or RTL.
// For LTR, the value is negative because the status icon is left of the url bar on the
// x/y plane.
// For RTL, the value is positive because the status icon is right of the url bar on the
// x/y plane.
return isRtl ? -overStatusIconTranslation : overStatusIconTranslation;
}
return isRtl ? -translation : translation;
}
private int getAdditionalOffsetForNTP() {
return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding)
- getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding);
}
/** Update the status visibility according to the current state held in LocationBar. */
private void updateStatusVisibility() {
boolean incognito = mLocationBarDataProvider.isIncognito();
......
......@@ -53,6 +53,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarCoordinator;
import org.chromium.chrome.browser.omnibox.SearchEngineLogoUtils;
import org.chromium.chrome.browser.omnibox.status.StatusCoordinator;
import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomizations;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
......@@ -984,9 +985,7 @@ public class ToolbarPhone extends ToolbarLayout implements OnClickListener, TabC
// implementation details.
boolean isIncognito = getToolbarDataProvider().isIncognito();
if (SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito)) {
locationBarBaseTranslationX +=
mLocationBar.getPhoneCoordinator().getLocationBarOffsetForFocusAnimation(
hasFocus());
locationBarBaseTranslationX += getLocationBarOffsetForFocusAnimation(hasFocus());
}
boolean isLocationBarRtl =
......@@ -1031,8 +1030,7 @@ public class ToolbarPhone extends ToolbarLayout implements OnClickListener, TabC
// LocationBar#getUrlBarTranslationXForToolbarAnimation() for implementation details.
if (SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito)) {
mUrlBar.setTranslationX(
mLocationBar.getPhoneCoordinator().getUrlBarTranslationXForToolbarAnimation(
mUrlExpansionFraction, hasFocus()));
getUrlBarTranslationXForToolbarAnimation(mUrlExpansionFraction, hasFocus()));
} else if (SearchEngineLogoUtils.isSearchEngineLogoEnabled()) {
mUrlBar.setTranslationX(0);
}
......@@ -2771,4 +2769,96 @@ public class ToolbarPhone extends ToolbarLayout implements OnClickListener, TabC
mOptionalButtonAnimator.cancel();
}
}
/**
* Calculates the offset required for the focused LocationBar to appear as if it's still
* unfocused so it can animate to a focused state.
*
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the dse icon.
*/
private int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
StatusCoordinator statusCoordinator = mLocationBar.getStatusCoordinator();
if (statusCoordinator == null) return 0;
// No offset is required if the experiment is disabled.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
getToolbarDataProvider().isIncognito())) {
return 0;
}
// On non-NTP pages, there will always be an icon when unfocused.
if (!getToolbarDataProvider().getNewTabPageDelegate().isCurrentlyVisible()) return 0;
// This offset is only required when the focus animation is running.
if (!hasFocus) return 0;
// We're on the NTP with the fakebox showing.
// The value returned changes based on if the layout is LTR OR RTL.
// For LTR, the value is negative because we are making space on the left-hand side.
// For RTL, the value is positive because we are pushing the icon further to the
// right-hand side.
int offset = statusCoordinator.getStatusIconWidth() - getAdditionalOffsetForNTP();
return getLayoutDirection() == LAYOUT_DIRECTION_RTL ? offset : -offset;
}
/**
* Function used to position the url bar inside the location bar during omnibox animation.
*
* @param urlExpansionPercent The current expansion percent, 1 is fully focused and 0 is
* completely unfocused.
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The X translation for the URL bar, used in the toolbar animation.
*/
private float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) {
StatusCoordinator statusCoordinator = mLocationBar.getStatusCoordinator();
if (statusCoordinator == null) return 0;
// No offset is required if the experiment is disabled.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
getToolbarDataProvider().isIncognito())) {
return 0;
}
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
// The calculation here is: the difference in padding between the focused vs unfocused
// states and also accounts for the translation that the status icon will do. In the end,
// this translation will be the distance that the url bar needs to travel to arrive at the
// desired padding when focused.
float translation =
urlExpansionPercent * statusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
boolean scrollingOnNtp =
getToolbarDataProvider().getNewTabPageDelegate().isCurrentlyVisible() && !hasFocus
&& statusCoordinator.isSearchEngineStatusIconVisible();
if (scrollingOnNtp) {
// When:
// 1. unfocusing the LocationBar on the NTP.
// 2. scrolling the fakebox to the LocationBar on the NTP.
// The status icon and the URL bar text overlap in the animation.
//
// This branch calculates the negative distance the URL bar needs to travel to
// completely overlap the status icon and end up in a state that matches the fakebox.
float overStatusIconTranslation = translation
- (1f - urlExpansionPercent)
* (statusCoordinator.getStatusIconWidth()
- getAdditionalOffsetForNTP());
// The value returned changes based on if the layout is LTR or RTL.
// For LTR, the value is negative because the status icon is left of the url bar on the
// x/y plane.
// For RTL, the value is positive because the status icon is right of the url bar on the
// x/y plane.
return isRtl ? -overStatusIconTranslation : overStatusIconTranslation;
}
return isRtl ? -translation : translation;
}
private int getAdditionalOffsetForNTP() {
return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding)
- getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding);
}
}
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