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..6c22e66680222c0a2d4197acba613052611d47f8 |
--- /dev/null |
+++ b/ash/system/logout_button/logout_confirmation_dialog_view.cc |
@@ -0,0 +1,107 @@ |
+// 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 = 100; // 100 millisecond |
bartfab (slow)
2013/10/30 11:17:28
* If the UI only shows seconds, why update it ever
binjin
2013/11/19 14:43:46
Done.
|
+ |
+} // namespace |
+ |
+namespace ash { |
+ |
+namespace internal { |
+ |
+LogoutConfirmationDialogView::LogoutConfirmationDialogView() |
+ : weak_factory_(this) { |
+ 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_); |
+} |
+ |
+bool LogoutConfirmationDialogView::Accept() { |
+ Shell::GetInstance()->system_tray_delegate()->SignOut(); |
+ 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_ = base::TimeTicks::Now(); |
+ duration_ = duration; |
+ |
+ UpdateCountdown(); |
+ |
+ views::DialogDelegate::CreateDialogWidget( |
+ this, ash::Shell::GetPrimaryRootWindow(), NULL); |
+ GetWidget()->Show(); |
+ |
+ timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), |
+ this, |
+ &LogoutConfirmationDialogView::UpdateCountdown); |
+} |
+ |
+void LogoutConfirmationDialogView::UpdateCountdown() { |
+ const base::TimeDelta logout_warning_time = countdown_start_time_ |
bartfab (slow)
2013/10/30 11:17:28
Could you rename this to something like "time_rema
binjin
2013/11/19 14:43:46
Done.
|
+ + duration_ - base::TimeTicks::Now(); |
+ if (logout_warning_time.InMilliseconds() > 0) { |
bartfab (slow)
2013/10/30 11:17:28
This should be:
if (logout_warning_time > base::T
binjin
2013/11/19 14:43:46
Done.
|
+ text_label_->SetText(l10n_util::GetStringFUTF16( |
+ IDS_ASH_LOGOUT_CONFIRMATION_WARNING, |
+ ui::TimeFormat::TimeDurationLong(logout_warning_time))); |
bartfab (slow)
2013/10/30 11:17:28
Nit: un-indent 2 spaces
binjin
2013/11/19 14:43:46
Done.
|
+ } else { |
+ text_label_->SetText(l10n_util::GetStringUTF16( |
+ IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); |
+ Shell::GetInstance()->system_tray_delegate()->SignOut(); |
+ } |
+} |
+ |
+void LogoutConfirmationDialogView::UpdateDialogDuration( |
+ base::TimeDelta duration) { |
+ duration_ = duration; |
+ UpdateCountdown(); |
+} |
+ |
+} // namespace internal |
+ |
+} // namespace ash |
+ |