Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/views/try_chrome_dialog_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698