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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
// 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_VIEWS_MAHI_MAHI_MENU_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_MAHI_MAHI_MENU_VIEW_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/ash/editor_menu/utils/pre_target_handler_view.h"
#include "chromeos/components/mahi/public/cpp/mahi_browser_util.h"
#include "chromeos/components/mahi/public/cpp/mahi_util.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/textfield/textfield_controller.h"
class ApplicationLocaleStorage;
namespace views {
class FlexLayoutView;
class ImageButton;
class LabelButton;
class UniqueWidgetPtr;
} // namespace views
namespace chromeos::mahi {
// A bubble style view to show Mahi Menu.
class MahiMenuView : public chromeos::editor_menu::PreTargetHandlerView {
METADATA_HEADER(MahiMenuView, chromeos::editor_menu::PreTargetHandlerView)
public:
// Enum that indicates where the Mahi Menu is shown. Different surfaces have
// different ways of providing content.
enum class Surface {
kBrowser,
kMediaApp,
};
struct ButtonStatus {
SelectedTextState summary_of_selection_eligibility =
SelectedTextState::kUnknown;
SelectedTextState elucidation_eligiblity = SelectedTextState::kUnknown;
};
// `application_locale_storage` must be non-null and must outlive `this`.
MahiMenuView(const ApplicationLocaleStorage* application_locale_storage,
ButtonStatus button_status,
Surface surface = Surface::kBrowser);
MahiMenuView(const MahiMenuView&) = delete;
MahiMenuView& operator=(const MahiMenuView&) = delete;
~MahiMenuView() override;
// Creates a menu widget that contains a `MahiMenuView`, 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,
const gfx::Rect& anchor_view_bounds,
const ButtonStatus& button_status,
const Surface surface = Surface::kBrowser);
// Returns the host widget's name.
static const char* GetWidgetName();
// chromeos::editor_menu::PreTargetHandlerView:
void RequestFocus() override;
// Updates the bounds of the view according to the given `anchor_view_bounds`.
void UpdateBounds(const gfx::Rect& anchor_view_bounds);
// views::WidgetObserver:
void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
private:
class MenuTextfieldController;
// Buttons callback.
void OnButtonPressed(::chromeos::mahi::ButtonType button_type);
// Texfield callback.
void OnQuestionSubmitted();
std::unique_ptr<views::FlexLayoutView> CreateInputContainer();
const raw_ref<const ApplicationLocaleStorage> application_locale_storage_;
// Controller for `textfield_`. Enables the
// `submit_question_button` only when the `textfield_` contains some input.
// Also, submits a question if the user presses the enter key while focused on
// the textfield.
std::unique_ptr<MenuTextfieldController> textfield_controller_;
raw_ptr<views::ImageButton> settings_button_ = nullptr;
raw_ptr<views::LabelButton> summary_button_ = nullptr;
raw_ptr<views::LabelButton> elucidation_button_ = nullptr;
raw_ptr<views::Textfield> textfield_ = nullptr;
raw_ptr<views::ImageButton> submit_question_button_ = nullptr;
// Where the mahi menu widget is shown, currently it could be the browser (web
// pages) or the media app (pdf files).
const Surface surface_;
bool announcement_alerted_ = false;
base::WeakPtrFactory<MahiMenuView> weak_ptr_factory_{this};
};
} // namespace chromeos::mahi
#endif // CHROME_BROWSER_UI_VIEWS_MAHI_MAHI_MENU_VIEW_H_
|