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

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

Issue 2927273002: Move code for old, deprecated Options UI to only ChromeOS (Closed)
Patch Set: font utils Created 3 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 #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/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_tab_util.h" 23 #include "chrome/browser/extensions/extension_tab_util.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 26 #include "chrome/browser/ui/webui/settings_utils.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
29 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
30 #include "content/public/browser/font_list_async.h" 30 #include "content/public/browser/font_list_async.h"
31 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
34 #include "extensions/browser/extension_registry.h" 34 #include "extensions/browser/extension_registry.h"
35 #include "extensions/browser/extension_system.h" 35 #include "extensions/browser/extension_system.h"
36 #include "extensions/common/extension.h" 36 #include "extensions/common/extension.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 SetUpSerifFontSample(); 109 SetUpSerifFontSample();
110 SetUpSansSerifFontSample(); 110 SetUpSansSerifFontSample();
111 SetUpFixedFontSample(); 111 SetUpFixedFontSample();
112 SetUpMinimumFontSample(); 112 SetUpMinimumFontSample();
113 NotifyAdvancedFontSettingsAvailability(); 113 NotifyAdvancedFontSettingsAvailability();
114 } 114 }
115 115
116 void FontSettingsHandler::RegisterMessages() { 116 void FontSettingsHandler::RegisterMessages() {
117 // Perform validation for saved fonts. 117 // Perform validation for saved fonts.
118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 118 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
119 FontSettingsUtilities::ValidateSavedFonts(pref_service); 119 settings_utils::ValidateSavedFonts(pref_service);
120 120
121 // Register for preferences that we need to observe manually. 121 // Register for preferences that we need to observe manually.
122 standard_font_.Init(prefs::kWebKitStandardFontFamily, 122 standard_font_.Init(prefs::kWebKitStandardFontFamily,
123 pref_service, 123 pref_service,
124 base::Bind(&FontSettingsHandler::SetUpStandardFontSample, 124 base::Bind(&FontSettingsHandler::SetUpStandardFontSample,
125 base::Unretained(this))); 125 base::Unretained(this)));
126 serif_font_.Init(prefs::kWebKitSerifFontFamily, 126 serif_font_.Init(prefs::kWebKitSerifFontFamily,
127 pref_service, 127 pref_service,
128 base::Bind(&FontSettingsHandler::SetUpSerifFontSample, 128 base::Bind(&FontSettingsHandler::SetUpSerifFontSample,
129 base::Unretained(this))); 129 base::Unretained(this)));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool has_font = list->GetList(i, &font); 185 bool has_font = list->GetList(i, &font);
186 DCHECK(has_font); 186 DCHECK(has_font);
187 base::string16 value; 187 base::string16 value;
188 bool has_value = font->GetString(1, &value); 188 bool has_value = font->GetString(1, &value);
189 DCHECK(has_value); 189 DCHECK(has_value);
190 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); 190 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value);
191 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); 191 font->AppendString(has_rtl_chars ? "rtl" : "ltr");
192 } 192 }
193 193
194 base::ListValue selected_values; 194 base::ListValue selected_values;
195 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName(
196 standard_font_.GetValue()));
197 selected_values.AppendString( 195 selected_values.AppendString(
198 FontSettingsUtilities::MaybeGetLocalizedFontName(serif_font_.GetValue())); 196 settings_utils::MaybeGetLocalizedFontName(standard_font_.GetValue()));
199 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName(
200 sans_serif_font_.GetValue()));
201 selected_values.AppendString( 197 selected_values.AppendString(
202 FontSettingsUtilities::MaybeGetLocalizedFontName(fixed_font_.GetValue())); 198 settings_utils::MaybeGetLocalizedFontName(serif_font_.GetValue()));
199 selected_values.AppendString(
200 settings_utils::MaybeGetLocalizedFontName(sans_serif_font_.GetValue()));
201 selected_values.AppendString(
202 settings_utils::MaybeGetLocalizedFontName(fixed_font_.GetValue()));
203 203
204 web_ui()->CallJavascriptFunctionUnsafe( 204 web_ui()->CallJavascriptFunctionUnsafe(
205 "FontSettings.setFontsData", *list.get(), selected_values); 205 "FontSettings.setFontsData", *list.get(), selected_values);
206 } 206 }
207 207
208 void FontSettingsHandler::SetUpStandardFontSample() { 208 void FontSettingsHandler::SetUpStandardFontSample() {
209 base::Value font_value( 209 base::Value font_value(
210 FontSettingsUtilities::ResolveFontList(standard_font_.GetValue())); 210 settings_utils::ResolveFontList(standard_font_.GetValue()));
211 base::Value size_value(default_font_size_.GetValue()); 211 base::Value size_value(default_font_size_.GetValue());
212 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", 212 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample",
213 font_value, size_value); 213 font_value, size_value);
214 } 214 }
215 215
216 void FontSettingsHandler::SetUpSerifFontSample() { 216 void FontSettingsHandler::SetUpSerifFontSample() {
217 base::Value font_value( 217 base::Value font_value(
218 FontSettingsUtilities::ResolveFontList(serif_font_.GetValue())); 218 settings_utils::ResolveFontList(serif_font_.GetValue()));
219 base::Value size_value(default_font_size_.GetValue()); 219 base::Value size_value(default_font_size_.GetValue());
220 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", 220 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample",
221 font_value, size_value); 221 font_value, size_value);
222 } 222 }
223 223
224 void FontSettingsHandler::SetUpSansSerifFontSample() { 224 void FontSettingsHandler::SetUpSansSerifFontSample() {
225 base::Value font_value( 225 base::Value font_value(
226 FontSettingsUtilities::ResolveFontList(sans_serif_font_.GetValue())); 226 settings_utils::ResolveFontList(sans_serif_font_.GetValue()));
227 base::Value size_value(default_font_size_.GetValue()); 227 base::Value size_value(default_font_size_.GetValue());
228 web_ui()->CallJavascriptFunctionUnsafe( 228 web_ui()->CallJavascriptFunctionUnsafe(
229 "FontSettings.setUpSansSerifFontSample", font_value, size_value); 229 "FontSettings.setUpSansSerifFontSample", font_value, size_value);
230 } 230 }
231 231
232 void FontSettingsHandler::SetUpFixedFontSample() { 232 void FontSettingsHandler::SetUpFixedFontSample() {
233 base::Value font_value( 233 base::Value font_value(
234 FontSettingsUtilities::ResolveFontList(fixed_font_.GetValue())); 234 settings_utils::ResolveFontList(fixed_font_.GetValue()));
235 base::Value size_value(default_fixed_font_size_.GetValue()); 235 base::Value size_value(default_fixed_font_size_.GetValue());
236 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", 236 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample",
237 font_value, size_value); 237 font_value, size_value);
238 } 238 }
239 239
240 void FontSettingsHandler::SetUpMinimumFontSample() { 240 void FontSettingsHandler::SetUpMinimumFontSample() {
241 base::Value size_value(minimum_font_size_.GetValue()); 241 base::Value size_value(minimum_font_size_.GetValue());
242 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", 242 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample",
243 size_value); 243 size_value);
244 } 244 }
(...skipping 23 matching lines...) Expand all
268 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); 268 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()));
269 } 269 }
270 270
271 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { 271 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() {
272 SetUpStandardFontSample(); 272 SetUpStandardFontSample();
273 SetUpSerifFontSample(); 273 SetUpSerifFontSample();
274 SetUpSansSerifFontSample(); 274 SetUpSansSerifFontSample();
275 } 275 }
276 276
277 } // namespace options 277 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698