summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.cc
blob: b0754f4a57b2f239234a84d6191f92c2f851db67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/chromeos/add_supervision/confirm_signout_dialog.h"

#include <memory>

#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/webui/chromeos/add_supervision/add_supervision_handler_utils.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"

namespace chromeos {

namespace {
// The width of the text body in the dialog.
const int kDialogBodyTextWidth = 250;
}  // namespace

ConfirmSignoutDialog::ConfirmSignoutDialog() {
  SetLayoutManager(std::make_unique<views::FillLayout>());
  SetBorder(views::CreateEmptyBorder(
      views::LayoutProvider::Get()->GetDialogInsetsForContentType(
          views::DialogContentType::TEXT, views::DialogContentType::TEXT)));

  // |body| will be owned by the views system.
  views::Label* body = new views::Label;
  body->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  body->SetMultiLine(true);
  body->SetText(
      l10n_util::GetStringUTF16(IDS_ADD_SUPERVISION_EXIT_DIALOG_BODY));
  body->SizeToFit(kDialogBodyTextWidth);
  AddChildView(body);
}

ConfirmSignoutDialog::~ConfirmSignoutDialog() = default;

ui::ModalType ConfirmSignoutDialog::GetModalType() const {
  return ui::ModalType::MODAL_TYPE_SYSTEM;
}

base::string16 ConfirmSignoutDialog::GetWindowTitle() const {
  return l10n_util::GetStringUTF16(IDS_ADD_SUPERVISION_EXIT_DIALOG_TITLE);
}

bool ConfirmSignoutDialog::Accept() {
  LogOutHelper();
  return true;
}

int ConfirmSignoutDialog::GetDialogButtons() const {
  return ui::DialogButton::DIALOG_BUTTON_OK |
         ui::DialogButton::DIALOG_BUTTON_CANCEL;
}

base::string16 ConfirmSignoutDialog::GetDialogButtonLabel(
    ui::DialogButton button) const {
  if (button == ui::DialogButton::DIALOG_BUTTON_OK) {
    return l10n_util::GetStringUTF16(
        IDS_ADD_SUPERVISION_EXIT_DIALOG_SIGNOUT_BUTTON_LABEL);
  }
  return l10n_util::GetStringUTF16(
      IDS_ADD_SUPERVISION_EXIT_DIALOG_CANCEL_BUTTON_LABEL);
}

// static
void ConfirmSignoutDialog::Show() {
  // Ownership of the ConfirmSignoutDialog is passed to the views system.
  // Dialog is system-modal, so no parent window is needed.
  constrained_window::CreateBrowserModalDialogViews(new ConfirmSignoutDialog(),
                                                    nullptr /* parent window */)
      ->Show();
}

}  // namespace chromeos