OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "views/controls/menu/native_menu_gtk.h" | 5 #include "views/controls/menu/native_menu_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DCHECK(!menu_shown_); | 105 DCHECK(!menu_shown_); |
106 menu_shown_ = true; | 106 menu_shown_ = true; |
107 | 107 |
108 for (unsigned int i = 0; i < listeners_.size(); ++i) { | 108 for (unsigned int i = 0; i < listeners_.size(); ++i) { |
109 listeners_[i]->OnMenuOpened(); | 109 listeners_[i]->OnMenuOpened(); |
110 } | 110 } |
111 | 111 |
112 // Listen for "hide" signal so that we know when to return from the blocking | 112 // Listen for "hide" signal so that we know when to return from the blocking |
113 // RunMenuAt call. | 113 // RunMenuAt call. |
114 gint hide_handle_id = | 114 gint hide_handle_id = |
115 g_signal_connect(menu_, "hide", G_CALLBACK(OnMenuHidden), this); | 115 g_signal_connect(menu_, "hide", G_CALLBACK(OnMenuHiddenThunk), this); |
116 | 116 |
117 gint move_handle_id = | 117 gint move_handle_id = |
118 g_signal_connect(menu_, "move-current", G_CALLBACK(OnMenuMoveCurrent), | 118 g_signal_connect(menu_, "move-current", |
119 this); | 119 G_CALLBACK(OnMenuMoveCurrentThunk), this); |
120 | 120 |
121 // Block until menu is no longer shown by running a nested message loop. | 121 // Block until menu is no longer shown by running a nested message loop. |
122 MessageLoopForUI::current()->Run(NULL); | 122 MessageLoopForUI::current()->Run(NULL); |
123 | 123 |
124 g_signal_handler_disconnect(G_OBJECT(menu_), hide_handle_id); | 124 g_signal_handler_disconnect(G_OBJECT(menu_), hide_handle_id); |
125 g_signal_handler_disconnect(G_OBJECT(menu_), move_handle_id); | 125 g_signal_handler_disconnect(G_OBJECT(menu_), move_handle_id); |
126 menu_shown_ = false; | 126 menu_shown_ = false; |
127 | 127 |
128 if (activated_menu_) { | 128 if (activated_menu_) { |
129 MessageLoop::current()->PostTask(FROM_HERE, | 129 MessageLoop::current()->PostTask(FROM_HERE, |
130 activate_factory_.NewRunnableMethod( | 130 activate_factory_.NewRunnableMethod( |
131 &NativeMenuGtk::ProcessActivate)); | 131 &NativeMenuGtk::ProcessActivate)); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 void NativeMenuGtk::CancelMenu() { | 135 void NativeMenuGtk::CancelMenu() { |
136 NOTIMPLEMENTED(); | 136 gtk_widget_hide(menu_); |
137 } | 137 } |
138 | 138 |
139 void NativeMenuGtk::Rebuild() { | 139 void NativeMenuGtk::Rebuild() { |
140 activated_menu_ = NULL; | 140 activated_menu_ = NULL; |
141 | 141 |
142 ResetMenu(); | 142 ResetMenu(); |
143 | 143 |
144 // Try to retrieve accelerator group as data from menu_; if null, create new | 144 // Try to retrieve accelerator group as data from menu_; if null, create new |
145 // one and store it as data into menu_. | 145 // one and store it as data into menu_. |
146 // We store it as data so as to use the destroy notifier to get rid of initial | 146 // We store it as data so as to use the destroy notifier to get rid of initial |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (*iter == listener) { | 201 if (*iter == listener) { |
202 listeners_.erase(iter); | 202 listeners_.erase(iter); |
203 return; | 203 return; |
204 } | 204 } |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 //////////////////////////////////////////////////////////////////////////////// | 208 //////////////////////////////////////////////////////////////////////////////// |
209 // NativeMenuGtk, private: | 209 // NativeMenuGtk, private: |
210 | 210 |
211 // static | 211 void NativeMenuGtk::OnMenuHidden(GtkWidget* widget) { |
212 void NativeMenuGtk::OnMenuHidden(GtkWidget* widget, NativeMenuGtk* menu) { | 212 if (!menu_shown_) { |
213 if (!menu->menu_shown_) { | |
214 // This indicates we don't have a menu open, and should never happen. | 213 // This indicates we don't have a menu open, and should never happen. |
215 NOTREACHED(); | 214 NOTREACHED(); |
216 return; | 215 return; |
217 } | 216 } |
218 // Quit the nested message loop we spawned in RunMenuAt. | 217 // Quit the nested message loop we spawned in RunMenuAt. |
219 MessageLoop::current()->Quit(); | 218 MessageLoop::current()->Quit(); |
220 } | 219 } |
221 | 220 |
222 // static | 221 void NativeMenuGtk::OnMenuMoveCurrent(GtkWidget* menu_widget, |
223 void NativeMenuGtk::OnMenuMoveCurrent(GtkMenu* menu_widget, | 222 GtkMenuDirectionType focus_direction) { |
224 GtkMenuDirectionType focus_direction, | |
225 NativeMenuGtk* menu) { | |
226 GtkWidget* parent = GTK_MENU_SHELL(menu_widget)->parent_menu_shell; | 223 GtkWidget* parent = GTK_MENU_SHELL(menu_widget)->parent_menu_shell; |
227 GtkWidget* menu_item = GTK_MENU_SHELL(menu_widget)->active_menu_item; | 224 GtkWidget* menu_item = GTK_MENU_SHELL(menu_widget)->active_menu_item; |
228 GtkWidget* submenu = NULL; | 225 GtkWidget* submenu = NULL; |
229 if (menu_item) { | 226 if (menu_item) { |
230 submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_item)); | 227 submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_item)); |
231 } | 228 } |
232 | 229 |
233 if (focus_direction == GTK_MENU_DIR_CHILD && submenu == NULL) { | 230 if (focus_direction == GTK_MENU_DIR_CHILD && submenu == NULL) { |
234 menu->GetAncestor()->menu_action_ = MENU_ACTION_NEXT; | 231 GetAncestor()->menu_action_ = MENU_ACTION_NEXT; |
235 gtk_menu_popdown(menu_widget); | 232 gtk_menu_popdown(GTK_MENU(menu_widget)); |
236 } else if (focus_direction == GTK_MENU_DIR_PARENT && parent == NULL) { | 233 } else if (focus_direction == GTK_MENU_DIR_PARENT && parent == NULL) { |
237 menu->GetAncestor()->menu_action_ = MENU_ACTION_PREVIOUS; | 234 GetAncestor()->menu_action_ = MENU_ACTION_PREVIOUS; |
238 gtk_menu_popdown(menu_widget); | 235 gtk_menu_popdown(GTK_MENU(menu_widget)); |
239 } | 236 } |
240 } | 237 } |
241 | 238 |
242 void NativeMenuGtk::AddSeparatorAt(int index) { | 239 void NativeMenuGtk::AddSeparatorAt(int index) { |
243 GtkWidget* separator = gtk_separator_menu_item_new(); | 240 GtkWidget* separator = gtk_separator_menu_item_new(); |
244 gtk_widget_show(separator); | 241 gtk_widget_show(separator); |
245 gtk_menu_append(menu_, separator); | 242 gtk_menu_append(menu_, separator); |
246 } | 243 } |
247 | 244 |
248 GtkWidget* NativeMenuGtk::AddMenuItemAt(int index, | 245 GtkWidget* NativeMenuGtk::AddMenuItemAt(int index, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 463 |
467 //////////////////////////////////////////////////////////////////////////////// | 464 //////////////////////////////////////////////////////////////////////////////// |
468 // MenuWrapper, public: | 465 // MenuWrapper, public: |
469 | 466 |
470 // static | 467 // static |
471 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 468 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
472 return new NativeMenuGtk(menu); | 469 return new NativeMenuGtk(menu); |
473 } | 470 } |
474 | 471 |
475 } // namespace views | 472 } // namespace views |
OLD | NEW |