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

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

Issue 2904823002: Inactive toast ux changes (Closed)
Patch Set: rebase, comments Created 3 years, 4 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
OLDNEW
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" 10 #include "base/run_loop.h"
grt (UTC plus 2) 2017/08/17 11:26:32 omit; already included in .h
skare_ 2017/08/18 11:37:33 Done.
12 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
13 #include "chrome/browser/process_singleton.h" 12 #include "chrome/app/vector_icons/vector_icons.h"
14 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" 13 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
15 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "chrome/grit/theme_resources.h" 16 #include "chrome/grit/theme_resources.h"
17 #include "chrome/install_static/install_util.h" 17 #include "chrome/installer/util/experiment.h"
18 #include "chrome/installer/util/user_experiment.h" 18 #include "chrome/installer/util/experiment_metrics.h"
19 #include "components/strings/grit/components_strings.h" 19 #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" 20 #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" 21 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/resources/grit/ui_resources.h" 23 #include "ui/resources/grit/ui_resources.h"
28 #include "ui/views/background.h" 24 #include "ui/views/background.h"
29 #include "ui/views/controls/button/checkbox.h" 25 #include "ui/views/border.h"
26 #include "ui/views/controls/button/button.h"
grt (UTC plus 2) 2017/08/17 11:26:32 omit; already included in .h
skare_ 2017/08/18 11:37:33 Done.
30 #include "ui/views/controls/button/image_button.h" 27 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/button/md_text_button.h" 28 #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" 29 #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" 30 #include "ui/views/layout/grid_layout.h"
37 #include "ui/views/layout/layout_provider.h"
38 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
39 32
40 namespace { 33 namespace {
41 34
42 const wchar_t kHelpCenterUrl[] = 35 constexpr unsigned int kToastWidth = 360;
43 L"https://support.google.com/chrome/answer/150752"; 36 constexpr int kHoverAboveTaskbarHeight = 24;
44 37
45 enum ButtonTags { 38 const SkColor kBackgroundColor = SkColorSetRGB(0x1F, 0x1F, 0x1F);
46 BT_NONE, 39 const SkColor kHeaderColor = SkColorSetRGB(0xFF, 0xFF, 0xFF);
47 BT_CLOSE_BUTTON, 40 const SkColor kBodyColor = SkColorSetARGB(0xAD, 0xFF, 0xFF, 0xFF);
48 BT_OK_BUTTON, 41 const SkColor kBorderColor = SkColorSetARGB(0x80, 0x80, 0x80, 0x80);
49 BT_TRY_IT_RADIO, 42 const SkColor kButtonTextColor = SkColorSetRGB(0xFF, 0xFF, 0xFF);
50 BT_DONT_BUG_RADIO 43 const SkColor kButtonAcceptColor = SkColorSetRGB(0x00, 0x78, 0xDA);
44 const SkColor kButtonNoThanksColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF);
45
46 enum class ButtonTags { CLOSE_BUTTON, OK_BUTTON, NO_THANKS_BUTTON };
grt (UTC plus 2) 2017/08/17 11:26:32 nit: singular ButtonTag
skare_ 2017/08/18 11:37:33 Done.
47
48 // Experiment specification information needed for layout.
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,
grt (UTC plus 2) 2017/08/17 11:26:32 variant #14 should not have the x-to-close button.
skare_ 2017/08/18 11:37:34 ack - currently all the variants do. The hover beh
grt (UTC plus 2) 2017/08/18 12:05:24 Please drop a "TODO(skare): Suppress x-to-close."
skare_ 2017/08/18 20:25:19 Done. Great for the tablet case.
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 button->SetBackground(views::CreateSolidBackground(
106 button_type == TryChromeButtonType::OPEN_CHROME ? kButtonAcceptColor
107 : kButtonNoThanksColor));
108 button->SetEnabledTextColors(kButtonTextColor);
109 button->SetMinSize(gfx::Size(160, 32));
110 button->SetMaxSize(gfx::Size(0, 32));
grt (UTC plus 2) 2017/08/17 11:26:32 maybe dumb q: why is the max width smaller than th
skare_ 2017/08/18 11:37:34 The height was to force 32; setting the width to 0
grt (UTC plus 2) 2017/08/18 12:05:24 Ah, thanks. Is this worthy of an explanatory comme
skare_ 2017/08/18 20:25:19 sure, added (though I'm less familiar with views a
111 return button;
112 }
54 113
55 } // namespace 114 } // namespace
56 115
57 // static 116 // static
58 TryChromeDialogView::Result TryChromeDialogView::Show( 117 TryChromeDialog::Result TryChromeDialog::Show(
59 size_t flavor, 118 size_t group,
60 const ActiveModalDialogListener& listener) { 119 const ActiveModalDialogListener& listener) {
61 if (flavor > 10000) { 120 if (group >= arraysize(kExperiments)) {
62 // This is a test value. We want to make sure we exercise 121 // This is a test value. We want to make sure we exercise
63 // returning this early. See TryChromeDialogBrowserTest test. 122 // returning this early. See TryChromeDialogBrowserTest test.
64 return NOT_NOW; 123 return NOT_NOW;
65 } 124 }
66 TryChromeDialogView dialog(flavor); 125
67 TryChromeDialogView::Result result = dialog.ShowDialog( 126 TryChromeDialog dialog(group);
68 listener, kDialogType::MODAL, kUsageType::FOR_CHROME); 127 return dialog.ShowDialog(listener, DialogType::MODAL, UsageType::FOR_CHROME);
69 return result; 128 }
70 } 129
71 130 TryChromeDialog::TryChromeDialog(size_t group)
72 TryChromeDialogView::TryChromeDialogView(size_t flavor) 131 : usage_type_(UsageType::FOR_CHROME),
73 : flavor_(flavor), 132 group_(group),
74 popup_(NULL), 133 popup_(nullptr),
75 try_chrome_(NULL), 134 result_(NOT_NOW) {}
76 kill_chrome_(NULL), 135
77 dont_try_chrome_(NULL), 136 TryChromeDialog::~TryChromeDialog() {}
78 make_default_(NULL), 137
79 result_(COUNT) {} 138 TryChromeDialog::Result TryChromeDialog::ShowDialog(
80
81 TryChromeDialogView::~TryChromeDialogView() {}
82
83 TryChromeDialogView::Result TryChromeDialogView::ShowDialog(
84 const ActiveModalDialogListener& listener, 139 const ActiveModalDialogListener& listener,
85 kDialogType dialog_type, 140 DialogType dialog_type,
86 kUsageType usage_type) { 141 UsageType usage_type) {
87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 142 usage_type_ = usage_type;
88 143
89 views::ImageView* icon = new views::ImageView(); 144 auto icon = base::MakeUnique<views::ImageView>();
90 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); 145 icon->SetImage(gfx::CreateVectorIcon(kInactiveToastLogoIcon, kHeaderColor));
91 gfx::Size icon_size = icon->GetPreferredSize(); 146 gfx::Size icon_size = icon->GetPreferredSize();
92 147
93 // An approximate window size. After Layout() we'll get better bounds.
94 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 148 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
95 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; 149 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES;
96 params.bounds = gfx::Rect(310, 200); 150 // An approximate window size. Layout() can adjust.
151 params.bounds = gfx::Rect(kToastWidth, 120);
97 popup_ = new views::Widget; 152 popup_ = new views::Widget;
98 popup_->Init(params); 153 popup_->Init(params);
99 154
100 views::View* root_view = popup_->GetRootView(); 155 views::View* root_view = popup_->GetRootView();
101 // The window color is a tiny bit off-white. 156 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); 157 views::GridLayout* layout = views::GridLayout::CreatePanel(root_view);
158 layout->set_minimum_size(gfx::Size(kToastWidth, 0));
106 views::ColumnSet* columns; 159 views::ColumnSet* columns;
107 160
108 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); 161 // Note the right padding is smaller than other dimensions,
109 const int label_spacing = 162 // to acommodate the close 'x' button.
110 provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL); 163 static constexpr gfx::Insets kInsets(10, 10, 12, 3);
111 const int unrelated_space_horiz = 164 root_view->SetBorder(views::CreatePaddedBorder(
112 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL); 165 views::CreateSolidBorder(1, kBorderColor), kInsets));
113 const int unrelated_space_vert = 166
114 provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL); 167 static constexpr int kLabelSpacing = 10;
115 const int button_spacing_horiz = 168 static constexpr int kSpaceBetweenButtons = 4;
116 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL); 169 static constexpr int kSpacingAfterHeadingHorizontal = 9;
117 170
118 // First row: [icon][pad][text][pad][button]. 171 // First row: [icon][pad][text][pad][close button].
172 // Left padding is accomplished via border.
119 columns = layout->AddColumnSet(0); 173 columns = layout->AddColumnSet(0);
120 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, 174 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
121 views::GridLayout::FIXED, icon_size.width(), 175 views::GridLayout::FIXED, icon_size.width(),
122 icon_size.height()); 176 icon_size.height());
123 columns->AddPaddingColumn(0, label_spacing); 177 columns->AddPaddingColumn(0, kLabelSpacing);
124 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 178 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1,
125 views::GridLayout::USE_PREF, 0, 0); 179 views::GridLayout::USE_PREF, 0, 0);
126 columns->AddPaddingColumn(0, unrelated_space_horiz); 180 columns->AddPaddingColumn(0, kSpacingAfterHeadingHorizontal);
127 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 181 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::TRAILING,
128 views::GridLayout::USE_PREF, 0, 0); 182 0, views::GridLayout::USE_PREF, 0, 0);
129 183 int icon_padding = icon_size.width() + kLabelSpacing;
130 int icon_padding = icon_size.width() + label_spacing; 184
131 // Optional second row: [pad][radio 1]. 185 // Optional second row: [pad][text].
132 columns = layout->AddColumnSet(1); 186 columns = layout->AddColumnSet(1);
133 columns->AddPaddingColumn(0, icon_padding); 187 columns->AddPaddingColumn(0, icon_padding);
134 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 188 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
135 views::GridLayout::USE_PREF, 0, 0); 189 views::GridLayout::USE_PREF, 0, 0);
136 190
137 // Third row: [pad][radio 2]. 191 // Third row: [pad][optional button][pad][button].
138 columns = layout->AddColumnSet(2); 192 columns = layout->AddColumnSet(2);
139 columns->AddPaddingColumn(0, icon_padding); 193 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, 194 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
174 views::GridLayout::USE_PREF, 0, 0); 195 views::GridLayout::USE_PREF, 0, 0);
175 196 columns->AddPaddingColumn(0, kSpaceBetweenButtons);
197 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0,
198 views::GridLayout::USE_PREF, 0, 0);
199 columns->AddPaddingColumn(0, 12 - kInsets.right());
200
201 // Padding between the top of the toast and first row is handled via border.
176 // First row. 202 // First row.
177 layout->StartRow(0, 0); 203 layout->StartRow(0, 0);
178 layout->AddView(icon); 204 layout->AddView(icon.release());
179 205 // All variants have a main header.
180 // Find out what experiment we are conducting. 206 auto header = base::MakeUnique<views::Label>(
181 installer::ExperimentDetails experiment; 207 l10n_util::GetStringUTF16(kExperiments[group_].heading_id),
182 if ((usage_type != kUsageType::FOR_TESTING && 208 CONTEXT_WINDOWS10_NATIVE);
183 !install_static::SupportsRetentionExperiments()) || 209 header->SetBackgroundColor(kBackgroundColor);
184 !installer::CreateExperimentDetails(flavor_, &experiment) || 210 header->SetEnabledColor(kHeaderColor);
185 !experiment.heading) { 211 header->SetMultiLine(true);
186 NOTREACHED() << "Cannot determine which headline to show."; 212 header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
187 return DIALOG_ERROR; 213 layout->AddView(header.release());
188 } 214
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. 215 // The close button is custom.
197 views::ImageButton* close_button = new views::ImageButton(this); 216 auto close_button = base::MakeUnique<views::ImageButton>(this);
198 close_button->SetImage(views::CustomButton::STATE_NORMAL, 217 close_button->SetImage(
199 rb.GetNativeImageNamed(IDR_CLOSE_2).ToImageSkia()); 218 views::CustomButton::STATE_NORMAL,
200 close_button->SetImage(views::CustomButton::STATE_HOVERED, 219 gfx::CreateVectorIcon(kInactiveToastCloseIcon, kBodyColor));
201 rb.GetNativeImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 220 close_button->set_tag(static_cast<int>(ButtonTags::CLOSE_BUTTON));
202 close_button->SetImage(views::CustomButton::STATE_PRESSED, 221 layout->AddView(close_button.release());
203 rb.GetNativeImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 222
204 close_button->set_tag(BT_CLOSE_BUTTON); 223 // Second row: May have text or may be blank.
205 layout->AddView(close_button); 224 layout->StartRow(0, 1);
206 225 const int body_string_id = kExperiments[group_].body_id;
207 // Second row. 226 if (body_string_id) {
208 layout->StartRowWithPadding(0, 1, 0, 10); 227 auto body_text = base::MakeUnique<views::Label>(
209 try_chrome_ = new views::RadioButton( 228 l10n_util::GetStringUTF16(body_string_id), CONTEXT_WINDOWS10_NATIVE);
210 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); 229 body_text->SetBackgroundColor(kBackgroundColor);
grt (UTC plus 2) 2017/08/17 11:26:32 please delete IDS_TRY_TOAST_TRY_OPT, IDS_TRY_TOAST
skare_ 2017/08/18 11:37:34 removed these will take a look at removing the ot
211 try_chrome_->SetChecked(true); 230 body_text->SetEnabledColor(kBodyColor);
212 try_chrome_->set_tag(BT_TRY_IT_RADIO); 231 layout->AddView(body_text.release());
213 try_chrome_->set_listener(this); 232 }
214 layout->AddView(try_chrome_); 233
215 234 // Third row: one or two buttons depending on group.
216 // Decide if the don't bug me is a button or a radio button. 235 layout->StartRowWithPadding(0, 2, 0, 12);
217 bool dont_bug_me_button = 236 if (!kExperiments[group_].has_no_thanks_button)
218 !!(experiment.flags & installer::kToastUiDontBugMeAsButton); 237 layout->SkipColumns(1);
219 238 auto accept_button = CreateWin10StyleButton(
220 // Optional third and fourth row. 239 this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_OPEN_CHROME),
221 if (!dont_bug_me_button) { 240 TryChromeButtonType::OPEN_CHROME);
222 layout->StartRow(0, 1); 241 accept_button->set_tag(static_cast<int>(ButtonTags::OK_BUTTON));
223 dont_try_chrome_ = new views::RadioButton( 242 layout->AddView(accept_button.release());
224 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); 243
225 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); 244 if (kExperiments[group_].has_no_thanks_button) {
226 dont_try_chrome_->set_listener(this); 245 auto no_thanks_button = CreateWin10StyleButton(
227 layout->AddView(dont_try_chrome_); 246 this, l10n_util::GetStringUTF16(IDS_WIN10_TOAST_NO_THANKS),
228 } 247 TryChromeButtonType::NO_THANKS);
229 if (experiment.flags & installer::kToastUiUninstall) { 248 no_thanks_button->set_tag(static_cast<int>(ButtonTags::NO_THANKS_BUTTON));
230 layout->StartRow(0, 2); 249 layout->AddView(no_thanks_button.release());
231 kill_chrome_ = new views::RadioButton( 250 }
232 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); 251
233 layout->AddView(kill_chrome_); 252 // Padding between buttons and the edge of the view is via the border.
234 } 253 gfx::Size preferred = layout->GetPreferredSize(root_view);
235 254 gfx::Rect pos = ComputePopupBounds(preferred, base::i18n::IsRTL());
236 views::LabelButton* accept_button = 255 popup_->SetBounds(pos);
237 views::MdTextButton::CreateSecondaryUiButton( 256 layout->Layout(root_view);
238 this, l10n_util::GetStringUTF16(IDS_OK)); 257
239 accept_button->set_tag(BT_OK_BUTTON); 258 // Update pre-show stats.
240 259 time_shown_ = base::TimeTicks::Now();
241 views::Separator* separator = NULL; 260
242 if (experiment.flags & installer::kToastUiMakeDefault) { 261 if (usage_type_ == UsageType::FOR_CHROME) {
243 // In this flavor we have some vertical space, then a separator line 262 auto lock = storage_.AcquireLock();
244 // and the 'make default' checkbox and the OK button on the same row. 263 installer::Experiment experiment;
245 layout->AddPaddingRow(0, unrelated_space_vert); 264 if (lock->LoadExperiment(&experiment)) {
246 layout->StartRow(0, 6); 265 experiment.SetDisplayTime(base::Time::Now());
247 separator = new views::Separator(); 266 experiment.SetToastCount(experiment.toast_count() + 1);
248 layout->AddView(separator); 267 // TODO(skare): SetToastLocation via checking pinned state.
249 layout->AddPaddingRow(0, unrelated_space_vert); 268 // TODO(skare): SetUserSessionUptime
250 269 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 } 270 }
271 } 271 }
272 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);
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(); 273 popup_->Show();
304
305 if (!listener.is_null()) 274 if (!listener.is_null())
306 listener.Run(popup_->GetNativeView()); 275 listener.Run(popup_->GetNativeView());
307 276
308 // If the dialog is not modal, we don't control when it is going to be 277 if (dialog_type == DialogType::MODAL) {
309 // dismissed and hence we cannot inform the listener about the dialog going 278 run_loop_.Run();
310 // away.
311 if (dialog_type == kDialogType::MODAL) {
312 base::RunLoop().Run();
313 if (!listener.is_null()) 279 if (!listener.is_null())
314 listener.Run(nullptr); 280 listener.Run(nullptr);
315 } 281 }
316 return result_; 282 return result_;
317 } 283 }
318 284
319 gfx::Rect TryChromeDialogView::ComputeWindowPosition(const gfx::Size& size, 285 gfx::Rect TryChromeDialog::ComputePopupBounds(const gfx::Size& size,
320 bool is_RTL) { 286 bool is_RTL) {
321 gfx::Point origin; 287 gfx::Point origin;
322 288
323 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen(); 289 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen();
324 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width()); 290 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width());
325 origin.set_y(work_area.bottom()- size.height()); 291 origin.set_y(work_area.bottom() - size.height() - kHoverAboveTaskbarHeight);
326 292
327 return gfx::Rect(origin, size); 293 return gfx::Rect(origin, size);
328 } 294 }
329 295
330 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { 296 void TryChromeDialog::ButtonPressed(views::Button* sender,
331 static const POINT polygon[] = { 297 const ui::Event& event) {
332 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. 298 if (sender->tag() == static_cast<int>(ButtonTags::CLOSE_BUTTON) ||
333 {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side. 299 sender->tag() == static_cast<int>(ButtonTags::NO_THANKS_BUTTON)) {
334 {w, h}, {0, h}}; 300 result_ = NOT_NOW;
335 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); 301 } else if (sender->tag() == static_cast<int>(ButtonTags::OK_BUTTON)) {
336 ::SetWindowRgn(window, region, FALSE); 302 result_ = kExperiments[group_].result;
337 } 303 } else {
338 304 NOTREACHED() << "Unknown button selected.";
339 void TryChromeDialogView::ButtonPressed(views::Button* sender, 305 }
340 const ui::Event& event) { 306
341 if (sender->tag() == BT_DONT_BUG_RADIO) { 307 // Update post-action stats.
342 if (make_default_) { 308 if (usage_type_ == UsageType::FOR_CHROME) {
343 make_default_->SetChecked(false); 309 auto lock = storage_.AcquireLock();
344 make_default_->SetVisible(false); 310 installer::Experiment experiment;
311 if (lock->LoadExperiment(&experiment)) {
312 base::TimeDelta action_delay = (base::TimeTicks::Now() - time_shown_);
313 experiment.SetActionDelay(action_delay);
314 if (sender->tag() == static_cast<int>(ButtonTags::CLOSE_BUTTON)) {
315 experiment.SetState(installer::ExperimentMetrics::kSelectedClose);
316 } else if (sender->tag() ==
317 static_cast<int>(ButtonTags::NO_THANKS_BUTTON)) {
318 experiment.SetState(installer::ExperimentMetrics::kSelectedNoThanks);
319 } else {
320 // TODO(skare): Differentiate crash/no-crash/logoff cases.
321 experiment.SetState(
322 installer::ExperimentMetrics::kSelectedOpenChromeAndNoCrash);
323 }
324 lock->StoreExperiment(experiment);
345 } 325 }
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 } 326 }
375 327
376 popup_->Close(); 328 popup_->Close();
grt (UTC plus 2) 2017/08/17 11:26:32 the Widget is destroyed sometime after this call (
skare_ 2017/08/18 11:37:34 Done.
377 base::RunLoop::QuitCurrentWhenIdleDeprecated(); 329 run_loop_.QuitWhenIdle();
grt (UTC plus 2) 2017/08/17 11:26:32 i suppose this is harmless if it it's a MODELESS_F
skare_ 2017/08/18 11:37:34 I believe so from experimentation and its presence
378 } 330 }
379
380 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
381 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698