Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/ui/libgtk2ui/owned_widget_gtk2.cc

Issue 10545037: Aura/GTK integration: Create a small stub library that can talk to GTK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky nits Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
6
7 #include <gtk/gtk.h>
8
9 #include "base/logging.h"
10
11 namespace libgtk2ui {
12
13 OwnedWidgetGtk::~OwnedWidgetGtk() {
14 Destroy();
15 }
16
17 void OwnedWidgetGtk::Own(GtkWidget* widget) {
18 if (!widget)
19 return;
20
21 DCHECK(!widget_);
22 // We want to make sure that Own() was called properly, right after the
23 // widget was created. There should be a floating reference.
24 DCHECK(g_object_is_floating(widget));
25
26 // Sink the floating reference, we should now own this reference.
27 g_object_ref_sink(widget);
28 widget_ = widget;
29 }
30
31 void OwnedWidgetGtk::Destroy() {
32 if (!widget_)
33 return;
34
35 GtkWidget* widget = widget_;
36 widget_ = NULL;
37 gtk_widget_destroy(widget);
38
39 DCHECK(!g_object_is_floating(widget));
40 // NOTE: Assumes some implementation details about glib internals.
41 DCHECK_EQ(G_OBJECT(widget)->ref_count, 1U);
42 g_object_unref(widget);
43 }
44
45 } // namespace libgtk2ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698