BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / owned_widget_gtk2.cc
blobe45996895a964295717706a92c62233c5bca8376
1 // Copyright (c) 2012 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 "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
7 #include <gtk/gtk.h>
9 #include "base/logging.h"
11 namespace libgtk2ui {
13 OwnedWidgetGtk::~OwnedWidgetGtk() {
14 Destroy();
17 void OwnedWidgetGtk::Own(GtkWidget* widget) {
18 if (!widget)
19 return;
21 DCHECK(!widget_);
23 // Keep a reference
24 g_object_ref_sink(widget);
25 widget_ = widget;
28 void OwnedWidgetGtk::Destroy() {
29 if (!widget_)
30 return;
32 GtkWidget* widget = widget_;
33 widget_ = NULL;
34 gtk_widget_destroy(widget);
36 DCHECK(!g_object_is_floating(widget));
37 // NOTE: Assumes some implementation details about glib internals.
38 DCHECK_EQ(G_OBJECT(widget)->ref_count, 1U);
39 g_object_unref(widget);
42 } // namespace libgtk2ui