| OLD | NEW |
| (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/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 "ui/aura/window_event_dispatcher.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/base/l10n/time_format.h" | |
| 16 #include "ui/base/ui_base_types.h" | |
| 17 #include "ui/gfx/text_constants.h" | |
| 18 #include "ui/views/border.h" | |
| 19 #include "ui/views/controls/label.h" | |
| 20 #include "ui/views/layout/fill_layout.h" | |
| 21 #include "ui/views/widget/widget.h" | |
| 22 | |
| 23 namespace ash { | |
| 24 namespace internal { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 const int kCountdownUpdateIntervalMs = 1000; // 1 second. | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 LogoutConfirmationDialogView::LogoutConfirmationDialogView( | |
| 33 LogoutButtonTray* owner, Delegate* delegate) : owner_(owner), | |
| 34 delegate_(delegate) { | |
| 35 text_label_ = new views::Label; | |
| 36 text_label_->SetBorder(views::Border::CreateEmptyBorder( | |
| 37 0, kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | |
| 38 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 39 text_label_->SetMultiLine(true); | |
| 40 | |
| 41 SetLayoutManager(new views::FillLayout()); | |
| 42 | |
| 43 AddChildView(text_label_); | |
| 44 } | |
| 45 | |
| 46 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() { | |
| 47 } | |
| 48 | |
| 49 bool LogoutConfirmationDialogView::Accept() { | |
| 50 LogoutCurrentUser(); | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 ui::ModalType LogoutConfirmationDialogView::GetModalType() const { | |
| 55 return ui::MODAL_TYPE_SYSTEM; | |
| 56 } | |
| 57 | |
| 58 base::string16 LogoutConfirmationDialogView::GetWindowTitle() const { | |
| 59 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
| 60 } | |
| 61 | |
| 62 base::string16 LogoutConfirmationDialogView::GetDialogButtonLabel( | |
| 63 ui::DialogButton button) const { | |
| 64 if (button == ui::DIALOG_BUTTON_OK) | |
| 65 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
| 66 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
| 67 } | |
| 68 | |
| 69 void LogoutConfirmationDialogView::OnClosed() { | |
| 70 owner_->ReleaseConfirmationDialog(); | |
| 71 owner_ = NULL; | |
| 72 timer_.Stop(); | |
| 73 // Nullify the delegate to prevent future activities of the dialog. | |
| 74 delegate_ = NULL; | |
| 75 } | |
| 76 | |
| 77 void LogoutConfirmationDialogView::DeleteDelegate() { | |
| 78 if (owner_) | |
| 79 owner_->ReleaseConfirmationDialog(); | |
| 80 delete this; | |
| 81 } | |
| 82 | |
| 83 void LogoutConfirmationDialogView::Show(base::TimeDelta duration) { | |
| 84 if (!delegate_) | |
| 85 return; | |
| 86 countdown_start_time_ = delegate_->GetCurrentTime(); | |
| 87 duration_ = duration; | |
| 88 | |
| 89 UpdateCountdown(); | |
| 90 | |
| 91 delegate_->ShowDialog(this); | |
| 92 | |
| 93 timer_.Start(FROM_HERE, | |
| 94 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), | |
| 95 this, | |
| 96 &LogoutConfirmationDialogView::UpdateCountdown); | |
| 97 } | |
| 98 | |
| 99 void LogoutConfirmationDialogView::UpdateDialogDuration( | |
| 100 base::TimeDelta duration) { | |
| 101 duration_ = duration; | |
| 102 UpdateCountdown(); | |
| 103 } | |
| 104 | |
| 105 void LogoutConfirmationDialogView::LogoutCurrentUser() { | |
| 106 if (!delegate_) | |
| 107 return; | |
| 108 delegate_->LogoutCurrentUser(); | |
| 109 } | |
| 110 | |
| 111 void LogoutConfirmationDialogView::UpdateCountdown() { | |
| 112 if (!delegate_) | |
| 113 return; | |
| 114 const base::TimeDelta time_remaining = countdown_start_time_ + | |
| 115 duration_ - delegate_->GetCurrentTime(); | |
| 116 if (time_remaining > base::TimeDelta::FromSeconds(0)) { | |
| 117 text_label_->SetText(l10n_util::GetStringFUTF16( | |
| 118 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
| 119 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION, | |
| 120 ui::TimeFormat::LENGTH_LONG, | |
| 121 10, | |
| 122 time_remaining))); | |
| 123 } else { | |
| 124 text_label_->SetText(l10n_util::GetStringUTF16( | |
| 125 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
| 126 timer_.Stop(); | |
| 127 LogoutCurrentUser(); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 } // namespace internal | |
| 132 } // namespace ash | |
| OLD | NEW |