diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 23:19:56 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-23 23:19:56 +0000 |
commit | fe30fceb9de19a4919cf299e00b944786a70b033 (patch) | |
tree | 36aa1abe8831bddba23fb6b1cd48de07b17ddba5 /webkit/glue/plugins/gtk_plugin_container.cc | |
parent | 9e9c869011d525480e1e463ceed357313356815e (diff) | |
download | chromium_src-fe30fceb9de19a4919cf299e00b944786a70b033.zip chromium_src-fe30fceb9de19a4919cf299e00b944786a70b033.tar.gz chromium_src-fe30fceb9de19a4919cf299e00b944786a70b033.tar.bz2 |
linux: Fix windowed plugin resize
The plugin window was not resized properly if its size depends on the page size and that gets changed (exposed by some O3D samples).
This CL does basically 2 things:
- when resizing the plugin, queue a resize to signal the parent that the size request has changed.
- explicitly store the size, to avoid relying on the allocation, that could be changed by the parent.
Review URL: http://codereview.chromium.org/144023
Patch from Antoine Labour <piman@google.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/gtk_plugin_container.cc')
-rw-r--r-- | webkit/glue/plugins/gtk_plugin_container.cc | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/webkit/glue/plugins/gtk_plugin_container.cc b/webkit/glue/plugins/gtk_plugin_container.cc index 64b3dc3..18bdb30 100644 --- a/webkit/glue/plugins/gtk_plugin_container.cc +++ b/webkit/glue/plugins/gtk_plugin_container.cc @@ -6,10 +6,13 @@ #include <gtk/gtk.h> +#include "base/basictypes.h" + namespace { -// This class has no members/methods, and is only used for namespacing purposes. -class GtkPluginContainer { +// NOTE: This class doesn't have constructors/destructors, it is created +// through GLib's object management. +class GtkPluginContainer : public GtkSocket { public: static GtkWidget* CreateNewWidget() { GtkWidget* container = GTK_WIDGET(g_object_new(GetType(), NULL)); @@ -18,6 +21,18 @@ class GtkPluginContainer { return container; } + // Sets the requested size of the widget. + void set_size(int width, int height) { + width_ = width; + height_ = height; + } + + // Casts a widget into a GtkPluginContainer, after checking the type. + template <class T> + static GtkPluginContainer *CastChecked(T *instance) { + return G_TYPE_CHECK_INSTANCE_CAST(instance, GetType(), GtkPluginContainer); + } + private: // Create and register our custom container type with GTK. static GType GetType() { @@ -29,7 +44,7 @@ class GtkPluginContainer { static_cast<GClassInitFunc>(&ClassInit), NULL, NULL, sizeof(GtkSocket), // We are identical to a GtkSocket. - 0, NULL, + 0, &InstanceInit, }; type = g_type_register_static(GTK_TYPE_SOCKET, "GtkPluginContainer", @@ -45,11 +60,18 @@ class GtkPluginContainer { widget_class->size_request = &HandleSizeRequest; } + // Implementation of the instance initializer (constructor). + static void InstanceInit(GTypeInstance *instance, gpointer klass) { + GtkPluginContainer *container = CastChecked(instance); + container->set_size(0, 0); + } + // Report our allocation size during size requisition. static void HandleSizeRequest(GtkWidget* widget, GtkRequisition* requisition) { - requisition->width = widget->allocation.width; - requisition->height = widget->allocation.height; + GtkPluginContainer *container = CastChecked(widget); + requisition->width = container->width_; + requisition->height = container->height_; } static gboolean OnPlugRemoved(GtkSocket* socket) { @@ -57,6 +79,10 @@ class GtkPluginContainer { // We return TRUE to indicate that we don't want to destroy our side. return TRUE; } + + int width_; + int height_; + DISALLOW_IMPLICIT_CONSTRUCTORS(GtkPluginContainer); }; } // anonymous namespace @@ -65,3 +91,9 @@ class GtkPluginContainer { GtkWidget* gtk_plugin_container_new() { return GtkPluginContainer::CreateNewWidget(); } + +void gtk_plugin_container_set_size(GtkWidget *widget, int width, int height) { + GtkPluginContainer::CastChecked(widget)->set_size(width, height); + // Signal the parent that the size request has changed. + gtk_widget_queue_resize_no_redraw(widget); +} |