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

Unified Diff: chrome/browser/tab_contents/render_view_context_menu_gtk.cc

Issue 7713033: Integrate the Spelling service to Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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/tab_contents/render_view_context_menu_gtk.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu_gtk.cc (revision 99616)
+++ chrome/browser/tab_contents/render_view_context_menu_gtk.cc (working copy)
@@ -7,6 +7,7 @@
#include <gtk/gtk.h>
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
@@ -16,6 +17,60 @@
#include "ui/gfx/gtk_util.h"
#include "webkit/glue/context_menu.h"
+namespace {
+
+// A callback function for gtk_container_foreach(). This callback just checks
+// the menu ID and set the given user data if it is same as the specified ID.
+struct GtkWidgetAtParam {
+ int index;
+ GtkWidget* widget;
+};
+
+void GtkWidgetAt(GtkWidget* widget, gpointer user_data) {
+ GtkWidgetAtParam* param = reinterpret_cast<GtkWidgetAtParam*>(user_data);
+
+ gpointer data = g_object_get_data(G_OBJECT(widget), "menu-id");
+ if (data && (GPOINTER_TO_INT(data) - 1) == param->index &&
+ GTK_IS_MENU_ITEM(widget)) {
+ param->widget = widget;
+ }
+}
+
+// Retrieves a GtkWidget which has the specified command_id. This function
+// traverses the given |model| in the depth-first order. When this function
+// finds an item whose command_id is the same as the given |command_id|, it
+// returns the GtkWidget associated with the item. This function emulates
+// views::MenuItemViews::GetMenuItemByID() for GTK.
+GtkWidget* GetMenuItemByID(ui::MenuModel* model,
+ GtkWidget* menu,
+ int command_id) {
+ if (!menu)
+ return NULL;
+
+ for (int i = 0; i < model->GetItemCount(); ++i) {
+ if (model->GetCommandIdAt(i) == command_id) {
+ GtkWidgetAtParam param;
+ param.index = i;
+ param.widget = NULL;
+ gtk_container_foreach(GTK_CONTAINER(menu), &GtkWidgetAt, &param);
+ return param.widget;
+ }
+
+ ui::MenuModel* submenu = model->GetSubmenuModelAt(i);
+ if (submenu) {
+ GtkWidget* subitem = GetMenuItemByID(
+ submenu,
+ gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu)),
+ command_id);
+ if (subitem)
+ return subitem;
+ }
+ }
+ return NULL;
+}
+
+} // namespace
+
RenderViewContextMenuGtk::RenderViewContextMenuGtk(
TabContents* web_contents,
const ContextMenuParams& params,
@@ -70,3 +125,16 @@
return command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST;
}
+
+void RenderViewContextMenuGtk::UpdateMenuItem(int command_id,
+ bool enabled,
+ const string16& title) {
+ GtkWidget* item = GetMenuItemByID(&menu_model_, menu_gtk_->widget(),
+ command_id);
+ if (!item || !GTK_IS_MENU_ITEM(item))
+ return;
+
+ // Enable (or disable) the menu item and updates its text.
+ gtk_widget_set_sensitive(item, enabled);
+ gtk_menu_item_set_label(GTK_MENU_ITEM(item), UTF16ToUTF8(title).c_str());
+}
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_gtk.h ('k') | chrome/browser/tab_contents/render_view_context_menu_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698