Commit e5844ce5 authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Modularization] Remove reference to InfoBarContainer from InfoBar

This CL extracts methods that InfoBar calls on InfoBarContainer into
InfoBar.Container interface. This breaks InfoBar dependency on
InfoBarContainer and allows moving InfoBar.java to
chrome/browser/ui/messages.

BUG=1056346
R=mdjones@chromium.org

Change-Id: I1b16b6021979dcdfcff1aa5e48cc9aacf613b02b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103140Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751088}
parent 57467667
......@@ -29,12 +29,38 @@ import org.chromium.ui.modelutil.PropertyModel;
public abstract class InfoBar implements InfoBarInteractionHandler, InfoBarUiItem {
private static final String TAG = "InfoBar";
/**
* Interface for InfoBar to interact with its container.
*/
public interface Container {
/**
* @return True if the infobar is in front.
*/
boolean isFrontInfoBar(InfoBar infoBar);
/**
* Remove the infobar from its container.
* @param infoBar InfoBar to remove from the View hierarchy.
*/
void removeInfoBar(InfoBar infoBar);
/**
* Notifies that an infobar's View ({@link InfoBar#getView}) has changed.
*/
void notifyInfoBarViewChanged();
/**
* @return True if the container's destroy() method has been called.
*/
boolean isDestroyed();
}
private final int mIconDrawableId;
private final Bitmap mIconBitmap;
private final @ColorRes int mIconTintId;
private final CharSequence mMessage;
private @Nullable InfoBarContainer mContainer;
private @Nullable Container mContainer;
private @Nullable View mView;
private @Nullable Context mContext;
......@@ -205,7 +231,7 @@ public abstract class InfoBar implements InfoBarInteractionHandler, InfoBarUiIte
private boolean closeInfoBar() {
if (!mIsDismissed) {
mIsDismissed = true;
if (!mContainer.hasBeenDestroyed()) {
if (!mContainer.isDestroyed()) {
// If the container was destroyed, it's already been emptied of all its infobars.
onStartedHiding();
mContainer.removeInfoBar(this);
......@@ -223,7 +249,7 @@ public abstract class InfoBar implements InfoBarInteractionHandler, InfoBarUiIte
* infobars).
*/
public boolean isFrontInfoBar() {
return mContainer.getFrontInfoBar() == this;
return mContainer.isFrontInfoBar(this);
}
/**
......@@ -236,7 +262,7 @@ public abstract class InfoBar implements InfoBarInteractionHandler, InfoBarUiIte
return mNativeInfoBarPtr;
}
void setInfoBarContainer(InfoBarContainer container) {
void setContainer(Container container) {
mContainer = container;
}
......
......@@ -37,7 +37,7 @@ import java.util.ArrayList;
* When initiated from native code, special code is needed to keep the Java and native infobar in
* sync, see NativeInfoBar.
*/
public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
public class InfoBarContainer implements UserData, KeyboardVisibilityListener, InfoBar.Container {
private static final String TAG = "InfoBarContainer";
private static final Class<InfoBarContainer> USER_DATA_KEY = InfoBarContainer.class;
......@@ -291,7 +291,7 @@ public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
}
infoBar.setContext(mInfoBarContainerView.getContext());
infoBar.setInfoBarContainer(this);
infoBar.setContainer(this);
// We notify observers immediately (before the animation starts).
for (InfoBarContainerObserver observer : mObservers) {
......@@ -317,10 +317,7 @@ public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
addInfoBar(infoBar);
}
/**
* Notifies that an infobar's View ({@link InfoBar#getView}) has changed. If the infobar is
* visible, a view swapping animation will be run.
*/
@Override
public void notifyInfoBarViewChanged() {
assert !mDestroyed;
if (mInfoBarContainerView != null) mInfoBarContainerView.notifyInfoBarViewChanged();
......@@ -341,12 +338,8 @@ public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
return mInfoBarContainerView != null ? mInfoBarContainerView.getVisibility() : View.GONE;
}
/**
* Called by {@link InfoBar} to remove itself from the view hierarchy.
*
* @param infoBar InfoBar to remove from the View hierarchy.
*/
void removeInfoBar(InfoBar infoBar) {
@Override
public void removeInfoBar(InfoBar infoBar) {
assert !mDestroyed;
if (!mInfoBars.remove(infoBar)) {
......@@ -364,11 +357,8 @@ public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
mInfoBarContainerView.removeInfoBar(infoBar);
}
/**
* @return True when this container has been emptied and its native counterpart has been
* destroyed.
*/
public boolean hasBeenDestroyed() {
@Override
public boolean isDestroyed() {
return mDestroyed;
}
......@@ -542,13 +532,10 @@ public class InfoBarContainer implements UserData, KeyboardVisibilityListener {
}
}
/**
* @return The infobar in front.
*/
@Nullable
InfoBar getFrontInfoBar() {
if (mInfoBars.isEmpty()) return null;
return mInfoBars.get(0);
@Override
public boolean isFrontInfoBar(InfoBar infoBar) {
if (mInfoBars.isEmpty()) return false;
return mInfoBars.get(0) == infoBar;
}
/**
......
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