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

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: minor fixes; use scoped_ptr; fix timer 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 = 1000; // 1 second.
27
28 } // namespace
29
30 namespace ash {
31
32 namespace internal {
33
34 LogoutConfirmationDialogView::LogoutConfirmationDialogView(
35 LogoutButtonTray* owner) : owner_(owner) {
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 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() {
49 if (owner_)
50 owner_->UnbindWithConfirmationDialog();
51 }
52
53 bool LogoutConfirmationDialogView::Accept() {
54 Shell::GetInstance()->system_tray_delegate()->SignOut();
55 return true;
56 }
57
58 ui::ModalType LogoutConfirmationDialogView::GetModalType() const {
59 return ui::MODAL_TYPE_SYSTEM;
60 }
61
62 string16 LogoutConfirmationDialogView::GetWindowTitle() const {
63 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
64 }
65
66 string16 LogoutConfirmationDialogView::GetDialogButtonLabel(
67 ui::DialogButton button) const {
68 if (button == ui::DIALOG_BUTTON_OK)
69 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
70 return views::DialogDelegateView::GetDialogButtonLabel(button);
71 }
72
73 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) {
74 countdown_start_time_ = base::TimeTicks::Now();
75 duration_ = duration;
76
77 UpdateCountdown();
78
79 views::DialogDelegate::CreateDialogWidget(
80 this, ash::Shell::GetPrimaryRootWindow(), NULL);
81 GetWidget()->Show();
82
83 timer_.Start(FROM_HERE,
84 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
85 this,
86 &LogoutConfirmationDialogView::UpdateCountdown);
87 }
88
89 void LogoutConfirmationDialogView::UpdateDialogDuration(
90 base::TimeDelta duration) {
91 duration_ = duration;
92 UpdateCountdown();
93 }
94
95 void LogoutConfirmationDialogView::ClearOwner() {
96 owner_ = NULL;
97 }
98
99 void LogoutConfirmationDialogView::UpdateCountdown() {
100 const base::TimeDelta time_remaining = countdown_start_time_
101 + duration_ - base::TimeTicks::Now();
102 // Round the remaining time to nearest second, and use this value for
103 // the count down display.
104 int seconds_remaining = (time_remaining
105 + base::TimeDelta::FromMilliseconds(500)).InSeconds();
106 if (seconds_remaining > 0) {
107 text_label_->SetText(l10n_util::GetStringFUTF16(
108 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
109 ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds(
110 seconds_remaining))));
111 } else {
112 text_label_->SetText(l10n_util::GetStringUTF16(
113 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
114 Shell::GetInstance()->system_tray_delegate()->SignOut();
115 }
116 }
117
118 } // namespace internal
119
120 } // namespace ash
121
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698