Changeset 73746 in webkit


Ignore:
Timestamp:
Dec 10, 2010 11:10:29 AM (13 years ago)
Author:
Martin Robinson
Message:

2010-12-10 Martin Robinson <mrobinson@igalia.com>

Unreviewed, rolling out r73703.
http://trac.webkit.org/changeset/73703
https://bugs.webkit.org/show_bug.cgi?id=49658

This patch is causing crashes on the GTK+ bots.

  • wtf/PlatformRefPtr.h:

2010-12-10 Martin Robinson <mrobinson@igalia.com>

Unreviewed, rolling out r73703.
http://trac.webkit.org/changeset/73703
https://bugs.webkit.org/show_bug.cgi?id=49658

This patch is causing crashes on the GTK+ bots.

  • platform/ContextMenuItem.h: (WebCore::PlatformMenuItemDescription::PlatformMenuItemDescription):
  • platform/gtk/ContextMenuGtk.cpp: (WebCore::ContextMenu::appendItem):
  • platform/gtk/ContextMenuItemGtk.cpp: (WebCore::ContextMenuItem::ContextMenuItem): (WebCore::ContextMenuItem::~ContextMenuItem): (WebCore::ContextMenuItem::createNativeMenuItem): (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):
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r73704 r73746  
     12010-12-10  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Unreviewed, rolling out r73703.
     4        http://trac.webkit.org/changeset/73703
     5        https://bugs.webkit.org/show_bug.cgi?id=49658
     6
     7        This patch is causing crashes on the GTK+ bots.
     8
     9        * wtf/PlatformRefPtr.h:
     10
    1112010-12-10  Patrick Gansterer  <paroga@webkit.org>
    212
  • trunk/JavaScriptCore/wtf/PlatformRefPtr.h

    r73703 r73746  
    7373        if (ptr)
    7474            derefPlatformPtr(ptr);
    75     }
    76 
    77     T* leakRef() WARN_UNUSED_RETURN
    78     {
    79         T* ptr = m_ptr;
    80         m_ptr = 0;
    81         return ptr;
    8275    }
    8376
  • trunk/WebCore/ChangeLog

    r73744 r73746  
     12010-12-10  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Unreviewed, rolling out r73703.
     4        http://trac.webkit.org/changeset/73703
     5        https://bugs.webkit.org/show_bug.cgi?id=49658
     6
     7        This patch is causing crashes on the GTK+ bots.
     8
     9        * platform/ContextMenuItem.h:
     10        (WebCore::PlatformMenuItemDescription::PlatformMenuItemDescription):
     11        * platform/gtk/ContextMenuGtk.cpp:
     12        (WebCore::ContextMenu::appendItem):
     13        * platform/gtk/ContextMenuItemGtk.cpp:
     14        (WebCore::ContextMenuItem::ContextMenuItem):
     15        (WebCore::ContextMenuItem::~ContextMenuItem):
     16        (WebCore::ContextMenuItem::createNativeMenuItem):
     17        (WebCore::ContextMenuItem::releasePlatformDescription):
     18        (WebCore::ContextMenuItem::type):
     19        (WebCore::ContextMenuItem::setType):
     20        (WebCore::ContextMenuItem::action):
     21        (WebCore::ContextMenuItem::setAction):
     22        (WebCore::ContextMenuItem::title):
     23        (WebCore::ContextMenuItem::setTitle):
     24        (WebCore::ContextMenuItem::platformSubMenu):
     25        (WebCore::ContextMenuItem::setSubMenu):
     26        (WebCore::ContextMenuItem::setChecked):
     27        (WebCore::ContextMenuItem::setEnabled):
     28
    1292010-12-08  Mihai Parparita  <mihaip@chromium.org>
    230
  • trunk/WebCore/platform/ContextMenuItem.h

    r73703 r73746  
    4343typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
    4444#elif PLATFORM(GTK)
    45 #include <GRefPtr.h>
    4645typedef struct _GtkMenuItem GtkMenuItem;
    4746#elif PLATFORM(QT)
     
    187186    };
    188187#elif PLATFORM(GTK)
    189     typedef GtkMenuItem* PlatformMenuItemDescription;
     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    };
    190204#elif PLATFORM(WX)
    191205    struct PlatformMenuItemDescription {
     
    247261        ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
    248262        ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
    249 
     263#if PLATFORM(GTK)
     264        ContextMenuItem(GtkMenuItem*);
     265#endif
    250266        ~ContextMenuItem();
    251267
     
    272288
    273289        // FIXME: Do we need a keyboard accelerator here?
     290#if PLATFORM(GTK)
     291        static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);
     292#endif
    274293
    275294    private:
    276295#if PLATFORM(MAC)
    277296        RetainPtr<NSMenuItem> m_platformDescription;
    278 #elif PLATFORM(GTK)
    279         PlatformRefPtr<GtkMenuItem> m_platformDescription;
    280297#else
    281298        PlatformMenuItemDescription m_platformDescription;
  • trunk/WebCore/platform/gtk/ContextMenuGtk.cpp

    r73703 r73746  
    4141    ASSERT(m_platformDescription);
    4242
    43     GtkMenuItem* platformItem = item.releasePlatformDescription();
     43    GtkMenuItem* platformItem = ContextMenuItem::createNativeMenuItem(item.releasePlatformDescription());
    4444    ASSERT(platformItem);
    4545    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem));
  • trunk/WebCore/platform/gtk/ContextMenuItemGtk.cpp

    r73703 r73746  
    1919
    2020#include "config.h"
     21#include "ContextMenu.h"
    2122#include "ContextMenuItem.h"
    22 
    23 #include "ContextMenu.h"
    24 #include "GOwnPtr.h"
    2523#include "NotImplemented.h"
     24#include <wtf/text/CString.h>
     25
    2626#include <gtk/gtk.h>
    27 #include <wtf/text/CString.h>
    2827
    2928#define WEBKIT_CONTEXT_MENU_ACTION "webkit-context-menu"
     
    116115
    117116// Extract the ActionType from the menu item
    118 ContextMenuItem::ContextMenuItem(PlatformMenuItemDescription item)
    119     : m_platformDescription(item)
    120 {
     117ContextMenuItem::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);
    121141}
    122142
     
    128148ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
    129149{
    130     if (type == SeparatorType) {
    131         m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new());
     150    m_platformDescription.type = type;
     151    m_platformDescription.action = action;
     152    m_platformDescription.title = title;
     153
     154    setSubMenu(subMenu);
     155}
     156
     157ContextMenuItem::~ContextMenuItem()
     158{
     159    if (m_platformDescription.subMenu)
     160        g_object_unref(m_platformDescription.subMenu);
     161}
     162
     163GtkMenuItem* 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            } else
     178                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}
     193
     194PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
     195{
     196    PlatformMenuItemDescription description = m_platformDescription;
     197    m_platformDescription = PlatformMenuItemDescription();
     198    return description;
     199}
     200
     201ContextMenuItemType ContextMenuItem::type() const
     202{
     203    return m_platformDescription.type;
     204}
     205
     206void ContextMenuItem::setType(ContextMenuItemType type)
     207{
     208    m_platformDescription.type = type;
     209}
     210
     211ContextMenuAction ContextMenuItem::action() const
     212{
     213    return m_platformDescription.action;
     214}
     215
     216void ContextMenuItem::setAction(ContextMenuAction action)
     217{
     218    m_platformDescription.action = action;
     219}
     220
     221String ContextMenuItem::title() const
     222{
     223    return m_platformDescription.title;
     224}
     225
     226void ContextMenuItem::setTitle(const String& title)
     227{
     228    m_platformDescription.title = title;
     229}
     230
     231PlatformMenuDescription ContextMenuItem::platformSubMenu() const
     232{
     233    return m_platformDescription.subMenu;
     234}
     235
     236void ContextMenuItem::setSubMenu(ContextMenu* menu)
     237{
     238    if (m_platformDescription.subMenu)
     239        g_object_unref(m_platformDescription.subMenu);
     240
     241    if (!menu)
    132242        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);
    150 }
    151 
    152 ContextMenuItem::~ContextMenuItem()
    153 {
    154 }
    155 
    156 PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
    157 {
    158     return m_platformDescription.leakRef();
    159 }
    160 
    161 ContextMenuItemType ContextMenuItem::type() const
    162 {
    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;
    170 }
    171 
    172 void ContextMenuItem::setType(ContextMenuItemType type)
    173 {
    174     if (type == SeparatorType)
    175         m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new());
    176 }
    177 
    178 ContextMenuAction ContextMenuItem::action() const
    179 {
    180     return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION)));
    181 }
    182 
    183 void ContextMenuItem::setAction(ContextMenuAction action)
    184 {
    185     g_object_set_data(G_OBJECT(m_platformDescription.get()), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
    186 }
    187 
    188 String ContextMenuItem::title() const
    189 {
    190     GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription.get()));
    191     return action ? String(gtk_action_get_label(action)) : String();
    192 }
    193 
    194 void ContextMenuItem::setTitle(const String& title)
    195 {
    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());
    199 }
    200 
    201 PlatformMenuDescription ContextMenuItem::platformSubMenu() const
    202 {
    203     GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription.get());
    204     return subMenu ? GTK_MENU(subMenu) : 0;
    205 }
    206 
    207 void ContextMenuItem::setSubMenu(ContextMenu* menu)
    208 {
    209     gtk_menu_item_set_submenu(m_platformDescription.get(), GTK_WIDGET(menu->platformDescription()));
     243
     244    m_platformDescription.subMenu = menu->releasePlatformDescription();
     245    m_platformDescription.type = SubmenuType;
     246
     247    g_object_ref_sink(G_OBJECT(m_platformDescription.subMenu));
    210248}
    211249
    212250void ContextMenuItem::setChecked(bool shouldCheck)
    213251{
    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);
     252    m_platformDescription.checked = shouldCheck;
    217253}
    218254
    219255void ContextMenuItem::setEnabled(bool shouldEnable)
    220256{
    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 }
     257    m_platformDescription.enabled = shouldEnable;
     258}
     259
     260}
Note: See TracChangeset for help on using the changeset viewer.