| OLD | NEW |
| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 fonts_list_loader_->SetObserver(NULL); | 32 fonts_list_loader_->SetObserver(NULL); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void FontSettingsHandler::GetLocalizedValues( | 35 void FontSettingsHandler::GetLocalizedValues( |
| 36 DictionaryValue* localized_strings) { | 36 DictionaryValue* localized_strings) { |
| 37 DCHECK(localized_strings); | 37 DCHECK(localized_strings); |
| 38 | 38 |
| 39 static OptionsStringResource resources[] = { | 39 static OptionsStringResource resources[] = { |
| 40 { "fontSettingsStandard", | 40 { "fontSettingsStandard", |
| 41 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL }, | 41 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL }, |
| 42 { "fontSettingsSerif", |
| 43 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL }, |
| 44 { "fontSettingsSansSerif", |
| 45 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL }, |
| 42 { "fontSettingsFixedWidth", | 46 { "fontSettingsFixedWidth", |
| 43 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL }, | 47 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL }, |
| 44 { "fontSettingsMinimumSize", | 48 { "fontSettingsMinimumSize", |
| 45 IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE }, | 49 IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE }, |
| 46 { "fontSettingsEncoding", | 50 { "fontSettingsEncoding", |
| 47 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE }, | 51 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE }, |
| 48 { "fontSettingsSizeLabel", | 52 { "fontSettingsSizeLabel", |
| 49 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_SELECTOR_LABEL }, | 53 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_SELECTOR_LABEL }, |
| 50 { "fontSettingsSizeTiny", | 54 { "fontSettingsSizeTiny", |
| 51 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_TINY }, | 55 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_TINY }, |
| 52 { "fontSettingsSizeHuge", | 56 { "fontSettingsSizeHuge", |
| 53 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_HUGE }, | 57 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_HUGE }, |
| 54 { "fontSettingsEncodingLabel", | 58 { "fontSettingsEncodingLabel", |
| 55 IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL }, | 59 IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL }, |
| 56 { "fontSettingsLoremIpsum", | 60 { "fontSettingsLoremIpsum", |
| 57 IDS_FONT_LANGUAGE_SETTING_LOREM_IPSUM }, | 61 IDS_FONT_LANGUAGE_SETTING_LOREM_IPSUM }, |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 RegisterStrings(localized_strings, resources, arraysize(resources)); | 64 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 61 RegisterTitle(localized_strings, "fontSettingsPage", | 65 RegisterTitle(localized_strings, "fontSettingsPage", |
| 62 IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE); | 66 IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE); |
| 63 localized_strings->SetString("fontSettingsPlaceholder", | 67 localized_strings->SetString("fontSettingsPlaceholder", |
| 64 l10n_util::GetStringUTF16( | 68 l10n_util::GetStringUTF16( |
| 65 IDS_FONT_LANGUAGE_SETTING_PLACEHOLDER)); | 69 IDS_FONT_LANGUAGE_SETTING_PLACEHOLDER)); |
| 66 } | 70 } |
| 67 | 71 |
| 68 void FontSettingsHandler::Initialize() { | 72 void FontSettingsHandler::Initialize() { |
| 69 DCHECK(web_ui_); | 73 DCHECK(web_ui_); |
| 70 SetupStandardFontSample(); | 74 SetupStandardFontSample(); |
| 75 SetupSerifFontSample(); |
| 76 SetupSansSerifFontSample(); |
| 77 SetupFixedFontSample(); |
| 71 SetupMinimumFontSample(); | 78 SetupMinimumFontSample(); |
| 72 SetupFixedFontSample(); | |
| 73 } | 79 } |
| 74 | 80 |
| 75 WebUIMessageHandler* FontSettingsHandler::Attach(WebUI* web_ui) { | 81 WebUIMessageHandler* FontSettingsHandler::Attach(WebUI* web_ui) { |
| 76 // Call through to superclass. | 82 // Call through to superclass. |
| 77 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); | 83 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); |
| 78 | 84 |
| 79 // Perform validation for saved fonts. | 85 // Perform validation for saved fonts. |
| 80 DCHECK(web_ui_); | 86 DCHECK(web_ui_); |
| 81 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); | 87 PrefService* pref_service = web_ui_->GetProfile()->GetPrefs(); |
| 82 FontSettingsUtilities::ValidateSavedFonts(pref_service); | 88 FontSettingsUtilities::ValidateSavedFonts(pref_service); |
| 83 | 89 |
| 84 // Register for preferences that we need to observe manually. | 90 // Register for preferences that we need to observe manually. |
| 85 standard_font_.Init(prefs::kWebKitStandardFontFamily, pref_service, this); | 91 standard_font_.Init(prefs::kWebKitStandardFontFamily, pref_service, this); |
| 92 serif_font_.Init(prefs::kWebKitSerifFontFamily, pref_service, this); |
| 93 sans_serif_font_.Init(prefs::kWebKitSansSerifFontFamily, pref_service, this); |
| 86 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); | 94 fixed_font_.Init(prefs::kWebKitFixedFontFamily, pref_service, this); |
| 87 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); | 95 font_encoding_.Init(prefs::kDefaultCharset, pref_service, this); |
| 88 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); | 96 default_font_size_.Init(prefs::kWebKitDefaultFontSize, pref_service, this); |
| 89 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, | 97 default_fixed_font_size_.Init(prefs::kWebKitDefaultFixedFontSize, |
| 90 pref_service, this); | 98 pref_service, this); |
| 91 minimum_font_size_.Init(prefs::kWebKitMinimumFontSize, pref_service, this); | 99 minimum_font_size_.Init(prefs::kWebKitMinimumFontSize, pref_service, this); |
| 92 | 100 |
| 93 // Return result from the superclass. | 101 // Return result from the superclass. |
| 94 return handler; | 102 return handler; |
| 95 } | 103 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } else { | 138 } else { |
| 131 // Add empty name/value to indicate a separator item. | 139 // Add empty name/value to indicate a separator item. |
| 132 option->Append(Value::CreateStringValue("")); | 140 option->Append(Value::CreateStringValue("")); |
| 133 option->Append(Value::CreateStringValue("")); | 141 option->Append(Value::CreateStringValue("")); |
| 134 } | 142 } |
| 135 encoding_list.Append(option); | 143 encoding_list.Append(option); |
| 136 } | 144 } |
| 137 | 145 |
| 138 ListValue selected_values; | 146 ListValue selected_values; |
| 139 selected_values.Append(Value::CreateStringValue(standard_font_.GetValue())); | 147 selected_values.Append(Value::CreateStringValue(standard_font_.GetValue())); |
| 148 selected_values.Append(Value::CreateStringValue(serif_font_.GetValue())); |
| 149 selected_values.Append(Value::CreateStringValue(sans_serif_font_.GetValue())); |
| 140 selected_values.Append(Value::CreateStringValue(fixed_font_.GetValue())); | 150 selected_values.Append(Value::CreateStringValue(fixed_font_.GetValue())); |
| 141 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); | 151 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); |
| 142 | 152 |
| 143 web_ui_->CallJavascriptFunction("FontSettings.setFontsData", | 153 web_ui_->CallJavascriptFunction("FontSettings.setFontsData", |
| 144 *fonts_list, encoding_list, selected_values); | 154 *fonts_list, encoding_list, selected_values); |
| 145 } | 155 } |
| 146 | 156 |
| 147 void FontSettingsHandler::Observe(NotificationType type, | 157 void FontSettingsHandler::Observe(NotificationType type, |
| 148 const NotificationSource& source, | 158 const NotificationSource& source, |
| 149 const NotificationDetails& details) { | 159 const NotificationDetails& details) { |
| 150 if (type == NotificationType::PREF_CHANGED) { | 160 if (type == NotificationType::PREF_CHANGED) { |
| 151 std::string* pref_name = Details<std::string>(details).ptr(); | 161 std::string* pref_name = Details<std::string>(details).ptr(); |
| 152 if (*pref_name == prefs::kWebKitStandardFontFamily || | 162 if (*pref_name == prefs::kWebKitStandardFontFamily) { |
| 153 *pref_name == prefs::kWebKitDefaultFontSize) { | |
| 154 SetupStandardFontSample(); | 163 SetupStandardFontSample(); |
| 164 } else if (*pref_name == prefs::kWebKitSerifFontFamily) { |
| 165 SetupSerifFontSample(); |
| 166 } else if (*pref_name == prefs::kWebKitSansSerifFontFamily) { |
| 167 SetupSansSerifFontSample(); |
| 155 } else if (*pref_name == prefs::kWebKitFixedFontFamily || | 168 } else if (*pref_name == prefs::kWebKitFixedFontFamily || |
| 156 *pref_name == prefs::kWebKitDefaultFixedFontSize) { | 169 *pref_name == prefs::kWebKitDefaultFixedFontSize) { |
| 157 SetupFixedFontSample(); | 170 SetupFixedFontSample(); |
| 171 } else if (*pref_name == prefs::kWebKitDefaultFontSize) { |
| 172 SetupStandardFontSample(); |
| 173 SetupSerifFontSample(); |
| 174 SetupSansSerifFontSample(); |
| 158 } else if (*pref_name == prefs::kWebKitMinimumFontSize) { | 175 } else if (*pref_name == prefs::kWebKitMinimumFontSize) { |
| 159 SetupMinimumFontSample(); | 176 SetupMinimumFontSample(); |
| 160 } | 177 } |
| 161 } | 178 } |
| 162 } | 179 } |
| 163 | 180 |
| 164 void FontSettingsHandler::SetupStandardFontSample() { | 181 void FontSettingsHandler::SetupStandardFontSample() { |
| 165 StringValue font_value(standard_font_.GetValue()); | 182 StringValue font_value(standard_font_.GetValue()); |
| 166 FundamentalValue size_value(default_font_size_.GetValue()); | 183 FundamentalValue size_value(default_font_size_.GetValue()); |
| 167 web_ui_->CallJavascriptFunction( | 184 web_ui_->CallJavascriptFunction( |
| 168 "FontSettings.setupStandardFontSample", font_value, size_value); | 185 "FontSettings.setupStandardFontSample", font_value, size_value); |
| 169 } | 186 } |
| 170 | 187 |
| 188 void FontSettingsHandler::SetupSerifFontSample() { |
| 189 StringValue font_value(serif_font_.GetValue()); |
| 190 FundamentalValue size_value(default_font_size_.GetValue()); |
| 191 web_ui_->CallJavascriptFunction( |
| 192 "FontSettings.setupSerifFontSample", font_value, size_value); |
| 193 } |
| 194 |
| 195 void FontSettingsHandler::SetupSansSerifFontSample() { |
| 196 StringValue font_value(sans_serif_font_.GetValue()); |
| 197 FundamentalValue size_value(default_font_size_.GetValue()); |
| 198 web_ui_->CallJavascriptFunction( |
| 199 "FontSettings.setupSansSerifFontSample", font_value, size_value); |
| 200 } |
| 201 |
| 171 void FontSettingsHandler::SetupFixedFontSample() { | 202 void FontSettingsHandler::SetupFixedFontSample() { |
| 172 StringValue font_value(fixed_font_.GetValue()); | 203 StringValue font_value(fixed_font_.GetValue()); |
| 173 FundamentalValue size_value(default_fixed_font_size_.GetValue()); | 204 FundamentalValue size_value(default_fixed_font_size_.GetValue()); |
| 174 web_ui_->CallJavascriptFunction( | 205 web_ui_->CallJavascriptFunction( |
| 175 "FontSettings.setupFixedFontSample", font_value, size_value); | 206 "FontSettings.setupFixedFontSample", font_value, size_value); |
| 176 } | 207 } |
| 177 | 208 |
| 178 void FontSettingsHandler::SetupMinimumFontSample() { | 209 void FontSettingsHandler::SetupMinimumFontSample() { |
| 179 FundamentalValue size_value(minimum_font_size_.GetValue()); | 210 FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 180 web_ui_->CallJavascriptFunction("FontSettings.setupMinimumFontSample", | 211 web_ui_->CallJavascriptFunction("FontSettings.setupMinimumFontSample", |
| 181 size_value); | 212 size_value); |
| 182 } | 213 } |
| OLD | NEW |