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

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: Add preference for dialog duration 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
27
28 } // namespace
29
30 namespace ash {
31
32 namespace internal {
33
34 base::WeakPtr<LogoutConfirmationDialogView>
35 LogoutConfirmationDialogView::GetWeakPtr() {
36 return weak_factory_.GetWeakPtr();
37 }
38
39 bool LogoutConfirmationDialogView::Accept() {
40 Shell::GetInstance()->system_tray_delegate()->SignOut();
41 return true;
42 }
43
44 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
45 return ui::MODAL_TYPE_SYSTEM;
46 }
47
48 string16 LogoutConfirmationDialogView::GetWindowTitle() const {
49 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
50 }
51
52 string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
53 ui::DialogButton button) const {
54 if (button == ui::DIALOG_BUTTON_OK)
55 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
56 return views::DialogDelegateView::GetDialogButtonLabel(button);
57 }
58
59 LogoutConfirmationDialogView::LogoutConfirmationDialogView()
60 : weak_factory_(this) {
61 text_label_ = new views::Label;
62 text_label_->set_border(
63 views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal,
64 0, kTrayPopupPaddingHorizontal));
65 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
66 text_label_->SetMultiLine(true);
67
68 SetLayoutManager(new views::FillLayout());
69
70 AddChildView(text_label_);
71 }
72
73 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
74 weak_factory_.InvalidateWeakPtrs();
bartfab (slow) 2013/10/28 16:24:07 This happens automatically when the weak_factory_
binjin 2013/10/29 16:07:05 Done.
75 }
76
77 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
78 countdown_end_time_ = base::TimeTicks::Now() + duration;
79
80 UpdateCountdown();
81
82 views::DialogDelegate::CreateDialogWidget(
83 this, ash::Shell::GetPrimaryRootWindow(), NULL);
84 GetWidget()->Show();
85
86 timer_.Start(FROM_HERE,
87 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
88 this,
89 &LogoutConfirmationDialogView::UpdateCountdown);
90 }
91
92 void LogoutConfirmationDialogView::UpdateCountdown() {
93 const base::TimeDelta logout_warning_time = countdown_end_time_ -
94 base::TimeTicks::Now();
95 if (logout_warning_time.InMilliseconds() > 0) {
96 text_label_->SetText(l10n_util::GetStringFUTF16(
97 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
98 ui::TimeFormat::TimeDurationLong(logout_warning_time)));
99 } else {
100 text_label_->SetText(l10n_util::GetStringUTF16(
101 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
102 Shell::GetInstance()->system_tray_delegate()->SignOut();
103 }
104 }
105
106 } // namespace internal
107
108 } // namespace ash
109
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698