Commit 6605ba60 authored by bttk's avatar bttk Committed by Commit Bot

Add StatusCoordinator.getEndPaddingPixelSizeOnFocusDelta()

With this change StatusView.getEndPaddingPixelSizeForFocusState() can
now be private.

Bug: 1109369
Change-Id: Ied30cd7cadbf1d06bfd2fa1a80b01379ddff2929
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335642Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Commit-Queue: who/bttk <bttk@chromium.org>
Auto-Submit: who/bttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796980}
parent 725e31cf
...@@ -45,6 +45,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -45,6 +45,7 @@ public class LocationBarPhone extends LocationBarLayout {
mUrlBar = findViewById(R.id.url_bar); mUrlBar = findViewById(R.id.url_bar);
updateUrlBarPaddingForSearchEngineIcon(); updateUrlBarPaddingForSearchEngineIcon();
mStatusView = findViewById(R.id.location_bar_status);
// Assign the first visible view here only if it hasn't been set by the DSE icon experiment. // Assign the first visible view here only if it hasn't been set by the DSE icon experiment.
// See onNativeLibrary ready for when this variable is set for the DSE icon case. // See onNativeLibrary ready for when this variable is set for the DSE icon case.
mFirstVisibleFocusedView = mFirstVisibleFocusedView =
...@@ -69,8 +70,6 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -69,8 +70,6 @@ public class LocationBarPhone extends LocationBarLayout {
getToolbarDataProvider().isIncognito()); getToolbarDataProvider().isIncognito());
// This branch will be hit if the search engine logo experiment is enabled. // This branch will be hit if the search engine logo experiment is enabled.
// This value can never revert back to false, so it's safe to initialize mStatusView here
// without a corresponding else that nulls it out.
if (SearchEngineLogoUtils.isSearchEngineLogoEnabled()) { if (SearchEngineLogoUtils.isSearchEngineLogoEnabled()) {
// Setup the padding once we're loaded, the focused padding changes will happen with // Setup the padding once we're loaded, the focused padding changes will happen with
// post-layout positioning via setTranslation. This is a byproduct of the way we do the // post-layout positioning via setTranslation. This is a byproduct of the way we do the
...@@ -83,7 +82,6 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -83,7 +82,6 @@ public class LocationBarPhone extends LocationBarLayout {
R.dimen.sei_location_bar_lateral_padding); R.dimen.sei_location_bar_lateral_padding);
setPaddingRelative(lateralPadding, getPaddingTop(), lateralPadding, getPaddingBottom()); setPaddingRelative(lateralPadding, getPaddingTop(), lateralPadding, getPaddingBottom());
updateUrlBarPaddingForSearchEngineIcon(); updateUrlBarPaddingForSearchEngineIcon();
mStatusView = findViewById(R.id.location_bar_status);
} }
// This branch will be hit if the search engine logo experiment is enabled and we should // This branch will be hit if the search engine logo experiment is enabled and we should
...@@ -105,7 +103,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -105,7 +103,7 @@ public class LocationBarPhone extends LocationBarLayout {
* Factor in extra padding added for the focused state when the search engine icon is active. * Factor in extra padding added for the focused state when the search engine icon is active.
*/ */
private void updateUrlBarPaddingForSearchEngineIcon() { private void updateUrlBarPaddingForSearchEngineIcon() {
if (mUrlBar == null || mStatusView == null) return; if (mUrlBar == null || mStatusCoordinator == null) return;
mUrlBar.post(() -> { mUrlBar.post(() -> {
// TODO(crbug.com/1019019): Come up with a better solution for M80 or M81. // TODO(crbug.com/1019019): Come up with a better solution for M80 or M81.
...@@ -114,8 +112,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -114,8 +112,7 @@ public class LocationBarPhone extends LocationBarLayout {
final int endPadding = SearchEngineLogoUtils.shouldShowSearchEngineLogo( final int endPadding = SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()) mToolbarDataProvider.isIncognito())
&& hasFocus() && hasFocus()
? mStatusView.getEndPaddingPixelSizeForFocusState(true) ? mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta()
- mStatusView.getEndPaddingPixelSizeForFocusState(false)
: 0; : 0;
mUrlBar.setPaddingRelative(mUrlBar.getPaddingStart(), mUrlBar.getPaddingTop(), mUrlBar.setPaddingRelative(mUrlBar.getPaddingStart(), mUrlBar.getPaddingTop(),
...@@ -202,7 +199,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -202,7 +199,7 @@ public class LocationBarPhone extends LocationBarLayout {
public float getUrlBarTranslationXForToolbarAnimation( public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) { float urlExpansionPercent, boolean hasFocus) {
// This will be called before status view is ready. // This will be called before status view is ready.
if (mStatusView == null) return 0; if (mStatusView == null || mStatusCoordinator == null) return 0;
// No offset is required if the experiment is disabled. // No offset is required if the experiment is disabled.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo( if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
...@@ -215,9 +212,8 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -215,9 +212,8 @@ public class LocationBarPhone extends LocationBarLayout {
// states and also accounts for the translation that the status icon will do. In the end, // 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 // this translation will be the distance that the url bar needs to travel to arrive at the
// desired padding when focused. // desired padding when focused.
float translation = urlExpansionPercent float translation =
* (mStatusView.getEndPaddingPixelSizeForFocusState(true) urlExpansionPercent * mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
- mStatusView.getEndPaddingPixelSizeForFocusState(false));
if (!hasFocus && mStatusView.isSearchEngineStatusIconVisible() if (!hasFocus && mStatusView.isSearchEngineStatusIconVisible()
&& SearchEngineLogoUtils.currentlyOnNTP(mToolbarDataProvider)) { && SearchEngineLogoUtils.currentlyOnNTP(mToolbarDataProvider)) {
......
...@@ -82,6 +82,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -82,6 +82,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
/** /**
* Provides data and state for the toolbar component. * Provides data and state for the toolbar component.
*
* @param toolbarDataProvider The data provider. * @param toolbarDataProvider The data provider.
*/ */
public void setToolbarDataProvider(ToolbarDataProvider toolbarDataProvider) { public void setToolbarDataProvider(ToolbarDataProvider toolbarDataProvider) {
...@@ -94,17 +95,13 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -94,17 +95,13 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
updateStatusIcon(); updateStatusIcon();
} }
/** /** Signals that native initialization has completed. */
* Signals that native initialization has completed.
*/
public void onNativeInitialized() { public void onNativeInitialized() {
mMediator.updateLocationBarIcon(); mMediator.updateLocationBarIcon();
mMediator.setStatusClickListener(this); mMediator.setStatusClickListener(this);
} }
/** /** @param urlHasFocus Whether the url currently has focus. */
* @param urlHasFocus Whether the url currently has focus.
*/
public void onUrlFocusChange(boolean urlHasFocus) { public void onUrlFocusChange(boolean urlHasFocus) {
mMediator.setUrlHasFocus(urlHasFocus); mMediator.setUrlHasFocus(urlHasFocus);
mUrlHasFocus = urlHasFocus; mUrlHasFocus = urlHasFocus;
...@@ -123,15 +120,14 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -123,15 +120,14 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
/** /**
* Set the url focus change percent. * Set the url focus change percent.
*
* @param percent The current focus percent. * @param percent The current focus percent.
*/ */
public void setUrlFocusChangePercent(float percent) { public void setUrlFocusChangePercent(float percent) {
mMediator.setUrlFocusChangePercent(percent); mMediator.setUrlFocusChangePercent(percent);
} }
/** /** @param useDarkColors Whether dark colors should be for the status icon and text. */
* @param useDarkColors Whether dark colors should be for the status icon and text.
*/
public void setUseDarkColors(boolean useDarkColors) { public void setUseDarkColors(boolean useDarkColors) {
mMediator.setUseDarkColors(useDarkColors); mMediator.setUseDarkColors(useDarkColors);
...@@ -140,9 +136,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -140,9 +136,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
updateStatusIcon(); updateStatusIcon();
} }
/** /** @param incognitoBadgeVisible Whether or not the incognito badge is visible. */
* @param incognitoBadgeVisible Whether or not the incognito badge is visible.
*/
public void setIncognitoBadgeVisibility(boolean incognitoBadgeVisible) { public void setIncognitoBadgeVisibility(boolean incognitoBadgeVisible) {
mMediator.setIncognitoBadgeVisibility(incognitoBadgeVisible); mMediator.setIncognitoBadgeVisibility(incognitoBadgeVisible);
} }
...@@ -156,9 +150,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -156,9 +150,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
mModalDialogManagerSupplier = modalDialogManagerSupplier; mModalDialogManagerSupplier = modalDialogManagerSupplier;
} }
/** /** Updates the security icon displayed in the LocationBar. */
* Updates the security icon displayed in the LocationBar.
*/
public void updateStatusIcon() { public void updateStatusIcon() {
mMediator.setSecurityIconResource(mToolbarDataProvider.getSecurityIconResource(mIsTablet)); mMediator.setSecurityIconResource(mToolbarDataProvider.getSecurityIconResource(mIsTablet));
mMediator.setSecurityIconTint(mToolbarDataProvider.getSecurityIconColorStateList()); mMediator.setSecurityIconTint(mToolbarDataProvider.getSecurityIconColorStateList());
...@@ -169,22 +161,18 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -169,22 +161,18 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
updateVerboseStatusVisibility(); updateVerboseStatusVisibility();
} }
/** /** Returns the view displaying the security icon. */
* @return The view displaying the security icon.
*/
public View getSecurityIconView() { public View getSecurityIconView() {
return mStatusView.getSecurityButton(); return mStatusView.getSecurityButton();
} }
/** /** Returns {@code true} if the security button is currently being displayed. */
* @return Whether the security button is currently being displayed.
*/
@VisibleForTesting @VisibleForTesting
public boolean isSecurityButtonShown() { public boolean isSecurityButtonShown() {
return mMediator.isSecurityButtonShown(); return mMediator.isSecurityButtonShown();
} }
/** @return The ID of the drawable currently shown in the security icon. */ /** Returns the ID of the drawable currently shown in the security icon. */
@DrawableRes @DrawableRes
public int getSecurityIconResourceIdForTesting() { public int getSecurityIconResourceIdForTesting() {
return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null
...@@ -192,7 +180,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -192,7 +180,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
: mModel.get(StatusProperties.STATUS_ICON_RESOURCE).getIconResForTesting(); : mModel.get(StatusProperties.STATUS_ICON_RESOURCE).getIconResForTesting();
} }
/** @return The icon identifier used for custom resources. */ /** Returns the icon identifier used for custom resources. */
public String getSecurityIconIdentifierForTesting() { public String getSecurityIconIdentifierForTesting() {
return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null
? null ? null
...@@ -236,29 +224,24 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -236,29 +224,24 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
/** /**
* Called to set the width of the location bar when the url bar is not focused. * Called to set the width of the location bar when the url bar is not focused.
* This value is used to determine whether the verbose status text should be visible. * This value is used to determine whether the verbose status text should be visible.
*
* @param width The unfocused location bar width. * @param width The unfocused location bar width.
*/ */
public void setUnfocusedLocationBarWidth(int width) { public void setUnfocusedLocationBarWidth(int width) {
mMediator.setUnfocusedLocationBarWidth(width); mMediator.setUnfocusedLocationBarWidth(width);
} }
/** /** Toggle animation of icon changes. */
* Toggle animation of icon changes.
*/
public void setShouldAnimateIconChanges(boolean shouldAnimate) { public void setShouldAnimateIconChanges(boolean shouldAnimate) {
mMediator.setAnimationsEnabled(shouldAnimate); mMediator.setAnimationsEnabled(shouldAnimate);
} }
/** /** Specify whether URL should present icons when focused. */
* Specify whether URL should present icons when focused.
*/
public void setShowIconsWhenUrlFocused(boolean showIconsWithUrlFocused) { public void setShowIconsWhenUrlFocused(boolean showIconsWithUrlFocused) {
mMediator.setShowIconsWhenUrlFocused(showIconsWithUrlFocused); mMediator.setShowIconsWhenUrlFocused(showIconsWithUrlFocused);
} }
/** /** Specify whether suggestion for URL bar is a search action. */
* Specify whether suggestion for URL bar is a search action.
*/
public void setFirstSuggestionIsSearchType(boolean firstSuggestionIsSearchQuery) { public void setFirstSuggestionIsSearchType(boolean firstSuggestionIsSearchQuery) {
mMediator.setFirstSuggestionIsSearchType(firstSuggestionIsSearchQuery); mMediator.setFirstSuggestionIsSearchType(firstSuggestionIsSearchQuery);
} }
...@@ -267,22 +250,23 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis ...@@ -267,22 +250,23 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
mMediator.setIncognitoStateProvider(incognitoStateProvider); mMediator.setIncognitoStateProvider(incognitoStateProvider);
} }
/** /** Update information required to display the search engine icon. */
* Update information required to display the search engine icon.
*/
public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo, public void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) { boolean isSearchEngineGoogle, String searchEngineUrl) {
mMediator.updateSearchEngineStatusIcon( mMediator.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl); shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
} }
/** /** Returns width of the status icon including start/end margins. */
* @return Width of the status icon including start/end margins.
*/
public int getStatusIconWidth() { public int getStatusIconWidth() {
return mStatusView.getStatusIconWidth(); return mStatusView.getStatusIconWidth();
} }
/** Returns the increase in StatusView end padding, when the Url bar is focused. */
public int getEndPaddingPixelSizeOnFocusDelta() {
return mMediator.getEndPaddingPixelSizeOnFocusDelta();
}
@Override @Override
public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) { public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) {
mMediator.onTextChanged(textWithoutAutocomplete); mMediator.onTextChanged(textWithoutAutocomplete);
......
...@@ -84,6 +84,7 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver { ...@@ -84,6 +84,7 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
private boolean mShouldCancelCustomFavicon; private boolean mShouldCancelCustomFavicon;
private boolean mIsTablet; private boolean mIsTablet;
private final int mEndPaddingPixelSizeOnFocusDelta;
private int mUrlMinWidth; private int mUrlMinWidth;
private int mSeparatorMinWidth; private int mSeparatorMinWidth;
private int mVerboseStatusTextMinWidth; private int mVerboseStatusTextMinWidth;
...@@ -130,13 +131,12 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver { ...@@ -130,13 +131,12 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
mContext = context; mContext = context;
mUrlBarEditingTextStateProvider = urlBarEditingTextStateProvider; mUrlBarEditingTextStateProvider = urlBarEditingTextStateProvider;
mEndPaddingPixelSizeOnFocusDelta =
mResources.getDimensionPixelSize(R.dimen.sei_location_bar_icon_end_padding_focused)
- mResources.getDimensionPixelSize(R.dimen.sei_location_bar_icon_end_padding);
int iconWidth = resources.getDimensionPixelSize(R.dimen.location_bar_status_icon_width); int iconWidth = resources.getDimensionPixelSize(R.dimen.location_bar_status_icon_width);
mTextOffsetThreshold = (float) iconWidth mTextOffsetThreshold =
/ (iconWidth (float) iconWidth / (iconWidth + getEndPaddingPixelSizeOnFocusDelta());
+ resources.getDimensionPixelSize(
R.dimen.sei_location_bar_icon_end_padding_focused)
- resources.getDimensionPixelSize(
R.dimen.sei_location_bar_icon_end_padding));
mTextOffsetAdjustedScale = mTextOffsetThreshold == 1 ? 1 : (1 - mTextOffsetThreshold); mTextOffsetAdjustedScale = mTextOffsetThreshold == 1 ? 1 : (1 - mTextOffsetThreshold);
mIsTablet = isTablet; mIsTablet = isTablet;
...@@ -232,6 +232,13 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver { ...@@ -232,6 +232,13 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
mSeparatorMinWidth = width; mSeparatorMinWidth = width;
} }
/**
* Returns the increase in StatusView end padding, when the Url bar is focused.
*/
int getEndPaddingPixelSizeOnFocusDelta() {
return mEndPaddingPixelSizeOnFocusDelta;
}
/** /**
* Specify whether status icon should be shown when URL is focused. * Specify whether status icon should be shown when URL is focused.
*/ */
......
...@@ -115,7 +115,9 @@ public class StatusView extends LinearLayout { ...@@ -115,7 +115,9 @@ public class StatusView extends LinearLayout {
// Setup the padding once we're loaded, the other padding changes will happen with post- // Setup the padding once we're loaded, the other padding changes will happen with post-
// layout positioning. // layout positioning.
setPaddingRelative(getPaddingStart(), getPaddingTop(), setPaddingRelative(getPaddingStart(), getPaddingTop(),
getEndPaddingPixelSizeForFocusState(false), getPaddingBottom()); getResources().getDimensionPixelOffset(
R.dimen.sei_location_bar_icon_end_padding),
getPaddingBottom());
// Note: the margins and implicit padding were removed from the status view for the // Note: the margins and implicit padding were removed from the status view for the
// dse icon experiment. Moving padding values that were there to the verbose status // dse icon experiment. Moving padding values that were there to the verbose status
// text view and the verbose text extra space. // text view and the verbose text extra space.
...@@ -422,19 +424,6 @@ public class StatusView extends LinearLayout { ...@@ -422,19 +424,6 @@ public class StatusView extends LinearLayout {
mIncognitoBadge.getPaddingTop(), endPadding, mIncognitoBadge.getPaddingBottom()); mIncognitoBadge.getPaddingTop(), endPadding, mIncognitoBadge.getPaddingBottom());
} }
/**
* @returns The end padding for the given state.
*/
public int getEndPaddingPixelSizeForFocusState(boolean hasFocus) {
if (hasFocus) {
return getResources().getDimensionPixelOffset(
R.dimen.sei_location_bar_icon_end_padding_focused);
} else {
return getResources().getDimensionPixelOffset(
R.dimen.sei_location_bar_icon_end_padding);
}
}
/** /**
* Create a touch delegate to expand the clickable area for the padlock icon (see * Create a touch delegate to expand the clickable area for the padlock icon (see
* crbug.com/970031 for motivation/info). This method will be called when the icon is animating * crbug.com/970031 for motivation/info). This method will be called when the icon is animating
......
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