blob: c948cd36d7a8511b23377fc9fd5e609417086216 [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]3853a4c2013-02-11 17:15:577#include "base/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:338#include "chrome/browser/profiles/profile.h"
[email protected]0a8db0d2011-04-13 15:15:409#include "chrome/common/pref_names.h"
[email protected]daf82f82011-10-31 22:35:3110#include "content/public/common/renderer_preferences.h"
[email protected]38a85712013-01-02 22:45:0211#include "third_party/skia/include/core/SkColor.h"
[email protected]93623c5d2009-12-10 21:40:3212
[email protected]7d076cf52012-07-09 23:04:4713#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]f57f69012012-06-13 02:52:2114#include "ui/gfx/font_render_params_linux.h"
15#endif
16
[email protected]a13283cc2012-04-05 00:21:2217#if defined(TOOLKIT_GTK)
[email protected]0174bed2012-05-03 01:04:4518#include "chrome/browser/ui/gtk/gtk_theme_service.h"
[email protected]f57f69012012-06-13 02:52:2119#include "ui/gfx/gtk_util.h"
[email protected]93623c5d2009-12-10 21:40:3220#endif
21
[email protected]7bd129f2012-11-30 02:06:0122#if defined(USE_AURA)
23#include "ui/views/controls/textfield/native_textfield_views.h"
24#endif
25
[email protected]93623c5d2009-12-10 21:40:3226namespace renderer_preferences_util {
27
[email protected]f57f69012012-06-13 02:52:2128namespace {
29
30#if defined(TOOLKIT_GTK)
31// Dividing GTK's cursor blink cycle time (in milliseconds) by this value yields
32// an appropriate value for content::RendererPreferences::caret_blink_interval.
33// This matches the logic in the WebKit GTK port.
34const double kGtkCursorBlinkCycleFactor = 2000.0;
35#endif // defined(TOOLKIT_GTK)
36
[email protected]7d076cf52012-07-09 23:04:4737#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]f57f69012012-06-13 02:52:2138content::RendererPreferencesHintingEnum GetRendererPreferencesHintingEnum(
39 gfx::FontRenderParams::Hinting hinting) {
40 switch (hinting) {
41 case gfx::FontRenderParams::HINTING_NONE:
42 return content::RENDERER_PREFERENCES_HINTING_NONE;
43 case gfx::FontRenderParams::HINTING_SLIGHT:
44 return content::RENDERER_PREFERENCES_HINTING_SLIGHT;
45 case gfx::FontRenderParams::HINTING_MEDIUM:
46 return content::RENDERER_PREFERENCES_HINTING_MEDIUM;
47 case gfx::FontRenderParams::HINTING_FULL:
48 return content::RENDERER_PREFERENCES_HINTING_FULL;
49 default:
50 NOTREACHED() << "Unhandled hinting style " << hinting;
51 return content::RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT;
52 }
53}
54
55content::RendererPreferencesSubpixelRenderingEnum
56GetRendererPreferencesSubpixelRenderingEnum(
57 gfx::FontRenderParams::SubpixelRendering subpixel_rendering) {
58 switch (subpixel_rendering) {
59 case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE:
60 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE;
61 case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB:
62 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB;
63 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR:
64 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR;
65 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB:
66 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB;
67 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR:
68 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR;
69 default:
70 NOTREACHED() << "Unhandled subpixel rendering style "
71 << subpixel_rendering;
72 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT;
73 }
74}
[email protected]7d076cf52012-07-09 23:04:4775#endif // defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]f57f69012012-06-13 02:52:2176
77} // namespace
78
[email protected]daf82f82011-10-31 22:35:3179void UpdateFromSystemSettings(
80 content::RendererPreferences* prefs, Profile* profile) {
[email protected]f57f69012012-06-13 02:52:2181 const PrefService* pref_service = profile->GetPrefs();
[email protected]9982c802013-06-12 15:22:0682 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
[email protected]f57f69012012-06-13 02:52:2183 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
[email protected]498bc512012-09-21 21:50:0884 prefs->enable_do_not_track =
85 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
[email protected]f57f69012012-06-13 02:52:2186 prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
87
[email protected]a13283cc2012-04-05 00:21:2288#if defined(TOOLKIT_GTK)
[email protected]0174bed2012-05-03 01:04:4589 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile);
[email protected]a0ea76c2011-03-23 17:36:4290 prefs->focus_ring_color = theme_service->get_focus_ring_color();
91 prefs->thumb_active_color = theme_service->get_thumb_active_color();
92 prefs->thumb_inactive_color = theme_service->get_thumb_inactive_color();
93 prefs->track_color = theme_service->get_track_color();
94 prefs->active_selection_bg_color =
95 theme_service->get_active_selection_bg_color();
96 prefs->active_selection_fg_color =
97 theme_service->get_active_selection_fg_color();
[email protected]644d77e2010-01-27 01:03:1098 prefs->inactive_selection_bg_color =
[email protected]a0ea76c2011-03-23 17:36:4299 theme_service->get_inactive_selection_bg_color();
[email protected]644d77e2010-01-27 01:03:10100 prefs->inactive_selection_fg_color =
[email protected]a0ea76c2011-03-23 17:36:42101 theme_service->get_inactive_selection_fg_color();
[email protected]0a8db0d2011-04-13 15:15:40102
[email protected]7bd129f2012-11-30 02:06:01103 const base::TimeDelta cursor_blink_time = gfx::GetCursorBlinkCycle();
104 prefs->caret_blink_interval =
105 cursor_blink_time.InMilliseconds() ?
106 cursor_blink_time.InMilliseconds() / kGtkCursorBlinkCycleFactor :
107 0;
[email protected]38a85712013-01-02 22:45:02108#elif defined(USE_DEFAULT_RENDER_THEME)
109 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
110
111 // This color is 0x544d90fe modulated with 0xffffff.
112 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
113 prefs->active_selection_fg_color = SK_ColorBLACK;
114 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
115 prefs->inactive_selection_fg_color = SK_ColorBLACK;
116
[email protected]7bd129f2012-11-30 02:06:01117 // WebKit accepts a single parameter to control the interval over which the
118 // cursor is shown or hidden, so divide Views's time for the full cycle by two
119 // and then convert to seconds.
120 prefs->caret_blink_interval =
121 views::NativeTextfieldViews::kCursorBlinkCycleMs / 2.0 / 1000;
[email protected]81a10552013-02-07 22:35:56122
123 prefs->touchpad_fling_profile[0] =
124 pref_service->GetDouble(prefs::kFlingCurveTouchpadAlpha);
125 prefs->touchpad_fling_profile[1] =
126 pref_service->GetDouble(prefs::kFlingCurveTouchpadBeta);
127 prefs->touchpad_fling_profile[2] =
128 pref_service->GetDouble(prefs::kFlingCurveTouchpadGamma);
129 prefs->touchscreen_fling_profile[0] =
130 pref_service->GetDouble(prefs::kFlingCurveTouchscreenAlpha);
131 prefs->touchscreen_fling_profile[1] =
132 pref_service->GetDouble(prefs::kFlingCurveTouchscreenBeta);
133 prefs->touchscreen_fling_profile[2] =
134 pref_service->GetDouble(prefs::kFlingCurveTouchscreenGamma);
[email protected]7bd129f2012-11-30 02:06:01135#endif
136
[email protected]7d076cf52012-07-09 23:04:47137#if defined(OS_LINUX) || defined(OS_ANDROID)
[email protected]f6f82832012-09-04 17:12:04138 const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams();
[email protected]f57f69012012-06-13 02:52:21139 prefs->should_antialias_text = params.antialiasing;
140 prefs->use_subpixel_positioning = params.subpixel_positioning;
141 prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting);
[email protected]7d076cf52012-07-09 23:04:47142 prefs->use_autohinter = params.autohinter;
143 prefs->use_bitmaps = params.use_bitmaps;
[email protected]f57f69012012-06-13 02:52:21144 prefs->subpixel_rendering =
145 GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering);
146#endif
[email protected]93623c5d2009-12-10 21:40:32147}
148
149} // renderer_preferences_util