// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ #include <stdint.h> #include <memory> #include <optional> #include <string> #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/geometry/rounded_corners_f.h" #include "ui/gfx/native_widget_types.h" #include "ui/views/controls/menu/menu_types.h" #include "ui/views/views_export.h" namespace base { class TimeTicks; } namespace gfx { class Rect; } // namespace gfx namespace ui { class MenuModel; } namespace views { class MenuButtonController; class MenuItemView; class MenuRunnerHandler; class Widget; namespace internal { class MenuRunnerImplInterface; } namespace test { class MenuRunnerTestAPI; } // MenuRunner is responsible for showing (running) the menu and additionally // owning the MenuItemView. It is safe to delete MenuRunner at any point, but // MenuRunner will not notify you of the closure caused by a deletion. // If MenuRunner is deleted while the menu is showing the delegate of the menu // is reset. This is done to ensure delegates aren't notified after they may // have been deleted. // // Similarly you should avoid creating MenuRunner on the stack. Doing so means // MenuRunner may not be immediately destroyed if your object is destroyed, // resulting in possible callbacks to your now deleted object. Instead you // should define MenuRunner as a scoped_ptr in your class so that when your // object is destroyed MenuRunner initiates the proper cleanup and ensures your // object isn't accessed again. class VIEWS_EXPORT MenuRunner { … }; } // namespace views #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_