Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/renderer/web_preferences.h" | 5 #include "content/public/renderer/web_preferences.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "third_party/WebKit/public/platform/WebString.h" | 8 #include "third_party/WebKit/public/platform/WebString.h" |
| 9 #include "third_party/WebKit/public/platform/WebURL.h" | 9 #include "third_party/WebKit/public/platform/WebURL.h" |
| 10 #include "third_party/WebKit/public/web/WebKit.h" | 10 #include "third_party/WebKit/public/web/WebKit.h" |
| 11 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 11 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
| 12 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 12 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 13 #include "third_party/WebKit/public/web/WebSettings.h" | 13 #include "third_party/WebKit/public/web/WebSettings.h" |
| 14 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
| 15 #include "third_party/icu/source/common/unicode/uchar.h" | 15 #include "third_party/icu/source/common/unicode/uchar.h" |
| 16 #include "third_party/icu/source/common/unicode/uscript.h" | 16 #include "third_party/icu/source/common/unicode/uscript.h" |
| 17 #include "webkit/common/webpreferences.h" | 17 #include "webkit/common/webpreferences.h" |
| 18 | 18 |
| 19 #if defined(OS_ANDROID) | |
| 20 #include "ui/gfx/android/device_display_info.h" | |
| 21 #endif | |
| 22 | |
| 19 using WebKit::WebNetworkStateNotifier; | 23 using WebKit::WebNetworkStateNotifier; |
| 20 using WebKit::WebRuntimeFeatures; | 24 using WebKit::WebRuntimeFeatures; |
| 21 using WebKit::WebSettings; | 25 using WebKit::WebSettings; |
| 22 using WebKit::WebString; | 26 using WebKit::WebString; |
| 23 using WebKit::WebURL; | 27 using WebKit::WebURL; |
| 24 using WebKit::WebView; | 28 using WebKit::WebView; |
| 25 | 29 |
| 26 namespace content { | 30 namespace content { |
| 27 | 31 |
| 28 namespace { | 32 namespace { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 it != map.end(); | 106 it != map.end(); |
| 103 ++it) { | 107 ++it) { |
| 104 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); | 108 int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str()); |
| 105 if (script >= 0 && script < USCRIPT_CODE_LIMIT) { | 109 if (script >= 0 && script < USCRIPT_CODE_LIMIT) { |
| 106 UScriptCode code = static_cast<UScriptCode>(script); | 110 UScriptCode code = static_cast<UScriptCode>(script); |
| 107 (*setter)(settings, it->second, GetScriptForWebSettings(code)); | 111 (*setter)(settings, it->second, GetScriptForWebSettings(code)); |
| 108 } | 112 } |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 | 115 |
| 116 #if defined(OS_ANDROID) | |
| 117 | |
| 118 const float kMinFSM = 1.05f; | |
| 119 const int kWidthForMinFSM = 320; | |
| 120 const float kMaxFSM = 1.3f; | |
| 121 const int kWidthForMaxFSM = 800; | |
| 122 | |
| 123 float GetFontScaleMultiplier(const WebPreferences& prefs) { | |
| 124 if (prefs.font_scale_factor_quirk) { | |
| 125 // The pref value passed by Clank already includes the multiplier. | |
| 126 return 1.0; | |
| 127 } | |
| 128 gfx::DeviceDisplayInfo info; | |
| 129 int minWidth = info.GetSmallestDIPWidth(); | |
| 130 | |
| 131 if (minWidth <= kWidthForMinFSM) return kMinFSM; | |
|
aelias_OOO_until_Jul13
2013/10/19 03:27:43
nit: return should be on another line
aelias_OOO_until_Jul13
2013/10/19 03:27:43
nit: return should be on newline
skobes
2013/10/21 17:49:30
Done.
skobes
2013/10/21 17:49:30
Done.
| |
| 132 if (minWidth >= kWidthForMaxFSM) return kMaxFSM; | |
| 133 | |
| 134 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. | |
| 135 float ratio = ((float)(minWidth - kWidthForMinFSM)) / | |
|
aelias_OOO_until_Jul13
2013/10/19 03:27:43
nit: use static_cast<float>(), and no need for the
skobes
2013/10/21 17:49:30
Done.
| |
| 136 ((float)(kWidthForMaxFSM - kWidthForMinFSM)); | |
| 137 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | |
| 138 } | |
| 139 | |
| 140 #endif // defined(OS_ANDROID) | |
| 141 | |
| 112 } // namespace | 142 } // namespace |
| 113 | 143 |
| 114 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { | 144 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { |
| 115 WebSettings* settings = web_view->settings(); | 145 WebSettings* settings = web_view->settings(); |
| 116 ApplyFontsFromMap(prefs.standard_font_family_map, | 146 ApplyFontsFromMap(prefs.standard_font_family_map, |
| 117 setStandardFontFamilyWrapper, settings); | 147 setStandardFontFamilyWrapper, settings); |
| 118 ApplyFontsFromMap(prefs.fixed_font_family_map, | 148 ApplyFontsFromMap(prefs.fixed_font_family_map, |
| 119 setFixedFontFamilyWrapper, settings); | 149 setFixedFontFamilyWrapper, settings); |
| 120 ApplyFontsFromMap(prefs.serif_font_family_map, | 150 ApplyFontsFromMap(prefs.serif_font_family_map, |
| 121 setSerifFontFamilyWrapper, settings); | 151 setSerifFontFamilyWrapper, settings); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 | 347 |
| 318 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); | 348 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); |
| 319 | 349 |
| 320 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); | 350 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); |
| 321 | 351 |
| 322 settings->setSelectionIncludesAltImageText(true); | 352 settings->setSelectionIncludesAltImageText(true); |
| 323 | 353 |
| 324 #if defined(OS_ANDROID) | 354 #if defined(OS_ANDROID) |
| 325 settings->setAllowCustomScrollbarInMainFrame(false); | 355 settings->setAllowCustomScrollbarInMainFrame(false); |
| 326 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled); | 356 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled); |
| 327 settings->setTextAutosizingFontScaleFactor(prefs.font_scale_factor); | 357 settings->setTextAutosizingFontScaleFactor( |
| 358 prefs.font_scale_factor * GetFontScaleMultiplier(prefs)); | |
| 328 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); | 359 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); |
| 329 settings->setAutoZoomFocusedNodeToLegibleScale(true); | 360 settings->setAutoZoomFocusedNodeToLegibleScale(true); |
| 330 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); | 361 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); |
| 331 settings->setMediaPlaybackRequiresUserGesture( | 362 settings->setMediaPlaybackRequiresUserGesture( |
| 332 prefs.user_gesture_required_for_media_playback); | 363 prefs.user_gesture_required_for_media_playback); |
| 333 settings->setMediaFullscreenRequiresUserGesture( | 364 settings->setMediaFullscreenRequiresUserGesture( |
| 334 prefs.user_gesture_required_for_media_fullscreen); | 365 prefs.user_gesture_required_for_media_fullscreen); |
| 335 settings->setDefaultVideoPosterURL( | 366 settings->setDefaultVideoPosterURL( |
| 336 ASCIIToUTF16(prefs.default_video_poster_url.spec())); | 367 ASCIIToUTF16(prefs.default_video_poster_url.spec())); |
| 337 settings->setSupportDeprecatedTargetDensityDPI( | 368 settings->setSupportDeprecatedTargetDensityDPI( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 356 settings->setPinchVirtualViewportEnabled( | 387 settings->setPinchVirtualViewportEnabled( |
| 357 prefs.pinch_virtual_viewport_enabled); | 388 prefs.pinch_virtual_viewport_enabled); |
| 358 | 389 |
| 359 settings->setPinchOverlayScrollbarThickness( | 390 settings->setPinchOverlayScrollbarThickness( |
| 360 prefs.pinch_overlay_scrollbar_thickness); | 391 prefs.pinch_overlay_scrollbar_thickness); |
| 361 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars); | 392 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars); |
| 362 settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing); | 393 settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing); |
| 363 } | 394 } |
| 364 | 395 |
| 365 } // namespace content | 396 } // namespace content |
| OLD | NEW |