Commit 44f98d1d authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

Reland "Fix chopped text on tab switcher long-press menu when text size is huge"

Reland of 76ed93dc

Fix failure on TabStripTest suite

Reason for revert: breaks org.chromium.chrome.browser.compositor.overlays.strip.TabStripTest suite

Original change's description:
> Fix chopped text on tab switcher long-press menu when text size is huge
>
> There exists some unknown issue on the measurement of a text view with
> a compound drawable. Using a linear layout containing an imageview and
> a textview inside can avoid this issue.
>
> Bug: 1053448
> Change-Id: Ibdcd220e0eba7218c1d500d870da17d37c7e767c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083729
> Commit-Queue: Lijin Shen <lazzzis@chromium.org>
> Reviewed-by: Theresa  <twellington@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#747078}

Bug: 1053448
Change-Id: Ib5c48a3010e7074ca9c92e2826ba407ffd76e9fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090833
Commit-Queue: Lijin Shen <lazzzis@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748753}
parent d9835620
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.tasks.tab_management; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.tasks.tab_management;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.chrome.tab_ui.R;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -16,7 +17,8 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -16,7 +17,8 @@ import org.chromium.ui.modelutil.PropertyModel;
public class TabGridDialogMenuItemBinder { public class TabGridDialogMenuItemBinder {
public static void binder(PropertyModel model, View view, PropertyKey propertyKey) { public static void binder(PropertyModel model, View view, PropertyKey propertyKey) {
if (propertyKey == TabGridDialogMenuItemProperties.TITLE) { if (propertyKey == TabGridDialogMenuItemProperties.TITLE) {
((TextView) view).setText(model.get(TabGridDialogMenuItemProperties.TITLE)); TextView textView = view.findViewById(R.id.menu_item_text);
textView.setText(model.get(TabGridDialogMenuItemProperties.TITLE));
} }
} }
} }
...@@ -505,7 +505,7 @@ public class TabGridDialogTest { ...@@ -505,7 +505,7 @@ public class TabGridDialogTest {
private void verifyTabGridDialogToolbarMenuItem(ListView listView, int index, String text) { private void verifyTabGridDialogToolbarMenuItem(ListView listView, int index, String text) {
View menuItemView = listView.getChildAt(index); View menuItemView = listView.getChildAt(index);
TextView menuItemText = menuItemView.findViewById(R.id.menu_item); TextView menuItemText = menuItemView.findViewById(R.id.menu_item_text);
assertEquals(text, menuItemText.getText()); assertEquals(text, menuItemText.getText());
} }
......
...@@ -197,7 +197,7 @@ public class StripLayoutHelper implements StripLayoutTab.StripLayoutTabDelegate ...@@ -197,7 +197,7 @@ public class StripLayoutHelper implements StripLayoutTab.StripLayoutTabDelegate
// Create tab menu // Create tab menu
mTabMenu = new ListPopupWindow(mContext); mTabMenu = new ListPopupWindow(mContext);
mTabMenu.setAdapter(new ArrayAdapter<String>(mContext, R.layout.list_menu_item, mTabMenu.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
new String[] { new String[] {
mContext.getString(!mIncognito ? R.string.menu_close_all_tabs mContext.getString(!mIncognito ? R.string.menu_close_all_tabs
: R.string.menu_close_all_incognito_tabs)})); : R.string.menu_close_all_incognito_tabs)}));
......
...@@ -2,16 +2,30 @@ ...@@ -2,16 +2,30 @@
<!-- Copyright 2017 The Chromium Authors. All rights reserved. <!-- Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<!-- Do not replace this with TextViewWithCompoundDrawables
<org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables https://crbug.com/1053448 -->
xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_item"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.ListMenuItem"
android:drawablePadding="@dimen/menu_drawable_padding"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
style="@style/ListMenuItemStyle" style="@style/ListMenuItemStyle"
app:chromeDrawableTint="@color/default_icon_color_secondary" /> android:minHeight="?android:attr/listPreferredItemHeightSmall" >
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/menu_item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tint="@color/default_icon_color_secondary" />
<TextView
android:id="@+id/menu_item_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:singleLine="false"
android:textAppearance="@style/TextAppearance.ListMenuItem" />
</LinearLayout>
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
<!-- Custom Menu dimensions --> <!-- Custom Menu dimensions -->
<dimen name="menu_negative_software_vertical_offset">0dp</dimen> <dimen name="menu_negative_software_vertical_offset">0dp</dimen>
<dimen name="menu_divider_padding">8dp</dimen> <dimen name="menu_divider_padding">8dp</dimen>
<dimen name="menu_drawable_padding">16dp</dimen>
<dimen name="menu_padding_start">16dp</dimen> <dimen name="menu_padding_start">16dp</dimen>
<!-- Drag-Reorderable List dimensions --> <!-- Drag-Reorderable List dimensions -->
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
<!-- ListMenuButton --> <!-- ListMenuButton -->
<style name="ListMenuItemStyle"> <style name="ListMenuItemStyle">
<item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item> <item name="android:paddingStart">@dimen/default_list_row_padding</item>
<item name="android:paddingEnd">?android:attr/listPreferredItemPaddingEnd</item> <item name="android:paddingEnd">@dimen/default_list_row_padding</item>
</style> </style>
<style name="OverflowMenuAnim"> <style name="OverflowMenuAnim">
......
...@@ -9,7 +9,8 @@ import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey; ...@@ -9,7 +9,8 @@ import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey;
/** /**
* The properties controlling the state of the list menu items. * The properties controlling the state of the list menu items. Any given list item can have either
* one start icon or one end icon but not both.
*/ */
public class ListMenuItemProperties { public class ListMenuItemProperties {
public static final WritableIntPropertyKey TITLE_ID = new WritableIntPropertyKey(); public static final WritableIntPropertyKey TITLE_ID = new WritableIntPropertyKey();
......
...@@ -7,45 +7,54 @@ package org.chromium.components.browser_ui.widget.listmenu; ...@@ -7,45 +7,54 @@ package org.chromium.components.browser_ui.widget.listmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.components.browser_ui.widget.R; import org.chromium.components.browser_ui.widget.R;
import org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModel.ReadableIntPropertyKey;
/** /**
* Class responsible for binding the model of the ListMenuItem and the view. * Class responsible for binding the model of the ListMenuItem and the view.
*/ */
public class ListMenuItemViewBinder { public class ListMenuItemViewBinder {
public static void binder(PropertyModel model, View view, PropertyKey propertyKey) { public static void binder(PropertyModel model, View view, PropertyKey propertyKey) {
TextViewWithCompoundDrawables textView = (TextViewWithCompoundDrawables) view; TextView textView = view.findViewById(R.id.menu_item_text);
ImageView imageView = view.findViewById(R.id.menu_item_icon);
if (propertyKey == ListMenuItemProperties.TITLE_ID) { if (propertyKey == ListMenuItemProperties.TITLE_ID) {
textView.setText(model.get(ListMenuItemProperties.TITLE_ID)); textView.setText(model.get(ListMenuItemProperties.TITLE_ID));
} else if (propertyKey == ListMenuItemProperties.START_ICON_ID) { } else if (propertyKey == ListMenuItemProperties.START_ICON_ID
int id = model.get(ListMenuItemProperties.START_ICON_ID); || propertyKey == ListMenuItemProperties.END_ICON_ID) {
Drawable[] drawables = textView.getCompoundDrawablesRelative(); int id = model.get((ReadableIntPropertyKey) propertyKey);
Drawable drawable = Drawable drawable =
id == 0 ? null : AppCompatResources.getDrawable(view.getContext(), id); id == 0 ? null : AppCompatResources.getDrawable(view.getContext(), id);
textView.setCompoundDrawablesRelativeWithIntrinsicBounds( imageView.setImageDrawable(drawable);
drawable, drawables[1], drawables[2], drawables[3]); if (drawable != null) {
if (id != 0) { if (propertyKey == ListMenuItemProperties.START_ICON_ID) {
// need more space between the start and the icon if icon is on the start. // need more space between the start and the icon if icon is on the start.
textView.setPaddingRelative( textView.setPaddingRelative(
view.getResources().getDimensionPixelOffset(R.dimen.menu_padding_start), view.getResources().getDimensionPixelOffset(R.dimen.menu_padding_start),
view.getPaddingTop(), view.getPaddingEnd(), view.getPaddingBottom()); textView.getPaddingTop(), textView.getPaddingEnd(),
textView.getPaddingBottom());
} else {
// Move to the end.
ViewGroup layout = (ViewGroup) view;
layout.removeView(imageView);
layout.addView(imageView);
}
} }
} else if (propertyKey == ListMenuItemProperties.END_ICON_ID) {
int id = model.get(ListMenuItemProperties.END_ICON_ID);
Drawable[] drawables = textView.getCompoundDrawablesRelative();
Drawable drawable =
id == 0 ? null : AppCompatResources.getDrawable(view.getContext(), id);
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(
drawables[0], drawables[1], drawable, drawables[3]);
} else if (propertyKey == ListMenuItemProperties.TINT_COLOR_ID) { } else if (propertyKey == ListMenuItemProperties.TINT_COLOR_ID) {
textView.setDrawableTintColor(ContextCompat.getColorStateList( ApiCompatibilityUtils.setImageTintList(imageView,
view.getContext(), model.get(ListMenuItemProperties.TINT_COLOR_ID))); ContextCompat.getColorStateList(
view.getContext(), model.get(ListMenuItemProperties.TINT_COLOR_ID)));
} else if (propertyKey == ListMenuItemProperties.ENABLED) {
textView.setEnabled(model.get(ListMenuItemProperties.ENABLED));
imageView.setEnabled(model.get(ListMenuItemProperties.ENABLED));
} }
} }
} }
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