Commit 734cfab5 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: .../try_chrome_dialog_win/

Bug: 772945
Change-Id: I3b5131b40eabe286131692bc9891ee1d94afbd1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476604
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Travis Skare <skare@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarTravis Skare <skare@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817673}
parent ddc6aa83
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.h" #include "chrome/browser/ui/views/try_chrome_dialog_win/try_chrome_dialog.h"
#include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include <utility> #include <utility>
...@@ -94,8 +96,6 @@ const SkColor kButtonTextColor = SkColorSetRGB(0xFF, 0xFF, 0xFF); ...@@ -94,8 +96,6 @@ const SkColor kButtonTextColor = SkColorSetRGB(0xFF, 0xFF, 0xFF);
const SkColor kButtonAcceptColor = SkColorSetRGB(0x00, 0x78, 0xDA); const SkColor kButtonAcceptColor = SkColorSetRGB(0x00, 0x78, 0xDA);
const SkColor kButtonNoThanksColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF); const SkColor kButtonNoThanksColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF);
enum class ButtonTag { CLOSE_BUTTON, OK_BUTTON, NO_THANKS_BUTTON };
// Experiment specification information needed for layout. // Experiment specification information needed for layout.
struct ExperimentVariations { struct ExperimentVariations {
enum class CloseStyle { enum class CloseStyle {
...@@ -170,10 +170,10 @@ enum class TryChromeButtonType { OPEN_CHROME, NO_THANKS }; ...@@ -170,10 +170,10 @@ enum class TryChromeButtonType { OPEN_CHROME, NO_THANKS };
// Builds a Win10-styled rectangular button, for this toast displayed outside of // Builds a Win10-styled rectangular button, for this toast displayed outside of
// the browser. // the browser.
std::unique_ptr<views::LabelButton> CreateWin10StyleButton( std::unique_ptr<views::LabelButton> CreateWin10StyleButton(
views::ButtonListener* listener, views::Button::PressedCallback callback,
const base::string16& text, const base::string16& text,
TryChromeButtonType button_type) { TryChromeButtonType button_type) {
auto button = std::make_unique<views::LabelButton>(listener, text, auto button = std::make_unique<views::LabelButton>(std::move(callback), text,
CONTEXT_WINDOWS10_NATIVE); CONTEXT_WINDOWS10_NATIVE);
button->SetHorizontalAlignment(gfx::ALIGN_CENTER); button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
...@@ -1129,11 +1129,13 @@ void TryChromeDialog::OnContextInitialized() { ...@@ -1129,11 +1129,13 @@ void TryChromeDialog::OnContextInitialized() {
ExperimentVariations::CloseStyle::kCloseX || ExperimentVariations::CloseStyle::kCloseX ||
kExperiments[group_].close_style == kExperiments[group_].close_style ==
ExperimentVariations::CloseStyle::kNoThanksButtonAndCloseX) { ExperimentVariations::CloseStyle::kNoThanksButtonAndCloseX) {
auto close_button = std::make_unique<views::ImageButton>(this); auto close_button =
std::make_unique<views::ImageButton>(base::BindRepeating(
&TryChromeDialog::ButtonPressed, base::Unretained(this),
installer::ExperimentMetrics::kSelectedClose));
close_button->SetImage( close_button->SetImage(
views::Button::STATE_NORMAL, views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor)); gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor));
close_button->set_tag(static_cast<int>(ButtonTag::CLOSE_BUTTON));
DCHECK_EQ(close_button->GetPreferredSize().width(), kCloseButtonWidth); DCHECK_EQ(close_button->GetPreferredSize().width(), kCloseButtonWidth);
close_button_ = layout->AddView(std::move(close_button), 1, 2); close_button_ = layout->AddView(std::move(close_button), 1, 2);
close_button_->SetVisible(false); close_button_->SetVisible(false);
...@@ -1178,9 +1180,11 @@ void TryChromeDialog::OnContextInitialized() { ...@@ -1178,9 +1180,11 @@ void TryChromeDialog::OnContextInitialized() {
layout->StartRow(views::GridLayout::kFixedSize, 2); layout->StartRow(views::GridLayout::kFixedSize, 2);
auto accept_button = CreateWin10StyleButton( auto accept_button = CreateWin10StyleButton(
this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_OPEN_CHROME), base::BindRepeating(
&TryChromeDialog::ButtonPressed, base::Unretained(this),
installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash),
l10n_util::GetStringUTF16(IDS_WIN10_TOAST_OPEN_CHROME),
TryChromeButtonType::OPEN_CHROME); TryChromeButtonType::OPEN_CHROME);
accept_button->set_tag(static_cast<int>(ButtonTag::OK_BUTTON));
buttons->AddChildView(accept_button.release()); buttons->AddChildView(accept_button.release());
if (kExperiments[group_].close_style == if (kExperiments[group_].close_style ==
...@@ -1188,9 +1192,11 @@ void TryChromeDialog::OnContextInitialized() { ...@@ -1188,9 +1192,11 @@ void TryChromeDialog::OnContextInitialized() {
kExperiments[group_].close_style == kExperiments[group_].close_style ==
ExperimentVariations::CloseStyle::kNoThanksButtonAndCloseX) { ExperimentVariations::CloseStyle::kNoThanksButtonAndCloseX) {
auto no_thanks_button = CreateWin10StyleButton( auto no_thanks_button = CreateWin10StyleButton(
this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS), base::BindRepeating(&TryChromeDialog::ButtonPressed,
base::Unretained(this),
installer::ExperimentMetrics::kSelectedNoThanks),
l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS),
TryChromeButtonType::NO_THANKS); TryChromeButtonType::NO_THANKS);
no_thanks_button->set_tag(static_cast<int>(ButtonTag::NO_THANKS_BUTTON));
buttons->AddChildView(std::move(no_thanks_button)); buttons->AddChildView(std::move(no_thanks_button));
} }
...@@ -1268,8 +1274,7 @@ void TryChromeDialog::LostMouseHover() { ...@@ -1268,8 +1274,7 @@ void TryChromeDialog::LostMouseHover() {
close_button_->SetVisible(false); close_button_->SetVisible(false);
} }
void TryChromeDialog::ButtonPressed(views::Button* sender, void TryChromeDialog::ButtonPressed(installer::ExperimentMetrics::State state) {
const ui::Event& event) {
DCHECK_CALLED_ON_VALID_SEQUENCE(my_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(my_sequence_checker_);
DCHECK_EQ(result_, NOT_NOW); DCHECK_EQ(result_, NOT_NOW);
...@@ -1278,23 +1283,9 @@ void TryChromeDialog::ButtonPressed(views::Button* sender, ...@@ -1278,23 +1283,9 @@ void TryChromeDialog::ButtonPressed(views::Button* sender,
if (state_ != installer::ExperimentMetrics::kOtherClose) if (state_ != installer::ExperimentMetrics::kOtherClose)
return; return;
// Figure out what the subsequent action and experiment state should be based state_ = state;
// on which button was pressed. if (state_ == installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash)
switch (sender->tag()) { result_ = kExperiments[group_].result;
case static_cast<int>(ButtonTag::CLOSE_BUTTON):
state_ = installer::ExperimentMetrics::kSelectedClose;
break;
case static_cast<int>(ButtonTag::OK_BUTTON):
result_ = kExperiments[group_].result;
state_ = installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash;
break;
case static_cast<int>(ButtonTag::NO_THANKS_BUTTON):
state_ = installer::ExperimentMetrics::kSelectedNoThanks;
break;
default:
NOTREACHED();
break;
}
popup_->Close(); popup_->Close();
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "chrome/installer/util/experiment_metrics.h" #include "chrome/installer/util/experiment_metrics.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
namespace gfx { namespace gfx {
...@@ -40,9 +39,7 @@ class Widget; ...@@ -40,9 +39,7 @@ class Widget;
// +-----------------------------------------------+ // +-----------------------------------------------+
// //
// Some variants do not have body text, or only have one button. // Some variants do not have body text, or only have one button.
class TryChromeDialog : public views::ButtonListener, class TryChromeDialog : public views::WidgetObserver, public ui::EventHandler {
public views::WidgetObserver,
public ui::EventHandler {
public: public:
// Receives a closure to run upon process singleton notification when the // Receives a closure to run upon process singleton notification when the
// modal dialog is open, or a null closure when the active dialog is // modal dialog is open, or a null closure when the active dialog is
...@@ -124,10 +121,8 @@ class TryChromeDialog : public views::ButtonListener, ...@@ -124,10 +121,8 @@ class TryChromeDialog : public views::ButtonListener,
void GainedMouseHover(); void GainedMouseHover();
void LostMouseHover(); void LostMouseHover();
// views::ButtonListener: // Updates the result_ and state_ based on |state| and closes the dialog.
// Updates the result_ and state_ based on which button was pressed and void ButtonPressed(installer::ExperimentMetrics::State state);
// closes the dialog.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::WidgetObserver: // views::WidgetObserver:
void OnWidgetClosing(views::Widget* widget) override; void OnWidgetClosing(views::Widget* widget) override;
......
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