summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 22:17:48 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-15 22:17:48 +0000
commit9b5b20a5040735ae626c8915a2d3f48868982e2f (patch)
treef6b19d46af150454c1129c444930ab3a19fd416c /chrome/browser
parent2eb9f48c38411fdb72f268c3b4864acb3683fa20 (diff)
downloadchromium_src-9b5b20a5040735ae626c8915a2d3f48868982e2f.zip
chromium_src-9b5b20a5040735ae626c8915a2d3f48868982e2f.tar.gz
chromium_src-9b5b20a5040735ae626c8915a2d3f48868982e2f.tar.bz2
GTK: Theme the NTP with GTK+ colors.
BUG=29948 TEST=none Review URL: http://codereview.chromium.org/551051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.cc64
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.h10
2 files changed, 65 insertions, 9 deletions
diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc
index 3c0efec..239308e 100644
--- a/chrome/browser/gtk/gtk_theme_provider.cc
+++ b/chrome/browser/gtk/gtk_theme_provider.cc
@@ -53,8 +53,12 @@ const double kMinimumLuminanceDifference = 0.1;
// calculate the border color in GTK theme mode.
const int kBgWeight = 3;
+// Default color for links on the NTP when the GTK+ theme doesn't define a
+// link color. Constant taken from gtklinkbutton.c.
+const GdkColor kDefaultLinkColor = { 0, 0, 0, 0xeeee };
+
// Converts a GdkColor to a SkColor.
-SkColor GdkToSkColor(GdkColor* color) {
+SkColor GdkToSkColor(const GdkColor* color) {
return SkColorSetRGB(color->red >> 8,
color->green >> 8,
color->blue >> 8);
@@ -99,6 +103,7 @@ GtkThemeProvider::GtkThemeProvider()
: BrowserThemeProvider(),
fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) {
fake_label_.Own(gtk_label_new(""));
+ fake_entry_.Own(gtk_entry_new());
// Only realized widgets receive style-set notifications, which we need to
// broadcast new theme images and colors.
@@ -110,6 +115,7 @@ GtkThemeProvider::~GtkThemeProvider() {
profile()->GetPrefs()->RemovePrefObserver(prefs::kUsesSystemTheme, this);
gtk_widget_destroy(fake_window_);
fake_label_.Destroy();
+ fake_entry_.Destroy();
// We have to call this because FreePlatformCached() in ~BrowserThemeProvider
// doesn't call the right virutal FreePlatformCaches.
@@ -369,6 +375,13 @@ GdkPixbuf* GtkThemeProvider::GetDefaultFavicon(bool native) {
return default_bookmark_icon_;
}
+void GtkThemeProvider::ClearAllThemeData() {
+ colors_.clear();
+ tints_.clear();
+
+ BrowserThemeProvider::ClearAllThemeData();
+}
+
void GtkThemeProvider::LoadThemePrefs() {
if (use_gtk_) {
LoadGtkValues();
@@ -502,8 +515,6 @@ void GtkThemeProvider::LoadGtkValues() {
BuildTintedFrameColor(BrowserThemeProvider::COLOR_FRAME_INCOGNITO_INACTIVE,
BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE);
- // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be
- // autogenerated from tints. TODO(erg): Still true?
SetThemeColorFromGtk(BrowserThemeProvider::COLOR_TOOLBAR, &toolbar_color);
SetThemeColorFromGtk(BrowserThemeProvider::COLOR_TAB_TEXT, &label_color);
SetThemeColorFromGtk(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, &label_color);
@@ -549,6 +560,47 @@ void GtkThemeProvider::LoadGtkValues() {
thumb_active_color_ = GdkToSkColor(&thumb_active_color);
thumb_inactive_color_ = GdkToSkColor(&thumb_inactive_color);
track_color_ = GdkToSkColor(&track_color);
+
+ // We pick the text and background colors for the NTP out of the colors for a
+ // GtkEntry. We do this because GtkEntries background color is never the same
+ // as |toolbar_color|, is usually a white, and when it isn't a white,
+ // provides sufficient contrast to |toolbar_color|. Try this out with
+ // Darklooks, HighContrastInverse or ThinIce.
+ GtkStyle* entry_style = gtk_rc_get_style(fake_entry_.get());
+ GdkColor ntp_background = entry_style->base[GTK_STATE_NORMAL];
+ GdkColor ntp_foreground = entry_style->fg[GTK_STATE_NORMAL];
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_BACKGROUND,
+ &ntp_background);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_TEXT,
+ &ntp_foreground);
+
+ // The NTP header is the color that surrounds the current active thumbnail on
+ // the NTP, and acts as the border of the "Recent Links" box. It would be
+ // awesome if they were separated so we could use GetBorderColor() for the
+ // border around the "Recent Links" section, but matching the frame color is
+ // more important.
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_HEADER,
+ &frame_color);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_SECTION,
+ &toolbar_color);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_SECTION_TEXT,
+ &label_color);
+
+ // Override the link color if the theme provides it.
+ const GdkColor* link_color = NULL;
+ gtk_widget_style_get(GTK_WIDGET(fake_window_),
+ "link-color", &link_color, NULL);
+ if (!link_color)
+ link_color = &kDefaultLinkColor;
+
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_LINK,
+ link_color);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_LINK_UNDERLINE,
+ link_color);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_SECTION_LINK,
+ link_color);
+ SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE,
+ link_color);
}
void GtkThemeProvider::LoadDefaultValues() {
@@ -558,11 +610,11 @@ void GtkThemeProvider::LoadDefaultValues() {
track_color_ = SkColorSetRGB(227, 221, 216);
}
-void GtkThemeProvider::SetThemeColorFromGtk(int id, GdkColor* color) {
+void GtkThemeProvider::SetThemeColorFromGtk(int id, const GdkColor* color) {
colors_[id] = GdkToSkColor(color);
}
-void GtkThemeProvider::SetThemeTintFromGtk(int id, GdkColor* color) {
+void GtkThemeProvider::SetThemeTintFromGtk(int id, const GdkColor* color) {
color_utils::HSL default_tint = GetDefaultTint(id);
color_utils::HSL hsl;
color_utils::SkColorToHSL(GdkToSkColor(color), &hsl);
@@ -581,7 +633,7 @@ void GtkThemeProvider::BuildTintedFrameColor(int color_id, int tint_id) {
tints_[tint_id]);
}
-void GtkThemeProvider::SetTintToExactColor(int id, GdkColor* color) {
+void GtkThemeProvider::SetTintToExactColor(int id, const GdkColor* color) {
color_utils::HSL hsl;
color_utils::SkColorToHSL(GdkToSkColor(color), &hsl);
tints_[id] = hsl;
diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h
index 87e3fe2..b8a2379 100644
--- a/chrome/browser/gtk/gtk_theme_provider.h
+++ b/chrome/browser/gtk/gtk_theme_provider.h
@@ -100,6 +100,9 @@ class GtkThemeProvider : public BrowserThemeProvider,
typedef std::map<int, color_utils::HSL> TintMap;
typedef std::map<int, SkBitmap*> ImageCache;
+ // Clears all the GTK color overrides.
+ virtual void ClearAllThemeData();
+
// Load theme data from preferences, possibly picking colors from GTK.
virtual void LoadThemePrefs();
@@ -122,10 +125,10 @@ class GtkThemeProvider : public BrowserThemeProvider,
void LoadDefaultValues();
// Sets the underlying theme colors/tints from a GTK color.
- void SetThemeColorFromGtk(int id, GdkColor* color);
- void SetThemeTintFromGtk(int id, GdkColor* color);
+ void SetThemeColorFromGtk(int id, const GdkColor* color);
+ void SetThemeTintFromGtk(int id, const GdkColor* color);
void BuildTintedFrameColor(int color_id, int tint_id);
- void SetTintToExactColor(int id, GdkColor* color);
+ void SetTintToExactColor(int id, const GdkColor* color);
// Split out from FreePlatformCaches so it can be called in our destructor;
// FreePlatformCaches() is called from the BrowserThemeProvider's destructor,
@@ -155,6 +158,7 @@ class GtkThemeProvider : public BrowserThemeProvider,
// their colors).
GtkWidget* fake_window_;
OwnedWidgetGtk fake_label_;
+ OwnedWidgetGtk fake_entry_;
// A list of all GtkChromeButton instances. We hold on to these to notify
// them of theme changes.