Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / controls / menu / menu_2.h
blob9c857b285b0a08d366dbbb70a28a36e7ec1e922b
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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_2_H_
6 #define UI_VIEWS_CONTROLS_MENU_MENU_2_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/controls/menu/menu_wrapper.h"
12 #include "ui/views/views_export.h"
14 namespace gfx {
15 class Point;
18 namespace ui {
19 class MenuModel;
22 namespace views {
24 // A menu. Populated from a model, and relies on a delegate to execute commands.
26 // WARNING: do NOT create and use Menu2 on the stack. Menu2 notifies the model
27 // of selection AFTER a delay. This means that if use a Menu2 on the stack
28 // ActivatedAt is never invoked.
29 class VIEWS_EXPORT Menu2 {
30 public:
31 // How the menu is aligned relative to the point it is shown at.
32 // The alignment is reversed by menu if text direction is right to left.
33 enum Alignment {
34 ALIGN_TOPLEFT,
35 ALIGN_TOPRIGHT
38 // Creates a new menu populated with the contents of |model|.
39 // WARNING: this populates the menu on construction by invoking methods on
40 // the model. As such, it is typically not safe to use this as the model
41 // from the constructor. EG:
42 // MyClass : menu_(this) {}
43 // is likely to have problems.
44 explicit Menu2(ui::MenuModel* model);
45 virtual ~Menu2();
47 // Runs the menu at the specified point. This method blocks until done.
48 // RunContextMenuAt is the same, but the alignment is the default for a
49 // context menu.
50 void RunMenuAt(const gfx::Point& point, Alignment alignment);
51 void RunContextMenuAt(const gfx::Point& point);
53 // Cancels the active menu.
54 void CancelMenu();
56 // Called when the model supplying data to this menu has changed, and the menu
57 // must be rebuilt.
58 void Rebuild();
60 // Called when the states of the menu items in the menu should be refreshed
61 // from the model.
62 void UpdateStates();
64 // For submenus.
65 HMENU GetNativeMenu() const;
67 // Get the result of the last call to RunMenuAt to determine whether an
68 // item was selected, the user navigated to a next or previous menu, or
69 // nothing.
70 MenuWrapper::MenuAction GetMenuAction() const;
72 // Add a listener to receive a callback when the menu opens.
73 void AddMenuListener(MenuListener* listener);
75 // Remove a menu listener.
76 void RemoveMenuListener(MenuListener* listener);
78 // Accessors.
79 ui::MenuModel* model() const { return model_; }
81 // Sets the minimum width of the menu.
82 void SetMinimumWidth(int width);
84 private:
86 ui::MenuModel* model_;
88 // The object that actually implements the menu.
89 scoped_ptr<MenuWrapper> wrapper_;
91 DISALLOW_COPY_AND_ASSIGN(Menu2);
94 } // namespace views
96 #endif // UI_VIEWS_CONTROLS_MENU_MENU_2_H_