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