Commit 2e218078 authored by Keren Zhu's avatar Keren Zhu Committed by Commit Bot

cbuiv: Split ActivationAction into focus and blur controls

ActivationAction controls both focus and blur behaviors of a bubble:
a) DO_NOT_ACTIVATE: no focus, persistent bubble.
b) ACTIVATE: get focus on creation, dismiss bubble on blur.
The blur behavior was not well documented.

Feature bug 1121399 introduces snoozable IPH bubble that needs to
c) get focus on creation, persist on blur.

To add support for c) and keep support for a) and b), this CL breaks
ActivationAction into two bools to control focus and blur behaviors of a
bubble separately.


Bug: 1121399
Change-Id: I2a38d740d901905bc13855d421000bff4bf2ca3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423305
Commit-Queue: Keren Zhu <kerenzhu@chromium.org>
Reviewed-by: default avatarCollin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809441}
parent 3307a497
......@@ -51,21 +51,23 @@ struct FeaturePromoBubbleParams {
// possible.
base::Optional<int> preferred_width;
enum class ActivationAction {
DO_NOT_ACTIVATE,
ACTIVATE,
};
// Determines if this bubble can be focused. If true, it will get
// focused on creation.
bool allow_focus = false;
// Determines whether the bubble's widget can be activated, and
// activates it on creation if so.
ActivationAction activation_action = ActivationAction::DO_NOT_ACTIVATE;
// Determines if this bubble will be dismissed when it loses focus.
// Only meaningful when |allow_focus| is true. When |allow_focus|
// is false, the bubble will always persist because it will never
// get blurred.
bool persist_on_blur = false;
// Determines if this IPH can be snoozed and reactivated later.
// If true, |allow_focus| must be true for keyboard accessibility.
bool allow_snooze = false;
// Changes the bubble timeout. Intended for tests, avoid use.
base::Optional<base::TimeDelta> timeout_default;
base::Optional<base::TimeDelta> timeout_short;
// Determines if this IPH can be snoozed and reactivated later.
bool allow_snooze = false;
};
#endif // CHROME_BROWSER_UI_VIEWS_IN_PRODUCT_HELP_FEATURE_PROMO_BUBBLE_PARAMS_H_
......@@ -99,12 +99,18 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
base::RepeatingClosure snooze_callback,
base::RepeatingClosure dismiss_callback)
: BubbleDialogDelegateView(params.anchor_view, params.arrow),
focusable_(params.allow_focus),
persist_on_blur_(params.persist_on_blur),
snoozable_(params.allow_snooze),
activation_action_(params.activation_action),
preferred_width_(params.preferred_width),
snooze_callback_(snooze_callback),
dismiss_callback_(dismiss_callback) {
DCHECK(params.anchor_view);
DCHECK(!params.allow_snooze || params.allow_focus)
<< "A snoozable bubble must be focusable to allow keyboard "
"accessibility.";
DCHECK(!params.persist_on_blur || params.allow_focus)
<< "A bubble that persists on blur must be focusable.";
UseCompactMargins();
// Bubble will not auto-dismiss for snoozble IPH.
......@@ -215,12 +221,13 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
dismiss_button_->SetCustomPadding(kBubbleButtonPadding);
}
if (params.activation_action ==
FeaturePromoBubbleParams::ActivationAction::DO_NOT_ACTIVATE) {
if (!focusable_) {
SetCanActivate(false);
set_shadow(views::BubbleBorder::BIG_SHADOW);
}
set_close_on_deactivate(!persist_on_blur_);
set_margins(gfx::Insets());
set_title_margins(gfx::Insets());
SetButtons(ui::DIALOG_BUTTON_NONE);
......@@ -278,8 +285,7 @@ void FeaturePromoBubbleView::ButtonPressed(views::Button* sender,
gfx::Rect FeaturePromoBubbleView::GetBubbleBounds() {
gfx::Rect bounds = BubbleDialogDelegateView::GetBubbleBounds();
if (activation_action_ ==
FeaturePromoBubbleParams::ActivationAction::DO_NOT_ACTIVATE) {
if (!focusable_) {
if (base::i18n::IsRTL())
bounds.Offset(5, 0);
else
......
......@@ -72,14 +72,23 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView,
// ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Determines if this bubble can be focused. If true, it will get
// focus on creation.
bool focusable_ = false;
// Determines if this bubble will be dismissed when it loses focus.
// Only meaningful when |focusable_| is true. When |allow_focus|
// is false, the bubble will always persist because it will never
// get blurred.
bool persist_on_blur_ = false;
// Determines if this bubble has dismiss and snooze buttons.
// If true, |focusable_| must be true for keyboard accessibility.
bool snoozable_;
views::MdTextButton* dismiss_button_ = nullptr;
views::MdTextButton* snooze_button_ = nullptr;
const FeaturePromoBubbleParams::ActivationAction activation_action_;
base::string16 accessible_name_;
base::Optional<int> preferred_width_;
......
......@@ -44,6 +44,7 @@ class FeaturePromoBubbleViewTest : public TestWithBrowserView {
params.body_string_specifier = IDS_REOPEN_TAB_PROMO;
params.anchor_view = browser_view()->contents_container();
params.arrow = views::BubbleBorder::TOP_RIGHT;
params.allow_focus = snoozable;
params.allow_snooze = snoozable;
return params;
}
......
......@@ -243,8 +243,8 @@ void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
IDS_NOTIFICATIONS_QUIET_PERMISSION_NEW_REQUEST_PROMO;
bubble_params.anchor_view = this;
bubble_params.arrow = views::BubbleBorder::TOP_RIGHT;
bubble_params.activation_action =
FeaturePromoBubbleParams::ActivationAction::ACTIVATE;
bubble_params.allow_focus = true;
bubble_params.persist_on_blur = false;
bubble_params.preferred_width = promo_width;
// Owned by its native widget. Will be destroyed as its widget is destroyed.
......
......@@ -760,8 +760,8 @@ void PasswordSaveUpdateWithAccountStoreView::ShowIPH(IPHType type) {
bubble_params.anchor_view = destination_dropdown_;
bubble_params.arrow = views::BubbleBorder::RIGHT_CENTER;
bubble_params.preferred_width = kAccountStoragePromoWidth;
bubble_params.activation_action =
FeaturePromoBubbleParams::ActivationAction::ACTIVATE;
bubble_params.allow_focus = true;
bubble_params.persist_on_blur = false;
bubble_params.timeout_default = GetRegularIPHTimeout();
bubble_params.timeout_short = GetShortIPHTimeout();
......
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