session_aborted_dialog.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/session_aborted_dialog.h"
  5. #include "ash/root_window_controller.h"
  6. #include "ash/session/session_controller_impl.h"
  7. #include "ash/shelf/shelf.h"
  8. #include "ash/shell.h"
  9. #include "ash/strings/grit/ash_strings.h"
  10. #include "base/bind.h"
  11. #include "base/strings/utf_string_conversions.h"
  12. #include "ui/base/l10n/l10n_util.h"
  13. #include "ui/base/resource/resource_bundle.h"
  14. #include "ui/views/border.h"
  15. #include "ui/views/controls/button/checkbox.h"
  16. #include "ui/views/controls/label.h"
  17. #include "ui/views/layout/fill_layout.h"
  18. #include "ui/views/layout/layout_provider.h"
  19. #include "ui/views/widget/widget.h"
  20. namespace ash {
  21. namespace {
  22. // Default width of the dialog.
  23. constexpr int kDefaultWidth = 448;
  24. } // namespace
  25. // static
  26. void SessionAbortedDialog::Show(const std::string& user_email) {
  27. SessionAbortedDialog* dialog_view = new SessionAbortedDialog();
  28. dialog_view->InitDialog(user_email);
  29. views::DialogDelegate::CreateDialogWidget(
  30. dialog_view, Shell::GetRootWindowForNewWindows(), nullptr);
  31. views::Widget* widget = dialog_view->GetWidget();
  32. DCHECK(widget);
  33. widget->Show();
  34. // Since this is the last thing the user ever sees, we also hide all system
  35. // trays from the screen.
  36. std::vector<RootWindowController*> controllers =
  37. Shell::GetAllRootWindowControllers();
  38. for (RootWindowController* controller : controllers) {
  39. controller->shelf()->SetAutoHideBehavior(
  40. ShelfAutoHideBehavior::kAlwaysHidden);
  41. }
  42. }
  43. gfx::Size SessionAbortedDialog::CalculatePreferredSize() const {
  44. return gfx::Size(
  45. kDefaultWidth,
  46. GetLayoutManager()->GetPreferredHeightForWidth(this, kDefaultWidth));
  47. }
  48. SessionAbortedDialog::SessionAbortedDialog() {
  49. SetModalType(ui::MODAL_TYPE_SYSTEM);
  50. SetTitle(
  51. l10n_util::GetStringUTF16(IDS_ASH_MULTIPROFILES_SESSION_ABORT_HEADLINE));
  52. SetShowCloseButton(false);
  53. SetButtons(ui::DIALOG_BUTTON_OK);
  54. SetButtonLabel(ui::DIALOG_BUTTON_OK,
  55. l10n_util::GetStringUTF16(
  56. IDS_ASH_MULTIPROFILES_SESSION_ABORT_BUTTON_LABEL));
  57. SetAcceptCallback(base::BindOnce(
  58. []() { Shell::Get()->session_controller()->RequestSignOut(); }));
  59. }
  60. SessionAbortedDialog::~SessionAbortedDialog() = default;
  61. void SessionAbortedDialog::InitDialog(const std::string& user_email) {
  62. const views::LayoutProvider* provider = views::LayoutProvider::Get();
  63. SetBorder(views::CreateEmptyBorder(provider->GetDialogInsetsForContentType(
  64. views::DialogContentType::kText, views::DialogContentType::kText)));
  65. SetLayoutManager(std::make_unique<views::FillLayout>());
  66. // Explanation string.
  67. views::Label* label = new views::Label(
  68. l10n_util::GetStringFUTF16(IDS_ASH_MULTIPROFILES_SESSION_ABORT_MESSAGE,
  69. base::ASCIIToUTF16(user_email)));
  70. label->SetMultiLine(true);
  71. label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  72. label->SetAllowCharacterBreak(true);
  73. AddChildView(label);
  74. }
  75. } // namespace ash