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

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: more fixes; make delegate pure; add ShowDialog() to delegate(); add TODO in tests Created 7 years 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 <cmath>
8
9 #include "ash/shell.h"
10 #include "ash/system/logout_button/logout_button_tray.h"
11 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/system/tray/tray_constants.h"
13 #include "base/location.h"
14 #include "grit/ash_strings.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/time_format.h"
18 #include "ui/base/ui_base_types.h"
19 #include "ui/gfx/text_constants.h"
20 #include "ui/views/border.h"
21 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h"
24
25 namespace ash {
26 namespace internal {
27
28 namespace {
29 const int kCountdownUpdateIntervalMs = 1000; // 1 second.
30 } // namespace
31
32 LogoutConfirmationDialogView::LogoutConfirmationDialogView(
33 LogoutButtonTray* owner, Delegate* delegate) : owner_(owner),
34 delegate_(delegate) {
35 text_label_ = new views::Label;
36 text_label_->set_border(
37 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal,
38 0, kTrayPopupPaddingHorizontal));
39 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
40 text_label_->SetMultiLine(true);
41
42 SetLayoutManager(new views::FillLayout());
43
44 AddChildView(text_label_);
45 }
46
47 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
48 }
49
50 bool LogoutConfirmationDialogView::Accept() {
51 LogoutCurrentUser();
52 return true;
53 }
54
55 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
56 return ui::MODAL_TYPE_SYSTEM;
57 }
58
59 string16 LogoutConfirmationDialogView::GetWindowTitle() const {
60 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
61 }
62
63 string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
64 ui::DialogButton button) const {
65 if (button == ui::DIALOG_BUTTON_OK)
66 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
67 return views::DialogDelegateView::GetDialogButtonLabel(button);
68 }
69
70 void LogoutConfirmationDialogView::OnClosed() {
71 owner_->ReleaseConfirmationDialog();
72 owner_ = NULL;
73 timer_.Stop();
74 // Nullify the delegate to prevent future activities of the dialog.
75 delegate_ = NULL;
76 }
77
78 void LogoutConfirmationDialogView::DeleteDelegate() {
79 if (owner_)
80 owner_->ReleaseConfirmationDialog();
81 delete this;
82 }
83
84 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
85 if (!delegate_)
86 return;
87 countdown_start_time_ = delegate_->GetCurrentTime();
88 duration_ = duration;
89
90 UpdateCountdown();
91
92 delegate_->ShowDialog(this);
93
94 timer_.Start(FROM_HERE,
95 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
96 this,
97 &LogoutConfirmationDialogView::UpdateCountdown);
98 }
99
100 void LogoutConfirmationDialogView::UpdateDialogDuration(
101 base::TimeDelta duration) {
102 duration_ = duration;
103 UpdateCountdown();
104 }
105
106 void LogoutConfirmationDialogView::LogoutCurrentUser() {
107 if (!delegate_)
108 return;
109 delegate_->LogoutCurrentUser();
110 }
111
112 void LogoutConfirmationDialogView::UpdateCountdown() {
113 if (!delegate_)
114 return;
115 const base::TimeDelta time_remaining = countdown_start_time_ +
116 duration_ - delegate_->GetCurrentTime();
117 // Round the remaining time to nearest second, and use this value for
118 // the countdown display and actual enforcement.
119 int seconds_remaining = round(time_remaining.InSecondsF());
120 if (seconds_remaining > 0) {
121 text_label_->SetText(l10n_util::GetStringFUTF16(
122 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
123 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds(
124 seconds_remaining))));
125 } else {
126 text_label_->SetText(l10n_util::GetStringUTF16(
127 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
128 timer_.Stop();
129 LogoutCurrentUser();
130 }
131 }
132
133 } // namespace internal
134 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698