diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 21:40:32 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 21:40:32 +0000 |
commit | 93623c5d8fd1847dc31b67ed15779a3267a78d97 (patch) | |
tree | e311599b977576d6b94ab47829ccfffcbaaf9fad /chrome/browser/gtk/gtk_theme_provider.cc | |
parent | 9fb89471331ec0b7fad12ffafa505aa6b8425fa5 (diff) | |
download | chromium_src-93623c5d8fd1847dc31b67ed15779a3267a78d97.zip chromium_src-93623c5d8fd1847dc31b67ed15779a3267a78d97.tar.gz chromium_src-93623c5d8fd1847dc31b67ed15779a3267a78d97.tar.bz2 |
re-apply r34183
---------------
linux: theme scrollbars from GTK theme
Pick the color of the slider's thumbpart and rail from the GTK theme.
We cannot match the exact visual appearance of the GTK theme, as
rendering engines can make arbitrary changes to the actual visual
appearance. But by sampling a representative set of pixels, we ensure
that we will at least match the general color scheme.
BUG=10949
patch by <markus [at] chromium>
original review: http://codereview.chromium.org/400027/show
Review URL: http://codereview.chromium.org/479006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/gtk_theme_provider.cc')
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc index c12ec92..4f35110 100644 --- a/chrome/browser/gtk/gtk_theme_provider.cc +++ b/chrome/browser/gtk/gtk_theme_provider.cc @@ -176,6 +176,95 @@ GdkColor GtkThemeProvider::GetBorderColor() const { return color; } +void GtkThemeProvider::GetScrollbarColors(GdkColor* thumb_active_color, + GdkColor* thumb_inactive_color, + GdkColor* track_color, + bool use_gtk_theme) { + if (!use_gtk_theme) { + // If using the default non-GTK colors, pick some reasonable choices of + // different greys. + thumb_active_color->pixel = 0; + thumb_active_color->red = 64250; + thumb_active_color->green = 63736; + thumb_active_color->blue = 62965; + thumb_inactive_color->pixel = 0; + thumb_inactive_color->red = 61680; + thumb_inactive_color->green = 60395; + thumb_inactive_color->blue = 58853; + track_color->pixel = 0; + track_color->red = 58339; + track_color->green = 56797; + track_color->blue = 55512; + return; + } + + // Create window containing scrollbar elements + GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); + GtkWidget* fixed = gtk_fixed_new(); + GtkWidget* scrollbar = gtk_hscrollbar_new(NULL); + gtk_container_add(GTK_CONTAINER(window), fixed); + gtk_container_add(GTK_CONTAINER(fixed), scrollbar); + gtk_widget_realize(window); + gtk_widget_realize(scrollbar); + + // Draw scrollbar thumb part and track into offscreen image + int kWidth = 100; + int kHeight = 20; + GtkStyle* style = gtk_rc_get_style(scrollbar); + GdkPixmap* pm = gdk_pixmap_new(window->window, kWidth, kHeight, -1); + GdkRectangle rect = { 0, 0, kWidth, kHeight }; + unsigned char data[3*kWidth*kHeight]; + for (int i = 0; i < 3; ++i) { + if (i < 2) { + // Thumb part + gtk_paint_slider(style, pm, + i == 0 ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, + GTK_SHADOW_OUT, &rect, scrollbar, "slider", 0, 0, + kWidth, kHeight, GTK_ORIENTATION_HORIZONTAL); + } else { + // Track + gtk_paint_box(style, pm, GTK_STATE_ACTIVE, GTK_SHADOW_IN, &rect, + scrollbar, "trough-upper", 0, 0, kWidth, kHeight); + } + GdkPixbuf* pb = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, + FALSE, 8, kWidth, kHeight, + 3*kWidth, 0, 0); + gdk_pixbuf_get_from_drawable(pb, pm, NULL, 0, 0, 0, 0, kWidth, kHeight); + + // Sample pixels + int components[3] = { 0 }; + for (int y = 2; y < kHeight-2; ++y) { + for (int c = 0; c < 3; ++c) { + // Sample a vertical slice of pixels at about one-thirds from the + // left edge. This allows us to avoid any fixed graphics that might be + // located at the edges or in the center of the scrollbar. + // Each pixel is made up of a red, green, and blue component; taking up + // a total of three bytes. + components[c] += data[3*(kWidth/3 + y*kWidth) + c]; + } + } + GdkColor* color = i == 0 ? thumb_active_color : + i == 1 ? thumb_inactive_color : + track_color; + color->pixel = 0; + // We sampled pixels across the full height of the image, ignoring a two + // pixel border. In some themes, the border has a completely different + // color which we do not want to factor into our average color computation. + // + // We now need to scale the colors from the 0..255 range, to the wider + // 0..65535 range, and we need to actually compute the average color; so, + // we divide by the total number of pixels in the sample. + color->red = components[0] * 65535 / (255*(kHeight-4)); + color->green = components[1] * 65535 / (255*(kHeight-4)); + color->blue = components[2] * 65535 / (255*(kHeight-4)); + + g_object_unref(pb); + } + g_object_unref(pm); + + gtk_widget_destroy(window); +} + CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed( int id, GtkWidget* widget_on_display) { GdkDisplay* display = gtk_widget_get_display(widget_on_display); |