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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 using views::GridLayout; | 48 using views::GridLayout; |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Fixed width of the column holding the description label of the bubble. | 52 // Fixed width of the column holding the description label of the bubble. |
53 const int kWidthOfDescriptionText = 320; | 53 const int kWidthOfDescriptionText = 320; |
54 | 54 |
55 // Distance between checkbox and the text to the right of it. | 55 // Distance between checkbox and the text to the right of it. |
56 const int kCheckboxTextDistance = 4; | 56 const int kCheckboxTextDistance = 4; |
57 | 57 |
58 // The color of the text and background of the sub panel to offer UMA optin. | 58 // The color of the text and background of the sub panel to offer UMA opt-in. |
59 // These values match the BookmarkSyncPromoView colors. | 59 // These values match the BookmarkSyncPromoView colors. |
60 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245); | 60 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245); |
61 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); | 61 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); |
62 | 62 |
63 // The Finch study name and group name that enables session crashed bubble UI. | 63 // The Finch study name and group name that enables session crashed bubble UI. |
64 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; | 64 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; |
65 const char kEnableBubbleUIGroupEnabled[] = "Enabled"; | 65 const char kEnableBubbleUIGroupEnabled[] = "Enabled"; |
66 | 66 |
67 enum SessionCrashedBubbleHistogramValue { | 67 enum SessionCrashedBubbleHistogramValue { |
68 SESSION_CRASHED_BUBBLE_SHOWN, | 68 SESSION_CRASHED_BUBBLE_SHOWN, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 if (offer_uma_optin_) { | 287 if (offer_uma_optin_) { |
288 const int kUMAOptionColumnSetId = 2; | 288 const int kUMAOptionColumnSetId = 2; |
289 cs = layout->AddColumnSet(kUMAOptionColumnSetId); | 289 cs = layout->AddColumnSet(kUMAOptionColumnSetId); |
290 cs->AddColumn( | 290 cs->AddColumn( |
291 GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); | 291 GridLayout::FILL, GridLayout::FILL, 1, GridLayout::USE_PREF, 0, 0); |
292 layout->StartRow(1, kUMAOptionColumnSetId); | 292 layout->StartRow(1, kUMAOptionColumnSetId); |
293 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 293 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
294 layout->StartRow(1, kUMAOptionColumnSetId); | 294 layout->StartRow(1, kUMAOptionColumnSetId); |
295 layout->AddView(CreateUMAOptinView()); | 295 layout->AddView(CreateUMAOptinView()); |
296 | 296 |
297 // Since the UMA optin row has a different background than the default | 297 // Since the UMA opt-in row has a different background than the default |
298 // background color of bubbles, the bottom margin has to be 0 to make sure | 298 // background color of bubbles, the bottom margin has to be 0 to make sure |
299 // the background extends to the bottom edge of the bubble. | 299 // the background extends to the bottom edge of the bubble. |
300 bottom_margin = 0; | 300 bottom_margin = 0; |
301 | 301 |
302 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); | 302 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN); |
303 } | 303 } |
304 | 304 |
305 set_margins(gfx::Insets(1, 0, bottom_margin, 0)); | 305 set_margins(gfx::Insets(1, 0, bottom_margin, 0)); |
306 Layout(); | 306 Layout(); |
307 } | 307 } |
(...skipping 21 matching lines...) Expand all Loading... |
329 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), | 329 uma_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), |
330 link_style); | 330 link_style); |
331 views::StyledLabel::RangeStyleInfo uma_style; | 331 views::StyledLabel::RangeStyleInfo uma_style; |
332 uma_style.color = kTextColor; | 332 uma_style.color = kTextColor; |
333 gfx::Range before_link_range(0, offset); | 333 gfx::Range before_link_range(0, offset); |
334 if (!before_link_range.is_empty()) | 334 if (!before_link_range.is_empty()) |
335 uma_label->AddStyleRange(before_link_range, uma_style); | 335 uma_label->AddStyleRange(before_link_range, uma_style); |
336 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); | 336 gfx::Range after_link_range(offset + link_text.length(), uma_text.length()); |
337 if (!after_link_range.is_empty()) | 337 if (!after_link_range.is_empty()) |
338 uma_label->AddStyleRange(after_link_range, uma_style); | 338 uma_label->AddStyleRange(after_link_range, uma_style); |
| 339 // Shift the text down by 1px to align with the checkbox. |
| 340 uma_label->SetBorder(views::Border::CreateEmptyBorder(1, 0, 0, 0)); |
339 | 341 |
340 // Create a view to hold the checkbox and the text. | 342 // Create a view to hold the checkbox and the text. |
341 views::View* uma_view = new views::View(); | 343 views::View* uma_view = new views::View(); |
342 GridLayout* uma_layout = new GridLayout(uma_view); | 344 GridLayout* uma_layout = new GridLayout(uma_view); |
343 uma_view->SetLayoutManager(uma_layout); | 345 uma_view->SetLayoutManager(uma_layout); |
344 | 346 |
345 uma_view->set_background( | 347 uma_view->set_background( |
346 views::Background::CreateSolidBackground(kBackgroundColor)); | 348 views::Background::CreateSolidBackground(kBackgroundColor)); |
347 int inset_left = GetBubbleFrameView()->GetTitleInsets().left(); | 349 int inset_left = GetBubbleFrameView()->GetTitleInsets().left(); |
| 350 |
| 351 // Bottom inset for UMA opt-in view in pixels. |
| 352 const int kUMAOptinViewBottomInset = 10; |
348 uma_layout->SetInsets(views::kRelatedControlVerticalSpacing, inset_left, | 353 uma_layout->SetInsets(views::kRelatedControlVerticalSpacing, inset_left, |
349 views::kRelatedControlVerticalSpacing, inset_left); | 354 kUMAOptinViewBottomInset, inset_left); |
350 | 355 |
351 const int kReportColumnSetId = 0; | 356 const int kReportColumnSetId = 0; |
352 views::ColumnSet* cs = uma_layout->AddColumnSet(kReportColumnSetId); | 357 views::ColumnSet* cs = uma_layout->AddColumnSet(kReportColumnSetId); |
353 cs->AddColumn(GridLayout::CENTER, GridLayout::LEADING, 0, | 358 cs->AddColumn(GridLayout::CENTER, GridLayout::LEADING, 0, |
354 GridLayout::USE_PREF, 0, 0); | 359 GridLayout::USE_PREF, 0, 0); |
355 cs->AddPaddingColumn(0, kCheckboxTextDistance); | 360 cs->AddPaddingColumn(0, kCheckboxTextDistance); |
356 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, | 361 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
357 GridLayout::FIXED, kWidthOfDescriptionText, 0); | 362 GridLayout::FIXED, kWidthOfDescriptionText, 0); |
358 | 363 |
359 uma_layout->StartRow(0, kReportColumnSetId); | 364 uma_layout->StartRow(0, kReportColumnSetId); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 int index) { | 418 int index) { |
414 if (web_contents_ == contents) | 419 if (web_contents_ == contents) |
415 CloseBubble(); | 420 CloseBubble(); |
416 } | 421 } |
417 | 422 |
418 void SessionCrashedBubbleView::RestorePreviousSession(views::Button* sender) { | 423 void SessionCrashedBubbleView::RestorePreviousSession(views::Button* sender) { |
419 SessionRestore::RestoreSessionAfterCrash(browser_); | 424 SessionRestore::RestoreSessionAfterCrash(browser_); |
420 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); | 425 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); |
421 restored_ = true; | 426 restored_ = true; |
422 | 427 |
423 // Record user's choice for opting in to UMA. | 428 // Record user's choice for opt-in in to UMA. |
424 // There's no opting-out choice in the crash restore bubble. | 429 // There's no opt-out choice in the crash restore bubble. |
425 if (uma_option_ && uma_option_->checked()) { | 430 if (uma_option_ && uma_option_->checked()) { |
426 InitiateMetricsReportingChange(true, OnMetricsReportingCallbackType()); | 431 InitiateMetricsReportingChange(true, OnMetricsReportingCallbackType()); |
427 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); | 432 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); |
428 } | 433 } |
429 CloseBubble(); | 434 CloseBubble(); |
430 } | 435 } |
431 | 436 |
432 void SessionCrashedBubbleView::CloseBubble() { | 437 void SessionCrashedBubbleView::CloseBubble() { |
433 GetWidget()->Close(); | 438 GetWidget()->Close(); |
434 } | 439 } |
435 | 440 |
436 bool ShowSessionCrashedBubble(Browser* browser) { | 441 bool ShowSessionCrashedBubble(Browser* browser) { |
437 if (IsBubbleUIEnabled()) { | 442 if (IsBubbleUIEnabled()) { |
438 SessionCrashedBubbleView::Show(browser); | 443 SessionCrashedBubbleView::Show(browser); |
439 return true; | 444 return true; |
440 } | 445 } |
441 return false; | 446 return false; |
442 } | 447 } |
OLD | NEW |