Commit ac6b36e8 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Replace FeaturePromoBubbleTimeout argument with plain TimeDeltas

This gives equivalent functionality, but avoids the need to construct
a complex object for each params object. Plus, it makes the params
copy-constructible.

Bug: 1106523
Change-Id: If35476314b33cdaf19703d58a084370c95a5f709
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353574Reviewed-by: default avatarDana Fried <dfried@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800266}
parent ce58a023
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
FeaturePromoBubbleParams::FeaturePromoBubbleParams() = default; FeaturePromoBubbleParams::FeaturePromoBubbleParams() = default;
FeaturePromoBubbleParams::~FeaturePromoBubbleParams() = default; FeaturePromoBubbleParams::~FeaturePromoBubbleParams() = default;
FeaturePromoBubbleParams::FeaturePromoBubbleParams(FeaturePromoBubbleParams&&) = FeaturePromoBubbleParams::FeaturePromoBubbleParams(
default; const FeaturePromoBubbleParams&) = default;
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
#include <memory> #include <memory>
#include "base/optional.h" #include "base/optional.h"
#include "base/time/time.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/views/bubble/bubble_border.h" #include "ui/views/bubble/bubble_border.h"
class FeaturePromoBubbleTimeout;
// Describes the content and appearance of an in-product help bubble. // Describes the content and appearance of an in-product help bubble.
// |body_string_specifier|, |anchor_view|, and |arrow| are required, all // |body_string_specifier|, |anchor_view|, and |arrow| are required, all
// other fields have good defaults. For consistency between different // other fields have good defaults. For consistency between different
...@@ -21,7 +20,7 @@ struct FeaturePromoBubbleParams { ...@@ -21,7 +20,7 @@ struct FeaturePromoBubbleParams {
FeaturePromoBubbleParams(); FeaturePromoBubbleParams();
~FeaturePromoBubbleParams(); ~FeaturePromoBubbleParams();
FeaturePromoBubbleParams(FeaturePromoBubbleParams&&); FeaturePromoBubbleParams(const FeaturePromoBubbleParams&);
// Promo contents: // Promo contents:
...@@ -62,7 +61,8 @@ struct FeaturePromoBubbleParams { ...@@ -62,7 +61,8 @@ struct FeaturePromoBubbleParams {
ActivationAction activation_action = ActivationAction::DO_NOT_ACTIVATE; ActivationAction activation_action = ActivationAction::DO_NOT_ACTIVATE;
// Changes the bubble timeout. Intended for tests, avoid use. // Changes the bubble timeout. Intended for tests, avoid use.
std::unique_ptr<FeaturePromoBubbleTimeout> timeout; base::Optional<base::TimeDelta> timeout_default;
base::Optional<base::TimeDelta> timeout_short;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_IN_PRODUCT_HELP_FEATURE_PROMO_BUBBLE_PARAMS_H_ #endif // CHROME_BROWSER_UI_VIEWS_IN_PRODUCT_HELP_FEATURE_PROMO_BUBBLE_PARAMS_H_
...@@ -40,19 +40,17 @@ constexpr gfx::Insets kBubbleContentsInsets(12, 16); ...@@ -40,19 +40,17 @@ constexpr gfx::Insets kBubbleContentsInsets(12, 16);
} // namespace } // namespace
FeaturePromoBubbleView::FeaturePromoBubbleView(FeaturePromoBubbleParams params) FeaturePromoBubbleView::FeaturePromoBubbleView(
const FeaturePromoBubbleParams& params)
: BubbleDialogDelegateView(params.anchor_view, params.arrow), : BubbleDialogDelegateView(params.anchor_view, params.arrow),
activation_action_(params.activation_action), activation_action_(params.activation_action),
feature_promo_bubble_timeout_(std::move(params.timeout)),
preferred_width_(params.preferred_width) { preferred_width_(params.preferred_width) {
DCHECK(params.anchor_view); DCHECK(params.anchor_view);
UseCompactMargins(); UseCompactMargins();
// If the timeout was not explicitly specified, use the default values. feature_promo_bubble_timeout_ = std::make_unique<FeaturePromoBubbleTimeout>(
if (!feature_promo_bubble_timeout_) { params.timeout_default ? *params.timeout_default : kDelayDefault,
feature_promo_bubble_timeout_ = params.timeout_short ? *params.timeout_short : kDelayShort);
std::make_unique<FeaturePromoBubbleTimeout>(kDelayDefault, kDelayShort);
}
const base::string16 body_text = const base::string16 body_text =
l10n_util::GetStringUTF16(params.body_string_specifier); l10n_util::GetStringUTF16(params.body_string_specifier);
...@@ -140,8 +138,8 @@ FeaturePromoBubbleView::~FeaturePromoBubbleView() = default; ...@@ -140,8 +138,8 @@ FeaturePromoBubbleView::~FeaturePromoBubbleView() = default;
// static // static
FeaturePromoBubbleView* FeaturePromoBubbleView::Create( FeaturePromoBubbleView* FeaturePromoBubbleView::Create(
FeaturePromoBubbleParams params) { const FeaturePromoBubbleParams& params) {
return new FeaturePromoBubbleView(std::move(params)); return new FeaturePromoBubbleView(params);
} }
void FeaturePromoBubbleView::CloseBubble() { void FeaturePromoBubbleView::CloseBubble() {
......
...@@ -32,13 +32,13 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView { ...@@ -32,13 +32,13 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView {
// Creates the promo. The returned pointer is only valid until the // Creates the promo. The returned pointer is only valid until the
// widget is destroyed. It must not be manually deleted by the caller. // widget is destroyed. It must not be manually deleted by the caller.
static FeaturePromoBubbleView* Create(FeaturePromoBubbleParams params); static FeaturePromoBubbleView* Create(const FeaturePromoBubbleParams& params);
// Closes the promo bubble. // Closes the promo bubble.
void CloseBubble(); void CloseBubble();
private: private:
explicit FeaturePromoBubbleView(FeaturePromoBubbleParams params); explicit FeaturePromoBubbleView(const FeaturePromoBubbleParams& params);
// BubbleDialogDelegateView: // BubbleDialogDelegateView:
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
...@@ -56,10 +56,10 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView { ...@@ -56,10 +56,10 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView {
base::string16 accessible_name_; base::string16 accessible_name_;
std::unique_ptr<FeaturePromoBubbleTimeout> feature_promo_bubble_timeout_;
base::Optional<int> preferred_width_; base::Optional<int> preferred_width_;
std::unique_ptr<FeaturePromoBubbleTimeout> feature_promo_bubble_timeout_;
DISALLOW_COPY_AND_ASSIGN(FeaturePromoBubbleView); DISALLOW_COPY_AND_ASSIGN(FeaturePromoBubbleView);
}; };
......
...@@ -54,9 +54,12 @@ void GlobalMediaControlsPromoController::ShowPromo() { ...@@ -54,9 +54,12 @@ void GlobalMediaControlsPromoController::ShowPromo() {
bubble_params.body_string_specifier = IDS_GLOBAL_MEDIA_CONTROLS_PROMO; bubble_params.body_string_specifier = IDS_GLOBAL_MEDIA_CONTROLS_PROMO;
bubble_params.anchor_view = owner_; bubble_params.anchor_view = owner_;
bubble_params.arrow = views::BubbleBorder::Arrow::TOP_RIGHT; bubble_params.arrow = views::BubbleBorder::Arrow::TOP_RIGHT;
if (!disable_bubble_timeout_for_test_) { if (disable_bubble_timeout_for_test_) {
bubble_params.timeout = std::make_unique<FeaturePromoBubbleTimeout>( bubble_params.timeout_default = base::TimeDelta();
kPromoHideDelay, base::TimeDelta()); bubble_params.timeout_short = base::TimeDelta();
} else {
bubble_params.timeout_default = kPromoHideDelay;
bubble_params.timeout_short = base::TimeDelta();
} }
promo_bubble_ = FeaturePromoBubbleView::Create(std::move(bubble_params)); promo_bubble_ = FeaturePromoBubbleView::Create(std::move(bubble_params));
......
...@@ -66,9 +66,10 @@ void ReopenTabPromoController::ShowPromo() { ...@@ -66,9 +66,10 @@ void ReopenTabPromoController::ShowPromo() {
bubble_params.feature_accelerator = accelerator; bubble_params.feature_accelerator = accelerator;
bubble_params.anchor_view = app_menu_button; bubble_params.anchor_view = app_menu_button;
bubble_params.arrow = views::BubbleBorder::Arrow::TOP_RIGHT; bubble_params.arrow = views::BubbleBorder::Arrow::TOP_RIGHT;
if (disable_bubble_timeout_for_test_) if (disable_bubble_timeout_for_test_) {
bubble_params.timeout = std::make_unique<FeaturePromoBubbleTimeout>( bubble_params.timeout_default = base::TimeDelta();
base::TimeDelta(), base::TimeDelta()); bubble_params.timeout_short = base::TimeDelta();
}
promo_bubble_ = FeaturePromoBubbleView::Create(std::move(bubble_params)); promo_bubble_ = FeaturePromoBubbleView::Create(std::move(bubble_params));
promo_bubble_->set_close_on_deactivate(false); promo_bubble_->set_close_on_deactivate(false);
......
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