| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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" |
| 37 #include "extensions/common/extension_urls.h" | 37 #include "extensions/common/extension_urls.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 #if defined(OS_WIN) | |
| 42 #include "ui/gfx/font.h" | |
| 43 #include "ui/gfx/platform_font_win.h" | |
| 44 #endif | |
| 45 | |
| 46 namespace { | 41 namespace { |
| 47 | 42 |
| 48 // Returns the localized name of a font so that settings can find it within the | |
| 49 // list of system fonts. On Windows, the list of system fonts has names only | |
| 50 // for the system locale, but the pref value may be in the English name. | |
| 51 std::string MaybeGetLocalizedFontName(const std::string& font_name) { | |
| 52 #if defined(OS_WIN) | |
| 53 gfx::Font font(font_name, 12); // dummy font size | |
| 54 return static_cast<gfx::PlatformFontWin*>(font.platform_font())-> | |
| 55 GetLocalizedFontName(); | |
| 56 #else | |
| 57 return font_name; | |
| 58 #endif | |
| 59 } | |
| 60 | |
| 61 const char kAdvancedFontSettingsExtensionId[] = | 43 const char kAdvancedFontSettingsExtensionId[] = |
| 62 "caclkomlalccbpcdllchkeecicepbmbm"; | 44 "caclkomlalccbpcdllchkeecicepbmbm"; |
| 63 | 45 |
| 64 } // namespace | 46 } // namespace |
| 65 | 47 |
| 66 | 48 |
| 67 namespace options { | 49 namespace options { |
| 68 | 50 |
| 69 FontSettingsHandler::FontSettingsHandler() | 51 FontSettingsHandler::FontSettingsHandler() |
| 70 : extension_registry_observer_(this), | 52 : extension_registry_observer_(this), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 bool has_font = list->GetList(i, &font); | 185 bool has_font = list->GetList(i, &font); |
| 204 DCHECK(has_font); | 186 DCHECK(has_font); |
| 205 base::string16 value; | 187 base::string16 value; |
| 206 bool has_value = font->GetString(1, &value); | 188 bool has_value = font->GetString(1, &value); |
| 207 DCHECK(has_value); | 189 DCHECK(has_value); |
| 208 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); | 190 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(value); |
| 209 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); | 191 font->AppendString(has_rtl_chars ? "rtl" : "ltr"); |
| 210 } | 192 } |
| 211 | 193 |
| 212 base::ListValue selected_values; | 194 base::ListValue selected_values; |
| 195 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName( |
| 196 standard_font_.GetValue())); |
| 213 selected_values.AppendString( | 197 selected_values.AppendString( |
| 214 MaybeGetLocalizedFontName(standard_font_.GetValue())); | 198 FontSettingsUtilities::MaybeGetLocalizedFontName(serif_font_.GetValue())); |
| 199 selected_values.AppendString(FontSettingsUtilities::MaybeGetLocalizedFontName( |
| 200 sans_serif_font_.GetValue())); |
| 215 selected_values.AppendString( | 201 selected_values.AppendString( |
| 216 MaybeGetLocalizedFontName(serif_font_.GetValue())); | 202 FontSettingsUtilities::MaybeGetLocalizedFontName(fixed_font_.GetValue())); |
| 217 selected_values.AppendString( | |
| 218 MaybeGetLocalizedFontName(sans_serif_font_.GetValue())); | |
| 219 selected_values.AppendString( | |
| 220 MaybeGetLocalizedFontName(fixed_font_.GetValue())); | |
| 221 | 203 |
| 222 web_ui()->CallJavascriptFunctionUnsafe( | 204 web_ui()->CallJavascriptFunctionUnsafe( |
| 223 "FontSettings.setFontsData", *list.get(), selected_values); | 205 "FontSettings.setFontsData", *list.get(), selected_values); |
| 224 } | 206 } |
| 225 | 207 |
| 226 void FontSettingsHandler::SetUpStandardFontSample() { | 208 void FontSettingsHandler::SetUpStandardFontSample() { |
| 227 base::StringValue font_value(standard_font_.GetValue()); | 209 base::StringValue font_value( |
| 210 FontSettingsUtilities::ResolveFontList(standard_font_.GetValue())); |
| 228 base::FundamentalValue size_value(default_font_size_.GetValue()); | 211 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 229 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", | 212 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpStandardFontSample", |
| 230 font_value, size_value); | 213 font_value, size_value); |
| 231 } | 214 } |
| 232 | 215 |
| 233 void FontSettingsHandler::SetUpSerifFontSample() { | 216 void FontSettingsHandler::SetUpSerifFontSample() { |
| 234 base::StringValue font_value(serif_font_.GetValue()); | 217 base::StringValue font_value( |
| 218 FontSettingsUtilities::ResolveFontList(serif_font_.GetValue())); |
| 235 base::FundamentalValue size_value(default_font_size_.GetValue()); | 219 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 236 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", | 220 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpSerifFontSample", |
| 237 font_value, size_value); | 221 font_value, size_value); |
| 238 } | 222 } |
| 239 | 223 |
| 240 void FontSettingsHandler::SetUpSansSerifFontSample() { | 224 void FontSettingsHandler::SetUpSansSerifFontSample() { |
| 241 base::StringValue font_value(sans_serif_font_.GetValue()); | 225 base::StringValue font_value( |
| 226 FontSettingsUtilities::ResolveFontList(sans_serif_font_.GetValue())); |
| 242 base::FundamentalValue size_value(default_font_size_.GetValue()); | 227 base::FundamentalValue size_value(default_font_size_.GetValue()); |
| 243 web_ui()->CallJavascriptFunctionUnsafe( | 228 web_ui()->CallJavascriptFunctionUnsafe( |
| 244 "FontSettings.setUpSansSerifFontSample", font_value, size_value); | 229 "FontSettings.setUpSansSerifFontSample", font_value, size_value); |
| 245 } | 230 } |
| 246 | 231 |
| 247 void FontSettingsHandler::SetUpFixedFontSample() { | 232 void FontSettingsHandler::SetUpFixedFontSample() { |
| 248 base::StringValue font_value(fixed_font_.GetValue()); | 233 base::StringValue font_value( |
| 234 FontSettingsUtilities::ResolveFontList(fixed_font_.GetValue())); |
| 249 base::FundamentalValue size_value(default_fixed_font_size_.GetValue()); | 235 base::FundamentalValue size_value(default_fixed_font_size_.GetValue()); |
| 250 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", | 236 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpFixedFontSample", |
| 251 font_value, size_value); | 237 font_value, size_value); |
| 252 } | 238 } |
| 253 | 239 |
| 254 void FontSettingsHandler::SetUpMinimumFontSample() { | 240 void FontSettingsHandler::SetUpMinimumFontSample() { |
| 255 base::FundamentalValue size_value(minimum_font_size_.GetValue()); | 241 base::FundamentalValue size_value(minimum_font_size_.GetValue()); |
| 256 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", | 242 web_ui()->CallJavascriptFunctionUnsafe("FontSettings.setUpMinimumFontSample", |
| 257 size_value); | 243 size_value); |
| 258 } | 244 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 282 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); | 268 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents())); |
| 283 } | 269 } |
| 284 | 270 |
| 285 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { | 271 void FontSettingsHandler::OnWebKitDefaultFontSizeChanged() { |
| 286 SetUpStandardFontSample(); | 272 SetUpStandardFontSample(); |
| 287 SetUpSerifFontSample(); | 273 SetUpSerifFontSample(); |
| 288 SetUpSansSerifFontSample(); | 274 SetUpSansSerifFontSample(); |
| 289 } | 275 } |
| 290 | 276 |
| 291 } // namespace options | 277 } // namespace options |
| OLD | NEW |