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" |
11 #include "ui/views/controls/menu/menu_item_view.h" | 11 #include "ui/views/controls/menu/menu_item_view.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 class MenuModel; | 14 class MenuModel; |
15 } | 15 } |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 class MenuButton; | 19 class MenuButton; |
20 class MenuModelAdapter; | 20 class MenuModelAdapter; |
21 class MenuRunnerHandler; | |
21 class Widget; | 22 class Widget; |
22 | 23 |
23 namespace internal { | 24 namespace internal { |
24 class DisplayChangeListener; | 25 class DisplayChangeListener; |
25 class MenuRunnerImpl; | 26 class MenuRunnerImpl; |
26 } | 27 } |
27 | 28 |
29 namespace test { | |
30 class MenuRunnerTestAPI; | |
31 } | |
32 | |
28 // MenuRunner is responsible for showing (running) the menu and additionally | 33 // MenuRunner is responsible for showing (running) the menu and additionally |
29 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe | 34 // owning the MenuItemView. RunMenuAt() runs a nested message loop. It is safe |
30 // to delete MenuRunner at any point, but MenuRunner internally only deletes the | 35 // to delete MenuRunner at any point, but MenuRunner internally only deletes the |
31 // MenuItemView *after* the nested message loop completes. If MenuRunner is | 36 // MenuItemView *after* the nested message loop completes. If MenuRunner is |
32 // deleted while the menu is showing the delegate of the menu is reset. This is | 37 // deleted while the menu is showing the delegate of the menu is reset. This is |
33 // done to ensure delegates aren't notified after they may have been deleted. | 38 // done to ensure delegates aren't notified after they may have been deleted. |
34 // | 39 // |
35 // NOTE: while you can delete a MenuRunner at any point, the nested message loop | 40 // NOTE: while you can delete a MenuRunner at any point, the nested message loop |
36 // won't return immediately. This means if you delete the object that owns | 41 // won't return immediately. This means if you delete the object that owns |
37 // the MenuRunner while the menu is running, your object is effectively still | 42 // the MenuRunner while the menu is running, your object is effectively still |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 // Returns true if we're in a nested message loop running the menu. | 110 // Returns true if we're in a nested message loop running the menu. |
106 bool IsRunning() const; | 111 bool IsRunning() const; |
107 | 112 |
108 // Hides and cancels the menu. This does nothing if the menu is not open. | 113 // Hides and cancels the menu. This does nothing if the menu is not open. |
109 void Cancel(); | 114 void Cancel(); |
110 | 115 |
111 // Returns the time from the event which closed the menu - or 0. | 116 // Returns the time from the event which closed the menu - or 0. |
112 base::TimeDelta closing_event_time() const; | 117 base::TimeDelta closing_event_time() const; |
113 | 118 |
114 private: | 119 private: |
120 friend class test::MenuRunnerTestAPI; | |
121 | |
122 // Sets an implementation of RunMenuAt. This takes the ownership of | |
123 // |runner_handler|. This is intended to be used at test. | |
124 void SetRunnerHandler(MenuRunnerHandler* runner_handler); | |
sky
2013/12/10 16:56:06
scoped_ptr
hajimehoshi
2013/12/11 04:07:04
Done.
| |
125 | |
115 scoped_ptr<MenuModelAdapter> menu_model_adapter_; | 126 scoped_ptr<MenuModelAdapter> menu_model_adapter_; |
116 | 127 |
117 internal::MenuRunnerImpl* holder_; | 128 internal::MenuRunnerImpl* holder_; |
118 | 129 |
130 // An implementation of RunMenuAt. This is usually NULL and ignored. If this | |
131 // is not NULL, this implementation will be used. | |
132 scoped_ptr<MenuRunnerHandler> runner_handler_; | |
133 | |
119 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; | 134 scoped_ptr<internal::DisplayChangeListener> display_change_listener_; |
120 | 135 |
121 DISALLOW_COPY_AND_ASSIGN(MenuRunner); | 136 DISALLOW_COPY_AND_ASSIGN(MenuRunner); |
122 }; | 137 }; |
123 | 138 |
124 namespace internal { | 139 namespace internal { |
125 | 140 |
126 // DisplayChangeListener is intended to listen for changes in the display size | 141 // DisplayChangeListener is intended to listen for changes in the display size |
127 // and cancel the menu. DisplayChangeListener is created when the menu is | 142 // and cancel the menu. DisplayChangeListener is created when the menu is |
128 // shown. | 143 // shown. |
129 class DisplayChangeListener { | 144 class DisplayChangeListener { |
130 public: | 145 public: |
131 virtual ~DisplayChangeListener() {} | 146 virtual ~DisplayChangeListener() {} |
132 | 147 |
133 // Creates the platform specified DisplayChangeListener, or NULL if there | 148 // Creates the platform specified DisplayChangeListener, or NULL if there |
134 // isn't one. Caller owns the returned value. | 149 // isn't one. Caller owns the returned value. |
135 static DisplayChangeListener* Create(Widget* parent, | 150 static DisplayChangeListener* Create(Widget* parent, |
136 MenuRunner* runner); | 151 MenuRunner* runner); |
137 | 152 |
138 protected: | 153 protected: |
139 DisplayChangeListener() {} | 154 DisplayChangeListener() {} |
140 }; | 155 }; |
141 | 156 |
142 } | 157 } |
143 | 158 |
144 } // namespace views | 159 } // namespace views |
145 | 160 |
146 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ | 161 #endif // UI_VIEWS_CONTROLS_MENU_MENU_RUNNER_H_ |
OLD | NEW |