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> ...@@ -80,8 +80,7 @@ public final class BaseSuggestionViewBinder<T extends View>
final ImageView actionView = actionViews.get(index); final ImageView actionView = actionViews.get(index);
final Action action = actions.get(index); final Action action = actions.get(index);
actionView.setOnClickListener(v -> action.callback.run()); actionView.setOnClickListener(v -> action.callback.run());
actionView.setContentDescription( actionView.setContentDescription(action.accessibilityDescription);
view.getContext().getResources().getString(action.accessibilityDescription));
actionView.setBackground(copyDrawable(backgroundDrawable)); actionView.setBackground(copyDrawable(backgroundDrawable));
updateIcon(actionView, action.icon, updateIcon(actionView, action.icon,
ChromeColors.getPrimaryIconTintRes(!useDarkColors(model))); ChromeColors.getPrimaryIconTintRes(!useDarkColors(model)));
......
...@@ -12,7 +12,6 @@ import android.text.style.StyleSpan; ...@@ -12,7 +12,6 @@ import android.text.style.StyleSpan;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
...@@ -125,16 +124,17 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor ...@@ -125,16 +124,17 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor
PropertyModel model, OmniboxSuggestion suggestion, int position) { PropertyModel model, OmniboxSuggestion suggestion, int position) {
@DrawableRes @DrawableRes
int icon = 0; int icon = 0;
@StringRes String iconString = null;
int iconString = 0;
Runnable action = null; Runnable action = null;
if (suggestion.hasTabMatch()) { if (suggestion.hasTabMatch()) {
icon = R.drawable.switch_to_tab; 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); action = () -> mSuggestionHost.onSwitchToTab(suggestion, position);
} else { } else {
icon = R.drawable.btn_suggestion_refine; 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); action = () -> mSuggestionHost.onRefineSuggestion(suggestion);
} }
setCustomActions(model, setCustomActions(model,
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.omnibox.suggestions.base; package org.chromium.chrome.browser.omnibox.suggestions.base;
import android.content.Context;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
...@@ -35,7 +37,7 @@ public class BaseSuggestionViewProperties { ...@@ -35,7 +37,7 @@ public class BaseSuggestionViewProperties {
public static final class Action { public static final class Action {
public final SuggestionDrawableState icon; public final SuggestionDrawableState icon;
public final Runnable callback; public final Runnable callback;
public final @StringRes int accessibilityDescription; public final String accessibilityDescription;
/** /**
* Create a new action for suggestion. * Create a new action for suggestion.
...@@ -44,11 +46,24 @@ public class BaseSuggestionViewProperties { ...@@ -44,11 +46,24 @@ public class BaseSuggestionViewProperties {
* @param description Content description for the action view. * @param description Content description for the action view.
* @param callback Callback to invoke when user interacts with the icon. * @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.icon = icon;
this.accessibilityDescription = description; this.accessibilityDescription = description;
this.callback = callback; 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. */ /** SuggestionDrawableState to show as a suggestion icon. */
......
...@@ -38,6 +38,8 @@ import java.util.Arrays; ...@@ -38,6 +38,8 @@ import java.util.Arrays;
* the rest of Chrome. * the rest of Chrome.
*/ */
public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor { public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
private final Context mContext;
/** The delegate for accessing the location bar for observation and modification. */ /** The delegate for accessing the location bar for observation and modification. */
private final UrlBarDelegate mUrlBarDelegate; private final UrlBarDelegate mUrlBarDelegate;
...@@ -67,6 +69,7 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor { ...@@ -67,6 +69,7 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
Supplier<Tab> tabSupplier, Supplier<ShareDelegate> shareDelegateSupplier) { Supplier<Tab> tabSupplier, Supplier<ShareDelegate> shareDelegateSupplier) {
super(context, suggestionHost); super(context, suggestionHost);
mContext = context;
mUrlBarDelegate = locationBarDelegate; mUrlBarDelegate = locationBarDelegate;
mIconBridgeSupplier = iconBridgeSupplier; mIconBridgeSupplier = iconBridgeSupplier;
mTabSupplier = tabSupplier; mTabSupplier = tabSupplier;
...@@ -132,14 +135,16 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor { ...@@ -132,14 +135,16 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
.build()); .build());
setCustomActions(model, setCustomActions(model,
Arrays.asList(new Action(SuggestionDrawableState.Builder Arrays.asList(new Action(mContext,
.forDrawableRes(getContext(), SuggestionDrawableState.Builder
R.drawable.ic_share_white_24dp) .forDrawableRes(
getContext(), R.drawable.ic_share_white_24dp)
.setLarge(true) .setLarge(true)
.setAllowTint(true) .setAllowTint(true)
.build(), .build(),
R.string.menu_share_page, this::onShareLink), R.string.menu_share_page, this::onShareLink),
new Action(SuggestionDrawableState.Builder new Action(mContext,
SuggestionDrawableState.Builder
.forDrawableRes( .forDrawableRes(
getContext(), R.drawable.ic_content_copy_black) getContext(), R.drawable.ic_content_copy_black)
.setLarge(true) .setLarge(true)
...@@ -147,7 +152,8 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor { ...@@ -147,7 +152,8 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
.build(), .build(),
R.string.copy_link, this::onCopyLink), R.string.copy_link, this::onCopyLink),
// TODO(https://crbug.com/1090187): do not re-use bookmark_item_edit here. // TODO(https://crbug.com/1090187): do not re-use bookmark_item_edit here.
new Action(SuggestionDrawableState.Builder new Action(mContext,
SuggestionDrawableState.Builder
.forDrawableRes( .forDrawableRes(
getContext(), R.drawable.bookmark_edit_active) getContext(), R.drawable.bookmark_edit_active)
.setLarge(true) .setLarge(true)
......
...@@ -132,8 +132,8 @@ public class BaseSuggestionViewBinderUnitTest { ...@@ -132,8 +132,8 @@ public class BaseSuggestionViewBinderUnitTest {
@Test @Test
public void actionIcon_showIcon() { public void actionIcon_showIcon() {
Runnable callback = mock(Runnable.class); Runnable callback = mock(Runnable.class);
List<Action> list = List<Action> list = Arrays.asList(
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, callback)); R.string.accessibility_omnibox_btn_refine, callback));
mModel.set(BaseSuggestionViewProperties.ACTIONS, list); mModel.set(BaseSuggestionViewProperties.ACTIONS, list);
...@@ -156,12 +156,12 @@ public class BaseSuggestionViewBinderUnitTest { ...@@ -156,12 +156,12 @@ public class BaseSuggestionViewBinderUnitTest {
Runnable call2 = mock(Runnable.class); Runnable call2 = mock(Runnable.class);
Runnable call3 = mock(Runnable.class); Runnable call3 = mock(Runnable.class);
List<Action> list = List<Action> list = Arrays.asList(
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call1), R.string.accessibility_omnibox_btn_refine, call1),
new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call2), R.string.accessibility_omnibox_btn_refine, call2),
new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, call3)); R.string.accessibility_omnibox_btn_refine, call3));
mModel.set(BaseSuggestionViewProperties.ACTIONS, list); mModel.set(BaseSuggestionViewProperties.ACTIONS, list);
...@@ -189,12 +189,12 @@ public class BaseSuggestionViewBinderUnitTest { ...@@ -189,12 +189,12 @@ public class BaseSuggestionViewBinderUnitTest {
@Test @Test
public void actionIcon_hideIcons() { public void actionIcon_hideIcons() {
final List<Action> list = final List<Action> list = Arrays.asList(
Arrays.asList(new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}), R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {}), R.string.accessibility_omnibox_btn_refine, () -> {}),
new Action(SuggestionDrawableState.Builder.forColor(0).build(), new Action(mActivity, SuggestionDrawableState.Builder.forColor(0).build(),
R.string.accessibility_omnibox_btn_refine, () -> {})); R.string.accessibility_omnibox_btn_refine, () -> {}));
final List<ImageView> actionButtons = mBaseView.getActionButtons(); final List<ImageView> actionButtons = mBaseView.getActionButtons();
......
...@@ -3024,8 +3024,8 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p ...@@ -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"> <message name="IDS_ACCESSIBILITY_TABSTRIP_INCOGNITO_IDENTIFIER_SELECTED" desc="Content description for the tab that is selected in incognito mode">
Selected Incognito Tab Selected Incognito Tab
</message> </message>
<message name="IDS_ACCESSIBILITY_OMNIBOX_BTN_REFINE" desc="Content description for the omnibox refine button."> <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 Refine: <ph name="REFINE_TEXT">%1$s<ex>The meaning of life</ex></ph>
</message> </message>
<message name="IDS_ACCESSIBILITY_OMNIBOX_SWITCH_TO_TAB" desc="Content description for the omnibox switch to tab button."> <message name="IDS_ACCESSIBILITY_OMNIBOX_SWITCH_TO_TAB" desc="Content description for the omnibox switch to tab button.">
Switch To Tab 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