OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" | 5 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" |
6 | 6 |
7 #include "ash/common/system/tray/tray_constants.h" | 7 #include "ash/common/system/tray/tray_constants.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | 9 #include "ash/system/chromeos/session/logout_confirmation_controller.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | 25 const int kCountdownUpdateIntervalMs = 1000; // 1 second. |
26 | 26 |
27 const int kHalfSecondInMs = 500; // Half a second. | 27 const int kHalfSecondInMs = 500; // Half a second. |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 LogoutConfirmationDialog::LogoutConfirmationDialog( | 31 LogoutConfirmationDialog::LogoutConfirmationDialog( |
32 LogoutConfirmationController* controller, | 32 LogoutConfirmationController* controller, |
33 base::TimeTicks logout_time) | 33 base::TimeTicks logout_time) |
34 : controller_(controller), | 34 : controller_(controller), logout_time_(logout_time) { |
35 logout_time_(logout_time) { | |
36 SetLayoutManager(new views::FillLayout()); | 35 SetLayoutManager(new views::FillLayout()); |
37 | 36 |
38 label_ = new views::Label; | 37 label_ = new views::Label; |
39 label_->SetBorder(views::Border::CreateEmptyBorder( | 38 label_->SetBorder(views::Border::CreateEmptyBorder( |
40 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | 39 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); |
41 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 40 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
42 label_->SetMultiLine(true); | 41 label_->SetMultiLine(true); |
43 AddChildView(label_); | 42 AddChildView(label_); |
44 | 43 |
45 UpdateLabel(); | 44 UpdateLabel(); |
46 | 45 |
47 CreateDialogWidget(this, ash::Shell::GetPrimaryRootWindow(), NULL); | 46 CreateDialogWidget(this, ash::Shell::GetPrimaryRootWindow(), NULL); |
48 GetWidget()->Show(); | 47 GetWidget()->Show(); |
49 | 48 |
50 update_timer_.Start( | 49 update_timer_.Start( |
51 FROM_HERE, | 50 FROM_HERE, base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), |
52 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), | 51 this, &LogoutConfirmationDialog::UpdateLabel); |
53 this, | |
54 &LogoutConfirmationDialog::UpdateLabel); | |
55 } | 52 } |
56 | 53 |
57 LogoutConfirmationDialog::~LogoutConfirmationDialog() { | 54 LogoutConfirmationDialog::~LogoutConfirmationDialog() {} |
58 } | |
59 | 55 |
60 void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) { | 56 void LogoutConfirmationDialog::Update(base::TimeTicks logout_time) { |
61 logout_time_ = logout_time; | 57 logout_time_ = logout_time; |
62 UpdateLabel(); | 58 UpdateLabel(); |
63 } | 59 } |
64 | 60 |
65 void LogoutConfirmationDialog::ControllerGone() { | 61 void LogoutConfirmationDialog::ControllerGone() { |
66 controller_ = nullptr; | 62 controller_ = nullptr; |
67 GetWidget()->Close(); | 63 GetWidget()->Close(); |
68 } | 64 } |
(...skipping 26 matching lines...) Expand all Loading... |
95 controller_->OnDialogClosed(); | 91 controller_->OnDialogClosed(); |
96 } | 92 } |
97 | 93 |
98 void LogoutConfirmationDialog::UpdateLabel() { | 94 void LogoutConfirmationDialog::UpdateLabel() { |
99 const base::TimeDelta time_remaining = | 95 const base::TimeDelta time_remaining = |
100 logout_time_ - controller_->clock()->NowTicks(); | 96 logout_time_ - controller_->clock()->NowTicks(); |
101 if (time_remaining >= base::TimeDelta::FromMilliseconds(kHalfSecondInMs)) { | 97 if (time_remaining >= base::TimeDelta::FromMilliseconds(kHalfSecondInMs)) { |
102 label_->SetText(l10n_util::GetStringFUTF16( | 98 label_->SetText(l10n_util::GetStringFUTF16( |
103 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | 99 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, |
104 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | 100 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, |
105 ui::TimeFormat::LENGTH_LONG, | 101 ui::TimeFormat::LENGTH_LONG, 10, |
106 10, | |
107 time_remaining))); | 102 time_remaining))); |
108 } else { | 103 } else { |
109 label_->SetText(l10n_util::GetStringUTF16( | 104 label_->SetText( |
110 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | 105 l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); |
111 update_timer_.Stop(); | 106 update_timer_.Stop(); |
112 } | 107 } |
113 } | 108 } |
114 | 109 |
115 } // namespace ash | 110 } // namespace ash |
OLD | NEW |