Chromium Code Reviews| Index: chrome/browser/ui/views/try_chrome_dialog.cc |
| diff --git a/chrome/browser/ui/views/try_chrome_dialog_view.cc b/chrome/browser/ui/views/try_chrome_dialog.cc |
| similarity index 20% |
| rename from chrome/browser/ui/views/try_chrome_dialog_view.cc |
| rename to chrome/browser/ui/views/try_chrome_dialog.cc |
| index 0222f5a930f651678b44bd96c892998c5c13f248..b4687b0217310201c40f9a74c590767511c07109 100644 |
| --- a/chrome/browser/ui/views/try_chrome_dialog_view.cc |
| +++ b/chrome/browser/ui/views/try_chrome_dialog.cc |
| @@ -2,381 +2,333 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/ui/views/try_chrome_dialog_view.h" |
| +#include "chrome/browser/ui/views/try_chrome_dialog.h" |
| #include <shellapi.h> |
| #include "base/logging.h" |
| -#include "base/macros.h" |
| -#include "base/run_loop.h" |
| #include "base/strings/string16.h" |
| -#include "chrome/browser/process_singleton.h" |
| -#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| +#include "chrome/app/vector_icons/vector_icons.h" |
| +#include "chrome/browser/ui/views/harmony/chrome_typography.h" |
| #include "chrome/grit/chromium_strings.h" |
| +#include "chrome/grit/generated_resources.h" |
| #include "chrome/grit/theme_resources.h" |
| -#include "chrome/install_static/install_util.h" |
| -#include "chrome/installer/util/user_experiment.h" |
| -#include "components/strings/grit/components_strings.h" |
| -#include "ui/aura/window.h" |
| -#include "ui/aura/window_tree_host.h" |
| +#include "chrome/installer/util/experiment.h" |
| +#include "chrome/installer/util/experiment_metrics.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| #include "ui/base/l10n/l10n_util.h" |
| -#include "ui/base/resource/resource_bundle.h" |
| -#include "ui/display/screen.h" |
| -#include "ui/display/win/screen_win.h" |
| #include "ui/gfx/image/image.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| #include "ui/resources/grit/ui_resources.h" |
| #include "ui/views/background.h" |
| -#include "ui/views/controls/button/checkbox.h" |
| +#include "ui/views/border.h" |
| #include "ui/views/controls/button/image_button.h" |
| -#include "ui/views/controls/button/md_text_button.h" |
| -#include "ui/views/controls/button/radio_button.h" |
| +#include "ui/views/controls/button/label_button.h" |
| #include "ui/views/controls/image_view.h" |
| -#include "ui/views/controls/link.h" |
| -#include "ui/views/controls/separator.h" |
| #include "ui/views/layout/grid_layout.h" |
| -#include "ui/views/layout/layout_provider.h" |
| #include "ui/views/widget/widget.h" |
| namespace { |
| -const wchar_t kHelpCenterUrl[] = |
| - L"https://support.google.com/chrome/answer/150752"; |
| - |
| -enum ButtonTags { |
| - BT_NONE, |
| - BT_CLOSE_BUTTON, |
| - BT_OK_BUTTON, |
| - BT_TRY_IT_RADIO, |
| - BT_DONT_BUG_RADIO |
| +constexpr unsigned int kToastWidth = 360; |
| +constexpr int kHoverAboveTaskbarHeight = 24; |
| + |
| +const SkColor kBackgroundColor = SkColorSetRGB(0x1F, 0x1F, 0x1F); |
| +const SkColor kHeaderColor = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
| +const SkColor kBodyColor = SkColorSetARGB(0xAD, 0xFF, 0xFF, 0xFF); |
| +const SkColor kBorderColor = SkColorSetARGB(0x80, 0x80, 0x80, 0x80); |
| +const SkColor kButtonTextColor = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
| +const SkColor kButtonAcceptColor = SkColorSetRGB(0x00, 0x78, 0xDA); |
| +const SkColor kButtonNoThanksColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF); |
| + |
| +enum class ButtonTag { CLOSE_BUTTON, OK_BUTTON, NO_THANKS_BUTTON }; |
| + |
| +// Experiment specification information needed for layout. |
| +// TODO(skare): Suppress x-to-close in relevant variations. |
| +// TODO(skare): Implement hover behavior for x-to-close. |
| +struct ExperimentVariations { |
| + // Resource ID for header message string. |
| + int heading_id; |
| + // Resource ID for body message string, or 0 for no body text. |
| + int body_id; |
| + // Whether the dialog has a 'no thanks' button. Dialog will always have a |
| + // close 'x'. |
| + bool has_no_thanks_button; |
| + // Which action to take on acceptance of the dialog. |
| + TryChromeDialog::Result result; |
| }; |
| -const int kRadioGroupID = 1; |
| +constexpr ExperimentVariations kExperiments[] = { |
| + {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, 0, true, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, |
| + TryChromeDialog::OPEN_CHROME_WELCOME_WIN10}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, |
| + TryChromeDialog::OPEN_CHROME_WELCOME}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_FAST, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_SECURE, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_SMART, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_SWITCH_FAST, IDS_WIN10_TOAST_RECOMMENDATION, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_SWITCH_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_SWITCH_SMART, IDS_WIN10_TOAST_RECOMMENDATION, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_BROWSE_FAST, 0, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_BROWSE_SAFELY, 0, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_BROWSE_SMART, 0, false, |
| + TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_SWITCH_SMART_AND_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, |
| + true, TryChromeDialog::OPEN_CHROME_DEFAULT}, |
| + {IDS_WIN10_TOAST_SWITCH_SMART_AND_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, |
| + true, TryChromeDialog::OPEN_CHROME_DEFAULT}}; |
| + |
| +// Whether a button is an accept or cancel-style button. |
| +enum class TryChromeButtonType { OPEN_CHROME, NO_THANKS }; |
| + |
| +// Builds a Win10-styled rectangular button, for this toast displayed outside of |
| +// the browser. |
| +std::unique_ptr<views::LabelButton> CreateWin10StyleButton( |
| + views::ButtonListener* listener, |
| + const base::string16& text, |
| + TryChromeButtonType button_type) { |
| + auto button = base::MakeUnique<views::LabelButton>(listener, text, |
| + CONTEXT_WINDOWS10_NATIVE); |
| + button->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| + |
| + button->SetBackground(views::CreateSolidBackground( |
| + button_type == TryChromeButtonType::OPEN_CHROME ? kButtonAcceptColor |
| + : kButtonNoThanksColor)); |
| + button->SetEnabledTextColors(kButtonTextColor); |
| + // Request specific 32pt height, 160+pt width. |
| + button->SetMinSize(gfx::Size(160, 32)); |
| + button->SetMaxSize(gfx::Size(0, 32)); |
| + return button; |
| +} |
| } // namespace |
| // static |
| -TryChromeDialogView::Result TryChromeDialogView::Show( |
| - size_t flavor, |
| +TryChromeDialog::Result TryChromeDialog::Show( |
| + size_t group, |
| const ActiveModalDialogListener& listener) { |
| - if (flavor > 10000) { |
| + if (group >= arraysize(kExperiments)) { |
| // This is a test value. We want to make sure we exercise |
| // returning this early. See TryChromeDialogBrowserTest test. |
| return NOT_NOW; |
| } |
| - TryChromeDialogView dialog(flavor); |
| - TryChromeDialogView::Result result = dialog.ShowDialog( |
| - listener, kDialogType::MODAL, kUsageType::FOR_CHROME); |
| - return result; |
| + |
| + TryChromeDialog dialog(group); |
| + return dialog.ShowDialog(listener, DialogType::MODAL, UsageType::FOR_CHROME); |
| } |
| -TryChromeDialogView::TryChromeDialogView(size_t flavor) |
| - : flavor_(flavor), |
| - popup_(NULL), |
| - try_chrome_(NULL), |
| - kill_chrome_(NULL), |
| - dont_try_chrome_(NULL), |
| - make_default_(NULL), |
| - result_(COUNT) {} |
| +TryChromeDialog::TryChromeDialog(size_t group) |
| + : usage_type_(UsageType::FOR_CHROME), |
| + group_(group), |
| + popup_(nullptr), |
| + result_(NOT_NOW) {} |
| -TryChromeDialogView::~TryChromeDialogView() {} |
| +TryChromeDialog::~TryChromeDialog() {} |
| -TryChromeDialogView::Result TryChromeDialogView::ShowDialog( |
| +TryChromeDialog::Result TryChromeDialog::ShowDialog( |
| const ActiveModalDialogListener& listener, |
| - kDialogType dialog_type, |
| - kUsageType usage_type) { |
| - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + DialogType dialog_type, |
| + UsageType usage_type) { |
| + usage_type_ = usage_type; |
| - views::ImageView* icon = new views::ImageView(); |
| - icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); |
| + auto icon = base::MakeUnique<views::ImageView>(); |
| + icon->SetImage(gfx::CreateVectorIcon(kInactiveToastLogoIcon, kHeaderColor)); |
| gfx::Size icon_size = icon->GetPreferredSize(); |
| - // An approximate window size. After Layout() we'll get better bounds. |
| views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
| - params.bounds = gfx::Rect(310, 200); |
| + // An approximate window size. Layout() can adjust. |
| + params.bounds = gfx::Rect(kToastWidth, 120); |
| popup_ = new views::Widget; |
| popup_->Init(params); |
| views::View* root_view = popup_->GetRootView(); |
| - // The window color is a tiny bit off-white. |
| - root_view->SetBackground( |
| - views::CreateSolidBackground(SkColorSetRGB(0xfc, 0xfc, 0xfc))); |
| - |
| + root_view->SetBackground(views::CreateSolidBackground(kBackgroundColor)); |
| views::GridLayout* layout = views::GridLayout::CreatePanel(root_view); |
| + layout->set_minimum_size(gfx::Size(kToastWidth, 0)); |
| views::ColumnSet* columns; |
| - ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
| - const int label_spacing = |
| - provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL); |
| - const int unrelated_space_horiz = |
| - provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL); |
| - const int unrelated_space_vert = |
| - provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL); |
| - const int button_spacing_horiz = |
| - provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL); |
| - |
| - // First row: [icon][pad][text][pad][button]. |
| + // Note the right padding is smaller than other dimensions, |
| + // to acommodate the close 'x' button. |
| + static constexpr gfx::Insets kInsets(10, 10, 12, 3); |
| + root_view->SetBorder(views::CreatePaddedBorder( |
| + views::CreateSolidBorder(1, kBorderColor), kInsets)); |
| + |
| + static constexpr int kLabelSpacing = 10; |
| + static constexpr int kSpaceBetweenButtons = 4; |
| + static constexpr int kSpacingAfterHeadingHorizontal = 9; |
| + |
| + // First row: [icon][pad][text][pad][close button]. |
| + // Left padding is accomplished via border. |
| columns = layout->AddColumnSet(0); |
| columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, |
| views::GridLayout::FIXED, icon_size.width(), |
| icon_size.height()); |
| - columns->AddPaddingColumn(0, label_spacing); |
| - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - columns->AddPaddingColumn(0, unrelated_space_horiz); |
| - columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, |
| + columns->AddPaddingColumn(0, kLabelSpacing); |
| + columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, |
| views::GridLayout::USE_PREF, 0, 0); |
| + columns->AddPaddingColumn(0, kSpacingAfterHeadingHorizontal); |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::TRAILING, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + int icon_padding = icon_size.width() + kLabelSpacing; |
| - int icon_padding = icon_size.width() + label_spacing; |
| - // Optional second row: [pad][radio 1]. |
| + // Optional second row: [pad][text]. |
| columns = layout->AddColumnSet(1); |
| columns->AddPaddingColumn(0, icon_padding); |
| columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| views::GridLayout::USE_PREF, 0, 0); |
| - // Third row: [pad][radio 2]. |
| + // Third row: [pad][optional button][pad][button]. |
| columns = layout->AddColumnSet(2); |
| - columns->AddPaddingColumn(0, icon_padding); |
| - columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - |
| - // Fourth row: [pad][button][pad][button]. |
| - columns = layout->AddColumnSet(3); |
| - columns->AddPaddingColumn(0, icon_padding); |
| - columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - columns->AddPaddingColumn(0, button_spacing_horiz); |
| - columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - |
| - // Fifth row: [pad][link]. |
| - columns = layout->AddColumnSet(4); |
| - columns->AddPaddingColumn(0, icon_padding); |
| - columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - |
| - // Optional fourth row: [button]. |
| - columns = layout->AddColumnSet(5); |
| - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - |
| - // Optional fourth row: [divider] |
| - columns = layout->AddColumnSet(6); |
| - columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - |
| - // Optional fifth row [checkbox][pad][button] |
| - columns = layout->AddColumnSet(7); |
| - columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, |
| - views::GridLayout::USE_PREF, 0, 0); |
| - columns->AddPaddingColumn(0, unrelated_space_horiz); |
| + columns->AddPaddingColumn(0, 12 - kInsets.left()); |
| columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, |
| views::GridLayout::USE_PREF, 0, 0); |
| + columns->AddPaddingColumn(0, kSpaceBetweenButtons); |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0, |
| + views::GridLayout::USE_PREF, 0, 0); |
| + columns->AddPaddingColumn(0, 12 - kInsets.right()); |
| + // Padding between the top of the toast and first row is handled via border. |
| // First row. |
| layout->StartRow(0, 0); |
| - layout->AddView(icon); |
| - |
| - // Find out what experiment we are conducting. |
| - installer::ExperimentDetails experiment; |
| - if ((usage_type != kUsageType::FOR_TESTING && |
| - !install_static::SupportsRetentionExperiments()) || |
| - !installer::CreateExperimentDetails(flavor_, &experiment) || |
| - !experiment.heading) { |
| - NOTREACHED() << "Cannot determine which headline to show."; |
| - return DIALOG_ERROR; |
| - } |
| - views::Label* label = |
| - new views::Label(l10n_util::GetStringUTF16(experiment.heading), |
| - views::style::CONTEXT_DIALOG_TITLE); |
| - label->SetMultiLine(true); |
| - label->SizeToFit(200); |
| - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - layout->AddView(label); |
| - // The close button is custom. |
| - views::ImageButton* close_button = new views::ImageButton(this); |
| - close_button->SetImage(views::Button::STATE_NORMAL, |
| - rb.GetNativeImageNamed(IDR_CLOSE_2).ToImageSkia()); |
| - close_button->SetImage(views::Button::STATE_HOVERED, |
| - rb.GetNativeImageNamed(IDR_CLOSE_2_H).ToImageSkia()); |
| - close_button->SetImage(views::Button::STATE_PRESSED, |
| - rb.GetNativeImageNamed(IDR_CLOSE_2_P).ToImageSkia()); |
| - close_button->set_tag(BT_CLOSE_BUTTON); |
| - layout->AddView(close_button); |
| - |
| - // Second row. |
| - layout->StartRowWithPadding(0, 1, 0, 10); |
| - try_chrome_ = new views::RadioButton( |
| - l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); |
| - try_chrome_->SetChecked(true); |
| - try_chrome_->set_tag(BT_TRY_IT_RADIO); |
| - try_chrome_->set_listener(this); |
| - layout->AddView(try_chrome_); |
| - |
| - // Decide if the don't bug me is a button or a radio button. |
| - bool dont_bug_me_button = |
| - !!(experiment.flags & installer::kToastUiDontBugMeAsButton); |
| - |
| - // Optional third and fourth row. |
| - if (!dont_bug_me_button) { |
| - layout->StartRow(0, 1); |
| - dont_try_chrome_ = new views::RadioButton( |
| - l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); |
| - dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); |
| - dont_try_chrome_->set_listener(this); |
| - layout->AddView(dont_try_chrome_); |
| - } |
| - if (experiment.flags & installer::kToastUiUninstall) { |
| - layout->StartRow(0, 2); |
| - kill_chrome_ = new views::RadioButton( |
| - l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); |
| - layout->AddView(kill_chrome_); |
| - } |
| + layout->AddView(icon.release()); |
| + // All variants have a main header. |
| + auto header = base::MakeUnique<views::Label>( |
| + l10n_util::GetStringUTF16(kExperiments[group_].heading_id), |
| + CONTEXT_WINDOWS10_NATIVE); |
| + header->SetBackgroundColor(kBackgroundColor); |
| + header->SetEnabledColor(kHeaderColor); |
| + header->SetMultiLine(true); |
| + header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + layout->AddView(header.release()); |
| - views::LabelButton* accept_button = |
| - views::MdTextButton::CreateSecondaryUiButton( |
| - this, l10n_util::GetStringUTF16(IDS_OK)); |
| - accept_button->set_tag(BT_OK_BUTTON); |
| - |
| - views::Separator* separator = NULL; |
| - if (experiment.flags & installer::kToastUiMakeDefault) { |
| - // In this flavor we have some vertical space, then a separator line |
| - // and the 'make default' checkbox and the OK button on the same row. |
| - layout->AddPaddingRow(0, unrelated_space_vert); |
| - layout->StartRow(0, 6); |
| - separator = new views::Separator(); |
| - layout->AddView(separator); |
| - layout->AddPaddingRow(0, unrelated_space_vert); |
| - |
| - layout->StartRow(0, 7); |
| - make_default_ = new views::Checkbox( |
| - l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); |
| - make_default_->SetChecked(true); |
| - layout->AddView(make_default_); |
| - layout->AddView(accept_button); |
| - } else { |
| - // On this other flavor there is no checkbox, the OK button and possibly |
| - // the cancel button are in the same row. |
| - layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); |
| - layout->AddView(accept_button); |
| - if (dont_bug_me_button) { |
| - // The dialog needs a "Don't bug me" as a button or as a radio button, |
| - // this the button case. |
| - views::LabelButton* cancel_button = |
| - views::MdTextButton::CreateSecondaryUiButton( |
| - this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); |
| - cancel_button->set_tag(BT_CLOSE_BUTTON); |
| - layout->AddView(cancel_button); |
| - } |
| + // The close button is custom. |
| + auto close_button = base::MakeUnique<views::ImageButton>(this); |
| + close_button->SetImage( |
| + views::Button::STATE_NORMAL, |
| + gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor)); |
| + close_button->set_tag(static_cast<int>(ButtonTag::CLOSE_BUTTON)); |
| + layout->AddView(close_button.release()); |
| + |
| + // Second row: May have text or may be blank. |
| + layout->StartRow(0, 1); |
| + const int body_string_id = kExperiments[group_].body_id; |
| + if (body_string_id) { |
| + auto body_text = base::MakeUnique<views::Label>( |
| + l10n_util::GetStringUTF16(body_string_id), CONTEXT_WINDOWS10_NATIVE); |
| + body_text->SetBackgroundColor(kBackgroundColor); |
| + body_text->SetEnabledColor(kBodyColor); |
| + layout->AddView(body_text.release()); |
| } |
| - if (experiment.flags & installer::kToastUiWhyLink) { |
| - layout->StartRowWithPadding(0, 4, 0, 10); |
| - views::Link* link = |
| - new views::Link(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); |
| - link->set_listener(this); |
| - layout->AddView(link); |
| + // Third row: one or two buttons depending on group. |
| + layout->StartRowWithPadding(0, 2, 0, 12); |
| + if (!kExperiments[group_].has_no_thanks_button) |
| + layout->SkipColumns(1); |
| + auto accept_button = CreateWin10StyleButton( |
| + this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_OPEN_CHROME), |
| + TryChromeButtonType::OPEN_CHROME); |
| + accept_button->set_tag(static_cast<int>(ButtonTag::OK_BUTTON)); |
| + layout->AddView(accept_button.release()); |
| + |
| + if (kExperiments[group_].has_no_thanks_button) { |
| + auto no_thanks_button = CreateWin10StyleButton( |
| + this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS), |
| + TryChromeButtonType::NO_THANKS); |
| + no_thanks_button->set_tag(static_cast<int>(ButtonTag::NO_THANKS_BUTTON)); |
| + layout->AddView(no_thanks_button.release()); |
| } |
| - // We resize the window according to the layout manager. This takes into |
| - // account the differences between XP and Vista fonts and buttons. |
| - layout->Layout(root_view); |
| + // Padding between buttons and the edge of the view is via the border. |
| gfx::Size preferred = layout->GetPreferredSize(root_view); |
| - if (separator) { |
| - int separator_height = separator->GetPreferredSize().height(); |
| - separator->SetSize(gfx::Size(preferred.width(), separator_height)); |
| - } |
| - |
| - gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); |
| + gfx::Rect pos = ComputePopupBounds(preferred, base::i18n::IsRTL()); |
| popup_->SetBounds(pos); |
| + layout->Layout(root_view); |
| - // Carve the toast shape into the window. |
| - HWND toast_window; |
| - toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); |
| - |
| - gfx::Size size_in_pixels = display::win::ScreenWin::DIPToScreenSize( |
| - toast_window, preferred); |
| - SetToastRegion(toast_window, size_in_pixels.width(), |
| - size_in_pixels.height()); |
| + // Update pre-show stats. |
| + time_shown_ = base::TimeTicks::Now(); |
| + |
| + if (usage_type_ == UsageType::FOR_CHROME) { |
| + auto lock = storage_.AcquireLock(); |
| + installer::Experiment experiment; |
| + if (lock->LoadExperiment(&experiment)) { |
| + experiment.SetDisplayTime(base::Time::Now()); |
| + experiment.SetToastCount(experiment.toast_count() + 1); |
| + // TODO(skare): SetToastLocation via checking pinned state. |
| + // TODO(skare): SetUserSessionUptime |
| + lock->StoreExperiment(experiment); |
| + } |
| + } |
| - // Time to show the window in a modal loop. |
| popup_->Show(); |
| - |
| if (!listener.is_null()) |
| listener.Run(popup_->GetNativeView()); |
| - // If the dialog is not modal, we don't control when it is going to be |
| - // dismissed and hence we cannot inform the listener about the dialog going |
| - // away. |
| - if (dialog_type == kDialogType::MODAL) { |
| - base::RunLoop().Run(); |
| + if (dialog_type == DialogType::MODAL) { |
| + run_loop_.reset(new base::RunLoop); |
| + run_loop_->Run(); |
| if (!listener.is_null()) |
| listener.Run(nullptr); |
| } |
| return result_; |
| } |
| -gfx::Rect TryChromeDialogView::ComputeWindowPosition(const gfx::Size& size, |
| - bool is_RTL) { |
| +gfx::Rect TryChromeDialog::ComputePopupBounds(const gfx::Size& size, |
| + bool is_RTL) { |
| gfx::Point origin; |
| gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); |
| origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); |
| - origin.set_y(work_area.bottom()- size.height()); |
| + origin.set_y(work_area.bottom() - size.height() - kHoverAboveTaskbarHeight); |
| return gfx::Rect(origin, size); |
| } |
| -void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { |
| - static const POINT polygon[] = { |
| - {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. |
| - {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side. |
| - {w, h}, {0, h}}; |
| - HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); |
| - ::SetWindowRgn(window, region, FALSE); |
| -} |
| - |
| -void TryChromeDialogView::ButtonPressed(views::Button* sender, |
| - const ui::Event& event) { |
| - if (sender->tag() == BT_DONT_BUG_RADIO) { |
| - if (make_default_) { |
| - make_default_->SetChecked(false); |
| - make_default_->SetVisible(false); |
| - } |
| - return; |
| - } else if (sender->tag() == BT_TRY_IT_RADIO) { |
| - if (make_default_) { |
| - make_default_->SetVisible(true); |
| - make_default_->SetChecked(true); |
| - } |
| - return; |
| - } else if (sender->tag() == BT_CLOSE_BUTTON) { |
| - // The user pressed cancel or the [x] button. |
| +void TryChromeDialog::ButtonPressed(views::Button* sender, |
| + const ui::Event& event) { |
| + if (sender->tag() == static_cast<int>(ButtonTag::CLOSE_BUTTON) || |
| + sender->tag() == static_cast<int>(ButtonTag::NO_THANKS_BUTTON)) { |
| result_ = NOT_NOW; |
| - } else if (!try_chrome_) { |
| - // We don't have radio buttons, the user pressed ok. |
| - result_ = TRY_CHROME; |
| + } else if (sender->tag() == static_cast<int>(ButtonTag::OK_BUTTON)) { |
| + result_ = kExperiments[group_].result; |
| } else { |
| - // The outcome is according to the selected radio button. |
| - if (try_chrome_->checked()) |
| - result_ = TRY_CHROME; |
| - else if (dont_try_chrome_ && dont_try_chrome_->checked()) |
| - result_ = NOT_NOW; |
| - else if (kill_chrome_ && kill_chrome_->checked()) |
| - result_ = UNINSTALL_CHROME; |
| - else |
| - NOTREACHED() << "Unknown radio button selected"; |
| + NOTREACHED() << "Unknown button selected."; |
| } |
| - if (make_default_) { |
| - if ((result_ == TRY_CHROME) && make_default_->checked()) |
| - result_ = TRY_CHROME_AS_DEFAULT; |
| + // Update post-action stats. |
| + if (usage_type_ == UsageType::FOR_CHROME) { |
| + auto lock = storage_.AcquireLock(); |
| + installer::Experiment experiment; |
| + if (lock->LoadExperiment(&experiment)) { |
| + base::TimeDelta action_delay = (base::TimeTicks::Now() - time_shown_); |
| + experiment.SetActionDelay(action_delay); |
| + if (sender->tag() == static_cast<int>(ButtonTag::CLOSE_BUTTON)) { |
| + experiment.SetState(installer::ExperimentMetrics::kSelectedClose); |
| + } else if (sender->tag() == |
| + static_cast<int>(ButtonTag::NO_THANKS_BUTTON)) { |
| + experiment.SetState(installer::ExperimentMetrics::kSelectedNoThanks); |
| + } else { |
| + // TODO(skare): Differentiate crash/no-crash/logoff cases. |
| + experiment.SetState( |
| + installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash); |
| + } |
| + lock->StoreExperiment(experiment); |
| + } |
| } |
| popup_->Close(); |
| - base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
| -} |
| - |
| -void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { |
| - ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); |
| + popup_ = nullptr; |
| + run_loop_->QuitWhenIdle(); |
|
grt (UTC plus 2)
2017/08/21 12:04:45
should there be "if (run_loop_)" ahead of this sin
|
| } |