Commit e5e3630a authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Ensure square size of the Suggestion images.

This change ensures that the Suggestion icon's drawable area remains square.
We cannot depend on vertical dimension of the embedded drawable because
ColorDrawables, that (along with BitmapDrawables) are entirely handled by
RoundedCornerImageView, do not have a fixed vertical size.

Bug: 982818
Change-Id: Ib6966eaaaa21d85e61220c9631ae19cd269a2779
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866921
Commit-Queue: Ender <ender@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708694}
parent 39576cb4
......@@ -57,10 +57,15 @@ public class BaseSuggestionViewBinder
final int paddingStart = res.getDimensionPixelSize(sds.isLarge
? R.dimen.omnibox_suggestion_36dp_icon_margin_start
: R.dimen.omnibox_suggestion_24dp_icon_margin_start);
final int paddingEnd = res.getDimensionPixelSize(sds.isLarge
? R.dimen.omnibox_suggestion_36dp_icon_margin_end
: R.dimen.omnibox_suggestion_24dp_icon_margin_end);
final int edgeSize = res.getDimensionPixelSize(sds.isLarge
? R.dimen.omnibox_suggestion_36dp_icon_size
: R.dimen.omnibox_suggestion_24dp_icon_size);
view.setPadding(paddingStart, 0, paddingEnd, 0);
view.setMinimumHeight(edgeSize);
// TODO(ender): move logic applying corner rounding to updateIcon when action images use
// RoundedCornerImageView too.
......@@ -69,8 +74,6 @@ public class BaseSuggestionViewBinder
? res.getDimensionPixelSize(R.dimen.default_rounded_corner_radius)
: 0;
rciv.setRoundedCorners(radius, radius, radius, radius);
view.setPadding(paddingStart, 0, paddingEnd, 0);
}
updateIcon(view, sds, isDarkMode(model));
......
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import org.chromium.chrome.R;
......@@ -19,7 +20,6 @@ import org.chromium.chrome.browser.ui.widget.RoundedCornerImageView;
class DecoratedSuggestionView extends SimpleHorizontalLayoutView {
private final RoundedCornerImageView mSuggestionIcon;
private View mContentView;
private boolean mUseDarkIconTint;
/**
* Constructs a new suggestion view.
......@@ -39,7 +39,7 @@ class DecoratedSuggestionView extends SimpleHorizontalLayoutView {
mSuggestionIcon.setLayoutParams(new LayoutParams(
getResources().getDimensionPixelSize(R.dimen.omnibox_suggestion_icon_area_size),
LayoutParams.MATCH_PARENT));
ViewGroup.LayoutParams.WRAP_CONTENT));
addView(mSuggestionIcon);
}
......
......@@ -53,23 +53,29 @@ class SimpleHorizontalLayoutView extends ViewGroup {
// Note: We layout children in the following order:
// - first-to-last in LTR orientation and
// - last-to-first in RTL orientation.
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
final boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
final int increment = isRtl ? -1 : 1;
final int height = getMeasuredHeight();
int index = isRtl ? getChildCount() - 1 : 0;
int increment = isRtl ? -1 : 1;
left = 0;
for (; index >= 0 && index < getChildCount(); index += increment) {
View v = getChildAt(index);
if (v.getVisibility() == GONE) continue;
v.layout(left, 0, left + v.getMeasuredWidth(), bottom - top);
int verticalMargin = (height - v.getMeasuredHeight()) / 2;
if (verticalMargin < 0) verticalMargin = 0;
v.layout(left, verticalMargin, left + v.getMeasuredWidth(), height - verticalMargin);
left += v.getMeasuredWidth();
}
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int contentViewWidth = MeasureSpec.getSize(widthSpec);
final int widthPx = MeasureSpec.getSize(widthSpec);
int contentViewWidth = widthPx;
View dynamicView = null;
// Compute and apply space we can offer to content view.
......@@ -96,7 +102,7 @@ class SimpleHorizontalLayoutView extends ViewGroup {
dynamicView.measure(MeasureSpec.makeMeasureSpec(contentViewWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
final int heightPx = dynamicView.getMeasuredHeight();
heightSpec = MeasureSpec.makeMeasureSpec(heightPx, MeasureSpec.EXACTLY);
heightSpec = MeasureSpec.makeMeasureSpec(heightPx, MeasureSpec.AT_MOST);
// Apply measured dimensions to all children.
for (int index = 0; index < getChildCount(); ++index) {
......@@ -106,9 +112,9 @@ class SimpleHorizontalLayoutView extends ViewGroup {
if (v == dynamicView) continue;
v.measure(MeasureSpec.makeMeasureSpec(v.getLayoutParams().width, MeasureSpec.EXACTLY),
heightSpec);
getChildMeasureSpec(heightSpec, 0, v.getLayoutParams().height));
}
setMeasuredDimension(MeasureSpec.getSize(widthSpec), MeasureSpec.getSize(heightSpec));
setMeasuredDimension(widthPx, heightPx);
}
}
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.omnibox.suggestions.base;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import android.app.Activity;
import android.view.View;
import android.view.View.MeasureSpec;
......@@ -124,7 +126,7 @@ public class BaseSuggestionViewTest {
Assert.assertEquals("right view edge", right, v.getRight());
Assert.assertEquals("bottom view edge", bottom, v.getBottom());
Assert.assertEquals("view width", right - left, v.getMeasuredWidth());
Assert.assertEquals("view height", bottom - top, v.getMeasuredHeight());
Assert.assertThat("view height", v.getMeasuredHeight(), lessThanOrEqualTo(bottom - top));
}
@Test
......
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