Commit 135cf58d authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Update Suggestions Refine button to announce refine text.

This change enables Refine button to announce also the text
that will replace the Omnibox content, if the user presses the button.

This change updates accessibility description of an already existing
component. There are no user-visible changes - only talkback
announcement is updated.

Skip-Translation-Screenshots-Check: True
Bug: 1096131
Change-Id: Ib07149b42e6216a0091592aa2dafd60c587672b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382190Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#802804}
parent d4c4648c
......@@ -80,8 +80,7 @@ public final class BaseSuggestionViewBinder<T extends View>
final ImageView actionView = actionViews.get(index);
final Action action = actions.get(index);
actionView.setOnClickListener(v -> action.callback.run());
actionView.setContentDescription(
view.getContext().getResources().getString(action.accessibilityDescription));
actionView.setContentDescription(action.accessibilityDescription);
actionView.setBackground(copyDrawable(backgroundDrawable));
updateIcon(actionView, action.icon,
ChromeColors.getPrimaryIconTintRes(!useDarkColors(model)));
......
......@@ -12,7 +12,6 @@ import android.text.style.StyleSpan;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
......@@ -125,16 +124,17 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor
PropertyModel model, OmniboxSuggestion suggestion, int position) {
@DrawableRes
int icon = 0;
@StringRes
int iconString = 0;
String iconString = null;
Runnable action = null;
if (suggestion.hasTabMatch()) {
icon = R.drawable.switch_to_tab;
iconString = R.string.accessibility_omnibox_switch_to_tab;
iconString =
mContext.getResources().getString(R.string.accessibility_omnibox_switch_to_tab);
action = () -> mSuggestionHost.onSwitchToTab(suggestion, position);
} else {
icon = R.drawable.btn_suggestion_refine;
iconString = R.string.accessibility_omnibox_btn_refine;
iconString = mContext.getResources().getString(
R.string.accessibility_omnibox_btn_refine, suggestion.getFillIntoEdit());
action = () -> mSuggestionHost.onRefineSuggestion(suggestion);
}
setCustomActions(model,
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.omnibox.suggestions.base;
import android.content.Context;
import androidx.annotation.IntDef;
import androidx.annotation.StringRes;
......@@ -35,7 +37,7 @@ public class BaseSuggestionViewProperties {
public static final class Action {
public final SuggestionDrawableState icon;
public final Runnable callback;
public final @StringRes int accessibilityDescription;
public final String accessibilityDescription;
/**
* Create a new action for suggestion.
......@@ -44,11 +46,24 @@ public class BaseSuggestionViewProperties {
* @param description Content description for the action view.
* @param callback Callback to invoke when user interacts with the icon.
*/
public Action(SuggestionDrawableState icon, @StringRes int description, Runnable callback) {
public Action(SuggestionDrawableState icon, String description, Runnable callback) {
this.icon = icon;
this.accessibilityDescription = description;
this.callback = callback;
}
/**
* Create a new action for suggestion, using Accessibility description from a resource.
*
* @param context Current context
* @param icon SuggestionDrawableState describing the icon to show.
* @param descriptionRes Resource to use as a content description for the action view.
* @param callback Callback to invoke when user interacts with the icon.
*/
public Action(Context context, SuggestionDrawableState icon, @StringRes int descriptionRes,
Runnable callback) {
this(icon, context.getResources().getString(descriptionRes), callback);
}
}
/** SuggestionDrawableState to show as a suggestion icon. */
......
......@@ -38,6 +38,8 @@ import java.util.Arrays;
* the rest of Chrome.
*/
public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
private final Context mContext;
/** The delegate for accessing the location bar for observation and modification. */
private final UrlBarDelegate mUrlBarDelegate;
......@@ -67,6 +69,7 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
Supplier<Tab> tabSupplier, Supplier<ShareDelegate> shareDelegateSupplier) {
super(context, suggestionHost);
mContext = context;
mUrlBarDelegate = locationBarDelegate;
mIconBridgeSupplier = iconBridgeSupplier;
mTabSupplier = tabSupplier;
......@@ -132,27 +135,30 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
.build());
setCustomActions(model,
Arrays.asList(new Action(SuggestionDrawableState.Builder
.forDrawableRes(getContext(),
R.drawable.ic_share_white_24dp)
.setLarge(true)
.setAllowTint(true)
.build(),
Arrays.asList(new Action(mContext,
SuggestionDrawableState.Builder
.forDrawableRes(
getContext(), R.drawable.ic_share_white_24dp)
.setLarge(true)
.setAllowTint(true)
.build(),
R.string.menu_share_page, this::onShareLink),
new Action(SuggestionDrawableState.Builder
.forDrawableRes(
getContext(), R.drawable.ic_content_copy_black)
.setLarge(true)
.setAllowTint(true)
.build(),
new Action(mContext,
SuggestionDrawableState.Builder
.forDrawableRes(
getContext(), R.drawable.ic_content_copy_black)
.setLarge(true)
.setAllowTint(true)
.build(),
R.string.copy_link, this::onCopyLink),
// TODO(https://crbug.com/1090187): do not re-use bookmark_item_edit here.
new Action(SuggestionDrawableState.Builder
.forDrawableRes(
getContext(), R.drawable.bookmark_edit_active)
.setLarge(true)
.setAllowTint(true)
.build(),
new Action(mContext,
SuggestionDrawableState.Builder
.forDrawableRes(
getContext(), R.drawable.bookmark_edit_active)
.setLarge(true)
.setAllowTint(true)
.build(),
R.string.bookmark_item_edit, this::onEditLink)));
fetchSuggestionFavicon(model, mLastProcessedSuggestionURL, mIconBridgeSupplier.get(), null);
......
......@@ -132,8 +132,8 @@ public class BaseSuggestionViewBinderUnitTest {
@Test
public void actionIcon_showIcon() {
Runnable callback = mock(Runnable.class);
List<Action> list =
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(),
List<Action> list = Arrays.asList(
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, callback));
mModel.set(BaseSuggestionViewProperties.ACTIONS, list);
......@@ -156,13 +156,13 @@ public class BaseSuggestionViewBinderUnitTest {
Runnable call2 = mock(Runnable.class);
Runnable call3 = mock(Runnable.class);
List<Action> list =
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call1),
new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call2),
new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call3));
List<Action> list = Arrays.asList(
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call1),
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call2),
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call3));
mModel.set(BaseSuggestionViewProperties.ACTIONS, list);
List<ImageView> actionButtons = mBaseView.getActionButtons();
......@@ -189,13 +189,13 @@ public class BaseSuggestionViewBinderUnitTest {
@Test
public void actionIcon_hideIcons() {
final List<Action> list =
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}));
final List<Action> list = Arrays.asList(
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}));
final List<ImageView> actionButtons = mBaseView.getActionButtons();
mModel.set(BaseSuggestionViewProperties.ACTIONS, list);
......
......@@ -3024,8 +3024,8 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_ACCESSIBILITY_TABSTRIP_INCOGNITO_IDENTIFIER_SELECTED" desc="Content description for the tab that is selected in incognito mode">
Selected Incognito Tab
</message>
<message name="IDS_ACCESSIBILITY_OMNIBOX_BTN_REFINE" desc="Content description for the omnibox refine button.">
Refine
<message name="IDS_ACCESSIBILITY_OMNIBOX_BTN_REFINE" desc="Content description for the omnibox refine button followed with the text or URL that will be shown in the Omnibox if the user clicks the refine button, eg. User input 'The' may offer a suggestion 'The meaning of life' or 'thewirecutter.com'.">
Refine: <ph name="REFINE_TEXT">%1$s<ex>The meaning of life</ex></ph>
</message>
<message name="IDS_ACCESSIBILITY_OMNIBOX_SWITCH_TO_TAB" desc="Content description for the omnibox switch to tab button.">
Switch To Tab
......
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