frame_context_menu_controller.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_FRAME_FRAME_CONTEXT_MENU_CONTROLLER_H_
  5. #define ASH_FRAME_FRAME_CONTEXT_MENU_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "ui/gfx/geometry/point.h"
  8. #include "ui/views/context_menu_controller.h"
  9. namespace chromeos {
  10. class MoveToDesksMenuModel;
  11. } // namespace chromeos
  12. namespace views {
  13. class View;
  14. class Widget;
  15. class MenuRunner;
  16. } // namespace views
  17. namespace ash {
  18. // FrameContextMenuController is used to house the common code for displaying
  19. // the context menu of frames like `NonClientFrameViewAsh` and `WideFrameView`.
  20. class ASH_EXPORT FrameContextMenuController
  21. : public views::ContextMenuController {
  22. public:
  23. class Delegate {
  24. public:
  25. // Given a `source` and a `screen_coords_point`, determine whether the
  26. // context menu should be shown.
  27. virtual bool ShouldShowContextMenu(
  28. views::View* source,
  29. const gfx::Point& screen_coords_point) = 0;
  30. protected:
  31. virtual ~Delegate() = default;
  32. };
  33. FrameContextMenuController(views::Widget* frame, Delegate* delegate);
  34. FrameContextMenuController(const FrameContextMenuController&) = delete;
  35. FrameContextMenuController& operator=(const FrameContextMenuController&) =
  36. delete;
  37. ~FrameContextMenuController() override;
  38. // views::ContextMenuController:
  39. void ShowContextMenuForViewImpl(views::View* source,
  40. const gfx::Point& point,
  41. ui::MenuSourceType source_type) override;
  42. private:
  43. // The widget that `this` controls the context menu for.
  44. views::Widget* frame_;
  45. // A delegate who is responsible for determining whether the context menu
  46. // should be shown at a point.
  47. Delegate* delegate_;
  48. std::unique_ptr<chromeos::MoveToDesksMenuModel> move_to_desks_menu_model_;
  49. std::unique_ptr<views::MenuRunner> menu_runner_;
  50. };
  51. } // namespace ash
  52. #endif // ASH_FRAME_FRAME_CONTEXT_MENU_CONTROLLER_H_