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

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

Issue 2588993002: Gtk3: Refactor NativeThemeGtk3 to use foreign drawing only (Closed)
Patch Set: Add color cache Created 3 years, 11 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/ui/libgtkui/gtk_ui.cc ('k') | chrome/browser/ui/libgtkui/gtk_util.cc » ('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 ab174c20d44d060521c01df5d06b2f5dea3d391e..fc9aa31cd68deaad3d78de92835ef7c98e3997b0 100644
--- a/chrome/browser/ui/libgtkui/gtk_util.h
+++ b/chrome/browser/ui/libgtkui/gtk_util.h
@@ -67,6 +67,74 @@ aura::Window* GetAuraTransientParent(GtkWidget* dialog);
// Clears the transient parent for |dialog|.
void ClearAuraTransientParent(GtkWidget* dialog);
+#if GTK_MAJOR_VERSION > 2
+template <typename T>
+class ScopedGObject {
+ public:
+ explicit ScopedGObject(T* obj) : obj_(obj) {
+ // Increase the reference count of |obj_|, removing the floating
+ // reference if it has one.
+ g_object_ref_sink(obj_);
+ }
+
+ ScopedGObject(const ScopedGObject<T>& other) : obj_(other.obj_) {
+ g_object_ref(obj_);
+ }
+
+ ScopedGObject(ScopedGObject<T>&& other) : obj_(other.obj_) {
+ other.obj_ = nullptr;
+ }
+
+ ~ScopedGObject() {
+ if (obj_)
+ g_object_unref(obj_);
+ }
+
+ ScopedGObject<T>& operator=(const ScopedGObject<T>& other) {
+ g_object_ref(other.obj_);
+ g_object_unref(obj_);
+ obj_ = other.obj_;
+ return *this;
+ }
+
+ ScopedGObject<T>& operator=(ScopedGObject<T>&& other) {
+ g_object_unref(obj_);
+ obj_ = other.obj_;
+ other.obj_ = nullptr;
+ return *this;
+ }
+
+ operator T*() { return obj_; }
+
+ private:
+ T* obj_;
+};
+
+typedef ScopedGObject<GtkStyleContext> ScopedStyleContext;
+
+// Parses |css_selector| into a GtkStyleContext. The format is a
+// sequence of whitespace-separated objects. Each object may have at
+// most one object name at the beginning of the string, and any number
+// of '.'-prefixed classes and ':'-prefixed pseudoclasses. An example
+// is "GtkButton.button.suggested-action:hover:active". The caller
+// must g_object_unref() the returned context.
+ScopedStyleContext GetStyleContextFromCss(const char* css_selector);
+
+// Get the 'color' property from the style context created by
+// GetStyleContextFromCss(|css_selector|).
+SkColor GetFGColor(const char* css_selector);
+
+// Renders a background from the style context created by
+// GetStyleContextFromCss(|css_selector|) into a single pixel and
+// returns the color.
+SkColor GetBGColor(const char* css_selector);
+
+// If there is a border, renders the border from the style context
+// created by GetStyleContextFromCss(|css_selector|) into a single
+// pixel and returns the color. Otherwise returns kInvalidColor.
+SkColor GetBorderColor(const char* css_selector);
+#endif
+
} // namespace libgtkui
#endif // CHROME_BROWSER_UI_LIBGTKUI_GTK_UTIL_H_
« no previous file with comments | « chrome/browser/ui/libgtkui/gtk_ui.cc ('k') | chrome/browser/ui/libgtkui/gtk_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698