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

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

Issue 2030013003: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 std::unique_ptr<base::ListValue> list) { 201 std::unique_ptr<base::ListValue> list) {
202 // Selects the directionality for the fonts in the given list. 202 // Selects the directionality for the fonts in the given list.
203 for (size_t i = 0; i < list->GetSize(); i++) { 203 for (size_t i = 0; i < list->GetSize(); i++) {
204 base::ListValue* font; 204 base::ListValue* font;
205 bool has_font = list->GetList(i, &font); 205 bool has_font = list->GetList(i, &font);
206 DCHECK(has_font); 206 DCHECK(has_font);
207 base::string16 value; 207 base::string16 value;
208 bool has_value = font->GetString(1, &value); 208 bool has_value = font->GetString(1, &value);
209 DCHECK(has_value); 209 DCHECK(has_value);
210 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); 210 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
211 font->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); 211 font->AppendString(has_rtl_chars ? "rtl" : "ltr");
212 } 212 }
213 213
214 base::ListValue encoding_list; 214 base::ListValue encoding_list;
215 const std::vector<CharacterEncoding::EncodingInfo>* encodings; 215 const std::vector<CharacterEncoding::EncodingInfo>* encodings;
216 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 216 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
217 encodings = CharacterEncoding::GetCurrentDisplayEncodings( 217 encodings = CharacterEncoding::GetCurrentDisplayEncodings(
218 g_browser_process->GetApplicationLocale(), 218 g_browser_process->GetApplicationLocale(),
219 pref_service->GetString(prefs::kStaticEncodings), 219 pref_service->GetString(prefs::kStaticEncodings),
220 pref_service->GetString(prefs::kRecentlySelectedEncoding)); 220 pref_service->GetString(prefs::kRecentlySelectedEncoding));
221 DCHECK(encodings); 221 DCHECK(encodings);
222 DCHECK(!encodings->empty()); 222 DCHECK(!encodings->empty());
223 223
224 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; 224 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it;
225 for (it = encodings->begin(); it != encodings->end(); ++it) { 225 for (it = encodings->begin(); it != encodings->end(); ++it) {
226 base::ListValue* option = new base::ListValue(); 226 base::ListValue* option = new base::ListValue();
227 if (it->encoding_id) { 227 if (it->encoding_id) {
228 int cmd_id = it->encoding_id; 228 int cmd_id = it->encoding_id;
229 std::string encoding = 229 std::string encoding =
230 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id); 230 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id);
231 base::string16 name = it->encoding_display_name; 231 base::string16 name = it->encoding_display_name;
232 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name); 232 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name);
233 option->Append(new base::StringValue(encoding)); 233 option->AppendString(encoding);
234 option->Append(new base::StringValue(name)); 234 option->AppendString(name);
235 option->Append(new base::StringValue(has_rtl_chars ? "rtl" : "ltr")); 235 option->AppendString(has_rtl_chars ? "rtl" : "ltr");
236 } else { 236 } else {
237 // Add empty name/value to indicate a separator item. 237 // Add empty name/value to indicate a separator item.
238 option->Append(new base::StringValue(std::string())); 238 option->AppendString(std::string());
239 option->Append(new base::StringValue(std::string())); 239 option->AppendString(std::string());
240 } 240 }
241 encoding_list.Append(option); 241 encoding_list.Append(option);
242 } 242 }
243 243
244 base::ListValue selected_values; 244 base::ListValue selected_values;
245 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( 245 selected_values.AppendString(
246 standard_font_.GetValue()))); 246 MaybeGetLocalizedFontName(standard_font_.GetValue()));
247 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( 247 selected_values.AppendString(
248 serif_font_.GetValue()))); 248 MaybeGetLocalizedFontName(serif_font_.GetValue()));
249 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( 249 selected_values.AppendString(
250 sans_serif_font_.GetValue()))); 250 MaybeGetLocalizedFontName(sans_serif_font_.GetValue()));
251 selected_values.Append(new base::StringValue(MaybeGetLocalizedFontName( 251 selected_values.AppendString(
252 fixed_font_.GetValue()))); 252 MaybeGetLocalizedFontName(fixed_font_.GetValue()));
253 selected_values.Append(new base::StringValue(font_encoding_.GetValue())); 253 selected_values.AppendString(font_encoding_.GetValue());
254 254
255 web_ui()->CallJavascriptFunction("FontSettings.setFontsData", 255 web_ui()->CallJavascriptFunction("FontSettings.setFontsData",
256 *list.get(), encoding_list, 256 *list.get(), encoding_list,
257 selected_values); 257 selected_values);
258 } 258 }
259 259
260 void FontSettingsHandler::SetUpStandardFontSample() { 260 void FontSettingsHandler::SetUpStandardFontSample() {
261 base::StringValue font_value(standard_font_.GetValue()); 261 base::StringValue font_value(standard_font_.GetValue());
262 base::FundamentalValue size_value(default_font_size_.GetValue()); 262 base::FundamentalValue size_value(default_font_size_.GetValue());
263 web_ui()->CallJavascriptFunction( 263 web_ui()->CallJavascriptFunction(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); 316 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()));
317 } 317 }
318 318
319 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { 319 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() {
320 SetUpStandardFontSample(); 320 SetUpStandardFontSample();
321 SetUpSerifFontSample(); 321 SetUpSerifFontSample();
322 SetUpSansSerifFontSample(); 322 SetUpSansSerifFontSample();
323 } 323 }
324 324
325 } // namespace options 325 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/core_options_handler.cc ('k') | chrome/browser/ui/webui/options/handler_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698