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

Side by Side Diff: ui/base/gtk/owned_widget_gtk.h

Issue 7708021: content: Move render_widget_host_view_gtk to content/ try 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
« no previous file with comments | « content/test/data/gtk_key_bindings_test_gtkrc ('k') | ui/base/gtk/owned_widget_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This class assists you in dealing with a specific situation when managing 5 // This class assists you in dealing with a specific situation when managing
6 // ownership between a C++ object and a GTK widget. It is common to have a 6 // ownership between a C++ object and a GTK widget. It is common to have a
7 // C++ object which encapsulates a GtkWidget, and that widget is exposed from 7 // C++ object which encapsulates a GtkWidget, and that widget is exposed from
8 // the object for use outside of the class. In this situation, you commonly 8 // the object for use outside of the class. In this situation, you commonly
9 // want the GtkWidget's lifetime to match its C++ object's lifetime. Using an 9 // want the GtkWidget's lifetime to match its C++ object's lifetime. Using an
10 // OwnedWigetGtk will take ownership over the initial reference of the 10 // OwnedWigetGtk will take ownership over the initial reference of the
(...skipping 28 matching lines...) Expand all
39 // was removed from a container, removing its only reference, it would be 39 // was removed from a container, removing its only reference, it would be
40 // destroyed (from the C++ object's perspective) unexpectedly destroyed. The 40 // destroyed (from the C++ object's perspective) unexpectedly destroyed. The
41 // solution is fairly simple, make sure that the C++ object owns the widget, 41 // solution is fairly simple, make sure that the C++ object owns the widget,
42 // and thus it is also responsible for destroying it. This boils down to: 42 // and thus it is also responsible for destroying it. This boils down to:
43 // GtkWidget* widget = gtk_widget_new(); 43 // GtkWidget* widget = gtk_widget_new();
44 // g_object_ref_sink(widget); // Claim the initial floating reference. 44 // g_object_ref_sink(widget); // Claim the initial floating reference.
45 // ... 45 // ...
46 // gtk_destroy_widget(widget); // Ask all code to destroy their references. 46 // gtk_destroy_widget(widget); // Ask all code to destroy their references.
47 // g_object_unref(widget); // Destroy the initial reference we had claimed. 47 // g_object_unref(widget); // Destroy the initial reference we had claimed.
48 48
49 #ifndef CHROME_BROWSER_UI_GTK_OWNED_WIDGET_GTK_H_ 49 #ifndef UI_BASE_GTK_OWNED_WIDGET_GTK_H_
50 #define CHROME_BROWSER_UI_GTK_OWNED_WIDGET_GTK_H_ 50 #define UI_BASE_GTK_OWNED_WIDGET_GTK_H_
51 #pragma once 51 #pragma once
52 52
53 #include "base/basictypes.h" 53 #include "base/basictypes.h"
54 #include "ui/base/ui_export.h"
54 55
55 typedef struct _GtkWidget GtkWidget; 56 typedef struct _GtkWidget GtkWidget;
56 57
57 class OwnedWidgetGtk { 58 namespace ui {
59
60 class UI_EXPORT OwnedWidgetGtk {
58 public: 61 public:
59 // Create an instance that isn't managing any ownership. 62 // Create an instance that isn't managing any ownership.
60 OwnedWidgetGtk() : widget_(NULL) { } 63 OwnedWidgetGtk() : widget_(NULL) { }
61 // Create an instance that owns |widget|. 64 // Create an instance that owns |widget|.
62 explicit OwnedWidgetGtk(GtkWidget* widget) : widget_(NULL) { Own(widget); } 65 explicit OwnedWidgetGtk(GtkWidget* widget) : widget_(NULL) { Own(widget); }
63 66
64 ~OwnedWidgetGtk(); 67 ~OwnedWidgetGtk();
65 68
66 // Return the currently owned widget, or NULL if no widget is owned. 69 // Return the currently owned widget, or NULL if no widget is owned.
67 GtkWidget* get() const { return widget_; } 70 GtkWidget* get() const { return widget_; }
(...skipping 13 matching lines...) Expand all
81 // that after gtk_widget_destroy we will be holding the only reference left 84 // that after gtk_widget_destroy we will be holding the only reference left
82 // on the object. We assert this in debug mode to help catch any leaks. 85 // on the object. We assert this in debug mode to help catch any leaks.
83 void Destroy(); 86 void Destroy();
84 87
85 private: 88 private:
86 GtkWidget* widget_; 89 GtkWidget* widget_;
87 90
88 DISALLOW_COPY_AND_ASSIGN(OwnedWidgetGtk); 91 DISALLOW_COPY_AND_ASSIGN(OwnedWidgetGtk);
89 }; 92 };
90 93
91 #endif // CHROME_BROWSER_UI_GTK_OWNED_WIDGET_GTK_H_ 94 } // namespace ui
95
96 #endif // UI_BASE_GTK_OWNED_WIDGET_GTK_H_
OLDNEW
« no previous file with comments | « content/test/data/gtk_key_bindings_test_gtkrc ('k') | ui/base/gtk/owned_widget_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698