#ifndef UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_
#define UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "ui/base/owned_window_anchor.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
namespace views {
class SubmenuView;
class View;
class Widget;
namespace internal {
#if defined(USE_AURA)
class PreMenuEventDispatchHandler;
#endif
}
namespace test {
class MenuControllerTest;
}
class MenuHost : public Widget, public WidgetObserver {
public:
struct InitParams {
raw_ptr<Widget> parent = nullptr;
gfx::Rect bounds;
raw_ptr<View> contents_view = nullptr;
bool do_capture = false;
gfx::NativeView native_view_for_gestures;
ui::MenuType menu_type = ui::MenuType::kRootContextMenu;
raw_ptr<Widget> context = nullptr;
ui::OwnedWindowAnchor owned_window_anchor;
gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget;
};
explicit MenuHost(SubmenuView* submenu);
MenuHost(const MenuHost&) = delete;
MenuHost& operator=(const MenuHost&) = delete;
~MenuHost() override;
void InitMenuHost(const InitParams& init_params);
bool IsMenuHostVisible();
void ShowMenuHost(bool do_capture);
void HideMenuHost();
void DestroyMenuHost();
void SetMenuHostBounds(const gfx::Rect& bounds);
void SetMenuHostOwnedWindowAnchor(const ui::OwnedWindowAnchor& anchor);
void ReleaseMenuHostCapture();
private:
friend class test::MenuControllerTest;
internal::RootView* CreateRootView() override;
void OnMouseCaptureLost() override;
void OnNativeWidgetDestroyed() override;
void OnOwnerClosing() override;
void OnDragWillStart() override;
void OnDragComplete() override;
Widget* GetPrimaryWindowWidget() override;
void OnWidgetDestroying(Widget* widget) override;
raw_ptr<Widget, DanglingUntriaged> owner_ = nullptr;
gfx::NativeView native_view_for_gestures_ = nullptr;
raw_ptr<SubmenuView, DanglingUntriaged> submenu_;
bool destroying_ = false;
bool ignore_capture_lost_ = false;
#if defined(USE_AURA)
std::unique_ptr<internal::PreMenuEventDispatchHandler> pre_dispatch_handler_;
#endif
};
}
#endif