Changeset 217209 in webkit


Ignore:
Timestamp:
May 22, 2017 12:50:44 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add webkit_context_menu_item_new_from_gaction
https://bugs.webkit.org/show_bug.cgi?id=159631

Reviewed by Michael Catanzaro.

Source/WebKit2:

Add new API to create a WebKitContextMenuItem from a GAction and also to get the associated GAction.

  • Shared/gtk/WebContextMenuItemGtk.cpp:

(WebKit::WebContextMenuItemGtk::WebContextMenuItemGtk): Add constructor that receives a GAction.
(WebKit::isGActionChecked): Helper to check if a stateful GAction is checked or not.
(WebKit::WebContextMenuItemGtk::createActionIfNeeded): When creating a GAction from a GtkAtion, use the
GtkAction name instead of adding a new one. Do not create the GAction if we already have one.

  • Shared/gtk/WebContextMenuItemGtk.h:

(WebKit::WebContextMenuItemGtk::gAction):
(WebKit::WebContextMenuItemGtk::gActionTarget):

  • UIProcess/API/gtk/WebKitContextMenuItem.cpp:

(webkit_context_menu_item_new_from_gaction):
(webkit_context_menu_item_get_gaction):

  • UIProcess/API/gtk/WebKitContextMenuItem.h:
  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
  • UIProcess/gtk/WebContextMenuProxyGtk.cpp:

(WebKit::contextMenuItemActivatedCallback): Update the state of the internal GAction in case of toggle menu items.
(WebKit::WebContextMenuProxyGtk::append): Pass the GAction target to g_menu_item_set_action_and_target_value. Do
not connect to activate signal of actions provided by the user.

Tools:

Update context menu tests to check the new GAction API.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:

