IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / gtk_plugin_container.cc
blob0b83f2ee69fd860a58c9a9e49ed71579c8164aee
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"
7 #include <gtk/gtk.h>
9 #include "base/basictypes.h"
11 namespace content {
13 namespace {
15 // NOTE: This class doesn't have constructors/destructors, it is created
16 // through GLib's object management.
17 class GtkPluginContainer : public GtkSocket {
18 public:
19 // Sets the requested size of the widget.
20 void set_size(int width, int height) {
21 width_ = width;
22 height_ = height;
25 // Casts a widget into a GtkPluginContainer, after checking the type.
26 template <class T>
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.
34 if (!type) {
35 static const GTypeInfo info = {
36 sizeof(GtkSocketClass),
37 NULL, NULL,
38 static_cast<GClassInitFunc>(&ClassInit),
39 NULL, NULL,
40 sizeof(GtkPluginContainer),
41 0, &InstanceInit,
43 type = g_type_register_static(GTK_TYPE_SOCKET,
44 "GtkPluginContainer",
45 &info,
46 static_cast<GTypeFlags>(0));
48 return type;
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_;
71 int width_;
72 int height_;
73 DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer);
76 } // namespace
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