Remove repaint callbacks from Viewport.
[chromium-blink-merge.git] / chrome / browser / renderer_preferences_util.cc
blob82a37790215ba8a94ea65a5270f7f85dd6d578c8
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.h"
15 #endif
17 #if defined(TOOLKIT_VIEWS)
18 #include "ui/views/controls/textfield/textfield.h"
19 #endif
21 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
22 #include "chrome/browser/themes/theme_service.h"
23 #include "chrome/browser/themes/theme_service_factory.h"
24 #include "ui/views/linux_ui/linux_ui.h"
25 #endif
27 namespace renderer_preferences_util {
29 namespace {
31 #if defined(OS_LINUX) || defined(OS_ANDROID)
32 content::RendererPreferencesHintingEnum GetRendererPreferencesHintingEnum(
33 gfx::FontRenderParams::Hinting hinting) {
34 switch (hinting) {
35 case gfx::FontRenderParams::HINTING_NONE:
36 return content::RENDERER_PREFERENCES_HINTING_NONE;
37 case gfx::FontRenderParams::HINTING_SLIGHT:
38 return content::RENDERER_PREFERENCES_HINTING_SLIGHT;
39 case gfx::FontRenderParams::HINTING_MEDIUM:
40 return content::RENDERER_PREFERENCES_HINTING_MEDIUM;
41 case gfx::FontRenderParams::HINTING_FULL:
42 return content::RENDERER_PREFERENCES_HINTING_FULL;
43 default:
44 NOTREACHED() << "Unhandled hinting style " << hinting;
45 return content::RENDERER_PREFERENCES_HINTING_SYSTEM_DEFAULT;
49 content::RendererPreferencesSubpixelRenderingEnum
50 GetRendererPreferencesSubpixelRenderingEnum(
51 gfx::FontRenderParams::SubpixelRendering subpixel_rendering) {
52 switch (subpixel_rendering) {
53 case gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE:
54 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_NONE;
55 case gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB:
56 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_RGB;
57 case gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR:
58 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_BGR;
59 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB:
60 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VRGB;
61 case gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR:
62 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_VBGR;
63 default:
64 NOTREACHED() << "Unhandled subpixel rendering style "
65 << subpixel_rendering;
66 return content::RENDERER_PREFERENCES_SUBPIXEL_RENDERING_SYSTEM_DEFAULT;
69 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
71 } // namespace
73 void UpdateFromSystemSettings(
74 content::RendererPreferences* prefs, Profile* profile) {
75 const PrefService* pref_service = profile->GetPrefs();
76 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages);
77 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers);
78 prefs->enable_do_not_track =
79 pref_service->GetBoolean(prefs::kEnableDoNotTrack);
80 prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel);
82 #if defined(USE_DEFAULT_RENDER_THEME)
83 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE);
85 #if defined(OS_CHROMEOS)
86 // This color is 0x544d90fe modulated with 0xffffff.
87 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA);
88 prefs->active_selection_fg_color = SK_ColorBLACK;
89 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA);
90 prefs->inactive_selection_fg_color = SK_ColorBLACK;
91 #endif
93 prefs->touchpad_fling_profile[0] =
94 pref_service->GetDouble(prefs::kFlingCurveTouchpadAlpha);
95 prefs->touchpad_fling_profile[1] =
96 pref_service->GetDouble(prefs::kFlingCurveTouchpadBeta);
97 prefs->touchpad_fling_profile[2] =
98 pref_service->GetDouble(prefs::kFlingCurveTouchpadGamma);
99 prefs->touchscreen_fling_profile[0] =
100 pref_service->GetDouble(prefs::kFlingCurveTouchscreenAlpha);
101 prefs->touchscreen_fling_profile[1] =
102 pref_service->GetDouble(prefs::kFlingCurveTouchscreenBeta);
103 prefs->touchscreen_fling_profile[2] =
104 pref_service->GetDouble(prefs::kFlingCurveTouchscreenGamma);
105 #endif
107 #if defined(TOOLKIT_VIEWS)
108 prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0;
109 #endif
111 #if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
112 views::LinuxUI* linux_ui = views::LinuxUI::instance();
113 if (linux_ui) {
114 if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
115 prefs->focus_ring_color = linux_ui->GetFocusRingColor();
116 prefs->thumb_active_color = linux_ui->GetThumbActiveColor();
117 prefs->thumb_inactive_color = linux_ui->GetThumbInactiveColor();
118 prefs->track_color = linux_ui->GetTrackColor();
119 prefs->active_selection_bg_color = linux_ui->GetActiveSelectionBgColor();
120 prefs->active_selection_fg_color = linux_ui->GetActiveSelectionFgColor();
121 prefs->inactive_selection_bg_color =
122 linux_ui->GetInactiveSelectionBgColor();
123 prefs->inactive_selection_fg_color =
124 linux_ui->GetInactiveSelectionFgColor();
127 // If we have a linux_ui object, set the caret blink interval regardless of
128 // whether we're in native theme mode.
129 prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval();
131 #endif
133 #if defined(OS_LINUX) || defined(OS_ANDROID)
134 const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams();
135 prefs->should_antialias_text = params.antialiasing;
136 prefs->use_subpixel_positioning = params.subpixel_positioning;
137 prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting);
138 prefs->use_autohinter = params.autohinter;
139 prefs->use_bitmaps = params.use_bitmaps;
140 prefs->subpixel_rendering =
141 GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering);
142 #endif
144 #if !defined(OS_MACOSX)
145 prefs->plugin_fullscreen_allowed =
146 pref_service->GetBoolean(prefs::kFullscreenAllowed);
147 #endif
150 } // namespace renderer_preferences_util