Bug 1328868 - Part 1 - Allow setting a global zoom factor via nsLayoutUtils. r?tnikkel draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 25 Feb 2017 13:22:45 +0100
changeset 508544 e03bb87c110ab8f926e843080ba8e6d8cffd604f
parent 508543 ad1b53fe9f75dc9bf970e03f37a5ec35905000e1
child 508545 cc6fc40bf63b9bfb6ee42bfe2eb833952317664f
push id50868
push usermozilla@buttercookie.de
push dateFri, 24 Mar 2017 17:08:10 +0000
reviewerstnikkel
bugs1328868
milestone55.0a1
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
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
modules/libpref/init/all.js
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -174,16 +174,19 @@ typedef nsStyleTransformMatrix::Transfor
 
 /* static */ uint32_t nsLayoutUtils::sFontSizeInflationEmPerLine;
 /* static */ uint32_t nsLayoutUtils::sFontSizeInflationMinTwips;
 /* static */ uint32_t nsLayoutUtils::sFontSizeInflationLineThreshold;
 /* static */ int32_t  nsLayoutUtils::sFontSizeInflationMappingIntercept;
 /* 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;
 /* static */ bool nsLayoutUtils::sSVGTransformBoxEnabled;
 /* static */ bool nsLayoutUtils::sTextCombineUprightDigitsEnabled;
 #ifdef MOZ_STYLO
 /* static */ bool nsLayoutUtils::sStyloEnabled;
 #endif
@@ -7711,16 +7714,22 @@ nsLayoutUtils::Initialize()
   Preferences::AddUintVarCache(&sFontSizeInflationLineThreshold,
                                "font.size.inflation.lineThreshold");
   Preferences::AddIntVarCache(&sFontSizeInflationMappingIntercept,
                               "font.size.inflation.mappingIntercept");
   Preferences::AddBoolVarCache(&sFontSizeInflationForceEnabled,
                                "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,
                                "layout.css.variables.enabled");
   Preferences::AddBoolVarCache(&sInterruptibleReflowEnabled,
                                "layout.interruptible-reflow.enabled");
   Preferences::AddBoolVarCache(&sSVGTransformBoxEnabled,
                                "svg.transform-box.enabled");
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2428,16 +2428,32 @@ public:
   static bool FontSizeInflationForceEnabled() {
     return sFontSizeInflationForceEnabled;
   }
 
   static bool FontSizeInflationDisabledInMasterProcess() {
     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;
   }
 
   static bool TextCombineUprightDigitsEnabled() {
     return sTextCombineUprightDigitsEnabled;
   }
 
@@ -2918,16 +2934,19 @@ public:
 private:
   static uint32_t sFontSizeInflationEmPerLine;
   static uint32_t sFontSizeInflationMinTwips;
   static uint32_t sFontSizeInflationLineThreshold;
   static int32_t  sFontSizeInflationMappingIntercept;
   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;
   static bool sSVGTransformBoxEnabled;
   static bool sTextCombineUprightDigitsEnabled;
 #ifdef MOZ_STYLO
   static bool sStyloEnabled;
 #endif
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -3212,16 +3212,27 @@ pref("font.size.inflation.mappingInterce
  * i/s * 100 should never exceed the value of this preference.
  *
  * In order for this preference to have any effect, its value must be
  * greater than 100, since font inflation can never decrease the ratio
  * i/s.
  */
 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.
  * The 'mm' prefs define a rectangle around the nominal event target point within which
  * we will search for suitable elements. 'visitedWeight' is a percentage weight;
  * a value > 100 makes a visited link be treated as further away from the event target
  * than it really is, while a value < 100 makes a visited link be treated as closer
  * to the event target than it really is.