OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/session_crashed_bubble_view.h" | 5 #include "chrome/browser/ui/views/session_crashed_bubble_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 base::Passed(&browser_observer))); | 146 base::Passed(&browser_observer))); |
147 #else | 147 #else |
148 SessionCrashedBubbleView::ShowForReal(browser_observer.Pass(), false); | 148 SessionCrashedBubbleView::ShowForReal(browser_observer.Pass(), false); |
149 #endif // defined(GOOGLE_CHROME_BUILD) | 149 #endif // defined(GOOGLE_CHROME_BUILD) |
150 } | 150 } |
151 | 151 |
152 // static | 152 // static |
153 void SessionCrashedBubbleView::ShowForReal( | 153 void SessionCrashedBubbleView::ShowForReal( |
154 scoped_ptr<BrowserRemovalObserver> browser_observer, | 154 scoped_ptr<BrowserRemovalObserver> browser_observer, |
155 bool uma_opted_in_already) { | 155 bool uma_opted_in_already) { |
156 // Determine whether or not the uma opt-in option should be offered. It is | 156 // Determine whether or not the UMA opt-in option should be offered. It is |
157 // offered only when it is a Google chrome build, user hasn't opted in yet, | 157 // offered only when it is a Google chrome build, user hasn't opted in yet, |
158 // and the preference is modifiable by the user. | 158 // and the preference is modifiable by the user. |
159 bool offer_uma_optin = false; | 159 bool offer_uma_optin = false; |
160 | 160 |
161 #if defined(GOOGLE_CHROME_BUILD) | 161 #if defined(GOOGLE_CHROME_BUILD) |
162 if (!uma_opted_in_already) { | 162 if (!uma_opted_in_already) { |
163 offer_uma_optin = g_browser_process->local_state()->FindPreference( | 163 offer_uma_optin = g_browser_process->local_state()->FindPreference( |
164 prefs::kMetricsReportingEnabled)->IsUserModifiable(); | 164 prefs::kMetricsReportingEnabled)->IsUserModifiable(); |
165 } | 165 } |
166 #endif // defined(GOOGLE_CHROME_BUILD) | 166 #endif // defined(GOOGLE_CHROME_BUILD) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 cs->AddPaddingColumn(0, GetBubbleFrameView()->GetTitleInsets().left()); | 275 cs->AddPaddingColumn(0, GetBubbleFrameView()->GetTitleInsets().left()); |
276 | 276 |
277 layout->StartRow(0, kTextColumnSetId); | 277 layout->StartRow(0, kTextColumnSetId); |
278 layout->AddView(text_label); | 278 layout->AddView(text_label); |
279 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 279 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
280 | 280 |
281 layout->StartRow(0, kButtonColumnSetId); | 281 layout->StartRow(0, kButtonColumnSetId); |
282 layout->AddView(restore_button_); | 282 layout->AddView(restore_button_); |
283 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 283 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
284 | 284 |
285 int bottom_margin = 1; | |
286 | |
285 // Metrics reporting option. | 287 // Metrics reporting option. |
286 if (offer_uma_optin_) { | 288 if (offer_uma_optin_) { |
287 CreateUmaOptinView(layout); | 289 const int kUMAOptionColumnSetId = 2; |
msw
2014/08/27 23:43:07
nit: should this be "Optin" instead of "Option"?
yao
2014/08/28 00:13:36
I wanted it to be Option, (The checkout box is nam
msw
2014/08/28 00:15:35
It's fine as-is if that what you intended.
| |
290 cs = layout->AddColumnSet(kUMAOptionColumnSetId); | |
291 cs->AddColumn( | |
292 GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); | |
293 layout->StartRow(1, kUMAOptionColumnSetId); | |
294 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | |
295 layout->StartRow(1, kUMAOptionColumnSetId); | |
296 layout->AddView(CreateUMAOptinView()); | |
297 | |
298 // Since the UMA optin row has a different background than the default | |
299 // background color of bubbles, the bottom margin has to be 0 to make sure | |
300 // the background extends to the bottom edge of the bubble. | |
301 bottom_margin = 0; | |
302 | |
288 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); | 303 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); |
289 } | 304 } |
290 | 305 |
291 set_margins(gfx::Insets()); | 306 set_margins(gfx::Insets(1, 0, bottom_margin, 0)); |
292 Layout(); | 307 Layout(); |
293 } | 308 } |
294 | 309 |
295 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 310 views::View* SessionCrashedBubbleView::CreateUMAOptinView() { |
296 // Checkbox for metric reporting setting. | 311 // Checkbox for metric reporting setting. |
297 // Since the text to the right of the checkbox can't be a simple string (needs | 312 // Since the text to the right of the checkbox can't be a simple string (needs |
298 // a hyperlink in it), this checkbox contains an empty string as its label, | 313 // a hyperlink in it), this checkbox contains an empty string as its label, |
299 // and the real text will be added as a separate view. | 314 // and the real text will be added as a separate view. |
300 uma_option_ = new views::Checkbox(base::string16()); | 315 uma_option_ = new views::Checkbox(base::string16()); |
301 uma_option_->SetChecked(false); | 316 uma_option_->SetChecked(false); |
302 uma_option_->set_background( | |
303 views::Background::CreateSolidBackground(kBackgroundColor)); | |
304 | 317 |
305 // The text to the right of the checkbox. | 318 // The text to the right of the checkbox. |
306 size_t offset; | 319 size_t offset; |
307 base::string16 link_text = | 320 base::string16 link_text = |
308 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_UMA_LINK_TEXT); | 321 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_UMA_LINK_TEXT); |
309 base::string16 uma_text = l10n_util::GetStringFUTF16( | 322 base::string16 uma_text = l10n_util::GetStringFUTF16( |
310 IDS_SESSION_CRASHED_VIEW_UMA_OPTIN, | 323 IDS_SESSION_CRASHED_VIEW_UMA_OPTIN, |
311 link_text, | 324 link_text, |
312 &offset); | 325 &offset); |
313 views::StyledLabel* uma_label = new views::StyledLabel(uma_text, this); | 326 views::StyledLabel* uma_label = new views::StyledLabel(uma_text, this); |
314 uma_label->set_background( | |
315 views::Background::CreateSolidBackground(kBackgroundColor)); | |
316 views::StyledLabel::RangeStyleInfo link_style = | 327 views::StyledLabel::RangeStyleInfo link_style = |
317 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 328 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
318 link_style.font_style = gfx::Font::NORMAL; | 329 link_style.font_style = gfx::Font::NORMAL; |
319 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), | 330 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), |
320 link_style); | 331 link_style); |
321 views::StyledLabel::RangeStyleInfo uma_style; | 332 views::StyledLabel::RangeStyleInfo uma_style; |
322 uma_style.color = kTextColor; | 333 uma_style.color = kTextColor; |
323 gfx::Range before_link_range(0, offset); | 334 gfx::Range before_link_range(0, offset); |
324 if (!before_link_range.is_empty()) | 335 if (!before_link_range.is_empty()) |
325 uma_label->AddStyleRange(before_link_range, uma_style); | 336 uma_label->AddStyleRange(before_link_range, uma_style); |
326 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); | 337 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); |
327 if (!after_link_range.is_empty()) | 338 if (!after_link_range.is_empty()) |
328 uma_label->AddStyleRange(after_link_range, uma_style); | 339 uma_label->AddStyleRange(after_link_range, uma_style); |
329 | 340 |
330 // We use a border instead of padding so that the background color reaches | 341 // Create a view to hold the checkbox and the text. |
331 // the edges of the bubble. | 342 views::View* uma_view = new views::View(); |
332 const gfx::Insets title_insets = GetBubbleFrameView()->GetTitleInsets(); | 343 GridLayout* uma_layout = new GridLayout(uma_view); |
333 uma_option_->SetBorder(views::Border::CreateSolidSidedBorder( | 344 uma_view->SetLayoutManager(uma_layout); |
334 0, title_insets.left(), 0, 0, kBackgroundColor)); | |
335 uma_label->SetBorder(views::Border::CreateSolidSidedBorder( | |
336 views::kRelatedControlVerticalSpacing, kCheckboxTextDistance, | |
337 views::kRelatedControlVerticalSpacing, title_insets.left(), | |
338 kBackgroundColor)); | |
339 | 345 |
340 // Separator. | 346 uma_view->set_background( |
341 const int kSeparatorColumnSetId = 2; | 347 views::Background::CreateSolidBackground(kBackgroundColor)); |
342 views::ColumnSet* cs = layout->AddColumnSet(kSeparatorColumnSetId); | 348 int inset_left = GetBubbleFrameView()->GetTitleInsets().left(); |
343 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 349 uma_layout->SetInsets(views::kRelatedControlVerticalSpacing, inset_left, |
350 views::kRelatedControlVerticalSpacing, inset_left); | |
351 | |
352 const int kReportColumnSetId = 0; | |
353 views::ColumnSet* cs = uma_layout->AddColumnSet(kReportColumnSetId); | |
354 cs->AddColumn(GridLayout::CENTER, GridLayout::LEADING, 0, | |
344 GridLayout::USE_PREF, 0, 0); | 355 GridLayout::USE_PREF, 0, 0); |
345 | 356 cs->AddPaddingColumn(0, kCheckboxTextDistance); |
346 // Reporting row. | |
347 const int kReportColumnSetId = 3; | |
348 cs = layout->AddColumnSet(kReportColumnSetId); | |
349 cs->AddColumn(GridLayout::CENTER, GridLayout::FILL, 0, | |
350 GridLayout::USE_PREF, 0, 0); | |
351 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, | 357 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
352 GridLayout::FIXED, kWidthOfDescriptionText, 0); | 358 GridLayout::FIXED, kWidthOfDescriptionText, 0); |
353 | 359 |
354 layout->StartRow(0, kSeparatorColumnSetId); | 360 uma_layout->StartRow(0, kReportColumnSetId); |
355 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 361 uma_layout->AddView(uma_option_); |
356 layout->StartRow(0, kReportColumnSetId); | 362 uma_layout->AddView(uma_label); |
357 layout->AddView(uma_option_); | 363 |
358 layout->AddView(uma_label); | 364 return uma_view; |
359 } | 365 } |
360 | 366 |
361 void SessionCrashedBubbleView::ButtonPressed(views::Button* sender, | 367 void SessionCrashedBubbleView::ButtonPressed(views::Button* sender, |
362 const ui::Event& event) { | 368 const ui::Event& event) { |
363 DCHECK_EQ(sender, restore_button_); | 369 DCHECK_EQ(sender, restore_button_); |
364 RestorePreviousSession(sender); | 370 RestorePreviousSession(sender); |
365 } | 371 } |
366 | 372 |
367 void SessionCrashedBubbleView::StyledLabelLinkClicked(const gfx::Range& range, | 373 void SessionCrashedBubbleView::StyledLabelLinkClicked(const gfx::Range& range, |
368 int event_flags) { | 374 int event_flags) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 GetWidget()->Close(); | 438 GetWidget()->Close(); |
433 } | 439 } |
434 | 440 |
435 bool ShowSessionCrashedBubble(Browser* browser) { | 441 bool ShowSessionCrashedBubble(Browser* browser) { |
436 if (IsBubbleUIEnabled()) { | 442 if (IsBubbleUIEnabled()) { |
437 SessionCrashedBubbleView::Show(browser); | 443 SessionCrashedBubbleView::Show(browser); |
438 return true; | 444 return true; |
439 } | 445 } |
440 return false; | 446 return false; |
441 } | 447 } |
OLD | NEW |