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

Side by Side Diff: chrome/browser/ui/gtk/gtk_theme_service.cc

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

Powered by Google App Engine
This is Rietveld 408576698