OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" | |
6 | |
7 #include "ash/common/system/tray/tray_constants.h" | |
8 #include "ash/shell.h" | |
9 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | |
10 #include "base/location.h" | |
11 #include "base/time/tick_clock.h" | |
12 #include "grit/ash_strings.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
14 #include "ui/base/l10n/time_format.h" | |
15 #include "ui/base/ui_base_types.h" | |
16 #include "ui/gfx/text_constants.h" | |
17 #include "ui/views/border.h" | |
18 #include "ui/views/controls/label.h" | |
19 #include "ui/views/layout/fill_layout.h" | |
20 #include "ui/views/widget/widget.h" | |
21 | |
22 namespace ash { | |
23 namespace { | |
24 | |
25 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | |
26 | |
27 const int kHalfSecondInMs = 500; // Half a second. | |
28 | |
29 } // namespace | |
30 | |
31 LogoutConfirmationDialog::LogoutConfirmationDialog( | |
32 LogoutConfirmationController* controller, | |
33 base::TimeTicks logout_time) | |
34 : controller_(controller), logout_time_(logout_time) { | |
35 SetLayoutManager(new views::FillLayout()); | |
36 | |
37 label_ = new views::Label; | |
38 label_->SetBorder(views::Border::CreateEmptyBorder( | |
39 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | |
40 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
41 label_->SetMultiLine(true); | |
42 AddChildView(label_); | |
43 | |
44 UpdateLabel(); | |
45 | |
46 CreateDialogWidget(this, ash::Shell::GetPrimaryRootWindow(), NULL); | |
47 GetWidget()->Show(); | |
48 | |
49 update_timer_.Start( | |
50 FROM_HERE, base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), | |
51 this, &LogoutConfirmationDialog::UpdateLabel); | |
52 } | |
53 | |
54 LogoutConfirmationDialog::~LogoutConfirmationDialog() {} | |
55 | |
56 void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) { | |
57 logout_time_ = logout_time; | |
58 UpdateLabel(); | |
59 } | |
60 | |
61 void LogoutConfirmationDialog::ControllerGone() { | |
62 controller_ = nullptr; | |
63 GetWidget()->Close(); | |
64 } | |
65 | |
66 bool LogoutConfirmationDialog::Accept() { | |
67 logout_time_ = controller_->clock()->NowTicks(); | |
68 UpdateLabel(); | |
69 controller_->OnLogoutConfirmed(); | |
70 return true; | |
71 } | |
72 | |
73 ui::ModalType LogoutConfirmationDialog::GetModalType() const { | |
74 return ui::MODAL_TYPE_SYSTEM; | |
75 } | |
76 | |
77 base::string16 LogoutConfirmationDialog::GetWindowTitle() const { | |
78 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
79 } | |
80 | |
81 base::string16 LogoutConfirmationDialog::GetDialogButtonLabel( | |
82 ui::DialogButton button) const { | |
83 if (button == ui::DIALOG_BUTTON_OK) | |
84 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
85 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
86 } | |
87 | |
88 void LogoutConfirmationDialog::WindowClosing() { | |
89 update_timer_.Stop(); | |
90 if (controller_) | |
91 controller_->OnDialogClosed(); | |
92 } | |
93 | |
94 void LogoutConfirmationDialog::UpdateLabel() { | |
95 const base::TimeDelta time_remaining = | |
96 logout_time_ - controller_->clock()->NowTicks(); | |
97 if (time_remaining >= base::TimeDelta::FromMilliseconds(kHalfSecondInMs)) { | |
98 label_->SetText(l10n_util::GetStringFUTF16( | |
99 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
100 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | |
101 ui::TimeFormat::LENGTH_LONG, 10, | |
102 time_remaining))); | |
103 } else { | |
104 label_->SetText( | |
105 l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
106 update_timer_.Stop(); | |
107 } | |
108 } | |
109 | |
110 } // namespace ash | |
OLD | NEW |