[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] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 7 | #include "base/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 8 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 9 | #include "chrome/common/pref_names.h" |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 10 | #include "content/public/common/renderer_preferences.h" |
[email protected] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 11 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 12 | |
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 13 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 14 | #include "ui/gfx/font_render_params_linux.h" |
15 | #endif | ||||
16 | |||||
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 17 | #if defined(TOOLKIT_GTK) |
[email protected] | 0174bed | 2012-05-03 01:04:45 | [diff] [blame] | 18 | #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 19 | #include "ui/gfx/gtk_util.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 20 | #endif |
21 | |||||
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 22 | #if defined(USE_AURA) |
23 | #include "ui/views/controls/textfield/native_textfield_views.h" | ||||
24 | #endif | ||||
25 | |||||
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 26 | namespace renderer_preferences_util { |
27 | |||||
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 28 | namespace { |
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. | ||||
34 | const double kGtkCursorBlinkCycleFactor = 2000.0; | ||||
35 | #endif // defined(TOOLKIT_GTK) | ||||
36 | |||||
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 37 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 38 | content::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 | |||||
55 | content::RendererPreferencesSubpixelRenderingEnum | ||||
56 | GetRendererPreferencesSubpixelRenderingEnum( | ||||
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] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 75 | #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 76 | |
77 | } // namespace | ||||
78 | |||||
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 79 | void UpdateFromSystemSettings( |
80 | content::RendererPreferences* prefs, Profile* profile) { | ||||
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 81 | const PrefService* pref_service = profile->GetPrefs(); |
[email protected] | 9982c80 | 2013-06-12 15:22:06 | [diff] [blame^] | 82 | prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 83 | prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); |
[email protected] | 498bc51 | 2012-09-21 21:50:08 | [diff] [blame] | 84 | prefs->enable_do_not_track = |
85 | pref_service->GetBoolean(prefs::kEnableDoNotTrack); | ||||
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 86 | prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); |
87 | |||||
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 88 | #if defined(TOOLKIT_GTK) |
[email protected] | 0174bed | 2012-05-03 01:04:45 | [diff] [blame] | 89 | GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 90 | 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] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 98 | prefs->inactive_selection_bg_color = |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 99 | theme_service->get_inactive_selection_bg_color(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 100 | prefs->inactive_selection_fg_color = |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 101 | theme_service->get_inactive_selection_fg_color(); |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 102 | |
[email protected] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 103 | 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] | 38a8571 | 2013-01-02 22:45:02 | [diff] [blame] | 108 | #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] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 117 | // 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] | 81a1055 | 2013-02-07 22:35:56 | [diff] [blame] | 122 | |
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] | 7bd129f | 2012-11-30 02:06:01 | [diff] [blame] | 135 | #endif |
136 | |||||
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 137 | #if defined(OS_LINUX) || defined(OS_ANDROID) |
[email protected] | f6f8283 | 2012-09-04 17:12:04 | [diff] [blame] | 138 | const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams(); |
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 139 | prefs->should_antialias_text = params.antialiasing; |
140 | prefs->use_subpixel_positioning = params.subpixel_positioning; | ||||
141 | prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting); | ||||
[email protected] | 7d076cf5 | 2012-07-09 23:04:47 | [diff] [blame] | 142 | prefs->use_autohinter = params.autohinter; |
143 | prefs->use_bitmaps = params.use_bitmaps; | ||||
[email protected] | f57f6901 | 2012-06-13 02:52:21 | [diff] [blame] | 144 | prefs->subpixel_rendering = |
145 | GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering); | ||||
146 | #endif | ||||
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 147 | } |
148 | |||||
149 | } // renderer_preferences_util |