From faccb486ba1f0a2d616328af3b92a219c6fbaa71 Mon Sep 17 00:00:00 2001 From: Dylan Roeh Date: Thu, 27 Jun 2019 21:50:03 +0000 Subject: [PATCH] Bug 1561135 - Don't automatically enable font inflation when automatic font size adjustment is enabled in GV. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D35819 --HG-- extra : moz-landing-system : lando --- .../org/mozilla/gecko/GeckoApplication.java | 1 + .../geckoview/test/RuntimeSettingsTest.kt | 4 ++-- .../geckoview/GeckoFontScaleListener.java | 8 +------ .../geckoview/GeckoRuntimeSettings.java | 21 +++++-------------- .../mozilla/geckoview/doc-files/CHANGELOG.md | 7 +++++++ 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java index dbd57d72ebc8..f18c879ae994 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java @@ -937,6 +937,7 @@ public class GeckoApplication extends Application if (GeckoPreferences.PREFS_SYSTEM_FONT_SIZE.equals(key)) { final boolean enabled = prefs.getBoolean(GeckoPreferences.PREFS_SYSTEM_FONT_SIZE, false); getRuntime().getSettings().setAutomaticFontSizeAdjustment(enabled); + getRuntime().getSettings().setFontInflationEnabled(enabled); } } } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt index 511cc7ae7d33..f27fb73368b9 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt @@ -41,7 +41,7 @@ class RuntimeSettingsTest : BaseSessionTest() { assertThat("Gecko font scale should match system font scale", settings.fontSizeFactor.toDouble(), closeTo(expectedFontSizeFactor.toDouble(), 0.05)) assertThat("font inflation enabled", - settings.fontInflationEnabled, `is`(true)) + settings.fontInflationEnabled, `is`(initialFontInflation)) settings.automaticFontSizeAdjustment = false assertThat("Gecko font scale restored to previous value", @@ -65,7 +65,7 @@ class RuntimeSettingsTest : BaseSessionTest() { assertThat("Gecko font scale should match system font scale", settings.fontSizeFactor.toDouble(), closeTo(expectedFontSizeFactor.toDouble(), 0.05)) assertThat("font inflation enabled", - settings.fontInflationEnabled, `is`(true)) + settings.fontInflationEnabled, `is`(initialFontInflation)) settings.automaticFontSizeAdjustment = false assertThat("Gecko font scale restored to previous value", diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java index e1edc289313b..4c26bf7dd6f1 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoFontScaleListener.java @@ -18,7 +18,7 @@ import android.support.annotation.UiThread; import android.util.Log; /** - * A class that automatically adjusts font size and font inflation settings for web content in Gecko + * A class that automatically adjusts font size settings for web content in Gecko * in accordance with the device's OS font scale setting. * * @see android.provider.Settings.System#FONT_SCALE @@ -41,7 +41,6 @@ import android.util.Log; private boolean mRunning; private float mPrevGeckoFontScale; - private boolean mPrevFontInflationState; public static GeckoFontScaleListener getInstance() { return sInstance; @@ -131,7 +130,6 @@ import android.util.Log; } mPrevGeckoFontScale = mSettings.getFontSizeFactor(); - mPrevFontInflationState = mSettings.getFontInflationEnabled(); ContentResolver contentResolver = mApplicationContext.getContentResolver(); Uri fontSizeSetting = Settings.System.getUriFor(Settings.System.FONT_SCALE); contentResolver.registerContentObserver(fontSizeSetting, false, this); @@ -155,17 +153,13 @@ import android.util.Log; private void onSystemFontScaleChange(final ContentResolver contentResolver, final boolean stopping) { float fontScale; - boolean fontInflationEnabled; if (!stopping) { // Either we were enabled, or else the system font scale changed. fontScale = Settings.System.getFloat(contentResolver, Settings.System.FONT_SCALE, DEFAULT_FONT_SCALE); - fontInflationEnabled = true; } else { // We were turned off. fontScale = mPrevGeckoFontScale; - fontInflationEnabled = mPrevFontInflationState; } - mSettings.setFontInflationEnabledInternal(fontInflationEnabled); mSettings.setFontSizeFactorInternal(fontScale); } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java index f82683c98b1e..ae01da2601ad 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java @@ -743,10 +743,10 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { /** * Set whether or not font sizes in web content should be automatically scaled according to - * the device's current system font scale setting. - * Disabling this setting will restore the previously used values for - * {@link GeckoRuntimeSettings#getFontSizeFactor()} and - * {@link GeckoRuntimeSettings#getFontInflationEnabled()}. + * the device's current system font scale setting. Enabling this will prevent modification of + * {@link GeckoRuntimeSettings#setFontSizeFactor()}. + * Disabling this setting will restore the previously used value for + * {@link GeckoRuntimeSettings#getFontSizeFactor()}. * * @param enabled A flag determining whether or not font sizes should be scaled automatically * to match the device's system font scale. @@ -835,7 +835,7 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { } final int fontSizePercentage = Math.round(fontSizeFactor * 100); - mFontSizeFactor.commit(Math.round(fontSizePercentage)); + mFontSizeFactor.commit(fontSizePercentage); if (getFontInflationEnabled()) { final int scaledFontInflation = Math.round(FONT_INFLATION_BASE_VALUE * fontSizeFactor); mFontInflationMinTwips.commit(scaledFontInflation); @@ -866,21 +866,10 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { * *

Currently, any changes only take effect after a reload of the session. * - *

This setting cannot be modified while - * {@link GeckoRuntimeSettings#setAutomaticFontSizeAdjustment automatic font size adjustment} - * is enabled. - * * @param enabled A flag determining whether or not font inflation should be enabled. * @return This GeckoRuntimeSettings instance. */ public @NonNull GeckoRuntimeSettings setFontInflationEnabled(final boolean enabled) { - if (getAutomaticFontSizeAdjustment()) { - throw new IllegalStateException("Not allowed when automatic font size adjustment is enabled"); - } - return setFontInflationEnabledInternal(enabled); - } - - /* package */ @NonNull GeckoRuntimeSettings setFontInflationEnabledInternal(final boolean enabled) { final int minTwips = enabled ? Math.round(FONT_INFLATION_BASE_VALUE * getFontSizeFactor()) : 0; mFontInflationMinTwips.commit(minTwips); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md index ea94f25dd08e..ccda0946e974 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md @@ -8,6 +8,13 @@ exclude: true

GeckoView API Changelog.

+## v69 +- Modified behavior of ['setAutomaticFontSizeAdjustment'][69.1] so that it no + longer has any effect on ['setFontInflationEnabled'][69.2] + +[69.1]: ./GeckoRuntimeSettings.html#setAutomaticFontSizeAdjustment-boolean- +[69.2]: ./GeckoRuntimeSettings.html#setFontInflationEnabled-boolean- + ## v68 - Added [`GeckoRuntime#configurationChanged`][68.1] to notify the device configuration has changed.