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

Side by Side Diff: chrome/browser/ui/webui/options/font_settings_handler.cc

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_handler.h" 5 #include "chrome/browser/ui/webui/options/font_settings_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/character_encoding.h" 16 #include "chrome/browser/character_encoding.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 19 #include "chrome/browser/ui/webui/options/font_settings_utils.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
21 #include "content/common/notification_type.h" 22 #include "content/common/notification_type.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 26
26 FontSettingsHandler::FontSettingsHandler() { 27 FontSettingsHandler::FontSettingsHandler() {
27 fonts_list_loader_ = new FontSettingsFontsListLoader(this);
28 } 28 }
29 29
30 FontSettingsHandler::~FontSettingsHandler() { 30 FontSettingsHandler::~FontSettingsHandler() {
31 if (fonts_list_loader_)
32 fonts_list_loader_->SetObserver(NULL);
33 } 31 }
34 32
35 void FontSettingsHandler::GetLocalizedValues( 33 void FontSettingsHandler::GetLocalizedValues(
36 DictionaryValue* localized_strings) { 34 DictionaryValue* localized_strings) {
37 DCHECK(localized_strings); 35 DCHECK(localized_strings);
38 36
39 static OptionsStringResource resources[] = { 37 static OptionsStringResource resources[] = {
40 { "fontSettingsStandard", 38 { "fontSettingsStandard",
41 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL }, 39 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL },
42 { "fontSettingsSerif", 40 { "fontSettingsSerif",
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Return result from the superclass. 95 // Return result from the superclass.
98 return handler; 96 return handler;
99 } 97 }
100 98
101 void FontSettingsHandler::RegisterMessages() { 99 void FontSettingsHandler::RegisterMessages() {
102 web_ui_->RegisterMessageCallback("fetchFontsData", 100 web_ui_->RegisterMessageCallback("fetchFontsData",
103 NewCallback(this, &FontSettingsHandler::HandleFetchFontsData)); 101 NewCallback(this, &FontSettingsHandler::HandleFetchFontsData));
104 } 102 }
105 103
106 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { 104 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) {
107 fonts_list_loader_->StartLoadFontsList(); 105 content::GetFontListAsync(
106 base::Bind(&FontSettingsHandler::FontsListHasLoaded, AsWeakPtr()));
108 } 107 }
109 108
110 void FontSettingsHandler::FontsListHasLoaded() { 109 void FontSettingsHandler::FontsListHasLoaded(
111 ListValue* fonts_list = fonts_list_loader_->GetFontsList(); 110 scoped_refptr<content::FontListResult> list) {
112
113 ListValue encoding_list; 111 ListValue encoding_list;
114 const std::vector<CharacterEncoding::EncodingInfo>* encodings; 112 const std::vector<CharacterEncoding::EncodingInfo>* encodings;
115 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); 113 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs();
116 encodings = CharacterEncoding::GetCurrentDisplayEncodings( 114 encodings = CharacterEncoding::GetCurrentDisplayEncodings(
117 g_browser_process->GetApplicationLocale(), 115 g_browser_process->GetApplicationLocale(),
118 pref_service->GetString(prefs::kStaticEncodings), 116 pref_service->GetString(prefs::kStaticEncodings),
119 pref_service->GetString(prefs::kRecentlySelectedEncoding)); 117 pref_service->GetString(prefs::kRecentlySelectedEncoding));
120 DCHECK(encodings); 118 DCHECK(encodings);
121 DCHECK(!encodings->empty()); 119 DCHECK(!encodings->empty());
122 120
(...skipping 17 matching lines...) Expand all
140 } 138 }
141 139
142 ListValue selected_values; 140 ListValue selected_values;
143 selected_values.Append(Value::CreateStringValue(standard_font_.GetValue())); 141 selected_values.Append(Value::CreateStringValue(standard_font_.GetValue()));
144 selected_values.Append(Value::CreateStringValue(serif_font_.GetValue())); 142 selected_values.Append(Value::CreateStringValue(serif_font_.GetValue()));
145 selected_values.Append(Value::CreateStringValue(sans_serif_font_.GetValue())); 143 selected_values.Append(Value::CreateStringValue(sans_serif_font_.GetValue()));
146 selected_values.Append(Value::CreateStringValue(fixed_font_.GetValue())); 144 selected_values.Append(Value::CreateStringValue(fixed_font_.GetValue()));
147 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); 145 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue()));
148 146
149 web_ui_->CallJavascriptFunction("FontSettings.setFontsData", 147 web_ui_->CallJavascriptFunction("FontSettings.setFontsData",
150 *fonts_list, encoding_list, selected_values); 148 *list->list.get(), encoding_list,
149 selected_values);
151 } 150 }
152 151
153 void FontSettingsHandler::Observe(NotificationType type, 152 void FontSettingsHandler::Observe(NotificationType type,
154 const NotificationSource& source, 153 const NotificationSource& source,
155 const NotificationDetails& details) { 154 const NotificationDetails& details) {
156 if (type == NotificationType::PREF_CHANGED) { 155 if (type == NotificationType::PREF_CHANGED) {
157 std::string* pref_name = Details<std::string>(details).ptr(); 156 std::string* pref_name = Details<std::string>(details).ptr();
158 if (*pref_name == prefs::kWebKitStandardFontFamily) { 157 if (*pref_name == prefs::kWebKitStandardFontFamily) {
159 SetUpStandardFontSample(); 158 SetUpStandardFontSample();
160 } else if (*pref_name == prefs::kWebKitSerifFontFamily) { 159 } else if (*pref_name == prefs::kWebKitSerifFontFamily) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 FundamentalValue size_value(default_fixed_font_size_.GetValue()); 199 FundamentalValue size_value(default_fixed_font_size_.GetValue());
201 web_ui_->CallJavascriptFunction( 200 web_ui_->CallJavascriptFunction(
202 "FontSettings.setUpFixedFontSample", font_value, size_value); 201 "FontSettings.setUpFixedFontSample", font_value, size_value);
203 } 202 }
204 203
205 void FontSettingsHandler::SetUpMinimumFontSample() { 204 void FontSettingsHandler::SetUpMinimumFontSample() {
206 FundamentalValue size_value(minimum_font_size_.GetValue()); 205 FundamentalValue size_value(minimum_font_size_.GetValue());
207 web_ui_->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", 206 web_ui_->CallJavascriptFunction("FontSettings.setUpMinimumFontSample",
208 size_value); 207 size_value);
209 } 208 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_handler.h ('k') | chrome/browser/ui/webui/options/font_settings_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698