зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1460874 - Part 11: Allow toggling font scale listener via GeckoRuntimeSettings. r=geckoview-reviewers,snorp
Differential Revision: https://phabricator.services.mozilla.com/D17751 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
7212b5e62f
Коммит
7ba904e7d6
|
@ -207,6 +207,7 @@ package org.mozilla.geckoview {
|
|||
|
||||
@android.support.annotation.AnyThread public final class GeckoRuntimeSettings extends org.mozilla.geckoview.RuntimeSettings {
|
||||
method @android.support.annotation.NonNull public java.lang.String[] getArguments();
|
||||
method public boolean getAutomaticFontSizeAdjustment();
|
||||
method public boolean getConsoleOutputEnabled();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.ContentBlocking.Settings getContentBlocking();
|
||||
method @android.support.annotation.Nullable public java.lang.Class<?> getCrashHandler();
|
||||
|
@ -224,6 +225,7 @@ package org.mozilla.geckoview {
|
|||
method public boolean getUseContentProcessHint();
|
||||
method public boolean getUseMaxScreenDepth();
|
||||
method public boolean getWebFontsEnabled();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setAutomaticFontSizeAdjustment(boolean);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setConsoleOutputEnabled(boolean);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setFontInflationEnabled(boolean);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings setFontSizeFactor(float);
|
||||
|
@ -237,6 +239,7 @@ package org.mozilla.geckoview {
|
|||
@android.support.annotation.AnyThread public static final class GeckoRuntimeSettings.Builder extends org.mozilla.geckoview.RuntimeSettings.Builder<Settings extends org.mozilla.geckoview.RuntimeSettings> {
|
||||
ctor public Builder();
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder arguments(@android.support.annotation.NonNull java.lang.String[]);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder automaticFontSizeAdjustment(boolean);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder consoleOutput(boolean);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder contentBlocking(@android.support.annotation.NonNull org.mozilla.geckoview.ContentBlocking.Settings);
|
||||
method @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoRuntimeSettings.Builder crashHandler(java.lang.Class<?>);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package org.mozilla.geckoview.test
|
||||
|
||||
import android.provider.Settings
|
||||
import android.support.test.InstrumentationRegistry
|
||||
import android.support.test.filters.MediumTest
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import org.hamcrest.Matchers.*
|
||||
|
@ -18,6 +20,58 @@ import kotlin.math.roundToInt
|
|||
@ReuseSession(false)
|
||||
class RuntimeSettingsTest : BaseSessionTest() {
|
||||
|
||||
@Test fun automaticFontSize() {
|
||||
val settings = sessionRule.runtime.settings
|
||||
var initialFontSize = 2.15f
|
||||
var initialFontInflation = true
|
||||
settings.fontSizeFactor = initialFontSize
|
||||
assertThat("initial font scale $initialFontSize set",
|
||||
settings.fontSizeFactor.toDouble(), closeTo(initialFontSize.toDouble(), 0.05))
|
||||
settings.fontInflationEnabled = initialFontInflation
|
||||
assertThat("font inflation initially set to $initialFontInflation",
|
||||
settings.fontInflationEnabled, `is`(initialFontInflation))
|
||||
|
||||
|
||||
settings.automaticFontSizeAdjustment = true
|
||||
val contentResolver = InstrumentationRegistry.getTargetContext().contentResolver
|
||||
val expectedFontSizeFactor = Settings.System.getFloat(contentResolver,
|
||||
Settings.System.FONT_SCALE, 1.0f)
|
||||
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.automaticFontSizeAdjustment = false
|
||||
assertThat("Gecko font scale restored to previous value",
|
||||
settings.fontSizeFactor.toDouble(), closeTo(initialFontSize.toDouble(), 0.05))
|
||||
assertThat("font inflation restored to previous value",
|
||||
settings.fontInflationEnabled, `is`(initialFontInflation))
|
||||
|
||||
// Now check with that with font inflation initially off, the initial state is still
|
||||
// restored correctly after switching auto mode back off.
|
||||
// Also reset font size factor back to its default value of 1.0f.
|
||||
initialFontSize = 1.0f
|
||||
initialFontInflation = false
|
||||
settings.fontSizeFactor = initialFontSize
|
||||
assertThat("initial font scale $initialFontSize set",
|
||||
settings.fontSizeFactor.toDouble(), closeTo(initialFontSize.toDouble(), 0.05))
|
||||
settings.fontInflationEnabled = initialFontInflation
|
||||
assertThat("font inflation initially set to $initialFontInflation",
|
||||
settings.fontInflationEnabled, `is`(initialFontInflation))
|
||||
|
||||
settings.automaticFontSizeAdjustment = true
|
||||
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.automaticFontSizeAdjustment = false
|
||||
assertThat("Gecko font scale restored to previous value",
|
||||
settings.fontSizeFactor.toDouble(), closeTo(initialFontSize.toDouble(), 0.05))
|
||||
assertThat("font inflation restored to previous value",
|
||||
settings.fontInflationEnabled, `is`(initialFontInflation))
|
||||
}
|
||||
|
||||
@WithDevToolsAPI
|
||||
@Test fun fontSize() {
|
||||
val settings = sessionRule.runtime.settings
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoFontScaleListener;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
|
||||
@AnyThread
|
||||
|
@ -154,6 +155,19 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not font sizes in web content should be automatically scaled according to
|
||||
* the device's current system font scale setting.
|
||||
*
|
||||
* @param enabled A flag determining whether or not font sizes should be scaled automatically
|
||||
* to match the device's system font scale.
|
||||
* @return The builder instance.
|
||||
*/
|
||||
public @NonNull Builder automaticFontSizeAdjustment(boolean enabled) {
|
||||
getSettings().setAutomaticFontSizeAdjustment(enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a font size factor that will operate as a global text zoom. All font sizes will be
|
||||
* multiplied by this factor.
|
||||
|
@ -566,6 +580,32 @@ public final class GeckoRuntimeSettings extends RuntimeSettings {
|
|||
return mConsoleOutput.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()}.
|
||||
*
|
||||
* @param enabled A flag determining whether or not font sizes should be scaled automatically
|
||||
* to match the device's system font scale.
|
||||
* @return This GeckoRuntimeSettings instance.
|
||||
*/
|
||||
public @NonNull GeckoRuntimeSettings setAutomaticFontSizeAdjustment(boolean enabled) {
|
||||
GeckoFontScaleListener.getInstance().setEnabled(enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not the font sizes for web content are automatically adjusted to match the
|
||||
* device's system font scale setting.
|
||||
*
|
||||
* @return True if font sizes are automatically adjusted.
|
||||
*/
|
||||
public boolean getAutomaticFontSizeAdjustment() {
|
||||
return GeckoFontScaleListener.getInstance().getEnabled();
|
||||
}
|
||||
|
||||
private static int FONT_INFLATION_BASE_VALUE = 120;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,9 @@ exclude: true
|
|||
<h1> GeckoView API Changelog. </h1>
|
||||
|
||||
## v67
|
||||
- Added GeckoRuntimeSetting for automatically adjusting font size settings
|
||||
depending on the OS-level font size setting.
|
||||
|
||||
- Added GeckoRuntimeSettings for setting a font size scaling factor, and for
|
||||
enabling font inflation for non-mobile-friendly pages.
|
||||
|
||||
|
@ -131,4 +134,4 @@ exclude: true
|
|||
[65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
|
||||
[65.25]: ../GeckoResult.html
|
||||
|
||||
[api-version]: 1f30cea0011654a414fd9bad35dd340ffc56c6e2
|
||||
[api-version]: fc7356566f3eb780127a4dbc135810a883a0e650
|
||||
|
|
Загрузка…
Ссылка в новой задаче