File: menu_runner_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 3,483 bytes parent folder | download | duplicates (6)
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
112
113
114
115
116
// Copyright 2014 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_IMPL_H_
#define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_

#include <stdint.h>

#include <memory>
#include <set>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "ui/base/mojom/menu_source_type.mojom-shared.h"
#include "ui/views/controls/menu/menu_controller_delegate.h"
#include "ui/views/controls/menu/menu_runner_impl_interface.h"
#include "ui/views/views_export.h"

namespace gfx {
class RoundedCornersF;
}  // namespace gfx

namespace views {

class MenuController;
class MenuDelegate;
class MenuItemView;

namespace test {

class MenuRunnerDestructionTest;

}  // namespace test

namespace internal {

// A menu runner implementation that uses views::MenuItemView to show a menu.
class VIEWS_EXPORT MenuRunnerImpl : public MenuRunnerImplInterface,
                                    public MenuControllerDelegate {
 public:
  explicit MenuRunnerImpl(std::unique_ptr<MenuItemView> menu);

  MenuRunnerImpl(const MenuRunnerImpl&) = delete;
  MenuRunnerImpl& operator=(const MenuRunnerImpl&) = delete;

  bool IsRunning() const override;
  void Release() override;
  using MenuRunnerImplInterface::RunMenuAt;
  void RunMenuAt(
      Widget* parent,
      MenuButtonController* button_controller,
      const gfx::Rect& bounds,
      MenuAnchorPosition anchor,
      ui::mojom::MenuSourceType source_type,
      int32_t run_types,
      gfx::NativeView native_view_for_gestures,
      std::optional<gfx::RoundedCornersF> corners,
      std::optional<std::string> show_menu_host_duration_histogram) override;
  void Cancel() override;
  base::TimeTicks GetClosingEventTime() const override;

  // MenuControllerDelegate:
  void OnMenuClosed(NotifyType type,
                    MenuItemView* menu,
                    int mouse_event_flags) override;
  void SiblingMenuCreated(MenuItemView* menu) override;

 private:
  friend class ::views::test::MenuRunnerDestructionTest;

  ~MenuRunnerImpl() override;

  // Returns true if mnemonics should be shown in the menu.
  bool ShouldShowMnemonics(int32_t run_types);

  // Created and set as the delegate of the MenuItemView if Release() is
  // invoked.  This is done to make sure the delegate isn't notified after
  // Release() is invoked. We do this as we assume the delegate is no longer
  // valid if MenuRunner has been deleted.
  std::unique_ptr<MenuDelegate> empty_delegate_;

  // The menu.
  std::unique_ptr<MenuItemView> menu_;

  // Any sibling menus. Does not include |menu_|. We own these too.
  std::set<raw_ptr<MenuItemView, SetExperimental>> sibling_menus_;

  // Are we in run waiting for it to return?
  bool running_ = false;

  // Set if |running_| and Release() has been invoked.
  bool delete_after_run_ = false;

  // Are we running for a drop?
  bool for_drop_ = false;

  // The controller.
  base::WeakPtr<MenuController> controller_;

  // Do we own the controller?
  bool owns_controller_ = false;

  // The timestamp of the event which closed the menu - or 0.
  base::TimeTicks closing_event_time_;

  // Used to detect deletion of |this| when notifying delegate of success.
  base::WeakPtrFactory<MenuRunnerImpl> weak_factory_{this};
};

}  // namespace internal
}  // namespace views

#endif  // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_IMPL_H_