#ifndef COMPONENTS_USER_EDUCATION_VIEWS_CUSTOM_HELP_BUBBLE_VIEW_H_
#define COMPONENTS_USER_EDUCATION_VIEWS_CUSTOM_HELP_BUBBLE_VIEW_H_
#include <concepts>
#include <memory>
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/ptr_util.h"
#include "components/user_education/common/feature_promo/feature_promo_specification.h"
#include "components/user_education/common/help_bubble/custom_help_bubble.h"
#include "components/user_education/common/help_bubble/help_bubble_params.h"
#include "components/user_education/views/help_bubble_factory_views.h"
#include "components/user_education/views/help_bubble_views.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/widget/widget.h"
namespace user_education {
template <typename T>
concept IsCustomHelpBubbleView =
std::derived_from<T, views::BubbleDialogDelegateView> &&
std::derived_from<T, CustomHelpBubbleUi>;
template <typename T>
requires IsCustomHelpBubbleView<T>
using CustomHelpBubbleViewFactoryCallback =
base::RepeatingCallback<std::unique_ptr<T>(
const UserEducationContextPtr& from_context,
FeaturePromoSpecification::BuildHelpBubbleParams build_params)>;
template <typename T>
requires IsCustomHelpBubbleView<T>
FeaturePromoSpecification::CustomHelpBubbleFactoryCallback<
CustomHelpBubbleViews>
CreateCustomHelpBubbleViewFactoryCallback(
CustomHelpBubbleViewFactoryCallback<T> bubble_factory_callback,
std::optional<CustomHelpBubbleUi::UserAction> accept_button_action =
std::nullopt,
std::optional<CustomHelpBubbleUi::UserAction> cancel_button_action =
std::nullopt) {
return base::BindRepeating(
[](const CustomHelpBubbleViewFactoryCallback<T>& bubble_factory_callback,
std::optional<CustomHelpBubbleUi::UserAction> accept_button_action,
std::optional<CustomHelpBubbleUi::UserAction> cancel_button_action,
const UserEducationContextPtr& from_context,
FeaturePromoSpecification::BuildHelpBubbleParams build_params) {
auto* const anchor_element = build_params.anchor_element.get();
const auto arrow = build_params.arrow;
auto bubble =
bubble_factory_callback.Run(from_context, std::move(build_params));
T* const bubble_ptr = bubble.get();
bubble_ptr->set_shadow(
HelpBubbleFactoryViews::GetDefaultBubbleShadow());
auto widget =
base::WrapUnique(views::BubbleDialogDelegateView::CreateBubble(
std::move(bubble),
views::Widget::InitParams::CLIENT_OWNS_WIDGET));
if (arrow != HelpBubbleArrow::kNone) {
bubble_ptr->GetBubbleFrameView()->SetDisplayVisibleArrow(true);
bubble_ptr->SizeToContents();
}
widget->Show();
return std::make_unique<CustomHelpBubbleViews>(
std::move(widget), bubble_ptr, anchor_element, accept_button_action,
cancel_button_action);
},
std::move(bubble_factory_callback), accept_button_action,
cancel_button_action);
}
}
#endif