Commit 948e8c21 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Update UrlBar layout to compensate for the additional focused padding

We introduced additional padding for the search engine icon experiment
focused state. This additional padding happens post-layout, so we don't
have to re-layout the view tree during the animation. As a result, the
UrlBar's width=match_parent makes the UrlBar too wide and the end of
the UrlBar's text is cut off by the next view.

Bug: 1012436
Change-Id: I5f46a2dd530783b002c529d3c4cdccbdd81e1b5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856868
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707035}
parent 099f4dc4
......@@ -11,6 +11,10 @@
<include layout="@layout/location_status" />
<!--
Padding for this view is adjusted in LocationBarPhone when the search engine logo is active.
This is to prevent the url clipping described in crbug.com/1012436.
-->
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
......
......@@ -43,9 +43,10 @@ public class LocationBarPhone extends LocationBarLayout {
protected void onFinishInflate() {
super.onFinishInflate();
mUrlBar = findViewById(R.id.url_bar);
updateUrlBarPaddingForSearchEngineIcon();
// 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.
mUrlBar = findViewById(R.id.url_bar);
mFirstVisibleFocusedView =
mFirstVisibleFocusedView == null ? mUrlBar : mFirstVisibleFocusedView;
......@@ -90,6 +91,7 @@ public class LocationBarPhone extends LocationBarLayout {
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
mIconView = mStatusView.findViewById(R.id.location_bar_status_icon);
mFirstVisibleFocusedView = mStatusView;
updateUrlBarPaddingForSearchEngineIcon();
// When the search engine icon is enabled, icons are translations into the parent view's
// padding area. Set clip padding to false to prevent them from getting clipped.
......@@ -98,6 +100,24 @@ public class LocationBarPhone extends LocationBarLayout {
setShowIconsWhenUrlFocused(shouldShowSearchEngineLogo);
}
/**
* 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;
int endPadding = 0;
if (SearchEngineLogoUtils.shouldShowSearchEngineLogo(mToolbarDataProvider.isIncognito())) {
// This padding prevents the UrlBar's content from extending past the available space
// and into the next view.
endPadding = mStatusView.getEndPaddingPixelSizeForFocusState(true)
- mStatusView.getEndPaddingPixelSizeForFocusState(false);
}
mUrlBar.setPaddingRelative(mUrlBar.getPaddingStart(), mUrlBar.getPaddingTop(), endPadding,
mUrlBar.getPaddingBottom());
}
/**
* @return The first view visible when the location bar is focused.
*/
......@@ -163,8 +183,8 @@ public class LocationBarPhone extends LocationBarLayout {
// 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.getEndPaddingPixelSizeForState(true)
- mStatusView.getEndPaddingPixelSizeForState(false));
* (mStatusView.getEndPaddingPixelSizeForFocusState(true)
- mStatusView.getEndPaddingPixelSizeForFocusState(false));
if (!hasFocus && mIconView.getVisibility() == VISIBLE
&& mToolbarDataProvider.getNewTabPageForCurrentTab() != null
......@@ -332,6 +352,7 @@ public class LocationBarPhone extends LocationBarLayout {
boolean isIncognito = getToolbarDataProvider().isIncognito();
boolean shouldShowSearchEngineLogo =
SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito);
updateUrlBarPaddingForSearchEngineIcon();
if (mIconView != null) mIconView.setVisibility(shouldShowSearchEngineLogo ? VISIBLE : GONE);
setShowIconsWhenUrlFocused(shouldShowSearchEngineLogo);
mFirstVisibleFocusedView = shouldShowSearchEngineLogo ? mStatusView : mUrlBar;
......
......@@ -122,7 +122,7 @@ 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(),
getEndPaddingPixelSizeForState(false), getPaddingBottom());
getEndPaddingPixelSizeForFocusState(false), getPaddingBottom());
}
}
......@@ -424,7 +424,7 @@ public class StatusView extends LinearLayout {
/**
* @returns The end padding for the given state.
*/
public int getEndPaddingPixelSizeForState(boolean hasFocus) {
public int getEndPaddingPixelSizeForFocusState(boolean hasFocus) {
if (hasFocus) {
return getResources().getDimensionPixelOffset(
R.dimen.sei_location_bar_icon_end_padding_focused);
......
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