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/logout_confirmation/logout_confirmation_dialog.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/system/logout_confirmation/logout_confirmation_controller.h" | |
9 #include "ash/system/tray/tray_constants.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 internal { | |
24 | |
25 namespace { | |
26 | |
27 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | |
28 | |
29 } // namespace | |
30 | |
31 LogoutConfirmationDialog::LogoutConfirmationDialog( | |
32 LogoutConfirmationController* controller, | |
33 base::TimeTicks logout_time) | |
34 : controller_(controller), | |
35 logout_time_(logout_time) { | |
36 SetLayoutManager(new views::FillLayout()); | |
37 | |
38 label_ = new views::Label; | |
39 label_->SetBorder(views::Border::CreateEmptyBorder( | |
40 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | |
41 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
42 label_->SetMultiLine(true); | |
43 AddChildView(label_); | |
44 | |
45 UpdateLabel(); | |
46 | |
47 CreateDialogWidget(this, ash::Shell::GetPrimaryRootWindow(), NULL); | |
48 GetWidget()->Show(); | |
49 | |
50 update_timer_.Start( | |
51 FROM_HERE, | |
52 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), | |
53 this, | |
54 &LogoutConfirmationDialog::UpdateLabel); | |
55 } | |
56 | |
57 LogoutConfirmationDialog::~LogoutConfirmationDialog() { | |
58 } | |
59 | |
60 void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) { | |
61 logout_time_ = logout_time; | |
62 UpdateLabel(); | |
63 } | |
64 | |
65 bool LogoutConfirmationDialog::Accept() { | |
66 logout_time_ = controller_->Clock()->NowTicks(); | |
67 UpdateLabel(); | |
68 controller_->OnLogoutConfirmed(); | |
69 return true; | |
70 } | |
71 | |
72 ui::ModalType LogoutConfirmationDialog::GetModalType() const { | |
73 return ui::MODAL_TYPE_SYSTEM; | |
74 } | |
75 | |
76 base::string16 LogoutConfirmationDialog::GetWindowTitle() const { | |
77 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
78 } | |
79 | |
80 base::string16 LogoutConfirmationDialog::GetDialogButtonLabel( | |
81 ui::DialogButton button) const { | |
82 if (button == ui::DIALOG_BUTTON_OK) | |
83 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
84 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
85 } | |
86 | |
87 void LogoutConfirmationDialog::OnClosed() { | |
88 update_timer_.Stop(); | |
89 controller_->OnDialogClosed(); | |
90 } | |
91 | |
92 void LogoutConfirmationDialog::DeleteDelegate() { | |
93 delete this; | |
94 } | |
95 | |
96 void LogoutConfirmationDialog::UpdateLabel() { | |
97 const base::TimeDelta time_remaining = | |
98 logout_time_ - controller_->Clock()->NowTicks(); | |
99 if (time_remaining >= base::TimeDelta::FromMilliseconds(500)) { | |
stevenjb
2014/02/27 17:58:44
const for 500
bartfab (slow)
2014/02/28 12:13:49
Done.
| |
100 label_->SetText(l10n_util::GetStringFUTF16( | |
101 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
102 ui::TimeFormat::TimeDurationLong(time_remaining))); | |
103 } else { | |
104 label_->SetText(l10n_util::GetStringUTF16( | |
105 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
106 update_timer_.Stop(); | |
107 } | |
108 } | |
109 | |
110 } // namespace internal | |
111 } // namespace ash | |
OLD | NEW |