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 {
mUrlBar = findViewById(R.id.url_bar);
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.
// See onNativeLibrary ready for when this variable is set for the DSE icon case.
mFirstVisibleFocusedView =
......@@ -69,8 +70,6 @@ public class LocationBarPhone extends LocationBarLayout {
getToolbarDataProvider().isIncognito());
// 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()) {
// 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
......@@ -83,7 +82,6 @@ public class LocationBarPhone extends LocationBarLayout {
R.dimen.sei_location_bar_lateral_padding);
setPaddingRelative(lateralPadding, getPaddingTop(), lateralPadding, getPaddingBottom());
updateUrlBarPaddingForSearchEngineIcon();
mStatusView = findViewById(R.id.location_bar_status);
}
// 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 {
* Factor in extra padding added for the focused state when the search engine icon is active.
*/
private void updateUrlBarPaddingForSearchEngineIcon() {
if (mUrlBar == null || mStatusView == null) return;
if (mUrlBar == null || mStatusCoordinator == null) return;
mUrlBar.post(() -> {
// TODO(crbug.com/1019019): Come up with a better solution for M80 or M81.
......@@ -114,8 +112,7 @@ public class LocationBarPhone extends LocationBarLayout {
final int endPadding = SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito())
&& hasFocus()
? mStatusView.getEndPaddingPixelSizeForFocusState(true)
- mStatusView.getEndPaddingPixelSizeForFocusState(false)
? mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta()
: 0;
mUrlBar.setPaddingRelative(mUrlBar.getPaddingStart(), mUrlBar.getPaddingTop(),
......@@ -202,7 +199,7 @@ public class LocationBarPhone extends LocationBarLayout {
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) {
// 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.
if (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(
......@@ -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,
// this translation will be the distance that the url bar needs to travel to arrive at the
// desired padding when focused.
float translation = urlExpansionPercent
* (mStatusView.getEndPaddingPixelSizeForFocusState(true)
- mStatusView.getEndPaddingPixelSizeForFocusState(false));
float translation =
urlExpansionPercent * mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
if (!hasFocus && mStatusView.isSearchEngineStatusIconVisible()
&& SearchEngineLogoUtils.currentlyOnNTP(mToolbarDataProvider)) {
......
......@@ -82,6 +82,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
/**
* Provides data and state for the toolbar component.
*
* @param toolbarDataProvider The data provider.
*/
public void setToolbarDataProvider(ToolbarDataProvider toolbarDataProvider) {
......@@ -94,17 +95,13 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
updateStatusIcon();
}
/**
* Signals that native initialization has completed.
*/
/** Signals that native initialization has completed. */
public void onNativeInitialized() {
mMediator.updateLocationBarIcon();
mMediator.setStatusClickListener(this);
}
/**
* @param urlHasFocus Whether the url currently has focus.
*/
/** @param urlHasFocus Whether the url currently has focus. */
public void onUrlFocusChange(boolean urlHasFocus) {
mMediator.setUrlHasFocus(urlHasFocus);
mUrlHasFocus = urlHasFocus;
......@@ -123,15 +120,14 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
/**
* Set the url focus change percent.
*
* @param percent The current focus percent.
*/
public void setUrlFocusChangePercent(float 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) {
mMediator.setUseDarkColors(useDarkColors);
......@@ -140,9 +136,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
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) {
mMediator.setIncognitoBadgeVisibility(incognitoBadgeVisible);
}
......@@ -156,9 +150,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
mModalDialogManagerSupplier = modalDialogManagerSupplier;
}
/**
* Updates the security icon displayed in the LocationBar.
*/
/** Updates the security icon displayed in the LocationBar. */
public void updateStatusIcon() {
mMediator.setSecurityIconResource(mToolbarDataProvider.getSecurityIconResource(mIsTablet));
mMediator.setSecurityIconTint(mToolbarDataProvider.getSecurityIconColorStateList());
......@@ -169,22 +161,18 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
updateVerboseStatusVisibility();
}
/**
* @return The view displaying the security icon.
*/
/** Returns the view displaying the security icon. */
public View getSecurityIconView() {
return mStatusView.getSecurityButton();
}
/**
* @return Whether the security button is currently being displayed.
*/
/** Returns {@code true} if the security button is currently being displayed. */
@VisibleForTesting
public boolean 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
public int getSecurityIconResourceIdForTesting() {
return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null
......@@ -192,7 +180,7 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
: 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() {
return mModel.get(StatusProperties.STATUS_ICON_RESOURCE) == null
? null
......@@ -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.
* This value is used to determine whether the verbose status text should be visible.
*
* @param width The unfocused location bar width.
*/
public void setUnfocusedLocationBarWidth(int width) {
mMediator.setUnfocusedLocationBarWidth(width);
}
/**
* Toggle animation of icon changes.
*/
/** Toggle animation of icon changes. */
public void setShouldAnimateIconChanges(boolean 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) {
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) {
mMediator.setFirstSuggestionIsSearchType(firstSuggestionIsSearchQuery);
}
......@@ -267,22 +250,23 @@ public class StatusCoordinator implements View.OnClickListener, UrlTextChangeLis
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,
boolean isSearchEngineGoogle, String searchEngineUrl) {
mMediator.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
}
/**
* @return Width of the status icon including start/end margins.
*/
/** Returns width of the status icon including start/end margins. */
public int getStatusIconWidth() {
return mStatusView.getStatusIconWidth();
}
/** Returns the increase in StatusView end padding, when the Url bar is focused. */
public int getEndPaddingPixelSizeOnFocusDelta() {
return mMediator.getEndPaddingPixelSizeOnFocusDelta();
}
@Override
public void onTextChanged(String textWithoutAutocomplete, String textWithAutocomplete) {
mMediator.onTextChanged(textWithoutAutocomplete);
......
......@@ -84,6 +84,7 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
private boolean mShouldCancelCustomFavicon;
private boolean mIsTablet;
private final int mEndPaddingPixelSizeOnFocusDelta;
private int mUrlMinWidth;
private int mSeparatorMinWidth;
private int mVerboseStatusTextMinWidth;
......@@ -130,13 +131,12 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
mContext = context;
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);
mTextOffsetThreshold = (float) iconWidth
/ (iconWidth
+ resources.getDimensionPixelSize(
R.dimen.sei_location_bar_icon_end_padding_focused)
- resources.getDimensionPixelSize(
R.dimen.sei_location_bar_icon_end_padding));
mTextOffsetThreshold =
(float) iconWidth / (iconWidth + getEndPaddingPixelSizeOnFocusDelta());
mTextOffsetAdjustedScale = mTextOffsetThreshold == 1 ? 1 : (1 - mTextOffsetThreshold);
mIsTablet = isTablet;
......@@ -232,6 +232,13 @@ class StatusMediator implements IncognitoStateProvider.IncognitoStateObserver {
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.
*/
......
......@@ -115,7 +115,9 @@ public class StatusView extends LinearLayout {
// Setup the padding once we're loaded, the other padding changes will happen with post-
// layout positioning.
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
// dse icon experiment. Moving padding values that were there to the verbose status
// text view and the verbose text extra space.
......@@ -422,19 +424,6 @@ public class StatusView extends LinearLayout {
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
* 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