(testContextMenuPopulateMenu):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r217206 r217209  
     12017-05-22  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add webkit_context_menu_item_new_from_gaction
     4        https://bugs.webkit.org/show_bug.cgi?id=159631
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add new API to create a WebKitContextMenuItem from a GAction and also to get the associated GAction.
     9
     10        * Shared/gtk/WebContextMenuItemGtk.cpp:
     11        (WebKit::WebContextMenuItemGtk::WebContextMenuItemGtk): Add constructor that receives a GAction.
     12        (WebKit::isGActionChecked): Helper to check if a stateful GAction is checked or not.
     13        (WebKit::WebContextMenuItemGtk::createActionIfNeeded): When creating a GAction from a GtkAtion, use the
     14        GtkAction name instead of adding a new one. Do not create the GAction if we already have one.
     15        * Shared/gtk/WebContextMenuItemGtk.h:
     16        (WebKit::WebContextMenuItemGtk::gAction):
     17        (WebKit::WebContextMenuItemGtk::gActionTarget):
     18        * UIProcess/API/gtk/WebKitContextMenuItem.cpp:
     19        (webkit_context_menu_item_new_from_gaction):
     20        (webkit_context_menu_item_get_gaction):
     21        * UIProcess/API/gtk/WebKitContextMenuItem.h:
     22        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
     23        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
     24        (WebKit::contextMenuItemActivatedCallback): Update the state of the internal GAction in case of toggle menu items.
     25        (WebKit::WebContextMenuProxyGtk::append): Pass the GAction target to g_menu_item_set_action_and_target_value. Do
     26        not connect to activate signal of actions provided by the user.
     27
    1282017-05-21  Carlos Garcia Campos  <cgarcia@igalia.com>
    229
  • trunk/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.cpp

    r206505 r217209  
    135135    : WebContextMenuItemData(ActionType, data.action(), data.title(), data.enabled(), false)
    136136{
    137     m_gAction = G_SIMPLE_ACTION(data.gAction());
     137    m_gAction = data.gAction();
    138138    m_gtkAction = data.gtkAction();
    139139    m_submenuItems = WTFMove(submenu);
     
    148148}
    149149
     150static bool isGActionChecked(GAction* action)
     151{
     152    if (!g_action_get_state_type(action))
     153        return false;
     154
     155    ASSERT(g_variant_type_equal(g_action_get_state_type(action), G_VARIANT_TYPE_BOOLEAN));
     156    GRefPtr<GVariant> state = adoptGRef(g_action_get_state(action));
     157    return g_variant_get_boolean(state.get());
     158}
     159
     160WebContextMenuItemGtk::WebContextMenuItemGtk(GAction* action, const String& title, GVariant* target)
     161    : WebContextMenuItemData(g_action_get_state_type(action) ? CheckableActionType : ActionType, ContextMenuItemBaseApplicationTag, title, g_action_get_enabled(action), isGActionChecked(action))
     162    , m_gAction(action)
     163    , m_gActionTarget(target)
     164{
     165    createActionIfNeeded();
     166}
     167
    150168WebContextMenuItemGtk::~WebContextMenuItemGtk()
    151169{
     
    158176
    159177    static uint64_t actionID = 0;
    160     GUniquePtr<char> actionName(g_strdup_printf("action-%" PRIu64, ++actionID));
    161     if (type() == CheckableActionType)
    162         m_gAction = adoptGRef(g_simple_action_new_stateful(actionName.get(), nullptr, g_variant_new_boolean(checked())));
    163     else
    164         m_gAction = adoptGRef(g_simple_action_new(actionName.get(), nullptr));
    165     g_simple_action_set_enabled(m_gAction.get(), enabled());
     178    if (!m_gAction) {
     179        GUniquePtr<char> actionName;
     180        if (m_gtkAction)
     181            actionName.reset(g_strdup(gtk_action_get_name(m_gtkAction)));
     182        else
     183            actionName.reset(g_strdup_printf("action-%" PRIu64, ++actionID));
     184        if (type() == CheckableActionType)
     185            m_gAction = adoptGRef(G_ACTION(g_simple_action_new_stateful(actionName.get(), nullptr, g_variant_new_boolean(checked()))));
     186        else
     187            m_gAction = adoptGRef(G_ACTION(g_simple_action_new(actionName.get(), nullptr)));
     188        g_simple_action_set_enabled(G_SIMPLE_ACTION(m_gAction.get()), enabled());
     189    }
    166190
    167191    // Create the GtkAction for backwards compatibility only.
    168192    if (!m_gtkAction) {
    169193        if (type() == CheckableActionType) {
    170             m_gtkAction = GTK_ACTION(gtk_toggle_action_new(actionName.get(), title().utf8().data(), nullptr, gtkStockIDFromContextMenuAction(action())));
     194            m_gtkAction = GTK_ACTION(gtk_toggle_action_new(g_action_get_name(m_gAction.get()), title().utf8().data(), nullptr, gtkStockIDFromContextMenuAction(action())));
    171195            gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(m_gtkAction), checked());
    172196        } else
    173             m_gtkAction = gtk_action_new(actionName.get(), title().utf8().data(), 0, gtkStockIDFromContextMenuAction(action()));
     197            m_gtkAction = gtk_action_new(g_action_get_name(m_gAction.get()), title().utf8().data(), 0, gtkStockIDFromContextMenuAction(action()));
    174198        gtk_action_set_sensitive(m_gtkAction, enabled());
    175199        g_object_set_data_full(G_OBJECT(m_gAction.get()), "webkit-gtk-action", m_gtkAction, g_object_unref);
  • trunk/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.h

    r206505 r217209  
    3333typedef struct _GtkAction GtkAction;
    3434typedef struct _GAction GAction;
    35 typedef struct _GSimpleAction GSimpleAction;
    3635
    3736namespace WebKit {
     
    4443    WebContextMenuItemGtk(const WebContextMenuItemGtk&, Vector<WebContextMenuItemGtk>&& submenu);
    4544    WebContextMenuItemGtk(GtkAction*);
     45    WebContextMenuItemGtk(GAction*, const String& title, GVariant* target = nullptr);
    4646    ~WebContextMenuItemGtk();
    4747
     
    4949    WebCore::ContextMenuItemType type() const { return m_submenuItems.isEmpty() ? WebContextMenuItemData::type() : WebCore::SubmenuType; }
    5050    GtkAction* gtkAction() const { return m_gtkAction; }
    51     GAction* gAction() const { return reinterpret_cast<GAction*>(m_gAction.get()); }
     51    GAction* gAction() const { return m_gAction.get(); }
     52    GVariant* gActionTarget() const { return m_gActionTarget.get(); }
    5253    const Vector<WebContextMenuItemGtk>& submenuItems() const { return m_submenuItems; }
    5354
     
    5556    void createActionIfNeeded();
    5657
    57     GRefPtr<GSimpleAction> m_gAction;
     58    GRefPtr<GAction> m_gAction;
     59    GRefPtr<GVariant> m_gActionTarget;
    5860    GtkAction* m_gtkAction { nullptr };
    5961    Vector<WebContextMenuItemGtk> m_submenuItems;
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp

    r213703 r217209  
    132132 *
    133133 * Returns: the newly created #WebKitContextMenuItem object.
     134 *
     135 * Deprecated: 2.18: Use webkit_context_menu_item_new_from_gaction() instead.
    134136 */
    135137WebKitContextMenuItem* webkit_context_menu_item_new(GtkAction* action)
     
    139141    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
    140142    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(action);
     143
     144    return item;
     145}
     146
     147/**
     148 * webkit_context_menu_item_new_from_gaction:
     149 * @action: a #GAction
     150 * @label: the menu item label text
     151 * @target: (allow-none): a #GVariant to use as the action target
     152 *
     153 * Creates a new #WebKitContextMenuItem for the given @action and @label. On activation
     154 * @target will be passed as parameter to the callback.
     155 *
     156 * Returns: the newly created #WebKitContextMenuItem object.
     157 *
     158 * Since: 2.18
     159 */
     160WebKitContextMenuItem* webkit_context_menu_item_new_from_gaction(GAction* action, const gchar* label, GVariant* target)
     161{
     162    g_return_val_if_fail(G_IS_ACTION(action), nullptr);
     163    g_return_val_if_fail(!g_action_get_state_type(action) || g_variant_type_equal(g_action_get_state_type(action), G_VARIANT_TYPE_BOOLEAN), nullptr);
     164    g_return_val_if_fail(label, nullptr);
     165    g_return_val_if_fail(!target || g_variant_is_of_type(target, g_action_get_parameter_type(action)), nullptr);
     166
     167    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
     168    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(action, String::fromUTF8(label), target);
    141169
    142170    return item;
     
    236264 * @item: a #WebKitContextMenuItem
    237265 *
    238  * Gets the action associated to @item.
     266 * Gets the action associated to @item as a #GtkAction.
    239267 *
    240268 * Returns: (transfer none): the #GtkAction associated to the #WebKitContextMenuItem,
    241269 *    or %NULL if @item is a separator.
     270 *
     271 * Deprecated: 2.18: Use webkit_context_menu_item_get_gaction() instead.
    242272 */
    243273GtkAction* webkit_context_menu_item_get_action(WebKitContextMenuItem* item)
     
    246276
    247277    return item->priv->menuItem->gtkAction();
     278}
     279
     280/**
     281 * webkit_context_menu_item_get_gaction:
     282 * @item: a #WebKitContextMenuItem
     283 *
     284 * Gets the action associated to @item as a #GAction.
     285 *
     286 * Returns: (transfer none): the #GAction associated to the #WebKitContextMenuItem,
     287 *    or %NULL if @item is a separator.
     288 *
     289 * Since: 2.18
     290 */
     291GAction* webkit_context_menu_item_get_gaction(WebKitContextMenuItem* item)
     292{
     293    g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), nullptr);
     294
     295    return item->priv->menuItem->gAction();
    248296}
    249297
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h

    r175694 r217209  
    6161webkit_context_menu_item_get_type                         (void);
    6262
     63WEBKIT_DEPRECATED_FOR(webkit_context_menu_item_new_from_gaction) WebKitContextMenuItem *
     64webkit_context_menu_item_new                              (GtkAction              *action);
     65
    6366WEBKIT_API WebKitContextMenuItem *
    64 webkit_context_menu_item_new                              (GtkAction              *action);
     67webkit_context_menu_item_new_from_gaction                 (GAction                *action,
     68                                                           const gchar            *label,
     69                                                           GVariant               *target);
    6570
    6671WEBKIT_API WebKitContextMenuItem *
     
    7883webkit_context_menu_item_new_separator                    (void);
    7984
    80 WEBKIT_API GtkAction *
     85WEBKIT_DEPRECATED_FOR(webkit_context_menu_item_get_gactionwebkit_context_menu_item_get_gaction) GtkAction *
    8186webkit_context_menu_item_get_action                       (WebKitContextMenuItem  *item);
     87
     88WEBKIT_API GAction *
     89webkit_context_menu_item_get_gaction                      (WebKitContextMenuItem  *item);
    8290
    8391WEBKIT_API WebKitContextMenuAction
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r216006 r217209  
    11501150WebKitContextMenuAction
    11511151webkit_context_menu_item_new
     1152webkit_context_menu_item_new_from_gaction
    11521153webkit_context_menu_item_new_from_stock_action
    11531154webkit_context_menu_item_new_from_stock_action_with_label
     
    11551156webkit_context_menu_item_new_separator
    11561157webkit_context_menu_item_get_action
     1158webkit_context_menu_item_get_gaction
    11571159webkit_context_menu_item_get_stock_action
    11581160webkit_context_menu_item_is_separator
  • trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp

    r215190 r217209  
    5858        String::fromUTF8(static_cast<const char*>(g_object_get_data(G_OBJECT(action), gContextMenuTitle))), g_action_get_enabled(action),
    5959        state ? g_variant_get_boolean(state.get()) : false);
     60    if (isToggle)
     61        g_action_change_state(action, g_variant_new_boolean(!g_variant_get_boolean(state.get())));
    6062    page->contextMenuItemSelected(item);
    6163}
     
    7880        GUniquePtr<char> actionName(g_strdup_printf("%s.%s", gContextMenuItemGroup, g_action_get_name(action)));
    7981        gMenuItem = adoptGRef(g_menu_item_new(menuItem.title().utf8().data(), nullptr));
    80         g_menu_item_set_action_and_target_value(gMenuItem.get(), actionName.get(), nullptr);
    81 
    82         g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action()));
    83         g_object_set_data_full(G_OBJECT(action), gContextMenuTitle, g_strdup(menuItem.title().utf8().data()), g_free);
    84         signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page);
    85         m_signalHandlers.set(signalHandlerId, action);
     82        g_menu_item_set_action_and_target_value(gMenuItem.get(), actionName.get(), menuItem.gActionTarget());
     83
     84        if (menuItem.action() < ContextMenuItemBaseApplicationTag) {
     85            g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action()));
     86            g_object_set_data_full(G_OBJECT(action), gContextMenuTitle, g_strdup(menuItem.title().utf8().data()), g_free);
     87            signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page);
     88            m_signalHandlers.set(signalHandlerId, action);
     89        }
    8690        break;
    8791    }
  • trunk/Tools/ChangeLog

    r217203 r217209  
     12017-05-22  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add webkit_context_menu_item_new_from_gaction
     4        https://bugs.webkit.org/show_bug.cgi?id=159631
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Update context menu tests to check the new GAction API.
     9
     10        * TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:
     11        (testContextMenuPopulateMenu):
     12
    1132017-05-21  Michael Catanzaro  <mcatanzaro@igalia.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp

    r213278 r217209  
    137137        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
    138138
     139        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    139140        GtkAction* action = webkit_context_menu_item_get_action(item);
    140141        g_assert(GTK_IS_ACTION(action));
     142        G_GNUC_END_IGNORE_DEPRECATIONS;
     143
     144        GAction* gAction = webkit_context_menu_item_get_gaction(item);
     145        g_assert(G_IS_ACTION(gAction));
    141146
    142147        g_assert_cmpint(webkit_context_menu_item_get_stock_action(item), ==, stockAction);
     
    155160        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
    156161
     162        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    157163        GtkAction* action = webkit_context_menu_item_get_action(item);
    158164        g_assert(GTK_IS_ACTION(action));
     165        G_GNUC_END_IGNORE_DEPRECATIONS;
     166
     167        GAction* gAction = webkit_context_menu_item_get_gaction(item);
     168        g_assert(G_IS_ACTION(gAction));
     169        g_assert_cmpstr(gtk_action_get_name(action), ==, g_action_get_name(gAction));
     170        g_assert(gtk_action_get_sensitive(action) == g_action_get_enabled(gAction));
     171        if (GTK_IS_TOGGLE_ACTION(action)) {
     172            g_assert(g_variant_type_equal(g_action_get_state_type(gAction), G_VARIANT_TYPE_BOOLEAN));
     173            GRefPtr<GVariant> state = adoptGRef(g_action_get_state(gAction));
     174            g_assert(gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) == g_variant_get_boolean(state.get()));
     175        } else
     176            g_assert(!g_action_get_state_type(gAction));
    159177
    160178        g_assert_cmpint(webkit_context_menu_item_get_stock_action(item), ==, WEBKIT_CONTEXT_MENU_ACTION_CUSTOM);
     
    174192        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item));
    175193
     194        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
    176195        GtkAction* action = webkit_context_menu_item_get_action(item);
    177196        g_assert(GTK_IS_ACTION(action));
    178 
    179197        g_assert_cmpstr(gtk_action_get_label(action), ==, label);
     198        G_GNUC_END_IGNORE_DEPRECATIONS;
     199
     200        GAction* gAction = webkit_context_menu_item_get_gaction(item);
     201        g_assert(G_IS_ACTION(gAction));
     202
    180203        checkActionState(action, state);
    181204
     
    500523    MAKE_GLIB_TEST_FIXTURE(ContextMenuCustomTest);
    501524
    502     ContextMenuCustomTest()
    503         : m_itemToActivateLabel(0)
    504         , m_activated(false)
    505         , m_toggled(false)
    506     {
    507     }
    508 
    509525    bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult* hitTestResult)
    510526    {
    511527        // Append our custom item to the default menu.
    512         webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(m_action.get()));
     528        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
     529        if (m_action)
     530            webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(m_action.get()));
     531        else if (m_gAction)
     532            webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_gaction(m_gAction.get(), m_gActionTitle.data(), m_expectedTarget.get()));
     533        G_GNUC_END_IGNORE_DEPRECATIONS;
    513534        quitMainLoop();
    514535
     
    534555        GtkMenuItem* item = getMenuItem(menu, m_itemToActivateLabel);
    535556        gtk_menu_shell_activate_item(GTK_MENU_SHELL(menu), GTK_WIDGET(item), TRUE);
    536         m_itemToActivateLabel = 0;
     557        m_itemToActivateLabel = nullptr;
    537558    }
    538559
     
    557578    }
    558579
    559     static void actionActivatedCallback(GtkAction*, ContextMenuCustomTest* test)
    560     {
    561         test->m_activated = true;
    562     }
    563 
    564     static void actionToggledCallback(GtkAction*, ContextMenuCustomTest* test)
     580    static void actionActivatedCallback(ContextMenuCustomTest* test, GVariant* target)
     581    {
     582        if (test->m_gAction) {
     583            if (g_action_get_state_type(test->m_gAction.get())) {
     584                GRefPtr<GVariant> state = adoptGRef(g_action_get_state(test->m_gAction.get()));
     585                g_action_change_state(test->m_gAction.get(), g_variant_new_boolean(!g_variant_get_boolean(state.get())));
     586            } else {
     587                test->m_activated = true;
     588                if (test->m_expectedTarget)
     589                    g_assert(g_variant_equal(test->m_expectedTarget.get(), target));
     590                else
     591                    g_assert(!target);
     592            }
     593        } else
     594            test->m_activated = true;
     595    }
     596
     597    static void actionToggledCallback(ContextMenuCustomTest* test)
    565598    {
    566599        test->m_toggled = true;
     
    570603    {
    571604        m_action = action;
     605        m_gAction = nullptr;
     606        m_expectedTarget = nullptr;
    572607        if (GTK_IS_TOGGLE_ACTION(action))
    573             g_signal_connect(action, "toggled", G_CALLBACK(actionToggledCallback), this);
     608            g_signal_connect_swapped(action, "toggled", G_CALLBACK(actionToggledCallback), this);
    574609        else
    575             g_signal_connect(action, "activate", G_CALLBACK(actionActivatedCallback), this);
     610            g_signal_connect_swapped(action, "activate", G_CALLBACK(actionActivatedCallback), this);
     611    }
     612
     613    void setAction(GAction* action, const char* title, GVariant* target = nullptr)
     614    {
     615        m_gAction = action;
     616        m_gActionTitle = title;
     617        m_action = nullptr;
     618        m_expectedTarget = target;
     619        g_signal_connect_swapped(action, "activate", G_CALLBACK(actionActivatedCallback), this);
     620        if (g_action_get_state_type(action))
     621            g_signal_connect_swapped(action, "change-state", G_CALLBACK(actionToggledCallback), this);
    576622    }
    577623
    578624    GRefPtr<GtkAction> m_action;
    579     const char* m_itemToActivateLabel;
    580     bool m_activated;
    581     bool m_toggled;
     625    GRefPtr<GAction> m_gAction;
     626    CString m_gActionTitle;
     627    GRefPtr<GVariant> m_expectedTarget;
     628    const char* m_itemToActivateLabel { nullptr };
     629    bool m_activated { false };
     630    bool m_toggled { false };
    582631};
    583632
     
    590639
    591640    // Create a custom menu item.
    592     GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", 0, 0));
     641    GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", nullptr, nullptr));
    593642    test->setAction(action.get());
    594643    test->showContextMenuAndWaitUntilFinished();
     
    598647
    599648    // Create a custom toggle menu item.
    600     GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", 0, 0)));
     649    GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", nullptr, nullptr)));
    601650    test->setAction(toggleAction.get());
    602651    test->showContextMenuAndWaitUntilFinished();
     
    604653    g_assert(!test->m_activated);
    605654    g_assert(test->m_toggled);
     655
     656    // Create a custom menu item using GAction.
     657    GRefPtr<GAction> gAction = adoptGRef(G_ACTION(g_simple_action_new("WebKitGTK+CustomGAction", nullptr)));
     658    test->setAction(gAction.get(), "Custom _GAction");
     659    test->showContextMenuAndWaitUntilFinished();
     660    test->activateCustomMenuItemAndWaitUntilActivated("Custom _GAction");
     661    g_assert(test->m_activated);
     662    g_assert(!test->m_toggled);
     663
     664    // Create a custom toggle menu item using GAction.
     665    GRefPtr<GAction> toggleGAction = adoptGRef(G_ACTION(g_simple_action_new_stateful("WebKitGTK+CustomToggleGAction", nullptr, g_variant_new_boolean(FALSE))));
     666    test->setAction(toggleGAction.get(), "Custom _Toggle GAction");
     667    test->showContextMenuAndWaitUntilFinished();
     668    test->toggleCustomMenuItemAndWaitUntilToggled("Custom _Toggle GAction");
     669    g_assert(!test->m_activated);
     670    g_assert(test->m_toggled);
     671
     672    // Create a custom menu item using GAction with a target.
     673    gAction = adoptGRef(G_ACTION(g_simple_action_new("WebKitGTK+CustomGActionWithTarget", G_VARIANT_TYPE_STRING)));
     674    test->setAction(gAction.get(), "Custom _GAction With Target", g_variant_new_string("WebKitGTK+CustomGActionTarget"));
     675    test->showContextMenuAndWaitUntilFinished();
     676    test->activateCustomMenuItemAndWaitUntilActivated("Custom _GAction With Target");
     677    g_assert(test->m_activated);
    606678}
    607679
     
    622694
    623695        // Add custom actions.
    624         GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", 0, 0));
     696        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
     697        GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", nullptr, nullptr));
    625698        gtk_action_set_sensitive(action.get(), FALSE);
    626699        webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new(action.get()), -1);
    627         GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", 0, 0)));
     700        GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", nullptr, nullptr)));
    628701        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(toggleAction.get()), TRUE);
    629702        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(toggleAction.get()));
    630703        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator());
     704        GRefPtr<GAction> gAction = adoptGRef(G_ACTION(g_simple_action_new("WebKitGTK+CustomGAction", nullptr)));
     705        g_simple_action_set_enabled(G_SIMPLE_ACTION(gAction.get()), FALSE);
     706        webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new_from_gaction(gAction.get(), "Custom _GAction", nullptr), -1);
     707        GRefPtr<GAction> toggleGAction = adoptGRef(G_ACTION(g_simple_action_new_stateful("WebKitGTK+CustomToggleGAction", nullptr, g_variant_new_boolean(TRUE))));
     708        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_gaction(toggleGAction.get(), "Custom T_oggle GAction", nullptr));
     709        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator());
     710        G_GNUC_END_IGNORE_DEPRECATIONS;
    631711
    632712        // Add a submenu.
     
    661741        iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom _Action", Visible);
    662742        iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom _Toggle Action", Visible | Enabled | Checked);
     743        iter = checkCurrentItemIsSeparatorAndGetNext(iter);
     744        iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom _GAction", Visible);
     745        iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom T_oggle GAction", Visible | Enabled | Checked);
    663746        g_assert(!iter);
    664747
Note: See TracChangeset for help on using the changeset viewer.