Chromium Code Reviews| 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 standard_font_.Init(prefs::kWebKitStandardFontFamily, |
| 110 serif_font_.Init(prefs::kWebKitSerifFontFamily, pref_service, this); | 110 pref_service, |
| 111 sans_serif_font_.Init(prefs::kWebKitSansSerifFontFamily, pref_service, this); | 111 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, |
| 112 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); | 112 base::Unretained(this))); |
| 113 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); | 113 serif_font_.Init(prefs::kWebKitSerifFontFamily, |
| 114 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); | 114 pref_service, |
| 115 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, | 115 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, |
| 116 pref_service, this); | 116 base::Unretained(this))); |
| 117 minimum_font_size_.Init(prefs::kWebKitMinimumFontSize, pref_service, this); | 117 sans_serif_font_.Init( |
| 118 prefs::kWebKitSansSerifFontFamily, | |
| 119 pref_service, | |
| 120 base::Bind(&FontSettingsHandler::SetUpSansSerifFontSample, | |
| 121 base::Unretained(this))); | |
| 122 fixed_font_.Init(prefs::kWebKitFixedFontFamily, | |
| 123 pref_service, | |
| 124 base::Bind(&FontSettingsHandler::SetUpFixedFontSample, | |
|
Jói
2012/11/21 13:37:45
I would group the initialization of fixed_font_ an
tfarina
2012/11/21 13:48:33
Done.
| |
| 125 base::Unretained(this))); | |
| 126 font_encoding_.Init(prefs::kDefaultCharset, | |
| 127 pref_service, | |
| 128 base::Bind(&base::DoNothing)); | |
|
Mattias Nissler (ping if slow)
2012/11/21 13:29:26
If we really don't want a change notification call
tfarina
2012/11/21 13:36:24
That was my first attempt.
But dropping it causes
Jói
2012/11/21 13:37:45
Agreed we should ask an OWNER.
Jói
2012/11/21 13:52:39
For now, you can pass a NULL as the 3rd argument.
falken
2012/11/21 14:21:45
Right, there's nothing to do when the encoding cha
| |
| 129 default_font_size_.Init( | |
| 130 prefs::kWebKitDefaultFontSize, | |
| 131 pref_service, | |
| 132 base::Bind(&FontSettingsHandler::OnWebKitDefaultFontSizeChanged, | |
| 133 base::Unretained(this))); | |
| 134 default_fixed_font_size_.Init( | |
| 135 prefs::kWebKitDefaultFixedFontSize, | |
| 136 pref_service, | |
| 137 base::Bind(&FontSettingsHandler::SetUpFixedFontSample, | |
| 138 base::Unretained(this))); | |
| 139 minimum_font_size_.Init( | |
| 140 prefs::kWebKitMinimumFontSize, | |
| 141 pref_service, | |
| 142 base::Bind(&FontSettingsHandler::SetUpMinimumFontSample, | |
| 143 base::Unretained(this))); | |
| 118 | 144 |
| 119 web_ui()->RegisterMessageCallback("fetchFontsData", | 145 web_ui()->RegisterMessageCallback("fetchFontsData", |
| 120 base::Bind(&FontSettingsHandler::HandleFetchFontsData, | 146 base::Bind(&FontSettingsHandler::HandleFetchFontsData, |
| 121 base::Unretained(this))); | 147 base::Unretained(this))); |
| 122 } | 148 } |
| 123 | 149 |
| 124 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { | 150 void FontSettingsHandler::HandleFetchFontsData(const ListValue* args) { |
| 125 content::GetFontListAsync( | 151 content::GetFontListAsync( |
| 126 base::Bind(&FontSettingsHandler::FontsListHasLoaded, | 152 base::Bind(&FontSettingsHandler::FontsListHasLoaded, |
| 127 base::Unretained(this))); | 153 base::Unretained(this))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 sans_serif_font_.GetValue()))); | 206 sans_serif_font_.GetValue()))); |
| 181 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 207 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( |
| 182 fixed_font_.GetValue()))); | 208 fixed_font_.GetValue()))); |
| 183 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); | 209 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); |
| 184 | 210 |
| 185 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", | 211 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", |
| 186 *list.get(), encoding_list, | 212 *list.get(), encoding_list, |
| 187 selected_values); | 213 selected_values); |
| 188 } | 214 } |
| 189 | 215 |
| 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() { | 216 void FontSettingsHandler::SetUpStandardFontSample() { |
| 211 base::StringValue font_value(standard_font_.GetValue()); | 217 base::StringValue font_value(standard_font_.GetValue()); |
| 212 base::FundamentalValue size_value(default_font_size_.GetValue()); | 218 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 213 web_ui()->CallJavascriptFunction( | 219 web_ui()->CallJavascriptFunction( |
| 214 "FontSettings.setUpStandardFontSample", font_value, size_value); | 220 "FontSettings.setUpStandardFontSample", font_value, size_value); |
| 215 } | 221 } |
| 216 | 222 |
| 217 void FontSettingsHandler::SetUpSerifFontSample() { | 223 void FontSettingsHandler::SetUpSerifFontSample() { |
| 218 base::StringValue font_value(serif_font_.GetValue()); | 224 base::StringValue font_value(serif_font_.GetValue()); |
| 219 base::FundamentalValue size_value(default_font_size_.GetValue()); | 225 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 234 web_ui()->CallJavascriptFunction( | 240 web_ui()->CallJavascriptFunction( |
| 235 "FontSettings.setUpFixedFontSample", font_value, size_value); | 241 "FontSettings.setUpFixedFontSample", font_value, size_value); |
| 236 } | 242 } |
| 237 | 243 |
| 238 void FontSettingsHandler::SetUpMinimumFontSample() { | 244 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 239 base::FundamentalValue size_value(minimum_font_size_.GetValue()); | 245 base::FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 240 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", | 246 web_ui()->CallJavascriptFunction("FontSettings.setUpMinimumFontSample", |
| 241 size_value); | 247 size_value); |
| 242 } | 248 } |
| 243 | 249 |
| 250 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { | |
| 251 SetUpStandardFontSample(); | |
| 252 SetUpSerifFontSample(); | |
| 253 SetUpSansSerifFontSample(); | |
| 254 } | |
| 255 | |
| 244 } // namespace options | 256 } // namespace options |
| OLD | NEW |