Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / renderer_preferences_util.cc
bloba95a4cea85d4627c94dd69b29faf3ec2fdf6fbec
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
3 // found in the LICENSE file.
5 #include "chrome/browser/renderer_preferences_util.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h"
10 #include "content/public/common/renderer_preferences.h"
11 #include "third_party/skia/include/core/SkColor.h"
13 #if defined(OS_LINUX) || defined(OS_ANDROID)
14 #include "ui/gfx/font_render_params_linux.h"
15 #endif
17 #if defined(TOOLKIT_GTK)
18 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
19 #include "ui/gfx/gtk_util.h"
20 #endif
22 #if defined(TOOLKIT_VIEWS)
23 #include "ui/views/controls/textfield/textfield.h"
24 #endif
26 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
27 #include "chrome/browser/themes/theme_service.h"
28 #include "chrome/browser/themes/theme_service_factory.h"
29 #include "ui/views/linux_ui/linux_ui.h"
30 #endif
32 namespace renderer_preferences_util {
34 namespace {
36 #if defined(OS_LINUX) || defined(OS_ANDROID)
37 content::RendererPreferencesHintingEnum GetRendererPreferencesHintingEnum(
38 gfx::FontRenderParams::Hinting hinting) {
39 switch (hinting) {
40 case gfx::FontRenderParams::HINTING_NONE:
41 return content::RENDERER_PREFERENCES_HINTING_NONE;
42 case gfx::FontRenderParams::HINTING_SLIGHT:
43 return content::RENDERER_PREFERENCES_HINTING_SLIGHT;
44 case gfx::FontRenderParams::HINTING_MEDIUM:
45 return content::RENDERER_PREFERENCES_HINTING_MEDIUM;
46 case gfx::FontRenderParams::HINTING_FULL:
47 return content::RENDERER_PREFERENCES_HINTING_FULL;
48 default:
49 NOTREACHED() << "Unhandled hinting style " << hinting;
50 return content::RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT;
54 content::RendererPreferencesSubpixelRenderingEnum
55 GetRendererPreferencesSubpixelRenderingEnum(
56 gfx::FontRenderParams::SubpixelRendering subpixel_rendering) {
57 switch (subpixel_rendering) {
58 case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE:
59 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE;
60 case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB:
61 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB;
62 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR:
63 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR;
64 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB:
65 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB;
66 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR:
67 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR;
68 default:
69 NOTREACHED() << "Unhandled subpixel rendering style "
70 << subpixel_rendering;
71 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT;
74 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
76 } // namespace
78 void UpdateFromSystemSettings(
79 content::RendererPreferences* prefs, Profile* profile) {
80 const PrefService* pref_service = profile->GetPrefs();
81 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
82 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
83 prefs->enable_do_not_track =
84 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
85 prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
87 #if defined(TOOLKIT_GTK)
88 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile);
89 prefs->focus_ring_color = theme_service->get_focus_ring_color();
90 prefs->thumb_active_color = theme_service->get_thumb_active_color();
91 prefs->thumb_inactive_color = theme_service->get_thumb_inactive_color();
92 prefs->track_color = theme_service->get_track_color();
93 prefs->active_selection_bg_color =
94 theme_service->get_active_selection_bg_color();
95 prefs->active_selection_fg_color =
96 theme_service->get_active_selection_fg_color();
97 prefs->inactive_selection_bg_color =
98 theme_service->get_inactive_selection_bg_color();
99 prefs->inactive_selection_fg_color =
100 theme_service->get_inactive_selection_fg_color();
102 // Dividing GTK's cursor blink cycle time (in milliseconds) by this value
103 // yields an appropriate value for RendererPreferences::caret_blink_interval.
104 // This matches the logic in the WebKit GTK port.
105 const double kGtkCursorBlinkCycleFactor = 2000.0;
106 const base::TimeDelta cursor_blink_time = gfx::GetCursorBlinkCycle();
107 prefs->caret_blink_interval =
108 cursor_blink_time.InMilliseconds() ?
109 cursor_blink_time.InMilliseconds() / kGtkCursorBlinkCycleFactor :
111 #elif defined(USE_DEFAULT_RENDER_THEME)
112 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
114 #if defined(OS_CHROMEOS)
115 // This color is 0x544d90fe modulated with 0xffffff.
116 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
117 prefs->active_selection_fg_color = SK_ColorBLACK;
118 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
119 prefs->inactive_selection_fg_color = SK_ColorBLACK;
120 #endif
122 prefs->touchpad_fling_profile[0] =
123 pref_service->GetDouble(prefs::kFlingCurveTouchpadAlpha);
124 prefs->touchpad_fling_profile[1] =
125 pref_service->GetDouble(prefs::kFlingCurveTouchpadBeta);
126 prefs->touchpad_fling_profile[2] =
127 pref_service->GetDouble(prefs::kFlingCurveTouchpadGamma);
128 prefs->touchscreen_fling_profile[0] =
129 pref_service->GetDouble(prefs::kFlingCurveTouchscreenAlpha);
130 prefs->touchscreen_fling_profile[1] =
131 pref_service->GetDouble(prefs::kFlingCurveTouchscreenBeta);
132 prefs->touchscreen_fling_profile[2] =
133 pref_service->GetDouble(prefs::kFlingCurveTouchscreenGamma);
134 #endif
136 #if defined(TOOLKIT_VIEWS)
137 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0;
138 #endif
140 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
141 views::LinuxUI* linux_ui = views::LinuxUI::instance();
142 if (linux_ui) {
143 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
144 prefs->focus_ring_color = linux_ui->GetFocusRingColor();
145 prefs->thumb_active_color = linux_ui->GetThumbActiveColor();
146 prefs->thumb_inactive_color = linux_ui->GetThumbInactiveColor();
147 prefs->track_color = linux_ui->GetTrackColor();
148 prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
149 prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
150 prefs->inactive_selection_bg_color =
151 linux_ui->GetInactiveSelectionBgColor();
152 prefs->inactive_selection_fg_color =
153 linux_ui->GetInactiveSelectionFgColor();
156 // If we have a linux_ui object, set the caret blink interval regardless of
157 // whether we're in native theme mode.
158 prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
160 #endif
162 #if defined(OS_LINUX) || defined(OS_ANDROID)
163 const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams();
164 prefs->should_antialias_text = params.antialiasing;
165 prefs->use_subpixel_positioning = params.subpixel_positioning;
166 prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting);
167 prefs->use_autohinter = params.autohinter;
168 prefs->use_bitmaps = params.use_bitmaps;
169 prefs->subpixel_rendering =
170 GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering);
171 #endif
173 #if !defined(OS_MACOSX)
174 prefs->plugin_fullscreen_allowed =
175 pref_service->GetBoolean(prefs::kFullscreenAllowed);
176 #endif
179 } // namespace renderer_preferences_util