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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 namespace views { | 27 namespace views { |
28 | 28 |
29 class MenuButton; | 29 class MenuButton; |
30 class MenuItemView; | 30 class MenuItemView; |
31 class MenuModelAdapter; | 31 class MenuModelAdapter; |
32 class MenuRunnerHandler; | 32 class MenuRunnerHandler; |
33 class Widget; | 33 class Widget; |
34 | 34 |
35 namespace internal { | 35 namespace internal { |
36 class DisplayChangeListener; | 36 class DisplayChangeListener; |
37 class MenuRunnerImpl; | 37 class MenuRunnerImplInterface; |
38 } | 38 } |
39 | 39 |
40 namespace test { | 40 namespace test { |
41 class MenuRunnerTestAPI; | 41 class MenuRunnerTestAPI; |
42 } | 42 } |
43 | 43 |
44 // MenuRunner is responsible for showing (running) the menu and additionally | 44 // MenuRunner is responsible for showing (running) the menu and additionally |
45 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe | 45 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe |
46 // to delete MenuRunner at any point, but MenuRunner internally only deletes the | 46 // to delete MenuRunner at any point, but MenuRunner internally only deletes the |
47 // MenuItemView *after* the nested message loop completes. If MenuRunner is | 47 // MenuItemView *after* the nested message loop completes. If MenuRunner is |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 | 86 |
87 enum RunResult { | 87 enum RunResult { |
88 // Indicates RunMenuAt is returning because the MenuRunner was deleted. | 88 // Indicates RunMenuAt is returning because the MenuRunner was deleted. |
89 MENU_DELETED, | 89 MENU_DELETED, |
90 | 90 |
91 // Indicates RunMenuAt returned and MenuRunner was not deleted. | 91 // Indicates RunMenuAt returned and MenuRunner was not deleted. |
92 NORMAL_EXIT | 92 NORMAL_EXIT |
93 }; | 93 }; |
94 | 94 |
95 // Creates a new MenuRunner. | 95 // Creates a new MenuRunner. |
96 explicit MenuRunner(ui::MenuModel* menu_model); | 96 // |run_types| is a bitmask of RunTypes. |
97 explicit MenuRunner(MenuItemView* menu); | 97 MenuRunner(ui::MenuModel* menu_model, int32 run_types); |
98 MenuRunner(MenuItemView* menu, int32 run_types); | |
98 ~MenuRunner(); | 99 ~MenuRunner(); |
99 | 100 |
100 // Returns the menu. | 101 // Returns the menu. |
101 MenuItemView* GetMenu(); | 102 MenuItemView* GetMenu(); |
102 | 103 |
103 // Takes ownership of |menu|, deleting it when MenuRunner is deleted. You | 104 // Takes ownership of |menu|, deleting it when MenuRunner is deleted. You |
104 // only need call this if you create additional menus from | 105 // only need call this if you create additional menus from |
105 // MenuDelegate::GetSiblingMenu. | 106 // MenuDelegate::GetSiblingMenu. |
106 void OwnMenu(MenuItemView* menu); | 107 void OwnMenu(MenuItemView* menu); |
107 | 108 |
108 // Runs the menu. |types| is a bitmask of RunTypes. If this returns | 109 // Runs the menu. If this returns MENU_DELETED the method is returning |
109 // MENU_DELETED the method is returning because the MenuRunner was deleted. | 110 // because the MenuRunner was deleted. |
110 // Typically callers should NOT do any processing if this returns | 111 // Typically callers should NOT do any processing if this returns |
111 // MENU_DELETED. | 112 // MENU_DELETED. |
112 // If |anchor| uses a |BUBBLE_..| type, the bounds will get determined by | 113 // If |anchor| uses a |BUBBLE_..| type, the bounds will get determined by |
113 // using |bounds| as the thing to point at in screen coordinates. | 114 // using |bounds| as the thing to point at in screen coordinates. |
114 RunResult RunMenuAt(Widget* parent, | 115 RunResult RunMenuAt(Widget* parent, |
115 MenuButton* button, | 116 MenuButton* button, |
116 const gfx::Rect& bounds, | 117 const gfx::Rect& bounds, |
117 MenuAnchorPosition anchor, | 118 MenuAnchorPosition anchor, |
118 ui::MenuSourceType source_type, | 119 ui::MenuSourceType source_type) WARN_UNUSED_RESULT; |
119 int32 types) WARN_UNUSED_RESULT; | |
120 | 120 |
121 // Returns true if we're in a nested message loop running the menu. | 121 // Returns true if we're in a nested message loop running the menu. |
122 bool IsRunning() const; | 122 bool IsRunning() const; |
123 | 123 |
124 // Hides and cancels the menu. This does nothing if the menu is not open. | 124 // Hides and cancels the menu. This does nothing if the menu is not open. |
125 void Cancel(); | 125 void Cancel(); |
126 | 126 |
127 // Returns the time from the event which closed the menu - or 0. | 127 // Returns the time from the event which closed the menu - or 0. |
128 base::TimeDelta closing_event_time() const; | 128 base::TimeDelta closing_event_time() const; |
129 | 129 |
130 private: | 130 private: |
131 friend class test::MenuRunnerTestAPI; | 131 friend class test::MenuRunnerTestAPI; |
132 | 132 |
133 // Sets an implementation of RunMenuAt. This is intended to be used at test. | 133 // Sets an implementation of RunMenuAt. This is intended to be used at test. |
134 void SetRunnerHandler(scoped_ptr<MenuRunnerHandler> runner_handler); | 134 void SetRunnerHandler(scoped_ptr<MenuRunnerHandler> runner_handler); |
135 | 135 |
136 scoped_ptr<MenuModelAdapter> menu_model_adapter_; | 136 const int32 run_types_; |
137 | 137 |
138 internal::MenuRunnerImpl* holder_; | 138 // We own this. No scoped_ptr because it is destroyed by calling Release(). |
139 internal::MenuRunnerImplInterface* holder_; | |
sky
2014/07/14 21:02:22
holder_ was always a poor name. Maybe impl_?
Andre
2014/07/14 22:59:42
Done.
| |
139 | 140 |
140 // An implementation of RunMenuAt. This is usually NULL and ignored. If this | 141 // An implementation of RunMenuAt. This is usually NULL and ignored. If this |
141 // is not NULL, this implementation will be used. | 142 // is not NULL, this implementation will be used. |
142 scoped_ptr<MenuRunnerHandler> runner_handler_; | 143 scoped_ptr<MenuRunnerHandler> runner_handler_; |
143 | 144 |
144 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; | 145 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; |
145 | 146 |
146 DISALLOW_COPY_AND_ASSIGN(MenuRunner); | 147 DISALLOW_COPY_AND_ASSIGN(MenuRunner); |
147 }; | 148 }; |
148 | 149 |
149 namespace internal { | 150 namespace internal { |
150 | 151 |
151 // DisplayChangeListener is intended to listen for changes in the display size | 152 // DisplayChangeListener is intended to listen for changes in the display size |
152 // and cancel the menu. DisplayChangeListener is created when the menu is | 153 // and cancel the menu. DisplayChangeListener is created when the menu is |
153 // shown. | 154 // shown. |
154 class DisplayChangeListener { | 155 class DisplayChangeListener { |
155 public: | 156 public: |
156 virtual ~DisplayChangeListener() {} | 157 virtual ~DisplayChangeListener() {} |
157 | 158 |
158 // Creates the platform specified DisplayChangeListener, or NULL if there | 159 // Creates the platform specified DisplayChangeListener, or NULL if there |
159 // isn't one. Caller owns the returned value. | 160 // isn't one. Caller owns the returned value. |
160 static DisplayChangeListener* Create(Widget* parent, | 161 static DisplayChangeListener* Create(Widget* parent, |
161 MenuRunner* runner); | 162 MenuRunner* runner); |
162 | 163 |
163 protected: | 164 protected: |
164 DisplayChangeListener() {} | 165 DisplayChangeListener() {} |
165 }; | 166 }; |
166 | 167 |
167 } | 168 } // namespace internal |
168 | 169 |
169 } // namespace views | 170 } // namespace views |
170 | 171 |
171 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 172 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
OLD | NEW |