Commit d04c36c8 authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Context menu redesign] Make the title expand on touch, like the URL

Bug: 1022185
Change-Id: Ib3344bd152874b92917b54b40a1f73003cfddd61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913463Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#714837}
parent 29a692ff
......@@ -42,7 +42,7 @@ class RevampedContextMenuHeaderMediator implements View.OnClickListener {
mContext = context;
mPlainUrl = params.getUrl();
mModel = model;
mModel.set(RevampedContextMenuHeaderProperties.URL_CLICK_LISTENER, this);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_AND_URL_CLICK_LISTENER, this);
if (!params.isImage() && !params.isVideo()) {
LargeIconBridge iconBridge = new LargeIconBridge(Profile.getLastUsedProfile());
......@@ -99,11 +99,19 @@ class RevampedContextMenuHeaderMediator implements View.OnClickListener {
public void onClick(View v) {
RecordHistogram.recordBooleanHistogram("ContextMenu.URLClicked", true);
if (mModel.get(RevampedContextMenuHeaderProperties.URL_MAX_LINES) == Integer.MAX_VALUE) {
boolean isEmpty =
// URL and title should both be expanded.
assert mModel.get(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES)
== Integer.MAX_VALUE;
final boolean isTitleEmpty =
TextUtils.isEmpty(mModel.get(RevampedContextMenuHeaderProperties.TITLE));
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, isEmpty ? 2 : 1);
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, isTitleEmpty ? 2 : 1);
final boolean isUrlEmpty =
TextUtils.isEmpty(mModel.get(RevampedContextMenuHeaderProperties.URL));
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, isUrlEmpty ? 2 : 1);
} else {
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, Integer.MAX_VALUE);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, Integer.MAX_VALUE);
}
}
......
......@@ -17,13 +17,13 @@ class RevampedContextMenuHeaderProperties {
public static final WritableIntPropertyKey TITLE_MAX_LINES = new WritableIntPropertyKey();
public static final WritableObjectPropertyKey<CharSequence> URL =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<View.OnClickListener> URL_CLICK_LISTENER =
new WritableObjectPropertyKey<>();
public static final WritableObjectPropertyKey<View.OnClickListener>
TITLE_AND_URL_CLICK_LISTENER = new WritableObjectPropertyKey<>();
public static final WritableIntPropertyKey URL_MAX_LINES = new WritableIntPropertyKey();
public static final WritableObjectPropertyKey<Bitmap> IMAGE = new WritableObjectPropertyKey<>();
public static final PropertyModel.WritableBooleanPropertyKey CIRCLE_BG_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = {TITLE, TITLE_MAX_LINES, URL, URL_CLICK_LISTENER,
URL_MAX_LINES, IMAGE, CIRCLE_BG_VISIBLE};
public static final PropertyKey[] ALL_KEYS = {TITLE, TITLE_MAX_LINES, URL,
TITLE_AND_URL_CLICK_LISTENER, URL_MAX_LINES, IMAGE, CIRCLE_BG_VISIBLE};
}
\ No newline at end of file
......@@ -25,7 +25,13 @@ class RevampedContextMenuHeaderViewBinder {
: View.VISIBLE);
} else if (propertyKey == RevampedContextMenuHeaderProperties.TITLE_MAX_LINES) {
final int maxLines = model.get(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES);
((TextView) view.findViewById(R.id.menu_header_title)).setMaxLines(maxLines);
final TextView titleText = view.findViewById(R.id.menu_header_title);
titleText.setMaxLines(maxLines);
if (maxLines == Integer.MAX_VALUE) {
titleText.setEllipsize(null);
} else {
titleText.setEllipsize(TextUtils.TruncateAt.END);
}
} else if (propertyKey == RevampedContextMenuHeaderProperties.URL) {
TextView urlText = view.findViewById(R.id.menu_header_url);
urlText.setText(model.get(RevampedContextMenuHeaderProperties.URL));
......@@ -33,10 +39,11 @@ class RevampedContextMenuHeaderViewBinder {
TextUtils.isEmpty(model.get(RevampedContextMenuHeaderProperties.URL))
? View.GONE
: View.VISIBLE);
} else if (propertyKey == RevampedContextMenuHeaderProperties.URL_CLICK_LISTENER) {
} else if (propertyKey
== RevampedContextMenuHeaderProperties.TITLE_AND_URL_CLICK_LISTENER) {
view.findViewById(R.id.title_and_url)
.setOnClickListener(
model.get(RevampedContextMenuHeaderProperties.URL_CLICK_LISTENER));
.setOnClickListener(model.get(
RevampedContextMenuHeaderProperties.TITLE_AND_URL_CLICK_LISTENER));
} else if (propertyKey == RevampedContextMenuHeaderProperties.URL_MAX_LINES) {
final int maxLines = model.get(RevampedContextMenuHeaderProperties.URL_MAX_LINES);
final TextView urlText = view.findViewById(R.id.menu_header_url);
......
......@@ -36,9 +36,7 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
@RunWith(ChromeJUnit4ClassRunner.class)
public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
private static final String TITLE_STRING = "Some Very Cool Title";
private static final int TITLE_MAX_COUNT = 2;
private static final String URL_STRING = "www.website.com";
private static final int URL_MAX_COUNT = 1;
private View mHeaderView;
private TextView mTitle;
......@@ -69,7 +67,8 @@ public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
mModel = new PropertyModel.Builder(RevampedContextMenuHeaderProperties.ALL_KEYS)
.with(RevampedContextMenuHeaderProperties.TITLE, "")
.with(RevampedContextMenuHeaderProperties.URL, "")
.with(RevampedContextMenuHeaderProperties.URL_CLICK_LISTENER, null)
.with(RevampedContextMenuHeaderProperties.TITLE_AND_URL_CLICK_LISTENER,
null)
.with(RevampedContextMenuHeaderProperties.IMAGE, null)
.with(RevampedContextMenuHeaderProperties.CIRCLE_BG_VISIBLE, false)
.build();
......@@ -92,13 +91,12 @@ public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mModel.set(RevampedContextMenuHeaderProperties.TITLE, TITLE_STRING);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, TITLE_MAX_COUNT);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, 2);
});
assertThat("Incorrect title visibility.", mTitle.getVisibility(), equalTo(View.VISIBLE));
assertThat("Incorrect title string.", mTitle.getText(), equalTo(TITLE_STRING));
assertThat("Incorrect max line count for title.", mTitle.getMaxLines(),
equalTo(TITLE_MAX_COUNT));
assertThat("Incorrect max line count for title.", mTitle.getMaxLines(), equalTo(2));
assertThat("Incorrect title ellipsize mode.", mTitle.getEllipsize(),
equalTo(TextUtils.TruncateAt.END));
}
......@@ -111,12 +109,12 @@ public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mModel.set(RevampedContextMenuHeaderProperties.URL, URL_STRING);
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, URL_MAX_COUNT);
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, 1);
});
assertThat("Incorrect URL visibility.", mUrl.getVisibility(), equalTo(View.VISIBLE));
assertThat("Incorrect URL string.", mUrl.getText(), equalTo(URL_STRING));
assertThat("Incorrect max line count for URL.", mUrl.getMaxLines(), equalTo(URL_MAX_COUNT));
assertThat("Incorrect max line count for URL.", mUrl.getMaxLines(), equalTo(1));
assertThat("Incorrect URL ellipsize mode.", mUrl.getEllipsize(),
equalTo(TextUtils.TruncateAt.END));
......@@ -132,20 +130,24 @@ public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
@Test
@SmallTest
@UiThreadTest
public void testUrlClick() {
// Even though the click event expands/shrinks the url, the click target is the LinearLayout
// that contains the title and the url to give the user more area to touch.
assertFalse("URL has onClickListeners when it shouldn't, yet, have.",
public void testTitleAndUrlClick() {
// Clicking on the title or the URL expands/shrinks both of them.
assertFalse("Title and URL have onClickListeners when it shouldn't, yet, have.",
mTitleAndUrl.hasOnClickListeners());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mModel.set(RevampedContextMenuHeaderProperties.TITLE, TITLE_STRING);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, 1);
mModel.set(RevampedContextMenuHeaderProperties.URL, URL_STRING);
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, URL_MAX_COUNT);
mModel.set(RevampedContextMenuHeaderProperties.URL_CLICK_LISTENER, (v) -> {
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, 1);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_AND_URL_CLICK_LISTENER, (v) -> {
if (mModel.get(RevampedContextMenuHeaderProperties.URL_MAX_LINES)
== Integer.MAX_VALUE) {
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, URL_MAX_COUNT);
mModel.set(RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, 1);
mModel.set(RevampedContextMenuHeaderProperties.URL_MAX_LINES, 1);
} else {
mModel.set(
RevampedContextMenuHeaderProperties.TITLE_MAX_LINES, Integer.MAX_VALUE);
mModel.set(
RevampedContextMenuHeaderProperties.URL_MAX_LINES, Integer.MAX_VALUE);
}
......@@ -153,13 +155,19 @@ public class RevampedContextMenuHeaderViewTest extends DummyUiActivityTestCase {
mTitleAndUrl.callOnClick();
});
assertThat("Incorrect max line count for title.", mTitle.getMaxLines(),
equalTo(Integer.MAX_VALUE));
assertNull("Title is ellipsized when it shouldn't be.", mTitle.getEllipsize());
assertThat("Incorrect max line count for URL.", mUrl.getMaxLines(),
equalTo(Integer.MAX_VALUE));
assertNull("URL is ellipsized when it shouldn't be.", mUrl.getEllipsize());
TestThreadUtils.runOnUiThreadBlocking(() -> { mTitleAndUrl.callOnClick(); });
assertThat("Incorrect max line count for URL.", mUrl.getMaxLines(), equalTo(URL_MAX_COUNT));
assertThat("Incorrect max line count for title.", mTitle.getMaxLines(), equalTo(1));
assertThat("Incorrect title ellipsize mode.", mTitle.getEllipsize(),
equalTo(TextUtils.TruncateAt.END));
assertThat("Incorrect max line count for URL.", mUrl.getMaxLines(), equalTo(1));
assertThat("Incorrect URL ellipsize mode.", mUrl.getEllipsize(),
equalTo(TextUtils.TruncateAt.END));
}
......
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