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

Side by Side Diff: content/common/font_list_mac.mm

Issue 2817603003: Remove ListValue::Append(raw ptr) on Mac and iOS (Closed)
Patch Set: Comments Created 3 years, 8 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
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 "content/common/font_list.h" 5 #include "content/common/font_list.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <utility>
10
9 #include "base/mac/scoped_nsautorelease_pool.h" 11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #include "base/memory/ptr_util.h"
10 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
11 #include "base/values.h" 14 #include "base/values.h"
12 15
13 namespace content { 16 namespace content {
14 17
15 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() { 18 std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
16 base::mac::ScopedNSAutoreleasePool autorelease_pool; 19 base::mac::ScopedNSAutoreleasePool autorelease_pool;
17 std::unique_ptr<base::ListValue> font_list(new base::ListValue); 20 std::unique_ptr<base::ListValue> font_list(new base::ListValue);
18 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; 21 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
19 NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary]; 22 NSMutableDictionary* fonts_dict = [NSMutableDictionary dictionary];
20 NSArray* fonts = [fontManager availableFontFamilies]; 23 NSArray* fonts = [fontManager availableFontFamilies];
21 24
22 for (NSString* family_name in fonts) { 25 for (NSString* family_name in fonts) {
23 NSString* localized_family_name = 26 NSString* localized_family_name =
24 [fontManager localizedNameForFamily:family_name face:nil]; 27 [fontManager localizedNameForFamily:family_name face:nil];
25 fonts_dict[family_name] = localized_family_name; 28 fonts_dict[family_name] = localized_family_name;
26 } 29 }
27 30
28 // Sort family names based on localized names. 31 // Sort family names based on localized names.
29 NSArray* sortedFonts = [fonts_dict 32 NSArray* sortedFonts = [fonts_dict
30 keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)]; 33 keysSortedByValueUsingSelector:@selector(localizedStandardCompare:)];
31 34
32 for (NSString* family_name in sortedFonts) { 35 for (NSString* family_name in sortedFonts) {
33 NSString* localized_family_name = fonts_dict[family_name]; 36 NSString* localized_family_name = fonts_dict[family_name];
34 base::ListValue* font_item = new base::ListValue(); 37 auto font_item = base::MakeUnique<base::ListValue>();
35 base::string16 family = base::SysNSStringToUTF16(family_name); 38 font_item->AppendString(base::SysNSStringToUTF16(family_name));
36 base::string16 loc_family = base::SysNSStringToUTF16(localized_family_name); 39 font_item->AppendString(base::SysNSStringToUTF16(localized_family_name));
37 font_item->Append(new base::Value(family)); 40 font_list->Append(std::move(font_item));
38 font_item->Append(new base::Value(loc_family));
39 font_list->Append(font_item);
40 } 41 }
41 42
42 return font_list; 43 return font_list;
43 } 44 }
44 45
45 } // namespace content 46 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/accessibility_tree_formatter_mac.mm ('k') | ios/chrome/browser/passwords/password_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698