| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/gtk_theme_service.h" | 5 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/nix/xdg_util.h" | 14 #include "base/nix/xdg_util.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 SkColor shifted = color_utils::HSLShift(gfx::GdkColorToSkColor(*frame_color), | 234 SkColor shifted = color_utils::HSLShift(gfx::GdkColorToSkColor(*frame_color), |
| 235 shift); | 235 shift); |
| 236 frame_color->pixel = 0; | 236 frame_color->pixel = 0; |
| 237 frame_color->red = SkColorGetR(shifted) * ui::kSkiaToGDKMultiplier; | 237 frame_color->red = SkColorGetR(shifted) * ui::kSkiaToGDKMultiplier; |
| 238 frame_color->green = SkColorGetG(shifted) * ui::kSkiaToGDKMultiplier; | 238 frame_color->green = SkColorGetG(shifted) * ui::kSkiaToGDKMultiplier; |
| 239 frame_color->blue = SkColorGetB(shifted) * ui::kSkiaToGDKMultiplier; | 239 frame_color->blue = SkColorGetB(shifted) * ui::kSkiaToGDKMultiplier; |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace | 242 } // namespace |
| 243 | 243 |
| 244 GtkWidget* GtkThemeService::icon_widget_ = NULL; | 244 GtkWidget* ThemeServiceGtk::icon_widget_ = NULL; |
| 245 gfx::Image* GtkThemeService::default_folder_icon_ = NULL; | 245 gfx::Image* ThemeServiceGtk::default_folder_icon_ = NULL; |
| 246 gfx::Image* GtkThemeService::default_bookmark_icon_ = NULL; | 246 gfx::Image* ThemeServiceGtk::default_bookmark_icon_ = NULL; |
| 247 | 247 |
| 248 // static | 248 // static |
| 249 GtkThemeService* GtkThemeService::GetFrom(Profile* profile) { | 249 ThemeServiceGtk* ThemeServiceGtk::GetFrom(Profile* profile) { |
| 250 return static_cast<GtkThemeService*>( | 250 return static_cast<ThemeServiceGtk*>( |
| 251 ThemeServiceFactory::GetForProfile(profile)); | 251 ThemeServiceFactory::GetForProfile(profile)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 GtkThemeService::GtkThemeService() | 254 ThemeServiceGtk::ThemeServiceGtk() |
| 255 : ThemeService(), | 255 : ThemeService(), |
| 256 use_gtk_(false), | 256 use_gtk_(false), |
| 257 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)), | 257 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)), |
| 258 fake_frame_(chrome_gtk_frame_new()), | 258 fake_frame_(chrome_gtk_frame_new()), |
| 259 signals_(new ui::GtkSignalRegistrar), | 259 signals_(new ui::GtkSignalRegistrar), |
| 260 fullscreen_icon_set_(NULL) { | 260 fullscreen_icon_set_(NULL) { |
| 261 fake_label_.Own(gtk_label_new("")); | 261 fake_label_.Own(gtk_label_new("")); |
| 262 fake_entry_.Own(gtk_entry_new()); | 262 fake_entry_.Own(gtk_entry_new()); |
| 263 fake_menu_item_.Own(gtk_menu_item_new()); | 263 fake_menu_item_.Own(gtk_menu_item_new()); |
| 264 | 264 |
| 265 // Only realized widgets receive style-set notifications, which we need to | 265 // Only realized widgets receive style-set notifications, which we need to |
| 266 // broadcast new theme images and colors. Only realized widgets have style | 266 // broadcast new theme images and colors. Only realized widgets have style |
| 267 // properties, too, which we query for some colors. | 267 // properties, too, which we query for some colors. |
| 268 gtk_widget_realize(fake_frame_); | 268 gtk_widget_realize(fake_frame_); |
| 269 gtk_widget_realize(fake_window_); | 269 gtk_widget_realize(fake_window_); |
| 270 signals_->Connect(fake_frame_, "style-set", | 270 signals_->Connect(fake_frame_, "style-set", |
| 271 G_CALLBACK(&OnStyleSetThunk), this); | 271 G_CALLBACK(&OnStyleSetThunk), this); |
| 272 } | 272 } |
| 273 | 273 |
| 274 GtkThemeService::~GtkThemeService() { | 274 ThemeServiceGtk::~ThemeServiceGtk() { |
| 275 gtk_widget_destroy(fake_window_); | 275 gtk_widget_destroy(fake_window_); |
| 276 gtk_widget_destroy(fake_frame_); | 276 gtk_widget_destroy(fake_frame_); |
| 277 fake_label_.Destroy(); | 277 fake_label_.Destroy(); |
| 278 fake_entry_.Destroy(); | 278 fake_entry_.Destroy(); |
| 279 fake_menu_item_.Destroy(); | 279 fake_menu_item_.Destroy(); |
| 280 | 280 |
| 281 FreeIconSets(); | 281 FreeIconSets(); |
| 282 | 282 |
| 283 // We have to call this because FreePlatformCached() in ~ThemeService | 283 // We have to call this because FreePlatformCached() in ~ThemeService |
| 284 // doesn't call the right virutal FreePlatformCaches. | 284 // doesn't call the right virutal FreePlatformCaches. |
| 285 FreePlatformCaches(); | 285 FreePlatformCaches(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void GtkThemeService::Init(Profile* profile) { | 288 void ThemeServiceGtk::Init(Profile* profile) { |
| 289 registrar_.Init(profile->GetPrefs()); | 289 registrar_.Init(profile->GetPrefs()); |
| 290 registrar_.Add(prefs::kUsesSystemTheme, this); | 290 registrar_.Add(prefs::kUsesSystemTheme, this); |
| 291 #if defined(OS_CHROMEOS) | 291 #if defined(OS_CHROMEOS) |
| 292 use_gtk_ = false; | 292 use_gtk_ = false; |
| 293 #else | 293 #else |
| 294 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 294 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 295 #endif | 295 #endif |
| 296 ThemeService::Init(profile); | 296 ThemeService::Init(profile); |
| 297 } | 297 } |
| 298 | 298 |
| 299 SkBitmap* GtkThemeService::GetBitmapNamed(int id) const { | 299 SkBitmap* ThemeServiceGtk::GetBitmapNamed(int id) const { |
| 300 // TODO(erg): Remove this const cast. The gfx::Image interface returns its | 300 // TODO(erg): Remove this const cast. The gfx::Image interface returns its |
| 301 // images const. GetBitmapNamed() also should but doesn't and has a million | 301 // images const. GetBitmapNamed() also should but doesn't and has a million |
| 302 // callsites. | 302 // callsites. |
| 303 return const_cast<SkBitmap*>(GetImageNamed(id)->ToSkBitmap()); | 303 return const_cast<SkBitmap*>(GetImageNamed(id)->ToSkBitmap()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 const gfx::Image* GtkThemeService::GetImageNamed(int id) const { | 306 const gfx::Image* ThemeServiceGtk::GetImageNamed(int id) const { |
| 307 // Try to get our cached version: | 307 // Try to get our cached version: |
| 308 ImageCache::const_iterator it = gtk_images_.find(id); | 308 ImageCache::const_iterator it = gtk_images_.find(id); |
| 309 if (it != gtk_images_.end()) | 309 if (it != gtk_images_.end()) |
| 310 return it->second; | 310 return it->second; |
| 311 | 311 |
| 312 if (use_gtk_ && IsOverridableImage(id)) { | 312 if (use_gtk_ && IsOverridableImage(id)) { |
| 313 gfx::Image* image = new gfx::Image(GenerateGtkThemeBitmap(id)); | 313 gfx::Image* image = new gfx::Image(GenerateGtkThemeBitmap(id)); |
| 314 gtk_images_[id] = image; | 314 gtk_images_[id] = image; |
| 315 return image; | 315 return image; |
| 316 } | 316 } |
| 317 | 317 |
| 318 return ThemeService::GetImageNamed(id); | 318 return ThemeService::GetImageNamed(id); |
| 319 } | 319 } |
| 320 | 320 |
| 321 SkColor GtkThemeService::GetColor(int id) const { | 321 SkColor ThemeServiceGtk::GetColor(int id) const { |
| 322 if (use_gtk_) { | 322 if (use_gtk_) { |
| 323 ColorMap::const_iterator it = colors_.find(id); | 323 ColorMap::const_iterator it = colors_.find(id); |
| 324 if (it != colors_.end()) | 324 if (it != colors_.end()) |
| 325 return it->second; | 325 return it->second; |
| 326 } | 326 } |
| 327 | 327 |
| 328 return ThemeService::GetColor(id); | 328 return ThemeService::GetColor(id); |
| 329 } | 329 } |
| 330 | 330 |
| 331 bool GtkThemeService::HasCustomImage(int id) const { | 331 bool ThemeServiceGtk::HasCustomImage(int id) const { |
| 332 if (use_gtk_) | 332 if (use_gtk_) |
| 333 return IsOverridableImage(id); | 333 return IsOverridableImage(id); |
| 334 | 334 |
| 335 return ThemeService::HasCustomImage(id); | 335 return ThemeService::HasCustomImage(id); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void GtkThemeService::InitThemesFor(NotificationObserver* observer) { | 338 void ThemeServiceGtk::InitThemesFor(NotificationObserver* observer) { |
| 339 observer->Observe(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 339 observer->Observe(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 340 content::Source<ThemeService>(this), | 340 content::Source<ThemeService>(this), |
| 341 content::NotificationService::NoDetails()); | 341 content::NotificationService::NoDetails()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void GtkThemeService::SetTheme(const Extension* extension) { | 344 void ThemeServiceGtk::SetTheme(const Extension* extension) { |
| 345 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 345 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| 346 LoadDefaultValues(); | 346 LoadDefaultValues(); |
| 347 ThemeService::SetTheme(extension); | 347 ThemeService::SetTheme(extension); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void GtkThemeService::UseDefaultTheme() { | 350 void ThemeServiceGtk::UseDefaultTheme() { |
| 351 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 351 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| 352 LoadDefaultValues(); | 352 LoadDefaultValues(); |
| 353 ThemeService::UseDefaultTheme(); | 353 ThemeService::UseDefaultTheme(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void GtkThemeService::SetNativeTheme() { | 356 void ThemeServiceGtk::SetNativeTheme() { |
| 357 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 357 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
| 358 ClearAllThemeData(); | 358 ClearAllThemeData(); |
| 359 LoadGtkValues(); | 359 LoadGtkValues(); |
| 360 NotifyThemeChanged(); | 360 NotifyThemeChanged(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 bool GtkThemeService::UsingDefaultTheme() const { | 363 bool ThemeServiceGtk::UsingDefaultTheme() const { |
| 364 return !use_gtk_ && ThemeService::UsingDefaultTheme(); | 364 return !use_gtk_ && ThemeService::UsingDefaultTheme(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool GtkThemeService::UsingNativeTheme() const { | 367 bool ThemeServiceGtk::UsingNativeTheme() const { |
| 368 return use_gtk_; | 368 return use_gtk_; |
| 369 } | 369 } |
| 370 | 370 |
| 371 void GtkThemeService::Observe(int type, | 371 void ThemeServiceGtk::Observe(int type, |
| 372 const content::NotificationSource& source, | 372 const content::NotificationSource& source, |
| 373 const content::NotificationDetails& details) { | 373 const content::NotificationDetails& details) { |
| 374 if ((type == chrome::NOTIFICATION_PREF_CHANGED) && | 374 if ((type == chrome::NOTIFICATION_PREF_CHANGED) && |
| 375 (*content::Details<std::string>(details).ptr() == | 375 (*content::Details<std::string>(details).ptr() == |
| 376 prefs::kUsesSystemTheme)) { | 376 prefs::kUsesSystemTheme)) { |
| 377 #if !defined(OS_CHROMEOS) | 377 #if !defined(OS_CHROMEOS) |
| 378 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 378 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 379 #endif | 379 #endif |
| 380 } else { | 380 } else { |
| 381 ThemeService::Observe(type, source, details); | 381 ThemeService::Observe(type, source, details); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 GtkWidget* GtkThemeService::BuildChromeButton() { | 385 GtkWidget* ThemeServiceGtk::BuildChromeButton() { |
| 386 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); | 386 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); |
| 387 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); | 387 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); |
| 388 chrome_buttons_.push_back(button); | 388 chrome_buttons_.push_back(button); |
| 389 | 389 |
| 390 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), | 390 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), |
| 391 this); | 391 this); |
| 392 return button; | 392 return button; |
| 393 } | 393 } |
| 394 | 394 |
| 395 GtkWidget* GtkThemeService::BuildChromeLinkButton(const std::string& text) { | 395 GtkWidget* ThemeServiceGtk::BuildChromeLinkButton(const std::string& text) { |
| 396 GtkWidget* link_button = gtk_chrome_link_button_new(text.c_str()); | 396 GtkWidget* link_button = gtk_chrome_link_button_new(text.c_str()); |
| 397 gtk_chrome_link_button_set_use_gtk_theme( | 397 gtk_chrome_link_button_set_use_gtk_theme( |
| 398 GTK_CHROME_LINK_BUTTON(link_button), | 398 GTK_CHROME_LINK_BUTTON(link_button), |
| 399 use_gtk_); | 399 use_gtk_); |
| 400 link_buttons_.push_back(link_button); | 400 link_buttons_.push_back(link_button); |
| 401 | 401 |
| 402 signals_->Connect(link_button, "destroy", | 402 signals_->Connect(link_button, "destroy", |
| 403 G_CALLBACK(OnDestroyChromeLinkButtonThunk), this); | 403 G_CALLBACK(OnDestroyChromeLinkButtonThunk), this); |
| 404 | 404 |
| 405 return link_button; | 405 return link_button; |
| 406 } | 406 } |
| 407 | 407 |
| 408 GtkWidget* GtkThemeService::BuildLabel(const std::string& text, | 408 GtkWidget* ThemeServiceGtk::BuildLabel(const std::string& text, |
| 409 GdkColor color) { | 409 GdkColor color) { |
| 410 GtkWidget* label = gtk_label_new(text.empty() ? NULL : text.c_str()); | 410 GtkWidget* label = gtk_label_new(text.empty() ? NULL : text.c_str()); |
| 411 if (!use_gtk_) | 411 if (!use_gtk_) |
| 412 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color); | 412 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color); |
| 413 labels_.insert(std::make_pair(label, color)); | 413 labels_.insert(std::make_pair(label, color)); |
| 414 | 414 |
| 415 signals_->Connect(label, "destroy", G_CALLBACK(OnDestroyLabelThunk), this); | 415 signals_->Connect(label, "destroy", G_CALLBACK(OnDestroyLabelThunk), this); |
| 416 | 416 |
| 417 return label; | 417 return label; |
| 418 } | 418 } |
| 419 | 419 |
| 420 GtkWidget* GtkThemeService::CreateToolbarSeparator() { | 420 GtkWidget* ThemeServiceGtk::CreateToolbarSeparator() { |
| 421 GtkWidget* separator = gtk_vseparator_new(); | 421 GtkWidget* separator = gtk_vseparator_new(); |
| 422 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); | 422 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); |
| 423 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), | 423 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
| 424 kSeparatorPadding, kSeparatorPadding, kSeparatorPadding, 0); | 424 kSeparatorPadding, kSeparatorPadding, kSeparatorPadding, 0); |
| 425 gtk_container_add(GTK_CONTAINER(alignment), separator); | 425 gtk_container_add(GTK_CONTAINER(alignment), separator); |
| 426 | 426 |
| 427 signals_->Connect(separator, "expose-event", | 427 signals_->Connect(separator, "expose-event", |
| 428 G_CALLBACK(OnSeparatorExposeThunk), this); | 428 G_CALLBACK(OnSeparatorExposeThunk), this); |
| 429 return alignment; | 429 return alignment; |
| 430 } | 430 } |
| 431 | 431 |
| 432 GdkColor GtkThemeService::GetGdkColor(int id) const { | 432 GdkColor ThemeServiceGtk::GetGdkColor(int id) const { |
| 433 return gfx::SkColorToGdkColor(GetColor(id)); | 433 return gfx::SkColorToGdkColor(GetColor(id)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 GdkColor GtkThemeService::GetBorderColor() const { | 436 GdkColor ThemeServiceGtk::GetBorderColor() const { |
| 437 GtkStyle* style = gtk_rc_get_style(fake_window_); | 437 GtkStyle* style = gtk_rc_get_style(fake_window_); |
| 438 | 438 |
| 439 GdkColor text; | 439 GdkColor text; |
| 440 GdkColor bg; | 440 GdkColor bg; |
| 441 if (use_gtk_) { | 441 if (use_gtk_) { |
| 442 text = style->text[GTK_STATE_NORMAL]; | 442 text = style->text[GTK_STATE_NORMAL]; |
| 443 bg = style->bg[GTK_STATE_NORMAL]; | 443 bg = style->bg[GTK_STATE_NORMAL]; |
| 444 } else { | 444 } else { |
| 445 text = GetGdkColor(COLOR_BOOKMARK_TEXT); | 445 text = GetGdkColor(COLOR_BOOKMARK_TEXT); |
| 446 bg = GetGdkColor(COLOR_TOOLBAR); | 446 bg = GetGdkColor(COLOR_TOOLBAR); |
| 447 } | 447 } |
| 448 | 448 |
| 449 // Creates a weighted average between the text and base color where | 449 // Creates a weighted average between the text and base color where |
| 450 // the base color counts more than once. | 450 // the base color counts more than once. |
| 451 GdkColor color; | 451 GdkColor color; |
| 452 color.pixel = 0; | 452 color.pixel = 0; |
| 453 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight); | 453 color.red = (text.red + (bg.red * kBgWeight)) / (1 + kBgWeight); |
| 454 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight); | 454 color.green = (text.green + (bg.green * kBgWeight)) / (1 + kBgWeight); |
| 455 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight); | 455 color.blue = (text.blue + (bg.blue * kBgWeight)) / (1 + kBgWeight); |
| 456 | 456 |
| 457 return color; | 457 return color; |
| 458 } | 458 } |
| 459 | 459 |
| 460 GtkIconSet* GtkThemeService::GetIconSetForId(int id) const { | 460 GtkIconSet* ThemeServiceGtk::GetIconSetForId(int id) const { |
| 461 if (id == IDR_FULLSCREEN_MENU_BUTTON) | 461 if (id == IDR_FULLSCREEN_MENU_BUTTON) |
| 462 return fullscreen_icon_set_; | 462 return fullscreen_icon_set_; |
| 463 | 463 |
| 464 return NULL; | 464 return NULL; |
| 465 } | 465 } |
| 466 | 466 |
| 467 void GtkThemeService::GetScrollbarColors(GdkColor* thumb_active_color, | 467 void ThemeServiceGtk::GetScrollbarColors(GdkColor* thumb_active_color, |
| 468 GdkColor* thumb_inactive_color, | 468 GdkColor* thumb_inactive_color, |
| 469 GdkColor* track_color) { | 469 GdkColor* track_color) { |
| 470 const GdkColor* theme_thumb_active = NULL; | 470 const GdkColor* theme_thumb_active = NULL; |
| 471 const GdkColor* theme_thumb_inactive = NULL; | 471 const GdkColor* theme_thumb_inactive = NULL; |
| 472 const GdkColor* theme_trough_color = NULL; | 472 const GdkColor* theme_trough_color = NULL; |
| 473 gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 473 gtk_widget_style_get(GTK_WIDGET(fake_frame_), |
| 474 "scrollbar-slider-prelight-color", &theme_thumb_active, | 474 "scrollbar-slider-prelight-color", &theme_thumb_active, |
| 475 "scrollbar-slider-normal-color", &theme_thumb_inactive, | 475 "scrollbar-slider-normal-color", &theme_thumb_inactive, |
| 476 "scrollbar-trough-color", &theme_trough_color, | 476 "scrollbar-trough-color", &theme_trough_color, |
| 477 NULL); | 477 NULL); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 *thumb_active_color = *theme_thumb_active; | 558 *thumb_active_color = *theme_thumb_active; |
| 559 | 559 |
| 560 if (theme_thumb_inactive) | 560 if (theme_thumb_inactive) |
| 561 *thumb_inactive_color = *theme_thumb_inactive; | 561 *thumb_inactive_color = *theme_thumb_inactive; |
| 562 | 562 |
| 563 if (theme_trough_color) | 563 if (theme_trough_color) |
| 564 *track_color = *theme_trough_color; | 564 *track_color = *theme_trough_color; |
| 565 } | 565 } |
| 566 | 566 |
| 567 // static | 567 // static |
| 568 gfx::Image* GtkThemeService::GetFolderIcon(bool native) { | 568 gfx::Image* ThemeServiceGtk::GetFolderIcon(bool native) { |
| 569 if (native) { | 569 if (native) { |
| 570 if (!icon_widget_) | 570 if (!icon_widget_) |
| 571 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 571 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 572 // We never release our ref, so we will leak this on program shutdown. | 572 // We never release our ref, so we will leak this on program shutdown. |
| 573 if (!default_folder_icon_) { | 573 if (!default_folder_icon_) { |
| 574 GdkPixbuf* pixbuf = gtk_widget_render_icon( | 574 GdkPixbuf* pixbuf = gtk_widget_render_icon( |
| 575 icon_widget_, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); | 575 icon_widget_, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); |
| 576 if (pixbuf) | 576 if (pixbuf) |
| 577 default_folder_icon_ = new gfx::Image(pixbuf); | 577 default_folder_icon_ = new gfx::Image(pixbuf); |
| 578 } | 578 } |
| 579 if (default_folder_icon_) | 579 if (default_folder_icon_) |
| 580 return default_folder_icon_; | 580 return default_folder_icon_; |
| 581 } | 581 } |
| 582 | 582 |
| 583 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 583 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 584 IDR_BOOKMARK_BAR_FOLDER); | 584 IDR_BOOKMARK_BAR_FOLDER); |
| 585 } | 585 } |
| 586 | 586 |
| 587 // static | 587 // static |
| 588 gfx::Image* GtkThemeService::GetDefaultFavicon(bool native) { | 588 gfx::Image* ThemeServiceGtk::GetDefaultFavicon(bool native) { |
| 589 if (native) { | 589 if (native) { |
| 590 if (!icon_widget_) | 590 if (!icon_widget_) |
| 591 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 591 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 592 // We never release our ref, so we will leak this on program shutdown. | 592 // We never release our ref, so we will leak this on program shutdown. |
| 593 if (!default_bookmark_icon_) { | 593 if (!default_bookmark_icon_) { |
| 594 GdkPixbuf* pixbuf = gtk_widget_render_icon( | 594 GdkPixbuf* pixbuf = gtk_widget_render_icon( |
| 595 icon_widget_, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); | 595 icon_widget_, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); |
| 596 if (pixbuf) | 596 if (pixbuf) |
| 597 default_bookmark_icon_ = new gfx::Image(pixbuf); | 597 default_bookmark_icon_ = new gfx::Image(pixbuf); |
| 598 } | 598 } |
| 599 if (default_bookmark_icon_) | 599 if (default_bookmark_icon_) |
| 600 return default_bookmark_icon_; | 600 return default_bookmark_icon_; |
| 601 } | 601 } |
| 602 | 602 |
| 603 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 603 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 604 IDR_DEFAULT_FAVICON); | 604 IDR_DEFAULT_FAVICON); |
| 605 } | 605 } |
| 606 | 606 |
| 607 // static | 607 // static |
| 608 bool GtkThemeService::DefaultUsesSystemTheme() { | 608 bool ThemeServiceGtk::DefaultUsesSystemTheme() { |
| 609 #if defined(OS_CHROMEOS) | 609 #if defined(OS_CHROMEOS) |
| 610 return false; | 610 return false; |
| 611 #else | 611 #else |
| 612 scoped_ptr<base::Environment> env(base::Environment::Create()); | 612 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 613 | 613 |
| 614 switch (base::nix::GetDesktopEnvironment(env.get())) { | 614 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 615 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 615 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
| 616 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 616 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
| 617 return true; | 617 return true; |
| 618 default: | 618 default: |
| 619 return false; | 619 return false; |
| 620 } | 620 } |
| 621 #endif | 621 #endif |
| 622 } | 622 } |
| 623 | 623 |
| 624 void GtkThemeService::ClearAllThemeData() { | 624 void ThemeServiceGtk::ClearAllThemeData() { |
| 625 colors_.clear(); | 625 colors_.clear(); |
| 626 tints_.clear(); | 626 tints_.clear(); |
| 627 | 627 |
| 628 ThemeService::ClearAllThemeData(); | 628 ThemeService::ClearAllThemeData(); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void GtkThemeService::LoadThemePrefs() { | 631 void ThemeServiceGtk::LoadThemePrefs() { |
| 632 if (use_gtk_) { | 632 if (use_gtk_) { |
| 633 LoadGtkValues(); | 633 LoadGtkValues(); |
| 634 } else { | 634 } else { |
| 635 LoadDefaultValues(); | 635 LoadDefaultValues(); |
| 636 ThemeService::LoadThemePrefs(); | 636 ThemeService::LoadThemePrefs(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 RebuildMenuIconSets(); | 639 RebuildMenuIconSets(); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void GtkThemeService::NotifyThemeChanged() { | 642 void ThemeServiceGtk::NotifyThemeChanged() { |
| 643 ThemeService::NotifyThemeChanged(); | 643 ThemeService::NotifyThemeChanged(); |
| 644 | 644 |
| 645 // Notify all GtkChromeButtons of their new rendering mode: | 645 // Notify all GtkChromeButtons of their new rendering mode: |
| 646 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); | 646 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); |
| 647 it != chrome_buttons_.end(); ++it) { | 647 it != chrome_buttons_.end(); ++it) { |
| 648 gtk_chrome_button_set_use_gtk_rendering( | 648 gtk_chrome_button_set_use_gtk_rendering( |
| 649 GTK_CHROME_BUTTON(*it), use_gtk_); | 649 GTK_CHROME_BUTTON(*it), use_gtk_); |
| 650 } | 650 } |
| 651 | 651 |
| 652 for (std::vector<GtkWidget*>::iterator it = link_buttons_.begin(); | 652 for (std::vector<GtkWidget*>::iterator it = link_buttons_.begin(); |
| 653 it != link_buttons_.end(); ++it) { | 653 it != link_buttons_.end(); ++it) { |
| 654 gtk_chrome_link_button_set_use_gtk_theme( | 654 gtk_chrome_link_button_set_use_gtk_theme( |
| 655 GTK_CHROME_LINK_BUTTON(*it), use_gtk_); | 655 GTK_CHROME_LINK_BUTTON(*it), use_gtk_); |
| 656 } | 656 } |
| 657 | 657 |
| 658 for (std::map<GtkWidget*, GdkColor>::iterator it = labels_.begin(); | 658 for (std::map<GtkWidget*, GdkColor>::iterator it = labels_.begin(); |
| 659 it != labels_.end(); ++it) { | 659 it != labels_.end(); ++it) { |
| 660 const GdkColor* color = use_gtk_ ? NULL : &it->second; | 660 const GdkColor* color = use_gtk_ ? NULL : &it->second; |
| 661 gtk_util::SetLabelColor(it->first, color); | 661 gtk_util::SetLabelColor(it->first, color); |
| 662 } | 662 } |
| 663 | 663 |
| 664 Browser* browser = BrowserList::GetLastActive(); | 664 Browser* browser = BrowserList::GetLastActive(); |
| 665 if (browser && browser->window()) { | 665 if (browser && browser->window()) { |
| 666 GtkWindow* window = browser->window()->GetNativeHandle(); | 666 GtkWindow* window = browser->window()->GetNativeHandle(); |
| 667 gtk_util::SetDefaultWindowIcon(window); | 667 gtk_util::SetDefaultWindowIcon(window); |
| 668 gtk_util::SetWindowIcon(window, browser->profile()); | 668 gtk_util::SetWindowIcon(window, browser->profile()); |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 void GtkThemeService::FreePlatformCaches() { | 672 void ThemeServiceGtk::FreePlatformCaches() { |
| 673 ThemeService::FreePlatformCaches(); | 673 ThemeService::FreePlatformCaches(); |
| 674 STLDeleteValues(>k_images_); | 674 STLDeleteValues(>k_images_); |
| 675 } | 675 } |
| 676 | 676 |
| 677 void GtkThemeService::OnStyleSet(GtkWidget* widget, | 677 void ThemeServiceGtk::OnStyleSet(GtkWidget* widget, |
| 678 GtkStyle* previous_style) { | 678 GtkStyle* previous_style) { |
| 679 gfx::Image* default_folder_icon = default_folder_icon_; | 679 gfx::Image* default_folder_icon = default_folder_icon_; |
| 680 gfx::Image* default_bookmark_icon = default_bookmark_icon_; | 680 gfx::Image* default_bookmark_icon = default_bookmark_icon_; |
| 681 default_folder_icon_ = NULL; | 681 default_folder_icon_ = NULL; |
| 682 default_bookmark_icon_ = NULL; | 682 default_bookmark_icon_ = NULL; |
| 683 | 683 |
| 684 if (profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { | 684 if (profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { |
| 685 ClearAllThemeData(); | 685 ClearAllThemeData(); |
| 686 LoadGtkValues(); | 686 LoadGtkValues(); |
| 687 NotifyThemeChanged(); | 687 NotifyThemeChanged(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 RebuildMenuIconSets(); | 690 RebuildMenuIconSets(); |
| 691 | 691 |
| 692 // Free the old icons only after the theme change notification has gone | 692 // Free the old icons only after the theme change notification has gone |
| 693 // through. | 693 // through. |
| 694 if (default_folder_icon) | 694 if (default_folder_icon) |
| 695 delete default_folder_icon; | 695 delete default_folder_icon; |
| 696 if (default_bookmark_icon) | 696 if (default_bookmark_icon) |
| 697 delete default_bookmark_icon; | 697 delete default_bookmark_icon; |
| 698 } | 698 } |
| 699 | 699 |
| 700 void GtkThemeService::LoadGtkValues() { | 700 void ThemeServiceGtk::LoadGtkValues() { |
| 701 // Before we start setting images and values, we have to clear out old, stale | 701 // Before we start setting images and values, we have to clear out old, stale |
| 702 // values. (If we don't do this, we'll regress startup time in the case where | 702 // values. (If we don't do this, we'll regress startup time in the case where |
| 703 // someone installs a heavyweight theme, then goes back to GTK.) | 703 // someone installs a heavyweight theme, then goes back to GTK.) |
| 704 profile()->GetPrefs()->ClearPref(prefs::kCurrentThemeImages); | 704 profile()->GetPrefs()->ClearPref(prefs::kCurrentThemeImages); |
| 705 | 705 |
| 706 GtkStyle* frame_style = gtk_rc_get_style(fake_frame_); | 706 GtkStyle* frame_style = gtk_rc_get_style(fake_frame_); |
| 707 | 707 |
| 708 GtkStyle* window_style = gtk_rc_get_style(fake_window_); | 708 GtkStyle* window_style = gtk_rc_get_style(fake_window_); |
| 709 SetThemeColorFromGtk(ThemeService::COLOR_CONTROL_BACKGROUND, | 709 SetThemeColorFromGtk(ThemeService::COLOR_CONTROL_BACKGROUND, |
| 710 &window_style->bg[GTK_STATE_NORMAL]); | 710 &window_style->bg[GTK_STATE_NORMAL]); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE, | 782 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE, |
| 783 link_color); | 783 link_color); |
| 784 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK, | 784 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK, |
| 785 link_color); | 785 link_color); |
| 786 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE, | 786 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE, |
| 787 link_color); | 787 link_color); |
| 788 | 788 |
| 789 // Generate the colors that we pass to WebKit. | 789 // Generate the colors that we pass to WebKit. |
| 790 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color); | 790 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color); |
| 791 GdkColor thumb_active_color, thumb_inactive_color, track_color; | 791 GdkColor thumb_active_color, thumb_inactive_color, track_color; |
| 792 GtkThemeService::GetScrollbarColors(&thumb_active_color, | 792 ThemeServiceGtk::GetScrollbarColors(&thumb_active_color, |
| 793 &thumb_inactive_color, | 793 &thumb_inactive_color, |
| 794 &track_color); | 794 &track_color); |
| 795 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color); | 795 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color); |
| 796 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color); | 796 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color); |
| 797 track_color_ = gfx::GdkColorToSkColor(track_color); | 797 track_color_ = gfx::GdkColorToSkColor(track_color); |
| 798 | 798 |
| 799 // Some GTK themes only define the text selection colors on the GtkEntry | 799 // Some GTK themes only define the text selection colors on the GtkEntry |
| 800 // class, so we need to use that for getting selection colors. | 800 // class, so we need to use that for getting selection colors. |
| 801 active_selection_bg_color_ = | 801 active_selection_bg_color_ = |
| 802 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); | 802 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); |
| 803 active_selection_fg_color_ = | 803 active_selection_fg_color_ = |
| 804 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); | 804 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); |
| 805 inactive_selection_bg_color_ = | 805 inactive_selection_bg_color_ = |
| 806 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); | 806 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); |
| 807 inactive_selection_fg_color_ = | 807 inactive_selection_fg_color_ = |
| 808 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); | 808 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); |
| 809 } | 809 } |
| 810 | 810 |
| 811 GdkColor GtkThemeService::BuildFrameColors(GtkStyle* frame_style) { | 811 GdkColor ThemeServiceGtk::BuildFrameColors(GtkStyle* frame_style) { |
| 812 const GdkColor* theme_frame = NULL; | 812 const GdkColor* theme_frame = NULL; |
| 813 const GdkColor* theme_inactive_frame = NULL; | 813 const GdkColor* theme_inactive_frame = NULL; |
| 814 const GdkColor* theme_incognito_frame = NULL; | 814 const GdkColor* theme_incognito_frame = NULL; |
| 815 const GdkColor* theme_incognito_inactive_frame = NULL; | 815 const GdkColor* theme_incognito_inactive_frame = NULL; |
| 816 gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 816 gtk_widget_style_get(GTK_WIDGET(fake_frame_), |
| 817 "frame-color", &theme_frame, | 817 "frame-color", &theme_frame, |
| 818 "inactive-frame-color", &theme_inactive_frame, | 818 "inactive-frame-color", &theme_inactive_frame, |
| 819 "incognito-frame-color", &theme_incognito_frame, | 819 "incognito-frame-color", &theme_incognito_frame, |
| 820 "incognito-inactive-frame-color", | 820 "incognito-inactive-frame-color", |
| 821 &theme_incognito_inactive_frame, | 821 &theme_incognito_inactive_frame, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 846 BuildAndSetFrameColor( | 846 BuildAndSetFrameColor( |
| 847 &frame_color, | 847 &frame_color, |
| 848 theme_incognito_inactive_frame, | 848 theme_incognito_inactive_frame, |
| 849 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), | 849 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), |
| 850 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, | 850 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, |
| 851 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); | 851 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); |
| 852 | 852 |
| 853 return frame_color; | 853 return frame_color; |
| 854 } | 854 } |
| 855 | 855 |
| 856 void GtkThemeService::LoadDefaultValues() { | 856 void ThemeServiceGtk::LoadDefaultValues() { |
| 857 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); | 857 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); |
| 858 thumb_active_color_ = SkColorSetRGB(244, 244, 244); | 858 thumb_active_color_ = SkColorSetRGB(244, 244, 244); |
| 859 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); | 859 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); |
| 860 track_color_ = SkColorSetRGB(211, 211, 211); | 860 track_color_ = SkColorSetRGB(211, 211, 211); |
| 861 | 861 |
| 862 active_selection_bg_color_ = SkColorSetRGB(30, 144, 255); | 862 active_selection_bg_color_ = SkColorSetRGB(30, 144, 255); |
| 863 active_selection_fg_color_ = SK_ColorWHITE; | 863 active_selection_fg_color_ = SK_ColorWHITE; |
| 864 inactive_selection_bg_color_ = SkColorSetRGB(200, 200, 200); | 864 inactive_selection_bg_color_ = SkColorSetRGB(200, 200, 200); |
| 865 inactive_selection_fg_color_ = SkColorSetRGB(50, 50, 50); | 865 inactive_selection_fg_color_ = SkColorSetRGB(50, 50, 50); |
| 866 } | 866 } |
| 867 | 867 |
| 868 void GtkThemeService::RebuildMenuIconSets() { | 868 void ThemeServiceGtk::RebuildMenuIconSets() { |
| 869 FreeIconSets(); | 869 FreeIconSets(); |
| 870 | 870 |
| 871 GtkStyle* style = gtk_rc_get_style(fake_menu_item_.get()); | 871 GtkStyle* style = gtk_rc_get_style(fake_menu_item_.get()); |
| 872 | 872 |
| 873 fullscreen_icon_set_ = gtk_icon_set_new(); | 873 fullscreen_icon_set_ = gtk_icon_set_new(); |
| 874 BuildIconFromIDRWithColor(IDR_FULLSCREEN_MENU_BUTTON, | 874 BuildIconFromIDRWithColor(IDR_FULLSCREEN_MENU_BUTTON, |
| 875 style, | 875 style, |
| 876 GTK_STATE_PRELIGHT, | 876 GTK_STATE_PRELIGHT, |
| 877 fullscreen_icon_set_); | 877 fullscreen_icon_set_); |
| 878 BuildIconFromIDRWithColor(IDR_FULLSCREEN_MENU_BUTTON, | 878 BuildIconFromIDRWithColor(IDR_FULLSCREEN_MENU_BUTTON, |
| 879 style, | 879 style, |
| 880 GTK_STATE_NORMAL, | 880 GTK_STATE_NORMAL, |
| 881 fullscreen_icon_set_); | 881 fullscreen_icon_set_); |
| 882 } | 882 } |
| 883 | 883 |
| 884 void GtkThemeService::SetThemeColorFromGtk(int id, const GdkColor* color) { | 884 void ThemeServiceGtk::SetThemeColorFromGtk(int id, const GdkColor* color) { |
| 885 colors_[id] = gfx::GdkColorToSkColor(*color); | 885 colors_[id] = gfx::GdkColorToSkColor(*color); |
| 886 } | 886 } |
| 887 | 887 |
| 888 void GtkThemeService::SetThemeTintFromGtk(int id, const GdkColor* color) { | 888 void ThemeServiceGtk::SetThemeTintFromGtk(int id, const GdkColor* color) { |
| 889 color_utils::HSL default_tint = GetDefaultTint(id); | 889 color_utils::HSL default_tint = GetDefaultTint(id); |
| 890 color_utils::HSL hsl; | 890 color_utils::HSL hsl; |
| 891 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(*color), &hsl); | 891 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(*color), &hsl); |
| 892 | 892 |
| 893 if (default_tint.s != -1) | 893 if (default_tint.s != -1) |
| 894 hsl.s = default_tint.s; | 894 hsl.s = default_tint.s; |
| 895 | 895 |
| 896 if (default_tint.l != -1) | 896 if (default_tint.l != -1) |
| 897 hsl.l = default_tint.l; | 897 hsl.l = default_tint.l; |
| 898 | 898 |
| 899 tints_[id] = hsl; | 899 tints_[id] = hsl; |
| 900 } | 900 } |
| 901 | 901 |
| 902 GdkColor GtkThemeService::BuildAndSetFrameColor(const GdkColor* base, | 902 GdkColor ThemeServiceGtk::BuildAndSetFrameColor(const GdkColor* base, |
| 903 const GdkColor* gtk_base, | 903 const GdkColor* gtk_base, |
| 904 const color_utils::HSL& tint, | 904 const color_utils::HSL& tint, |
| 905 int color_id, | 905 int color_id, |
| 906 int tint_id) { | 906 int tint_id) { |
| 907 GdkColor out_color = *base; | 907 GdkColor out_color = *base; |
| 908 if (gtk_base) { | 908 if (gtk_base) { |
| 909 // The theme author specified a color to use, use it without modification. | 909 // The theme author specified a color to use, use it without modification. |
| 910 out_color = *gtk_base; | 910 out_color = *gtk_base; |
| 911 } else { | 911 } else { |
| 912 // Tint the basic color since this is a heuristic color instead of one | 912 // Tint the basic color since this is a heuristic color instead of one |
| 913 // specified by the theme author. | 913 // specified by the theme author. |
| 914 GdkColorHSLShift(tint, &out_color); | 914 GdkColorHSLShift(tint, &out_color); |
| 915 } | 915 } |
| 916 SetThemeColorFromGtk(color_id, &out_color); | 916 SetThemeColorFromGtk(color_id, &out_color); |
| 917 SetThemeTintFromGtk(tint_id, &out_color); | 917 SetThemeTintFromGtk(tint_id, &out_color); |
| 918 | 918 |
| 919 return out_color; | 919 return out_color; |
| 920 } | 920 } |
| 921 | 921 |
| 922 void GtkThemeService::FreeIconSets() { | 922 void ThemeServiceGtk::FreeIconSets() { |
| 923 if (fullscreen_icon_set_) { | 923 if (fullscreen_icon_set_) { |
| 924 gtk_icon_set_unref(fullscreen_icon_set_); | 924 gtk_icon_set_unref(fullscreen_icon_set_); |
| 925 fullscreen_icon_set_ = NULL; | 925 fullscreen_icon_set_ = NULL; |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 | 928 |
| 929 SkBitmap* GtkThemeService::GenerateGtkThemeBitmap(int id) const { | 929 SkBitmap* ThemeServiceGtk::GenerateGtkThemeBitmap(int id) const { |
| 930 switch (id) { | 930 switch (id) { |
| 931 case IDR_THEME_TOOLBAR: { | 931 case IDR_THEME_TOOLBAR: { |
| 932 GtkStyle* style = gtk_rc_get_style(fake_window_); | 932 GtkStyle* style = gtk_rc_get_style(fake_window_); |
| 933 GdkColor* color = &style->bg[GTK_STATE_NORMAL]; | 933 GdkColor* color = &style->bg[GTK_STATE_NORMAL]; |
| 934 SkBitmap* bitmap = new SkBitmap; | 934 SkBitmap* bitmap = new SkBitmap; |
| 935 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 935 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 936 kToolbarImageWidth, kToolbarImageHeight); | 936 kToolbarImageWidth, kToolbarImageHeight); |
| 937 bitmap->allocPixels(); | 937 bitmap->allocPixels(); |
| 938 bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); | 938 bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); |
| 939 return bitmap; | 939 return bitmap; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 case IDR_OMNIBOX_SEARCH_DARK: | 979 case IDR_OMNIBOX_SEARCH_DARK: |
| 980 case IDR_OMNIBOX_STAR_DARK: { | 980 case IDR_OMNIBOX_STAR_DARK: { |
| 981 return GenerateTintedIcon(id, selected_entry_tint_); | 981 return GenerateTintedIcon(id, selected_entry_tint_); |
| 982 } | 982 } |
| 983 default: { | 983 default: { |
| 984 return GenerateTintedIcon(id, button_tint_); | 984 return GenerateTintedIcon(id, button_tint_); |
| 985 } | 985 } |
| 986 } | 986 } |
| 987 } | 987 } |
| 988 | 988 |
| 989 SkBitmap* GtkThemeService::GenerateFrameImage( | 989 SkBitmap* ThemeServiceGtk::GenerateFrameImage( |
| 990 int color_id, | 990 int color_id, |
| 991 const char* gradient_name) const { | 991 const char* gradient_name) const { |
| 992 // We use two colors: the main color (passed in) and a lightened version of | 992 // We use two colors: the main color (passed in) and a lightened version of |
| 993 // that color (which is supposed to match the light gradient at the top of | 993 // that color (which is supposed to match the light gradient at the top of |
| 994 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). | 994 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). |
| 995 ColorMap::const_iterator it = colors_.find(color_id); | 995 ColorMap::const_iterator it = colors_.find(color_id); |
| 996 DCHECK(it != colors_.end()); | 996 DCHECK(it != colors_.end()); |
| 997 SkColor base = it->second; | 997 SkColor base = it->second; |
| 998 | 998 |
| 999 gfx::CanvasSkia canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), | 999 gfx::CanvasSkia canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1018 shader->unref(); | 1018 shader->unref(); |
| 1019 | 1019 |
| 1020 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); | 1020 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth, | 1023 canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth, |
| 1024 kToolbarImageHeight - gradient_size), base); | 1024 kToolbarImageHeight - gradient_size), base); |
| 1025 return new SkBitmap(canvas.ExtractBitmap()); | 1025 return new SkBitmap(canvas.ExtractBitmap()); |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 SkBitmap* GtkThemeService::GenerateTabImage(int base_id) const { | 1028 SkBitmap* ThemeServiceGtk::GenerateTabImage(int base_id) const { |
| 1029 SkBitmap* base_image = GetBitmapNamed(base_id); | 1029 SkBitmap* base_image = GetBitmapNamed(base_id); |
| 1030 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( | 1030 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( |
| 1031 *base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB)); | 1031 *base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB)); |
| 1032 return new SkBitmap(SkBitmapOperations::CreateTiledBitmap( | 1032 return new SkBitmap(SkBitmapOperations::CreateTiledBitmap( |
| 1033 bg_tint, 0, 0, bg_tint.width(), bg_tint.height())); | 1033 bg_tint, 0, 0, bg_tint.width(), bg_tint.height())); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 SkBitmap* GtkThemeService::GenerateTintedIcon( | 1036 SkBitmap* ThemeServiceGtk::GenerateTintedIcon( |
| 1037 int base_id, | 1037 int base_id, |
| 1038 const color_utils::HSL& tint) const { | 1038 const color_utils::HSL& tint) const { |
| 1039 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1039 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1040 return new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( | 1040 return new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( |
| 1041 *rb.GetBitmapNamed(base_id), tint)); | 1041 *rb.GetBitmapNamed(base_id), tint)); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 void GtkThemeService::GetNormalButtonTintHSL( | 1044 void ThemeServiceGtk::GetNormalButtonTintHSL( |
| 1045 color_utils::HSL* tint) const { | 1045 color_utils::HSL* tint) const { |
| 1046 GtkStyle* window_style = gtk_rc_get_style(fake_window_); | 1046 GtkStyle* window_style = gtk_rc_get_style(fake_window_); |
| 1047 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; | 1047 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; |
| 1048 const GdkColor base_color = window_style->base[GTK_STATE_NORMAL]; | 1048 const GdkColor base_color = window_style->base[GTK_STATE_NORMAL]; |
| 1049 | 1049 |
| 1050 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 1050 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
| 1051 const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL]; | 1051 const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL]; |
| 1052 | 1052 |
| 1053 PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint); | 1053 PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 void GtkThemeService::GetNormalEntryForegroundHSL( | 1056 void ThemeServiceGtk::GetNormalEntryForegroundHSL( |
| 1057 color_utils::HSL* tint) const { | 1057 color_utils::HSL* tint) const { |
| 1058 GtkStyle* window_style = gtk_rc_get_style(fake_window_); | 1058 GtkStyle* window_style = gtk_rc_get_style(fake_window_); |
| 1059 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; | 1059 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; |
| 1060 | 1060 |
| 1061 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); | 1061 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); |
| 1062 const GdkColor text_color = style->text[GTK_STATE_NORMAL]; | 1062 const GdkColor text_color = style->text[GTK_STATE_NORMAL]; |
| 1063 const GdkColor base_color = style->base[GTK_STATE_NORMAL]; | 1063 const GdkColor base_color = style->base[GTK_STATE_NORMAL]; |
| 1064 | 1064 |
| 1065 PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint); | 1065 PickButtonTintFromColors(accent_gdk_color, text_color, base_color, tint); |
| 1066 } | 1066 } |
| 1067 | 1067 |
| 1068 void GtkThemeService::GetSelectedEntryForegroundHSL( | 1068 void ThemeServiceGtk::GetSelectedEntryForegroundHSL( |
| 1069 color_utils::HSL* tint) const { | 1069 color_utils::HSL* tint) const { |
| 1070 // The simplest of all the tints. We just use the selected text in the entry | 1070 // The simplest of all the tints. We just use the selected text in the entry |
| 1071 // since the icons tinted this way will only be displayed against | 1071 // since the icons tinted this way will only be displayed against |
| 1072 // base[GTK_STATE_SELECTED]. | 1072 // base[GTK_STATE_SELECTED]. |
| 1073 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); | 1073 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); |
| 1074 const GdkColor color = style->text[GTK_STATE_SELECTED]; | 1074 const GdkColor color = style->text[GTK_STATE_SELECTED]; |
| 1075 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(color), tint); | 1075 color_utils::SkColorToHSL(gfx::GdkColorToSkColor(color), tint); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 void GtkThemeService::OnDestroyChromeButton(GtkWidget* button) { | 1078 void ThemeServiceGtk::OnDestroyChromeButton(GtkWidget* button) { |
| 1079 std::vector<GtkWidget*>::iterator it = | 1079 std::vector<GtkWidget*>::iterator it = |
| 1080 find(chrome_buttons_.begin(), chrome_buttons_.end(), button); | 1080 find(chrome_buttons_.begin(), chrome_buttons_.end(), button); |
| 1081 if (it != chrome_buttons_.end()) | 1081 if (it != chrome_buttons_.end()) |
| 1082 chrome_buttons_.erase(it); | 1082 chrome_buttons_.erase(it); |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 void GtkThemeService::OnDestroyChromeLinkButton(GtkWidget* button) { | 1085 void ThemeServiceGtk::OnDestroyChromeLinkButton(GtkWidget* button) { |
| 1086 std::vector<GtkWidget*>::iterator it = | 1086 std::vector<GtkWidget*>::iterator it = |
| 1087 find(link_buttons_.begin(), link_buttons_.end(), button); | 1087 find(link_buttons_.begin(), link_buttons_.end(), button); |
| 1088 if (it != link_buttons_.end()) | 1088 if (it != link_buttons_.end()) |
| 1089 link_buttons_.erase(it); | 1089 link_buttons_.erase(it); |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 void GtkThemeService::OnDestroyLabel(GtkWidget* button) { | 1092 void ThemeServiceGtk::OnDestroyLabel(GtkWidget* button) { |
| 1093 std::map<GtkWidget*, GdkColor>::iterator it = labels_.find(button); | 1093 std::map<GtkWidget*, GdkColor>::iterator it = labels_.find(button); |
| 1094 if (it != labels_.end()) | 1094 if (it != labels_.end()) |
| 1095 labels_.erase(it); | 1095 labels_.erase(it); |
| 1096 } | 1096 } |
| 1097 | 1097 |
| 1098 gboolean GtkThemeService::OnSeparatorExpose(GtkWidget* widget, | 1098 gboolean ThemeServiceGtk::OnSeparatorExpose(GtkWidget* widget, |
| 1099 GdkEventExpose* event) { | 1099 GdkEventExpose* event) { |
| 1100 UNSHIPPED_TRACE_EVENT0("ui::gtk", "GtkThemeService::OnSeparatorExpose"); | 1100 UNSHIPPED_TRACE_EVENT0("ui::gtk", "ThemeServiceGtk::OnSeparatorExpose"); |
| 1101 if (UsingNativeTheme()) | 1101 if (UsingNativeTheme()) |
| 1102 return FALSE; | 1102 return FALSE; |
| 1103 | 1103 |
| 1104 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget)); | 1104 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget)); |
| 1105 gdk_cairo_rectangle(cr, &event->area); | 1105 gdk_cairo_rectangle(cr, &event->area); |
| 1106 cairo_clip(cr); | 1106 cairo_clip(cr); |
| 1107 | 1107 |
| 1108 GdkColor bottom_color = GetGdkColor(ThemeService::COLOR_TOOLBAR); | 1108 GdkColor bottom_color = GetGdkColor(ThemeService::COLOR_TOOLBAR); |
| 1109 double bottom_color_rgb[] = { | 1109 double bottom_color_rgb[] = { |
| 1110 static_cast<double>(bottom_color.red / 257) / 255.0, | 1110 static_cast<double>(bottom_color.red / 257) / 255.0, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1133 cairo_new_path(cr); | 1133 cairo_new_path(cr); |
| 1134 cairo_set_line_width(cr, 1.0); | 1134 cairo_set_line_width(cr, 1.0); |
| 1135 cairo_move_to(cr, start_x, allocation.y); | 1135 cairo_move_to(cr, start_x, allocation.y); |
| 1136 cairo_line_to(cr, start_x, allocation.y + allocation.height); | 1136 cairo_line_to(cr, start_x, allocation.y + allocation.height); |
| 1137 cairo_stroke(cr); | 1137 cairo_stroke(cr); |
| 1138 cairo_destroy(cr); | 1138 cairo_destroy(cr); |
| 1139 cairo_pattern_destroy(pattern); | 1139 cairo_pattern_destroy(pattern); |
| 1140 | 1140 |
| 1141 return TRUE; | 1141 return TRUE; |
| 1142 } | 1142 } |
| OLD | NEW |