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
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.sync.SyncAndServicesSettings;
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.PropertyModelChangeProcessor;
import org.chromium.ui.widget.ViewRectProvider;
......@@ -166,7 +167,8 @@ class AssistantHeaderViewBinder
view.mTextBubble = new TextBubble(
/*context = */ view.mContext, /*rootView = */ poodle, /*contentString = */ message,
/*accessibilityString = */ message, /*showArrow = */ true,
/*anchorRectProvider = */ new ViewRectProvider(poodle));
/*anchorRectProvider = */ new ViewRectProvider(poodle),
AccessibilityUtil.isAccessibilityEnabled());
view.mTextBubble.setDismissOnTouchInteraction(true);
view.mTextBubble.show();
}
......
......@@ -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.profiles.Profile;
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.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker;
......@@ -61,7 +62,8 @@ class KeyboardAccessoryIPHUtils {
@StringRes
int helpText = getHelpTextForFeature(feature);
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.show();
// 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;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
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.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker;
......@@ -72,8 +73,8 @@ public class TabGroupUtils {
ViewRectProvider rectProvider = new ViewRectProvider(view);
TextBubble textBubble = new TextBubble(
view.getContext(), view, textId, accessibilityTextId, true, rectProvider);
TextBubble textBubble = new TextBubble(view.getContext(), view, textId, accessibilityTextId,
true, rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> tracker.dismissed(featureName));
textBubble.show();
......
......@@ -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.profiles.Profile;
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.ui.widget.ViewRectProvider;
......@@ -37,7 +38,8 @@ public class BasicTooltipApi implements TooltipApi {
rectProvider.setInsetPx(0, tooltipInfo.getTopInset(), 0, tooltipInfo.getBottomInset());
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.addOnDismissListener(() -> {
tracker.dismissed(featureForIPH);
......
......@@ -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.profiles.Profile;
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.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker;
......@@ -112,8 +113,8 @@ public class ContextualSearchIPH {
assert stringId != 0;
assert mHelpBubble == null;
mRectProvider = new RectProvider(getHelpBubbleAnchorRect());
mHelpBubble = new TextBubble(
mParentView.getContext(), mParentView, stringId, stringId, mRectProvider);
mHelpBubble = new TextBubble(mParentView.getContext(), mParentView, stringId, stringId,
mRectProvider, AccessibilityUtil.isAccessibilityEnabled());
mHelpBubble.setDismissOnTouchInteraction(true);
mHelpBubble.addOnDismissListener(() -> {
......
......@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.download.DirectoryOption;
import org.chromium.chrome.browser.download.DownloadDirectoryProvider;
import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter;
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.Tracker;
import org.chromium.ui.widget.ViewRectProvider;
......@@ -68,7 +69,7 @@ public class ToolbarUtils {
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_accessibility_text,
new ViewRectProvider(anchorView));
new ViewRectProvider(anchorView), AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> {
tracker.dismissed(FeatureConstants.DOWNLOAD_SETTINGS_FEATURE);
......
......@@ -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.ViewHighlighter;
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.Tracker;
import org.chromium.ui.widget.ViewRectProvider;
......@@ -61,8 +62,9 @@ public class ExploreSitesIPH {
ViewRectProvider rectProvider = new ViewRectProvider(tileView);
TextBubble textBubble = new TextBubble(tileView.getContext(), tileView, contentString,
accessibilityString, true, rectProvider);
TextBubble textBubble =
new TextBubble(tileView.getContext(), tileView, contentString, accessibilityString,
true, rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true);
View foregroundView = tileView.findViewById(org.chromium.chrome.R.id.tile_view_highlight);
if (foregroundView == null) return;
......
......@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.infobar.IPHInfoBarSupport.TrackerParameters;
import org.chromium.chrome.browser.permissions.PermissionSettingsBridge;
import org.chromium.chrome.browser.profiles.Profile;
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.Tracker;
......@@ -45,8 +46,8 @@ class IPHBubbleDelegateImpl implements IPHInfoBarSupport.IPHBubbleDelegate {
PopupState state = new PopupState();
state.view = anchorView;
state.feature = params.feature;
state.bubble = new TextBubble(
mContext, anchorView, params.textId, params.accessibilityTextId, anchorView);
state.bubble = new TextBubble(mContext, anchorView, params.textId,
params.accessibilityTextId, anchorView, AccessibilityUtil.isAccessibilityEnabled());
state.bubble.setDismissOnTouchInteraction(true);
return state;
......
......@@ -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.ui.appmenu.AppMenuButtonHelper;
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.components.browser_ui.styles.ChromeColors;
......@@ -218,7 +219,8 @@ class StartSurfaceToolbarView extends RelativeLayout {
*/
void showIPHOnIdentityDisc(IPHContainer iphContainer) {
TextBubble textBubble = new TextBubble(getContext(), mIdentityDiscButton,
iphContainer.stringId, iphContainer.accessibilityStringId, mIdentityDiscButton);
iphContainer.stringId, iphContainer.accessibilityStringId, mIdentityDiscButton,
AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true);
if (iphContainer.dismissedCallback != null) {
textBubble.addOnDismissListener(() -> { iphContainer.dismissedCallback.run(); });
......
......@@ -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.ui.appmenu.AppMenuButtonHelper;
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.ui.UiUtils;
import org.chromium.ui.base.ViewUtils;
......@@ -894,8 +895,9 @@ public abstract class ToolbarLayout
void showIPHOnExperimentalButton(@StringRes int stringId, @StringRes int accessibilityStringId,
Runnable dismissedCallback) {
View experimentalButton = getExperimentalButtonView();
TextBubble textBubble = new TextBubble(getContext(), experimentalButton, stringId,
accessibilityStringId, experimentalButton);
TextBubble textBubble =
new TextBubble(getContext(), experimentalButton, stringId, accessibilityStringId,
experimentalButton, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(true);
textBubble.addOnDismissListener(() -> {
dismissedCallback.run();
......
......@@ -11,6 +11,7 @@ import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.widget.highlight.ViewHighlighter;
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.ui.widget.ViewRectProvider;
......@@ -68,8 +69,9 @@ public class UserEducationHelper {
assert (!accessibilityString.isEmpty());
ViewRectProvider rectProvider = new ViewRectProvider(anchorView);
TextBubble textBubble = new TextBubble(
mActivity, anchorView, contentString, accessibilityString, true, rectProvider);
TextBubble textBubble =
new TextBubble(mActivity, anchorView, contentString, accessibilityString, true,
rectProvider, AccessibilityUtil.isAccessibilityEnabled());
textBubble.setDismissOnTouchInteraction(iphCommand.dismissOnTouch);
textBubble.addOnDismissListener(() -> anchorView.getHandler().postDelayed(() -> {
tracker.dismissed(featureName);
......
......@@ -27,11 +27,14 @@ public class ImageTextBubble extends TextBubble {
* @param showArrow Whether the bubble should have an arrow.
* @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 isAccessibilityEnabled Whether accessibility mode is enabled. Used to determine bubble
* text and dismiss UX.
*/
public ImageTextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, boolean showArrow,
RectProvider anchorRectProvider, int imageDrawableId) {
super(context, rootView, stringId, accessibilityStringId, showArrow, anchorRectProvider);
RectProvider anchorRectProvider, int imageDrawableId, boolean isAccessibilityEnabled) {
super(context, rootView, stringId, accessibilityStringId, showArrow, anchorRectProvider,
isAccessibilityEnabled);
((ImageView) mContentView.findViewById(R.id.image)).setImageResource(imageDrawableId);
}
......
......@@ -21,7 +21,6 @@ import androidx.annotation.StringRes;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.MathUtils;
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.RectProvider;
import org.chromium.ui.widget.ViewRectProvider;
......@@ -81,6 +80,8 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
/** The accessibility string associated with the bubble. */
private final String mAccessibilityString;
private final boolean mIsAccessibilityEnabled;
/** The content view shown in the popup window. */
protected View mContentView;
......@@ -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 accessibilityStringId The id of the string resource of the accessibility text.
* @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,
@StringRes int accessibilityStringId, View anchorView) {
@StringRes int accessibilityStringId, View anchorView, boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true,
new ViewRectProvider(anchorView));
new ViewRectProvider(anchorView), isAccessibilityEnabled);
}
/**
......@@ -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 accessibilityStringId The id of the string resource of the accessibility text.
* @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,
@StringRes int accessibilityStringId, Rect anchorRect) {
this(context, rootView, stringId, accessibilityStringId, true,
new RectProvider(anchorRect));
@StringRes int accessibilityStringId, Rect anchorRect, boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true, new RectProvider(anchorRect),
isAccessibilityEnabled);
}
/**
......@@ -123,11 +128,14 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param accessibilityStringId The id of the string resource of the accessibility text.
* @param showArrow Whether the bubble should have an arrow.
* @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,
@StringRes int accessibilityStringId, boolean showArrow, Rect anchorRect) {
@StringRes int accessibilityStringId, boolean showArrow, Rect anchorRect,
boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, showArrow,
new RectProvider(anchorRect));
new RectProvider(anchorRect), isAccessibilityEnabled);
}
/**
......@@ -139,8 +147,10 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param anchorRectProvider The {@link RectProvider} used to anchor the text bubble.
*/
public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId, RectProvider anchorRectProvider) {
this(context, rootView, stringId, accessibilityStringId, true, anchorRectProvider);
@StringRes int accessibilityStringId, RectProvider anchorRectProvider,
boolean isAccessibilityEnabled) {
this(context, rootView, stringId, accessibilityStringId, true, anchorRectProvider,
isAccessibilityEnabled);
}
/**
......@@ -151,12 +161,15 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param accessibilityStringId The id of the string resource of the accessibility text.
* @param showArrow Whether the bubble should have an arrow.
* @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,
@StringRes int accessibilityStringId, boolean showArrow,
RectProvider anchorRectProvider) {
RectProvider anchorRectProvider, boolean isAccessibilityEnabled) {
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 {
* @param accessibilityString The string shown in the bubble when accessibility is enabled.
* @param showArrow Whether the bubble should have an arrow.
* @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,
String accessibilityString, boolean showArrow, RectProvider anchorRectProvider) {
String accessibilityString, boolean showArrow, RectProvider anchorRectProvider,
boolean isAccessibilityEnabled) {
mContext = context;
mString = contentString;
mAccessibilityString = accessibilityString;
mIsAccessibilityEnabled = isAccessibilityEnabled;
mDrawable = new ArrowBubbleDrawable(context);
mDrawable.setShowArrow(showArrow);
......@@ -197,7 +214,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
mPopupWindow.setAnimationStyle(R.style.TextBubbleAnimation);
addOnDismissListener(mDismissListener);
if (AccessibilityUtil.isAccessibilityEnabled()) setDismissOnTouchInteraction(true);
if (mIsAccessibilityEnabled) setDismissOnTouchInteraction(true);
// Set predefined styles for the TextBubble.
mDrawable.setBubbleColor(ApiCompatibilityUtils.getColor(
......@@ -273,7 +290,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* {@link #NO_TIMEOUT} for no timeout.
*/
public void setAutoDismissTimeout(long timeoutMs) {
if (AccessibilityUtil.isAccessibilityEnabled()) return;
if (mIsAccessibilityEnabled) return;
mAutoDismissTimeoutMs = timeoutMs;
mHandler.removeCallbacks(mDismissRunnable);
......@@ -290,9 +307,7 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
public void setDismissOnTouchInteraction(boolean dismiss) {
// For accessibility mode, since there is no timeout value, the bubble can be dismissed
// only on touch interaction.
if (AccessibilityUtil.isAccessibilityEnabled()) dismiss = true;
mPopupWindow.setDismissOnTouchInteraction(dismiss);
mPopupWindow.setDismissOnTouchInteraction(mIsAccessibilityEnabled || dismiss);
}
/**
......@@ -337,6 +352,6 @@ public class TextBubble implements AnchoredPopupWindow.LayoutObserver {
* @param view The {@link TextView} to set text on.
*/
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