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