Bug 1328868 - Part 1 - Allow setting a global zoom factor via nsLayoutUtils. r=tnikkel

For Android we want to be able to set a global zoom factor that will scale any page where font inflation is not turned on.

Android makes the system font scale available as a float factor. For our purposes, converting this to a percentage based value and rounding to an integer is accurate enough and enables us to pass this value as a standard Gecko int preference. This means we can make use of the standard infrastructure for setting and retrieving Gecko-side preferences both from Java and JS (the latter during testing), as opposed to having to write custom JNI and C++/IDL helper functions.

To that effect, we implement a method for retrieving that setting via nsLayoutUtils, analogous to the current font inflation settings. Since we later want to clamp the effective text zoom resulting from that setting by zoom.minPercent and maxPercent, we add var caches for them in nsLayoutUtils as well.

MozReview-Commit-ID: Ler2YmwzImE

--HG--
extra : rebase_source : 6959c42267c1cb2b53804a609dda3d6d8b0bf14c
extra : source : 6a06ccede9eb54e4311e75e9f481d42d8c1f47a1
This commit is contained in:
Jan Henning 2017-02-25 13:22:45 +01:00
parent 9606419e96
commit 320ff25d1c
3 changed files with 39 additions and 0 deletions

View File

@ -179,6 +179,9 @@ typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox;
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMaxRatio;
/* static */ bool nsLayoutUtils::sFontSizeInflationForceEnabled;
/* static */ bool nsLayoutUtils::sFontSizeInflationDisabledInMasterProcess;
/* static */ uint32_t nsLayoutUtils::sSystemFontScale;
/* static */ uint32_t nsLayoutUtils::sZoomMaxPercent;
/* static */ uint32_t nsLayoutUtils::sZoomMinPercent;
/* static */ bool nsLayoutUtils::sInvalidationDebuggingIsEnabled;
/* static */ bool nsLayoutUtils::sCSSVariablesEnabled;
/* static */ bool nsLayoutUtils::sInterruptibleReflowEnabled;
@ -7716,6 +7719,12 @@ nsLayoutUtils::Initialize()
"font.size.inflation.forceEnabled");
Preferences::AddBoolVarCache(&sFontSizeInflationDisabledInMasterProcess,
"font.size.inflation.disabledInMasterProcess");
Preferences::AddUintVarCache(&sSystemFontScale,
"font.size.systemFontScale", 100);
Preferences::AddUintVarCache(&sZoomMaxPercent,
"zoom.maxPercent", 300);
Preferences::AddUintVarCache(&sZoomMinPercent,
"zoom.minPercent", 30);
Preferences::AddBoolVarCache(&sInvalidationDebuggingIsEnabled,
"nglayout.debug.invalidation");
Preferences::AddBoolVarCache(&sCSSVariablesEnabled,

View File

@ -2433,6 +2433,22 @@ public:
return sFontSizeInflationDisabledInMasterProcess;
}
/**
* See comment above "font.size.systemFontScale" in
* modules/libpref/init/all.js.
*/
static float SystemFontScale() {
return sSystemFontScale / 100.0f;
}
static float MaxZoom() {
return sZoomMaxPercent / 100.0f;
}
static float MinZoom() {
return sZoomMinPercent / 100.0f;
}
static bool SVGTransformBoxEnabled() {
return sSVGTransformBoxEnabled;
}
@ -2923,6 +2939,9 @@ private:
static uint32_t sFontSizeInflationMaxRatio;
static bool sFontSizeInflationForceEnabled;
static bool sFontSizeInflationDisabledInMasterProcess;
static uint32_t sSystemFontScale;
static uint32_t sZoomMaxPercent;
static uint32_t sZoomMinPercent;
static bool sInvalidationDebuggingIsEnabled;
static bool sCSSVariablesEnabled;
static bool sInterruptibleReflowEnabled;

View File

@ -3221,6 +3221,17 @@ pref("font.size.inflation.mappingIntercept", 1);
*/
pref("font.size.inflation.maxRatio", 0);
/**
* This setting corresponds to a global text zoom setting affecting
* all content that is not already subject to font size inflation.
* It is interpreted as a percentage value that is applied on top
* of the document's current text zoom setting.
*
* The resulting total zoom factor (text zoom * system font scale)
* will be limited by zoom.minPercent and maxPercent.
*/
pref("font.size.systemFontScale", 100);
/*
* When enabled, the touch.radius and mouse.radius prefs allow events to be dispatched
* to nearby elements that are sensitive to the event. See PositionedEventTargeting.cpp.