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

Side by Side Diff: chrome/browser/first_run/try_chrome_dialog_view.cc

Issue 10821007: The new toast experiments. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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/first_run/try_chrome_dialog_view.h" 5 #include "chrome/browser/first_run/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/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "chrome/browser/process_singleton.h" 12 #include "chrome/browser/process_singleton.h"
13 #include "chrome/installer/util/browser_distribution.h" 13 #include "chrome/installer/util/browser_distribution.h"
14 #include "grit/chromium_strings.h" 14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "grit/ui_resources.h" 17 #include "grit/ui_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
21 #include "ui/views/controls/button/checkbox.h"
21 #include "ui/views/controls/button/image_button.h" 22 #include "ui/views/controls/button/image_button.h"
22 #include "ui/views/controls/button/radio_button.h" 23 #include "ui/views/controls/button/radio_button.h"
23 #include "ui/views/controls/button/text_button.h" 24 #include "ui/views/controls/button/text_button.h"
24 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
25 #include "ui/views/controls/link.h" 26 #include "ui/views/controls/link.h"
26 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/layout/layout_constants.h" 28 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
29 30
30 namespace { 31 namespace {
31 32
32 const wchar_t kHelpCenterUrl[] = 33 const wchar_t kHelpCenterUrl[] =
33 L"https://www.google.com/support/chrome/bin/answer.py?answer=150752"; 34 L"https://www.google.com/support/chrome/bin/answer.py?answer=150752";
34 35
36 enum ButtonTags {
37 BT_NONE,
38 BT_CLOSE_BUTTON,
39 BT_OK_BUTTON,
40 BT_TRY_IT_RADIO,
41 BT_DONT_BUG_RADIO
42 };
43
35 } // namespace 44 } // namespace
36 45
37 // static 46 // static
38 TryChromeDialogView::Result TryChromeDialogView::Show( 47 TryChromeDialogView::Result TryChromeDialogView::Show(
39 size_t flavor, 48 size_t flavor,
40 ProcessSingleton* process_singleton) { 49 ProcessSingleton* process_singleton) {
41 if (flavor > 10000) { 50 if (flavor > 10000) {
42 // This is a test value. We want to make sure we exercise 51 // This is a test value. We want to make sure we exercise
43 // returning this early. See TryChromeDialogBrowserTest test. 52 // returning this early. See TryChromeDialogBrowserTest test.
44 return NOT_NOW; 53 return NOT_NOW;
45 } 54 }
46 TryChromeDialogView dialog(flavor); 55 TryChromeDialogView dialog(flavor);
47 return dialog.ShowModal(process_singleton); 56 return dialog.ShowModal(process_singleton);
48 } 57 }
49 58
50 TryChromeDialogView::TryChromeDialogView(size_t flavor) 59 TryChromeDialogView::TryChromeDialogView(size_t flavor)
51 : flavor_(flavor), 60 : flavor_(flavor),
52 popup_(NULL), 61 popup_(NULL),
53 try_chrome_(NULL), 62 try_chrome_(NULL),
54 kill_chrome_(NULL), 63 kill_chrome_(NULL),
55 dont_try_chrome_(NULL), 64 dont_try_chrome_(NULL),
56 result_(COUNT) { 65 make_default_(NULL),
66 result_(COUNT) {
57 } 67 }
58 68
59 TryChromeDialogView::~TryChromeDialogView() { 69 TryChromeDialogView::~TryChromeDialogView() {
60 } 70 }
61 71
62 TryChromeDialogView::Result TryChromeDialogView::ShowModal( 72 TryChromeDialogView::Result TryChromeDialogView::ShowModal(
63 ProcessSingleton* process_singleton) { 73 ProcessSingleton* process_singleton) {
64 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 74 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
65 75
66 views::ImageView* icon = new views::ImageView(); 76 views::ImageView* icon = new views::ImageView();
(...skipping 28 matching lines...) Expand all
95 // First row: [icon][pad][text][button]. 105 // First row: [icon][pad][text][button].
96 columns = layout->AddColumnSet(0); 106 columns = layout->AddColumnSet(0);
97 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, 107 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
98 views::GridLayout::FIXED, icon_size.width(), 108 views::GridLayout::FIXED, icon_size.width(),
99 icon_size.height()); 109 icon_size.height());
100 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 110 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
101 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 111 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
102 views::GridLayout::USE_PREF, 0, 0); 112 views::GridLayout::USE_PREF, 0, 0);
103 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 113 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
104 views::GridLayout::USE_PREF, 0, 0); 114 views::GridLayout::USE_PREF, 0, 0);
105 // Second row: [pad][pad][radio 1]. 115 // Optional second row: [pad][pad][radio 1].
Finnur 2012/07/26 12:27:07 Can you add a line break above this and on lines 1
cpu_(ooo_6.6-7.5) 2012/07/27 03:06:23 Done.
106 columns = layout->AddColumnSet(1); 116 columns = layout->AddColumnSet(1);
107 columns->AddPaddingColumn(0, icon_size.width()); 117 columns->AddPaddingColumn(0, icon_size.width());
108 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 118 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
109 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 119 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
110 views::GridLayout::USE_PREF, 0, 0); 120 views::GridLayout::USE_PREF, 0, 0);
111 // Third row: [pad][pad][radio 2]. 121 // Third row: [pad][pad][radio 2].
112 columns = layout->AddColumnSet(2); 122 columns = layout->AddColumnSet(2);
113 columns->AddPaddingColumn(0, icon_size.width()); 123 columns->AddPaddingColumn(0, icon_size.width());
114 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 124 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
115 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 125 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
116 views::GridLayout::USE_PREF, 0, 0); 126 views::GridLayout::USE_PREF, 0, 0);
117 // Fourth row: [pad][pad][button][pad][button]. 127 // Fourth row: [pad][pad][button][pad][button].
118 columns = layout->AddColumnSet(3); 128 columns = layout->AddColumnSet(3);
119 columns->AddPaddingColumn(0, icon_size.width()); 129 columns->AddPaddingColumn(0, icon_size.width());
120 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
121 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, 130 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
122 views::GridLayout::USE_PREF, 0, 0); 131 views::GridLayout::USE_PREF, 0, 0);
123 columns->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 132 columns->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
124 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, 133 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
125 views::GridLayout::USE_PREF, 0, 0); 134 views::GridLayout::USE_PREF, 0, 0);
126 // Fifth row: [pad][pad][link]. 135 // Fifth row: [pad][pad][link].
127 columns = layout->AddColumnSet(4); 136 columns = layout->AddColumnSet(4);
128 columns->AddPaddingColumn(0, icon_size.width()); 137 columns->AddPaddingColumn(0, icon_size.width());
129 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 138 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
130 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 139 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
131 views::GridLayout::USE_PREF, 0, 0); 140 views::GridLayout::USE_PREF, 0, 0);
132 // Optional fourth row: [button]. 141 // Optional fourth row: [button].
133 columns = layout->AddColumnSet(5); 142 columns = layout->AddColumnSet(5);
134 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, 143 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
135 views::GridLayout::USE_PREF, 0, 0); 144 views::GridLayout::USE_PREF, 0, 0);
145 // Optional fourth row: [pad][pad][checkbox].
146 columns = layout->AddColumnSet(6);
147 columns->AddPaddingColumn(0, icon_size.width());
148 columns->AddPaddingColumn(0,
149 views::kRelatedControlHorizontalSpacing + views::kPanelHorizIndentation);
150 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
151 views::GridLayout::USE_PREF, 0, 0);
136 // First row views. 152 // First row views.
137 layout->StartRow(0, 0); 153 layout->StartRow(0, 0);
138 layout->AddView(icon); 154 layout->AddView(icon);
139 155
140 // Find out what experiment we are conducting. 156 // Find out what experiment we are conducting.
141 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 157 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
142 if (!dist) { 158 if (!dist) {
143 NOTREACHED() << "Cannot determine browser distribution"; 159 NOTREACHED() << "Cannot determine browser distribution";
144 return DIALOG_ERROR; 160 return DIALOG_ERROR;
145 } 161 }
(...skipping 18 matching lines...) Expand all
164 rb.GetNativeImageNamed(IDR_CLOSE_BAR_H).ToImageSkia()); 180 rb.GetNativeImageNamed(IDR_CLOSE_BAR_H).ToImageSkia());
165 close_button->SetImage(views::CustomButton::BS_PUSHED, 181 close_button->SetImage(views::CustomButton::BS_PUSHED,
166 rb.GetNativeImageNamed(IDR_CLOSE_BAR_P).ToImageSkia()); 182 rb.GetNativeImageNamed(IDR_CLOSE_BAR_P).ToImageSkia());
167 close_button->set_tag(BT_CLOSE_BUTTON); 183 close_button->set_tag(BT_CLOSE_BUTTON);
168 layout->AddView(close_button); 184 layout->AddView(close_button);
169 185
170 // Second row views. 186 // Second row views.
171 const string16 try_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT)); 187 const string16 try_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT));
172 layout->StartRowWithPadding(0, 1, 0, 10); 188 layout->StartRowWithPadding(0, 1, 0, 10);
173 try_chrome_ = new views::RadioButton(try_it, 1); 189 try_chrome_ = new views::RadioButton(try_it, 1);
190 try_chrome_->SetChecked(true);
191 try_chrome_->set_tag(BT_TRY_IT_RADIO);
192 try_chrome_->set_listener(this);
174 layout->AddView(try_chrome_); 193 layout->AddView(try_chrome_);
175 try_chrome_->SetChecked(true);
176 194
177 // Third row views. 195 // Decide if the don't bug me is a button or a radio button.
178 layout->StartRow(0, 2); 196 bool dont_bug_me_button =
179 if (experiment.compact_bubble) { 197 experiment.flags & BrowserDistribution::kDontBugMeAsButton ? true : false;
198
199 // Optional third and fourth row views.
200 if (!dont_bug_me_button) {
201 layout->StartRow(0, 1);
180 // The compact bubble has, as its second radio button, "Don't bug me". 202 // The compact bubble has, as its second radio button, "Don't bug me".
Finnur 2012/07/26 12:27:07 This comment refers to the compact bubble. Do we w
cpu_(ooo_6.6-7.5) 2012/07/27 03:06:23 Reworded the comments mentioning compact and regul
181 const string16 decline(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); 203 const string16 decline(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
182 dont_try_chrome_ = new views::RadioButton(decline, 1); 204 dont_try_chrome_ = new views::RadioButton(decline, 1);
205 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO);
206 dont_try_chrome_->set_listener(this);
183 layout->AddView(dont_try_chrome_); 207 layout->AddView(dont_try_chrome_);
184 } else { 208 }
209 if (experiment.flags & BrowserDistribution::kUninstall) {
210 layout->StartRow(0, 2);
185 // The regular bubble has, as its second radio button, "Uninstall Chrome". 211 // The regular bubble has, as its second radio button, "Uninstall Chrome".
186 const string16 kill_it(l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME)); 212 const string16 kill_it(l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME));
187 kill_chrome_ = new views::RadioButton(kill_it, 1); 213 kill_chrome_ = new views::RadioButton(kill_it, 1);
188 layout->AddView(kill_chrome_); 214 layout->AddView(kill_chrome_);
189 } 215 }
216 if (experiment.flags & BrowserDistribution::kMakeDefault) {
217 layout->StartRow(0, 6);
218 const string16 default_text(
219 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT));
220 make_default_ = new views::Checkbox(default_text);
221 layout->AddView(make_default_);
222 make_default_->SetChecked(true);
Finnur 2012/07/26 12:27:07 nit: For consistency with line 190 maybe move this
cpu_(ooo_6.6-7.5) 2012/07/27 03:06:23 Done.
223 }
190 224
191 // Fourth row views. 225 // Button row, the last or next to last depending on the 'why?' link.
192 const string16 ok_it(l10n_util::GetStringUTF16(IDS_OK)); 226 const string16 ok_it(l10n_util::GetStringUTF16(IDS_OK));
193 const string16 cancel_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
194 const string16 why_this(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));
195 views::Button* accept_button = new views::NativeTextButton(this, ok_it); 227 views::Button* accept_button = new views::NativeTextButton(this, ok_it);
196 accept_button->set_tag(BT_OK_BUTTON); 228 accept_button->set_tag(BT_OK_BUTTON);
197 229
198 // The compact bubble uses a centered button column for buttons, since only 230 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10);
199 // the OK button appears.
200 int column_id_buttons = experiment.compact_bubble ? 5 : 3;
201 layout->StartRowWithPadding(0, column_id_buttons, 0, 10);
202 layout->AddView(accept_button); 231 layout->AddView(accept_button);
203 if (!experiment.compact_bubble) { 232 if (dont_bug_me_button) {
204 // The regular bubble needs a "Don't bug me" as a button, since it is not 233 // The regular bubble needs a "Don't bug me" as a button, since it is not
205 // one of the options for the radio buttons. We also decided to include the 234 // one of the options for the radio buttons.
206 // "Why am I seeing this?" link for the regular bubble only. 235 const string16 cancel_it(l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
207 views::Button* cancel_button = new views::NativeTextButton(this, cancel_it); 236 views::Button* cancel_button = new views::NativeTextButton(this, cancel_it);
208 cancel_button->set_tag(BT_CLOSE_BUTTON); 237 cancel_button->set_tag(BT_CLOSE_BUTTON);
209 layout->AddView(cancel_button); 238 layout->AddView(cancel_button);
210 239 }
211 // Fifth row views. 240 if (experiment.flags & BrowserDistribution::kWhyLink) {
212 layout->StartRowWithPadding(0, 4, 0, 10); 241 layout->StartRowWithPadding(0, 4, 0, 10);
242 const string16 why_this(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));
213 views::Link* link = new views::Link(why_this); 243 views::Link* link = new views::Link(why_this);
214 link->set_listener(this); 244 link->set_listener(this);
215 layout->AddView(link); 245 layout->AddView(link);
216 } 246 }
217 247
218 // We resize the window according to the layout manager. This takes into 248 // We resize the window according to the layout manager. This takes into
219 // account the differences between XP and Vista fonts and buttons. 249 // account the differences between XP and Vista fonts and buttons.
220 layout->Layout(root_view); 250 layout->Layout(root_view);
221 gfx::Size preferred = layout->GetPreferredSize(root_view); 251 gfx::Size preferred = layout->GetPreferredSize(root_view);
222 gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(), 252 gfx::Rect pos = ComputeWindowPosition(preferred.width(), preferred.height(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. 292 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side.
263 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. 293 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side.
264 {w, h}, {0, h} 294 {w, h}, {0, h}
265 }; 295 };
266 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); 296 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING);
267 ::SetWindowRgn(window, region, FALSE); 297 ::SetWindowRgn(window, region, FALSE);
268 } 298 }
269 299
270 void TryChromeDialogView::ButtonPressed(views::Button* sender, 300 void TryChromeDialogView::ButtonPressed(views::Button* sender,
271 const views::Event& event) { 301 const views::Event& event) {
272 if (sender->tag() == BT_CLOSE_BUTTON) { 302 if (sender->tag() == BT_DONT_BUG_RADIO) {
303 if (make_default_) {
304 make_default_->SetChecked(false);
305 make_default_->SetState(views::CustomButton::BS_DISABLED);
306 }
307 return;
308 } else if (sender->tag() == BT_TRY_IT_RADIO) {
309 if (make_default_) {
310 make_default_->SetChecked(true);
311 make_default_->SetState(views::CustomButton::BS_NORMAL);
312 }
313 return;
314 } else if (sender->tag() == BT_CLOSE_BUTTON) {
273 // The user pressed cancel or the [x] button. 315 // The user pressed cancel or the [x] button.
274 result_ = NOT_NOW; 316 result_ = NOT_NOW;
275 } else if (!try_chrome_) { 317 } else if (!try_chrome_) {
276 // We don't have radio buttons, the user pressed ok. 318 // We don't have radio buttons, the user pressed ok.
277 result_ = TRY_CHROME; 319 result_ = TRY_CHROME;
278 } else { 320 } else {
279 // The outcome is according to the selected ratio button. 321 // The outcome is according to the selected radio button.
280 if (try_chrome_->checked()) 322 if (try_chrome_->checked())
281 result_ = TRY_CHROME; 323 result_ = TRY_CHROME;
282 else if (dont_try_chrome_ && dont_try_chrome_->checked()) 324 else if (dont_try_chrome_ && dont_try_chrome_->checked())
283 result_ = NOT_NOW; 325 result_ = NOT_NOW;
284 else if (kill_chrome_ && kill_chrome_->checked()) 326 else if (kill_chrome_ && kill_chrome_->checked())
285 result_ = UNINSTALL_CHROME; 327 result_ = UNINSTALL_CHROME;
286 else 328 else
287 NOTREACHED() << "Unknown radio button selected"; 329 NOTREACHED() << "Unknown radio button selected";
288 } 330 }
331
332 if (result_ == TRY_CHROME) {
333 if (make_default_->checked())
Finnur 2012/07/26 12:27:07 nit: collapse 332 and 333 into one line and loose
cpu_(ooo_6.6-7.5) 2012/07/27 03:06:23 Done.
334 result_ = TRY_CHROME_AS_DEFAULT;
335 }
336
289 popup_->Close(); 337 popup_->Close();
290 MessageLoop::current()->Quit(); 338 MessageLoop::current()->Quit();
291 } 339 }
292 340
293 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { 341 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
294 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); 342 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
295 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698