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

Side by Side Diff: chrome/browser/gtk/gtk_theme_provider.cc

Issue 160188: GTK Themes: A gtkrc file can now override our choice of frame color by (Closed)
Patch Set: Make 257 a constant Created 11 years, 4 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 unified diff | Download patch
« no previous file with comments | « base/gfx/gtk_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/gtk_theme_provider.h" 5 #include "chrome/browser/gtk/gtk_theme_provider.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/gfx/gtk_util.h" 9 #include "base/gfx/gtk_util.h"
10 #include "chrome/browser/metrics/user_metrics.h" 10 #include "chrome/browser/metrics/user_metrics.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/skia/include/core/SkColor.h" 21 #include "third_party/skia/include/core/SkColor.h"
22 22
23 namespace { 23 namespace {
24 24
25 // The size of the rendered toolbar image. 25 // The size of the rendered toolbar image.
26 const int kToolbarImageWidth = 64; 26 const int kToolbarImageWidth = 64;
27 const int kToolbarImageHeight = 128; 27 const int kToolbarImageHeight = 128;
28 28
29 const skia::HSL kExactColor = { -1, -1, -1 }; 29 const skia::HSL kExactColor = { -1, -1, -1 };
30 30
31 const skia::HSL kDefaultFrameShift = { -1, -1, 0.4 };
32
31 } // namespace 33 } // namespace
32 34
33 // static 35 // static
34 GtkThemeProvider* GtkThemeProvider::GetFrom(Profile* profile) { 36 GtkThemeProvider* GtkThemeProvider::GetFrom(Profile* profile) {
35 return static_cast<GtkThemeProvider*>(profile->GetThemeProvider()); 37 return static_cast<GtkThemeProvider*>(profile->GetThemeProvider());
36 } 38 }
37 39
38 GtkThemeProvider::GtkThemeProvider() 40 GtkThemeProvider::GtkThemeProvider()
39 : BrowserThemeProvider(), 41 : BrowserThemeProvider(),
40 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) { 42 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 provider->ClearAllThemeData(); 166 provider->ClearAllThemeData();
165 provider->LoadGtkValues(); 167 provider->LoadGtkValues();
166 provider->NotifyThemeChanged(); 168 provider->NotifyThemeChanged();
167 } 169 }
168 } 170 }
169 171
170 void GtkThemeProvider::LoadGtkValues() { 172 void GtkThemeProvider::LoadGtkValues() {
171 GtkStyle* window_style = gtk_rc_get_style(fake_window_); 173 GtkStyle* window_style = gtk_rc_get_style(fake_window_);
172 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); 174 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
173 175
174 SetThemeColorFromGtk(kColorFrame, &window_style->bg[GTK_STATE_SELECTED]); 176 GdkColor frame_color = window_style->bg[GTK_STATE_SELECTED];
177 GdkColor inactive_frame_color = window_style->bg[GTK_STATE_INSENSITIVE];
178 GdkColor button_color = window_style->bg[GTK_STATE_SELECTED];
179
180 GtkSettings* settings = gtk_settings_get_default();
181 bool theme_has_frame_color = false;
182 if (settings) {
183 GHashTable* color_scheme = NULL;
184 g_object_get(settings, "color-hash", &color_scheme, NULL);
185
186 if (color_scheme) {
187 // If we have a "gtk-color-scheme" set in this theme, mine it for hints
188 // about what we should actually set the frame color to.
189 GdkColor* color = NULL;
190 if ((color = static_cast<GdkColor*>(
191 g_hash_table_lookup(color_scheme, "frame_color")))) {
192 frame_color = *color;
193 theme_has_frame_color = true;
194 }
195
196 if ((color = static_cast<GdkColor*>(
197 g_hash_table_lookup(color_scheme, "inactive_frame_color")))) {
198 inactive_frame_color = *color;
199 }
200 }
201 }
202
203 if (!theme_has_frame_color) {
204 // If the theme's gtkrc doesn't explicitly tell us to use a specific frame
205 // color, change the luminosity of the frame color downwards to 80% of what
206 // it currently is. This is in a futile attempt to match the default
207 // metacity and xfwm themes.
208 SkColor shifted =
209 skia::HSLShift(SkColorSetRGB((frame_color.red >> 8),
210 (frame_color.green >> 8),
211 (frame_color.blue >> 8)),
212 kDefaultFrameShift);
213 frame_color.pixel = 0;
214 frame_color.red = SkColorGetR(shifted) * kSkiaToGDKMultiplier;
215 frame_color.green = SkColorGetG(shifted) * kSkiaToGDKMultiplier;
216 frame_color.blue = SkColorGetB(shifted) * kSkiaToGDKMultiplier;
217 }
218
219 SetThemeColorFromGtk(kColorFrame, &frame_color);
175 // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be 220 // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be
176 // autogenerated from tints. 221 // autogenerated from tints.
177 SetThemeColorFromGtk(kColorToolbar, 222 SetThemeColorFromGtk(kColorToolbar,
178 &window_style->bg[GTK_STATE_NORMAL]); 223 &window_style->bg[GTK_STATE_NORMAL]);
179 SetThemeColorFromGtk(kColorTabText, 224 SetThemeColorFromGtk(kColorTabText,
180 &label_style->text[GTK_STATE_NORMAL]); 225 &label_style->text[GTK_STATE_NORMAL]);
181 SetThemeColorFromGtk(kColorBackgroundTabText, 226 SetThemeColorFromGtk(kColorBackgroundTabText,
182 &label_style->text[GTK_STATE_NORMAL]); 227 &label_style->text[GTK_STATE_NORMAL]);
183 SetThemeColorFromGtk(kColorBookmarkText, 228 SetThemeColorFromGtk(kColorBookmarkText,
184 &label_style->text[GTK_STATE_NORMAL]); 229 &label_style->text[GTK_STATE_NORMAL]);
185 SetThemeColorFromGtk(kColorControlBackground, 230 SetThemeColorFromGtk(kColorControlBackground,
186 &window_style->bg[GTK_STATE_NORMAL]); 231 &window_style->bg[GTK_STATE_NORMAL]);
187 SetThemeColorFromGtk(kColorButtonBackground, 232 SetThemeColorFromGtk(kColorButtonBackground,
188 &window_style->bg[GTK_STATE_NORMAL]); 233 &window_style->bg[GTK_STATE_NORMAL]);
189 234
190 SetThemeTintFromGtk(kTintButtons, &window_style->bg[GTK_STATE_SELECTED], 235 SetThemeTintFromGtk(kTintButtons, &button_color,
191 kDefaultTintButtons); 236 kDefaultTintButtons);
192 SetThemeTintFromGtk(kTintFrame, &window_style->bg[GTK_STATE_SELECTED], 237 SetThemeTintFromGtk(kTintFrame, &frame_color,
193 kDefaultTintFrame); 238 kDefaultTintFrame);
194 SetThemeTintFromGtk(kTintFrameIncognito, 239 SetThemeTintFromGtk(kTintFrameIncognito,
195 &window_style->bg[GTK_STATE_SELECTED], 240 &frame_color,
196 kDefaultTintFrameIncognito); 241 kDefaultTintFrameIncognito);
197 SetThemeTintFromGtk(kTintBackgroundTab, 242 SetThemeTintFromGtk(kTintBackgroundTab,
198 &window_style->bg[GTK_STATE_SELECTED], 243 &frame_color,
199 kDefaultTintBackgroundTab); 244 kDefaultTintBackgroundTab);
200 245
201 // The inactive color/tint is special: We *must* use the exact insensitive 246 // The inactive color/tint is special: We *must* use the exact insensitive
202 // color for all inactive windows, otherwise we end up neon pink half the 247 // color for all inactive windows, otherwise we end up neon pink half the
203 // time. 248 // time.
204 SetThemeColorFromGtk(kColorFrameInactive, 249 SetThemeColorFromGtk(kColorFrameInactive, &inactive_frame_color);
205 &window_style->bg[GTK_STATE_INSENSITIVE]); 250 SetThemeTintFromGtk(kTintFrameInactive, &inactive_frame_color,
206 SetThemeTintFromGtk(kTintFrameInactive,
207 &window_style->bg[GTK_STATE_INSENSITIVE],
208 kExactColor); 251 kExactColor);
209 SetThemeTintFromGtk(kTintFrameIncognitoInactive, 252 SetThemeTintFromGtk(kTintFrameIncognitoInactive, &inactive_frame_color,
210 &window_style->bg[GTK_STATE_INSENSITIVE],
211 kExactColor); 253 kExactColor);
212 254
213 GenerateFrameColors(); 255 GenerateFrameColors();
214 GenerateFrameImages(); 256 GenerateFrameImages();
215 } 257 }
216 258
217 void GtkThemeProvider::SetThemeColorFromGtk(const char* id, GdkColor* color) { 259 void GtkThemeProvider::SetThemeColorFromGtk(const char* id, GdkColor* color) {
218 SetColor(id, SkColorSetRGB(color->red >> 8, 260 SetColor(id, SkColorSetRGB(color->red >> 8,
219 color->green >> 8, 261 color->green >> 8,
220 color->blue >> 8)); 262 color->blue >> 8));
(...skipping 14 matching lines...) Expand all
235 } 277 }
236 278
237 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, 279 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button,
238 GtkThemeProvider* provider) { 280 GtkThemeProvider* provider) {
239 std::vector<GtkWidget*>::iterator it = 281 std::vector<GtkWidget*>::iterator it =
240 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), 282 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(),
241 button); 283 button);
242 if (it != provider->chrome_buttons_.end()) 284 if (it != provider->chrome_buttons_.end())
243 provider->chrome_buttons_.erase(it); 285 provider->chrome_buttons_.erase(it);
244 } 286 }
OLDNEW
« no previous file with comments | « base/gfx/gtk_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698