Commit aa0309f6 authored by Karthikeyan Ramasubramanian's avatar Karthikeyan Ramasubramanian Committed by Commit Bot

Add support to generate shutdown confirmation dialog

Shutdown confirmation dialog is used to display/highlight specific
information to the user prior to shutdown/restart eg. like a slow
reboot following an OS update or similar use-cases. The shutdown
confirmation dialog allows customized dialog title and message depending
on the use-case.

Bug: b/129056373
Change-Id: Ibaa9473e979314acf4856f6ac646cda209d0e303
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2001723
Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736542}
parent 5b08e216
......@@ -939,6 +939,8 @@ component("ash") {
"system/session/logout_confirmation_dialog.h",
"system/session/session_limit_notification_controller.cc",
"system/session/session_limit_notification_controller.h",
"system/session/shutdown_confirmation_dialog.cc",
"system/session/shutdown_confirmation_dialog.h",
"system/status_area_layout_manager.cc",
"system/status_area_layout_manager.h",
"system/status_area_widget.cc",
......
......@@ -1575,6 +1575,12 @@ This file contains the strings for ash.
<message name="IDS_ASH_YES_BUTTON" desc="The text for the button on a dialog OK button that agrees to the contents of the dialog.">
Yes
</message>
<message name="IDS_ASH_SHUTDOWN_CONFIRMATION_OK_BUTTON" desc="The text for the OK button in the shutdown confirmation dialog.">
Restart
</message>
<message name="IDS_ASH_SHUTDOWN_CONFIRMATION_CANCEL_BUTTON" desc="The text for the Cancel button in the shutdown confirmation dialog.">
Do it later
</message>
<message name="IDS_ASH_AUTO_NIGHT_LIGHT_NOTIFY_TITLE" desc="The title of the notification shown when Night Light turns on automatically when the auto-night-light feature is enabled.">
Night Light turns on automatically at sunset
......
// Copyright 2020 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/session/shutdown_confirmation_dialog.h"
#include <memory>
#include <utility>
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/bind.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {
// Default width of the dialog in DIPs.
constexpr int kDefaultWidth = 448;
} // namespace
ShutdownConfirmationDialog::ShutdownConfirmationDialog(
int window_title_text_id,
int dialog_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback)
: window_title_(l10n_util::GetStringUTF16(window_title_text_id)),
on_accept_callback_(std::move(on_accept_callback)),
on_cancel_callback_(std::move(on_cancel_callback)) {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_ASH_SHUTDOWN_CONFIRMATION_OK_BUTTON));
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_ASH_SHUTDOWN_CONFIRMATION_CANCEL_BUTTON));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(
views::LayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT)));
label_ = new views::Label;
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label_->SetMultiLine(true);
label_->SetText(l10n_util::GetStringUTF16(dialog_text_id));
AddChildView(label_);
// Parent the dialog widget to the PowerButtonAnimationContainer
int container_id = kShellWindowId_PowerButtonAnimationContainer;
views::Widget* widget = CreateDialogWidget(
this, nullptr,
Shell::GetContainer(ash::Shell::GetRootWindowForNewWindows(),
container_id));
widget->Show();
}
ShutdownConfirmationDialog::~ShutdownConfirmationDialog() = default;
bool ShutdownConfirmationDialog::Accept() {
std::move(on_accept_callback_).Run();
return true;
}
bool ShutdownConfirmationDialog::Cancel() {
std::move(on_cancel_callback_).Run();
return true;
}
ui::ModalType ShutdownConfirmationDialog::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 ShutdownConfirmationDialog::GetWindowTitle() const {
return window_title_;
}
bool ShutdownConfirmationDialog::ShouldShowCloseButton() const {
return false;
}
gfx::Size ShutdownConfirmationDialog::CalculatePreferredSize() const {
return gfx::Size(
kDefaultWidth,
GetLayoutManager()->GetPreferredHeightForWidth(this, kDefaultWidth));
}
} // namespace ash
// Copyright 2020 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.
#ifndef ASH_SYSTEM_SESSION_SHUTDOWN_CONFIRMATION_DIALOG_H_
#define ASH_SYSTEM_SESSION_SHUTDOWN_CONFIRMATION_DIALOG_H_
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
class Label;
}
namespace ash {
// Defines a dialog for shutdown that require confirmation from users -
// more specifically for the situation where the subsequent boot is slow.
class ShutdownConfirmationDialog : public views::DialogDelegateView {
public:
ShutdownConfirmationDialog(int window_title_text_id,
int dialog_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback);
~ShutdownConfirmationDialog() override;
// views::DialogDelegateView:
bool Accept() override;
bool Cancel() override;
// views::WidgetDelegate:
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
private:
const base::string16 window_title_;
base::OnceClosure on_accept_callback_;
base::OnceClosure on_cancel_callback_;
views::Label* label_;
DISALLOW_COPY_AND_ASSIGN(ShutdownConfirmationDialog);
};
} // namespace ash
#endif // ASH_SYSTEM_SESSION_SHUTDOWN_CONFIRMATION_DIALOG_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment