Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Side by Side Diff: content/renderer/web_preferences.cc

Issue 28053002: Add font_scale_factor_quirk pref. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master.pinned
Patch Set: Address review comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 value of font_scale_factor passed by Chrome for Android already
126 // includes the multiplier.
127 return 1.0;
128 }
129 gfx::DeviceDisplayInfo info;
130 int minWidth = info.GetSmallestDIPWidth();
jamesr 2013/10/21 17:58:33 we shouldn't be doing logic like this here in the
131
132 if (minWidth <= kWidthForMinFSM)
133 return kMinFSM;
134 if (minWidth >= kWidthForMaxFSM)
135 return kMaxFSM;
136
137 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
138 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
139 (kWidthForMaxFSM - kWidthForMinFSM);
140 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
141 }
142
143 #endif // defined(OS_ANDROID)
144
112 } // namespace 145 } // namespace
113 146
114 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) { 147 void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
115 WebSettings* settings = web_view->settings(); 148 WebSettings* settings = web_view->settings();
116 ApplyFontsFromMap(prefs.standard_font_family_map, 149 ApplyFontsFromMap(prefs.standard_font_family_map,
117 setStandardFontFamilyWrapper, settings); 150 setStandardFontFamilyWrapper, settings);
118 ApplyFontsFromMap(prefs.fixed_font_family_map, 151 ApplyFontsFromMap(prefs.fixed_font_family_map,
119 setFixedFontFamilyWrapper, settings); 152 setFixedFontFamilyWrapper, settings);
120 ApplyFontsFromMap(prefs.serif_font_family_map, 153 ApplyFontsFromMap(prefs.serif_font_family_map,
121 setSerifFontFamilyWrapper, settings); 154 setSerifFontFamilyWrapper, settings);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 350
318 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled); 351 settings->setSmartInsertDeleteEnabled(prefs.smart_insert_delete_enabled);
319 352
320 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled); 353 settings->setSpatialNavigationEnabled(prefs.spatial_navigation_enabled);
321 354
322 settings->setSelectionIncludesAltImageText(true); 355 settings->setSelectionIncludesAltImageText(true);
323 356
324 #if defined(OS_ANDROID) 357 #if defined(OS_ANDROID)
325 settings->setAllowCustomScrollbarInMainFrame(false); 358 settings->setAllowCustomScrollbarInMainFrame(false);
326 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled); 359 settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
327 settings->setTextAutosizingFontScaleFactor(prefs.font_scale_factor); 360 settings->setTextAutosizingFontScaleFactor(
361 prefs.font_scale_factor * GetFontScaleMultiplier(prefs));
328 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom); 362 web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
329 settings->setAutoZoomFocusedNodeToLegibleScale(true); 363 settings->setAutoZoomFocusedNodeToLegibleScale(true);
330 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled); 364 settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
331 settings->setMediaPlaybackRequiresUserGesture( 365 settings->setMediaPlaybackRequiresUserGesture(
332 prefs.user_gesture_required_for_media_playback); 366 prefs.user_gesture_required_for_media_playback);
333 settings->setMediaFullscreenRequiresUserGesture( 367 settings->setMediaFullscreenRequiresUserGesture(
334 prefs.user_gesture_required_for_media_fullscreen); 368 prefs.user_gesture_required_for_media_fullscreen);
335 settings->setDefaultVideoPosterURL( 369 settings->setDefaultVideoPosterURL(
336 ASCIIToUTF16(prefs.default_video_poster_url.spec())); 370 ASCIIToUTF16(prefs.default_video_poster_url.spec()));
337 settings->setSupportDeprecatedTargetDensityDPI( 371 settings->setSupportDeprecatedTargetDensityDPI(
(...skipping 18 matching lines...) Expand all
356 settings->setPinchVirtualViewportEnabled( 390 settings->setPinchVirtualViewportEnabled(
357 prefs.pinch_virtual_viewport_enabled); 391 prefs.pinch_virtual_viewport_enabled);
358 392
359 settings->setPinchOverlayScrollbarThickness( 393 settings->setPinchOverlayScrollbarThickness(
360 prefs.pinch_overlay_scrollbar_thickness); 394 prefs.pinch_overlay_scrollbar_thickness);
361 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars); 395 settings->setUseSolidColorScrollbars(prefs.use_solid_color_scrollbars);
362 settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing); 396 settings->setCompositorTouchHitTesting(prefs.compositor_touch_hit_testing);
363 } 397 }
364 398
365 } // namespace content 399 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/common_param_traits_macros.h ('k') | ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698