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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/web_preferences.cc
diff --git a/content/renderer/web_preferences.cc b/content/renderer/web_preferences.cc
index 17d4a9c2344df2af9ca9bb35f95c9b2e6687083d..033de7301cd54cb288642a986fc96df6ba66983e 100644
--- a/content/renderer/web_preferences.cc
+++ b/content/renderer/web_preferences.cc
@@ -16,6 +16,10 @@
#include "third_party/icu/source/common/unicode/uscript.h"
#include "webkit/common/webpreferences.h"
+#if defined(OS_ANDROID)
+#include "ui/gfx/android/device_display_info.h"
+#endif
+
using WebKit::WebNetworkStateNotifier;
using WebKit::WebRuntimeFeatures;
using WebKit::WebSettings;
@@ -109,6 +113,32 @@ void ApplyFontsFromMap(const webkit_glue::ScriptFontFamilyMap& map,
}
}
+#if defined(OS_ANDROID)
+
+const float kMinFSM = 1.05f;
+const int kWidthForMinFSM = 320;
+const float kMaxFSM = 1.3f;
+const int kWidthForMaxFSM = 800;
+
+float GetFontScaleMultiplier(const WebPreferences& prefs) {
+ if (prefs.font_scale_factor_quirk) {
+ // The pref value passed by Clank already includes the multiplier.
+ return 1.0;
+ }
+ gfx::DeviceDisplayInfo info;
+ int minWidth = info.GetSmallestDIPWidth();
+
+ 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.
+ if (minWidth >= kWidthForMaxFSM) return kMaxFSM;
+
+ // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
+ 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.
+ ((float)(kWidthForMaxFSM - kWidthForMinFSM));
+ return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
+}
+
+#endif // defined(OS_ANDROID)
+
} // namespace
void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
@@ -324,7 +354,8 @@ void ApplyWebPreferences(const WebPreferences& prefs, WebView* web_view) {
#if defined(OS_ANDROID)
settings->setAllowCustomScrollbarInMainFrame(false);
settings->setTextAutosizingEnabled(prefs.text_autosizing_enabled);
- settings->setTextAutosizingFontScaleFactor(prefs.font_scale_factor);
+ settings->setTextAutosizingFontScaleFactor(
+ prefs.font_scale_factor * GetFontScaleMultiplier(prefs));
web_view->setIgnoreViewportTagScaleLimits(prefs.force_enable_zoom);
settings->setAutoZoomFocusedNodeToLegibleScale(true);
settings->setDoubleTapToZoomEnabled(prefs.double_tap_to_zoom_enabled);
« 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