OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 5 #ifndef VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
6 #define VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 6 #define VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace views { | 26 namespace views { |
27 | 27 |
28 class DropTargetEvent; | 28 class DropTargetEvent; |
29 class MenuButton; | 29 class MenuButton; |
30 class MenuHostRootView; | 30 class MenuHostRootView; |
31 class MouseEvent; | 31 class MouseEvent; |
32 class SubmenuView; | 32 class SubmenuView; |
33 class View; | 33 class View; |
34 | 34 |
| 35 namespace internal { |
| 36 class MenuControllerDelegate; |
| 37 class MenuRunnerImpl; |
| 38 } |
| 39 |
35 // MenuController ------------------------------------------------------------- | 40 // MenuController ------------------------------------------------------------- |
36 | 41 |
37 // MenuController is used internally by the various menu classes to manage | 42 // MenuController is used internally by the various menu classes to manage |
38 // showing, selecting and drag/drop for menus. All relevant events are | 43 // showing, selecting and drag/drop for menus. All relevant events are |
39 // forwarded to the MenuController from SubmenuView and MenuHost. | 44 // forwarded to the MenuController from SubmenuView and MenuHost. |
40 class VIEWS_EXPORT MenuController : public MessageLoop::Dispatcher { | 45 class VIEWS_EXPORT MenuController : public MessageLoop::Dispatcher { |
41 public: | 46 public: |
42 friend class MenuHostRootView; | |
43 friend class MenuItemView; | |
44 friend class SubmenuView; | |
45 | |
46 // Enumeration of how the menu should exit. | 47 // Enumeration of how the menu should exit. |
47 enum ExitType { | 48 enum ExitType { |
48 // Don't exit. | 49 // Don't exit. |
49 EXIT_NONE, | 50 EXIT_NONE, |
50 | 51 |
51 // All menus, including nested, should be exited. | 52 // All menus, including nested, should be exited. |
52 EXIT_ALL, | 53 EXIT_ALL, |
53 | 54 |
54 // Only the outermost menu should be exited. | 55 // Only the outermost menu should be exited. |
55 EXIT_OUTERMOST, | 56 EXIT_OUTERMOST, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 116 |
116 // Invoked from the scroll buttons of the MenuScrollViewContainer. | 117 // Invoked from the scroll buttons of the MenuScrollViewContainer. |
117 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); | 118 void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); |
118 void OnDragExitedScrollButton(SubmenuView* source); | 119 void OnDragExitedScrollButton(SubmenuView* source); |
119 | 120 |
120 // Invoked once for any Widget activation change. This allows the menu | 121 // Invoked once for any Widget activation change. This allows the menu |
121 // to be canceled if the window manager changes the active window. | 122 // to be canceled if the window manager changes the active window. |
122 void OnWidgetActivationChanged(); | 123 void OnWidgetActivationChanged(); |
123 | 124 |
124 private: | 125 private: |
| 126 friend class internal::MenuRunnerImpl; |
| 127 friend class MenuHostRootView; |
| 128 friend class MenuItemView; |
| 129 friend class SubmenuView; |
| 130 |
125 class MenuScrollTask; | 131 class MenuScrollTask; |
126 | 132 |
127 struct SelectByCharDetails; | 133 struct SelectByCharDetails; |
128 | 134 |
129 // Values supplied to SetSelection. | 135 // Values supplied to SetSelection. |
130 enum SetSelectionTypes { | 136 enum SetSelectionTypes { |
131 SELECTION_DEFAULT = 0, | 137 SELECTION_DEFAULT = 0, |
132 | 138 |
133 // If set submenus are opened immediately, otherwise submenus are only | 139 // If set submenus are opened immediately, otherwise submenus are only |
134 // openned after a timer fires. | 140 // openned after a timer fires. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 208 |
203 // Sets the selection to menu_item a value of NULL unselects | 209 // Sets the selection to menu_item a value of NULL unselects |
204 // everything. |types| is a bitmask of |SetSelectionTypes|. | 210 // everything. |types| is a bitmask of |SetSelectionTypes|. |
205 // | 211 // |
206 // Internally this updates pending_state_ immediatley. state_ is only updated | 212 // Internally this updates pending_state_ immediatley. state_ is only updated |
207 // immediately if SELECTION_UPDATE_IMMEDIATELY is set. If | 213 // immediately if SELECTION_UPDATE_IMMEDIATELY is set. If |
208 // SELECTION_UPDATE_IMMEDIATELY is not set CommitPendingSelection is invoked | 214 // SELECTION_UPDATE_IMMEDIATELY is not set CommitPendingSelection is invoked |
209 // to show/hide submenus and update state_. | 215 // to show/hide submenus and update state_. |
210 void SetSelection(MenuItemView* menu_item, int types); | 216 void SetSelection(MenuItemView* menu_item, int types); |
211 | 217 |
212 // Sets the active MenuController. | |
213 static void SetActiveInstance(MenuController* controller); | |
214 | |
215 #if defined(OS_WIN) | 218 #if defined(OS_WIN) |
216 // Dispatcher method. This returns true if the menu was canceled, or | 219 // Dispatcher method. This returns true if the menu was canceled, or |
217 // if the message is such that the menu should be closed. | 220 // if the message is such that the menu should be closed. |
218 virtual bool Dispatch(const MSG& msg); | 221 virtual bool Dispatch(const MSG& msg); |
219 #elif defined(TOUCH_UI) | 222 #elif defined(TOUCH_UI) |
220 virtual base::MessagePumpDispatcher::DispatchStatus Dispatch(XEvent* xevent); | 223 virtual base::MessagePumpDispatcher::DispatchStatus Dispatch(XEvent* xevent); |
221 #else | 224 #else |
222 virtual bool Dispatch(GdkEvent* event); | 225 virtual bool Dispatch(GdkEvent* event); |
223 #endif | 226 #endif |
224 | 227 |
225 // Key processing. The return value of this is returned from Dispatch. | 228 // Key processing. The return value of this is returned from Dispatch. |
226 // In other words, if this returns false (which happens if escape was | 229 // In other words, if this returns false (which happens if escape was |
227 // pressed, or a matching mnemonic was found) the message loop returns. | 230 // pressed, or a matching mnemonic was found) the message loop returns. |
228 #if defined(OS_WIN) | 231 #if defined(OS_WIN) |
229 bool OnKeyDown(int key_code, const MSG& msg); | 232 bool OnKeyDown(int key_code, const MSG& msg); |
230 #else | 233 #else |
231 bool OnKeyDown(int key_code); | 234 bool OnKeyDown(int key_code); |
232 #endif | 235 #endif |
233 | 236 |
234 // Creates a MenuController. If blocking is true, Run blocks the caller | 237 // Creates a MenuController. If |blocking| is true a nested message loop is |
235 explicit MenuController(bool blocking); | 238 // started in |Run|. |
| 239 MenuController(bool blocking, internal::MenuControllerDelegate* delegate); |
236 | 240 |
237 virtual ~MenuController(); | 241 virtual ~MenuController(); |
238 | 242 |
239 // If there is a hot tracked view AcceleratorPressed is invoked on it and | 243 // If there is a hot tracked view AcceleratorPressed is invoked on it and |
240 // true is returned. | 244 // true is returned. |
241 bool SendAcceleratorToHotTrackedView(); | 245 bool SendAcceleratorToHotTrackedView(); |
242 | 246 |
243 void UpdateInitialLocation(const gfx::Rect& bounds, | 247 void UpdateInitialLocation(const gfx::Rect& bounds, |
244 MenuItemView::AnchorPosition position); | 248 MenuItemView::AnchorPosition position); |
245 | 249 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 // Task for scrolling the menu. If non-null indicates a scroll is currently | 491 // Task for scrolling the menu. If non-null indicates a scroll is currently |
488 // underway. | 492 // underway. |
489 scoped_ptr<MenuScrollTask> scroll_task_; | 493 scoped_ptr<MenuScrollTask> scroll_task_; |
490 | 494 |
491 MenuButton* menu_button_; | 495 MenuButton* menu_button_; |
492 | 496 |
493 // If non-null mouse drag events are forwarded to this view. See | 497 // If non-null mouse drag events are forwarded to this view. See |
494 // UpdateActiveMouseView for details. | 498 // UpdateActiveMouseView for details. |
495 View* active_mouse_view_; | 499 View* active_mouse_view_; |
496 | 500 |
| 501 internal::MenuControllerDelegate* delegate_; |
| 502 |
497 DISALLOW_COPY_AND_ASSIGN(MenuController); | 503 DISALLOW_COPY_AND_ASSIGN(MenuController); |
498 }; | 504 }; |
499 | 505 |
500 } // namespace views | 506 } // namespace views |
501 | 507 |
502 #endif // VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ | 508 #endif // VIEWS_CONTROLS_MENU_MENU_CONTROLLER_H_ |
OLD | NEW |