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

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

Issue 499004: Try 2: Completely redo how themes are stored on disk and processed at install time. (Closed)
Patch Set: Created 11 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/gtk_theme_provider.h" 5 #include "chrome/browser/gtk/gtk_theme_provider.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gfx/color_utils.h" 9 #include "app/gfx/color_utils.h"
10 #include "app/gfx/gtk_util.h" 10 #include "app/gfx/gtk_util.h"
11 #include "app/gfx/skbitmap_operations.h"
12 #include "base/stl_util-inl.h"
11 #include "chrome/browser/metrics/user_metrics.h" 13 #include "chrome/browser/metrics/user_metrics.h"
12 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
13 #include "chrome/browser/gtk/cairo_cached_surface.h" 15 #include "chrome/browser/gtk/cairo_cached_surface.h"
14 #include "chrome/browser/gtk/gtk_chrome_button.h" 16 #include "chrome/browser/gtk/gtk_chrome_button.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "chrome/common/pref_service.h" 18 #include "chrome/common/pref_service.h"
17 #include "chrome/common/notification_details.h" 19 #include "chrome/common/notification_details.h"
18 #include "chrome/common/notification_service.h" 20 #include "chrome/common/notification_service.h"
19 #include "chrome/common/notification_source.h" 21 #include "chrome/common/notification_source.h"
20 #include "chrome/common/notification_type.h" 22 #include "chrome/common/notification_type.h"
(...skipping 29 matching lines...) Expand all
50 // calculate the border color in GTK theme mode. 52 // calculate the border color in GTK theme mode.
51 const int kBgWeight = 3; 53 const int kBgWeight = 3;
52 54
53 // Converts a GdkColor to a SkColor. 55 // Converts a GdkColor to a SkColor.
54 SkColor GdkToSkColor(GdkColor* color) { 56 SkColor GdkToSkColor(GdkColor* color) {
55 return SkColorSetRGB(color->red >> 8, 57 return SkColorSetRGB(color->red >> 8,
56 color->green >> 8, 58 color->green >> 8,
57 color->blue >> 8); 59 color->blue >> 8);
58 } 60 }
59 61
62 // A list of images that we provide while in gtk mode.
63 const int kThemeImages[] = {
64 IDR_THEME_TOOLBAR,
65 IDR_THEME_TAB_BACKGROUND,
66 IDR_THEME_TAB_BACKGROUND_INCOGNITO,
67 IDR_THEME_FRAME,
68 IDR_THEME_FRAME_INACTIVE,
69 IDR_THEME_FRAME_INCOGNITO,
70 IDR_THEME_FRAME_INCOGNITO_INACTIVE,
71 };
72
73 bool IsOverridableImage(int id) {
74 for (size_t i = 0; i < arraysize(kThemeImages); ++i) {
75 if (kThemeImages[i] == id)
76 return true;
77 }
78
79 return false;
80 }
81
60 } // namespace 82 } // namespace
61 83
62 GtkWidget* GtkThemeProvider::icon_widget_ = NULL; 84 GtkWidget* GtkThemeProvider::icon_widget_ = NULL;
63 GdkPixbuf* GtkThemeProvider::default_folder_icon_ = NULL; 85 GdkPixbuf* GtkThemeProvider::default_folder_icon_ = NULL;
64 GdkPixbuf* GtkThemeProvider::default_bookmark_icon_ = NULL; 86 GdkPixbuf* GtkThemeProvider::default_bookmark_icon_ = NULL;
65 87
66 // static 88 // static
67 GtkThemeProvider* GtkThemeProvider::GetFrom(Profile* profile) { 89 GtkThemeProvider* GtkThemeProvider::GetFrom(Profile* profile) {
68 return static_cast<GtkThemeProvider*>(profile->GetThemeProvider()); 90 return static_cast<GtkThemeProvider*>(profile->GetThemeProvider());
69 } 91 }
70 92
71 GtkThemeProvider::GtkThemeProvider() 93 GtkThemeProvider::GtkThemeProvider()
72 : BrowserThemeProvider(), 94 : BrowserThemeProvider(),
73 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) { 95 fake_window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) {
74 fake_label_.Own(gtk_label_new("")); 96 fake_label_.Own(gtk_label_new(""));
75 97
76 // Only realized widgets receive style-set notifications, which we need to 98 // Only realized widgets receive style-set notifications, which we need to
77 // broadcast new theme images and colors. 99 // broadcast new theme images and colors.
78 gtk_widget_realize(fake_window_); 100 gtk_widget_realize(fake_window_);
79 g_signal_connect(fake_window_, "style-set", G_CALLBACK(&OnStyleSet), this); 101 g_signal_connect(fake_window_, "style-set", G_CALLBACK(&OnStyleSet), this);
80 } 102 }
81 103
82 GtkThemeProvider::~GtkThemeProvider() { 104 GtkThemeProvider::~GtkThemeProvider() {
83 profile()->GetPrefs()->RemovePrefObserver(prefs::kUsesSystemTheme, this); 105 profile()->GetPrefs()->RemovePrefObserver(prefs::kUsesSystemTheme, this);
84 gtk_widget_destroy(fake_window_); 106 gtk_widget_destroy(fake_window_);
85 fake_label_.Destroy(); 107 fake_label_.Destroy();
86 108
87 // We have to call this because ClearCaches in ~BrowserThemeProvider doesn't 109 // We have to call this because FreePlatformCached() in ~BrowserThemeProvider
88 // call the right virutal FreePlatformCaches. 110 // doesn't call the right virutal FreePlatformCaches.
89 FreePerDisplaySurfaces(); 111 FreePlatformCaches();
90 112
91 // Disconnect from the destroy signal of any redisual widgets in 113 // Disconnect from the destroy signal of any redisual widgets in
92 // |chrome_buttons_|. 114 // |chrome_buttons_|.
93 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); 115 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin();
94 it != chrome_buttons_.end(); ++it) { 116 it != chrome_buttons_.end(); ++it) {
95 gtk_signal_disconnect_by_data(GTK_OBJECT(*it), this); 117 gtk_signal_disconnect_by_data(GTK_OBJECT(*it), this);
96 } 118 }
97 } 119 }
98 120
99 void GtkThemeProvider::Init(Profile* profile) { 121 void GtkThemeProvider::Init(Profile* profile) {
100 profile->GetPrefs()->AddPrefObserver(prefs::kUsesSystemTheme, this); 122 profile->GetPrefs()->AddPrefObserver(prefs::kUsesSystemTheme, this);
101 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); 123 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
102 124
103 BrowserThemeProvider::Init(profile); 125 BrowserThemeProvider::Init(profile);
104 } 126 }
105 127
128 SkBitmap* GtkThemeProvider::GetBitmapNamed(int id) const {
129 if (use_gtk_ && IsOverridableImage(id)) {
130 // Try to get our cached version:
131 ImageCache::const_iterator it = gtk_images_.find(id);
132 if (it != gtk_images_.end())
133 return it->second;
134
135 // We haven't built this image yet:
136 SkBitmap* bitmap = GenerateGtkThemeBitmap(id);
137 gtk_images_[id] = bitmap;
138 return bitmap;
139 }
140
141 return BrowserThemeProvider::GetBitmapNamed(id);
142 }
143
144 SkColor GtkThemeProvider::GetColor(int id) const {
145 if (use_gtk_) {
146 ColorMap::const_iterator it = colors_.find(id);
147 if (it != colors_.end())
148 return it->second;
149 }
150
151 return BrowserThemeProvider::GetColor(id);
152 }
153
154 bool GtkThemeProvider::HasCustomImage(int id) const {
155 if (use_gtk_)
156 return IsOverridableImage(id);
157
158 return BrowserThemeProvider::HasCustomImage(id);
159 }
160
106 void GtkThemeProvider::InitThemesFor(NotificationObserver* observer) { 161 void GtkThemeProvider::InitThemesFor(NotificationObserver* observer) {
107 observer->Observe(NotificationType::BROWSER_THEME_CHANGED, 162 observer->Observe(NotificationType::BROWSER_THEME_CHANGED,
108 Source<ThemeProvider>(this), 163 Source<ThemeProvider>(this),
109 NotificationService::NoDetails()); 164 NotificationService::NoDetails());
110 } 165 }
111 166
112 void GtkThemeProvider::SetTheme(Extension* extension) { 167 void GtkThemeProvider::SetTheme(Extension* extension) {
113 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); 168 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false);
114 BrowserThemeProvider::SetTheme(extension); 169 BrowserThemeProvider::SetTheme(extension);
115 } 170 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 BrowserThemeProvider::NotifyThemeChanged(); 393 BrowserThemeProvider::NotifyThemeChanged();
339 394
340 // Notify all GtkChromeButtons of their new rendering mode: 395 // Notify all GtkChromeButtons of their new rendering mode:
341 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); 396 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin();
342 it != chrome_buttons_.end(); ++it) { 397 it != chrome_buttons_.end(); ++it) {
343 gtk_chrome_button_set_use_gtk_rendering( 398 gtk_chrome_button_set_use_gtk_rendering(
344 GTK_CHROME_BUTTON(*it), use_gtk_); 399 GTK_CHROME_BUTTON(*it), use_gtk_);
345 } 400 }
346 } 401 }
347 402
348 SkBitmap* GtkThemeProvider::LoadThemeBitmap(int id) const {
349 if (use_gtk_) {
350 if (id == IDR_THEME_TOOLBAR) {
351 GtkStyle* style = gtk_rc_get_style(fake_window_);
352 GdkColor* color = &style->bg[GTK_STATE_NORMAL];
353 SkBitmap* bitmap = new SkBitmap;
354 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
355 kToolbarImageWidth, kToolbarImageHeight);
356 bitmap->allocPixels();
357 bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8);
358 return bitmap;
359 }
360 if ((id == IDR_THEME_TAB_BACKGROUND) ||
361 (id == IDR_THEME_TAB_BACKGROUND_INCOGNITO))
362 return GenerateTabBackgroundBitmapImpl(id);
363 }
364
365 return BrowserThemeProvider::LoadThemeBitmap(id);
366 }
367
368 void GtkThemeProvider::SaveThemeBitmap(const std::string resource_name,
369 int id) const {
370 if (!use_gtk_) {
371 // Prevent us from writing out our mostly unused resources in gtk theme
372 // mode. Simply preventing us from writing this data out in gtk mode isn't
373 // the best design, but this would probably be a very invasive change on
374 // all three platforms otherwise.
375 BrowserThemeProvider::SaveThemeBitmap(resource_name, id);
376 }
377 }
378
379 void GtkThemeProvider::FreePlatformCaches() { 403 void GtkThemeProvider::FreePlatformCaches() {
380 BrowserThemeProvider::FreePlatformCaches(); 404 BrowserThemeProvider::FreePlatformCaches();
381 FreePerDisplaySurfaces(); 405 FreePerDisplaySurfaces();
406 STLDeleteValues(&gtk_images_);
382 } 407 }
383 408
384 // static 409 // static
385 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, 410 void GtkThemeProvider::OnStyleSet(GtkWidget* widget,
386 GtkStyle* previous_style, 411 GtkStyle* previous_style,
387 GtkThemeProvider* provider) { 412 GtkThemeProvider* provider) {
388 GdkPixbuf* default_folder_icon = default_folder_icon_; 413 GdkPixbuf* default_folder_icon = default_folder_icon_;
389 GdkPixbuf* default_bookmark_icon = default_bookmark_icon_; 414 GdkPixbuf* default_bookmark_icon = default_bookmark_icon_;
390 default_folder_icon_ = NULL; 415 default_folder_icon_ = NULL;
391 default_bookmark_icon_ = NULL; 416 default_bookmark_icon_ = NULL;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if (hsl_difference <= kMinimumLuminanceDifference) { 493 if (hsl_difference <= kMinimumLuminanceDifference) {
469 // Not enough contrast. Try the text color instead. 494 // Not enough contrast. Try the text color instead.
470 color_utils::HSL label_hsl; 495 color_utils::HSL label_hsl;
471 color_utils::SkColorToHSL(GdkToSkColor(&label_color), &label_hsl); 496 color_utils::SkColorToHSL(GdkToSkColor(&label_color), &label_hsl);
472 double label_difference = fabs(label_hsl.l - toolbar_hsl.l); 497 double label_difference = fabs(label_hsl.l - toolbar_hsl.l);
473 if (label_difference >= kMinimumLuminanceDifference) { 498 if (label_difference >= kMinimumLuminanceDifference) {
474 button_color = label_color; 499 button_color = label_color;
475 } 500 }
476 } 501 }
477 502
478 SetThemeColorFromGtk(kColorFrame, &frame_color); 503 SetThemeTintFromGtk(BrowserThemeProvider::TINT_BUTTONS, &button_color);
504 SetThemeTintFromGtk(BrowserThemeProvider::TINT_FRAME, &frame_color);
505 SetThemeTintFromGtk(BrowserThemeProvider::TINT_FRAME_INCOGNITO, &frame_color);
506 SetThemeTintFromGtk(BrowserThemeProvider::TINT_BACKGROUND_TAB, &frame_color);
507
508 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_FRAME, &frame_color);
509 BuildTintedFrameColor(BrowserThemeProvider::COLOR_FRAME_INACTIVE,
510 BrowserThemeProvider::TINT_FRAME_INACTIVE);
511 BuildTintedFrameColor(BrowserThemeProvider::COLOR_FRAME_INCOGNITO,
512 BrowserThemeProvider::TINT_FRAME_INCOGNITO);
513 BuildTintedFrameColor(BrowserThemeProvider::COLOR_FRAME_INCOGNITO_INACTIVE,
514 BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE);
515
479 // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be 516 // Skip COLOR_FRAME_INACTIVE and the incognito colors, as they will be
480 // autogenerated from tints. 517 // autogenerated from tints. TODO(erg): Still true?
481 SetThemeColorFromGtk(kColorToolbar, &toolbar_color); 518 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_TOOLBAR, &toolbar_color);
482 SetThemeColorFromGtk(kColorTabText, &label_color); 519 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_TAB_TEXT, &label_color);
483 SetThemeColorFromGtk(kColorBookmarkText, &label_color); 520 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, &label_color);
484 SetThemeColorFromGtk(kColorControlBackground, 521 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_CONTROL_BACKGROUND,
485 &window_style->bg[GTK_STATE_NORMAL]); 522 &window_style->bg[GTK_STATE_NORMAL]);
486 SetThemeColorFromGtk(kColorButtonBackground, 523 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND,
487 &window_style->bg[GTK_STATE_NORMAL]); 524 &window_style->bg[GTK_STATE_NORMAL]);
488 525
489 SetThemeTintFromGtk(kTintButtons, &button_color,
490 kDefaultTintButtons);
491 SetThemeTintFromGtk(kTintFrame, &frame_color,
492 kDefaultTintFrame);
493 SetThemeTintFromGtk(kTintFrameIncognito,
494 &frame_color,
495 kDefaultTintFrameIncognito);
496 SetThemeTintFromGtk(kTintBackgroundTab,
497 &frame_color,
498 kDefaultTintBackgroundTab);
499
500 // The inactive frame color never occurs naturally in the theme, as it is a 526 // The inactive frame color never occurs naturally in the theme, as it is a
501 // tinted version of |frame_color|. We generate another color based on the 527 // tinted version of |frame_color|. We generate another color based on the
502 // background tab color, with the lightness and saturation moved in the 528 // background tab color, with the lightness and saturation moved in the
503 // opposite direction. (We don't touch the hue, since there should be subtle 529 // opposite direction. (We don't touch the hue, since there should be subtle
504 // hints of the color in the text.) 530 // hints of the color in the text.)
505 color_utils::HSL inactive_tab_text_hsl = GetTint(TINT_BACKGROUND_TAB); 531 color_utils::HSL inactive_tab_text_hsl = tints_[TINT_BACKGROUND_TAB];
506 if (inactive_tab_text_hsl.l < 0.5) 532 if (inactive_tab_text_hsl.l < 0.5)
507 inactive_tab_text_hsl.l = kDarkInactiveLuminance; 533 inactive_tab_text_hsl.l = kDarkInactiveLuminance;
508 else 534 else
509 inactive_tab_text_hsl.l = kLightInactiveLuminance; 535 inactive_tab_text_hsl.l = kLightInactiveLuminance;
510 536
511 if (inactive_tab_text_hsl.s < 0.5) 537 if (inactive_tab_text_hsl.s < 0.5)
512 inactive_tab_text_hsl.s = kHeavyInactiveSaturation; 538 inactive_tab_text_hsl.s = kHeavyInactiveSaturation;
513 else 539 else
514 inactive_tab_text_hsl.s = kLightInactiveSaturation; 540 inactive_tab_text_hsl.s = kLightInactiveSaturation;
515 541
516 SetColor(kColorBackgroundTabText, 542 colors_[BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT] =
517 color_utils::HSLToSkColor(inactive_tab_text_hsl, 255)); 543 color_utils::HSLToSkColor(inactive_tab_text_hsl, 255);
518 544
519 // The inactive color/tint is special: We *must* use the exact insensitive 545 // The inactive color/tint is special: We *must* use the exact insensitive
520 // color for all inactive windows, otherwise we end up neon pink half the 546 // color for all inactive windows, otherwise we end up neon pink half the
521 // time. 547 // time.
522 SetThemeColorFromGtk(kColorFrameInactive, &inactive_frame_color); 548 SetThemeColorFromGtk(BrowserThemeProvider::COLOR_FRAME_INACTIVE,
523 SetThemeTintFromGtk(kTintFrameInactive, &inactive_frame_color, 549 &inactive_frame_color);
524 kExactColor); 550 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INACTIVE,
525 SetThemeTintFromGtk(kTintFrameIncognitoInactive, &inactive_frame_color, 551 &inactive_frame_color);
526 kExactColor); 552 SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE,
527 553 &inactive_frame_color);
528 force_process_images();
529 GenerateFrameColors();
530 AutoLock lock(themed_image_cache_lock_);
531 GenerateFrameImages();
532 } 554 }
533 555
534 void GtkThemeProvider::SetThemeColorFromGtk(const char* id, GdkColor* color) { 556 void GtkThemeProvider::SetThemeColorFromGtk(int id, GdkColor* color) {
535 SetColor(id, GdkToSkColor(color)); 557 colors_[id] = GdkToSkColor(color);
536 } 558 }
537 559
538 void GtkThemeProvider::SetThemeTintFromGtk( 560 void GtkThemeProvider::SetThemeTintFromGtk(int id, GdkColor* color) {
539 const char* id, 561 color_utils::HSL default_tint = GetDefaultTint(id);
540 GdkColor* color,
541 const color_utils::HSL& default_tint) {
542 color_utils::HSL hsl; 562 color_utils::HSL hsl;
543 color_utils::SkColorToHSL(GdkToSkColor(color), &hsl); 563 color_utils::SkColorToHSL(GdkToSkColor(color), &hsl);
544 564
545 if (default_tint.s != -1) 565 if (default_tint.s != -1)
546 hsl.s = default_tint.s; 566 hsl.s = default_tint.s;
547 567
548 if (default_tint.l != -1) 568 if (default_tint.l != -1)
549 hsl.l = default_tint.l; 569 hsl.l = default_tint.l;
550 SetTint(id, hsl); 570
571 tints_[id] = hsl;
572 }
573
574 void GtkThemeProvider::BuildTintedFrameColor(int color_id, int tint_id) {
575 colors_[color_id] = HSLShift(colors_[BrowserThemeProvider::COLOR_FRAME],
576 tints_[tint_id]);
577 }
578
579 void GtkThemeProvider::SetTintToExactColor(int id, GdkColor* color) {
580 color_utils::HSL hsl;
581 color_utils::SkColorToHSL(GdkToSkColor(color), &hsl);
582 tints_[id] = hsl;
551 } 583 }
552 584
553 void GtkThemeProvider::FreePerDisplaySurfaces() { 585 void GtkThemeProvider::FreePerDisplaySurfaces() {
554 for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin(); 586 for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin();
555 it != per_display_surfaces_.end(); ++it) { 587 it != per_display_surfaces_.end(); ++it) {
556 for (CairoCachedSurfaceMap::iterator jt = it->second.begin(); 588 for (CairoCachedSurfaceMap::iterator jt = it->second.begin();
557 jt != it->second.end(); ++jt) { 589 jt != it->second.end(); ++jt) {
558 delete jt->second; 590 delete jt->second;
559 } 591 }
560 } 592 }
561 per_display_surfaces_.clear(); 593 per_display_surfaces_.clear();
562 } 594 }
563 595
596 SkBitmap* GtkThemeProvider::GenerateGtkThemeBitmap(int id) const {
597 switch (id) {
598 case IDR_THEME_TOOLBAR: {
599 GtkStyle* style = gtk_rc_get_style(fake_window_);
600 GdkColor* color = &style->bg[GTK_STATE_NORMAL];
601 SkBitmap* bitmap = new SkBitmap;
602 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
603 kToolbarImageWidth, kToolbarImageHeight);
604 bitmap->allocPixels();
605 bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8);
606 return bitmap;
607 }
608 case IDR_THEME_TAB_BACKGROUND:
609 return GenerateTabImage(IDR_THEME_FRAME);
610 case IDR_THEME_TAB_BACKGROUND_INCOGNITO:
611 return GenerateTabImage(IDR_THEME_FRAME_INCOGNITO);
612 case IDR_THEME_FRAME:
613 return GenerateFrameImage(BrowserThemeProvider::TINT_FRAME);
614 case IDR_THEME_FRAME_INACTIVE:
615 return GenerateFrameImage(BrowserThemeProvider::TINT_FRAME_INACTIVE);
616 case IDR_THEME_FRAME_INCOGNITO:
617 return GenerateFrameImage(BrowserThemeProvider::TINT_FRAME_INCOGNITO);
618 case IDR_THEME_FRAME_INCOGNITO_INACTIVE: {
619 return GenerateFrameImage(
620 BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE);
621 }
622 }
623
624 NOTREACHED() << "Invalid bitmap request " << id;
625 return NULL;
626 }
627
628 SkBitmap* GtkThemeProvider::GenerateFrameImage(int tint_id) const {
629 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
630 scoped_ptr<SkBitmap> frame(new SkBitmap(*rb.GetBitmapNamed(IDR_THEME_FRAME)));
631 TintMap::const_iterator it = tints_.find(tint_id);
632 DCHECK(it != tints_.end());
633 return new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap(*frame,
634 it->second));
635 }
636
637 SkBitmap* GtkThemeProvider::GenerateTabImage(int base_id) const {
638 SkBitmap* base_image = GetBitmapNamed(base_id);
639 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
640 *base_image, GetTint(BrowserThemeProvider::TINT_BACKGROUND_TAB));
641 return new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
642 bg_tint, 0, 0, bg_tint.width(), bg_tint.height()));
643 }
644
564 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, 645 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button,
565 GtkThemeProvider* provider) { 646 GtkThemeProvider* provider) {
566 std::vector<GtkWidget*>::iterator it = 647 std::vector<GtkWidget*>::iterator it =
567 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), 648 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(),
568 button); 649 button);
569 if (it != provider->chrome_buttons_.end()) 650 if (it != provider->chrome_buttons_.end())
570 provider->chrome_buttons_.erase(it); 651 provider->chrome_buttons_.erase(it);
571 } 652 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698