OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_VIEWS_NATIVE_MENU_WEBUI_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_VIEWS_NATIVE_MENU_WEBUI_H_ | |
7 #pragma once | |
8 | |
9 #include <vector> | |
10 | |
11 #include "base/message_loop.h" | |
12 #include "base/observer_list.h" | |
13 #include "base/scoped_ptr.h" | |
14 #include "chrome/browser/chromeos/webui_menu_control.h" | |
15 #include "googleurl/src/gurl.h" | |
16 #include "views/controls/menu/menu_wrapper.h" | |
17 | |
18 class DictionaryValue; | |
19 class Profile; | |
20 class SkBitmap; | |
21 | |
22 namespace ui { | |
23 class MenuModel; | |
24 } // namespace ui | |
25 | |
26 namespace views { | |
27 class NestedDispatcherGtk; | |
28 } // namespace views; | |
29 | |
30 #if defined(TOUCH_UI) | |
31 typedef union _XEvent XEvent; | |
32 #endif | |
33 | |
34 namespace chromeos { | |
35 | |
36 class MenuLocator; | |
37 class WebUIMenuWidget; | |
38 | |
39 // A WebUI implementation of MenuWrapper. | |
40 class NativeMenuWebUI : public views::MenuWrapper, | |
41 public WebUIMenuControl, | |
42 public MessageLoop::Dispatcher { | |
43 public: | |
44 NativeMenuWebUI(ui::MenuModel* menu_model, bool root); | |
45 virtual ~NativeMenuWebUI(); | |
46 | |
47 // Returns true if menu is currently shown. | |
48 bool is_menu_shown() { return menu_shown_; } | |
49 | |
50 // Set parent menu. | |
51 void set_parent(NativeMenuWebUI* parent) { parent_ = parent; } | |
52 | |
53 // Overridden from views::MenuWrapper: | |
54 virtual void RunMenuAt(const gfx::Point& point, int alignment); | |
55 virtual void CancelMenu(); | |
56 virtual void Rebuild(); | |
57 virtual void UpdateStates(); | |
58 virtual gfx::NativeMenu GetNativeMenu() const; | |
59 virtual MenuAction GetMenuAction() const; | |
60 virtual void AddMenuListener(views::MenuListener* listener); | |
61 virtual void RemoveMenuListener(views::MenuListener* listener); | |
62 virtual void SetMinimumWidth(int width); | |
63 | |
64 // Overridden from MessageLoopForUI::Dispatcher: | |
65 virtual bool Dispatch(GdkEvent* event); | |
66 #if defined(TOUCH_UI) | |
67 virtual base::MessagePumpGlibXDispatcher::DispatchStatus DispatchX( | |
68 XEvent* xevent); | |
69 #endif | |
70 | |
71 // Overridden from WebUIMenuControl: | |
72 virtual ui::MenuModel* GetMenuModel() { return model_; } | |
73 virtual void Activate(ui::MenuModel* model, | |
74 int index, | |
75 ActivationMode activation_mode); | |
76 virtual void CloseAll(); | |
77 virtual void CloseSubmenu(); | |
78 virtual void MoveInputToParent(); | |
79 virtual void MoveInputToSubmenu(); | |
80 virtual void OnLoad(); | |
81 virtual void OpenSubmenu(int index, int y); | |
82 virtual void SetSize(const gfx::Size& size); | |
83 | |
84 // Hide All menu (including submenus). | |
85 void Hide(); | |
86 | |
87 // Returns the root of the menu tree. Returns NULL if it cannot find | |
88 // a root. (i.e. detached from root) | |
89 NativeMenuWebUI* GetRoot(); | |
90 | |
91 // Returns the profile to create DOMView. | |
92 Profile* GetProfile(); | |
93 | |
94 // Called when the menu is ready to accept input. | |
95 // Used in interactive_ui_test to wait for menu opened. | |
96 void InputIsReady(); | |
97 | |
98 // Sets/Gets the url for the WebUI menu. | |
99 void set_menu_url(const GURL& url) { menu_url_ = url; } | |
100 const GURL& menu_url() const { return menu_url_; } | |
101 | |
102 // Sets the menu url of menu2. This has to be called before | |
103 // RunMenuAt/RunContextMenuAt is called. | |
104 static void SetMenuURL(views::Menu2* menu2, const GURL& url); | |
105 | |
106 private: | |
107 // Callback that we should really process the menu activation. | |
108 // See description above class for why we delay processing activation. | |
109 void ProcessActivate(); | |
110 | |
111 // Show the menu using given |locator|. | |
112 void ShowAt(MenuLocator* locator); | |
113 | |
114 // Find a menu object at point. | |
115 NativeMenuWebUI* FindMenuAt(const gfx::Point& point); | |
116 | |
117 // If we're a submenu, this is the parent. | |
118 NativeMenuWebUI* parent_; | |
119 | |
120 // Holds the current submenu. | |
121 scoped_ptr<NativeMenuWebUI> submenu_; | |
122 | |
123 ui::MenuModel* model_; | |
124 | |
125 // A window widget that draws the content of the menu. | |
126 WebUIMenuWidget* menu_widget_; | |
127 | |
128 // True if the menu is currently shown. | |
129 // Used only in root. | |
130 bool menu_shown_; | |
131 | |
132 // If the user selects something from the menu this is the menu they selected | |
133 // it from. When an item is selected menu_activated_ on the root ancestor is | |
134 // set to the menu the user selected and after the nested message loop exits | |
135 // Activate is invoked on this menu. | |
136 ui::MenuModel* activated_menu_; | |
137 | |
138 // The index of the item the user selected. This is set on the | |
139 // actual menu the user selects and not the root. | |
140 int activated_index_; | |
141 | |
142 // The action that took place during the call to RunMenuAt. | |
143 MenuAction menu_action_; | |
144 | |
145 // Vector of listeners to receive callbacks when the menu opens. | |
146 ObserverList<views::MenuListener> listeners_; | |
147 | |
148 // URL to invoke Menu WebUI. Default menu is chrome://menu, but | |
149 // custom menu can use different url using SetMenuURL method | |
150 // (e.g. chrome://wrench-menu for wrench menu). | |
151 GURL menu_url_; | |
152 | |
153 // A guard flag to avoid calling MenuListener::OnMenuOpened twice. | |
154 bool on_menu_opened_called_; | |
155 | |
156 // Nested dispatcher object that can outlive this object. | |
157 // This is to deal with the menu being deleted while the nested | |
158 // message loop is handled. see http://crosbug.com/7929 . | |
159 views::NestedDispatcherGtk* nested_dispatcher_; | |
160 | |
161 DISALLOW_COPY_AND_ASSIGN(NativeMenuWebUI); | |
162 }; | |
163 | |
164 } // namespace chromeos | |
165 | |
166 #endif // CHROME_BROWSER_CHROMEOS_VIEWS_NATIVE_MENU_WEBUI_H_ | |
OLD | NEW |