[email protected] | 37cc804 | 2012-02-27 19:32:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/renderer_preferences_util.h" |
| 6 | |
[email protected] | 516b2c73 | 2014-07-25 00:10:31 | [diff] [blame^] | 7 | #include "base/macros.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 8 | #include "base/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 10 | #include "chrome/common/pref_names.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 11 | #include "content/public/common/renderer_preferences.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 12 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 13 | |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 14 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | cd9c65e | 2014-07-10 02:57:01 | [diff] [blame] | 15 | #include "ui/gfx/font_render_params.h" |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 16 | #endif |
| 17 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 18 | #if defined(TOOLKIT_VIEWS) |
| 19 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 20 | #endif |
| 21 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 22 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 23 | #include "chrome/browser/themes/theme_service.h" |
| 24 | #include "chrome/browser/themes/theme_service_factory.h" |
| 25 | #include "ui/views/linux_ui/linux_ui.h" |
| 26 | #endif |
| 27 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 28 | namespace renderer_preferences_util { |
| 29 | |
[email protected] | bd2c470 | 2014-07-24 16:03:44 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 33 | content::RendererPreferencesHintingEnum GetRendererPreferencesHintingEnum( |
| 34 | gfx::FontRenderParams::Hinting hinting) { |
| 35 | switch (hinting) { |
| 36 | case gfx::FontRenderParams::HINTING_NONE: |
| 37 | return content::RENDERER_PREFERENCES_HINTING_NONE; |
| 38 | case gfx::FontRenderParams::HINTING_SLIGHT: |
| 39 | return content::RENDERER_PREFERENCES_HINTING_SLIGHT; |
| 40 | case gfx::FontRenderParams::HINTING_MEDIUM: |
| 41 | return content::RENDERER_PREFERENCES_HINTING_MEDIUM; |
| 42 | case gfx::FontRenderParams::HINTING_FULL: |
| 43 | return content::RENDERER_PREFERENCES_HINTING_FULL; |
| 44 | default: |
| 45 | NOTREACHED() << "Unhandled hinting style " << hinting; |
| 46 | return content::RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | content::RendererPreferencesSubpixelRenderingEnum |
| 51 | GetRendererPreferencesSubpixelRenderingEnum( |
| 52 | gfx::FontRenderParams::SubpixelRendering subpixel_rendering) { |
| 53 | switch (subpixel_rendering) { |
| 54 | case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE: |
| 55 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE; |
| 56 | case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB: |
| 57 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB; |
| 58 | case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR: |
| 59 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR; |
| 60 | case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB: |
| 61 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB; |
| 62 | case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR: |
| 63 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR; |
| 64 | default: |
| 65 | NOTREACHED() << "Unhandled subpixel rendering style " |
| 66 | << subpixel_rendering; |
| 67 | return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT; |
| 68 | } |
| 69 | } |
| 70 | #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 71 | |
| 72 | } // namespace |
| 73 | |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 74 | void UpdateFromSystemSettings( |
| 75 | content::RendererPreferences* prefs, Profile* profile) { |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 76 | const PrefService* pref_service = profile->GetPrefs(); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame] | 77 | prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 78 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 79 | prefs->enable_do_not_track = |
| 80 | pref_service->GetBoolean(prefs::kEnableDoNotTrack); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 81 | prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); |
| 82 | |
[email protected] | 993f4bb | 2014-06-17 22:15:48 | [diff] [blame] | 83 | #if defined(USE_DEFAULT_RENDER_THEME) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 84 | prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); |
| 85 | |
[email protected] | d41e4050 | 2014-04-12 00:56:22 | [diff] [blame] | 86 | #if defined(OS_CHROMEOS) |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 87 | // This color is 0x544d90fe modulated with 0xffffff. |
| 88 | prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); |
| 89 | prefs->active_selection_fg_color = SK_ColorBLACK; |
| 90 | prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); |
| 91 | prefs->inactive_selection_fg_color = SK_ColorBLACK; |
[email protected] | f2cb988d2 | 2013-07-01 22:07:04 | [diff] [blame] | 92 | #endif |
[email protected] | 81a1055 | 2013-02-07 22:35:56 | [diff] [blame] | 93 | |
| 94 | prefs->touchpad_fling_profile[0] = |
| 95 | pref_service->GetDouble(prefs::kFlingCurveTouchpadAlpha); |
| 96 | prefs->touchpad_fling_profile[1] = |
| 97 | pref_service->GetDouble(prefs::kFlingCurveTouchpadBeta); |
| 98 | prefs->touchpad_fling_profile[2] = |
| 99 | pref_service->GetDouble(prefs::kFlingCurveTouchpadGamma); |
| 100 | prefs->touchscreen_fling_profile[0] = |
| 101 | pref_service->GetDouble(prefs::kFlingCurveTouchscreenAlpha); |
| 102 | prefs->touchscreen_fling_profile[1] = |
| 103 | pref_service->GetDouble(prefs::kFlingCurveTouchscreenBeta); |
| 104 | prefs->touchscreen_fling_profile[2] = |
| 105 | pref_service->GetDouble(prefs::kFlingCurveTouchscreenGamma); |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 106 | #endif |
| 107 | |
[email protected] | dbf7501 | 2013-09-24 06:37:25 | [diff] [blame] | 108 | #if defined(TOOLKIT_VIEWS) |
| 109 | prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0; |
| 110 | #endif |
| 111 | |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 112 | #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 113 | views::LinuxUI* linux_ui = views::LinuxUI::instance(); |
| 114 | if (linux_ui) { |
[email protected] | 448d7dc | 2014-05-13 03:22:55 | [diff] [blame] | 115 | if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { |
[email protected] | 96514e7 | 2013-09-25 20:42:24 | [diff] [blame] | 116 | prefs->focus_ring_color = linux_ui->GetFocusRingColor(); |
| 117 | prefs->thumb_active_color = linux_ui->GetThumbActiveColor(); |
| 118 | prefs->thumb_inactive_color = linux_ui->GetThumbInactiveColor(); |
| 119 | prefs->track_color = linux_ui->GetTrackColor(); |
| 120 | prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor(); |
| 121 | prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor(); |
| 122 | prefs->inactive_selection_bg_color = |
| 123 | linux_ui->GetInactiveSelectionBgColor(); |
| 124 | prefs->inactive_selection_fg_color = |
| 125 | linux_ui->GetInactiveSelectionFgColor(); |
| 126 | } |
| 127 | |
| 128 | // If we have a linux_ui object, set the caret blink interval regardless of |
| 129 | // whether we're in native theme mode. |
| 130 | prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); |
| 131 | } |
| 132 | #endif |
| 133 | |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 134 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | 516b2c73 | 2014-07-25 00:10:31 | [diff] [blame^] | 135 | CR_DEFINE_STATIC_LOCAL(const gfx::FontRenderParams, params, |
| 136 | (gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(true), NULL))); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 137 | prefs->should_antialias_text = params.antialiasing; |
| 138 | prefs->use_subpixel_positioning = params.subpixel_positioning; |
[email protected] | bd2c470 | 2014-07-24 16:03:44 | [diff] [blame] | 139 | prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting); |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 140 | prefs->use_autohinter = params.autohinter; |
| 141 | prefs->use_bitmaps = params.use_bitmaps; |
[email protected] | bd2c470 | 2014-07-24 16:03:44 | [diff] [blame] | 142 | prefs->subpixel_rendering = |
| 143 | GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 144 | #endif |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 145 | |
| 146 | #if !defined(OS_MACOSX) |
| 147 | prefs->plugin_fullscreen_allowed = |
| 148 | pref_service->GetBoolean(prefs::kFullscreenAllowed); |
| 149 | #endif |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 0509bc8 | 2013-09-20 20:42:59 | [diff] [blame] | 152 | } // namespace renderer_preferences_util |