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

Unified Diff: chrome/browser/ui/libgtkui/gtk_ui.cc

Issue 2715153002: Gtk3: Refactor GtkButtonImageSource::GetImageForScale (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | chrome/browser/ui/libgtkui/gtk_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/libgtkui/gtk_ui.cc
diff --git a/chrome/browser/ui/libgtkui/gtk_ui.cc b/chrome/browser/ui/libgtkui/gtk_ui.cc
index 0e08463e3f649520785b67eb03806591eb8fb115..574806fa97177c741d76eda61fee6153945fb856 100644
--- a/chrome/browser/ui/libgtkui/gtk_ui.cc
+++ b/chrome/browser/ui/libgtkui/gtk_ui.cc
@@ -116,6 +116,12 @@ class GtkButtonImageSource : public gfx::ImageSkiaSource {
border.allocN32Pixels(width, height);
border.eraseColor(0);
+ cairo_surface_t* surface = cairo_image_surface_create_for_data(
+ static_cast<unsigned char*>(border.getAddr(0, 0)), CAIRO_FORMAT_ARGB32,
+ width, height, width * 4);
+ cairo_t* cr = cairo_create(surface);
+
+#if GTK_MAJOR_VERSION == 2
// Create a temporary GTK button to snapshot
GtkWidget* window = gtk_offscreen_window_new();
GtkWidget* button = gtk_toggle_button_new();
@@ -133,12 +139,6 @@ class GtkButtonImageSource : public gfx::ImageSkiaSource {
gtk_widget_show_all(window);
- cairo_surface_t* surface = cairo_image_surface_create_for_data(
- static_cast<unsigned char*>(border.getAddr(0, 0)), CAIRO_FORMAT_ARGB32,
- width, height, width * 4);
- cairo_t* cr = cairo_create(surface);
-
-#if GTK_MAJOR_VERSION == 2
if (focus_)
GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS);
@@ -161,8 +161,18 @@ class GtkButtonImageSource : public gfx::ImageSkiaSource {
g_object_unref(pixbuf);
g_object_unref(pixmap);
+
+ gtk_widget_destroy(window);
#else
- GtkStyleContext* context = gtk_widget_get_style_context(button);
+ ScopedStyleContext context = GetStyleContextFromCss(
+ is_blue_ ? "GtkButton#button.default.suggested-action"
+ : "GtkButton#button");
+ GtkStateFlags state_flags = StateToStateFlags(state_);
+ if (focus_) {
+ state_flags =
+ static_cast<GtkStateFlags>(state_flags | GTK_STATE_FLAG_FOCUSED);
+ }
+ gtk_style_context_set_state(context, state_flags);
gtk_render_background(context, cr, 0, 0, width, height);
gtk_render_frame(context, cr, 0, 0, width, height);
if (focus_)
@@ -172,8 +182,6 @@ class GtkButtonImageSource : public gfx::ImageSkiaSource {
cairo_destroy(cr);
cairo_surface_destroy(surface);
- gtk_widget_destroy(window);
-
return gfx::ImageSkiaRep(border, scale);
}
« no previous file with comments | « no previous file | chrome/browser/ui/libgtkui/gtk_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698