OLD | NEW |
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 "app/gfx/color_utils.h" | 9 #include "app/gfx/color_utils.h" |
10 #include "app/gfx/gtk_util.h" | 10 #include "app/gfx/gtk_util.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 void GtkThemeProvider::InitThemesFor(NotificationObserver* observer) { | 166 void GtkThemeProvider::InitThemesFor(NotificationObserver* observer) { |
167 observer->Observe(NotificationType::BROWSER_THEME_CHANGED, | 167 observer->Observe(NotificationType::BROWSER_THEME_CHANGED, |
168 Source<ThemeProvider>(this), | 168 Source<ThemeProvider>(this), |
169 NotificationService::NoDetails()); | 169 NotificationService::NoDetails()); |
170 } | 170 } |
171 | 171 |
172 void GtkThemeProvider::SetTheme(Extension* extension) { | 172 void GtkThemeProvider::SetTheme(Extension* extension) { |
173 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 173 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| 174 LoadDefaultValues(); |
174 BrowserThemeProvider::SetTheme(extension); | 175 BrowserThemeProvider::SetTheme(extension); |
175 } | 176 } |
176 | 177 |
177 void GtkThemeProvider::UseDefaultTheme() { | 178 void GtkThemeProvider::UseDefaultTheme() { |
178 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 179 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| 180 LoadDefaultValues(); |
179 BrowserThemeProvider::UseDefaultTheme(); | 181 BrowserThemeProvider::UseDefaultTheme(); |
180 } | 182 } |
181 | 183 |
182 void GtkThemeProvider::SetNativeTheme() { | 184 void GtkThemeProvider::SetNativeTheme() { |
183 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 185 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
184 ClearAllThemeData(); | 186 ClearAllThemeData(); |
185 LoadGtkValues(); | 187 LoadGtkValues(); |
186 NotifyThemeChanged(); | 188 NotifyThemeChanged(); |
187 } | 189 } |
188 | 190 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 color.pixel = 0; | 233 color.pixel = 0; |
232 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight); | 234 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight); |
233 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight); | 235 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight); |
234 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight); | 236 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight); |
235 | 237 |
236 return color; | 238 return color; |
237 } | 239 } |
238 | 240 |
239 void GtkThemeProvider::GetScrollbarColors(GdkColor* thumb_active_color, | 241 void GtkThemeProvider::GetScrollbarColors(GdkColor* thumb_active_color, |
240 GdkColor* thumb_inactive_color, | 242 GdkColor* thumb_inactive_color, |
241 GdkColor* track_color, | 243 GdkColor* track_color) { |
242 bool use_gtk_theme) { | |
243 if (!use_gtk_theme) { | |
244 // If using the default non-GTK colors, pick some reasonable choices of | |
245 // different greys. | |
246 thumb_active_color->pixel = 0; | |
247 thumb_active_color->red = 64250; | |
248 thumb_active_color->green = 63736; | |
249 thumb_active_color->blue = 62965; | |
250 thumb_inactive_color->pixel = 0; | |
251 thumb_inactive_color->red = 61680; | |
252 thumb_inactive_color->green = 60395; | |
253 thumb_inactive_color->blue = 58853; | |
254 track_color->pixel = 0; | |
255 track_color->red = 58339; | |
256 track_color->green = 56797; | |
257 track_color->blue = 55512; | |
258 return; | |
259 } | |
260 | |
261 // Create window containing scrollbar elements | 244 // Create window containing scrollbar elements |
262 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); | 245 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); |
263 GtkWidget* fixed = gtk_fixed_new(); | 246 GtkWidget* fixed = gtk_fixed_new(); |
264 GtkWidget* scrollbar = gtk_hscrollbar_new(NULL); | 247 GtkWidget* scrollbar = gtk_hscrollbar_new(NULL); |
265 gtk_container_add(GTK_CONTAINER(window), fixed); | 248 gtk_container_add(GTK_CONTAINER(window), fixed); |
266 gtk_container_add(GTK_CONTAINER(fixed), scrollbar); | 249 gtk_container_add(GTK_CONTAINER(fixed), scrollbar); |
267 gtk_widget_realize(window); | 250 gtk_widget_realize(window); |
268 gtk_widget_realize(scrollbar); | 251 gtk_widget_realize(scrollbar); |
269 | 252 |
270 // Draw scrollbar thumb part and track into offscreen image | 253 // Draw scrollbar thumb part and track into offscreen image |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 366 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
384 static GdkPixbuf* default_bookmark_icon_ = rb.GetPixbufNamed( | 367 static GdkPixbuf* default_bookmark_icon_ = rb.GetPixbufNamed( |
385 IDR_DEFAULT_FAVICON); | 368 IDR_DEFAULT_FAVICON); |
386 return default_bookmark_icon_; | 369 return default_bookmark_icon_; |
387 } | 370 } |
388 | 371 |
389 void GtkThemeProvider::LoadThemePrefs() { | 372 void GtkThemeProvider::LoadThemePrefs() { |
390 if (use_gtk_) { | 373 if (use_gtk_) { |
391 LoadGtkValues(); | 374 LoadGtkValues(); |
392 } else { | 375 } else { |
| 376 LoadDefaultValues(); |
393 BrowserThemeProvider::LoadThemePrefs(); | 377 BrowserThemeProvider::LoadThemePrefs(); |
394 } | 378 } |
395 } | 379 } |
396 | 380 |
397 void GtkThemeProvider::NotifyThemeChanged() { | 381 void GtkThemeProvider::NotifyThemeChanged() { |
398 BrowserThemeProvider::NotifyThemeChanged(); | 382 BrowserThemeProvider::NotifyThemeChanged(); |
399 | 383 |
400 // Notify all GtkChromeButtons of their new rendering mode: | 384 // Notify all GtkChromeButtons of their new rendering mode: |
401 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); | 385 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); |
402 it != chrome_buttons_.end(); ++it) { | 386 it != chrome_buttons_.end(); ++it) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 533 |
550 // The inactive color/tint is special: We *must* use the exact insensitive | 534 // The inactive color/tint is special: We *must* use the exact insensitive |
551 // color for all inactive windows, otherwise we end up neon pink half the | 535 // color for all inactive windows, otherwise we end up neon pink half the |
552 // time. | 536 // time. |
553 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_FRAME_INACTIVE, | 537 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_FRAME_INACTIVE, |
554 &inactive_frame_color); | 538 &inactive_frame_color); |
555 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INACTIVE, | 539 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INACTIVE, |
556 &inactive_frame_color); | 540 &inactive_frame_color); |
557 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE, | 541 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE, |
558 &inactive_frame_color); | 542 &inactive_frame_color); |
| 543 |
| 544 focus_ring_color_ = GdkToSkColor(&button_color); |
| 545 GdkColor thumb_active_color, thumb_inactive_color, track_color; |
| 546 GtkThemeProvider::GetScrollbarColors(&thumb_active_color, |
| 547 &thumb_inactive_color, |
| 548 &track_color); |
| 549 thumb_active_color_ = GdkToSkColor(&thumb_active_color); |
| 550 thumb_inactive_color_ = GdkToSkColor(&thumb_inactive_color); |
| 551 track_color_ = GdkToSkColor(&track_color); |
| 552 } |
| 553 |
| 554 void GtkThemeProvider::LoadDefaultValues() { |
| 555 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); |
| 556 thumb_active_color_ = SkColorSetRGB(250, 248, 245); |
| 557 thumb_inactive_color_ = SkColorSetRGB(240, 235, 229); |
| 558 track_color_ = SkColorSetRGB(227, 221, 216); |
559 } | 559 } |
560 | 560 |
561 void GtkThemeProvider::SetThemeColorFromGtk(int id, GdkColor* color) { | 561 void GtkThemeProvider::SetThemeColorFromGtk(int id, GdkColor* color) { |
562 colors_[id] = GdkToSkColor(color); | 562 colors_[id] = GdkToSkColor(color); |
563 } | 563 } |
564 | 564 |
565 void GtkThemeProvider::SetThemeTintFromGtk(int id, GdkColor* color) { | 565 void GtkThemeProvider::SetThemeTintFromGtk(int id, GdkColor* color) { |
566 color_utils::HSL default_tint = GetDefaultTint(id); | 566 color_utils::HSL default_tint = GetDefaultTint(id); |
567 color_utils::HSL hsl; | 567 color_utils::HSL hsl; |
568 color_utils::SkColorToHSL(GdkToSkColor(color), &hsl); | 568 color_utils::SkColorToHSL(GdkToSkColor(color), &hsl); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 655 } |
656 | 656 |
657 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, | 657 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, |
658 GtkThemeProvider* provider) { | 658 GtkThemeProvider* provider) { |
659 std::vector<GtkWidget*>::iterator it = | 659 std::vector<GtkWidget*>::iterator it = |
660 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), | 660 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), |
661 button); | 661 button); |
662 if (it != provider->chrome_buttons_.end()) | 662 if (it != provider->chrome_buttons_.end()) |
663 provider->chrome_buttons_.erase(it); | 663 provider->chrome_buttons_.erase(it); |
664 } | 664 } |
OLD | NEW |