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

Unified Diff: chrome/browser/ui/libgtkui/gtk_util.h

Issue 2803873003: Linux native notifications: Support closing and updating notifications (Closed)
Patch Set: glib_signals.h -> glib_signal.h to fix gn gen --check Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/libgtkui/gtk_util.h
diff --git a/chrome/browser/ui/libgtkui/gtk_util.h b/chrome/browser/ui/libgtkui/gtk_util.h
index 583e0e4ec7e70f15d30bee3d004dd17dab31ff0d..95feec21edce91584df4cc15df4b17aaabd5bf04 100644
--- a/chrome/browser/ui/libgtkui/gtk_util.h
+++ b/chrome/browser/ui/libgtkui/gtk_util.h
@@ -8,6 +8,7 @@
#include <gtk/gtk.h>
#include <string>
+#include "ui/base/glib/scoped_gobject.h"
#include "ui/native_theme/native_theme.h"
namespace aura {
@@ -115,47 +116,14 @@ class CairoSurface {
// |major|.|minor|.|micro|.
bool GtkVersionCheck(int major, int minor = 0, int micro = 0);
-// Similar in spirit to a std::unique_ptr.
-template <typename T>
-class ScopedGObject {
- public:
- explicit ScopedGObject(T* obj) : obj_(obj) {
- // Remove the floating reference from |obj_| if it has one.
- if (g_object_is_floating(obj_))
- g_object_ref_sink(obj_);
- DCHECK(G_OBJECT(obj_)->ref_count == 1);
- }
+using ScopedStyleContext = ScopedGObject<GtkStyleContext>;
+using ScopedCssProvider = ScopedGObject<GtkCssProvider>;
- ScopedGObject(const ScopedGObject<T>& other) = delete;
-
- ScopedGObject(ScopedGObject<T>&& other) : obj_(other.obj_) {
- other.obj_ = nullptr;
- }
-
- ~ScopedGObject() {
- if (obj_)
- Unref();
- }
-
- ScopedGObject<T>& operator=(const ScopedGObject<T>& other) = delete;
-
- ScopedGObject<T>& operator=(ScopedGObject<T>&& other) {
- g_object_unref(obj_);
- obj_ = other.obj_;
- other.obj_ = nullptr;
- return *this;
- }
-
- operator T*() { return obj_; }
-
- private:
- void Unref() { g_object_unref(obj_); }
-
- T* obj_;
-};
+} // namespace libgtkui
+// Template override cannot be in the libgtkui namespace.
template <>
-inline void ScopedGObject<GtkStyleContext>::Unref() {
+inline void libgtkui::ScopedStyleContext::Unref() {
// Versions of GTK earlier than 3.15.4 had a bug where a g_assert
// would be triggered when trying to free a GtkStyleContext that had
// a parent whose only reference was the child context in question.
@@ -165,7 +133,7 @@ inline void ScopedGObject<GtkStyleContext>::Unref() {
while (context) {
GtkStyleContext* parent = gtk_style_context_get_parent(context);
if (parent && G_OBJECT(context)->ref_count == 1 &&
- !GtkVersionCheck(3, 15, 4)) {
+ !libgtkui::GtkVersionCheck(3, 15, 4)) {
g_object_ref(parent);
gtk_style_context_set_parent(context, nullptr);
g_object_unref(context);
@@ -177,8 +145,7 @@ inline void ScopedGObject<GtkStyleContext>::Unref() {
}
}
-typedef ScopedGObject<GtkStyleContext> ScopedStyleContext;
-typedef ScopedGObject<GtkCssProvider> ScopedCssProvider;
+namespace libgtkui {
// Converts ui::NativeTheme::State to GtkStateFlags.
GtkStateFlags StateToStateFlags(ui::NativeTheme::State state);
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_linux.cc ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698