| 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/prefs/prefs_tab_helper.h" | 5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/prefs/overlay_user_pref_store.h" | 9 #include "base/prefs/overlay_user_pref_store.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/renderer_preferences_util.h" | 17 #include "chrome/browser/renderer_preferences_util.h" |
| 18 #include "chrome/common/pref_font_webkit_names.h" | 18 #include "chrome/common/pref_font_webkit_names.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/pref_names_util.h" | 20 #include "chrome/common/pref_names_util.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "grit/locale_settings.h" | 26 #include "grit/locale_settings.h" |
| 27 #include "grit/platform_locale_settings.h" | 27 #include "grit/platform_locale_settings.h" |
| 28 #include "third_party/icu/source/common/unicode/uchar.h" | 28 #include "third_party/icu/source/common/unicode/uchar.h" |
| 29 #include "third_party/icu/source/common/unicode/uscript.h" | 29 #include "third_party/icu/source/common/unicode/uscript.h" |
| 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "webkit/common/webpreferences.h" | 31 #include "webkit/common/webpreferences.h" |
| 31 | 32 |
| 32 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES) | 33 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES) |
| 33 #include "chrome/browser/themes/theme_service.h" | 34 #include "chrome/browser/themes/theme_service.h" |
| 34 #include "chrome/browser/themes/theme_service_factory.h" | 35 #include "chrome/browser/themes/theme_service_factory.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 38 #include "base/win/windows_version.h" | 39 #include "base/win/windows_version.h" |
| 39 #endif | 40 #endif |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true)); | 123 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true)); |
| 123 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { | 124 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 124 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; | 125 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 125 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); | 126 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 126 registrar->Add(pref_name.c_str(), obs); | 127 registrar->Add(pref_name.c_str(), obs); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 #endif // !defined(OS_ANDROID) | 130 #endif // !defined(OS_ANDROID) |
| 130 | 131 |
| 131 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 132 // On Windows with DirectWrite we want to use an alternate fixed font like | 133 // On Windows with antialising we want to use an alternate fixed font like |
| 133 // Consolas, which looks much better than Courier New. | 134 // Consolas, which looks much better than Courier New. |
| 134 bool ShouldUseAlternateDefaultFixedFont() { | 135 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) { |
| 136 if (!StartsWithASCII(script, "courier", false)) |
| 137 return false; |
| 135 UINT smooth_type = 0; | 138 UINT smooth_type = 0; |
| 136 SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smooth_type, 0); | 139 SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smooth_type, 0); |
| 137 return (base::win::GetVersion() >= base::win::VERSION_WIN7) && | 140 return (base::win::GetVersion() >= base::win::VERSION_WIN7) && |
| 138 (smooth_type == FE_FONTSMOOTHINGCLEARTYPE); | 141 (smooth_type == FE_FONTSMOOTHINGCLEARTYPE); |
| 139 } | 142 } |
| 140 #endif | 143 #endif |
| 141 | 144 |
| 142 struct FontDefault { | 145 struct FontDefault { |
| 143 const char* pref_name; | 146 const char* pref_name; |
| 144 int resource_id; | 147 int resource_id; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 469 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 467 | 470 |
| 468 // Register font prefs that have defaults. | 471 // Register font prefs that have defaults. |
| 469 std::set<std::string> fonts_with_defaults; | 472 std::set<std::string> fonts_with_defaults; |
| 470 UScriptCode browser_script = GetScriptOfBrowserLocale(); | 473 UScriptCode browser_script = GetScriptOfBrowserLocale(); |
| 471 for (size_t i = 0; i < kFontDefaultsLength; ++i) { | 474 for (size_t i = 0; i < kFontDefaultsLength; ++i) { |
| 472 FontDefault pref = kFontDefaults[i]; | 475 FontDefault pref = kFontDefaults[i]; |
| 473 | 476 |
| 474 #if defined(OS_WIN) | 477 #if defined(OS_WIN) |
| 475 if (pref.pref_name == prefs::kWebKitFixedFontFamily) { | 478 if (pref.pref_name == prefs::kWebKitFixedFontFamily) { |
| 476 if (ShouldUseAlternateDefaultFixedFont()) | 479 if (ShouldUseAlternateDefaultFixedFont( |
| 480 l10n_util::GetStringUTF8(pref.resource_id))) |
| 477 pref.resource_id = IDS_FIXED_FONT_FAMILY_ALT_WIN; | 481 pref.resource_id = IDS_FIXED_FONT_FAMILY_ALT_WIN; |
| 478 } | 482 } |
| 479 #endif | 483 #endif |
| 480 | 484 |
| 481 UScriptCode pref_script = GetScriptOfFontPref(pref.pref_name); | 485 UScriptCode pref_script = GetScriptOfFontPref(pref.pref_name); |
| 482 | 486 |
| 483 // Suppress this default font pref value if it is for the primary script of | 487 // Suppress this default font pref value if it is for the primary script of |
| 484 // the browser's UI locale. For example, if the pref is for the sans-serif | 488 // the browser's UI locale. For example, if the pref is for the sans-serif |
| 485 // font for the Cyrillic script, and the browser locale is "ru" (Russian), | 489 // font for the Cyrillic script, and the browser locale is "ru" (Russian), |
| 486 // the default is suppressed. Otherwise, the default would override the | 490 // the default is suppressed. Otherwise, the default would override the |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 WebPreferences web_prefs = | 599 WebPreferences web_prefs = |
| 596 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); | 600 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); |
| 597 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); | 601 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); |
| 598 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); | 602 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); |
| 599 return; | 603 return; |
| 600 } | 604 } |
| 601 } | 605 } |
| 602 | 606 |
| 603 UpdateWebPreferences(); | 607 UpdateWebPreferences(); |
| 604 } | 608 } |
| OLD | NEW |