multiprofiles_intro_dialog.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/session/multiprofiles_intro_dialog.h"
  5. #include "ash/shell.h"
  6. #include "ash/strings/grit/ash_strings.h"
  7. #include "base/bind.h"
  8. #include "ui/base/l10n/l10n_util.h"
  9. #include "ui/base/resource/resource_bundle.h"
  10. #include "ui/views/border.h"
  11. #include "ui/views/controls/button/checkbox.h"
  12. #include "ui/views/controls/label.h"
  13. #include "ui/views/layout/box_layout.h"
  14. #include "ui/views/layout/layout_provider.h"
  15. #include "ui/views/widget/widget.h"
  16. namespace ash {
  17. namespace {
  18. // Default width of the dialog.
  19. constexpr int kDefaultWidth = 448;
  20. } // namespace
  21. // static
  22. void MultiprofilesIntroDialog::Show(OnAcceptCallback on_accept) {
  23. MultiprofilesIntroDialog* dialog_view =
  24. new MultiprofilesIntroDialog(std::move(on_accept));
  25. dialog_view->InitDialog();
  26. views::DialogDelegate::CreateDialogWidget(
  27. dialog_view, Shell::GetRootWindowForNewWindows(), nullptr);
  28. views::Widget* widget = dialog_view->GetWidget();
  29. DCHECK(widget);
  30. widget->Show();
  31. }
  32. gfx::Size MultiprofilesIntroDialog::CalculatePreferredSize() const {
  33. return gfx::Size(
  34. kDefaultWidth,
  35. GetLayoutManager()->GetPreferredHeightForWidth(this, kDefaultWidth));
  36. }
  37. MultiprofilesIntroDialog::MultiprofilesIntroDialog(OnAcceptCallback on_accept)
  38. : never_show_again_checkbox_(new views::Checkbox(
  39. l10n_util::GetStringUTF16(IDS_ASH_DIALOG_DONT_SHOW_AGAIN))),
  40. on_accept_(std::move(on_accept)) {
  41. never_show_again_checkbox_->SetChecked(true);
  42. SetModalType(ui::MODAL_TYPE_SYSTEM);
  43. SetTitle(l10n_util::GetStringUTF16(IDS_ASH_MULTIPROFILES_INTRO_HEADLINE));
  44. SetShowCloseButton(false);
  45. SetAcceptCallback(base::BindOnce(
  46. [](MultiprofilesIntroDialog* dialog) {
  47. std::move(dialog->on_accept_)
  48. .Run(true, dialog->never_show_again_checkbox_->GetChecked());
  49. },
  50. base::Unretained(this)));
  51. SetCancelCallback(base::BindOnce(
  52. [](MultiprofilesIntroDialog* dialog) {
  53. std::move(dialog->on_accept_).Run(false, false);
  54. },
  55. base::Unretained(this)));
  56. }
  57. MultiprofilesIntroDialog::~MultiprofilesIntroDialog() = default;
  58. void MultiprofilesIntroDialog::InitDialog() {
  59. const views::LayoutProvider* provider = views::LayoutProvider::Get();
  60. SetBorder(views::CreateEmptyBorder(provider->GetDialogInsetsForContentType(
  61. views::DialogContentType::kText, views::DialogContentType::kControl)));
  62. SetLayoutManager(std::make_unique<views::BoxLayout>(
  63. views::BoxLayout::Orientation::kVertical, gfx::Insets(),
  64. provider->GetDistanceMetric(views::DISTANCE_UNRELATED_CONTROL_VERTICAL)));
  65. // Explanation string
  66. views::Label* label = new views::Label(
  67. l10n_util::GetStringUTF16(IDS_ASH_MULTIPROFILES_INTRO_MESSAGE));
  68. label->SetMultiLine(true);
  69. label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  70. AddChildView(label);
  71. AddChildView(never_show_again_checkbox_);
  72. }
  73. } // namespace ash