Commit ed84e528 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

Remove TextBubble dependency on AccessibilityUtil

This is needed to allow TextBubble to move to //components/browser_ui/.
AccessibilityUtil isn't valid outside of //chrome/ because it uses
ApplicationStatus, which isn't applicable to WebView/WebLayer.

BUG=1030785

Change-Id: I3133bb062f520deed3d9994bbfe1b60561060d41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2017930
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735241}
parent 29ac94a8
...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChipView ...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChipView
import org.chromium.chrome.browser.settings.SettingsLauncher; import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.sync.SyncAndServicesSettings; import org.chromium.chrome.browser.settings.sync.SyncAndServicesSettings;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor; import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -166,7 +167,8 @@ class AssistantHeaderViewBinder ...@@ -166,7 +167,8 @@ class AssistantHeaderViewBinder
view.mTextBubble = new TextBubble( view.mTextBubble = new TextBubble(
/*context = */ view.mContext, /*rootView = */ poodle, /*contentString = */ message, /*context = */ view.mContext, /*rootView = */ poodle, /*contentString = */ message,
/*accessibilityString = */ message, /*showArrow = */ true, /*accessibilityString = */ message, /*showArrow = */ true,
/*anchorRectProvider = */ new ViewRectProvider(poodle)); /*anchorRectProvider = */ new ViewRectProvider(poodle),
AccessibilityUtil.isAccessibilityEnabled());
view.mTextBubble.setDismissOnTouchInteraction(true); view.mTextBubble.setDismissOnTouchInteraction(true);
view.mTextBubble.show(); view.mTextBubble.show();
} }
......
...@@ -12,6 +12,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory; ...@@ -12,6 +12,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.keyboard_accessory.R; import org.chromium.chrome.browser.keyboard_accessory.R;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.textbubble.ImageTextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.ImageTextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.EventConstants; import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
...@@ -61,7 +62,8 @@ class KeyboardAccessoryIPHUtils { ...@@ -61,7 +62,8 @@ class KeyboardAccessoryIPHUtils {
@StringRes @StringRes
int helpText = getHelpTextForFeature(feature); int helpText = getHelpTextForFeature(feature);
ImageTextBubble helpBubble = new ImageTextBubble(view.getContext(), rootView, helpText, ImageTextBubble helpBubble = new ImageTextBubble(view.getContext(), rootView, helpText,
helpText, true, new ViewRectProvider(view), R.drawable.ic_chrome); helpText, true, new ViewRectProvider(view), R.drawable.ic_chrome,
AccessibilityUtil.isAccessibilityEnabled());
helpBubble.setDismissOnTouchInteraction(true); helpBubble.setDismissOnTouchInteraction(true);
helpBubble.show(); helpBubble.show();
// To emphasize which chip is pointed to, set selected to true for the built-in highlight. // To emphasize which chip is pointed to, set selected to true for the built-in highlight.
......
...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.tabmodel.TabModel; ...@@ -24,6 +24,7 @@ import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
...@@ -72,8 +73,8 @@ public class TabGroupUtils { ...@@ -72,8 +73,8 @@ public class TabGroupUtils {
ViewRectProvider rectProvider = new ViewRectProvider(view); ViewRectProvider rectProvider = new ViewRectProvider(view);
TextBubble textBubble = new TextBubble( TextBubble textBubble = new TextBubble(view.getContext(), view, textId, accessibilityTextId,
view.getContext(), view, textId, accessibilityTextId, true, rectProvider); true, rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> tracker.dismissed(featureName)); textBubble.addOnDismissListener(() -> tracker.dismissed(featureName));
textBubble.show(); textBubble.show();
......
...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.feed.library.api.host.stream.TooltipCallbackA ...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.feed.library.api.host.stream.TooltipCallbackA
import org.chromium.chrome.browser.feed.library.api.host.stream.TooltipInfo; import org.chromium.chrome.browser.feed.library.api.host.stream.TooltipInfo;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -37,7 +38,8 @@ public class BasicTooltipApi implements TooltipApi { ...@@ -37,7 +38,8 @@ public class BasicTooltipApi implements TooltipApi {
rectProvider.setInsetPx(0, tooltipInfo.getTopInset(), 0, tooltipInfo.getBottomInset()); rectProvider.setInsetPx(0, tooltipInfo.getTopInset(), 0, tooltipInfo.getBottomInset());
TextBubble textBubble = new TextBubble(view.getContext(), view, tooltipInfo.getLabel(), TextBubble textBubble = new TextBubble(view.getContext(), view, tooltipInfo.getLabel(),
tooltipInfo.getAccessibilityLabel(), true, rectProvider); tooltipInfo.getAccessibilityLabel(), true, rectProvider,
AccessibilityUtil.isAccessibilityEnabled());
textBubble.setAutoDismissTimeout(TEXT_BUBBLE_TIMEOUT_MS); textBubble.setAutoDismissTimeout(TEXT_BUBBLE_TIMEOUT_MS);
textBubble.addOnDismissListener(() -> { textBubble.addOnDismissListener(() -> {
tracker.dismissed(featureForIPH); tracker.dismissed(featureForIPH);
......
...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
import org.chromium.chrome.browser.feature_engagement.TrackerFactory; import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.EventConstants; import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
...@@ -112,8 +113,8 @@ public class ContextualSearchIPH { ...@@ -112,8 +113,8 @@ public class ContextualSearchIPH {
assert stringId != 0; assert stringId != 0;
assert mHelpBubble == null; assert mHelpBubble == null;
mRectProvider = new RectProvider(getHelpBubbleAnchorRect()); mRectProvider = new RectProvider(getHelpBubbleAnchorRect());
mHelpBubble = new TextBubble( mHelpBubble = new TextBubble(mParentView.getContext(), mParentView, stringId, stringId,
mParentView.getContext(), mParentView, stringId, stringId, mRectProvider); mRectProvider, AccessibilityUtil.isAccessibilityEnabled());
mHelpBubble.setDismissOnTouchInteraction(true); mHelpBubble.setDismissOnTouchInteraction(true);
mHelpBubble.addOnDismissListener(() -> { mHelpBubble.addOnDismissListener(() -> {
......
...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.download.DirectoryOption; ...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.download.DirectoryOption;
import org.chromium.chrome.browser.download.DownloadDirectoryProvider; import org.chromium.chrome.browser.download.DownloadDirectoryProvider;
import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter; import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -68,7 +69,7 @@ public class ToolbarUtils { ...@@ -68,7 +69,7 @@ public class ToolbarUtils {
TextBubble textBubble = new TextBubble(rootView.getContext(), rootView, TextBubble textBubble = new TextBubble(rootView.getContext(), rootView,
org.chromium.chrome.download.R.string.iph_download_settings_text, org.chromium.chrome.download.R.string.iph_download_settings_text,
org.chromium.chrome.download.R.string.iph_download_settings_accessibility_text, org.chromium.chrome.download.R.string.iph_download_settings_accessibility_text,
new ViewRectProvider(anchorView)); new ViewRectProvider(anchorView), AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> { textBubble.addOnDismissListener(() -> {
tracker.dismissed(FeatureConstants.DOWNLOAD_SETTINGS_FEATURE); tracker.dismissed(FeatureConstants.DOWNLOAD_SETTINGS_FEATURE);
......
...@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.suggestions.tile.TileView; ...@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.suggestions.tile.TileView;
import org.chromium.chrome.browser.ui.widget.highlight.PulseDrawable; import org.chromium.chrome.browser.ui.widget.highlight.PulseDrawable;
import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter; import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -61,8 +62,9 @@ public class ExploreSitesIPH { ...@@ -61,8 +62,9 @@ public class ExploreSitesIPH {
ViewRectProvider rectProvider = new ViewRectProvider(tileView); ViewRectProvider rectProvider = new ViewRectProvider(tileView);
TextBubble textBubble = new TextBubble(tileView.getContext(), tileView, contentString, TextBubble textBubble =
accessibilityString, true, rectProvider); new TextBubble(tileView.getContext(), tileView, contentString, accessibilityString,
true, rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
View foregroundView = tileView.findViewById(org.chromium.chrome.R.id.tile_view_highlight); View foregroundView = tileView.findViewById(org.chromium.chrome.R.id.tile_view_highlight);
if (foregroundView == null) return; if (foregroundView == null) return;
......
...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.infobar.IPHInfoBarSupport.TrackerParameters; ...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.infobar.IPHInfoBarSupport.TrackerParameters;
import org.chromium.chrome.browser.permissions.PermissionSettingsBridge; import org.chromium.chrome.browser.permissions.PermissionSettingsBridge;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.FeatureConstants; import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
...@@ -45,8 +46,8 @@ class IPHBubbleDelegateImpl implements IPHInfoBarSupport.IPHBubbleDelegate { ...@@ -45,8 +46,8 @@ class IPHBubbleDelegateImpl implements IPHInfoBarSupport.IPHBubbleDelegate {
PopupState state = new PopupState(); PopupState state = new PopupState();
state.view = anchorView; state.view = anchorView;
state.feature = params.feature; state.feature = params.feature;
state.bubble = new TextBubble( state.bubble = new TextBubble(mContext, anchorView, params.textId,
mContext, anchorView, params.textId, params.accessibilityTextId, anchorView); params.accessibilityTextId, anchorView, AccessibilityUtil.isAccessibilityEnabled());
state.bubble.setDismissOnTouchInteraction(true); state.bubble.setDismissOnTouchInteraction(true);
return state; return state;
......
...@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.toolbar.NewTabButton; ...@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IPHContainer; import org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IPHContainer;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper; import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.components.browser_ui.styles.ChromeColors; import org.chromium.components.browser_ui.styles.ChromeColors;
...@@ -218,7 +219,8 @@ class StartSurfaceToolbarView extends RelativeLayout { ...@@ -218,7 +219,8 @@ class StartSurfaceToolbarView extends RelativeLayout {
*/ */
void showIPHOnIdentityDisc(IPHContainer iphContainer) { void showIPHOnIdentityDisc(IPHContainer iphContainer) {
TextBubble textBubble = new TextBubble(getContext(), mIdentityDiscButton, TextBubble textBubble = new TextBubble(getContext(), mIdentityDiscButton,
iphContainer.stringId, iphContainer.accessibilityStringId, mIdentityDiscButton); iphContainer.stringId, iphContainer.accessibilityStringId, mIdentityDiscButton,
AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
if (iphContainer.dismissedCallback != null) { if (iphContainer.dismissedCallback != null) {
textBubble.addOnDismissListener(() -> { iphContainer.dismissedCallback.run(); }); textBubble.addOnDismissListener(() -> { iphContainer.dismissedCallback.run(); });
......
...@@ -49,6 +49,7 @@ import org.chromium.chrome.browser.toolbar.ToolbarTabController; ...@@ -49,6 +49,7 @@ import org.chromium.chrome.browser.toolbar.ToolbarTabController;
import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator.UrlExpansionObserver; import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator.UrlExpansionObserver;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper; import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.security_state.ConnectionSecurityLevel; import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.ui.UiUtils; import org.chromium.ui.UiUtils;
import org.chromium.ui.base.ViewUtils; import org.chromium.ui.base.ViewUtils;
...@@ -894,8 +895,9 @@ public abstract class ToolbarLayout ...@@ -894,8 +895,9 @@ public abstract class ToolbarLayout
void showIPHOnExperimentalButton(@StringRes int stringId, @StringRes int accessibilityStringId, void showIPHOnExperimentalButton(@StringRes int stringId, @StringRes int accessibilityStringId,
Runnable dismissedCallback) { Runnable dismissedCallback) {
View experimentalButton = getExperimentalButtonView(); View experimentalButton = getExperimentalButtonView();
TextBubble textBubble = new TextBubble(getContext(), experimentalButton, stringId, TextBubble textBubble =
accessibilityStringId, experimentalButton); new TextBubble(getContext(), experimentalButton, stringId, accessibilityStringId,
experimentalButton, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true); textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> { textBubble.addOnDismissListener(() -> {
dismissedCallback.run(); dismissedCallback.run();
......
...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory; ...@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter; import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter;
import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble; import org.chromium.chrome.browser.ui.widget.textbubble.TextBubble;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.components.feature_engagement.Tracker; import org.chromium.components.feature_engagement.Tracker;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -68,8 +69,9 @@ public class UserEducationHelper { ...@@ -68,8 +69,9 @@ public class UserEducationHelper {
assert (!accessibilityString.isEmpty()); assert (!accessibilityString.isEmpty());
ViewRectProvider rectProvider = new ViewRectProvider(anchorView); ViewRectProvider rectProvider = new ViewRectProvider(anchorView);
TextBubble textBubble = new TextBubble( TextBubble textBubble =
mActivity, anchorView, contentString, accessibilityString, true, rectProvider); new TextBubble(mActivity, anchorView, contentString, accessibilityString, true,
rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(iphCommand.dismissOnTouch); textBubble.setDismissOnTouchInteraction(iphCommand.dismissOnTouch);
textBubble.addOnDismissListener(() -> anchorView.getHandler().postDelayed(() -> { textBubble.addOnDismissListener(() -> anchorView.getHandler().postDelayed(() -> {
tracker.dismissed(featureName); tracker.dismissed(featureName);
......
...@@ -27,11 +27,14 @@ public class ImageTextBubble extends TextBubble { ...@@ -27,11 +27,14 @@ public class ImageTextBubble extends TextBubble {
* @param showArrow Whether the bubble should have an arrow. * @param showArrow Whether the bubble should have an arrow.
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble. * @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
* @param imageDrawableId The resource id of the image to show at the start of the text bubble. * @param imageDrawableId The resource id of the image to show at the start of the text bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public ImageTextBubble(Context context, View rootView, @StringRes int stringId, public ImageTextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, boolean showArrow, @StringRes int accessibilityStringId, boolean showArrow,
RectProvider anchorRectProvider, int imageDrawableId) { RectProvider anchorRectProvider, int imageDrawableId, boolean isAccessibilityEnabled) {
super(context, rootView, stringId, accessibilityStringId, showArrow, anchorRectProvider); super(context, rootView, stringId, accessibilityStringId, showArrow, anchorRectProvider,
isAccessibilityEnabled);
((ImageView) mContentView.findViewById(R.id.image)).setImageResource(imageDrawableId); ((ImageView) mContentView.findViewById(R.id.image)).setImageResource(imageDrawableId);
} }
......
...@@ -21,7 +21,6 @@ import androidx.annotation.StringRes; ...@@ -21,7 +21,6 @@ import androidx.annotation.StringRes;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.MathUtils; import org.chromium.base.MathUtils;
import org.chromium.chrome.browser.ui.widget.R; import org.chromium.chrome.browser.ui.widget.R;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.ui.widget.AnchoredPopupWindow; import org.chromium.ui.widget.AnchoredPopupWindow;
import org.chromium.ui.widget.RectProvider; import org.chromium.ui.widget.RectProvider;
import org.chromium.ui.widget.ViewRectProvider; import org.chromium.ui.widget.ViewRectProvider;
...@@ -81,6 +80,8 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -81,6 +80,8 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
/** The accessibility string associated with the bubble. */ /** The accessibility string associated with the bubble. */
private final String mAccessibilityString; private final String mAccessibilityString;
private final boolean mIsAccessibilityEnabled;
/** The content view shown in the popup window. */ /** The content view shown in the popup window. */
protected View mContentView; protected View mContentView;
...@@ -92,11 +93,13 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -92,11 +93,13 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param stringId The id of the string resource for the text that should be shown. * @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text. * @param accessibilityStringId The id of the string resource of the accessibility text.
* @param anchorView The {@link View} used to anchor the bubble. * @param anchorView The {@link View} used to anchor the bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, View anchorView) { @StringRes int accessibilityStringId, View anchorView, boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true, this(context, rootView, stringId, accessibilityStringId, true,
new ViewRectProvider(anchorView)); new ViewRectProvider(anchorView), isAccessibilityEnabled);
} }
/** /**
...@@ -107,11 +110,13 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -107,11 +110,13 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param stringId The id of the string resource for the text that should be shown. * @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text. * @param accessibilityStringId The id of the string resource of the accessibility text.
* @param anchorRect The {@link Rect} used to anchor the text bubble. * @param anchorRect The {@link Rect} used to anchor the text bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, Rect anchorRect) { @StringRes int accessibilityStringId, Rect anchorRect, boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true, this(context, rootView, stringId, accessibilityStringId, true, new RectProvider(anchorRect),
new RectProvider(anchorRect)); isAccessibilityEnabled);
} }
/** /**
...@@ -123,11 +128,14 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -123,11 +128,14 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param accessibilityStringId The id of the string resource of the accessibility text. * @param accessibilityStringId The id of the string resource of the accessibility text.
* @param showArrow Whether the bubble should have an arrow. * @param showArrow Whether the bubble should have an arrow.
* @param anchorRect The {@link Rect} used to anchor the text bubble. * @param anchorRect The {@link Rect} used to anchor the text bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, boolean showArrow, Rect anchorRect) { @StringRes int accessibilityStringId, boolean showArrow, Rect anchorRect,
boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, showArrow, this(context, rootView, stringId, accessibilityStringId, showArrow,
new RectProvider(anchorRect)); new RectProvider(anchorRect), isAccessibilityEnabled);
} }
/** /**
...@@ -139,8 +147,10 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -139,8 +147,10 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble. * @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
*/ */
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, RectProvider anchorRectProvider) { @StringRes int accessibilityStringId, RectProvider anchorRectProvider,
this(context, rootView, stringId, accessibilityStringId, true, anchorRectProvider); boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true, anchorRectProvider,
isAccessibilityEnabled);
} }
/** /**
...@@ -151,12 +161,15 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -151,12 +161,15 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param accessibilityStringId The id of the string resource of the accessibility text. * @param accessibilityStringId The id of the string resource of the accessibility text.
* @param showArrow Whether the bubble should have an arrow. * @param showArrow Whether the bubble should have an arrow.
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble. * @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public TextBubble(Context context, View rootView, @StringRes int stringId, public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, boolean showArrow, @StringRes int accessibilityStringId, boolean showArrow,
RectProvider anchorRectProvider) { RectProvider anchorRectProvider, boolean isAccessibilityEnabled) {
this(context, rootView, context.getString(stringId), this(context, rootView, context.getString(stringId),
context.getString(accessibilityStringId), showArrow, anchorRectProvider); context.getString(accessibilityStringId), showArrow, anchorRectProvider,
isAccessibilityEnabled);
} }
/** /**
...@@ -167,12 +180,16 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -167,12 +180,16 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param accessibilityString The string shown in the bubble when accessibility is enabled. * @param accessibilityString The string shown in the bubble when accessibility is enabled.
* @param showArrow Whether the bubble should have an arrow. * @param showArrow Whether the bubble should have an arrow.
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble. * @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
* @param isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/ */
public TextBubble(Context context, View rootView, String contentString, public TextBubble(Context context, View rootView, String contentString,
String accessibilityString, boolean showArrow, RectProvider anchorRectProvider) { String accessibilityString, boolean showArrow, RectProvider anchorRectProvider,
boolean isAccessibilityEnabled) {
mContext = context; mContext = context;
mString = contentString; mString = contentString;
mAccessibilityString = accessibilityString; mAccessibilityString = accessibilityString;
mIsAccessibilityEnabled = isAccessibilityEnabled;
mDrawable = new ArrowBubbleDrawable(context); mDrawable = new ArrowBubbleDrawable(context);
mDrawable.setShowArrow(showArrow); mDrawable.setShowArrow(showArrow);
...@@ -197,7 +214,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -197,7 +214,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
mPopupWindow.setAnimationStyle(R.style.TextBubbleAnimation); mPopupWindow.setAnimationStyle(R.style.TextBubbleAnimation);
addOnDismissListener(mDismissListener); addOnDismissListener(mDismissListener);
if (AccessibilityUtil.isAccessibilityEnabled()) setDismissOnTouchInteraction(true); if (mIsAccessibilityEnabled) setDismissOnTouchInteraction(true);
// Set predefined styles for the TextBubble. // Set predefined styles for the TextBubble.
mDrawable.setBubbleColor(ApiCompatibilityUtils.getColor( mDrawable.setBubbleColor(ApiCompatibilityUtils.getColor(
...@@ -273,7 +290,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -273,7 +290,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* {@link #NO_TIMEOUT} for no timeout. * {@link #NO_TIMEOUT} for no timeout.
*/ */
public void setAutoDismissTimeout(long timeoutMs) { public void setAutoDismissTimeout(long timeoutMs) {
if (AccessibilityUtil.isAccessibilityEnabled()) return; if (mIsAccessibilityEnabled) return;
mAutoDismissTimeoutMs = timeoutMs; mAutoDismissTimeoutMs = timeoutMs;
mHandler.removeCallbacks(mDismissRunnable); mHandler.removeCallbacks(mDismissRunnable);
...@@ -290,9 +307,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -290,9 +307,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
public void setDismissOnTouchInteraction(boolean dismiss) { public void setDismissOnTouchInteraction(boolean dismiss) {
// For accessibility mode, since there is no timeout value, the bubble can be dismissed // For accessibility mode, since there is no timeout value, the bubble can be dismissed
// only on touch interaction. // only on touch interaction.
if (AccessibilityUtil.isAccessibilityEnabled()) dismiss = true; mPopupWindow.setDismissOnTouchInteraction(mIsAccessibilityEnabled || dismiss);
mPopupWindow.setDismissOnTouchInteraction(dismiss);
} }
/** /**
...@@ -337,6 +352,6 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver { ...@@ -337,6 +352,6 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param view The {@link TextView} to set text on. * @param view The {@link TextView} to set text on.
*/ */
protected void setText(TextView view) { protected void setText(TextView view) {
view.setText(AccessibilityUtil.isAccessibilityEnabled() ? mAccessibilityString : mString); view.setText(mIsAccessibilityEnabled ? mAccessibilityString : mString);
} }
} }
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