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

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

Issue 2254273003: Remove text encoding UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 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 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/character_encoding.h"
23 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_tab_util.h" 23 #include "chrome/browser/extensions/extension_tab_util.h"
25 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 26 #include "chrome/browser/ui/webui/options/font_settings_utils.h"
28 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
29 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
30 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
31 #include "content/public/browser/font_list_async.h" 30 #include "content/public/browser/font_list_async.h"
32 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 { "fontSettingsStandard", 82 { "fontSettingsStandard",
84 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL }, 83 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_STANDARD_LABEL },
85 { "fontSettingsSerif", 84 { "fontSettingsSerif",
86 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL }, 85 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL },
87 { "fontSettingsSansSerif", 86 { "fontSettingsSansSerif",
88 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL }, 87 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL },
89 { "fontSettingsFixedWidth", 88 { "fontSettingsFixedWidth",
90 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL }, 89 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL },
91 { "fontSettingsMinimumSize", 90 { "fontSettingsMinimumSize",
92 IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE }, 91 IDS_FONT_LANGUAGE_SETTING_MINIMUM_FONT_SIZE_TITLE },
93 { "fontSettingsEncoding", 92 { "fontSettings",
94 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE }, 93 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_TITLE },
95 { "fontSettingsSizeTiny", 94 { "fontSettingsSizeTiny",
96 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_TINY }, 95 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_TINY },
97 { "fontSettingsSizeHuge", 96 { "fontSettingsSizeHuge",
98 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_HUGE }, 97 IDS_FONT_LANGUAGE_SETTING_FONT_SIZE_HUGE },
99 { "fontSettingsLoremIpsum", 98 { "fontSettingsLoremIpsum",
100 IDS_FONT_LANGUAGE_SETTING_LOREM_IPSUM }, 99 IDS_FONT_LANGUAGE_SETTING_LOREM_IPSUM },
101 { "advancedFontSettingsOptions", 100 { "advancedFontSettingsOptions",
102 IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_OPTIONS } 101 IDS_FONT_LANGUAGE_SETTING_ADVANCED_FONT_SETTINGS_OPTIONS }
103 }; 102 };
104 103
(...skipping 26 matching lines...) Expand all
131 SetUpMinimumFontSample(); 130 SetUpMinimumFontSample();
132 NotifyAdvancedFontSettingsAvailability(); 131 NotifyAdvancedFontSettingsAvailability();
133 } 132 }
134 133
135 void FontSettingsHandler::RegisterMessages() { 134 void FontSettingsHandler::RegisterMessages() {
136 // Perform validation for saved fonts. 135 // Perform validation for saved fonts.
137 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 136 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
138 FontSettingsUtilities::ValidateSavedFonts(pref_service); 137 FontSettingsUtilities::ValidateSavedFonts(pref_service);
139 138
140 // Register for preferences that we need to observe manually. 139 // Register for preferences that we need to observe manually.
141 font_encoding_.Init(prefs::kDefaultCharset, pref_service);
142
143 standard_font_.Init(prefs::kWebKitStandardFontFamily, 140 standard_font_.Init(prefs::kWebKitStandardFontFamily,
144 pref_service, 141 pref_service,
145 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, 142 base::Bind(&FontSettingsHandler::SetUpStandardFontSample,
146 base::Unretained(this))); 143 base::Unretained(this)));
147 serif_font_.Init(prefs::kWebKitSerifFontFamily, 144 serif_font_.Init(prefs::kWebKitSerifFontFamily,
148 pref_service, 145 pref_service,
149 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, 146 base::Bind(&FontSettingsHandler::SetUpSerifFontSample,
150 base::Unretained(this))); 147 base::Unretained(this)));
151 sans_serif_font_.Init( 148 sans_serif_font_.Init(
152 prefs::kWebKitSansSerifFontFamily, 149 prefs::kWebKitSansSerifFontFamily,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 base::ListValue* font; 202 base::ListValue* font;
206 bool has_font = list->GetList(i, &font); 203 bool has_font = list->GetList(i, &font);
207 DCHECK(has_font); 204 DCHECK(has_font);
208 base::string16 value; 205 base::string16 value;
209 bool has_value = font->GetString(1, &value); 206 bool has_value = font->GetString(1, &value);
210 DCHECK(has_value); 207 DCHECK(has_value);
211 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); 208 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
212 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); 209 font->AppendString(has_rtl_chars ? "rtl" : "ltr");
213 } 210 }
214 211
215 base::ListValue encoding_list;
216 const std::vector<CharacterEncoding::EncodingInfo>* encodings;
217 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
218 encodings = CharacterEncoding::GetCurrentDisplayEncodings(
219 g_browser_process->GetApplicationLocale(),
220 pref_service->GetString(prefs::kStaticEncodings),
221 pref_service->GetString(prefs::kRecentlySelectedEncoding));
222 DCHECK(encodings);
223 DCHECK(!encodings->empty());
224
225 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it;
226 for (it = encodings->begin(); it != encodings->end(); ++it) {
227 std::unique_ptr<base::ListValue> option(new base::ListValue());
228 if (it->encoding_id) {
229 int cmd_id = it->encoding_id;
230 std::string encoding =
231 CharacterEncoding::GetCanonicalEncodingNameByCommandId(cmd_id);
232 base::string16 name = it->encoding_display_name;
233 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(name);
234 option->AppendString(encoding);
235 option->AppendString(name);
236 option->AppendString(has_rtl_chars ? "rtl" : "ltr");
237 } else {
238 // Add empty name/value to indicate a separator item.
239 option->AppendString(std::string());
240 option->AppendString(std::string());
241 }
242 encoding_list.Append(std::move(option));
243 }
244
245 base::ListValue selected_values; 212 base::ListValue selected_values;
246 selected_values.AppendString( 213 selected_values.AppendString(
247 MaybeGetLocalizedFontName(standard_font_.GetValue())); 214 MaybeGetLocalizedFontName(standard_font_.GetValue()));
248 selected_values.AppendString( 215 selected_values.AppendString(
249 MaybeGetLocalizedFontName(serif_font_.GetValue())); 216 MaybeGetLocalizedFontName(serif_font_.GetValue()));
250 selected_values.AppendString( 217 selected_values.AppendString(
251 MaybeGetLocalizedFontName(sans_serif_font_.GetValue())); 218 MaybeGetLocalizedFontName(sans_serif_font_.GetValue()));
252 selected_values.AppendString( 219 selected_values.AppendString(
253 MaybeGetLocalizedFontName(fixed_font_.GetValue())); 220 MaybeGetLocalizedFontName(fixed_font_.GetValue()));
254 selected_values.AppendString(font_encoding_.GetValue());
255 221
256 web_ui()->CallJavascriptFunctionUnsafe( 222 web_ui()->CallJavascriptFunctionUnsafe(
257 "FontSettings.setFontsData", *list.get(), encoding_list, selected_values); 223 "FontSettings.setFontsData", *list.get(), selected_values);
258 } 224 }
259 225
260 void FontSettingsHandler::SetUpStandardFontSample() { 226 void FontSettingsHandler::SetUpStandardFontSample() {
261 base::StringValue font_value(standard_font_.GetValue()); 227 base::StringValue font_value(standard_font_.GetValue());
262 base::FundamentalValue size_value(default_font_size_.GetValue()); 228 base::FundamentalValue size_value(default_font_size_.GetValue());
263 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", 229 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample",
264 font_value, size_value); 230 font_value, size_value);
265 } 231 }
266 232
267 void FontSettingsHandler::SetUpSerifFontSample() { 233 void FontSettingsHandler::SetUpSerifFontSample() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); 282 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()));
317 } 283 }
318 284
319 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { 285 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() {
320 SetUpStandardFontSample(); 286 SetUpStandardFontSample();
321 SetUpSerifFontSample(); 287 SetUpSerifFontSample();
322 SetUpSansSerifFontSample(); 288 SetUpSansSerifFontSample();
323 } 289 }
324 290
325 } // namespace options 291 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/font_settings_handler.h ('k') | chrome/browser/ui/webui/settings/font_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698