Chromium Code Reviews| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "skia/ext/skia_utils.h" | |
| 10 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
| 11 | 12 |
| 13 namespace { | |
| 14 | |
| 15 void HSLToHSB(const skia::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) { | |
|
Erik does not do reviews
2009/08/03 22:09:42
One nit perhaps worth mentioning in a comment is t
Avi (use Gerrit)
2009/08/04 13:58:21
But Skia::HSL also uses [0.0, 1.0). I think that a
| |
| 16 SkColor color = skia::HSLToSkColor(1.0, hsl); // alpha value doesn't matter | |
| 17 SkScalar hsv[3]; | |
| 18 SkColorToHSV(color, hsv); | |
| 19 | |
| 20 *h = SkScalarToDouble(hsv[0]) / 360.0; | |
| 21 *s = SkScalarToDouble(hsv[1]); | |
| 22 *b = SkScalarToDouble(hsv[2]); | |
| 23 } | |
| 24 | |
| 25 } | |
| 26 | |
| 12 NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { | 27 NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { |
| 13 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
| 14 | 29 |
| 15 if (!HasCustomImage(id)) | 30 if (!HasCustomImage(id)) |
| 16 return nil; | 31 return nil; |
| 17 | 32 |
| 18 // Check to see if we already have the image in the cache. | 33 // Check to see if we already have the image in the cache. |
| 19 NSImageMap::const_iterator found = nsimage_cache_.find(id); | 34 NSImageMap::const_iterator found = nsimage_cache_.find(id); |
| 20 if (found != nsimage_cache_.end()) | 35 if (found != nsimage_cache_.end()) |
| 21 return found->second; | 36 return found->second; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
| 57 | 72 |
| 58 // Check to see if we already have the color in the cache. | 73 // Check to see if we already have the color in the cache. |
| 59 NSColorMap::const_iterator found = nscolor_cache_.find(id); | 74 NSColorMap::const_iterator found = nscolor_cache_.find(id); |
| 60 if (found != nscolor_cache_.end()) | 75 if (found != nscolor_cache_.end()) |
| 61 return found->second; | 76 return found->second; |
| 62 | 77 |
| 63 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); | 78 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); |
| 64 if (tint_iter != tints_.end()) { | 79 if (tint_iter != tints_.end()) { |
| 65 skia::HSL tint = tint_iter->second; | 80 skia::HSL tint = tint_iter->second; |
| 81 CGFloat hue, saturation, brightness; | |
| 82 HSLToHSB(tint, &hue, &saturation, &brightness); | |
| 66 | 83 |
| 67 // The tint is HSL, not HSB, but we're cheating for now. TODO(avi,alcor): | 84 NSColor* tint_color = [NSColor colorWithCalibratedHue:hue |
| 68 // determine how much this matters and fix it if necessary. | 85 saturation:saturation |
| 69 // http://crbug.com/15760 | 86 brightness:brightness |
| 70 NSColor* tint_color = [NSColor colorWithCalibratedHue:tint.h | |
| 71 saturation:tint.s | |
| 72 brightness:tint.l | |
| 73 alpha:1.0]; | 87 alpha:1.0]; |
| 74 | 88 |
| 75 // We loaded successfully. Cache the color. | 89 // We loaded successfully. Cache the color. |
| 76 if (tint_color) { | 90 if (tint_color) { |
| 77 nscolor_cache_[id] = [tint_color retain]; | 91 nscolor_cache_[id] = [tint_color retain]; |
| 78 return tint_color; | 92 return tint_color; |
| 79 } | 93 } |
| 80 } | 94 } |
| 81 | 95 |
| 82 return nil; | 96 return nil; |
| 83 } | 97 } |
| 84 | 98 |
| 85 void BrowserThemeProvider::FreePlatformCaches() { | 99 void BrowserThemeProvider::FreePlatformCaches() { |
| 86 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 87 | 101 |
| 88 // Free images. | 102 // Free images. |
| 89 for (NSImageMap::iterator i = nsimage_cache_.begin(); | 103 for (NSImageMap::iterator i = nsimage_cache_.begin(); |
| 90 i != nsimage_cache_.end(); i++) { | 104 i != nsimage_cache_.end(); i++) { |
| 91 [i->second release]; | 105 [i->second release]; |
| 92 } | 106 } |
| 93 nsimage_cache_.clear(); | 107 nsimage_cache_.clear(); |
| 94 | 108 |
| 95 // Free colors. | 109 // Free colors. |
| 96 for (NSColorMap::iterator i = nscolor_cache_.begin(); | 110 for (NSColorMap::iterator i = nscolor_cache_.begin(); |
| 97 i != nscolor_cache_.end(); i++) { | 111 i != nscolor_cache_.end(); i++) { |
| 98 [i->second release]; | 112 [i->second release]; |
| 99 } | 113 } |
| 100 nscolor_cache_.clear(); | 114 nscolor_cache_.clear(); |
| 101 } | 115 } |
| OLD | NEW |