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

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

Issue 7044012: Support getting the font list in Pepper. This currently only works out of (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
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/ui/webui/options/font_settings_utils.h" 5 #include "content/common/font_list.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_nsautorelease_pool.h" 9 #include "base/mac/scoped_nsautorelease_pool.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
viettrungluu 2011/05/18 20:40:43 I believe the two prefs includes aren't needed her
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 14
15 static void ValidateFontFamily(PrefService* prefs, 15 namespace content {
16 const char* family_pref_name) {
17 // The native font settings dialog saved fonts by the font name, rather
18 // than the family name. This worked for the old dialog since
19 // -[NSFont fontWithName:size] accepted a font or family name, but the
20 // behavior was technically wrong. Since we really need the family name for
21 // the dom-ui options window, we will fix the saved preference if necessary.
22 NSString *family_name =
23 base::SysUTF8ToNSString(prefs->GetString(family_pref_name));
24 NSFont *font = [NSFont fontWithName:family_name
25 size:[NSFont systemFontSize]];
26 if (font &&
27 [[font familyName] caseInsensitiveCompare:family_name] != NSOrderedSame) {
28 std::string new_family_name = base::SysNSStringToUTF8([font familyName]);
29 prefs->SetString(family_pref_name, new_family_name);
30 }
31 }
32 16
33 ListValue* FontSettingsUtilities::GetFontsList() { 17 ListValue* GetFontList_SlowBlocking() {
34 base::mac::ScopedNSAutoreleasePool autorelease_pool; 18 base::mac::ScopedNSAutoreleasePool autorelease_pool;
35 ListValue* font_list = new ListValue; 19 ListValue* font_list = new ListValue;
36 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease]; 20 NSFontManager* fontManager = [[[NSFontManager alloc] init] autorelease];
37 NSArray* fonts = [fontManager availableFontFamilies]; 21 NSArray* fonts = [fontManager availableFontFamilies];
38 for (NSString* family_name in fonts) { 22 for (NSString* family_name in fonts) {
39 NSString* localized_family_name = 23 NSString* localized_family_name =
40 [fontManager localizedNameForFamily:family_name face:nil]; 24 [fontManager localizedNameForFamily:family_name face:nil];
41 ListValue* font_item = new ListValue(); 25 ListValue* font_item = new ListValue();
42 string16 family = base::SysNSStringToUTF16(family_name); 26 string16 family = base::SysNSStringToUTF16(family_name);
43 font_item->Append(Value::CreateStringValue(family)); 27 font_item->Append(Value::CreateStringValue(family));
44 string16 loc_family = base::SysNSStringToUTF16(localized_family_name); 28 string16 loc_family = base::SysNSStringToUTF16(localized_family_name);
45 font_item->Append(Value::CreateStringValue(loc_family)); 29 font_item->Append(Value::CreateStringValue(loc_family));
46 font_list->Append(font_item); 30 font_list->Append(font_item);
47 } 31 }
48 return font_list; 32 return font_list;
49 } 33 }
50 34
51 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { 35 } // namespace content
52 ValidateFontFamily(prefs, prefs::kWebKitSerifFontFamily);
53 ValidateFontFamily(prefs, prefs::kWebKitSansSerifFontFamily);
54 ValidateFontFamily(prefs, prefs::kWebKitFixedFontFamily);
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698