Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/themes/theme_service_mac.mm

Issue 2909183002: Replace deprecated base::NonThreadSafe in chrome/browser/themes in favor of SequenceChecker. (Closed)
Patch Set: Merge with theme_service_mac.mm changes Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/themes/theme_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.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 "chrome/browser/themes/browser_theme_pack.h" 10 #include "chrome/browser/themes/browser_theme_pack.h"
(...skipping 26 matching lines...) Expand all
37 SkColorToHSV(color, hsv); 37 SkColorToHSV(color, hsv);
38 38
39 *h = SkScalarToDouble(hsv[0]) / 360.0; 39 *h = SkScalarToDouble(hsv[0]) / 360.0;
40 *s = SkScalarToDouble(hsv[1]); 40 *s = SkScalarToDouble(hsv[1]);
41 *b = SkScalarToDouble(hsv[2]); 41 *b = SkScalarToDouble(hsv[2]);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 NSImage* ThemeService::GetNSImageNamed(int id, bool incognito) const { 46 NSImage* ThemeService::GetNSImageNamed(int id, bool incognito) const {
47 DCHECK(CalledOnValidThread()); 47 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
48 48
49 bool is_tab_or_toolbar_color = 49 bool is_tab_or_toolbar_color =
50 id == IDR_THEME_TAB_BACKGROUND_INACTIVE || 50 id == IDR_THEME_TAB_BACKGROUND_INACTIVE ||
51 id == IDR_THEME_TOOLBAR_INACTIVE || 51 id == IDR_THEME_TOOLBAR_INACTIVE ||
52 id == IDR_THEME_TAB_BACKGROUND || 52 id == IDR_THEME_TAB_BACKGROUND ||
53 id == IDR_THEME_TOOLBAR; 53 id == IDR_THEME_TOOLBAR;
54 // TODO(ellyjones): remove traces of the MD redesign from this file. See 54 // TODO(ellyjones): remove traces of the MD redesign from this file. See
55 // crbug.com/648281 55 // crbug.com/648281
56 bool isModeMaterial = true; 56 bool isModeMaterial = true;
57 57
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 [empty_image lockFocus]; 140 [empty_image lockFocus];
141 [[NSColor redColor] set]; 141 [[NSColor redColor] set];
142 NSRectFill(image_rect); 142 NSRectFill(image_rect);
143 [empty_image unlockFocus]; 143 [empty_image unlockFocus];
144 } 144 }
145 145
146 return empty_image; 146 return empty_image;
147 } 147 }
148 148
149 NSColor* ThemeService::GetNSImageColorNamed(int id, bool incognito) const { 149 NSColor* ThemeService::GetNSImageColorNamed(int id, bool incognito) const {
150 DCHECK(CalledOnValidThread()); 150 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
151 151
152 bool is_tab_or_toolbar_color = 152 bool is_tab_or_toolbar_color =
153 id == IDR_THEME_TAB_BACKGROUND_INACTIVE || 153 id == IDR_THEME_TAB_BACKGROUND_INACTIVE ||
154 id == IDR_THEME_TOOLBAR_INACTIVE || 154 id == IDR_THEME_TOOLBAR_INACTIVE ||
155 id == IDR_THEME_TAB_BACKGROUND || 155 id == IDR_THEME_TAB_BACKGROUND ||
156 id == IDR_THEME_TOOLBAR; 156 id == IDR_THEME_TOOLBAR;
157 bool isModeMaterial = true; 157 bool isModeMaterial = true;
158 158
159 // In Material Design, Incognito mode draws tabs and the toolbar using colors 159 // In Material Design, Incognito mode draws tabs and the toolbar using colors
160 // that are different from non-Incognito mode. If in MD, offset these ids so 160 // that are different from non-Incognito mode. If in MD, offset these ids so
(...skipping 19 matching lines...) Expand all
180 180
181 return image_color; 181 return image_color;
182 } 182 }
183 183
184 bool ThemeService::HasCustomColor(int id) const { 184 bool ThemeService::HasCustomColor(int id) const {
185 SkColor color; 185 SkColor color;
186 return theme_supplier_ && theme_supplier_->GetColor(id, &color); 186 return theme_supplier_ && theme_supplier_->GetColor(id, &color);
187 } 187 }
188 188
189 NSColor* ThemeService::GetNSColor(int id, bool incognito) const { 189 NSColor* ThemeService::GetNSColor(int id, bool incognito) const {
190 DCHECK(CalledOnValidThread()); 190 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
191 191
192 int original_id = id; 192 int original_id = id;
193 const bool is_mode_material = true; 193 const bool is_mode_material = true;
194 if (is_mode_material && incognito) { 194 if (is_mode_material && incognito) {
195 id += kMaterialDesignIdOffset; 195 id += kMaterialDesignIdOffset;
196 } 196 }
197 197
198 // Check to see if we already have the color in the cache. 198 // Check to see if we already have the color in the cache.
199 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); 199 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id);
200 if (nscolor_iter != nscolor_cache_.end()) 200 if (nscolor_iter != nscolor_cache_.end())
201 return nscolor_iter->second; 201 return nscolor_iter->second;
202 202
203 SkColor sk_color = GetColor(original_id, incognito); 203 SkColor sk_color = GetColor(original_id, incognito);
204 NSColor* color = nil; 204 NSColor* color = nil;
205 if (is_mode_material) { 205 if (is_mode_material) {
206 color = skia::SkColorToSRGBNSColor(sk_color); 206 color = skia::SkColorToSRGBNSColor(sk_color);
207 } else { 207 } else {
208 color = skia::SkColorToCalibratedNSColor(sk_color); 208 color = skia::SkColorToCalibratedNSColor(sk_color);
209 } 209 }
210 210
211 // We loaded successfully. Cache the color. 211 // We loaded successfully. Cache the color.
212 if (color) 212 if (color)
213 nscolor_cache_[id] = [color retain]; 213 nscolor_cache_[id] = [color retain];
214 214
215 return color; 215 return color;
216 } 216 }
217 217
218 NSColor* ThemeService::GetNSColorTint(int id) const { 218 NSColor* ThemeService::GetNSColorTint(int id) const {
219 DCHECK(CalledOnValidThread()); 219 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
220 220
221 // Check to see if we already have the color in the cache. 221 // Check to see if we already have the color in the cache.
222 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); 222 NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id);
223 if (nscolor_iter != nscolor_cache_.end()) 223 if (nscolor_iter != nscolor_cache_.end())
224 return nscolor_iter->second; 224 return nscolor_iter->second;
225 225
226 color_utils::HSL tint = GetTint(id, false); 226 color_utils::HSL tint = GetTint(id, false);
227 NSColor* tint_color = nil; 227 NSColor* tint_color = nil;
228 if (tint.h == -1 && tint.s == -1 && tint.l == -1) { 228 if (tint.h == -1 && tint.s == -1 && tint.l == -1) {
229 tint_color = [NSColor blackColor]; 229 tint_color = [NSColor blackColor];
230 } else { 230 } else {
231 CGFloat hue, saturation, brightness; 231 CGFloat hue, saturation, brightness;
232 HSLToHSB(tint, &hue, &saturation, &brightness); 232 HSLToHSB(tint, &hue, &saturation, &brightness);
233 233
234 tint_color = [NSColor colorWithCalibratedHue:hue 234 tint_color = [NSColor colorWithCalibratedHue:hue
235 saturation:saturation 235 saturation:saturation
236 brightness:brightness 236 brightness:brightness
237 alpha:1.0]; 237 alpha:1.0];
238 } 238 }
239 239
240 // We loaded successfully. Cache the color. 240 // We loaded successfully. Cache the color.
241 if (tint_color) 241 if (tint_color)
242 nscolor_cache_[id] = [tint_color retain]; 242 nscolor_cache_[id] = [tint_color retain];
243 243
244 return tint_color; 244 return tint_color;
245 } 245 }
246 246
247 NSGradient* ThemeService::GetNSGradient(int id) const { 247 NSGradient* ThemeService::GetNSGradient(int id) const {
248 DCHECK(CalledOnValidThread()); 248 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
249 249
250 // Check to see if we already have the gradient in the cache. 250 // Check to see if we already have the gradient in the cache.
251 NSGradientMap::const_iterator nsgradient_iter = nsgradient_cache_.find(id); 251 NSGradientMap::const_iterator nsgradient_iter = nsgradient_cache_.find(id);
252 if (nsgradient_iter != nsgradient_cache_.end()) 252 if (nsgradient_iter != nsgradient_cache_.end())
253 return nsgradient_iter->second; 253 return nsgradient_iter->second;
254 254
255 NSGradient* gradient = nil; 255 NSGradient* gradient = nil;
256 256
257 // Note that we are not leaking when we assign a retained object to 257 // Note that we are not leaking when we assign a retained object to
258 // |gradient|; in all cases we cache it before we return. 258 // |gradient|; in all cases we cache it before we return.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 // Let all the browser views know that themes have changed in a platform way. 323 // Let all the browser views know that themes have changed in a platform way.
324 void ThemeService::NotifyPlatformThemeChanged() { 324 void ThemeService::NotifyPlatformThemeChanged() {
325 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 325 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
326 [defaultCenter postNotificationName:kBrowserThemeDidChangeNotification 326 [defaultCenter postNotificationName:kBrowserThemeDidChangeNotification
327 object:[NSValue valueWithPointer:this]]; 327 object:[NSValue valueWithPointer:this]];
328 } 328 }
329 329
330 void ThemeService::FreePlatformCaches() { 330 void ThemeService::FreePlatformCaches() {
331 DCHECK(CalledOnValidThread()); 331 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
332 332
333 // Free images. 333 // Free images.
334 for (NSImageMap::iterator i = nsimage_cache_.begin(); 334 for (NSImageMap::iterator i = nsimage_cache_.begin();
335 i != nsimage_cache_.end(); i++) { 335 i != nsimage_cache_.end(); i++) {
336 [i->second release]; 336 [i->second release];
337 } 337 }
338 nsimage_cache_.clear(); 338 nsimage_cache_.clear();
339 339
340 // Free colors. 340 // Free colors.
341 for (NSColorMap::iterator i = nscolor_cache_.begin(); 341 for (NSColorMap::iterator i = nscolor_cache_.begin();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 bool ThemeService::BrowserThemeProvider::ShouldIncreaseContrast() const { 388 bool ThemeService::BrowserThemeProvider::ShouldIncreaseContrast() const {
389 NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; 389 NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
390 if ([workspace 390 if ([workspace
391 respondsToSelector:@selector( 391 respondsToSelector:@selector(
392 accessibilityDisplayShouldIncreaseContrast)]) { 392 accessibilityDisplayShouldIncreaseContrast)]) {
393 return workspace.accessibilityDisplayShouldIncreaseContrast == YES; 393 return workspace.accessibilityDisplayShouldIncreaseContrast == YES;
394 } 394 }
395 return false; 395 return false;
396 } 396 }
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698