Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7421)

Unified Diff: chrome/browser/ui/gtk/menu_gtk.cc

Issue 6732007: Native menu implementation for bug 5679. Followup to http://codereview.chromium.org/2928005/ Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/menu_gtk.cc
diff --git a/chrome/browser/ui/gtk/menu_gtk.cc b/chrome/browser/ui/gtk/menu_gtk.cc
index 19e4d1264494556eebd6e4a2238be1f6d8c1bf55..189070cb17e6bf6d3c1c1e9d18054122aa62d158 100644
--- a/chrome/browser/ui/gtk/menu_gtk.cc
+++ b/chrome/browser/ui/gtk/menu_gtk.cc
@@ -284,6 +284,7 @@ MenuGtk::MenuGtk(MenuGtk::Delegate* delegate,
DCHECK(model);
g_object_ref_sink(menu_);
ConnectSignalHandlers();
+ model->SetMenuModelDelegate(this);
BuildMenuFromModel();
}
@@ -400,6 +401,10 @@ void MenuGtk::Cancel() {
gtk_menu_popdown(GTK_MENU(menu_));
}
+void MenuGtk::OnIconChanged(int model_index) {
+ gtk_container_foreach(GTK_CONTAINER(menu_), UpdateMenuIcon, &model_index);
+}
+
void MenuGtk::UpdateMenu() {
gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this);
}
@@ -640,6 +645,26 @@ gboolean MenuGtk::OnMenuTryButtonPressed(GtkWidget* menu_item,
}
// static
+void MenuGtk::UpdateMenuIcon(GtkWidget* widget, gpointer userdata) {
+ if (GTK_IS_MENU_ITEM(widget)) {
+ int model_index = *static_cast<int*>(userdata);
+ int menu_id;
+ GetMenuItemID(widget, &menu_id);
+ if (menu_id != model_index) {
+ return;
+ }
+ SkBitmap icon;
+ ui::MenuModel* model = ModelForMenuItem(GTK_MENU_ITEM(widget));
+ if (model->GetIconAt(model_index, &icon)) {
+ GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget),
+ gtk_image_new_from_pixbuf(pixbuf));
+ g_object_unref(pixbuf);
+ }
+ }
+}
+
+// static
void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu,
int* x,
int* y,

Powered by Google App Engine
This is Rietveld 408576698