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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 } | 25 } |
26 | 26 |
27 NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { | 27 NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { |
28 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
29 | 29 |
30 if (!HasCustomImage(id)) | 30 if (!HasCustomImage(id)) |
31 return nil; | 31 return nil; |
32 | 32 |
33 // 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. |
34 NSImageMap::const_iterator found = nsimage_cache_.find(id); | 34 NSImageMap::const_iterator nsimage_iter = nsimage_cache_.find(id); |
35 if (found != nsimage_cache_.end()) | 35 if (nsimage_iter != nsimage_cache_.end()) |
36 return found->second; | 36 return nsimage_iter->second; |
37 | 37 |
38 // Why don't we load the file directly into the image instead of the whole | 38 // Why don't we load the file directly into the image instead of the whole |
39 // SkBitmap > native conversion? | 39 // SkBitmap > native conversion? |
40 // - For consistency with other platforms. | 40 // - For consistency with other platforms. |
41 // - To get the generated tinted images. | 41 // - To get the generated tinted images. |
42 SkBitmap* bitmap = GetBitmapNamed(id); | 42 SkBitmap* bitmap = GetBitmapNamed(id); |
43 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); | 43 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); |
44 | 44 |
45 // We loaded successfully. Cache the image. | 45 // We loaded successfully. Cache the image. |
46 if (nsimage) { | 46 if (nsimage) { |
(...skipping 17 matching lines...) Expand all Loading... |
64 [empty_image unlockFocus]; | 64 [empty_image unlockFocus]; |
65 } | 65 } |
66 | 66 |
67 return empty_image; | 67 return empty_image; |
68 } | 68 } |
69 | 69 |
70 NSColor* BrowserThemeProvider::GetNSColor(int id) { | 70 NSColor* BrowserThemeProvider::GetNSColor(int id) { |
71 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
72 | 72 |
73 // 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. |
74 NSColorMap::const_iterator found = nscolor_cache_.find(id); | 74 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); |
75 if (found != nscolor_cache_.end()) | 75 if (nscolor_iter != nscolor_cache_.end()) |
76 return found->second; | 76 return nscolor_iter->second; |
77 | 77 |
78 SkColor sk_color = GetColor(id); | 78 SkColor sk_color = GetColor(id); |
79 NSColor* color = [NSColor | 79 NSColor* color = [NSColor |
80 colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 | 80 colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 |
81 green:SkColorGetG(sk_color)/255.0 | 81 green:SkColorGetG(sk_color)/255.0 |
82 blue:SkColorGetB(sk_color)/255.0 | 82 blue:SkColorGetB(sk_color)/255.0 |
83 alpha:SkColorGetA(sk_color)/255.0]; | 83 alpha:SkColorGetA(sk_color)/255.0]; |
84 | 84 |
85 // We loaded successfully. Cache the color. | 85 // We loaded successfully. Cache the color. |
86 if (color) { | 86 if (color) { |
87 nscolor_cache_[id] = [color retain]; | 87 nscolor_cache_[id] = [color retain]; |
88 return color; | 88 return color; |
89 } | 89 } |
90 | 90 |
91 return nil; | 91 return nil; |
92 } | 92 } |
93 | 93 |
94 NSColor* BrowserThemeProvider::GetNSColorTint(int id) { | 94 NSColor* BrowserThemeProvider::GetNSColorTint(int id) { |
95 DCHECK(CalledOnValidThread()); | 95 DCHECK(CalledOnValidThread()); |
96 | 96 |
97 // Check to see if we already have the color in the cache. | 97 // Check to see if we already have the color in the cache. |
98 NSColorMap::const_iterator found = nscolor_cache_.find(id); | 98 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); |
99 if (found != nscolor_cache_.end()) | 99 if (nscolor_iter != nscolor_cache_.end()) |
100 return found->second; | 100 return nscolor_iter->second; |
101 | 101 |
102 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); | 102 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); |
103 if (tint_iter != tints_.end()) { | 103 if (tint_iter != tints_.end()) { |
104 color_utils::HSL tint = tint_iter->second; | 104 color_utils::HSL tint = tint_iter->second; |
105 CGFloat hue, saturation, brightness; | 105 CGFloat hue, saturation, brightness; |
106 HSLToHSB(tint, &hue, &saturation, &brightness); | 106 HSLToHSB(tint, &hue, &saturation, &brightness); |
107 | 107 |
108 NSColor* tint_color = [NSColor colorWithCalibratedHue:hue | 108 NSColor* tint_color = [NSColor colorWithCalibratedHue:hue |
109 saturation:saturation | 109 saturation:saturation |
110 brightness:brightness | 110 brightness:brightness |
(...skipping 19 matching lines...) Expand all Loading... |
130 } | 130 } |
131 nsimage_cache_.clear(); | 131 nsimage_cache_.clear(); |
132 | 132 |
133 // Free colors. | 133 // Free colors. |
134 for (NSColorMap::iterator i = nscolor_cache_.begin(); | 134 for (NSColorMap::iterator i = nscolor_cache_.begin(); |
135 i != nscolor_cache_.end(); i++) { | 135 i != nscolor_cache_.end(); i++) { |
136 [i->second release]; | 136 [i->second release]; |
137 } | 137 } |
138 nscolor_cache_.clear(); | 138 nscolor_cache_.clear(); |
139 } | 139 } |
OLD | NEW |