| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 SetUpFixedFontSample(); | 99 SetUpFixedFontSample(); |
| 100 SetUpMinimumFontSample(); | 100 SetUpMinimumFontSample(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void FontSettingsHandler::RegisterMessages() { | 103 void FontSettingsHandler::RegisterMessages() { |
| 104 // Perform validation for saved fonts. | 104 // Perform validation for saved fonts. |
| 105 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 105 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 106 FontSettingsUtilities::ValidateSavedFonts(pref_service); | 106 FontSettingsUtilities::ValidateSavedFonts(pref_service); |
| 107 | 107 |
| 108 // Register for preferences that we need to observe manually. | 108 // Register for preferences that we need to observe manually. |
| 109 standard_font_.Init(prefs::kWebKitStandardFontFamily, pref_service, this); | 109 font_encoding_.Init(prefs::kDefaultCharset, pref_service, NULL); |
| 110 serif_font_.Init(prefs::kWebKitSerifFontFamily, pref_service, this); | 110 |
| 111 sans_serif_font_.Init(prefs::kWebKitSansSerifFontFamily, pref_service, this); | 111 standard_font_.Init(prefs::kWebKitStandardFontFamily, |
| 112 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); | 112 pref_service, |
| 113 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); | 113 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, |
| 114 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); | 114 base::Unretained(this))); |
| 115 serif_font_.Init(prefs::kWebKitSerifFontFamily, |
| 116 pref_service, |
| 117 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, |
| 118 base::Unretained(this))); |
| 119 sans_serif_font_.Init( |
| 120 prefs::kWebKitSansSerifFontFamily, |
| 121 pref_service, |
| 122 base::Bind(&FontSettingsHandler::SetUpSansSerifFontSample, |
| 123 base::Unretained(this))); |
| 124 |
| 125 base::Closure callback = base::Bind( |
| 126 &FontSettingsHandler::SetUpFixedFontSample, base::Unretained(this)); |
| 127 |
| 128 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, callback); |
| 115 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, | 129 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, |
| 116 pref_service, this); | 130 pref_service, callback); |
| 117 minimum_font_size_.Init(prefs::kWebKitMinimumFontSize, pref_service, this); | 131 default_font_size_.Init( |
| 132 prefs::kWebKitDefaultFontSize, |
| 133 pref_service, |
| 134 base::Bind(&FontSettingsHandler::OnWebKitDefaultFontSizeChanged, |
| 135 base::Unretained(this))); |
| 136 minimum_font_size_.Init( |
| 137 prefs::kWebKitMinimumFontSize, |
| 138 pref_service, |
| 139 base::Bind(&FontSettingsHandler::SetUpMinimumFontSample, |
| 140 base::Unretained(this))); |
| 118 | 141 |
| 119 web_ui()->RegisterMessageCallback("fetchFontsData", | 142 web_ui()->RegisterMessageCallback("fetchFontsData", |
| 120 base::Bind(&FontSettingsHandler::HandleFetchFontsData, | 143 base::Bind(&FontSettingsHandler::HandleFetchFontsData, |
| 121 base::Unretained(this))); | 144 base::Unretained(this))); |
| 122 } | 145 } |
| 123 | 146 |
| 124 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { | 147 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { |
| 125 content::GetFontListAsync( | 148 content::GetFontListAsync( |
| 126 base::Bind(&FontSettingsHandler::FontsListHasLoaded, | 149 base::Bind(&FontSettingsHandler::FontsListHasLoaded, |
| 127 base::Unretained(this))); | 150 base::Unretained(this))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 sans_serif_font_.GetValue()))); | 203 sans_serif_font_.GetValue()))); |
| 181 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 204 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( |
| 182 fixed_font_.GetValue()))); | 205 fixed_font_.GetValue()))); |
| 183 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); | 206 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); |
| 184 | 207 |
| 185 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", | 208 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", |
| 186 *list.get(), encoding_list, | 209 *list.get(), encoding_list, |
| 187 selected_values); | 210 selected_values); |
| 188 } | 211 } |
| 189 | 212 |
| 190 void FontSettingsHandler::OnPreferenceChanged(PrefServiceBase* service, | |
| 191 const std::string& pref_name) { | |
| 192 if (pref_name == prefs::kWebKitStandardFontFamily) { | |
| 193 SetUpStandardFontSample(); | |
| 194 } else if (pref_name == prefs::kWebKitSerifFontFamily) { | |
| 195 SetUpSerifFontSample(); | |
| 196 } else if (pref_name == prefs::kWebKitSansSerifFontFamily) { | |
| 197 SetUpSansSerifFontSample(); | |
| 198 } else if (pref_name == prefs::kWebKitFixedFontFamily || | |
| 199 pref_name == prefs::kWebKitDefaultFixedFontSize) { | |
| 200 SetUpFixedFontSample(); | |
| 201 } else if (pref_name == prefs::kWebKitDefaultFontSize) { | |
| 202 SetUpStandardFontSample(); | |
| 203 SetUpSerifFontSample(); | |
| 204 SetUpSansSerifFontSample(); | |
| 205 } else if (pref_name == prefs::kWebKitMinimumFontSize) { | |
| 206 SetUpMinimumFontSample(); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 void FontSettingsHandler::SetUpStandardFontSample() { | 213 void FontSettingsHandler::SetUpStandardFontSample() { |
| 211 base::StringValue font_value(standard_font_.GetValue()); | 214 base::StringValue font_value(standard_font_.GetValue()); |
| 212 base::FundamentalValue size_value(default_font_size_.GetValue()); | 215 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 213 web_ui()->CallJavascriptFunction( | 216 web_ui()->CallJavascriptFunction( |
| 214 "FontSettings.setUpStandardFontSample", font_value, size_value); | 217 "FontSettings.setUpStandardFontSample", font_value, size_value); |
| 215 } | 218 } |
| 216 | 219 |
| 217 void FontSettingsHandler::SetUpSerifFontSample() { | 220 void FontSettingsHandler::SetUpSerifFontSample() { |
| 218 base::StringValue font_value(serif_font_.GetValue()); | 221 base::StringValue font_value(serif_font_.GetValue()); |
| 219 base::FundamentalValue size_value(default_font_size_.GetValue()); | 222 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 234 web_ui()->CallJavascriptFunction( | 237 web_ui()->CallJavascriptFunction( |
| 235 "FontSettings.setUpFixedFontSample", font_value, size_value); | 238 "FontSettings.setUpFixedFontSample", font_value, size_value); |
| 236 } | 239 } |
| 237 | 240 |
| 238 void FontSettingsHandler::SetUpMinimumFontSample() { | 241 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 239 base::FundamentalValue size_value(minimum_font_size_.GetValue()); | 242 base::FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 240 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", | 243 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", |
| 241 size_value); | 244 size_value); |
| 242 } | 245 } |
| 243 | 246 |
| 247 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
| 248 SetUpStandardFontSample(); |
| 249 SetUpSerifFontSample(); |
| 250 SetUpSansSerifFontSample(); |
| 251 } |
| 252 |
| 244 } // namespace options | 253 } // namespace options |
| OLD | NEW |