| 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 NSColor* BrowserThemeProvider::GetNSColor(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 ColorMap::iterator color_iter = colors_.find(GetColorKey(id)); |
| 64 if (color_iter != colors_.end()) { |
| 65 const SkColor& sk_color = color_iter->second; |
| 66 |
| 67 NSColor* color = [NSColor colorWithCalibratedRed:SkColorGetR(sk_color) |
| 68 green:SkColorGetG(sk_color) |
| 69 blue:SkColorGetB(sk_color) |
| 70 alpha:SkColorGetA(sk_color)]; |
| 71 |
| 72 // We loaded successfully. Cache the color. |
| 73 if (color) { |
| 74 nscolor_cache_[id] = [color retain]; |
| 75 return color; |
| 76 } |
| 77 } |
| 78 |
| 79 return nil; |
| 80 } |
| 81 |
| 55 NSColor* BrowserThemeProvider::GetNSColorTint(int id) { | 82 NSColor* BrowserThemeProvider::GetNSColorTint(int id) { |
| 56 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 57 | 84 |
| 58 // Check to see if we already have the color in the cache. | 85 // Check to see if we already have the color in the cache. |
| 59 NSColorMap::const_iterator found = nscolor_cache_.find(id); | 86 NSColorMap::const_iterator found = nscolor_cache_.find(id); |
| 60 if (found != nscolor_cache_.end()) | 87 if (found != nscolor_cache_.end()) |
| 61 return found->second; | 88 return found->second; |
| 62 | 89 |
| 63 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); | 90 TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); |
| 64 if (tint_iter != tints_.end()) { | 91 if (tint_iter != tints_.end()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 92 } | 119 } |
| 93 nsimage_cache_.clear(); | 120 nsimage_cache_.clear(); |
| 94 | 121 |
| 95 // Free colors. | 122 // Free colors. |
| 96 for (NSColorMap::iterator i = nscolor_cache_.begin(); | 123 for (NSColorMap::iterator i = nscolor_cache_.begin(); |
| 97 i != nscolor_cache_.end(); i++) { | 124 i != nscolor_cache_.end(); i++) { |
| 98 [i->second release]; | 125 [i->second release]; |
| 99 } | 126 } |
| 100 nscolor_cache_.clear(); | 127 nscolor_cache_.clear(); |
| 101 } | 128 } |
| OLD | NEW |