Changeset 73703 in webkit
- Timestamp:
- Dec 10, 2010 2:31:15 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r73640 r73703 1 2010-12-10 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Simplify context-menu handling code 6 https://bugs.webkit.org/show_bug.cgi?id=49658 7 8 * wtf/PlatformRefPtr.h: 9 1 10 2010-12-09 Michael Saboff <msaboff@apple.com> 2 11 -
trunk/JavaScriptCore/wtf/PlatformRefPtr.h
r71148 r73703 73 73 if (ptr) 74 74 derefPlatformPtr(ptr); 75 } 76 77 T* leakRef() WARN_UNUSED_RETURN 78 { 79 T* ptr = m_ptr; 80 m_ptr = 0; 81 return ptr; 75 82 } 76 83 -
trunk/WebCore/ChangeLog
r73700 r73703 1 2010-12-10 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Simplify context-menu handling code 6 https://bugs.webkit.org/show_bug.cgi?id=49658 7 8 * platform/ContextMenuItem.h: 9 * platform/gtk/ContextMenuGtk.cpp: 10 (WebCore::ContextMenu::appendItem): 11 * platform/gtk/ContextMenuItemGtk.cpp: 12 (WebCore::ContextMenuItem::ContextMenuItem): 13 (WebCore::ContextMenuItem::~ContextMenuItem): 14 (WebCore::ContextMenuItem::releasePlatformDescription): 15 (WebCore::ContextMenuItem::type): 16 (WebCore::ContextMenuItem::setType): 17 (WebCore::ContextMenuItem::action): 18 (WebCore::ContextMenuItem::setAction): 19 (WebCore::ContextMenuItem::title): 20 (WebCore::ContextMenuItem::setTitle): 21 (WebCore::ContextMenuItem::platformSubMenu): 22 (WebCore::ContextMenuItem::setSubMenu): 23 (WebCore::ContextMenuItem::setChecked): 24 (WebCore::ContextMenuItem::setEnabled): 25 1 26 2010-12-10 Philippe Normand <pnormand@igalia.com> 2 27 -
trunk/WebCore/platform/ContextMenuItem.h
r71682 r73703 43 43 typedef struct tagMENUITEMINFOW* LPMENUITEMINFO; 44 44 #elif PLATFORM(GTK) 45 #include <GRefPtr.h> 45 46 typedef struct _GtkMenuItem GtkMenuItem; 46 47 #elif PLATFORM(QT) … … 186 187 }; 187 188 #elif PLATFORM(GTK) 188 struct PlatformMenuItemDescription { 189 PlatformMenuItemDescription() 190 : type(ActionType) 191 , action(ContextMenuItemTagNoAction) 192 , subMenu(0) 193 , checked(false) 194 , enabled(true) 195 {} 196 197 ContextMenuItemType type; 198 ContextMenuAction action; 199 String title; 200 GtkMenu* subMenu; 201 bool checked; 202 bool enabled; 203 }; 189 typedef GtkMenuItem* PlatformMenuItemDescription; 204 190 #elif PLATFORM(WX) 205 191 struct PlatformMenuItemDescription { … … 261 247 ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked); 262 248 ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems); 263 #if PLATFORM(GTK) 264 ContextMenuItem(GtkMenuItem*); 265 #endif 249 266 250 ~ContextMenuItem(); 267 251 … … 288 272 289 273 // FIXME: Do we need a keyboard accelerator here? 290 #if PLATFORM(GTK)291 static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);292 #endif293 274 294 275 private: 295 276 #if PLATFORM(MAC) 296 277 RetainPtr<NSMenuItem> m_platformDescription; 278 #elif PLATFORM(GTK) 279 PlatformRefPtr<GtkMenuItem> m_platformDescription; 297 280 #else 298 281 PlatformMenuItemDescription m_platformDescription; -
trunk/WebCore/platform/gtk/ContextMenuGtk.cpp
r73535 r73703 41 41 ASSERT(m_platformDescription); 42 42 43 GtkMenuItem* platformItem = ContextMenuItem::createNativeMenuItem(item.releasePlatformDescription());43 GtkMenuItem* platformItem = item.releasePlatformDescription(); 44 44 ASSERT(platformItem); 45 45 gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem)); -
trunk/WebCore/platform/gtk/ContextMenuItemGtk.cpp
r67928 r73703 19 19 20 20 #include "config.h" 21 #include "ContextMenuItem.h" 22 21 23 #include "ContextMenu.h" 22 #include " ContextMenuItem.h"24 #include "GOwnPtr.h" 23 25 #include "NotImplemented.h" 26 #include <gtk/gtk.h> 24 27 #include <wtf/text/CString.h> 25 26 #include <gtk/gtk.h>27 28 28 29 #define WEBKIT_CONTEXT_MENU_ACTION "webkit-context-menu" … … 115 116 116 117 // Extract the ActionType from the menu item 117 ContextMenuItem::ContextMenuItem(GtkMenuItem* item) 118 : m_platformDescription() 119 { 120 if (GTK_IS_SEPARATOR_MENU_ITEM(item)) 121 m_platformDescription.type = SeparatorType; 122 else if (gtk_menu_item_get_submenu(item)) 123 m_platformDescription.type = SubmenuType; 124 else if (GTK_IS_CHECK_MENU_ITEM(item)) { 125 m_platformDescription.type = CheckableActionType; 126 m_platformDescription.checked = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)); 127 } else 128 m_platformDescription.type = ActionType; 129 #if GTK_CHECK_VERSION (2, 16, 0) 130 m_platformDescription.title = String::fromUTF8(gtk_menu_item_get_label(GTK_MENU_ITEM(item))); 131 #else 132 GtkWidget* label = gtk_bin_get_child(GTK_BIN(item)); 133 m_platformDescription.title = String::fromUTF8(gtk_label_get_label(GTK_LABEL(label))); 134 #endif 135 136 m_platformDescription.action = *static_cast<ContextMenuAction*>(g_object_get_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION)); 137 138 m_platformDescription.subMenu = GTK_MENU(gtk_menu_item_get_submenu(item)); 139 if (m_platformDescription.subMenu) 140 g_object_ref(m_platformDescription.subMenu); 118 ContextMenuItem::ContextMenuItem(PlatformMenuItemDescription item) 119 : m_platformDescription(item) 120 { 141 121 } 142 122 … … 148 128 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu) 149 129 { 150 m_platformDescription.type = type; 151 m_platformDescription.action = action; 152 m_platformDescription.title = title; 153 154 setSubMenu(subMenu); 130 if (type == SeparatorType) { 131 m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new()); 132 return; 133 } 134 135 GOwnPtr<char> actionName(g_strdup_printf("context-menu-action-%d", action)); 136 GtkAction* platformAction = 0; 137 138 if (type == ActionType) 139 platformAction = gtk_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action)); 140 else if (type == CheckableActionType) 141 platformAction = GTK_ACTION(gtk_toggle_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action))); 142 143 m_platformDescription = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction)); 144 g_object_unref(platformAction); 145 146 g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action)); 147 148 if (subMenu) 149 setSubMenu(subMenu); 155 150 } 156 151 157 152 ContextMenuItem::~ContextMenuItem() 158 153 { 159 if (m_platformDescription.subMenu)160 g_object_unref(m_platformDescription.subMenu);161 }162 163 GtkMenuItem* ContextMenuItem::createNativeMenuItem(const PlatformMenuItemDescription& menu)164 {165 GtkMenuItem* item = 0;166 if (menu.type == SeparatorType)167 item = GTK_MENU_ITEM(gtk_separator_menu_item_new());168 else {169 if (menu.type == CheckableActionType) {170 item = GTK_MENU_ITEM(gtk_check_menu_item_new_with_mnemonic(menu.title.utf8().data()));171 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), menu.checked);172 } else {173 if (const gchar* stockID = gtkStockIDFromContextMenuAction(menu.action)) {174 item = GTK_MENU_ITEM(gtk_image_menu_item_new_with_mnemonic(menu.title.utf8().data()));175 GtkWidget* image = gtk_image_new_from_stock(stockID, GTK_ICON_SIZE_MENU);176 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);177 } else178 item = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(menu.title.utf8().data()));179 }180 181 ContextMenuAction* menuAction = static_cast<ContextMenuAction*>(malloc(sizeof(ContextMenuAction*)));182 *menuAction = menu.action;183 g_object_set_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION, menuAction);184 185 gtk_widget_set_sensitive(GTK_WIDGET(item), menu.enabled);186 187 if (menu.subMenu)188 gtk_menu_item_set_submenu(item, GTK_WIDGET(menu.subMenu));189 }190 191 return item;192 154 } 193 155 194 156 PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription() 195 157 { 196 PlatformMenuItemDescription description = m_platformDescription; 197 m_platformDescription = PlatformMenuItemDescription(); 198 return description; 158 return m_platformDescription.leakRef(); 199 159 } 200 160 201 161 ContextMenuItemType ContextMenuItem::type() const 202 162 { 203 return m_platformDescription.type; 163 if (GTK_IS_SEPARATOR_MENU_ITEM(m_platformDescription.get())) 164 return SeparatorType; 165 if (GTK_IS_CHECK_MENU_ITEM(m_platformDescription.get())) 166 return CheckableActionType; 167 if (gtk_menu_item_get_submenu(m_platformDescription.get())) 168 return SubmenuType; 169 return ActionType; 204 170 } 205 171 206 172 void ContextMenuItem::setType(ContextMenuItemType type) 207 173 { 208 m_platformDescription.type = type; 174 if (type == SeparatorType) 175 m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new()); 209 176 } 210 177 211 178 ContextMenuAction ContextMenuItem::action() const 212 179 { 213 return m_platformDescription.action;180 return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION))); 214 181 } 215 182 216 183 void ContextMenuItem::setAction(ContextMenuAction action) 217 184 { 218 m_platformDescription.action = action;185 g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action)); 219 186 } 220 187 221 188 String ContextMenuItem::title() const 222 189 { 223 return m_platformDescription.title; 190 GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get())); 191 return action ? String(gtk_action_get_label(action)) : String(); 224 192 } 225 193 226 194 void ContextMenuItem::setTitle(const String& title) 227 195 { 228 m_platformDescription.title = title; 196 GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get())); 197 if (action) 198 gtk_action_set_label(action, title.utf8().data()); 229 199 } 230 200 231 201 PlatformMenuDescription ContextMenuItem::platformSubMenu() const 232 202 { 233 return m_platformDescription.subMenu; 203 GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription.get()); 204 return subMenu ? GTK_MENU(subMenu) : 0; 234 205 } 235 206 236 207 void ContextMenuItem::setSubMenu(ContextMenu* menu) 237 208 { 238 if (m_platformDescription.subMenu) 239 g_object_unref(m_platformDescription.subMenu); 240 241 if (!menu) 242 return; 243 244 m_platformDescription.subMenu = menu->releasePlatformDescription(); 245 m_platformDescription.type = SubmenuType; 246 247 g_object_ref_sink(G_OBJECT(m_platformDescription.subMenu)); 209 gtk_menu_item_set_submenu(m_platformDescription.get(), GTK_WIDGET(menu->platformDescription())); 248 210 } 249 211 250 212 void ContextMenuItem::setChecked(bool shouldCheck) 251 213 { 252 m_platformDescription.checked = shouldCheck; 214 GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get())); 215 if (action && GTK_IS_TOGGLE_ACTION(action)) 216 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), shouldCheck); 253 217 } 254 218 255 219 void ContextMenuItem::setEnabled(bool shouldEnable) 256 220 { 257 m_platformDescription.enabled = shouldEnable; 258 } 259 260 } 221 GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get())); 222 if (action) 223 gtk_action_set_sensitive(action, shouldEnable); 224 } 225 226 }
Note: See TracChangeset
for help on using the changeset viewer.