Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: ash/system/logout_button/logout_confirmation_dialog_view.cc

Issue 40053002: Implements the dialog view for logout button tray in public sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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_button/logout_confirmation_dialog_view.h"
6
7 #include "ash/shell.h"
8 #include "ash/system/logout_button/logout_button_tray.h"
9 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ash/system/tray/tray_constants.h"
11 #include "base/location.h"
12 #include "grit/ash_strings.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/l10n/time_format.h"
16 #include "ui/base/ui_base_types.h"
17 #include "ui/gfx/text_constants.h"
18 #include "ui/views/border.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/widget/widget.h"
22
23 namespace ash {
24 namespace internal {
25
26 namespace {
27
28 const int kCountdownUpdateIntervalMs = 1000; // 1 second.
29
30 inline int Round(double x) {
31 return static_cast<int>(x + 0.5);
32 }
33
34 } // namespace
35
36 LogoutConfirmationDialogView::LogoutConfirmationDialogView(
37 LogoutButtonTray* owner, Delegate* delegate) : owner_(owner),
38 delegate_(delegate) {
39 text_label_ = new views::Label;
40 text_label_->set_border(
41 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal,
42 0, kTrayPopupPaddingHorizontal));
43 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
44 text_label_->SetMultiLine(true);
45
46 SetLayoutManager(new views::FillLayout());
47
48 AddChildView(text_label_);
49 }
50
51 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
52 }
53
54 bool LogoutConfirmationDialogView::Accept() {
55 LogoutCurrentUser();
56 return true;
57 }
58
59 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
60 return ui::MODAL_TYPE_SYSTEM;
61 }
62
63 base::string16 LogoutConfirmationDialogView::GetWindowTitle() const {
64 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
65 }
66
67 base::string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
68 ui::DialogButton button) const {
69 if (button == ui::DIALOG_BUTTON_OK)
70 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
71 return views::DialogDelegateView::GetDialogButtonLabel(button);
72 }
73
74 void LogoutConfirmationDialogView::OnClosed() {
75 owner_->ReleaseConfirmationDialog();
76 owner_ = NULL;
77 timer_.Stop();
78 // Nullify the delegate to prevent future activities of the dialog.
79 delegate_ = NULL;
80 }
81
82 void LogoutConfirmationDialogView::DeleteDelegate() {
83 if (owner_)
84 owner_->ReleaseConfirmationDialog();
85 delete this;
86 }
87
88 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
89 if (!delegate_)
90 return;
91 countdown_start_time_ = delegate_->GetCurrentTime();
92 duration_ = duration;
93
94 UpdateCountdown();
95
96 delegate_->ShowDialog(this);
97
98 timer_.Start(FROM_HERE,
99 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
100 this,
101 &LogoutConfirmationDialogView::UpdateCountdown);
102 }
103
104 void LogoutConfirmationDialogView::UpdateDialogDuration(
105 base::TimeDelta duration) {
106 duration_ = duration;
107 UpdateCountdown();
108 }
109
110 void LogoutConfirmationDialogView::LogoutCurrentUser() {
111 if (!delegate_)
112 return;
113 delegate_->LogoutCurrentUser();
114 }
115
116 void LogoutConfirmationDialogView::UpdateCountdown() {
117 if (!delegate_)
118 return;
119 const base::TimeDelta time_remaining = countdown_start_time_ +
120 duration_ - delegate_->GetCurrentTime();
121 // Round the remaining time to nearest second, and use this value for
122 // the countdown display and actual enforcement.
123 int seconds_remaining = Round(time_remaining.InSecondsF());
124 if (seconds_remaining > 0) {
125 text_label_->SetText(l10n_util::GetStringFUTF16(
126 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
127 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds(
128 seconds_remaining))));
129 } else {
130 text_label_->SetText(l10n_util::GetStringUTF16(
131 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
132 timer_.Stop();
133 LogoutCurrentUser();
134 }
135 }
136
137 } // namespace internal
138 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/logout_button/logout_confirmation_dialog_view.h ('k') | ash/system/tray/system_tray_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698