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

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

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

Powered by Google App Engine
This is Rietveld 408576698