Chromium Code Reviews| Index: ash/system/logout_button/logout_confirmation_dialog_view.cc |
| diff --git a/ash/system/logout_button/logout_confirmation_dialog_view.cc b/ash/system/logout_button/logout_confirmation_dialog_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc646ad46dd3f1663f3a013351de5c5fbc3a457a |
| --- /dev/null |
| +++ b/ash/system/logout_button/logout_confirmation_dialog_view.cc |
| @@ -0,0 +1,162 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/system/logout_button/logout_confirmation_dialog_view.h" |
| + |
| +#include "ash/shell.h" |
| +#include "ash/system/logout_button/logout_button_tray.h" |
| +#include "ash/system/tray/system_tray_delegate.h" |
| +#include "ash/system/tray/tray_constants.h" |
| +#include "base/location.h" |
| +#include "grit/ash_strings.h" |
| +#include "grit/ui_strings.h" |
| +#include "ui/aura/root_window.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/l10n/time_format.h" |
| +#include "ui/base/ui_base_types.h" |
| +#include "ui/gfx/text_constants.h" |
| +#include "ui/views/controls/label.h" |
| +#include "ui/views/layout/fill_layout.h" |
| +#include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace { |
| + |
| +const int kCountdownUpdateIntervalMs = 1000; // 1 second. |
| + |
| +} // namespace |
| + |
| +namespace ash { |
| +namespace internal { |
| + |
| +LogoutConfirmationSettingsProvider* |
| + LogoutConfirmationDialogView::provider_ = NULL; |
| + |
| +LogoutConfirmationSettingsProvider::LogoutConfirmationSettingsProvider() { |
| +} |
| + |
| +LogoutConfirmationSettingsProvider::~LogoutConfirmationSettingsProvider() { |
| +} |
| + |
| +void LogoutConfirmationSettingsProvider::LogoutCurrentUser( |
| + LogoutConfirmationDialogView* dialog) { |
| + if (dialog) |
| + dialog->GetWidget()->Close(); |
|
bartfab (slow)
2013/12/03 19:46:04
Nit: Can the dialog not just call GetWidget()->Clo
binjin
2013/12/05 10:08:05
I'm not sure I understand, it's the dialog it self
bartfab (slow)
2013/12/06 13:50:04
What I meant is this: The LogoutCurrentUser() call
binjin
2013/12/09 18:50:02
Done.
|
| + if (Shell::HasInstance()) |
| + Shell::GetInstance()->system_tray_delegate()->SignOut(); |
| +} |
| + |
| +base::TimeTicks LogoutConfirmationSettingsProvider::GetCurrentTime() { |
| + return base::TimeTicks::Now(); |
| +} |
| + |
| +base::TimeDelta LogoutConfirmationSettingsProvider::GetUpdateInterval() { |
| + return base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs); |
| +} |
| + |
| +LogoutConfirmationDialogView::LogoutConfirmationDialogView( |
| + base::WeakPtr<LogoutButtonTray> owner) : owner_(owner) { |
| + if (!provider_) { |
| + provider_ = new LogoutConfirmationSettingsProvider; |
| + } |
| + |
| + text_label_ = new views::Label; |
| + text_label_->set_border( |
| + views::Border::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, |
| + 0, kTrayPopupPaddingHorizontal)); |
| + text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + text_label_->SetMultiLine(true); |
| + |
| + SetLayoutManager(new views::FillLayout()); |
| + |
| + AddChildView(text_label_); |
| +} |
| + |
| +LogoutConfirmationDialogView::~LogoutConfirmationDialogView() { |
| +} |
| + |
| +void LogoutConfirmationDialogView::DeleteDelegate() { |
| + if (owner_) { |
| + owner_->DeleteConfirmationDialog(); |
| + } |
| +} |
| + |
| +bool LogoutConfirmationDialogView::Accept() { |
| + provider_->LogoutCurrentUser(this); |
| + return true; |
| +} |
| + |
| +ui::ModalType LogoutConfirmationDialogView::GetModalType() const { |
| + return ui::MODAL_TYPE_SYSTEM; |
| +} |
| + |
| +string16 LogoutConfirmationDialogView::GetWindowTitle() const { |
| + return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); |
| +} |
| + |
| +string16 LogoutConfirmationDialogView::GetDialogButtonLabel( |
| + ui::DialogButton button) const { |
| + if (button == ui::DIALOG_BUTTON_OK) |
| + return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); |
| + return views::DialogDelegateView::GetDialogButtonLabel(button); |
| +} |
| + |
| +void LogoutConfirmationDialogView::Show(base::TimeDelta duration) { |
| + countdown_start_time_ = provider_->GetCurrentTime(); |
| + duration_ = duration; |
| + |
| + UpdateCountdown(); |
| + |
| + // For testint purpose, only run the actually display the dialog if an |
| + // existing ash::Shell is available. |
| + if (ash::Shell::HasInstance()) { |
| + views::DialogDelegate::CreateDialogWidget( |
| + this, ash::Shell::GetPrimaryRootWindow(), NULL); |
| + GetWidget()->Show(); |
| + } |
| + |
| + timer_.Start(FROM_HERE, |
| + provider_->GetUpdateInterval(), |
| + this, |
| + &LogoutConfirmationDialogView::UpdateCountdown); |
| +} |
| + |
| +void LogoutConfirmationDialogView::UpdateDialogDuration( |
| + base::TimeDelta duration) { |
| + duration_ = duration; |
| + UpdateCountdown(); |
| +} |
| + |
| +void LogoutConfirmationDialogView::SetProvider( |
| + LogoutConfirmationSettingsProvider* provider) { |
| + provider_ = provider; |
| +} |
| + |
| +LogoutConfirmationSettingsProvider* |
| +LogoutConfirmationDialogView::GetProvider() { |
| + return provider_; |
| +} |
| + |
| +void LogoutConfirmationDialogView::UpdateCountdown() { |
| + const base::TimeDelta time_remaining = countdown_start_time_ |
| + + duration_ - provider_->GetCurrentTime(); |
| + // Round the remaining time to nearest second, and use this value for |
| + // the count down display. |
| + int seconds_remaining = (time_remaining |
| + + base::TimeDelta::FromMilliseconds(500)).InSeconds(); |
| + if (seconds_remaining > 0) { |
| + text_label_->SetText(l10n_util::GetStringFUTF16( |
| + IDS_ASH_LOGOUT_CONFIRMATION_WARNING, |
| + ui::TimeFormat::TimeDurationLong(base::TimeDelta::FromSeconds( |
| + seconds_remaining)))); |
| + } else { |
| + text_label_->SetText(l10n_util::GetStringUTF16( |
| + IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); |
| + timer_.Stop(); |
| + provider_->LogoutCurrentUser(this); |
| + } |
| +} |
| + |
| +} // namespace internal |
| +} // namespace ash |