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

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

Issue 2816293002: Description: Replace layout constants in chrome/browser/extensions and chrome/browser/first_run (Closed)
Patch Set: Enable the TryChromeDialogTest.InvokeDialog_default test. The TryChromeDialogTest is now a friend o… Created 3 years, 7 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/first_run/try_chrome_dialog_view.h" 5 #include "chrome/browser/ui/views/try_chrome_dialog_view.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "chrome/browser/process_singleton.h" 14 #include "chrome/browser/process_singleton.h"
15 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
15 #include "chrome/grit/chromium_strings.h" 16 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "chrome/grit/theme_resources.h" 18 #include "chrome/grit/theme_resources.h"
18 #include "chrome/install_static/install_util.h" 19 #include "chrome/install_static/install_util.h"
19 #include "chrome/installer/util/user_experiment.h" 20 #include "chrome/installer/util/user_experiment.h"
20 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 #include "ui/aura/window_tree_host.h" 23 #include "ui/aura/window_tree_host.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/display/screen.h"
25 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
26 #include "ui/resources/grit/ui_resources.h" 28 #include "ui/resources/grit/ui_resources.h"
27 #include "ui/views/background.h" 29 #include "ui/views/background.h"
28 #include "ui/views/controls/button/checkbox.h" 30 #include "ui/views/controls/button/checkbox.h"
29 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/image_button.h"
30 #include "ui/views/controls/button/md_text_button.h" 32 #include "ui/views/controls/button/md_text_button.h"
31 #include "ui/views/controls/button/radio_button.h" 33 #include "ui/views/controls/button/radio_button.h"
32 #include "ui/views/controls/image_view.h" 34 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/link.h" 35 #include "ui/views/controls/link.h"
34 #include "ui/views/controls/separator.h" 36 #include "ui/views/controls/separator.h"
35 #include "ui/views/layout/grid_layout.h" 37 #include "ui/views/layout/grid_layout.h"
36 #include "ui/views/layout/layout_constants.h"
37 #include "ui/views/layout/layout_provider.h" 38 #include "ui/views/layout/layout_provider.h"
38 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
39 40
40 namespace { 41 namespace {
41 42
42 const wchar_t kHelpCenterUrl[] = 43 const wchar_t kHelpCenterUrl[] =
43 L"https://support.google.com/chrome/answer/150752"; 44 L"https://support.google.com/chrome/answer/150752";
44 45
45 enum ButtonTags { 46 enum ButtonTags {
46 BT_NONE, 47 BT_NONE,
(...skipping 10 matching lines...) Expand all
57 // static 58 // static
58 TryChromeDialogView::Result TryChromeDialogView::Show( 59 TryChromeDialogView::Result TryChromeDialogView::Show(
59 size_t flavor, 60 size_t flavor,
60 const ActiveModalDialogListener& listener) { 61 const ActiveModalDialogListener& listener) {
61 if (flavor > 10000) { 62 if (flavor > 10000) {
62 // This is a test value. We want to make sure we exercise 63 // This is a test value. We want to make sure we exercise
63 // returning this early. See TryChromeDialogBrowserTest test. 64 // returning this early. See TryChromeDialogBrowserTest test.
64 return NOT_NOW; 65 return NOT_NOW;
65 } 66 }
66 TryChromeDialogView dialog(flavor); 67 TryChromeDialogView dialog(flavor);
67 return dialog.ShowModal(listener); 68 TryChromeDialogView::Result result = dialog.ShowDialog(
69 listener, MODAL, FOR_CHROME);
70 return result;
68 } 71 }
69 72
70 TryChromeDialogView::TryChromeDialogView(size_t flavor) 73 TryChromeDialogView::TryChromeDialogView(size_t flavor)
71 : flavor_(flavor), 74 : flavor_(flavor),
72 popup_(NULL), 75 popup_(NULL),
73 try_chrome_(NULL), 76 try_chrome_(NULL),
74 kill_chrome_(NULL), 77 kill_chrome_(NULL),
75 dont_try_chrome_(NULL), 78 dont_try_chrome_(NULL),
76 make_default_(NULL), 79 make_default_(NULL),
77 result_(COUNT) { 80 result_(COUNT) {}
78 }
79 81
80 TryChromeDialogView::~TryChromeDialogView() { 82 TryChromeDialogView::~TryChromeDialogView() {}
81 }
82 83
83 TryChromeDialogView::Result TryChromeDialogView::ShowModal( 84 TryChromeDialogView::Result TryChromeDialogView::ShowDialog(
84 const ActiveModalDialogListener& listener) { 85 const ActiveModalDialogListener& listener,
86 DialogType dialog_type,
87 UsageType usage_type) {
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 88 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86 89
87 views::ImageView* icon = new views::ImageView(); 90 views::ImageView* icon = new views::ImageView();
88 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); 91 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia());
89 gfx::Size icon_size = icon->GetPreferredSize(); 92 gfx::Size icon_size = icon->GetPreferredSize();
90 93
91 // An approximate window size. After Layout() we'll get better bounds. 94 // An approximate window size. After Layout() we'll get better bounds.
92 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 95 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
93 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES; 96 params.activatable = views::Widget::InitParams::ACTIVATABLE_YES;
94 params.bounds = gfx::Rect(310, 200); 97 params.bounds = gfx::Rect(310, 200);
95 popup_ = new views::Widget; 98 popup_ = new views::Widget;
96 popup_->Init(params); 99 popup_->Init(params);
97 100
98 views::View* root_view = popup_->GetRootView(); 101 views::View* root_view = popup_->GetRootView();
99 // The window color is a tiny bit off-white. 102 // The window color is a tiny bit off-white.
100 root_view->set_background( 103 root_view->set_background(
101 views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc)); 104 views::Background::CreateSolidBackground(0xfc, 0xfc, 0xfc));
102 105
103 views::GridLayout* layout = views::GridLayout::CreatePanel(root_view); 106 views::GridLayout* layout = views::GridLayout::CreatePanel(root_view);
104 views::ColumnSet* columns; 107 views::ColumnSet* columns;
105 108
109 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
110 const int label_spacing =
111 provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL);
112 const int unrelated_space_horiz =
113 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL);
114 const int unrelated_space_vert =
115 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL);
116 const int button_spacing_horiz =
117 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
118
106 // First row: [icon][pad][text][pad][button]. 119 // First row: [icon][pad][text][pad][button].
107 columns = layout->AddColumnSet(0); 120 columns = layout->AddColumnSet(0);
108 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, 121 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
109 views::GridLayout::FIXED, icon_size.width(), 122 views::GridLayout::FIXED, icon_size.width(),
110 icon_size.height()); 123 icon_size.height());
111 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 124 columns->AddPaddingColumn(0, label_spacing);
112 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 125 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
113 views::GridLayout::USE_PREF, 0, 0); 126 views::GridLayout::USE_PREF, 0, 0);
114 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 127 columns->AddPaddingColumn(0, unrelated_space_horiz);
115 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 128 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
116 views::GridLayout::USE_PREF, 0, 0); 129 views::GridLayout::USE_PREF, 0, 0);
117 130
118 // Optional second row: [pad][pad][radio 1]. 131 int icon_padding = icon_size.width() + label_spacing;
132 // Optional second row: [pad][radio 1].
119 columns = layout->AddColumnSet(1); 133 columns = layout->AddColumnSet(1);
120 columns->AddPaddingColumn(0, icon_size.width()); 134 columns->AddPaddingColumn(0, icon_padding);
121 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
122 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 135 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
123 views::GridLayout::USE_PREF, 0, 0); 136 views::GridLayout::USE_PREF, 0, 0);
124 137
125 // Third row: [pad][pad][radio 2]. 138 // Third row: [pad][radio 2].
126 columns = layout->AddColumnSet(2); 139 columns = layout->AddColumnSet(2);
127 columns->AddPaddingColumn(0, icon_size.width()); 140 columns->AddPaddingColumn(0, icon_padding);
128 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
129 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 141 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
130 views::GridLayout::USE_PREF, 0, 0); 142 views::GridLayout::USE_PREF, 0, 0);
131 143
132 // Fourth row: [pad][pad][button][pad][button]. 144 // Fourth row: [pad][button][pad][button].
133 columns = layout->AddColumnSet(3); 145 columns = layout->AddColumnSet(3);
134 columns->AddPaddingColumn(0, icon_size.width()); 146 columns->AddPaddingColumn(0, icon_padding);
135 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, 147 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
136 views::GridLayout::USE_PREF, 0, 0); 148 views::GridLayout::USE_PREF, 0, 0);
137 columns->AddPaddingColumn(0, views::LayoutProvider::Get()->GetDistanceMetric( 149 columns->AddPaddingColumn(0, button_spacing_horiz);
138 views::DISTANCE_RELATED_BUTTON_HORIZONTAL));
139 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, 150 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
140 views::GridLayout::USE_PREF, 0, 0); 151 views::GridLayout::USE_PREF, 0, 0);
141 152
142 // Fifth row: [pad][pad][link]. 153 // Fifth row: [pad][link].
143 columns = layout->AddColumnSet(4); 154 columns = layout->AddColumnSet(4);
144 columns->AddPaddingColumn(0, icon_size.width()); 155 columns->AddPaddingColumn(0, icon_padding);
145 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
146 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, 156 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
147 views::GridLayout::USE_PREF, 0, 0); 157 views::GridLayout::USE_PREF, 0, 0);
148 158
149 // Optional fourth row: [button]. 159 // Optional fourth row: [button].
150 columns = layout->AddColumnSet(5); 160 columns = layout->AddColumnSet(5);
151 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, 161 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
152 views::GridLayout::USE_PREF, 0, 0); 162 views::GridLayout::USE_PREF, 0, 0);
153 163
154 // Optional fourth row: [divider] 164 // Optional fourth row: [divider]
155 columns = layout->AddColumnSet(6); 165 columns = layout->AddColumnSet(6);
156 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1, 166 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
157 views::GridLayout::USE_PREF, 0, 0); 167 views::GridLayout::USE_PREF, 0, 0);
158 168
159 // Optional fifth row [checkbox][pad][button] 169 // Optional fifth row [checkbox][pad][button]
160 columns = layout->AddColumnSet(7); 170 columns = layout->AddColumnSet(7);
161 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0, 171 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 0,
162 views::GridLayout::USE_PREF, 0, 0); 172 views::GridLayout::USE_PREF, 0, 0);
163 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 173 columns->AddPaddingColumn(0, unrelated_space_horiz);
164 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 174 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
165 views::GridLayout::USE_PREF, 0, 0); 175 views::GridLayout::USE_PREF, 0, 0);
166 176
167 // First row. 177 // First row.
168 layout->StartRow(0, 0); 178 layout->StartRow(0, 0);
169 layout->AddView(icon); 179 layout->AddView(icon);
170 180
171 // Find out what experiment we are conducting. 181 // Find out what experiment we are conducting.
172 installer::ExperimentDetails experiment; 182 installer::ExperimentDetails experiment;
173 if (!install_static::SupportsRetentionExperiments() || 183 if ((usage_type != FOR_TESTING &&
184 !install_static::SupportsRetentionExperiments()) ||
174 !installer::CreateExperimentDetails(flavor_, &experiment) || 185 !installer::CreateExperimentDetails(flavor_, &experiment) ||
175 !experiment.heading) { 186 !experiment.heading) {
176 NOTREACHED() << "Cannot determine which headline to show."; 187 NOTREACHED() << "Cannot determine which headline to show.";
177 return DIALOG_ERROR; 188 return DIALOG_ERROR;
178 } 189 }
179 views::Label* label = 190 views::Label* label =
180 new views::Label(l10n_util::GetStringUTF16(experiment.heading), 191 new views::Label(l10n_util::GetStringUTF16(experiment.heading),
181 views::style::CONTEXT_DIALOG_TITLE); 192 views::style::CONTEXT_DIALOG_TITLE);
182 label->SetMultiLine(true); 193 label->SetMultiLine(true);
183 label->SizeToFit(200); 194 label->SizeToFit(200);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 layout->AddView(kill_chrome_); 234 layout->AddView(kill_chrome_);
224 } 235 }
225 236
226 views::LabelButton* accept_button = 237 views::LabelButton* accept_button =
227 views::MdTextButton::CreateSecondaryUiButton( 238 views::MdTextButton::CreateSecondaryUiButton(
228 this, l10n_util::GetStringUTF16(IDS_OK)); 239 this, l10n_util::GetStringUTF16(IDS_OK));
229 accept_button->set_tag(BT_OK_BUTTON); 240 accept_button->set_tag(BT_OK_BUTTON);
230 241
231 views::Separator* separator = NULL; 242 views::Separator* separator = NULL;
232 if (experiment.flags & installer::kToastUiMakeDefault) { 243 if (experiment.flags & installer::kToastUiMakeDefault) {
233 // In this flavor we have some veritical space, then a separator line 244 // In this flavor we have some vertical space, then a separator line
234 // and the 'make default' checkbox and the OK button on the same row. 245 // and the 'make default' checkbox and the OK button on the same row.
235 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 246 layout->AddPaddingRow(0, unrelated_space_vert);
236 layout->StartRow(0, 6); 247 layout->StartRow(0, 6);
237 separator = new views::Separator(); 248 separator = new views::Separator();
238 layout->AddView(separator); 249 layout->AddView(separator);
239 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 250 layout->AddPaddingRow(0, unrelated_space_vert);
240 251
241 layout->StartRow(0, 7); 252 layout->StartRow(0, 7);
242 make_default_ = new views::Checkbox( 253 make_default_ = new views::Checkbox(
243 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); 254 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT));
244 make_default_->SetChecked(true); 255 make_default_->SetChecked(true);
245 layout->AddView(make_default_); 256 layout->AddView(make_default_);
246 layout->AddView(accept_button); 257 layout->AddView(accept_button);
247 } else { 258 } else {
248 // On this other flavor there is no checkbox, the OK button and possibly 259 // On this other flavor there is no checkbox, the OK button and possibly
249 // the cancel button are in the same row. 260 // the cancel button are in the same row.
250 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); 261 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10);
251 layout->AddView(accept_button); 262 layout->AddView(accept_button);
252 if (dont_bug_me_button) { 263 if (dont_bug_me_button) {
253 // The dialog needs a "Don't bug me" as a button or as a radio button, 264 // The dialog needs a "Don't bug me" as a button or as a radio button,
254 // this the button case. 265 // this the button case.
255 views::LabelButton* cancel_button = 266 views::LabelButton* cancel_button =
256 views::MdTextButton::CreateSecondaryUiButton( 267 views::MdTextButton::CreateSecondaryUiButton(
257 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); 268 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
258 cancel_button->set_tag(BT_CLOSE_BUTTON); 269 cancel_button->set_tag(BT_CLOSE_BUTTON);
259 layout->AddView(cancel_button); 270 layout->AddView(cancel_button);
260 } 271 }
261 } 272 }
262 273
263 if (experiment.flags & installer::kToastUiWhyLink) { 274 if (experiment.flags & installer::kToastUiWhyLink) {
264 layout->StartRowWithPadding(0, 4, 0, 10); 275 layout->StartRowWithPadding(0, 4, 0, 10);
265 views::Link* link = new views::Link( 276 views::Link* link =
266 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); 277 new views::Link(l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));
267 link->set_listener(this); 278 link->set_listener(this);
268 layout->AddView(link); 279 layout->AddView(link);
269 } 280 }
270 281
271 // We resize the window according to the layout manager. This takes into 282 // We resize the window according to the layout manager. This takes into
272 // account the differences between XP and Vista fonts and buttons. 283 // account the differences between XP and Vista fonts and buttons.
273 layout->Layout(root_view); 284 layout->Layout(root_view);
274 gfx::Size preferred = layout->GetPreferredSize(root_view); 285 gfx::Size preferred = layout->GetPreferredSize(root_view);
275 if (separator) { 286 if (separator) {
276 int separator_height = separator->GetPreferredSize().height(); 287 int separator_height = separator->GetPreferredSize().height();
277 separator->SetSize(gfx::Size(preferred.width(), separator_height)); 288 separator->SetSize(gfx::Size(preferred.width(), separator_height));
278 } 289 }
279 290
280 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL()); 291 gfx::Rect pos = ComputeWindowPosition(preferred, base::i18n::IsRTL());
281 popup_->SetBounds(pos); 292 popup_->SetBounds(pos);
282 293
283 // Carve the toast shape into the window. 294 // Carve the toast shape into the window.
284 HWND toast_window; 295 HWND toast_window;
285 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget(); 296 toast_window = popup_->GetNativeView()->GetHost()->GetAcceleratedWidget();
286 SetToastRegion(toast_window, preferred.width(), preferred.height()); 297 SetToastRegion(toast_window, preferred.width(), preferred.height());
287 298
288 // Time to show the window in a modal loop. 299 // Time to show the window in a modal loop.
289 popup_->Show(); 300 popup_->Show();
301
290 if (!listener.is_null()) 302 if (!listener.is_null())
291 listener.Run(popup_->GetNativeView()); 303 listener.Run(popup_->GetNativeView());
292 base::RunLoop().Run(); 304
293 if (!listener.is_null()) 305 // If the dialog is not modal, we don't control when it is going to be
294 listener.Run(NULL); 306 // dismissed and hence we cannot inform the listener about the dialog going
307 // away.
308 if (dialog_type == MODAL) {
309 base::RunLoop().Run();
310 if (!listener.is_null())
311 listener.Run(NULL);
sky 2017/04/28 21:25:49 NULL -> nullptr
ananta 2017/04/28 21:45:22 Done.
312 }
295 return result_; 313 return result_;
296 } 314 }
297 315
298 gfx::Rect TryChromeDialogView::ComputeWindowPosition(gfx::Size size, 316 gfx::Rect TryChromeDialogView::ComputeWindowPosition(gfx::Size size,
sky 2017/04/28 21:25:49 const gfx::Size&
ananta 2017/04/28 21:45:22 Done.
299 bool is_RTL) { 317 bool is_RTL) {
300 // A best guess at a visible location in case all else fails. 318 gfx::Point origin;
301 gfx::Point origin(20, 20);
302 319
303 // The taskbar (the 'Shell_TrayWnd' window) is always on the primary monitor. 320 gfx::Rect work_area = popup_->GetWorkAreaBoundsInScreen();
304 constexpr POINT kOrigin = {}; 321 origin.set_x(is_RTL ? work_area.x() : work_area.right() - size.width());
305 MONITORINFO info = {sizeof(info)}; 322 origin.set_y(work_area.bottom()- size.height());
306 if (::GetMonitorInfo(::MonitorFromPoint(kOrigin, MONITOR_DEFAULTTOPRIMARY),
307 &info)) {
308 // |rcWork| is the work area, accounting for the visible taskbars.
309 origin.set_x(is_RTL ? info.rcWork.left : info.rcWork.right - size.width());
310 origin.set_y(info.rcWork.bottom - size.height());
311 }
312 323
313 return gfx::Rect(origin, size); 324 return display::Screen::GetScreen()->ScreenToDIPRectInWindow(
325 popup_->GetNativeView(), gfx::Rect(origin, size));
314 } 326 }
315 327
316 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) { 328 void TryChromeDialogView::SetToastRegion(HWND window, int w, int h) {
317 static const POINT polygon[] = { 329 static const POINT polygon[] = {
318 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side. 330 {0, 4}, {1, 2}, {2, 1}, {4, 0}, // Left side.
319 {w-4, 0}, {w-2, 1}, {w-1, 2}, {w, 4}, // Right side. 331 {w - 4, 0}, {w - 2, 1}, {w - 1, 2}, {w, 4}, // Right side.
320 {w, h}, {0, h} 332 {w, h}, {0, h}};
321 };
322 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING); 333 HRGN region = ::CreatePolygonRgn(polygon, arraysize(polygon), WINDING);
323 ::SetWindowRgn(window, region, FALSE); 334 ::SetWindowRgn(window, region, FALSE);
324 } 335 }
325 336
326 void TryChromeDialogView::ButtonPressed(views::Button* sender, 337 void TryChromeDialogView::ButtonPressed(views::Button* sender,
327 const ui::Event& event) { 338 const ui::Event& event) {
328 if (sender->tag() == BT_DONT_BUG_RADIO) { 339 if (sender->tag() == BT_DONT_BUG_RADIO) {
329 if (make_default_) { 340 if (make_default_) {
330 make_default_->SetChecked(false); 341 make_default_->SetChecked(false);
331 make_default_->SetVisible(false); 342 make_default_->SetVisible(false);
(...skipping 18 matching lines...) Expand all
350 else if (dont_try_chrome_ && dont_try_chrome_->checked()) 361 else if (dont_try_chrome_ && dont_try_chrome_->checked())
351 result_ = NOT_NOW; 362 result_ = NOT_NOW;
352 else if (kill_chrome_ && kill_chrome_->checked()) 363 else if (kill_chrome_ && kill_chrome_->checked())
353 result_ = UNINSTALL_CHROME; 364 result_ = UNINSTALL_CHROME;
354 else 365 else
355 NOTREACHED() << "Unknown radio button selected"; 366 NOTREACHED() << "Unknown radio button selected";
356 } 367 }
357 368
358 if (make_default_) { 369 if (make_default_) {
359 if ((result_ == TRY_CHROME) && make_default_->checked()) 370 if ((result_ == TRY_CHROME) && make_default_->checked())
360 result_ = TRY_CHROME_AS_DEFAULT; 371 result_ = TRY_CHROME_AS_DEFAULT;
361 } 372 }
362 373
363 popup_->Close(); 374 popup_->Close();
364 base::MessageLoop::current()->QuitWhenIdle(); 375 base::MessageLoop::current()->QuitWhenIdle();
365 } 376 }
366 377
367 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { 378 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
368 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); 379 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
369 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698