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: Immediately reflect duration updates Created 7 years, 1 month 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 "grit/ui_strings.h"
14 #include "ui/aura/root_window.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/l10n/time_format.h"
17 #include "ui/base/ui_base_types.h"
18 #include "ui/gfx/text_constants.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/layout/layout_constants.h"
22 #include "ui/views/widget/widget.h"
23
24 namespace {
25
26 const int kCountdownUpdateIntervalMs = 100; // 100 millisecond
bartfab (slow) 2013/10/30 11:17:28 * If the UI only shows seconds, why update it ever
binjin 2013/11/19 14:43:46 Done.
27
28 } // namespace
29
30 namespace ash {
31
32 namespace internal {
33
34 LogoutConfirmationDialogView::LogoutConfirmationDialogView()
35 : weak_factory_(this) {
36 text_label_ = new views::Label;
37 text_label_->set_border(
38 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal,
39 0, kTrayPopupPaddingHorizontal));
40 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
41 text_label_->SetMultiLine(true);
42
43 SetLayoutManager(new views::FillLayout());
44
45 AddChildView(text_label_);
46 }
47
48 bool LogoutConfirmationDialogView::Accept() {
49 Shell::GetInstance()->system_tray_delegate()->SignOut();
50 return true;
51 }
52
53 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
54 return ui::MODAL_TYPE_SYSTEM;
55 }
56
57 string16 LogoutConfirmationDialogView::GetWindowTitle() const {
58 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
59 }
60
61 string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
62 ui::DialogButton button) const {
63 if (button == ui::DIALOG_BUTTON_OK)
64 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
65 return views::DialogDelegateView::GetDialogButtonLabel(button);
66 }
67
68 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
69 countdown_start_time_ = base::TimeTicks::Now();
70 duration_ = duration;
71
72 UpdateCountdown();
73
74 views::DialogDelegate::CreateDialogWidget(
75 this, ash::Shell::GetPrimaryRootWindow(), NULL);
76 GetWidget()->Show();
77
78 timer_.Start(FROM_HERE,
79 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
80 this,
81 &LogoutConfirmationDialogView::UpdateCountdown);
82 }
83
84 void LogoutConfirmationDialogView::UpdateCountdown() {
85 const base::TimeDelta logout_warning_time = countdown_start_time_
bartfab (slow) 2013/10/30 11:17:28 Could you rename this to something like "time_rema
binjin 2013/11/19 14:43:46 Done.
86 + duration_ - base::TimeTicks::Now();
87 if (logout_warning_time.InMilliseconds() > 0) {
bartfab (slow) 2013/10/30 11:17:28 This should be: if (logout_warning_time > base::T
binjin 2013/11/19 14:43:46 Done.
88 text_label_->SetText(l10n_util::GetStringFUTF16(
89 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
90 ui::TimeFormat::TimeDurationLong(logout_warning_time)));
bartfab (slow) 2013/10/30 11:17:28 Nit: un-indent 2 spaces
binjin 2013/11/19 14:43:46 Done.
91 } else {
92 text_label_->SetText(l10n_util::GetStringUTF16(
93 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
94 Shell::GetInstance()->system_tray_delegate()->SignOut();
95 }
96 }
97
98 void LogoutConfirmationDialogView::UpdateDialogDuration(
99 base::TimeDelta duration) {
100 duration_ = duration;
101 UpdateCountdown();
102 }
103
104 } // namespace internal
105
106 } // namespace ash
107
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698