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. 4 5 #include "chrome/browser/renderer_preferences_util.h" 6 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" 12 13 #if defined(OS_LINUX) || defined(OS_ANDROID) 14 #include "ui/gfx/font_render_params_linux.h" 15 #endif 16 17 #if defined(TOOLKIT_GTK) 18 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 19 #include "ui/gfx/gtk_util.h" 20 #endif 21 22 #if defined(USE_AURA) 23 #include "ui/views/controls/textfield/native_textfield_views.h" 24 #endif 25 26 namespace renderer_preferences_util { 27 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 37 #if defined(OS_LINUX) || defined(OS_ANDROID) 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 } 75 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 76 77 } // namespace 78 79 void UpdateFromSystemSettings( 80 content::RendererPreferences* prefs, Profile* profile) { 81 const PrefService* pref_service = profile->GetPrefs(); 82 prefs->accept_languages = pref_service->GetString(prefs::kAcceptLanguages); 83 prefs->enable_referrers = pref_service->GetBoolean(prefs::kEnableReferrers); 84 prefs->enable_do_not_track = 85 pref_service->GetBoolean(prefs::kEnableDoNotTrack); 86 prefs->default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); 87 88 #if defined(TOOLKIT_GTK) 89 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); 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(); 98 prefs->inactive_selection_bg_color = 99 theme_service->get_inactive_selection_bg_color(); 100 prefs->inactive_selection_fg_color = 101 theme_service->get_inactive_selection_fg_color(); 102 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; 108 #elif defined(USE_DEFAULT_RENDER_THEME) 109 prefs->focus_ring_color = SkColorSetRGB(0x4D, 0x90, 0xFE); 110 111 #if !defined(OS_WIN) 112 // This color is 0x544d90fe modulated with 0xffffff. 113 prefs->active_selection_bg_color = SkColorSetRGB(0xCB, 0xE4, 0xFA); 114 prefs->active_selection_fg_color = SK_ColorBLACK; 115 prefs->inactive_selection_bg_color = SkColorSetRGB(0xEA, 0xEA, 0xEA); 116 prefs->inactive_selection_fg_color = SK_ColorBLACK; 117 #endif 118 // WebKit accepts a single parameter to control the interval over which the 119 // cursor is shown or hidden, so divide Views's time for the full cycle by two 120 // and then convert to seconds. 121 prefs->caret_blink_interval = 122 views::NativeTextfieldViews::kCursorBlinkCycleMs / 2.0 / 1000; 123 124 prefs->touchpad_fling_profile[0] = 125 pref_service->GetDouble(prefs::kFlingCurveTouchpadAlpha); 126 prefs->touchpad_fling_profile[1] = 127 pref_service->GetDouble(prefs::kFlingCurveTouchpadBeta); 128 prefs->touchpad_fling_profile[2] = 129 pref_service->GetDouble(prefs::kFlingCurveTouchpadGamma); 130 prefs->touchscreen_fling_profile[0] = 131 pref_service->GetDouble(prefs::kFlingCurveTouchscreenAlpha); 132 prefs->touchscreen_fling_profile[1] = 133 pref_service->GetDouble(prefs::kFlingCurveTouchscreenBeta); 134 prefs->touchscreen_fling_profile[2] = 135 pref_service->GetDouble(prefs::kFlingCurveTouchscreenGamma); 136 #endif 137 138 #if defined(OS_LINUX) || defined(OS_ANDROID) 139 const gfx::FontRenderParams& params = gfx::GetDefaultWebKitFontRenderParams(); 140 prefs->should_antialias_text = params.antialiasing; 141 prefs->use_subpixel_positioning = params.subpixel_positioning; 142 prefs->hinting = GetRendererPreferencesHintingEnum(params.hinting); 143 prefs->use_autohinter = params.autohinter; 144 prefs->use_bitmaps = params.use_bitmaps; 145 prefs->subpixel_rendering = 146 GetRendererPreferencesSubpixelRenderingEnum(params.subpixel_rendering); 147 #endif 148 } 149 150 } // renderer_preferences_util 151