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 264 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 buttom_margin = 1; | |
msw
2014/08/26 20:19:37
nit: "bottom".
yao
2014/08/27 23:07:03
Done.
| |
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/26 20:19:37
nit: capitalize UMA here.
yao
2014/08/27 23:07:03
Done.
| |
290 cs = layout->AddColumnSet(kUmaOptionColumnSetId); | |
291 cs->AddColumn( | |
292 GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); | |
293 // Add a separator. | |
msw
2014/08/26 20:19:37
nit: remove superfluous comment.
yao
2014/08/27 23:07:03
Done.
| |
294 layout->StartRow(1, kUmaOptionColumnSetId); | |
295 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | |
296 // Add the view that lets user opt-in to UMA. | |
msw
2014/08/26 20:19:37
nit: remove superfluous comment.
yao
2014/08/27 23:07:02
Done.
| |
297 layout->StartRow(1, kUmaOptionColumnSetId); | |
298 layout->AddView(CreateUmaOptinView()); | |
299 | |
300 // Since the uma optin row has a different background than the default | |
msw
2014/08/26 20:19:37
nit: capitalize UMA here.
yao
2014/08/27 23:07:03
Done.
| |
301 // background color of bubbles, the bottom margin has to be 0 to make sure | |
302 // the background extends to the bottom edge of the bubble. | |
303 buttom_margin = 0; | |
304 | |
288 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); | 305 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); |
289 } | 306 } |
290 | 307 |
291 set_margins(gfx::Insets()); | 308 set_margins(gfx::Insets(1, 0, buttom_margin, 0)); |
292 Layout(); | 309 Layout(); |
293 } | 310 } |
294 | 311 |
295 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 312 views::View* SessionCrashedBubbleView::CreateUmaOptinView() { |
296 // Checkbox for metric reporting setting. | 313 // Checkbox for metric reporting setting. |
297 // Since the text to the right of the checkbox can't be a simple string (needs | 314 // 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, | 315 // 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. | 316 // and the real text will be added as a separate view. |
300 uma_option_ = new views::Checkbox(base::string16()); | 317 uma_option_ = new views::Checkbox(base::string16()); |
301 uma_option_->SetChecked(false); | 318 uma_option_->SetChecked(false); |
302 uma_option_->set_background( | |
303 views::Background::CreateSolidBackground(kBackgroundColor)); | |
304 | 319 |
305 // The text to the right of the checkbox. | 320 // The text to the right of the checkbox. |
306 size_t offset; | 321 size_t offset; |
307 base::string16 link_text = | 322 base::string16 link_text = |
308 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_UMA_LINK_TEXT); | 323 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_UMA_LINK_TEXT); |
309 base::string16 uma_text = l10n_util::GetStringFUTF16( | 324 base::string16 uma_text = l10n_util::GetStringFUTF16( |
310 IDS_SESSION_CRASHED_VIEW_UMA_OPTIN, | 325 IDS_SESSION_CRASHED_VIEW_UMA_OPTIN, |
311 link_text, | 326 link_text, |
312 &offset); | 327 &offset); |
313 views::StyledLabel* uma_label = new views::StyledLabel(uma_text, this); | 328 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 = | 329 views::StyledLabel::RangeStyleInfo link_style = |
317 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 330 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
318 link_style.font_style = gfx::Font::NORMAL; | 331 link_style.font_style = gfx::Font::NORMAL; |
319 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), | 332 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), |
320 link_style); | 333 link_style); |
321 views::StyledLabel::RangeStyleInfo uma_style; | 334 views::StyledLabel::RangeStyleInfo uma_style; |
322 uma_style.color = kTextColor; | 335 uma_style.color = kTextColor; |
323 gfx::Range before_link_range(0, offset); | 336 gfx::Range before_link_range(0, offset); |
324 if (!before_link_range.is_empty()) | 337 if (!before_link_range.is_empty()) |
325 uma_label->AddStyleRange(before_link_range, uma_style); | 338 uma_label->AddStyleRange(before_link_range, uma_style); |
326 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); | 339 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); |
327 if (!after_link_range.is_empty()) | 340 if (!after_link_range.is_empty()) |
328 uma_label->AddStyleRange(after_link_range, uma_style); | 341 uma_label->AddStyleRange(after_link_range, uma_style); |
329 | 342 |
330 // We use a border instead of padding so that the background color reaches | 343 // Create a view to hold the checkbox and the text. |
331 // the edges of the bubble. | 344 views::View* sub_view = new views::View(); |
msw
2014/08/26 20:19:37
optional nit: consider |uma_view| or |optin_view|;
yao
2014/08/27 23:07:03
Done.
| |
332 const gfx::Insets title_insets = GetBubbleFrameView()->GetTitleInsets(); | 345 GridLayout* sub_layout = new GridLayout(sub_view); |
333 uma_option_->SetBorder(views::Border::CreateSolidSidedBorder( | 346 sub_view->SetLayoutManager(sub_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 | 347 |
340 // Separator. | 348 sub_view->set_background( |
341 const int kSeparatorColumnSetId = 2; | 349 views::Background::CreateSolidBackground(kBackgroundColor)); |
342 views::ColumnSet* cs = layout->AddColumnSet(kSeparatorColumnSetId); | 350 int inset_left = GetBubbleFrameView()->GetTitleInsets().left(); |
343 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 351 sub_layout->SetInsets(views::kRelatedControlVerticalSpacing, inset_left, |
352 views::kRelatedControlVerticalSpacing, inset_left); | |
353 | |
354 const int kReportColumnSetId = 0; | |
355 views::ColumnSet* cs = sub_layout->AddColumnSet(kReportColumnSetId); | |
356 cs->AddColumn(GridLayout::CENTER, GridLayout::LEADING, 0, | |
344 GridLayout::USE_PREF, 0, 0); | 357 GridLayout::USE_PREF, 0, 0); |
345 | 358 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, | 359 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
352 GridLayout::FIXED, kWidthOfDescriptionText, 0); | 360 GridLayout::FIXED, kWidthOfDescriptionText, 0); |
353 | 361 |
354 layout->StartRow(0, kSeparatorColumnSetId); | 362 sub_layout->StartRow(0, kReportColumnSetId); |
355 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 363 sub_layout->AddView(uma_option_); |
356 layout->StartRow(0, kReportColumnSetId); | 364 sub_layout->AddView(uma_label); |
357 layout->AddView(uma_option_); | 365 |
358 layout->AddView(uma_label); | 366 return sub_view; |
359 } | 367 } |
360 | 368 |
361 void SessionCrashedBubbleView::ButtonPressed(views::Button* sender, | 369 void SessionCrashedBubbleView::ButtonPressed(views::Button* sender, |
362 const ui::Event& event) { | 370 const ui::Event& event) { |
363 DCHECK_EQ(sender, restore_button_); | 371 DCHECK_EQ(sender, restore_button_); |
364 RestorePreviousSession(sender); | 372 RestorePreviousSession(sender); |
365 } | 373 } |
366 | 374 |
367 void SessionCrashedBubbleView::StyledLabelLinkClicked(const gfx::Range& range, | 375 void SessionCrashedBubbleView::StyledLabelLinkClicked(const gfx::Range& range, |
368 int event_flags) { | 376 int event_flags) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 GetWidget()->Close(); | 440 GetWidget()->Close(); |
433 } | 441 } |
434 | 442 |
435 bool ShowSessionCrashedBubble(Browser* browser) { | 443 bool ShowSessionCrashedBubble(Browser* browser) { |
436 if (IsBubbleUIEnabled()) { | 444 if (IsBubbleUIEnabled()) { |
437 SessionCrashedBubbleView::Show(browser); | 445 SessionCrashedBubbleView::Show(browser); |
438 return true; | 446 return true; |
439 } | 447 } |
440 return false; | 448 return false; |
441 } | 449 } |
OLD | NEW |