Commit 07842c81 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

SimpleHorizontalLayout: add support for horizontal padding.

This change is needed to properly manage suggestions with no
decoration icons. These suggestions will receive additional padding
at the front of the view.

Bug: 1021263
Change-Id: I78c3d8ef6ad95882a812d9a076c36fe9dd3d29e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1955088Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Commit-Queue: Ender <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#722719}
parent 39daef1d
......@@ -58,7 +58,7 @@ class SimpleHorizontalLayoutView extends ViewGroup {
final int height = getMeasuredHeight();
int index = isRtl ? getChildCount() - 1 : 0;
left = 0;
left = getPaddingLeft();
for (; index >= 0 && index < getChildCount(); index += increment) {
View v = getChildAt(index);
......@@ -75,7 +75,7 @@ class SimpleHorizontalLayoutView extends ViewGroup {
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
final int widthPx = MeasureSpec.getSize(widthSpec);
int contentViewWidth = widthPx;
int contentViewWidth = widthPx - getPaddingLeft() - getPaddingRight();
View dynamicView = null;
// Compute and apply space we can offer to content view.
......
......@@ -367,6 +367,118 @@ public class SimpleHorizontalLayoutViewTest {
giveContentHeight);
}
/**
* Verify that start padding is respected during layout.
*/
@Test
public void layout_LtrPaddingLeft() {
final int contentWidth = 250;
final int contentHeight = 48;
final int paddingWidth = 18;
final int suggestionWidth = paddingWidth + SMALL_VIEW_WIDTH + contentWidth;
mView.setPaddingRelative(paddingWidth, 0, 0, 0);
mView.addView(mSmallView);
mView.addView(mDynamicView);
final int expectedSmallCornerLeft = paddingWidth;
final int expectedSmallCornerRight = expectedSmallCornerLeft + SMALL_VIEW_WIDTH;
final int expectedDynamicCornerLeft = expectedSmallCornerRight;
final int expectedDynamicCornerRight = expectedDynamicCornerLeft + contentWidth;
executeLayoutTest(suggestionWidth, contentHeight, View.LAYOUT_DIRECTION_LTR);
verifyViewLayout(
mSmallView, expectedSmallCornerLeft, 0, expectedSmallCornerRight, contentHeight);
verifyViewLayout(mDynamicView, expectedDynamicCornerLeft, 0, expectedDynamicCornerRight,
contentHeight);
}
/**
* Verify that end padding is respected during layout.
*/
@Test
public void layout_LtrPaddingEnd() {
final int contentWidth = 250;
final int contentHeight = 48;
final int paddingWidth = 18;
final int suggestionWidth = paddingWidth + SMALL_VIEW_WIDTH + contentWidth;
mView.setPaddingRelative(0, 0, paddingWidth, 0);
mView.addView(mSmallView);
mView.addView(mDynamicView);
final int expectedSmallCornerLeft = 0;
final int expectedSmallCornerRight = SMALL_VIEW_WIDTH;
final int expectedDynamicCornerLeft = expectedSmallCornerRight;
final int expectedDynamicCornerRight = expectedDynamicCornerLeft + contentWidth;
executeLayoutTest(suggestionWidth, contentHeight, View.LAYOUT_DIRECTION_LTR);
verifyViewLayout(
mSmallView, expectedSmallCornerLeft, 0, expectedSmallCornerRight, contentHeight);
verifyViewLayout(mDynamicView, expectedDynamicCornerLeft, 0, expectedDynamicCornerRight,
contentHeight);
}
/**
* Verify that start padding is respected during layout / RTL.
*/
@Test
public void layout_RtlPaddingLeft() {
final int contentWidth = 250;
final int contentHeight = 48;
final int paddingWidth = 18;
final int suggestionWidth = paddingWidth + SMALL_VIEW_WIDTH + contentWidth;
mView.addView(mSmallView);
mView.addView(mDynamicView);
final int expectedDynamicCornerLeft = 0;
final int expectedDynamicCornerRight = contentWidth;
final int expectedSmallCornerLeft = expectedDynamicCornerRight;
final int expectedSmallCornerRight = expectedSmallCornerLeft + SMALL_VIEW_WIDTH;
mView.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
mView.setPaddingRelative(paddingWidth, 0, 0, 0);
executeLayoutTest(suggestionWidth, contentHeight, View.LAYOUT_DIRECTION_RTL);
verifyViewLayout(
mSmallView, expectedSmallCornerLeft, 0, expectedSmallCornerRight, contentHeight);
verifyViewLayout(mDynamicView, expectedDynamicCornerLeft, 0, expectedDynamicCornerRight,
contentHeight);
}
/**
* Verify that end padding is respected during layout / RTL.
*/
@Test
public void layout_RtlPaddingEnd() {
final int contentWidth = 250;
final int contentHeight = 48;
final int paddingWidth = 18;
final int suggestionWidth = paddingWidth + SMALL_VIEW_WIDTH + contentWidth;
mView.addView(mSmallView);
mView.addView(mDynamicView);
final int expectedDynamicCornerLeft = paddingWidth;
final int expectedDynamicCornerRight = expectedDynamicCornerLeft + contentWidth;
final int expectedSmallCornerLeft = expectedDynamicCornerRight;
final int expectedSmallCornerRight = expectedSmallCornerLeft + SMALL_VIEW_WIDTH;
mView.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
mView.setPaddingRelative(0, 0, paddingWidth, 0);
executeLayoutTest(suggestionWidth, contentHeight, View.LAYOUT_DIRECTION_RTL);
verifyViewLayout(
mSmallView, expectedSmallCornerLeft, 0, expectedSmallCornerRight, contentHeight);
verifyViewLayout(mDynamicView, expectedDynamicCornerLeft, 0, expectedDynamicCornerRight,
contentHeight);
}
/**
* Two dynamic views. Expect the layout mechanism to fail.
*/
......
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