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_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 empty_image = [[NSImage alloc] initWithSize:image_rect.size]; | 45 empty_image = [[NSImage alloc] initWithSize:image_rect.size]; |
46 [empty_image lockFocus]; | 46 [empty_image lockFocus]; |
47 [[NSColor redColor] set]; | 47 [[NSColor redColor] set]; |
48 NSRectFill(image_rect); | 48 NSRectFill(image_rect); |
49 [empty_image unlockFocus]; | 49 [empty_image unlockFocus]; |
50 } | 50 } |
51 | 51 |
52 return empty_image; | 52 return empty_image; |
53 } | 53 } |
54 | 54 |
55 void BrowserThemeProvider::FreePlatformImages() { | 55 NSColor* BrowserThemeProvider::GetNSColorTint(int id) { |
| 56 DCHECK(CalledOnValidThread()); |
| 57 |
| 58 // Check to see if we already have the color in the cache. |
| 59 NSColorMap::const_iterator found = nscolor_cache_.find(id); |
| 60 if (found != nscolor_cache_.end()) |
| 61 return found->second; |
| 62 |
| 63 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); |
| 64 if (tint_iter != tints_.end()) { |
| 65 skia::HSL tint = tint_iter->second; |
| 66 |
| 67 // The tint is HSL, not HSB, but we're cheating for now. TODO(avi,alcor): |
| 68 // determine how much this matters and fix it if necessary. |
| 69 // http://crbug.com/15760 |
| 70 NSColor* tint_color = [NSColor colorWithCalibratedHue:tint.h |
| 71 saturation:tint.s |
| 72 brightness:tint.l |
| 73 alpha:1.0]; |
| 74 |
| 75 // We loaded successfully. Cache the color. |
| 76 if (tint_color) { |
| 77 nscolor_cache_[id] = [tint_color retain]; |
| 78 return tint_color; |
| 79 } |
| 80 } |
| 81 |
| 82 return nil; |
| 83 } |
| 84 |
| 85 void BrowserThemeProvider::FreePlatformCaches() { |
56 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
57 | 87 |
58 // Free images. | 88 // Free images. |
59 for (NSImageMap::iterator i = nsimage_cache_.begin(); | 89 for (NSImageMap::iterator i = nsimage_cache_.begin(); |
60 i != nsimage_cache_.end(); i++) { | 90 i != nsimage_cache_.end(); i++) { |
61 [i->second release]; | 91 [i->second release]; |
62 } | 92 } |
63 nsimage_cache_.clear(); | 93 nsimage_cache_.clear(); |
| 94 |
| 95 // Free colors. |
| 96 for (NSColorMap::iterator i = nscolor_cache_.begin(); |
| 97 i != nscolor_cache_.end(); i++) { |
| 98 [i->second release]; |
| 99 } |
| 100 nscolor_cache_.clear(); |
64 } | 101 } |
OLD | NEW |