| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser_theme_provider.h" | 5 #include "chrome/browser/browser_theme_provider.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "app/gfx/color_utils.h" | 9 #include "app/gfx/color_utils.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/browser_theme_pack.h" |
| 11 #include "skia/ext/skia_utils_mac.h" | 12 #include "skia/ext/skia_utils_mac.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) { | 16 void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) { |
| 16 SkColor color = color_utils::HSLToSkColor(hsl, 255); // alpha doesn't matter | 17 SkColor color = color_utils::HSLToSkColor(hsl, 255); // alpha doesn't matter |
| 17 SkScalar hsv[3]; | 18 SkScalar hsv[3]; |
| 18 SkColorToHSV(color, hsv); | 19 SkColorToHSV(color, hsv); |
| 19 | 20 |
| 20 *h = SkScalarToDouble(hsv[0]) / 360.0; | 21 *h = SkScalarToDouble(hsv[0]) / 360.0; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 69 } |
| 69 | 70 |
| 70 NSColor* BrowserThemeProvider::GetNSColor(int id) const { | 71 NSColor* BrowserThemeProvider::GetNSColor(int id) const { |
| 71 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 72 | 73 |
| 73 // Check to see if we already have the color in the cache. | 74 // Check to see if we already have the color in the cache. |
| 74 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); | 75 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); |
| 75 if (nscolor_iter != nscolor_cache_.end()) | 76 if (nscolor_iter != nscolor_cache_.end()) |
| 76 return nscolor_iter->second; | 77 return nscolor_iter->second; |
| 77 | 78 |
| 78 ColorMap::const_iterator color_iter = colors_.find(GetColorKey(id)); | 79 SkColor sk_color; |
| 79 if (color_iter != colors_.end()) { | 80 if (theme_pack_.get() && theme_pack_->GetColor(id, &sk_color)) { |
| 80 const SkColor& sk_color = color_iter->second; | |
| 81 NSColor* color = [NSColor | 81 NSColor* color = [NSColor |
| 82 colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 | 82 colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 |
| 83 green:SkColorGetG(sk_color)/255.0 | 83 green:SkColorGetG(sk_color)/255.0 |
| 84 blue:SkColorGetB(sk_color)/255.0 | 84 blue:SkColorGetB(sk_color)/255.0 |
| 85 alpha:SkColorGetA(sk_color)/255.0]; | 85 alpha:SkColorGetA(sk_color)/255.0]; |
| 86 | 86 |
| 87 // We loaded successfully. Cache the color. | 87 // We loaded successfully. Cache the color. |
| 88 if (color) { | 88 if (color) { |
| 89 nscolor_cache_[id] = [color retain]; | 89 nscolor_cache_[id] = [color retain]; |
| 90 return color; | 90 return color; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 return nil; | 94 return nil; |
| 95 } | 95 } |
| 96 | 96 |
| 97 NSColor* BrowserThemeProvider::GetNSColorTint(int id) const { | 97 NSColor* BrowserThemeProvider::GetNSColorTint(int id) const { |
| 98 DCHECK(CalledOnValidThread()); | 98 DCHECK(CalledOnValidThread()); |
| 99 | 99 |
| 100 // Check to see if we already have the color in the cache. | 100 // Check to see if we already have the color in the cache. |
| 101 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); | 101 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); |
| 102 if (nscolor_iter != nscolor_cache_.end()) | 102 if (nscolor_iter != nscolor_cache_.end()) |
| 103 return nscolor_iter->second; | 103 return nscolor_iter->second; |
| 104 | 104 |
| 105 TintMap::const_iterator tint_iter = tints_.find(GetTintKey(id)); | 105 color_utils::HSL tint; |
| 106 if (tint_iter != tints_.end()) { | 106 if (theme_pack_.get() && theme_pack_->GetTint(id, &tint)) { |
| 107 color_utils::HSL tint = tint_iter->second; | |
| 108 CGFloat hue, saturation, brightness; | 107 CGFloat hue, saturation, brightness; |
| 109 HSLToHSB(tint, &hue, &saturation, &brightness); | 108 HSLToHSB(tint, &hue, &saturation, &brightness); |
| 110 | 109 |
| 111 NSColor* tint_color = [NSColor colorWithCalibratedHue:hue | 110 NSColor* tint_color = [NSColor colorWithCalibratedHue:hue |
| 112 saturation:saturation | 111 saturation:saturation |
| 113 brightness:brightness | 112 brightness:brightness |
| 114 alpha:1.0]; | 113 alpha:1.0]; |
| 115 | 114 |
| 116 // We loaded successfully. Cache the color. | 115 // We loaded successfully. Cache the color. |
| 117 if (tint_color) { | 116 if (tint_color) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 } | 132 } |
| 134 nsimage_cache_.clear(); | 133 nsimage_cache_.clear(); |
| 135 | 134 |
| 136 // Free colors. | 135 // Free colors. |
| 137 for (NSColorMap::iterator i = nscolor_cache_.begin(); | 136 for (NSColorMap::iterator i = nscolor_cache_.begin(); |
| 138 i != nscolor_cache_.end(); i++) { | 137 i != nscolor_cache_.end(); i++) { |
| 139 [i->second release]; | 138 [i->second release]; |
| 140 } | 139 } |
| 141 nscolor_cache_.clear(); | 140 nscolor_cache_.clear(); |
| 142 } | 141 } |
| OLD | NEW |