#ifndef ASH_STYLE_SYSTEM_DIALOG_DELEGATE_VIEW_H_
#define ASH_STYLE_SYSTEM_DIALOG_DELEGATE_VIEW_H_
#include <string>
#include "ash/ash_export.h"
#include "ash/style/pill_button.h"
#include "ash/style/system_shadow.h"
#include "base/functional/callback_forward.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
class ImageView;
class Label;
}
namespace ash {
class ASH_EXPORT SystemDialogDelegateView : public views::WidgetDelegateView {
METADATA_HEADER(SystemDialogDelegateView, views::WidgetDelegateView)
public:
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kAcceptButtonIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kCancelButtonIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kDescriptionTextIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kTitleTextIdForTesting);
SystemDialogDelegateView();
SystemDialogDelegateView(const SystemDialogDelegateView&) = delete;
SystemDialogDelegateView& operator=(const SystemDialogDelegateView&) = delete;
~SystemDialogDelegateView() override;
void SetIcon(const gfx::VectorIcon& icon);
void SetTitleText(const std::u16string& title);
void SetDescription(const std::u16string& description);
void SetDescriptionAccessibleName(const std::u16string& accessible_name);
void SetAcceptButtonVisible(bool visible);
void SetCancelButtonVisible(bool visible);
void SetAcceptButtonText(const std::u16string& accept_text);
void SetCancelButtonText(const std::u16string& cancel_text);
void SetAcceptCallback(base::OnceClosure accept_callback) {
accept_callback_ = std::move(accept_callback);
}
void SetCancelCallback(base::OnceClosure cancel_callback) {
cancel_callback_ = std::move(cancel_callback);
}
void SetCloseCallback(base::OnceClosure close_callback) {
close_callback_ = std::move(close_callback);
}
template <typename T>
T* SetTopContentView(std::unique_ptr<T> view) {
T* ptr = view.get();
SetContentInternal(std::move(view), ContentType::kTop);
return ptr;
}
template <typename T>
T* SetMiddleContentView(std::unique_ptr<T> view) {
T* ptr = view.get();
SetContentInternal(std::move(view), ContentType::kMiddle);
return ptr;
}
template <typename T>
T* SetAdditionalViewInButtonRow(std::unique_ptr<T> view) {
T* ptr = view.get();
SetAdditionalViewInButtonRowInternal(std::move(view));
return ptr;
}
void SetButtonContainerAlignment(views::LayoutAlignment alignment);
void SetTopContentAlignment(views::LayoutAlignment alignment);
void SetMiddleContentAlignment(views::LayoutAlignment alignment);
void SetTitleMargins(const gfx::Insets& margins);
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
gfx::Size GetMinimumSize() const override;
gfx::Size GetMaximumSize() const override;
void OnWidgetInitialized() override;
void OnWorkAreaChanged() override;
const PillButton* GetAcceptButtonForTesting() const;
const PillButton* GetCancelButtonForTesting() const;
protected:
virtual void UpdateDialogSize();
private:
class ButtonContainer;
enum class ContentType {
kTop,
kMiddle,
};
size_t GetContentIndex(ContentType type) const;
void SetContentInternal(std::unique_ptr<views::View> view, ContentType type);
void SetAdditionalViewInButtonRowInternal(std::unique_ptr<views::View> view);
void Accept();
void Cancel();
void Close();
void RunCallbackAndCloseDialog(base::OnceClosure callback,
views::Widget::ClosedReason closed_reason);
base::OnceClosure accept_callback_;
base::OnceClosure cancel_callback_;
base::OnceClosure close_callback_;
raw_ptr<views::ImageView> icon_ = nullptr;
raw_ptr<views::Label> title_ = nullptr;
raw_ptr<views::Label> description_ = nullptr;
raw_ptr<ButtonContainer> button_container_ = nullptr;
base::flat_map<ContentType, raw_ptr<views::View>> contents_;
std::unique_ptr<SystemShadow> shadow_;
bool closing_dialog_ = false;
};
BEGIN_VIEW_BUILDER(ASH_EXPORT,
SystemDialogDelegateView,
views::WidgetDelegateView)
VIEW_BUILDER_PROPERTY(const gfx::VectorIcon&, Icon, const gfx::VectorIcon&)
VIEW_BUILDER_PROPERTY(const std::u16string&, TitleText)
VIEW_BUILDER_PROPERTY(const std::u16string&, Description)
VIEW_BUILDER_PROPERTY(const std::u16string&, DescriptionAccessibleName)
VIEW_BUILDER_PROPERTY(const std::u16string&, AcceptButtonText)
VIEW_BUILDER_PROPERTY(const std::u16string&, CancelButtonText)
VIEW_BUILDER_PROPERTY(base::OnceClosure, AcceptCallback)
VIEW_BUILDER_PROPERTY(base::OnceClosure, CancelCallback)
VIEW_BUILDER_PROPERTY(base::OnceClosure, CloseCallback)
VIEW_BUILDER_VIEW_TYPE_PROPERTY(views::View, TopContentView)
VIEW_BUILDER_VIEW_TYPE_PROPERTY(views::View, MiddleContentView)
VIEW_BUILDER_VIEW_TYPE_PROPERTY(views::View, AdditionalViewInButtonRow)
VIEW_BUILDER_PROPERTY(views::LayoutAlignment, TopContentAlignment)
VIEW_BUILDER_PROPERTY(views::LayoutAlignment, MiddleContentAlignment)
VIEW_BUILDER_PROPERTY(bool, AcceptButtonVisible)
VIEW_BUILDER_PROPERTY(const gfx::Insets&, TitleMargins)
VIEW_BUILDER_PROPERTY(ui::mojom::ModalType, ModalType)
END_VIEW_BUILDER
}
DEFINE_VIEW_BUILDER(ASH_EXPORT, ash::SystemDialogDelegateView)
#endif