OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 27 matching lines...) Expand all Loading... |
38 namespace internal { | 38 namespace internal { |
39 class DisplayChangeListener; | 39 class DisplayChangeListener; |
40 class MenuRunnerImplInterface; | 40 class MenuRunnerImplInterface; |
41 } | 41 } |
42 | 42 |
43 namespace test { | 43 namespace test { |
44 class MenuRunnerTestAPI; | 44 class MenuRunnerTestAPI; |
45 } | 45 } |
46 | 46 |
47 // MenuRunner is responsible for showing (running) the menu and additionally | 47 // MenuRunner is responsible for showing (running) the menu and additionally |
48 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe | 48 // owning the MenuItemView. It is safe to delete MenuRunner at any point, but |
49 // to delete MenuRunner at any point, but MenuRunner internally only deletes the | 49 // MenuRunner will not notify you of the closure caused by a deletion. |
50 // MenuItemView *after* the nested message loop completes. If MenuRunner is | 50 // If MenuRunner is deleted while the menu is showing the delegate of the menu |
51 // deleted while the menu is showing the delegate of the menu is reset. This is | 51 // is reset. This is done to ensure delegates aren't notified after they may |
52 // done to ensure delegates aren't notified after they may have been deleted. | 52 // have been deleted. |
53 // | |
54 // NOTE: while you can delete a MenuRunner at any point, the nested message loop | |
55 // won't return immediately. This means if you delete the object that owns | |
56 // the MenuRunner while the menu is running, your object is effectively still | |
57 // on the stack. A return value of MENU_DELETED indicated this. In most cases | |
58 // if RunMenuAt() returns MENU_DELETED, you should return immediately. | |
59 // | 53 // |
60 // Similarly you should avoid creating MenuRunner on the stack. Doing so means | 54 // Similarly you should avoid creating MenuRunner on the stack. Doing so means |
61 // MenuRunner may not be immediately destroyed if your object is destroyed, | 55 // MenuRunner may not be immediately destroyed if your object is destroyed, |
62 // resulting in possible callbacks to your now deleted object. Instead you | 56 // resulting in possible callbacks to your now deleted object. Instead you |
63 // should define MenuRunner as a scoped_ptr in your class so that when your | 57 // should define MenuRunner as a scoped_ptr in your class so that when your |
64 // object is destroyed MenuRunner initiates the proper cleanup and ensures your | 58 // object is destroyed MenuRunner initiates the proper cleanup and ensures your |
65 // object isn't accessed again. | 59 // object isn't accessed again. |
66 class VIEWS_EXPORT MenuRunner { | 60 class VIEWS_EXPORT MenuRunner { |
67 public: | 61 public: |
68 enum RunTypes { | 62 enum RunTypes { |
(...skipping 15 matching lines...) Expand all Loading... |
84 | 78 |
85 // The menu should behave like a Windows native Combobox dropdow menu. | 79 // The menu should behave like a Windows native Combobox dropdow menu. |
86 // This behavior includes accepting the pending item and closing on F4. | 80 // This behavior includes accepting the pending item and closing on F4. |
87 COMBOBOX = 1 << 4, | 81 COMBOBOX = 1 << 4, |
88 | 82 |
89 // A child view is performing a drag-and-drop operation, so the menu should | 83 // A child view is performing a drag-and-drop operation, so the menu should |
90 // stay open (even if it doesn't receive drag updated events). In this case, | 84 // stay open (even if it doesn't receive drag updated events). In this case, |
91 // the caller is responsible for closing the menu upon completion of the | 85 // the caller is responsible for closing the menu upon completion of the |
92 // drag-and-drop. | 86 // drag-and-drop. |
93 NESTED_DRAG = 1 << 5, | 87 NESTED_DRAG = 1 << 5, |
94 | |
95 // Used for showing a menu which does NOT block the caller. Instead the | |
96 // delegate is notified when the menu closes via OnMenuClosed. | |
97 ASYNC = 1 << 6, | |
98 }; | |
99 | |
100 enum RunResult { | |
101 // Indicates RunMenuAt is returning because the MenuRunner was deleted. | |
102 MENU_DELETED, | |
103 | |
104 // Indicates RunMenuAt returned and MenuRunner was not deleted. | |
105 NORMAL_EXIT | |
106 }; | 88 }; |
107 | 89 |
108 // Creates a new MenuRunner, which may use a native menu if available. | 90 // Creates a new MenuRunner, which may use a native menu if available. |
109 // |run_types| is a bitmask of RunTypes. If provided, | 91 // |run_types| is a bitmask of RunTypes. If provided, |
110 // |on_menu_closed_callback| is invoked when the menu is closed. | 92 // |on_menu_closed_callback| is invoked when the menu is closed. |
111 // Note that with a native menu (e.g. on Mac), the ASYNC flag in |run_types| | 93 // Note that with a native menu (e.g. on Mac), the ASYNC flag in |run_types| |
112 // may be ignored. See http://crbug.com/682544. | 94 // may be ignored. See http://crbug.com/682544. |
113 MenuRunner(ui::MenuModel* menu_model, | 95 MenuRunner(ui::MenuModel* menu_model, |
114 int32_t run_types, | 96 int32_t run_types, |
115 const base::Closure& on_menu_closed_callback = base::Closure()); | 97 const base::Closure& on_menu_closed_callback = base::Closure()); |
116 | 98 |
117 // Creates a runner for a custom-created toolkit-views menu. | 99 // Creates a runner for a custom-created toolkit-views menu. |
118 MenuRunner(MenuItemView* menu, int32_t run_types); | 100 MenuRunner(MenuItemView* menu, int32_t run_types); |
119 ~MenuRunner(); | 101 ~MenuRunner(); |
120 | 102 |
121 // Runs the menu. If this returns MENU_DELETED the method is returning | 103 // Runs the menu. MenuDelegate::OnMenuClosed will be notified of the results. |
122 // because the MenuRunner was deleted. | |
123 // Typically callers should NOT do any processing if this returns | |
124 // MENU_DELETED. | |
125 // If |anchor| uses a |BUBBLE_..| type, the bounds will get determined by | 104 // If |anchor| uses a |BUBBLE_..| type, the bounds will get determined by |
126 // using |bounds| as the thing to point at in screen coordinates. | 105 // using |bounds| as the thing to point at in screen coordinates. |
127 RunResult RunMenuAt(Widget* parent, | 106 void RunMenuAt(Widget* parent, |
128 MenuButton* button, | 107 MenuButton* button, |
129 const gfx::Rect& bounds, | 108 const gfx::Rect& bounds, |
130 MenuAnchorPosition anchor, | 109 MenuAnchorPosition anchor, |
131 ui::MenuSourceType source_type); | 110 ui::MenuSourceType source_type); |
132 | 111 |
133 // Returns true if we're in a nested message loop running the menu. | 112 // Returns true if we're in a nested message loop running the menu. |
134 bool IsRunning() const; | 113 bool IsRunning() const; |
135 | 114 |
136 // Hides and cancels the menu. This does nothing if the menu is not open. | 115 // Hides and cancels the menu. This does nothing if the menu is not open. |
137 void Cancel(); | 116 void Cancel(); |
138 | 117 |
139 // Returns the time from the event which closed the menu - or 0. | 118 // Returns the time from the event which closed the menu - or 0. |
140 base::TimeTicks closing_event_time() const; | 119 base::TimeTicks closing_event_time() const; |
141 | 120 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 154 |
176 protected: | 155 protected: |
177 DisplayChangeListener() {} | 156 DisplayChangeListener() {} |
178 }; | 157 }; |
179 | 158 |
180 } // namespace internal | 159 } // namespace internal |
181 | 160 |
182 } // namespace views | 161 } // namespace views |
183 | 162 |
184 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 163 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
OLD | NEW |