Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/try_chrome_dialog_view.h" | 5 #include "chrome/browser/ui/views/try_chrome_dialog.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 13 #include "chrome/browser/process_singleton.h" | 11 #include "chrome/app/vector_icons/vector_icons.h" |
| 14 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 12 #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
| 15 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | |
| 16 #include "chrome/grit/theme_resources.h" | 15 #include "chrome/grit/theme_resources.h" |
| 17 #include "chrome/install_static/install_util.h" | 16 #include "chrome/installer/util/experiment.h" |
| 18 #include "chrome/installer/util/user_experiment.h" | 17 #include "chrome/installer/util/experiment_metrics.h" |
| 19 #include "components/strings/grit/components_strings.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/aura/window.h" | |
| 21 #include "ui/aura/window_tree_host.h" | |
| 22 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | |
| 24 #include "ui/display/screen.h" | |
| 25 #include "ui/display/win/screen_win.h" | |
| 26 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/paint_vector_icon.h" | |
| 27 #include "ui/resources/grit/ui_resources.h" | 22 #include "ui/resources/grit/ui_resources.h" |
| 28 #include "ui/views/background.h" | 23 #include "ui/views/background.h" |
| 29 #include "ui/views/controls/button/checkbox.h" | 24 #include "ui/views/border.h" |
| 30 #include "ui/views/controls/button/image_button.h" | 25 #include "ui/views/controls/button/image_button.h" |
| 31 #include "ui/views/controls/button/md_text_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
| 32 #include "ui/views/controls/button/radio_button.h" | |
| 33 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
| 34 #include "ui/views/controls/link.h" | |
| 35 #include "ui/views/controls/separator.h" | |
| 36 #include "ui/views/layout/grid_layout.h" | 28 #include "ui/views/layout/grid_layout.h" |
| 37 #include "ui/views/layout/layout_provider.h" | |
| 38 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 39 | 30 |
| 40 namespace { | 31 namespace { |
| 41 | 32 |
| 42 const wchar_t kHelpCenterUrl[] = | 33 constexpr unsigned int kToastWidth = 360; |
| 43 L"https://support.google.com/chrome/answer/150752"; | 34 constexpr int kHoverAboveTaskbarHeight = 24; |
| 44 | 35 |
| 45 enum ButtonTags { | 36 const SkColor kBackgroundColor = SkColorSetRGB(0x1F, 0x1F, 0x1F); |
| 46 BT_NONE, | 37 const SkColor kHeaderColor = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
| 47 BT_CLOSE_BUTTON, | 38 const SkColor kBodyColor = SkColorSetARGB(0xAD, 0xFF, 0xFF, 0xFF); |
| 48 BT_OK_BUTTON, | 39 const SkColor kBorderColor = SkColorSetARGB(0x80, 0x80, 0x80, 0x80); |
| 49 BT_TRY_IT_RADIO, | 40 const SkColor kButtonTextColor = SkColorSetRGB(0xFF, 0xFF, 0xFF); |
| 50 BT_DONT_BUG_RADIO | 41 const SkColor kButtonAcceptColor = SkColorSetRGB(0x00, 0x78, 0xDA); |
| 42 const SkColor kButtonNoThanksColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF); | |
| 43 | |
| 44 enum class ButtonTag { CLOSE_BUTTON, OK_BUTTON, NO_THANKS_BUTTON }; | |
| 45 | |
| 46 // Experiment specification information needed for layout. | |
| 47 // TODO(skare): Suppress x-to-close in relevant variations. | |
| 48 // TODO(skare): Implement hover behavior for x-to-close. | |
| 49 struct ExperimentVariations { | |
| 50 // Resource ID for header message string. | |
| 51 int heading_id; | |
| 52 // Resource ID for body message string, or 0 for no body text. | |
| 53 int body_id; | |
| 54 // Whether the dialog has a 'no thanks' button. Dialog will always have a | |
| 55 // close 'x'. | |
| 56 bool has_no_thanks_button; | |
| 57 // Which action to take on acceptance of the dialog. | |
| 58 TryChromeDialog::Result result; | |
| 51 }; | 59 }; |
| 52 | 60 |
| 53 const int kRadioGroupID = 1; | 61 constexpr ExperimentVariations kExperiments[] = { |
| 62 {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, | |
| 63 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 64 {IDS_WIN10_TOAST_RECOMMENDATION, 0, true, | |
| 65 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 66 {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, | |
| 67 TryChromeDialog::OPEN_CHROME_WELCOME_WIN10}, | |
| 68 {IDS_WIN10_TOAST_RECOMMENDATION, 0, false, | |
| 69 TryChromeDialog::OPEN_CHROME_WELCOME}, | |
| 70 {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_FAST, false, | |
| 71 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 72 {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_SECURE, false, | |
| 73 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 74 {IDS_WIN10_TOAST_RECOMMENDATION, IDS_WIN10_TOAST_SWITCH_SMART, false, | |
| 75 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 76 {IDS_WIN10_TOAST_SWITCH_FAST, IDS_WIN10_TOAST_RECOMMENDATION, false, | |
| 77 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 78 {IDS_WIN10_TOAST_SWITCH_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, false, | |
| 79 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 80 {IDS_WIN10_TOAST_SWITCH_SMART, IDS_WIN10_TOAST_RECOMMENDATION, false, | |
| 81 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 82 {IDS_WIN10_TOAST_BROWSE_FAST, 0, false, | |
| 83 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 84 {IDS_WIN10_TOAST_BROWSE_SAFELY, 0, false, | |
| 85 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 86 {IDS_WIN10_TOAST_BROWSE_SMART, 0, false, | |
| 87 TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 88 {IDS_WIN10_TOAST_SWITCH_SMART_AND_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, | |
| 89 true, TryChromeDialog::OPEN_CHROME_DEFAULT}, | |
| 90 {IDS_WIN10_TOAST_SWITCH_SMART_AND_SECURE, IDS_WIN10_TOAST_RECOMMENDATION, | |
| 91 true, TryChromeDialog::OPEN_CHROME_DEFAULT}}; | |
| 92 | |
| 93 // Whether a button is an accept or cancel-style button. | |
| 94 enum class TryChromeButtonType { OPEN_CHROME, NO_THANKS }; | |
| 95 | |
| 96 // Builds a Win10-styled rectangular button, for this toast displayed outside of | |
| 97 // the browser. | |
| 98 std::unique_ptr<views::LabelButton> CreateWin10StyleButton( | |
| 99 views::ButtonListener* listener, | |
| 100 const base::string16& text, | |
| 101 TryChromeButtonType button_type) { | |
| 102 auto button = base::MakeUnique<views::LabelButton>(listener, text, | |
| 103 CONTEXT_WINDOWS10_NATIVE); | |
| 104 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 105 | |
| 106 button->SetBackground(views::CreateSolidBackground( | |
| 107 button_type == TryChromeButtonType::OPEN_CHROME ? kButtonAcceptColor | |
| 108 : kButtonNoThanksColor)); | |
| 109 button->SetEnabledTextColors(kButtonTextColor); | |
| 110 // Request specific 32pt height, 160+pt width. | |
| 111 button->SetMinSize(gfx::Size(160, 32)); | |
| 112 button->SetMaxSize(gfx::Size(0, 32)); | |
| 113 return button; | |
| 114 } | |
| 54 | 115 |
| 55 } // namespace | 116 } // namespace |
| 56 | 117 |
| 57 // static | 118 // static |
| 58 TryChromeDialogView::Result TryChromeDialogView::Show( | 119 TryChromeDialog::Result TryChromeDialog::Show( |
| 59 size_t flavor, | 120 size_t group, |
| 60 const ActiveModalDialogListener& listener) { | 121 const ActiveModalDialogListener& listener) { |
| 61 if (flavor > 10000) { | 122 if (group >= arraysize(kExperiments)) { |
| 62 // This is a test value. We want to make sure we exercise | 123 // This is a test value. We want to make sure we exercise |
| 63 // returning this early. See TryChromeDialogBrowserTest test. | 124 // returning this early. See TryChromeDialogBrowserTest test. |
| 64 return NOT_NOW; | 125 return NOT_NOW; |
| 65 } | 126 } |
| 66 TryChromeDialogView dialog(flavor); | 127 |
| 67 TryChromeDialogView::Result result = dialog.ShowDialog( | 128 TryChromeDialog dialog(group); |
| 68 listener, kDialogType::MODAL, kUsageType::FOR_CHROME); | 129 return dialog.ShowDialog(listener, DialogType::MODAL, UsageType::FOR_CHROME); |
| 69 return result; | 130 } |
| 70 } | 131 |
| 71 | 132 TryChromeDialog::TryChromeDialog(size_t group) |
| 72 TryChromeDialogView::TryChromeDialogView(size_t flavor) | 133 : usage_type_(UsageType::FOR_CHROME), |
| 73 : flavor_(flavor), | 134 group_(group), |
| 74 popup_(NULL), | 135 popup_(nullptr), |
| 75 try_chrome_(NULL), | 136 result_(NOT_NOW) {} |
| 76 kill_chrome_(NULL), | 137 |
| 77 dont_try_chrome_(NULL), | 138 TryChromeDialog::~TryChromeDialog() {} |
| 78 make_default_(NULL), | 139 |
| 79 result_(COUNT) {} | 140 TryChromeDialog::Result TryChromeDialog::ShowDialog( |
| 80 | |
| 81 TryChromeDialogView::~TryChromeDialogView() {} | |
| 82 | |
| 83 TryChromeDialogView::Result TryChromeDialogView::ShowDialog( | |
| 84 const ActiveModalDialogListener& listener, | 141 const ActiveModalDialogListener& listener, |
| 85 kDialogType dialog_type, | 142 DialogType dialog_type, |
| 86 kUsageType usage_type) { | 143 UsageType usage_type) { |
| 87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 144 usage_type_ = usage_type; |
| 88 | 145 |
| 89 views::ImageView* icon = new views::ImageView(); | 146 auto icon = base::MakeUnique<views::ImageView>(); |
| 90 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); | 147 icon->SetImage(gfx::CreateVectorIcon(kInactiveToastLogoIcon, kHeaderColor)); |
| 91 gfx::Size icon_size = icon->GetPreferredSize(); | 148 gfx::Size icon_size = icon->GetPreferredSize(); |
| 92 | 149 |
| 93 // An approximate window size. After Layout() we'll get better bounds. | |
| 94 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 150 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 95 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; | 151 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; |
| 96 params.bounds = gfx::Rect(310, 200); | 152 // An approximate window size. Layout() can adjust. |
| 153 params.bounds = gfx::Rect(kToastWidth, 120); | |
| 97 popup_ = new views::Widget; | 154 popup_ = new views::Widget; |
| 98 popup_->Init(params); | 155 popup_->Init(params); |
| 99 | 156 |
| 100 views::View* root_view = popup_->GetRootView(); | 157 views::View* root_view = popup_->GetRootView(); |
| 101 // The window color is a tiny bit off-white. | 158 root_view->SetBackground(views::CreateSolidBackground(kBackgroundColor)); |
| 102 root_view->SetBackground( | |
| 103 views::CreateSolidBackground(SkColorSetRGB(0xfc, 0xfc, 0xfc))); | |
| 104 | |
| 105 views::GridLayout* layout = views::GridLayout::CreatePanel(root_view); | 159 views::GridLayout* layout = views::GridLayout::CreatePanel(root_view); |
| 160 layout->set_minimum_size(gfx::Size(kToastWidth, 0)); | |
| 106 views::ColumnSet* columns; | 161 views::ColumnSet* columns; |
| 107 | 162 |
| 108 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); | 163 // Note the right padding is smaller than other dimensions, |
| 109 const int label_spacing = | 164 // to acommodate the close 'x' button. |
| 110 provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL); | 165 static constexpr gfx::Insets kInsets(10, 10, 12, 3); |
| 111 const int unrelated_space_horiz = | 166 root_view->SetBorder(views::CreatePaddedBorder( |
| 112 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL); | 167 views::CreateSolidBorder(1, kBorderColor), kInsets)); |
| 113 const int unrelated_space_vert = | 168 |
| 114 provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL); | 169 static constexpr int kLabelSpacing = 10; |
| 115 const int button_spacing_horiz = | 170 static constexpr int kSpaceBetweenButtons = 4; |
| 116 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL); | 171 static constexpr int kSpacingAfterHeadingHorizontal = 9; |
| 117 | 172 |
| 118 // First row: [icon][pad][text][pad][button]. | 173 // First row: [icon][pad][text][pad][close button]. |
| 174 // Left padding is accomplished via border. | |
| 119 columns = layout->AddColumnSet(0); | 175 columns = layout->AddColumnSet(0); |
| 120 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, | 176 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, |
| 121 views::GridLayout::FIXED, icon_size.width(), | 177 views::GridLayout::FIXED, icon_size.width(), |
| 122 icon_size.height()); | 178 icon_size.height()); |
| 123 columns->AddPaddingColumn(0, label_spacing); | 179 columns->AddPaddingColumn(0, kLabelSpacing); |
| 124 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 180 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, |
| 125 views::GridLayout::USE_PREF, 0, 0); | 181 views::GridLayout::USE_PREF, 0, 0); |
| 126 columns->AddPaddingColumn(0, unrelated_space_horiz); | 182 columns->AddPaddingColumn(0, kSpacingAfterHeadingHorizontal); |
| 127 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, | 183 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::TRAILING, |
| 128 views::GridLayout::USE_PREF, 0, 0); | 184 0, views::GridLayout::USE_PREF, 0, 0); |
| 129 | 185 int icon_padding = icon_size.width() + kLabelSpacing; |
| 130 int icon_padding = icon_size.width() + label_spacing; | 186 |
| 131 // Optional second row: [pad][radio 1]. | 187 // Optional second row: [pad][text]. |
| 132 columns = layout->AddColumnSet(1); | 188 columns = layout->AddColumnSet(1); |
| 133 columns->AddPaddingColumn(0, icon_padding); | 189 columns->AddPaddingColumn(0, icon_padding); |
| 134 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | 190 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 135 views::GridLayout::USE_PREF, 0, 0); | 191 views::GridLayout::USE_PREF, 0, 0); |
| 136 | 192 |
| 137 // Third row: [pad][radio 2]. | 193 // Third row: [pad][optional button][pad][button]. |
| 138 columns = layout->AddColumnSet(2); | 194 columns = layout->AddColumnSet(2); |
| 139 columns->AddPaddingColumn(0, icon_padding); | 195 columns->AddPaddingColumn(0, 12 - kInsets.left()); |
| 140 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | |
| 141 views::GridLayout::USE_PREF, 0, 0); | |
| 142 | |
| 143 // Fourth row: [pad][button][pad][button]. | |
| 144 columns = layout->AddColumnSet(3); | |
| 145 columns->AddPaddingColumn(0, icon_padding); | |
| 146 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, | |
| 147 views::GridLayout::USE_PREF, 0, 0); | |
| 148 columns->AddPaddingColumn(0, button_spacing_horiz); | |
| 149 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, | |
| 150 views::GridLayout::USE_PREF, 0, 0); | |
| 151 | |
| 152 // Fifth row: [pad][link]. | |
| 153 columns = layout->AddColumnSet(4); | |
| 154 columns->AddPaddingColumn(0, icon_padding); | |
| 155 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | |
| 156 views::GridLayout::USE_PREF, 0, 0); | |
| 157 | |
| 158 // Optional fourth row: [button]. | |
| 159 columns = layout->AddColumnSet(5); | |
| 160 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, | |
| 161 views::GridLayout::USE_PREF, 0, 0); | |
| 162 | |
| 163 // Optional fourth row: [divider] | |
| 164 columns = layout->AddColumnSet(6); | |
| 165 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, | |
| 166 views::GridLayout::USE_PREF, 0, 0); | |
| 167 | |
| 168 // Optional fifth row [checkbox][pad][button] | |
| 169 columns = layout->AddColumnSet(7); | |
| 170 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, | |
| 171 views::GridLayout::USE_PREF, 0, 0); | |
| 172 columns->AddPaddingColumn(0, unrelated_space_horiz); | |
| 173 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, | 196 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, |
| 174 views::GridLayout::USE_PREF, 0, 0); | 197 views::GridLayout::USE_PREF, 0, 0); |
| 175 | 198 columns->AddPaddingColumn(0, kSpaceBetweenButtons); |
| 199 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0, | |
| 200 views::GridLayout::USE_PREF, 0, 0); | |
| 201 columns->AddPaddingColumn(0, 12 - kInsets.right()); | |
| 202 | |
| 203 // Padding between the top of the toast and first row is handled via border. | |
| 176 // First row. | 204 // First row. |
| 177 layout->StartRow(0, 0); | 205 layout->StartRow(0, 0); |
| 178 layout->AddView(icon); | 206 layout->AddView(icon.release()); |
| 179 | 207 // All variants have a main header. |
| 180 // Find out what experiment we are conducting. | 208 auto header = base::MakeUnique<views::Label>( |
| 181 installer::ExperimentDetails experiment; | 209 l10n_util::GetStringUTF16(kExperiments[group_].heading_id), |
| 182 if ((usage_type != kUsageType::FOR_TESTING && | 210 CONTEXT_WINDOWS10_NATIVE); |
| 183 !install_static::SupportsRetentionExperiments()) || | 211 header->SetBackgroundColor(kBackgroundColor); |
| 184 !installer::CreateExperimentDetails(flavor_, &experiment) || | 212 header->SetEnabledColor(kHeaderColor); |
| 185 !experiment.heading) { | 213 header->SetMultiLine(true); |
| 186 NOTREACHED() << "Cannot determine which headline to show."; | 214 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 187 return DIALOG_ERROR; | 215 layout->AddView(header.release()); |
| 188 } | 216 |
| 189 views::Label* label = | |
| 190 new views::Label(l10n_util::GetStringUTF16(experiment.heading), | |
| 191 views::style::CONTEXT_DIALOG_TITLE); | |
| 192 label->SetMultiLine(true); | |
| 193 label->SizeToFit(200); | |
| 194 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 195 layout->AddView(label); | |
| 196 // The close button is custom. | 217 // The close button is custom. |
| 197 views::ImageButton* close_button = new views::ImageButton(this); | 218 auto close_button = base::MakeUnique<views::ImageButton>(this); |
| 198 close_button->SetImage(views::Button::STATE_NORMAL, | 219 close_button->SetImage( |
| 199 rb.GetNativeImageNamed(IDR_CLOSE_2).ToImageSkia()); | 220 views::Button::STATE_NORMAL, |
| 200 close_button->SetImage(views::Button::STATE_HOVERED, | 221 gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor)); |
| 201 rb.GetNativeImageNamed(IDR_CLOSE_2_H).ToImageSkia()); | 222 close_button->set_tag(static_cast<int>(ButtonTag::CLOSE_BUTTON)); |
| 202 close_button->SetImage(views::Button::STATE_PRESSED, | 223 layout->AddView(close_button.release()); |
| 203 rb.GetNativeImageNamed(IDR_CLOSE_2_P).ToImageSkia()); | 224 |
| 204 close_button->set_tag(BT_CLOSE_BUTTON); | 225 // Second row: May have text or may be blank. |
| 205 layout->AddView(close_button); | 226 layout->StartRow(0, 1); |
| 206 | 227 const int body_string_id = kExperiments[group_].body_id; |
| 207 // Second row. | 228 if (body_string_id) { |
| 208 layout->StartRowWithPadding(0, 1, 0, 10); | 229 auto body_text = base::MakeUnique<views::Label>( |
| 209 try_chrome_ = new views::RadioButton( | 230 l10n_util::GetStringUTF16(body_string_id), CONTEXT_WINDOWS10_NATIVE); |
| 210 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); | 231 body_text->SetBackgroundColor(kBackgroundColor); |
| 211 try_chrome_->SetChecked(true); | 232 body_text->SetEnabledColor(kBodyColor); |
| 212 try_chrome_->set_tag(BT_TRY_IT_RADIO); | 233 layout->AddView(body_text.release()); |
| 213 try_chrome_->set_listener(this); | 234 } |
| 214 layout->AddView(try_chrome_); | 235 |
| 215 | 236 // Third row: one or two buttons depending on group. |
| 216 // Decide if the don't bug me is a button or a radio button. | 237 layout->StartRowWithPadding(0, 2, 0, 12); |
| 217 bool dont_bug_me_button = | 238 if (!kExperiments[group_].has_no_thanks_button) |
| 218 !!(experiment.flags & installer::kToastUiDontBugMeAsButton); | 239 layout->SkipColumns(1); |
| 219 | 240 auto accept_button = CreateWin10StyleButton( |
| 220 // Optional third and fourth row. | 241 this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_OPEN_CHROME), |
| 221 if (!dont_bug_me_button) { | 242 TryChromeButtonType::OPEN_CHROME); |
| 222 layout->StartRow(0, 1); | 243 accept_button->set_tag(static_cast<int>(ButtonTag::OK_BUTTON)); |
| 223 dont_try_chrome_ = new views::RadioButton( | 244 layout->AddView(accept_button.release()); |
| 224 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); | 245 |
| 225 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); | 246 if (kExperiments[group_].has_no_thanks_button) { |
| 226 dont_try_chrome_->set_listener(this); | 247 auto no_thanks_button = CreateWin10StyleButton( |
| 227 layout->AddView(dont_try_chrome_); | 248 this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS), |
| 228 } | 249 TryChromeButtonType::NO_THANKS); |
| 229 if (experiment.flags & installer::kToastUiUninstall) { | 250 no_thanks_button->set_tag(static_cast<int>(ButtonTag::NO_THANKS_BUTTON)); |
| 230 layout->StartRow(0, 2); | 251 layout->AddView(no_thanks_button.release()); |
| 231 kill_chrome_ = new views::RadioButton( | 252 } |
| 232 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); | 253 |
| 233 layout->AddView(kill_chrome_); | 254 // Padding between buttons and the edge of the view is via the border. |
| 234 } | 255 gfx::Size preferred = layout->GetPreferredSize(root_view); |
| 235 | 256 gfx::Rect pos = ComputePopupBounds(preferred, base::i18n::IsRTL()); |
| 236 views::LabelButton* accept_button = | 257 popup_->SetBounds(pos); |
| 237 views::MdTextButton::CreateSecondaryUiButton( | 258 layout->Layout(root_view); |
| 238 this, l10n_util::GetStringUTF16(IDS_OK)); | 259 |
| 239 accept_button->set_tag(BT_OK_BUTTON); | 260 // Update pre-show stats. |
| 240 | 261 time_shown_ = base::TimeTicks::Now(); |
| 241 views::Separator* separator = NULL; | 262 |
| 242 if (experiment.flags & installer::kToastUiMakeDefault) { | 263 if (usage_type_ == UsageType::FOR_CHROME) { |
| 243 // In this flavor we have some vertical space, then a separator line | 264 auto lock = storage_.AcquireLock(); |
| 244 // and the 'make default' checkbox and the OK button on the same row. | 265 installer::Experiment experiment; |
| 245 layout->AddPaddingRow(0, unrelated_space_vert); | 266 if (lock->LoadExperiment(&experiment)) { |
| 246 layout->StartRow(0, 6); | 267 experiment.SetDisplayTime(base::Time::Now()); |
| 247 separator = new views::Separator(); | 268 experiment.SetToastCount(experiment.toast_count() + 1); |
| 248 layout->AddView(separator); | 269 // TODO(skare): SetToastLocation via checking pinned state. |
| 249 layout->AddPaddingRow(0, unrelated_space_vert); | 270 // TODO(skare): SetUserSessionUptime |
| 250 | 271 lock->StoreExperiment(experiment); |
| 251 layout->StartRow(0, 7); | |
| 252 make_default_ = new views::Checkbox( | |
| 253 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); | |
| 254 make_default_->SetChecked(true); | |
| 255 layout->AddView(make_default_); | |
| 256 layout->AddView(accept_button); | |
| 257 } else { | |
| 258 // On this other flavor there is no checkbox, the OK button and possibly | |
| 259 // the cancel button are in the same row. | |
| 260 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); | |
| 261 layout->AddView(accept_button); | |
| 262 if (dont_bug_me_button) { | |
| 263 // The dialog needs a "Don't bug me" as a button or as a radio button, | |
| 264 // this the button case. | |
| 265 views::LabelButton* cancel_button = | |
| 266 views::MdTextButton::CreateSecondaryUiButton( | |
| 267 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); | |
| 268 cancel_button->set_tag(BT_CLOSE_BUTTON); | |
| 269 layout->AddView(cancel_button); | |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 | 274 |
| 273 if (experiment.flags & installer::kToastUiWhyLink) { | |
| 274 layout->StartRowWithPadding(0, 4, 0, 10); | |
| 275 views::Link* link = | |
| 276 new views::Link(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); | |
| 277 link->set_listener(this); | |
| 278 layout->AddView(link); | |
| 279 } | |
| 280 | |
| 281 // We resize the window according to the layout manager. This takes into | |
| 282 // account the differences between XP and Vista fonts and buttons. | |
| 283 layout->Layout(root_view); | |
| 284 gfx::Size preferred = layout->GetPreferredSize(root_view); | |
| 285 if (separator) { | |
| 286 int separator_height = separator->GetPreferredSize().height(); | |
| 287 separator->SetSize(gfx::Size(preferred.width(), separator_height)); | |
| 288 } | |
| 289 | |
| 290 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); | |
| 291 popup_->SetBounds(pos); | |
| 292 | |
| 293 // Carve the toast shape into the window. | |
| 294 HWND toast_window; | |
| 295 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); | |
| 296 | |
| 297 gfx::Size size_in_pixels = display::win::ScreenWin::DIPToScreenSize( | |
| 298 toast_window, preferred); | |
| 299 SetToastRegion(toast_window, size_in_pixels.width(), | |
| 300 size_in_pixels.height()); | |
| 301 | |
| 302 // Time to show the window in a modal loop. | |
| 303 popup_->Show(); | 275 popup_->Show(); |
| 304 | |
| 305 if (!listener.is_null()) | 276 if (!listener.is_null()) |
| 306 listener.Run(popup_->GetNativeView()); | 277 listener.Run(popup_->GetNativeView()); |
| 307 | 278 |
| 308 // If the dialog is not modal, we don't control when it is going to be | 279 if (dialog_type == DialogType::MODAL) { |
| 309 // dismissed and hence we cannot inform the listener about the dialog going | 280 run_loop_.reset(new base::RunLoop); |
| 310 // away. | 281 run_loop_->Run(); |
| 311 if (dialog_type == kDialogType::MODAL) { | |
| 312 base::RunLoop().Run(); | |
| 313 if (!listener.is_null()) | 282 if (!listener.is_null()) |
| 314 listener.Run(nullptr); | 283 listener.Run(nullptr); |
| 315 } | 284 } |
| 316 return result_; | 285 return result_; |
| 317 } | 286 } |
| 318 | 287 |
| 319 gfx::Rect TryChromeDialogView::ComputeWindowPosition(const gfx::Size& size, | 288 gfx::Rect TryChromeDialog::ComputePopupBounds(const gfx::Size& size, |
| 320 bool is_RTL) { | 289 bool is_RTL) { |
| 321 gfx::Point origin; | 290 gfx::Point origin; |
| 322 | 291 |
| 323 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); | 292 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); |
| 324 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); | 293 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); |
| 325 origin.set_y(work_area.bottom()- size.height()); | 294 origin.set_y(work_area.bottom() - size.height() - kHoverAboveTaskbarHeight); |
| 326 | 295 |
| 327 return gfx::Rect(origin, size); | 296 return gfx::Rect(origin, size); |
| 328 } | 297 } |
| 329 | 298 |
| 330 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { | 299 void TryChromeDialog::ButtonPressed(views::Button* sender, |
| 331 static const POINT polygon[] = { | 300 const ui::Event& event) { |
| 332 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. | 301 if (sender->tag() == static_cast<int>(ButtonTag::CLOSE_BUTTON) || |
| 333 {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side. | 302 sender->tag() == static_cast<int>(ButtonTag::NO_THANKS_BUTTON)) { |
| 334 {w, h}, {0, h}}; | 303 result_ = NOT_NOW; |
| 335 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); | 304 } else if (sender->tag() == static_cast<int>(ButtonTag::OK_BUTTON)) { |
| 336 ::SetWindowRgn(window, region, FALSE); | 305 result_ = kExperiments[group_].result; |
| 337 } | 306 } else { |
| 338 | 307 NOTREACHED() << "Unknown button selected."; |
| 339 void TryChromeDialogView::ButtonPressed(views::Button* sender, | 308 } |
| 340 const ui::Event& event) { | 309 |
| 341 if (sender->tag() == BT_DONT_BUG_RADIO) { | 310 // Update post-action stats. |
| 342 if (make_default_) { | 311 if (usage_type_ == UsageType::FOR_CHROME) { |
| 343 make_default_->SetChecked(false); | 312 auto lock = storage_.AcquireLock(); |
| 344 make_default_->SetVisible(false); | 313 installer::Experiment experiment; |
| 314 if (lock->LoadExperiment(&experiment)) { | |
| 315 base::TimeDelta action_delay = (base::TimeTicks::Now() - time_shown_); | |
| 316 experiment.SetActionDelay(action_delay); | |
| 317 if (sender->tag() == static_cast<int>(ButtonTag::CLOSE_BUTTON)) { | |
| 318 experiment.SetState(installer::ExperimentMetrics::kSelectedClose); | |
| 319 } else if (sender->tag() == | |
| 320 static_cast<int>(ButtonTag::NO_THANKS_BUTTON)) { | |
| 321 experiment.SetState(installer::ExperimentMetrics::kSelectedNoThanks); | |
| 322 } else { | |
| 323 // TODO(skare): Differentiate crash/no-crash/logoff cases. | |
| 324 experiment.SetState( | |
| 325 installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash); | |
| 326 } | |
| 327 lock->StoreExperiment(experiment); | |
| 345 } | 328 } |
| 346 return; | |
| 347 } else if (sender->tag() == BT_TRY_IT_RADIO) { | |
| 348 if (make_default_) { | |
| 349 make_default_->SetVisible(true); | |
| 350 make_default_->SetChecked(true); | |
| 351 } | |
| 352 return; | |
| 353 } else if (sender->tag() == BT_CLOSE_BUTTON) { | |
| 354 // The user pressed cancel or the [x] button. | |
| 355 result_ = NOT_NOW; | |
| 356 } else if (!try_chrome_) { | |
| 357 // We don't have radio buttons, the user pressed ok. | |
| 358 result_ = TRY_CHROME; | |
| 359 } else { | |
| 360 // The outcome is according to the selected radio button. | |
| 361 if (try_chrome_->checked()) | |
| 362 result_ = TRY_CHROME; | |
| 363 else if (dont_try_chrome_ && dont_try_chrome_->checked()) | |
| 364 result_ = NOT_NOW; | |
| 365 else if (kill_chrome_ && kill_chrome_->checked()) | |
| 366 result_ = UNINSTALL_CHROME; | |
| 367 else | |
| 368 NOTREACHED() << "Unknown radio button selected"; | |
| 369 } | |
| 370 | |
| 371 if (make_default_) { | |
| 372 if ((result_ == TRY_CHROME) && make_default_->checked()) | |
| 373 result_ = TRY_CHROME_AS_DEFAULT; | |
| 374 } | 329 } |
| 375 | 330 |
| 376 popup_->Close(); | 331 popup_->Close(); |
| 377 base::RunLoop::QuitCurrentWhenIdleDeprecated(); | 332 popup_ = nullptr; |
| 378 } | 333 run_loop_->QuitWhenIdle(); |
|
grt (UTC plus 2)
2017/08/21 12:04:45
should there be "if (run_loop_)" ahead of this sin
| |
| 379 | 334 } |
| 380 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { | |
| 381 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); | |
| 382 } | |
| OLD | NEW |