1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_MAGIC_BOOST_MAGIC_BOOST_OPT_IN_CARD_H_
#define CHROME_BROWSER_UI_ASH_MAGIC_BOOST_MAGIC_BOOST_OPT_IN_CARD_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/ash/editor_menu/utils/pre_target_handler_view.h"
#include "ui/base/metadata/metadata_header_macros.h"
class ApplicationLocaleStorage;
namespace views {
class Label;
class MdTextButton;
class UniqueWidgetPtr;
} // namespace views
namespace chromeos {
class MagicBoostCardController;
// The Magic Boost opt-in card view.
class MagicBoostOptInCard : public chromeos::editor_menu::PreTargetHandlerView {
METADATA_HEADER(MagicBoostOptInCard,
chromeos::editor_menu::PreTargetHandlerView)
public:
// `application_locale_storage` must be non-null and must outlive `this`.
MagicBoostOptInCard(
const ApplicationLocaleStorage* application_locale_storage,
MagicBoostCardController* controller);
MagicBoostOptInCard(const MagicBoostOptInCard&) = delete;
MagicBoostOptInCard& operator=(const MagicBoostOptInCard&) = delete;
~MagicBoostOptInCard() override;
// Creates a widget that contains a `MagicBoostOptInCard`, configured with the
// given `anchor_view_bounds`.
// `application_locale_storage` must be non-null and must outlive the returned
// widget.
static views::UniqueWidgetPtr CreateWidget(
const ApplicationLocaleStorage* application_locale_storage,
MagicBoostCardController* controller,
const gfx::Rect& anchor_view_bounds);
// Returns the host widget's name.
static const char* GetWidgetName();
// Updates the bounds of the widget to the given `anchor_view_bounds`.
void UpdateWidgetBounds(const gfx::Rect& anchor_view_bounds);
// views::View:
void RequestFocus() override;
// Returns the host widget's name.
static const char* GetWidgetNameForTest();
private:
// Button callbacks.
void OnPrimaryButtonPressed();
void OnSecondaryButtonPressed();
const raw_ref<const ApplicationLocaleStorage> application_locale_storage_;
raw_ptr<MagicBoostCardController> controller_ = nullptr;
// Owned by the views hierarchy.
raw_ptr<views::Label> title_label_ = nullptr;
raw_ptr<views::Label> body_label_ = nullptr;
raw_ptr<views::MdTextButton> secondary_button_ = nullptr;
base::WeakPtrFactory<MagicBoostOptInCard> weak_ptr_factory_{this};
};
} // namespace chromeos
#endif // CHROME_BROWSER_UI_ASH_MAGIC_BOOST_MAGIC_BOOST_OPT_IN_CARD_H_
|