diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-02 19:57:25 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-02 19:57:25 +0000 |
commit | d5e4a478d52c048f60b514cdffc64320ffa4cd1b (patch) | |
tree | 9af276b38456b8e77939fcb7b7cfc1e66a8a5db4 /views | |
parent | a08df20f67c559c6594be07040a8d8eadce568dd (diff) | |
download | chromium_src-d5e4a478d52c048f60b514cdffc64320ffa4cd1b.zip chromium_src-d5e4a478d52c048f60b514cdffc64320ffa4cd1b.tar.gz chromium_src-d5e4a478d52c048f60b514cdffc64320ffa4cd1b.tar.bz2 |
Create CompositePainter once for a widget instead of ref count.
There is a issue in adding new composited child after the ref count of painter became zero.
RefCount::Release does not tell if it's been deleted so it can't remove the painter key from G_OBJECT(widget).
I could have changed RefCounted::Release to return true, but I took this approach because new child will be added
later in most use case (like info bubble), and it's more efficient to keep the painter rather than
creating and deleting each time.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2449010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/widget_gtk.cc | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 5ca89a5..055c855 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -17,7 +17,6 @@ #include "base/auto_reset.h" #include "base/compiler_specific.h" #include "base/message_loop.h" -#include "base/ref_counted.h" #include "base/utf_string_conversions.h" #include "gfx/path.h" #include "views/widget/default_theme_provider.h" @@ -42,9 +41,9 @@ const char* kCompositePainterKey = "__VIEWS_COMPOSITE_PAINTER__"; const char* kCompositeEnabledKey = "__VIEWS_COMPOSITE_ENABLED__"; // CompositePainter draws a composited child widgets image into its -// drawing area. This object is ref counted so that it can disconnect -// expose event handler when all transparent widgets are deleted. -class CompositePainter : public base::RefCounted<CompositePainter> { +// drawing area. This object is created at most once for a widget and kept +// until the widget is destroyed. +class CompositePainter { public: explicit CompositePainter(GtkWidget* parent) : parent_object_(G_OBJECT(parent)) { @@ -55,21 +54,14 @@ class CompositePainter : public base::RefCounted<CompositePainter> { static void AddCompositePainter(GtkWidget* widget) { CompositePainter* painter = static_cast<CompositePainter*>( g_object_get_data(G_OBJECT(widget), kCompositePainterKey)); - if (painter) { - painter->AddRef(); - } else { + if (!painter) { g_object_set_data(G_OBJECT(widget), kCompositePainterKey, new CompositePainter(widget)); + g_signal_connect(widget, "destroy", + G_CALLBACK(&DestroyPainter), NULL); } } - static void RemoveCompositePainter(GtkWidget* widget) { - CompositePainter* painter = reinterpret_cast<CompositePainter*>( - g_object_get_data(G_OBJECT(widget), kCompositePainterKey)); - DCHECK(painter); - painter->Release(); - } - // Enable the composition. static void SetComposited(GtkWidget* widget) { DCHECK(GTK_WIDGET_REALIZED(widget)); @@ -84,11 +76,7 @@ class CompositePainter : public base::RefCounted<CompositePainter> { } private: - friend class base::RefCounted<CompositePainter>; - virtual ~CompositePainter() { - g_signal_handler_disconnect(parent_object_, handler_id_); - g_object_set_data(parent_object_, kCompositePainterKey, NULL); - } + virtual ~CompositePainter() {} // Composes a image from one child. static void CompositeChildWidget(GtkWidget* child, gpointer data) { @@ -119,6 +107,13 @@ class CompositePainter : public base::RefCounted<CompositePainter> { return false; } + static void DestroyPainter(GtkWidget* object) { + CompositePainter* painter = reinterpret_cast<CompositePainter*>( + g_object_get_data(G_OBJECT(object), kCompositePainterKey)); + DCHECK(painter); + delete painter; + } + GObject* parent_object_; gulong handler_id_; @@ -678,13 +673,6 @@ void WidgetGtk::Close() { void WidgetGtk::CloseNow() { if (widget_) { - if (transparent_ && type_ == TYPE_CHILD) { - GtkWidget* parent = gtk_widget_get_parent(widget_); - if (parent) { - DCHECK(parent != null_parent_); - CompositePainter::RemoveCompositePainter(parent); - } - } gtk_widget_destroy(widget_); widget_ = NULL; } |