diff options
-rw-r--r-- | base/gfx/gtk_util.h | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.cc | 64 |
2 files changed, 57 insertions, 12 deletions
diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h index c219dab..523f7bf 100644 --- a/base/gfx/gtk_util.h +++ b/base/gfx/gtk_util.h @@ -18,10 +18,13 @@ typedef struct _GdkRegion GdkRegion; class SkBitmap; +const int kSkiaToGDKMultiplier = 257; + // Define a macro for creating GdkColors from RGB values. This is a macro to // allow static construction of literals, etc. Use this like: // GdkColor white = GDK_COLOR_RGB(0xff, 0xff, 0xff); -#define GDK_COLOR_RGB(r, g, b) {0, r * 257, g * 257, b * 257} +#define GDK_COLOR_RGB(r, g, b) {0, r * kSkiaToGDKMultiplier, \ + g * kSkiaToGDKMultiplier, b * kSkiaToGDKMultiplier} namespace gfx { diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc index 45ec594..a9e331b 100644 --- a/chrome/browser/gtk/gtk_theme_provider.cc +++ b/chrome/browser/gtk/gtk_theme_provider.cc @@ -28,6 +28,8 @@ const int kToolbarImageHeight = 128; const skia::HSL kExactColor = { -1, -1, -1 }; +const skia::HSL kDefaultFrameShift = { -1, -1, 0.4 }; + } // namespace // static @@ -171,7 +173,50 @@ void GtkThemeProvider::LoadGtkValues() { GtkStyle* window_style = gtk_rc_get_style(fake_window_); GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); - SetThemeColorFromGtk(kColorFrame, &window_style->bg[GTK_STATE_SELECTED]); + GdkColor frame_color = window_style->bg[GTK_STATE_SELECTED]; + GdkColor inactive_frame_color = window_style->bg[GTK_STATE_INSENSITIVE]; + GdkColor button_color = window_style->bg[GTK_STATE_SELECTED]; + + GtkSettings* settings = gtk_settings_get_default(); + bool theme_has_frame_color = false; + if (settings) { + GHashTable* color_scheme = NULL; + g_object_get(settings, "color-hash", &color_scheme, NULL); + + if (color_scheme) { + // If we have a "gtk-color-scheme" set in this theme, mine it for hints + // about what we should actually set the frame color to. + GdkColor* color = NULL; + if ((color = static_cast<GdkColor*>( + g_hash_table_lookup(color_scheme, "frame_color")))) { + frame_color = *color; + theme_has_frame_color = true; + } + + if ((color = static_cast<GdkColor*>( + g_hash_table_lookup(color_scheme, "inactive_frame_color")))) { + inactive_frame_color = *color; + } + } + } + + if (!theme_has_frame_color) { + // If the theme's gtkrc doesn't explicitly tell us to use a specific frame + // color, change the luminosity of the frame color downwards to 80% of what + // it currently is. This is in a futile attempt to match the default + // metacity and xfwm themes. + SkColor shifted = + skia::HSLShift(SkColorSetRGB((frame_color.red >> 8), + (frame_color.green >> 8), + (frame_color.blue >> 8)), + kDefaultFrameShift); + frame_color.pixel = 0; + frame_color.red = SkColorGetR(shifted) * kSkiaToGDKMultiplier; + frame_color.green = SkColorGetG(shifted) * kSkiaToGDKMultiplier; + frame_color.blue = SkColorGetB(shifted) * kSkiaToGDKMultiplier; + } + + SetThemeColorFromGtk(kColorFrame, &frame_color); // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be // autogenerated from tints. SetThemeColorFromGtk(kColorToolbar, @@ -187,27 +232,24 @@ void GtkThemeProvider::LoadGtkValues() { SetThemeColorFromGtk(kColorButtonBackground, &window_style->bg[GTK_STATE_NORMAL]); - SetThemeTintFromGtk(kTintButtons, &window_style->bg[GTK_STATE_SELECTED], + SetThemeTintFromGtk(kTintButtons, &button_color, kDefaultTintButtons); - SetThemeTintFromGtk(kTintFrame, &window_style->bg[GTK_STATE_SELECTED], + SetThemeTintFromGtk(kTintFrame, &frame_color, kDefaultTintFrame); SetThemeTintFromGtk(kTintFrameIncognito, - &window_style->bg[GTK_STATE_SELECTED], + &frame_color, kDefaultTintFrameIncognito); SetThemeTintFromGtk(kTintBackgroundTab, - &window_style->bg[GTK_STATE_SELECTED], + &frame_color, kDefaultTintBackgroundTab); // The inactive color/tint is special: We *must* use the exact insensitive // color for all inactive windows, otherwise we end up neon pink half the // time. - SetThemeColorFromGtk(kColorFrameInactive, - &window_style->bg[GTK_STATE_INSENSITIVE]); - SetThemeTintFromGtk(kTintFrameInactive, - &window_style->bg[GTK_STATE_INSENSITIVE], + SetThemeColorFromGtk(kColorFrameInactive, &inactive_frame_color); + SetThemeTintFromGtk(kTintFrameInactive, &inactive_frame_color, kExactColor); - SetThemeTintFromGtk(kTintFrameIncognitoInactive, - &window_style->bg[GTK_STATE_INSENSITIVE], + SetThemeTintFromGtk(kTintFrameIncognitoInactive, &inactive_frame_color, kExactColor); GenerateFrameColors(); |