OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "app/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
10 #include "base/keyboard_codes.h" | 10 #include "base/keyboard_codes.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // NativeMenuGtk, MenuWrapper implementation: | 79 // NativeMenuGtk, MenuWrapper implementation: |
80 | 80 |
81 void NativeMenuGtk::RunMenuAt(const gfx::Point& point, int alignment) { | 81 void NativeMenuGtk::RunMenuAt(const gfx::Point& point, int alignment) { |
82 Position position = { point, static_cast<Menu2::Alignment>(alignment) }; | 82 Position position = { point, static_cast<Menu2::Alignment>(alignment) }; |
83 // TODO(beng): value of '1' will not work for context menus! | 83 // TODO(beng): value of '1' will not work for context menus! |
84 gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, MenuPositionFunc, &position, 1, | 84 gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, MenuPositionFunc, &position, 1, |
85 gtk_get_current_event_time()); | 85 gtk_get_current_event_time()); |
86 | 86 |
87 DCHECK(!menu_shown_); | 87 DCHECK(!menu_shown_); |
88 menu_shown_ = true; | 88 menu_shown_ = true; |
| 89 // Listen for "hide" signal so that we know when to return from the blocking |
| 90 // RunMenuAt call. |
| 91 gint handle_id = |
| 92 g_signal_connect(G_OBJECT(menu_), "hide", G_CALLBACK(OnMenuHidden), this); |
89 | 93 |
90 // Block until menu is no longer shown by running a nested message loop. | 94 // Block until menu is no longer shown by running a nested message loop. |
91 MessageLoopForUI::current()->Run(NULL); | 95 MessageLoopForUI::current()->Run(NULL); |
92 | 96 |
| 97 g_signal_handler_disconnect(G_OBJECT(menu_), handle_id); |
93 menu_shown_ = false; | 98 menu_shown_ = false; |
94 } | 99 } |
95 | 100 |
96 void NativeMenuGtk::CancelMenu() { | 101 void NativeMenuGtk::CancelMenu() { |
97 NOTIMPLEMENTED(); | 102 NOTIMPLEMENTED(); |
98 } | 103 } |
99 | 104 |
100 void NativeMenuGtk::Rebuild() { | 105 void NativeMenuGtk::Rebuild() { |
101 ResetMenu(); | 106 ResetMenu(); |
102 | 107 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 submenu->UpdateStates(); | 221 submenu->UpdateStates(); |
217 } | 222 } |
218 } | 223 } |
219 ++usd->index; | 224 ++usd->index; |
220 } | 225 } |
221 | 226 |
222 void NativeMenuGtk::ResetMenu() { | 227 void NativeMenuGtk::ResetMenu() { |
223 if (menu_) | 228 if (menu_) |
224 gtk_widget_destroy(menu_); | 229 gtk_widget_destroy(menu_); |
225 menu_ = gtk_menu_new(); | 230 menu_ = gtk_menu_new(); |
226 // Listen for "hide" signal so that we know when to return from the blocking | |
227 // RunMenuAt call. | |
228 g_signal_connect(G_OBJECT(menu_), "hide", G_CALLBACK(OnMenuHidden), this); | |
229 } | 231 } |
230 | 232 |
231 // static | 233 // static |
232 void NativeMenuGtk::MenuPositionFunc(GtkMenu* menu, | 234 void NativeMenuGtk::MenuPositionFunc(GtkMenu* menu, |
233 int* x, | 235 int* x, |
234 int* y, | 236 int* y, |
235 gboolean* push_in, | 237 gboolean* push_in, |
236 void* data) { | 238 void* data) { |
237 Position* position = reinterpret_cast<Position*>(data); | 239 Position* position = reinterpret_cast<Position*>(data); |
238 // TODO(beng): RTL | 240 // TODO(beng): RTL |
(...skipping 24 matching lines...) Expand all Loading... |
263 | 265 |
264 //////////////////////////////////////////////////////////////////////////////// | 266 //////////////////////////////////////////////////////////////////////////////// |
265 // MenuWrapper, public: | 267 // MenuWrapper, public: |
266 | 268 |
267 // static | 269 // static |
268 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 270 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
269 return new NativeMenuGtk(menu->model()); | 271 return new NativeMenuGtk(menu->model()); |
270 } | 272 } |
271 | 273 |
272 } // namespace views | 274 } // namespace views |
OLD | NEW |