From 16f913ef6088601ae530d78a9ff22bb9c3b60eb8 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Thu, 8 Aug 2019 19:38:35 +0000 Subject: [PATCH] Bug 1511177 - Part 1: Make desktop mode viewport width configurable in GeckoRuntimeSettings. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D40679 --HG-- extra : moz-landing-system : lando --- mobile/android/geckoview/api.txt | 5 ++ .../geckoview/test/NavigationDelegateTest.kt | 24 +++++--- .../geckoview/GeckoRuntimeSettings.java | 55 +++++++++++++++++++ .../geckoview/GeckoSessionSettings.java | 7 ++- .../mozilla/geckoview/doc-files/CHANGELOG.md | 5 +- 5 files changed, 83 insertions(+), 13 deletions(-) diff --git a/mobile/android/geckoview/api.txt b/mobile/android/geckoview/api.txt index 92b2446cc559..24fe3a70c591 100644 --- a/mobile/android/geckoview/api.txt +++ b/mobile/android/geckoview/api.txt @@ -314,6 +314,7 @@ package org.mozilla.geckoview { method public boolean getConsoleOutputEnabled(); method @NonNull public ContentBlocking.Settings getContentBlocking(); method @Nullable public Class getCrashHandler(); + method public int getDesktopViewportWidth(); method @Nullable public Float getDisplayDensityOverride(); method @Nullable public Integer getDisplayDpiOverride(); method public boolean getDoubleTapZoomingEnabled(); @@ -335,6 +336,7 @@ package org.mozilla.geckoview { method @NonNull public GeckoRuntimeSettings setAutomaticFontSizeAdjustment(boolean); method @NonNull public GeckoRuntimeSettings setAutoplayDefault(int); method @NonNull public GeckoRuntimeSettings setConsoleOutputEnabled(boolean); + method @NonNull public GeckoRuntimeSettings setDesktopViewportWidth(int); method @NonNull public GeckoRuntimeSettings setDoubleTapZoomingEnabled(boolean); method @NonNull public GeckoRuntimeSettings setFontInflationEnabled(boolean); method @NonNull public GeckoRuntimeSettings setFontSizeFactor(float); @@ -351,6 +353,8 @@ package org.mozilla.geckoview { field public static final int COLOR_SCHEME_LIGHT = 0; field public static final int COLOR_SCHEME_SYSTEM = -1; field public static final Parcelable.Creator CREATOR; + field public static final int DESKTOP_VIEWPORT_WIDTH_PHONE = 980; + field public static final int DESKTOP_VIEWPORT_WIDTH_TABLET = 1280; } @AnyThread public static final class GeckoRuntimeSettings.Builder extends RuntimeSettings.Builder { @@ -362,6 +366,7 @@ package org.mozilla.geckoview { method @NonNull public GeckoRuntimeSettings.Builder consoleOutput(boolean); method @NonNull public GeckoRuntimeSettings.Builder contentBlocking(@NonNull ContentBlocking.Settings); method @NonNull public GeckoRuntimeSettings.Builder crashHandler(@Nullable Class); + method @NonNull public GeckoRuntimeSettings.Builder desktopViewportWidth(int); method @NonNull public GeckoRuntimeSettings.Builder displayDensityOverride(float); method @NonNull public GeckoRuntimeSettings.Builder displayDpiOverride(int); method @NonNull public GeckoRuntimeSettings.Builder doubleTapZoomingEnabled(boolean); diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt index c9e752e993b2..99bd5f9d2fd2 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt @@ -7,13 +7,7 @@ package org.mozilla.geckoview.test import android.os.Handler import android.os.Looper import android.support.test.InstrumentationRegistry -import org.mozilla.geckoview.AllowOrDeny -import org.mozilla.geckoview.ContentBlocking -import org.mozilla.geckoview.GeckoResult -import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest -import org.mozilla.geckoview.GeckoSessionSettings -import org.mozilla.geckoview.WebRequestError import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate @@ -29,6 +23,7 @@ import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.geckoview.* import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.util.HttpBin import org.mozilla.geckoview.test.util.UiThreadUtils @@ -554,7 +549,8 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(VIEWPORT_PATH) sessionRule.waitForPageStop() - val desktopInnerWidth = 980.0 + val desktopInnerWidthTablet = GeckoRuntimeSettings.DESKTOP_VIEWPORT_WIDTH_TABLET + val desktopInnerWidthPhone = GeckoRuntimeSettings.DESKTOP_VIEWPORT_WIDTH_PHONE val physicalWidth = 600.0 val pixelRatio = sessionRule.session.evaluateJS("window.devicePixelRatio") as Double val mobileInnerWidth = physicalWidth / pixelRatio @@ -565,13 +561,23 @@ class NavigationDelegateTest : BaseSessionTest() { innerWidth, closeTo(mobileInnerWidth, 0.1)) sessionRule.session.settings.viewportMode = GeckoSessionSettings.VIEWPORT_MODE_DESKTOP + sessionRule.runtime.settings.desktopViewportWidth = desktopInnerWidthTablet sessionRule.session.reload() sessionRule.session.waitForPageStop() innerWidth = sessionRule.session.evaluateJS(innerWidthJs) as Double - assertThat("innerWidth should be equal to $desktopInnerWidth", innerWidth, - closeTo(desktopInnerWidth, 0.1)) + assertThat("innerWidth should be equal to $desktopInnerWidthTablet", innerWidth, + closeTo(desktopInnerWidthTablet.toDouble(), 0.1)) + + sessionRule.runtime.settings.desktopViewportWidth = desktopInnerWidthPhone + + sessionRule.session.reload() + sessionRule.session.waitForPageStop() + + innerWidth = sessionRule.session.evaluateJS(innerWidthJs) as Double + assertThat("innerWidth should be equal to $desktopInnerWidthPhone", innerWidth, + closeTo(desktopInnerWidthPhone.toDouble(), 0.1)) sessionRule.session.settings.viewportMode = GeckoSessionSettings.VIEWPORT_MODE_MOBILE 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 9b56db2a4a2d..ab322208a936 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 @@ -375,6 +375,23 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { getSettings().mGlMsaaLevel.set(level); return this; } + + /** + * Set the width of the special desktop mode viewport, which is used for displaying pages + * without a <meta> viewport tag, or for all pages when setting + * {@link GeckoSessionSettings#setViewportMode(int)} to + * {@link GeckoSessionSettings#VIEWPORT_MODE_DESKTOP}. + * + * @param width The width of the desktop mode viewport in CSS px. + * Some common default values are provided by the + * {@link GeckoRuntimeSettings#DESKTOP_VIEWPORT_WIDTH_PHONE + * GeckoRuntimeSettings#DESKTOP_VIEWPORT_WIDTH_*} constants. + * @return This Builder instance. + */ + public @NonNull Builder desktopViewportWidth(final int width) { + getSettings().mDesktopViewportWidth.set(width); + return this; + } } private GeckoRuntime mRuntime; @@ -411,6 +428,8 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { "apz.allow_double_tap_zooming", true); /* package */ final Pref mGlMsaaLevel = new Pref<>( "gl.msaa-level", 0); + /* package */ final Pref mDesktopViewportWidth = new Pref<>( + "browser.viewport.desktopWidth", 980); /* package */ boolean mDebugPause; /* package */ boolean mUseMaxScreenDepth; @@ -979,6 +998,42 @@ public final class GeckoRuntimeSettings extends RuntimeSettings { return this; } + /** + * A desktop mode viewport width appropriate for use on phone-sized devices. + */ + public static final int DESKTOP_VIEWPORT_WIDTH_PHONE = 980; + /** + * A desktop mode viewport width appropriate for use on tablet-sized devices. + */ + public static final int DESKTOP_VIEWPORT_WIDTH_TABLET = 1280; + + /** + * Get the current width of the special desktop mode viewport. + * @return The width of the desktop mode viewport in CSS px. + */ + public int getDesktopViewportWidth() { + return mDesktopViewportWidth.get(); + } + + /** + * Set the width of the special desktop mode viewport, which is used for displaying pages + * without a <meta> viewport tag, or for all pages when setting + * {@link GeckoSessionSettings#setViewportMode(int)} to + * {@link GeckoSessionSettings#VIEWPORT_MODE_DESKTOP}. + * + *

Currently, any changes only take effect after a reload of the session. + * + * @param width The width of the desktop mode viewport in CSS px. + * Some common default values are provided by the + * {@link GeckoRuntimeSettings#DESKTOP_VIEWPORT_WIDTH_PHONE + * GeckoRuntimeSettings#DESKTOP_VIEWPORT_WIDTH_*} constants. + * @return This GeckoRuntimeSettings instance. + */ + public @NonNull GeckoRuntimeSettings setDesktopViewportWidth(final int width) { + mDesktopViewportWidth.commit(width); + return this; + } + @Override // Parcelable public void writeToParcel(final Parcel out, final int flags) { super.writeToParcel(out, flags); diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java index 0235ec160ada..7110d4f2b54d 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java @@ -231,13 +231,14 @@ public final class GeckoSessionSettings implements Parcelable { /** * Mobile-friendly pages will be rendered using a viewport based on their <meta> viewport * tag. All other pages will be rendered using a special desktop mode viewport, which has a - * width of 980 CSS px. + * default width of 980 CSS px. */ public static final int VIEWPORT_MODE_MOBILE = 0; /** - * All pages will be rendered using the special desktop mode viewport, which has a width of - * 980 CSS px, regardless of whether the page has a <meta> viewport tag specified or not. + * All pages will be rendered using the special desktop mode viewport, which has a default width + * of 980 CSS px, regardless of whether the page has a <meta> viewport tag specified or + * not. */ public static final int VIEWPORT_MODE_DESKTOP = 1; 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 ca0e3cdf5ed9..18a04ccd9310 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 @@ -27,6 +27,8 @@ exclude: true [`CrashReporter#sendCrashReport(Context, File, Map, String)`][70.4]. - Add GeckoSession.LOAD_FLAGS_REPLACE_HISTORY - Complete rewrite of [`PromptDelegate`][70.11]. +- Added [`GeckoRuntimeSettings.setDesktopViewportWidth`][70.12] for configuring the desktop mode + viewport width. [70.1]: {{javadoc_uri}}/GeckoSessionSettings.Builder.html#contextId-java.lang.String- [70.2]: {{javadoc_uri}}/StorageController.html#clearDataForSessionContext-java.lang.String- @@ -39,6 +41,7 @@ exclude: true [70.9]: {{javadoc_uri}}/GeckoSession.PromptDelegate.html#onFilePrompt-org.mozilla.geckoview.GeckoSession-java.lang.String-int-java.lang.String:A-int-org.mozilla.geckoview.GeckoSession.PromptDelegate.FileCallback- [70.10]: {{javadoc_uri}}/GeckoView.html#setSession-org.mozilla.geckoview.GeckoSession- [70.11]: {{javadoc_uri}}/GeckoSession.PromptDelegate.html +[70.12]: {{javadoc_uri}}/GeckoRuntimeSettings.html#setDesktopViewportWidth-int- ## v69 - Modified behavior of ['setAutomaticFontSizeAdjustment'][69.1] so that it no @@ -291,4 +294,4 @@ exclude: true [65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String- [65.25]: {{javadoc_uri}}/GeckoResult.html -[api-version]: 4550b507a55bdf91d21960209b66f893f4b5b317 +[api-version]: badc73dc79860a8f69a5e14d7c3725107af68c8e