[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da
mrobinson at webkit.org
mrobinson at webkit.org
Wed Dec 22 18:22:49 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit feabe044f71c0f5c9febc06dd8ce3fe1ee529eeb
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Dec 10 10:31:15 2010 +0000
2010-12-10 Carlos Garcia Campos <cgarcia at igalia.com>
Reviewed by Martin Robinson.
[GTK] Simplify context-menu handling code
https://bugs.webkit.org/show_bug.cgi?id=49658
* wtf/PlatformRefPtr.h:
2010-12-10 Carlos Garcia Campos <cgarcia at igalia.com>
Reviewed by Martin Robinson.
[GTK] Simplify context-menu handling code
https://bugs.webkit.org/show_bug.cgi?id=49658
* platform/ContextMenuItem.h:
* platform/gtk/ContextMenuGtk.cpp:
(WebCore::ContextMenu::appendItem):
* platform/gtk/ContextMenuItemGtk.cpp:
(WebCore::ContextMenuItem::ContextMenuItem):
(WebCore::ContextMenuItem::~ContextMenuItem):
(WebCore::ContextMenuItem::releasePlatformDescription):
(WebCore::ContextMenuItem::type):
(WebCore::ContextMenuItem::setType):
(WebCore::ContextMenuItem::action):
(WebCore::ContextMenuItem::setAction):
(WebCore::ContextMenuItem::title):
(WebCore::ContextMenuItem::setTitle):
(WebCore::ContextMenuItem::platformSubMenu):
(WebCore::ContextMenuItem::setSubMenu):
(WebCore::ContextMenuItem::setChecked):
(WebCore::ContextMenuItem::setEnabled):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73703 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 8a483d3..b839134 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,12 @@
+2010-12-10 Carlos Garcia Campos <cgarcia at igalia.com>
+
+ Reviewed by Martin Robinson.
+
+ [GTK] Simplify context-menu handling code
+ https://bugs.webkit.org/show_bug.cgi?id=49658
+
+ * wtf/PlatformRefPtr.h:
+
2010-12-09 Michael Saboff <msaboff at apple.com>
Reviewed by Gavin Barraclough.
diff --git a/JavaScriptCore/wtf/PlatformRefPtr.h b/JavaScriptCore/wtf/PlatformRefPtr.h
index 8ac16cb..e4f1314 100644
--- a/JavaScriptCore/wtf/PlatformRefPtr.h
+++ b/JavaScriptCore/wtf/PlatformRefPtr.h
@@ -74,6 +74,13 @@ public:
derefPlatformPtr(ptr);
}
+ T* leakRef() WARN_UNUSED_RETURN
+ {
+ T* ptr = m_ptr;
+ m_ptr = 0;
+ return ptr;
+ }
+
// Hash table deleted values, which are only constructed and never copied or destroyed.
PlatformRefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 92179ec..a5bcc27 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2010-12-10 Carlos Garcia Campos <cgarcia at igalia.com>
+
+ Reviewed by Martin Robinson.
+
+ [GTK] Simplify context-menu handling code
+ https://bugs.webkit.org/show_bug.cgi?id=49658
+
+ * platform/ContextMenuItem.h:
+ * platform/gtk/ContextMenuGtk.cpp:
+ (WebCore::ContextMenu::appendItem):
+ * platform/gtk/ContextMenuItemGtk.cpp:
+ (WebCore::ContextMenuItem::ContextMenuItem):
+ (WebCore::ContextMenuItem::~ContextMenuItem):
+ (WebCore::ContextMenuItem::releasePlatformDescription):
+ (WebCore::ContextMenuItem::type):
+ (WebCore::ContextMenuItem::setType):
+ (WebCore::ContextMenuItem::action):
+ (WebCore::ContextMenuItem::setAction):
+ (WebCore::ContextMenuItem::title):
+ (WebCore::ContextMenuItem::setTitle):
+ (WebCore::ContextMenuItem::platformSubMenu):
+ (WebCore::ContextMenuItem::setSubMenu):
+ (WebCore::ContextMenuItem::setChecked):
+ (WebCore::ContextMenuItem::setEnabled):
+
2010-12-10 Philippe Normand <pnormand at igalia.com>
Reviewed by Gustavo Noronha Silva.
diff --git a/WebCore/platform/ContextMenuItem.h b/WebCore/platform/ContextMenuItem.h
index e702921..e0a008d 100644
--- a/WebCore/platform/ContextMenuItem.h
+++ b/WebCore/platform/ContextMenuItem.h
@@ -42,6 +42,7 @@ class NSMenuItem;
#elif PLATFORM(WIN)
typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
#elif PLATFORM(GTK)
+#include <GRefPtr.h>
typedef struct _GtkMenuItem GtkMenuItem;
#elif PLATFORM(QT)
#include <QAction>
@@ -185,22 +186,7 @@ namespace WebCore {
bool enabled;
};
#elif PLATFORM(GTK)
- struct PlatformMenuItemDescription {
- PlatformMenuItemDescription()
- : type(ActionType)
- , action(ContextMenuItemTagNoAction)
- , subMenu(0)
- , checked(false)
- , enabled(true)
- {}
-
- ContextMenuItemType type;
- ContextMenuAction action;
- String title;
- GtkMenu* subMenu;
- bool checked;
- bool enabled;
- };
+ typedef GtkMenuItem* PlatformMenuItemDescription;
#elif PLATFORM(WX)
struct PlatformMenuItemDescription {
PlatformMenuItemDescription()
@@ -260,9 +246,7 @@ namespace WebCore {
ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
-#if PLATFORM(GTK)
- ContextMenuItem(GtkMenuItem*);
-#endif
+
~ContextMenuItem();
PlatformMenuItemDescription releasePlatformDescription();
@@ -287,13 +271,12 @@ namespace WebCore {
bool enabled() const;
// FIXME: Do we need a keyboard accelerator here?
-#if PLATFORM(GTK)
- static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);
-#endif
private:
#if PLATFORM(MAC)
RetainPtr<NSMenuItem> m_platformDescription;
+#elif PLATFORM(GTK)
+ PlatformRefPtr<GtkMenuItem> m_platformDescription;
#else
PlatformMenuItemDescription m_platformDescription;
#endif
diff --git a/WebCore/platform/gtk/ContextMenuGtk.cpp b/WebCore/platform/gtk/ContextMenuGtk.cpp
index 327167e..423959a 100644
--- a/WebCore/platform/gtk/ContextMenuGtk.cpp
+++ b/WebCore/platform/gtk/ContextMenuGtk.cpp
@@ -40,7 +40,7 @@ void ContextMenu::appendItem(ContextMenuItem& item)
{
ASSERT(m_platformDescription);
- GtkMenuItem* platformItem = ContextMenuItem::createNativeMenuItem(item.releasePlatformDescription());
+ GtkMenuItem* platformItem = item.releasePlatformDescription();
ASSERT(platformItem);
gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem));
gtk_widget_show(GTK_WIDGET(platformItem));
diff --git a/WebCore/platform/gtk/ContextMenuItemGtk.cpp b/WebCore/platform/gtk/ContextMenuItemGtk.cpp
index 68d0a9a..37c29b5 100644
--- a/WebCore/platform/gtk/ContextMenuItemGtk.cpp
+++ b/WebCore/platform/gtk/ContextMenuItemGtk.cpp
@@ -18,12 +18,13 @@
*/
#include "config.h"
-#include "ContextMenu.h"
#include "ContextMenuItem.h"
-#include "NotImplemented.h"
-#include <wtf/text/CString.h>
+#include "ContextMenu.h"
+#include "GOwnPtr.h"
+#include "NotImplemented.h"
#include <gtk/gtk.h>
+#include <wtf/text/CString.h>
#define WEBKIT_CONTEXT_MENU_ACTION "webkit-context-menu"
@@ -114,30 +115,9 @@ static const char* gtkStockIDFromContextMenuAction(const ContextMenuAction& acti
}
// Extract the ActionType from the menu item
-ContextMenuItem::ContextMenuItem(GtkMenuItem* item)
- : m_platformDescription()
+ContextMenuItem::ContextMenuItem(PlatformMenuItemDescription item)
+ : m_platformDescription(item)
{
- if (GTK_IS_SEPARATOR_MENU_ITEM(item))
- m_platformDescription.type = SeparatorType;
- else if (gtk_menu_item_get_submenu(item))
- m_platformDescription.type = SubmenuType;
- else if (GTK_IS_CHECK_MENU_ITEM(item)) {
- m_platformDescription.type = CheckableActionType;
- m_platformDescription.checked = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item));
- } else
- m_platformDescription.type = ActionType;
-#if GTK_CHECK_VERSION (2, 16, 0)
- m_platformDescription.title = String::fromUTF8(gtk_menu_item_get_label(GTK_MENU_ITEM(item)));
-#else
- GtkWidget* label = gtk_bin_get_child(GTK_BIN(item));
- m_platformDescription.title = String::fromUTF8(gtk_label_get_label(GTK_LABEL(label)));
-#endif
-
- m_platformDescription.action = *static_cast<ContextMenuAction*>(g_object_get_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION));
-
- m_platformDescription.subMenu = GTK_MENU(gtk_menu_item_get_submenu(item));
- if (m_platformDescription.subMenu)
- g_object_ref(m_platformDescription.subMenu);
}
ContextMenuItem::ContextMenuItem(ContextMenu*)
@@ -147,114 +127,100 @@ ContextMenuItem::ContextMenuItem(ContextMenu*)
ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
{
- m_platformDescription.type = type;
- m_platformDescription.action = action;
- m_platformDescription.title = title;
-
- setSubMenu(subMenu);
-}
+ if (type == SeparatorType) {
+ m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new());
+ return;
+ }
-ContextMenuItem::~ContextMenuItem()
-{
- if (m_platformDescription.subMenu)
- g_object_unref(m_platformDescription.subMenu);
-}
+ GOwnPtr<char> actionName(g_strdup_printf("context-menu-action-%d", action));
+ GtkAction* platformAction = 0;
-GtkMenuItem* ContextMenuItem::createNativeMenuItem(const PlatformMenuItemDescription& menu)
-{
- GtkMenuItem* item = 0;
- if (menu.type == SeparatorType)
- item = GTK_MENU_ITEM(gtk_separator_menu_item_new());
- else {
- if (menu.type == CheckableActionType) {
- item = GTK_MENU_ITEM(gtk_check_menu_item_new_with_mnemonic(menu.title.utf8().data()));
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), menu.checked);
- } else {
- if (const gchar* stockID = gtkStockIDFromContextMenuAction(menu.action)) {
- item = GTK_MENU_ITEM(gtk_image_menu_item_new_with_mnemonic(menu.title.utf8().data()));
- GtkWidget* image = gtk_image_new_from_stock(stockID, GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
- } else
- item = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(menu.title.utf8().data()));
- }
+ if (type == ActionType)
+ platformAction = gtk_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action));
+ else if (type == CheckableActionType)
+ platformAction = GTK_ACTION(gtk_toggle_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action)));
- ContextMenuAction* menuAction = static_cast<ContextMenuAction*>(malloc(sizeof(ContextMenuAction*)));
- *menuAction = menu.action;
- g_object_set_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION, menuAction);
+ m_platformDescription = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction));
+ g_object_unref(platformAction);
- gtk_widget_set_sensitive(GTK_WIDGET(item), menu.enabled);
+ g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
- if (menu.subMenu)
- gtk_menu_item_set_submenu(item, GTK_WIDGET(menu.subMenu));
- }
+ if (subMenu)
+ setSubMenu(subMenu);
+}
- return item;
+ContextMenuItem::~ContextMenuItem()
+{
}
PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
{
- PlatformMenuItemDescription description = m_platformDescription;
- m_platformDescription = PlatformMenuItemDescription();
- return description;
+ return m_platformDescription.leakRef();
}
ContextMenuItemType ContextMenuItem::type() const
{
- return m_platformDescription.type;
+ if (GTK_IS_SEPARATOR_MENU_ITEM(m_platformDescription.get()))
+ return SeparatorType;
+ if (GTK_IS_CHECK_MENU_ITEM(m_platformDescription.get()))
+ return CheckableActionType;
+ if (gtk_menu_item_get_submenu(m_platformDescription.get()))
+ return SubmenuType;
+ return ActionType;
}
void ContextMenuItem::setType(ContextMenuItemType type)
{
- m_platformDescription.type = type;
+ if (type == SeparatorType)
+ m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new());
}
ContextMenuAction ContextMenuItem::action() const
{
- return m_platformDescription.action;
+ return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION)));
}
void ContextMenuItem::setAction(ContextMenuAction action)
{
- m_platformDescription.action = action;
+ g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
}
String ContextMenuItem::title() const
{
- return m_platformDescription.title;
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ return action ? String(gtk_action_get_label(action)) : String();
}
void ContextMenuItem::setTitle(const String& title)
{
- m_platformDescription.title = title;
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ if (action)
+ gtk_action_set_label(action, title.utf8().data());
}
PlatformMenuDescription ContextMenuItem::platformSubMenu() const
{
- return m_platformDescription.subMenu;
+ GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription.get());
+ return subMenu ? GTK_MENU(subMenu) : 0;
}
void ContextMenuItem::setSubMenu(ContextMenu* menu)
{
- if (m_platformDescription.subMenu)
- g_object_unref(m_platformDescription.subMenu);
-
- if (!menu)
- return;
-
- m_platformDescription.subMenu = menu->releasePlatformDescription();
- m_platformDescription.type = SubmenuType;
-
- g_object_ref_sink(G_OBJECT(m_platformDescription.subMenu));
+ gtk_menu_item_set_submenu(m_platformDescription.get(), GTK_WIDGET(menu->platformDescription()));
}
void ContextMenuItem::setChecked(bool shouldCheck)
{
- m_platformDescription.checked = shouldCheck;
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ if (action && GTK_IS_TOGGLE_ACTION(action))
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), shouldCheck);
}
void ContextMenuItem::setEnabled(bool shouldEnable)
{
- m_platformDescription.enabled = shouldEnable;
+ GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
+ if (action)
+ gtk_action_set_sensitive(action, shouldEnable);
}
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list