Commit 86297b3b authored by Jun Cai's avatar Jun Cai Committed by Commit Bot

[sms] Show SMS infobar on top of existing infobars

This CL does the following:
1. Updates infobar java code to assign a priority number to each
infobar, and high priority infobar is shown in front of low priority
infobar. If infobars have the same priorities, the most recently
added one is shown behind previous ones.
2. Update the SMS infobar to have USER_TRIGGERED priority.

Bug: 999222
Change-Id: I8f2b3ccb45dd8a6ec97ed4f0b246ac69ae60c7c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783720
Commit-Queue: Jun Cai <juncai@chromium.org>
Reviewed-by: default avatarAyu Ishii <ayui@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693863}
parent 8b872e43
...@@ -17,6 +17,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -17,6 +17,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DownloadInfoBarController; import org.chromium.chrome.browser.download.DownloadInfoBarController;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item.InfoBarPriority;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.offline_items_collection.ContentId; import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
...@@ -70,8 +71,8 @@ public class DownloadProgressInfoBar extends InfoBar { ...@@ -70,8 +71,8 @@ public class DownloadProgressInfoBar extends InfoBar {
} }
@Override @Override
public boolean isBottomMostInfoBar() { public int getPriority() {
return true; return InfoBarPriority.BACKGROUND;
} }
@Override @Override
......
...@@ -17,6 +17,7 @@ import android.widget.TextView; ...@@ -17,6 +17,7 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item.InfoBarPriority;
import org.chromium.chrome.browser.snackbar.SnackbarManager; import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties; import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties.ActionNames; import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties.ActionNames;
...@@ -238,13 +239,8 @@ public abstract class InfoBar implements InfoBarView { ...@@ -238,13 +239,8 @@ public abstract class InfoBar implements InfoBarView {
} }
@Override @Override
public boolean isLegalDisclosure() { public int getPriority() {
return false; return InfoBarPriority.PAGE_TRIGGERED;
}
@Override
public boolean isBottomMostInfoBar() {
return false;
} }
@Override @Override
......
...@@ -12,6 +12,7 @@ import android.animation.ValueAnimator; ...@@ -12,6 +12,7 @@ import android.animation.ValueAnimator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.annotation.IntDef;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Gravity; import android.view.Gravity;
import android.view.MotionEvent; import android.view.MotionEvent;
...@@ -21,6 +22,8 @@ import android.widget.FrameLayout; ...@@ -21,6 +22,8 @@ import android.widget.FrameLayout;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarAnimationListener; import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarAnimationListener;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
...@@ -66,6 +69,17 @@ public class InfoBarContainerLayout extends FrameLayout { ...@@ -66,6 +69,17 @@ public class InfoBarContainerLayout extends FrameLayout {
* An interface for items that can be added to an InfoBarContainerLayout. * An interface for items that can be added to an InfoBarContainerLayout.
*/ */
public interface Item { public interface Item {
// The infobar priority.
@IntDef({InfoBarPriority.CRITICAL, InfoBarPriority.USER_TRIGGERED,
InfoBarPriority.PAGE_TRIGGERED, InfoBarPriority.BACKGROUND})
@Retention(RetentionPolicy.SOURCE)
public @interface InfoBarPriority {
int CRITICAL = 0;
int USER_TRIGGERED = 1;
int PAGE_TRIGGERED = 2;
int BACKGROUND = 3;
}
/** /**
* Returns the View that represents this infobar. This should have no background or borders; * Returns the View that represents this infobar. This should have no background or borders;
* a background and shadow will be added by a wrapper view. * a background and shadow will be added by a wrapper view.
...@@ -91,16 +105,12 @@ public class InfoBarContainerLayout extends FrameLayout { ...@@ -91,16 +105,12 @@ public class InfoBarContainerLayout extends FrameLayout {
CharSequence getAccessibilityText(); CharSequence getAccessibilityText();
/** /**
* Returns whether the infobar is a legal disclosure and thus should be shown in front of * Returns the priority of an infobar. High priority infobar is shown in front of low
* any other infobars already visible. * priority infobar. If infobars have the same priorities, the most recently added one
* is shown behind previous ones.
*
*/ */
boolean isLegalDisclosure(); int getPriority();
/**
* Returns whether the infobar is a low prirority one and thus if there are other infobars,
* they would be shown in front of this one.
*/
boolean isBottomMostInfoBar();
/** /**
* Returns the type of infobar, as best as can be determined at this time. See * Returns the type of infobar, as best as can be determined at this time. See
...@@ -133,20 +143,16 @@ public class InfoBarContainerLayout extends FrameLayout { ...@@ -133,20 +143,16 @@ public class InfoBarContainerLayout extends FrameLayout {
} }
/** /**
* Finds the appropriate index in the infobar stack for inserting this item. Legal disclosures * Finds the appropriate index in the infobar stack for inserting this item.
* are at the top and bottommost infobar at the bottom, everything else goes in the middle.
* @param item The infobar to be inserted. * @param item The infobar to be inserted.
*/ */
private int findInsertIndex(Item item) { private int findInsertIndex(Item item) {
if (item.isLegalDisclosure()) return 0; for (int i = 0; i < mItems.size(); ++i) {
if (item.isBottomMostInfoBar()) return mItems.size(); if (item.getPriority() < mItems.get(i).getPriority()) {
return i;
// Insert at the end before any bottom most infobars. }
for (int i = 0; i < mItems.size(); i++) {
if (mItems.get(i).isBottomMostInfoBar()) return i;
} }
// Just be the last in the stack by default.
return mItems.size(); return mItems.size();
} }
......
...@@ -10,6 +10,7 @@ import org.chromium.base.ContextUtils; ...@@ -10,6 +10,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item.InfoBarPriority;
import org.chromium.chrome.browser.preferences.PreferencesLauncher; import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
...@@ -50,8 +51,8 @@ public class SearchGeolocationDisclosureInfoBar extends InfoBar { ...@@ -50,8 +51,8 @@ public class SearchGeolocationDisclosureInfoBar extends InfoBar {
} }
@Override @Override
public boolean isLegalDisclosure() { public int getPriority() {
return true; return InfoBarPriority.CRITICAL;
} }
@CalledByNative @CalledByNative
......
...@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.infobar.ConfirmInfoBar; import org.chromium.chrome.browser.infobar.ConfirmInfoBar;
import org.chromium.chrome.browser.infobar.InfoBarContainerLayout.Item.InfoBarPriority;
import org.chromium.chrome.browser.infobar.InfoBarControlLayout; import org.chromium.chrome.browser.infobar.InfoBarControlLayout;
import org.chromium.chrome.browser.infobar.InfoBarLayout; import org.chromium.chrome.browser.infobar.InfoBarLayout;
import org.chromium.ui.KeyboardVisibilityDelegate; import org.chromium.ui.KeyboardVisibilityDelegate;
...@@ -48,6 +49,11 @@ public class SmsReceiverInfoBar extends ConfirmInfoBar { ...@@ -48,6 +49,11 @@ public class SmsReceiverInfoBar extends ConfirmInfoBar {
mWindowAndroid = windowAndroid; mWindowAndroid = windowAndroid;
} }
@Override
public int getPriority() {
return InfoBarPriority.USER_TRIGGERED;
}
@Override @Override
public void createContent(InfoBarLayout layout) { public void createContent(InfoBarLayout layout) {
super.createContent(layout); super.createContent(layout);
......
...@@ -27,8 +27,7 @@ void SmsInfoBar::Create(content::WebContents* web_contents, ...@@ -27,8 +27,7 @@ void SmsInfoBar::Create(content::WebContents* web_contents,
auto infobar = auto infobar =
std::make_unique<SmsInfoBar>(web_contents, std::move(delegate)); std::make_unique<SmsInfoBar>(web_contents, std::move(delegate));
auto* infobar_service = InfoBarService::FromWebContents(web_contents); auto* infobar_service = InfoBarService::FromWebContents(web_contents);
infobar_service->RemoveAllInfoBars(/*animate=*/false); infobar_service->AddInfoBar(std::move(infobar));
infobar_service->AddInfoBar(std::move(infobar), /*replace_existing=*/true);
} }
SmsInfoBar::SmsInfoBar(content::WebContents* web_contents, SmsInfoBar::SmsInfoBar(content::WebContents* web_contents,
......
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