1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/gtk_plugin_container.h"
9 #include "base/basictypes.h"
15 // NOTE: This class doesn't have constructors/destructors, it is created
16 // through GLib's object management.
17 class GtkPluginContainer
: public GtkSocket
{
19 // Sets the requested size of the widget.
20 void set_size(int width
, int height
) {
25 // Casts a widget into a GtkPluginContainer, after checking the type.
27 static GtkPluginContainer
*CastChecked(T
*instance
) {
28 return G_TYPE_CHECK_INSTANCE_CAST(instance
, GetType(), GtkPluginContainer
);
31 // Create and register our custom container type with GTK.
32 static GType
GetType() {
33 static GType type
= 0; // We only want to register our type once.
35 static const GTypeInfo info
= {
36 sizeof(GtkSocketClass
),
38 static_cast<GClassInitFunc
>(&ClassInit
),
40 sizeof(GtkPluginContainer
),
43 type
= g_type_register_static(GTK_TYPE_SOCKET
,
46 static_cast<GTypeFlags
>(0));
51 // Implementation of the class initializer.
52 static void ClassInit(gpointer klass
, gpointer class_data_unusued
) {
53 GtkWidgetClass
* widget_class
= reinterpret_cast<GtkWidgetClass
*>(klass
);
54 widget_class
->size_request
= &HandleSizeRequest
;
57 // Implementation of the instance initializer (constructor).
58 static void InstanceInit(GTypeInstance
*instance
, gpointer klass
) {
59 GtkPluginContainer
*container
= CastChecked(instance
);
60 container
->set_size(0, 0);
63 // Report our allocation size during size requisition.
64 static void HandleSizeRequest(GtkWidget
* widget
,
65 GtkRequisition
* requisition
) {
66 GtkPluginContainer
*container
= CastChecked(widget
);
67 requisition
->width
= container
->width_
;
68 requisition
->height
= container
->height_
;
73 DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer
);
78 // Create a new instance of our GTK widget object.
79 GtkWidget
* gtk_plugin_container_new() {
80 return GTK_WIDGET(g_object_new(GtkPluginContainer::GetType(), NULL
));
83 void gtk_plugin_container_set_size(GtkWidget
*widget
, int width
, int height
) {
84 GtkPluginContainer::CastChecked(widget
)->set_size(width
, height
);
85 // Signal the parent that the size request has changed.
86 gtk_widget_queue_resize_no_redraw(widget
);
89 } // namespace content