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_NATIVE_MENU_WIN_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_NATIVE_MENU_WIN_H_ |
6 #define UI_VIEWS_CONTROLS_MENU_NATIVE_MENU_WIN_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_NATIVE_MENU_WIN_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
15 #include "base/string16.h" | 14 #include "base/string16.h" |
16 #include "ui/views/controls/menu/menu_wrapper.h" | |
17 #include "ui/views/views_export.h" | 15 #include "ui/views/views_export.h" |
18 | 16 |
| 17 namespace gfx { |
| 18 class Point; |
| 19 } |
| 20 |
19 namespace ui { | 21 namespace ui { |
20 class MenuModel; | 22 class MenuModel; |
21 } | 23 } |
22 | 24 |
23 namespace views { | 25 namespace views { |
24 | 26 |
25 // A Windows implementation of MenuWrapper. | 27 class MenuInsertionDelegate; |
26 // TODO(beng): rename to MenuWin once the old class is dead. | 28 class MenuListener; |
27 class VIEWS_EXPORT NativeMenuWin : public MenuWrapper { | 29 |
| 30 class VIEWS_EXPORT NativeMenuWin { |
28 public: | 31 public: |
| 32 // All of the possible actions that can result from RunMenuAt. |
| 33 enum MenuAction { |
| 34 MENU_ACTION_NONE, // Menu cancelled, or never opened. |
| 35 MENU_ACTION_SELECTED, // An item was selected. |
| 36 MENU_ACTION_PREVIOUS, // User wants to navigate to the previous menu. |
| 37 MENU_ACTION_NEXT, // User wants to navigate to the next menu. |
| 38 }; |
| 39 |
| 40 // How the menu is aligned relative to the point it is shown at. |
| 41 // The alignment is reversed by menu if text direction is right to left. |
| 42 enum Alignment { |
| 43 ALIGN_TOPLEFT, |
| 44 ALIGN_TOPRIGHT |
| 45 }; |
| 46 |
29 // Construct a NativeMenuWin, with a model and delegate. If |system_menu_for| | 47 // Construct a NativeMenuWin, with a model and delegate. If |system_menu_for| |
30 // is non-NULL, the NativeMenuWin wraps the system menu for that window. | 48 // is non-NULL, the NativeMenuWin wraps the system menu for that window. |
31 // The caller owns the model and the delegate. | 49 // The caller owns the model and the delegate. |
32 NativeMenuWin(ui::MenuModel* model, HWND system_menu_for); | 50 NativeMenuWin(ui::MenuModel* model, HWND system_menu_for); |
33 virtual ~NativeMenuWin(); | 51 ~NativeMenuWin(); |
34 | 52 |
35 // Overridden from MenuWrapper: | 53 void RunMenuAt(const gfx::Point& point, int alignment); |
36 virtual void RunMenuAt(const gfx::Point& point, int alignment) OVERRIDE; | 54 void CancelMenu(); |
37 virtual void CancelMenu() OVERRIDE; | 55 void Rebuild(MenuInsertionDelegate* delegate); |
38 virtual void Rebuild(InsertionDelegate* delegate) OVERRIDE; | 56 void UpdateStates(); |
39 virtual void UpdateStates() OVERRIDE; | 57 HMENU GetNativeMenu() const; |
40 virtual HMENU GetNativeMenu() const OVERRIDE; | 58 MenuAction GetMenuAction() const; |
41 virtual MenuAction GetMenuAction() const OVERRIDE; | 59 void AddMenuListener(MenuListener* listener); |
42 virtual void AddMenuListener(MenuListener* listener) OVERRIDE; | 60 void RemoveMenuListener(MenuListener* listener); |
43 virtual void RemoveMenuListener(MenuListener* listener) OVERRIDE; | 61 void SetMinimumWidth(int width); |
44 virtual void SetMinimumWidth(int width) OVERRIDE; | |
45 | 62 |
46 private: | 63 private: |
47 // IMPORTANT: Note about indices. | 64 // IMPORTANT: Note about indices. |
48 // Functions in this class deal in two index spaces: | 65 // Functions in this class deal in two index spaces: |
49 // 1. menu_index - the index of an item within the actual Windows | 66 // 1. menu_index - the index of an item within the actual Windows |
50 // native menu. | 67 // native menu. |
51 // 2. model_index - the index of the item within our model. | 68 // 2. model_index - the index of the item within our model. |
52 // These two are most often but not always the same value! The | 69 // These two are most often but not always the same value! The |
53 // notable exception is when this object is used to wrap the | 70 // notable exception is when this object is used to wrap the |
54 // Windows System Menu. In this instance, the model indices start | 71 // Windows System Menu. In this instance, the model indices start |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // has a menu open, because our hook function that receives keyboard | 177 // has a menu open, because our hook function that receives keyboard |
161 // events doesn't have a mechanism to get a user data pointer. | 178 // events doesn't have a mechanism to get a user data pointer. |
162 static NativeMenuWin* open_native_menu_win_; | 179 static NativeMenuWin* open_native_menu_win_; |
163 | 180 |
164 DISALLOW_COPY_AND_ASSIGN(NativeMenuWin); | 181 DISALLOW_COPY_AND_ASSIGN(NativeMenuWin); |
165 }; | 182 }; |
166 | 183 |
167 } // namespace views | 184 } // namespace views |
168 | 185 |
169 #endif // UI_VIEWS_CONTROLS_MENU_NATIVE_MENU_WIN_H_ | 186 #endif // UI_VIEWS_CONTROLS_MENU_NATIVE_MENU_WIN_H_ |
OLD | NEW |