blob: 45ab1b3ce5c4461c78738657c85fd066f3428c11 [file] [log] [blame]
[email protected]37cc8042012-02-27 19:32:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]93623c5d2009-12-10 21:40:322// 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]516b2c732014-07-25 00:10:317#include "base/macros.h"
[email protected]3853a4c2013-02-11 17:15:578#include "base/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:339#include "chrome/browser/profiles/profile.h"
[email protected]0a8db0d2011-04-13 15:15:4010#include "chrome/common/pref_names.h"
[email protected]daf82f82011-10-31 22:35:3111#include "content/public/common/renderer_preferences.h"
[email protected]38a85712013-01-02 22:45:0212#include "third_party/skia/include/core/SkColor.h"
[email protected]93623c5d2009-12-10 21:40:3213
[email protected]7d076cf52012-07-09 23:04:4714#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]cd9c65e2014-07-10 02:57:0115#include "ui/gfx/font_render_params.h"
[email protected]f57f69012012-06-13 02:52:2116#endif
17
[email protected]dbf75012013-09-24 06:37:2518#if defined(TOOLKIT_VIEWS)
19#include "ui/views/controls/textfield/textfield.h"
[email protected]7bd129f2012-11-30 02:06:0120#endif
21
[email protected]96514e72013-09-25 20:42:2422#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]93623c5d2009-12-10 21:40:3228namespace renderer_preferences_util {
29
[email protected]bd2c4702014-07-24 16:03:4430namespace {
31
32#if defined(OS_LINUX) || defined(OS_ANDROID)
33content::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
50content::RendererPreferencesSubpixelRenderingEnum
51GetRendererPreferencesSubpixelRenderingEnum(
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]daf82f82011-10-31 22:35:3174void UpdateFromSystemSettings(
75 content::RendererPreferences* prefs, Profile* profile) {
[email protected]f57f69012012-06-13 02:52:2176 const PrefService* pref_service = profile->GetPrefs();
[email protected]9982c802013-06-12 15:22:0677 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
[email protected]f57f69012012-06-13 02:52:2178 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
[email protected]498bc512012-09-21 21:50:0879 prefs->enable_do_not_track =
80 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
[email protected]f57f69012012-06-13 02:52:2181 prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
82
[email protected]993f4bb2014-06-17 22:15:4883#if defined(USE_DEFAULT_RENDER_THEME)
[email protected]38a85712013-01-02 22:45:0284 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
85
[email protected]d41e40502014-04-12 00:56:2286#if defined(OS_CHROMEOS)
[email protected]38a85712013-01-02 22:45:0287 // 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]f2cb988d22013-07-01 22:07:0492#endif
[email protected]81a10552013-02-07 22:35:5693
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]7bd129f2012-11-30 02:06:01106#endif
107
[email protected]dbf75012013-09-24 06:37:25108#if defined(TOOLKIT_VIEWS)
109 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0;
110#endif
111
[email protected]96514e72013-09-25 20:42:24112#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
113 views::LinuxUI* linux_ui = views::LinuxUI::instance();
114 if (linux_ui) {
[email protected]448d7dc2014-05-13 03:22:55115 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
[email protected]96514e72013-09-25 20:42:24116 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]7d076cf52012-07-09 23:04:47134#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]516b2c732014-07-25 00:10:31135 CR_DEFINE_STATIC_LOCAL(const gfx::FontRenderParams, params,
136 (gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(true), NULL)));
[email protected]f57f69012012-06-13 02:52:21137 prefs->should_antialias_text = params.antialiasing;
138 prefs->use_subpixel_positioning = params.subpixel_positioning;
[email protected]bd2c4702014-07-24 16:03:44139 prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting);
[email protected]7d076cf52012-07-09 23:04:47140 prefs->use_autohinter = params.autohinter;
141 prefs->use_bitmaps = params.use_bitmaps;
[email protected]bd2c4702014-07-24 16:03:44142 prefs->subpixel_rendering =
143 GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering);
[email protected]f57f69012012-06-13 02:52:21144#endif
[email protected]0509bc82013-09-20 20:42:59145
146#if !defined(OS_MACOSX)
147 prefs->plugin_fullscreen_allowed =
148 pref_service->GetBoolean(prefs::kFullscreenAllowed);
149#endif
[email protected]93623c5d2009-12-10 21:40:32150}
151
[email protected]0509bc82013-09-20 20:42:59152} // namespace renderer_preferences_util