| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 scoped_ptr<base::ListValue> list) { | 154 scoped_ptr<base::ListValue> list) { |
| 155 // Selects the directionality for the fonts in the given list. | 155 // Selects the directionality for the fonts in the given list. |
| 156 for (size_t i = 0; i < list->GetSize(); i++) { | 156 for (size_t i = 0; i < list->GetSize(); i++) { |
| 157 ListValue* font; | 157 ListValue* font; |
| 158 bool has_font = list->GetList(i, &font); | 158 bool has_font = list->GetList(i, &font); |
| 159 DCHECK(has_font); | 159 DCHECK(has_font); |
| 160 string16 value; | 160 string16 value; |
| 161 bool has_value = font->GetString(1, &value); | 161 bool has_value = font->GetString(1, &value); |
| 162 DCHECK(has_value); | 162 DCHECK(has_value); |
| 163 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); | 163 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); |
| 164 font->Append(Value::CreateStringValue(has_rtl_chars ? "rtl" : "ltr")); | 164 font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); |
| 165 } | 165 } |
| 166 | 166 |
| 167 ListValue encoding_list; | 167 ListValue encoding_list; |
| 168 const std::vector<CharacterEncoding::EncodingInfo>* encodings; | 168 const std::vector<CharacterEncoding::EncodingInfo>* encodings; |
| 169 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 169 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 170 encodings = CharacterEncoding::GetCurrentDisplayEncodings( | 170 encodings = CharacterEncoding::GetCurrentDisplayEncodings( |
| 171 g_browser_process->GetApplicationLocale(), | 171 g_browser_process->GetApplicationLocale(), |
| 172 pref_service->GetString(prefs::kStaticEncodings), | 172 pref_service->GetString(prefs::kStaticEncodings), |
| 173 pref_service->GetString(prefs::kRecentlySelectedEncoding)); | 173 pref_service->GetString(prefs::kRecentlySelectedEncoding)); |
| 174 DCHECK(encodings); | 174 DCHECK(encodings); |
| 175 DCHECK(!encodings->empty()); | 175 DCHECK(!encodings->empty()); |
| 176 | 176 |
| 177 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; | 177 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; |
| 178 for (it = encodings->begin(); it != encodings->end(); ++it) { | 178 for (it = encodings->begin(); it != encodings->end(); ++it) { |
| 179 ListValue* option = new ListValue(); | 179 ListValue* option = new ListValue(); |
| 180 if (it->encoding_id) { | 180 if (it->encoding_id) { |
| 181 int cmd_id = it->encoding_id; | 181 int cmd_id = it->encoding_id; |
| 182 std::string encoding = | 182 std::string encoding = |
| 183 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id); | 183 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id); |
| 184 string16 name = it->encoding_display_name; | 184 string16 name = it->encoding_display_name; |
| 185 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name); | 185 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name); |
| 186 option->Append(Value::CreateStringValue(encoding)); | 186 option->Append(new base::StringValue(encoding)); |
| 187 option->Append(Value::CreateStringValue(name)); | 187 option->Append(new base::StringValue(name)); |
| 188 option->Append(Value::CreateStringValue(has_rtl_chars ? "rtl" : "ltr")); | 188 option->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); |
| 189 } else { | 189 } else { |
| 190 // Add empty name/value to indicate a separator item. | 190 // Add empty name/value to indicate a separator item. |
| 191 option->Append(Value::CreateStringValue("")); | 191 option->Append(new base::StringValue("")); |
| 192 option->Append(Value::CreateStringValue("")); | 192 option->Append(new base::StringValue("")); |
| 193 } | 193 } |
| 194 encoding_list.Append(option); | 194 encoding_list.Append(option); |
| 195 } | 195 } |
| 196 | 196 |
| 197 ListValue selected_values; | 197 ListValue selected_values; |
| 198 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 198 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 199 standard_font_.GetValue()))); | 199 standard_font_.GetValue()))); |
| 200 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 200 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 201 serif_font_.GetValue()))); | 201 serif_font_.GetValue()))); |
| 202 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 202 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 203 sans_serif_font_.GetValue()))); | 203 sans_serif_font_.GetValue()))); |
| 204 selected_values.Append(Value::CreateStringValue(MaybeGetLocalizedFontName( | 204 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( |
| 205 fixed_font_.GetValue()))); | 205 fixed_font_.GetValue()))); |
| 206 selected_values.Append(Value::CreateStringValue(font_encoding_.GetValue())); | 206 selected_values.Append(new base::StringValue(font_encoding_.GetValue())); |
| 207 | 207 |
| 208 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", | 208 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", |
| 209 *list.get(), encoding_list, | 209 *list.get(), encoding_list, |
| 210 selected_values); | 210 selected_values); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void FontSettingsHandler::SetUpStandardFontSample() { | 213 void FontSettingsHandler::SetUpStandardFontSample() { |
| 214 base::StringValue font_value(standard_font_.GetValue()); | 214 base::StringValue font_value(standard_font_.GetValue()); |
| 215 base::FundamentalValue size_value(default_font_size_.GetValue()); | 215 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 216 web_ui()->CallJavascriptFunction( | 216 web_ui()->CallJavascriptFunction( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 244 size_value); | 244 size_value); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { | 247 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
| 248 SetUpStandardFontSample(); | 248 SetUpStandardFontSample(); |
| 249 SetUpSerifFontSample(); | 249 SetUpSerifFontSample(); |
| 250 SetUpSansSerifFontSample(); | 250 SetUpSansSerifFontSample(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace options | 253 } // namespace options |
| OLD | NEW |