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

Side by Side Diff: ash/common/system/chromeos/session/logout_confirmation_dialog.cc

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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 2014 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/common/system/chromeos/session/logout_confirmation_dialog.h"
6
7 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
8 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h"
11 #include "ash/public/cpp/shell_window_ids.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/strings/grit/ash_strings.h"
14 #include "base/location.h"
15 #include "base/time/tick_clock.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/geometry/rect.h"
20 #include "ui/gfx/text_constants.h"
21 #include "ui/views/border.h"
22 #include "ui/views/controls/label.h"
23 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/widget/widget.h"
25
26 namespace ash {
27 namespace {
28
29 const int kCountdownUpdateIntervalMs = 1000; // 1 second.
30
31 const int kHalfSecondInMs = 500; // Half a second.
32
33 } // namespace
34
35 LogoutConfirmationDialog::LogoutConfirmationDialog(
36 LogoutConfirmationController* controller,
37 base::TimeTicks logout_time)
38 : controller_(controller), logout_time_(logout_time) {
39 SetLayoutManager(new views::FillLayout());
40
41 label_ = new views::Label;
42 label_->SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0,
43 kTrayPopupPaddingHorizontal));
44 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
45 label_->SetMultiLine(true);
46 AddChildView(label_);
47
48 UpdateLabel();
49
50 views::Widget* widget = new views::Widget;
51 views::Widget::InitParams params =
52 GetDialogWidgetInitParams(this, nullptr, nullptr, gfx::Rect());
53 WmShell::Get()
54 ->GetPrimaryRootWindow()
55 ->GetRootWindowController()
56 ->ConfigureWidgetInitParamsForContainer(
57 widget, kShellWindowId_SystemModalContainer, &params);
58 widget->Init(params);
59 widget->Show();
60
61 update_timer_.Start(
62 FROM_HERE, base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
63 this, &LogoutConfirmationDialog::UpdateLabel);
64 }
65
66 LogoutConfirmationDialog::~LogoutConfirmationDialog() {}
67
68 void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) {
69 logout_time_ = logout_time;
70 UpdateLabel();
71 }
72
73 void LogoutConfirmationDialog::ControllerGone() {
74 controller_ = nullptr;
75 GetWidget()->Close();
76 }
77
78 bool LogoutConfirmationDialog::Accept() {
79 logout_time_ = controller_->clock()->NowTicks();
80 UpdateLabel();
81 controller_->OnLogoutConfirmed();
82 return true;
83 }
84
85 ui::ModalType LogoutConfirmationDialog::GetModalType() const {
86 return ui::MODAL_TYPE_SYSTEM;
87 }
88
89 base::string16 LogoutConfirmationDialog::GetWindowTitle() const {
90 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE);
91 }
92
93 base::string16 LogoutConfirmationDialog::GetDialogButtonLabel(
94 ui::DialogButton button) const {
95 if (button == ui::DIALOG_BUTTON_OK)
96 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON);
97 return views::DialogDelegateView::GetDialogButtonLabel(button);
98 }
99
100 void LogoutConfirmationDialog::WindowClosing() {
101 update_timer_.Stop();
102 if (controller_)
103 controller_->OnDialogClosed();
104 }
105
106 void LogoutConfirmationDialog::UpdateLabel() {
107 const base::TimeDelta time_remaining =
108 logout_time_ - controller_->clock()->NowTicks();
109 if (time_remaining >= base::TimeDelta::FromMilliseconds(kHalfSecondInMs)) {
110 label_->SetText(l10n_util::GetStringFUTF16(
111 IDS_ASH_LOGOUT_CONFIRMATION_WARNING,
112 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION,
113 ui::TimeFormat::LENGTH_LONG, 10,
114 time_remaining)));
115 } else {
116 label_->SetText(
117 l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW));
118 update_timer_.Stop();
119 }
120 }
121
122 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698