#ifndef COMPONENTS_USER_EDUCATION_VIEWS_HELP_BUBBLE_VIEW_H_
#define COMPONENTS_USER_EDUCATION_VIEWS_HELP_BUBBLE_VIEW_H_
#include <cstddef>
#include <memory>
#include <optional>
#include <vector>
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/user_education/common/help_bubble/help_bubble_params.h"
#include "components/user_education/views/help_bubble_event_relay.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/label_button.h"
namespace views {
class ImageView;
class Label;
class MdTextButton;
}
namespace user_education {
class HelpBubbleDelegate;
namespace internal {
struct HelpBubbleAnchorParams {
raw_ptr<views::View> view = nullptr;
std::optional<gfx::Rect> rect;
bool show_arrow = true;
};
}
class HelpBubbleView : public views::BubbleDialogDelegateView {
METADATA_HEADER(HelpBubbleView, views::BubbleDialogDelegateView)
public:
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHelpBubbleElementIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kDefaultButtonIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kFirstNonDefaultButtonIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kCloseButtonIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kBodyTextIdForTesting);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kTitleTextIdForTesting);
static constexpr int kMinWidthDip = 200;
static constexpr int kMaxWidthDip = 340;
HelpBubbleView(const HelpBubbleDelegate* delegate,
const internal::HelpBubbleAnchorParams& anchor,
HelpBubbleParams params,
std::unique_ptr<HelpBubbleEventRelay> event_relay = nullptr);
HelpBubbleView(const HelpBubbleView&) = delete;
HelpBubbleView& operator=(const HelpBubbleView&) = delete;
~HelpBubbleView() override;
static bool IsHelpBubble(views::DialogDelegate* dialog);
views::LabelButton* GetDefaultButtonForTesting() const;
views::LabelButton* GetNonDefaultButtonForTesting(int index) const;
void SetForceAnchorRect(gfx::Rect force_anchor_rect);
protected:
std::u16string GetAccessibleWindowTitle() const override;
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
void OnThemeChanged() override;
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
gfx::Rect GetAnchorRect() const override;
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override;
private:
FRIEND_TEST_ALL_PREFIXES(HelpBubbleViewTimeoutTest,
RespectsProvidedTimeoutAfterActivate);
FRIEND_TEST_ALL_PREFIXES(HelpBubbleViewsTest, RootViewAccessibleName);
friend class HelpBubbleViewsTest;
friend class HelpBubbleEventRelay;
class AnchorViewObserver;
void MaybeStartAutoCloseTimer();
void OnTimeout();
const raw_ptr<const HelpBubbleDelegate> delegate_;
int max_bubble_width_ = kMaxWidthDip;
std::optional<gfx::Rect> local_anchor_bounds_;
raw_ptr<views::ImageView> icon_view_ = nullptr;
std::vector<raw_ptr<views::Label, VectorExperimental>> labels_;
std::vector<raw_ptr<views::MdTextButton, VectorExperimental>>
non_default_buttons_;
raw_ptr<views::MdTextButton> default_button_ = nullptr;
raw_ptr<views::Button> close_button_ = nullptr;
std::u16string accessible_name_;
std::u16string screenreader_hint_text_;
int activate_count_ = 0;
std::unique_ptr<CloseOnDeactivatePin> anchor_pin_;
std::unique_ptr<HelpBubbleEventRelay> event_relay_;
std::unique_ptr<AnchorViewObserver> anchor_observer_;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC)
class PrimaryWidgetObserver;
std::unique_ptr<PrimaryWidgetObserver> primary_widget_observer_;
#endif
base::TimeDelta timeout_;
base::OneShotTimer auto_close_timer_;
base::OnceClosure timeout_callback_;
};
}
#endif