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