Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / widget / gtk / GRefPtr.h
blobc2dc3110cf20e9000e9a1aec62eb7c7d1b7e0882
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GRefPtr_h_
7 #define GRefPtr_h_
9 // Allows to use RefPtr<T> with various kinds of GObjects
11 #include <gdk/gdk.h>
12 #include <gio/gio.h>
13 #include <gtk/gtk.h>
14 #include <gio/gdesktopappinfo.h>
15 #include "mozilla/RefPtr.h"
17 typedef struct _DbusmenuMenuitem DbusmenuMenuitem;
18 typedef struct _DbusmenuServer DbusmenuServer;
20 namespace mozilla {
22 template <typename T>
23 struct GObjectRefPtrTraits {
24 static void AddRef(T* aObject) { g_object_ref(aObject); }
25 static void Release(T* aObject) { g_object_unref(aObject); }
28 #define GOBJECT_TRAITS(type_) \
29 template <> \
30 struct RefPtrTraits<type_> : public GObjectRefPtrTraits<type_> {};
32 GOBJECT_TRAITS(DbusmenuMenuitem)
33 GOBJECT_TRAITS(DbusmenuServer)
34 GOBJECT_TRAITS(GtkWidget)
35 GOBJECT_TRAITS(GFile)
36 GOBJECT_TRAITS(GFileMonitor)
37 GOBJECT_TRAITS(GMenu)
38 GOBJECT_TRAITS(GMenuItem)
39 GOBJECT_TRAITS(GSimpleAction)
40 GOBJECT_TRAITS(GSimpleActionGroup)
41 GOBJECT_TRAITS(GDBusProxy)
42 GOBJECT_TRAITS(GAppInfo)
43 GOBJECT_TRAITS(GDesktopAppInfo)
44 GOBJECT_TRAITS(GAppLaunchContext)
45 GOBJECT_TRAITS(GdkDragContext)
46 GOBJECT_TRAITS(GDBusMessage)
47 GOBJECT_TRAITS(GdkPixbuf)
48 GOBJECT_TRAITS(GCancellable)
49 GOBJECT_TRAITS(GtkIMContext)
50 GOBJECT_TRAITS(GUnixFDList)
51 GOBJECT_TRAITS(GtkCssProvider)
52 GOBJECT_TRAITS(GDBusMethodInvocation)
53 GOBJECT_TRAITS(GdkWindow)
55 #undef GOBJECT_TRAITS
57 template <>
58 struct RefPtrTraits<GVariant> {
59 static void AddRef(GVariant* aVariant) { g_variant_ref(aVariant); }
60 static void Release(GVariant* aVariant) { g_variant_unref(aVariant); }
63 template <>
64 struct RefPtrTraits<GHashTable> {
65 static void AddRef(GHashTable* aObject) { g_hash_table_ref(aObject); }
66 static void Release(GHashTable* aObject) { g_hash_table_unref(aObject); }
69 template <>
70 struct RefPtrTraits<GDBusNodeInfo> {
71 static void AddRef(GDBusNodeInfo* aObject) { g_dbus_node_info_ref(aObject); }
72 static void Release(GDBusNodeInfo* aObject) {
73 g_dbus_node_info_unref(aObject);
77 } // namespace mozilla
79 #endif