1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3  */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #ifndef __MOZ_CONTAINER_H__
9 #define __MOZ_CONTAINER_H__
10 
11 #ifdef MOZ_WAYLAND
12 #  include "MozContainerWayland.h"
13 #endif
14 
15 #include <gtk/gtk.h>
16 #include <functional>
17 
18 /*
19  * MozContainer
20  *
21  * This class serves three purposes in the nsIWidget implementation.
22  *
23  *   - It provides objects to receive signals from GTK for events on native
24  *     windows.
25  *
26  *   - It provides GdkWindow to draw content on Wayland or when Gtk+ renders
27  *     client side decorations to mShell.
28  *
29  *   - It provides a container parent for GtkWidgets.  The only GtkWidgets
30  *     that need this in Mozilla are the GtkSockets for windowed plugins (Xt
31  *     and XEmbed).
32  *
33  * Note that the window hierarchy in Mozilla differs from conventional
34  * GtkWidget hierarchies.
35  *
36  * Mozilla's hierarchy exists through the GdkWindow hierarchy, and all child
37  * GdkWindows (within a child nsIWidget hierarchy) belong to one MozContainer
38  * GtkWidget.  If the MozContainer is unrealized or its GdkWindows are
39  * destroyed for some other reason, then the hierarchy no longer exists.  (In
40  * conventional GTK clients, the hierarchy is recorded by the GtkWidgets, and
41  * so can be re-established after destruction of the GdkWindows.)
42  *
43  * One consequence of this is that the MozContainer does not know which of its
44  * GdkWindows should parent child GtkWidgets.  (Conventional GtkContainers
45  * determine which GdkWindow to assign child GtkWidgets.)
46  *
47  * Therefore, when adding a child GtkWidget to a MozContainer,
48  * gtk_widget_set_parent_window should be called on the child GtkWidget before
49  * it is realized.
50  */
51 
52 #define MOZ_CONTAINER_TYPE (moz_container_get_type())
53 #define MOZ_CONTAINER(obj) \
54   (G_TYPE_CHECK_INSTANCE_CAST((obj), MOZ_CONTAINER_TYPE, MozContainer))
55 #define MOZ_CONTAINER_CLASS(klass) \
56   (G_TYPE_CHECK_CLASS_CAST((klass), MOZ_CONTAINER_TYPE, MozContainerClass))
57 #define IS_MOZ_CONTAINER(obj) \
58   (G_TYPE_CHECK_INSTANCE_TYPE((obj), MOZ_CONTAINER_TYPE))
59 #define IS_MOZ_CONTAINER_CLASS(klass) \
60   (G_TYPE_CHECK_CLASS_TYPE((klass), MOZ_CONTAINER_TYPE))
61 #define MOZ_CONTAINER_GET_CLASS(obj) \
62   (G_TYPE_INSTANCE_GET_CLASS((obj), MOZ_CONTAINER_TYPE, MozContainerClass))
63 
64 // We need to shape only a few pixels of the titlebar as we care about
65 // the corners only
66 #define TITLEBAR_SHAPE_MASK_HEIGHT 10
67 
68 typedef struct _MozContainer MozContainer;
69 typedef struct _MozContainerClass MozContainerClass;
70 
71 struct _MozContainer {
72   GtkContainer container;
73   GList* children;
74   gboolean force_default_visual;
75 #ifdef MOZ_WAYLAND
76   MozContainerWayland wl_container;
77 #endif
78 };
79 
80 struct _MozContainerClass {
81   GtkContainerClass parent_class;
82 };
83 
84 GType moz_container_get_type(void);
85 GtkWidget* moz_container_new(void);
86 void moz_container_put(MozContainer* container, GtkWidget* child_widget, gint x,
87                        gint y);
88 void moz_container_force_default_visual(MozContainer* container);
89 
90 #endif /* __MOZ_CONTAINER_H__ */
91