| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/glue/plugins/gtk_plugin_container.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // NOTE: This class doesn't have constructors/destructors, it is created | |
| 14 // through GLib's object management. | |
| 15 class GtkPluginContainer : public GtkSocket { | |
| 16 public: | |
| 17 // Sets the requested size of the widget. | |
| 18 void set_size(int width, int height) { | |
| 19 width_ = width; | |
| 20 height_ = height; | |
| 21 } | |
| 22 | |
| 23 // Casts a widget into a GtkPluginContainer, after checking the type. | |
| 24 template <class T> | |
| 25 static GtkPluginContainer *CastChecked(T *instance) { | |
| 26 return G_TYPE_CHECK_INSTANCE_CAST(instance, GetType(), GtkPluginContainer); | |
| 27 } | |
| 28 | |
| 29 // Create and register our custom container type with GTK. | |
| 30 static GType GetType() { | |
| 31 static GType type = 0; // We only want to register our type once. | |
| 32 if (!type) { | |
| 33 static const GTypeInfo info = { | |
| 34 sizeof(GtkSocketClass), | |
| 35 NULL, NULL, | |
| 36 static_cast<GClassInitFunc>(&ClassInit), | |
| 37 NULL, NULL, | |
| 38 sizeof(GtkPluginContainer), | |
| 39 0, &InstanceInit, | |
| 40 }; | |
| 41 type = g_type_register_static(GTK_TYPE_SOCKET, | |
| 42 "GtkPluginContainer", | |
| 43 &info, | |
| 44 static_cast<GTypeFlags>(0)); | |
| 45 } | |
| 46 return type; | |
| 47 } | |
| 48 | |
| 49 // Implementation of the class initializer. | |
| 50 static void ClassInit(gpointer klass, gpointer class_data_unusued) { | |
| 51 GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(klass); | |
| 52 widget_class->size_request = &HandleSizeRequest; | |
| 53 } | |
| 54 | |
| 55 // Implementation of the instance initializer (constructor). | |
| 56 static void InstanceInit(GTypeInstance *instance, gpointer klass) { | |
| 57 GtkPluginContainer *container = CastChecked(instance); | |
| 58 container->set_size(0, 0); | |
| 59 } | |
| 60 | |
| 61 // Report our allocation size during size requisition. | |
| 62 static void HandleSizeRequest(GtkWidget* widget, | |
| 63 GtkRequisition* requisition) { | |
| 64 GtkPluginContainer *container = CastChecked(widget); | |
| 65 requisition->width = container->width_; | |
| 66 requisition->height = container->height_; | |
| 67 } | |
| 68 | |
| 69 int width_; | |
| 70 int height_; | |
| 71 DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer); | |
| 72 }; | |
| 73 | |
| 74 } // anonymous namespace | |
| 75 | |
| 76 // Create a new instance of our GTK widget object. | |
| 77 GtkWidget* gtk_plugin_container_new() { | |
| 78 return GTK_WIDGET(g_object_new(GtkPluginContainer::GetType(), NULL)); | |
| 79 } | |
| 80 | |
| 81 void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height) { | |
| 82 GtkPluginContainer::CastChecked(widget)->set_size(width, height); | |
| 83 // Signal the parent that the size request has changed. | |
| 84 gtk_widget_queue_resize_no_redraw(widget); | |
| 85 } | |
| OLD | NEW |