Commit 1a91ae76 authored by Keren Zhu's avatar Keren Zhu Committed by Commit Bot

Use callbacks instead of ButtonPressed overrides:cbuiv/iph

Bug: 772945
Change-Id: Ibfcd4c6fb74f39e95a5892573a30ff6ea9e200b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429534
Commit-Queue: Keren Zhu <kerenzhu@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810497}
parent 4387123b
......@@ -7,6 +7,8 @@
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/callback_forward.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/themes/theme_properties.h"
......@@ -65,10 +67,10 @@ namespace views {
class MdIPHBubbleButton : public MdTextButton {
public:
MdIPHBubbleButton(ButtonListener* listener,
MdIPHBubbleButton(PressedCallback callback,
const base::string16& text,
bool has_border)
: MdTextButton(listener,
: MdTextButton(callback,
text,
ChromeTextContext::CONTEXT_IPH_BUBBLE_BUTTON),
has_border_(has_border) {
......@@ -117,9 +119,7 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
focusable_(params.allow_focus),
persist_on_blur_(params.persist_on_blur),
snoozable_(params.allow_snooze),
preferred_width_(params.preferred_width),
snooze_callback_(snooze_callback),
dismiss_callback_(dismiss_callback) {
preferred_width_(params.preferred_width) {
DCHECK(params.anchor_view);
DCHECK(!params.allow_snooze || params.allow_focus)
<< "A snoozable bubble must be focusable to allow keyboard "
......@@ -216,10 +216,23 @@ FeaturePromoBubbleView::FeaturePromoBubbleView(
l10n_util::GetStringUTF16(IDS_PROMO_DISMISS_BUTTON);
bool dismiss_is_leading = views::PlatformStyle::kIsOkButtonLeading;
auto close_bubble_and_run_callback = [](FeaturePromoBubbleView* view,
base::RepeatingClosure callback,
const ui::Event& event) {
view->CloseBubble();
callback.Run();
};
snooze_button_ = button_container->AddChildView(
std::make_unique<views::MdIPHBubbleButton>(this, snooze_text, false));
std::make_unique<views::MdIPHBubbleButton>(
base::BindRepeating(close_bubble_and_run_callback,
base::Unretained(this), snooze_callback),
snooze_text, false));
dismiss_button_ = button_container->AddChildViewAt(
std::make_unique<views::MdIPHBubbleButton>(this, dismiss_text, true),
std::make_unique<views::MdIPHBubbleButton>(
base::BindRepeating(close_bubble_and_run_callback,
base::Unretained(this), dismiss_callback),
dismiss_text, true),
dismiss_is_leading ? 0 : 1);
auto* leading_button =
......@@ -289,15 +302,6 @@ void FeaturePromoBubbleView::OnMouseExited(const ui::MouseEvent& event) {
feature_promo_bubble_timeout_->OnMouseExited();
}
void FeaturePromoBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
CloseBubble();
if (sender == snooze_button_)
snooze_callback_.Run();
else // sender == dismiss_button_
dismiss_callback_.Run();
}
gfx::Rect FeaturePromoBubbleView::GetBubbleBounds() {
gfx::Rect bounds = BubbleDialogDelegateView::GetBubbleBounds();
if (!focusable_) {
......
......@@ -14,7 +14,6 @@
#include "chrome/browser/ui/views/in_product_help/feature_promo_bubble_timeout.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
namespace gfx {
class Rect;
......@@ -31,8 +30,7 @@ class MdTextButton;
// The FeaturePromoBubbleView is a special BubbleDialogDelegateView for
// in-product help which educates users about certain Chrome features in a
// deferred context.
class FeaturePromoBubbleView : public views::BubbleDialogDelegateView,
public views::ButtonListener {
class FeaturePromoBubbleView : public views::BubbleDialogDelegateView {
public:
// Disallow copy and assign.
FeaturePromoBubbleView(const FeaturePromoBubbleView&) = delete;
......@@ -69,9 +67,6 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView,
}
gfx::Size CalculatePreferredSize() const override;
// 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;
......@@ -94,9 +89,6 @@ class FeaturePromoBubbleView : public views::BubbleDialogDelegateView,
base::Optional<int> preferred_width_;
std::unique_ptr<FeaturePromoBubbleTimeout> feature_promo_bubble_timeout_;
base::RepeatingClosure snooze_callback_;
base::RepeatingClosure dismiss_callback_;
};
#endif // CHROME_BROWSER_UI_VIEWS_IN_PRODUCT_HELP_FEATURE_PROMO_BUBBLE_VIEW_H_
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