mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1532850 - Implement the backend for prefers-color-scheme on Android. r=geckoview-reviewers,snorp
Differential Revision: https://phabricator.services.mozilla.com/D22272 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f5a86384ed
commit
36b25f6fb1
@ -58,7 +58,7 @@
|
||||
android:label="@string/moz_app_displayname"
|
||||
android:taskAffinity="@ANDROID_PACKAGE_NAME@.BROWSER"
|
||||
android:alwaysRetainTaskState="true"
|
||||
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
|
||||
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout|uiMode"
|
||||
android:resizeableActivity="true"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:windowSoftInputMode="stateUnspecified|adjustResize"
|
||||
@ -352,7 +352,7 @@
|
||||
</activity>
|
||||
|
||||
<activity android:name="org.mozilla.gecko.customtabs.CustomTabsActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
|
||||
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout|uiMode"
|
||||
android:windowSoftInputMode="stateUnspecified|adjustResize"
|
||||
android:theme="@style/GeckoCustomTabs" />
|
||||
|
||||
|
@ -177,6 +177,7 @@ package org.mozilla.geckoview {
|
||||
public final class GeckoRuntime implements android.os.Parcelable {
|
||||
ctor public GeckoRuntime();
|
||||
method @android.support.annotation.UiThread public void attachTo(@android.support.annotation.NonNull android.content.Context);
|
||||
method @android.support.annotation.UiThread public void configurationChanged(@android.support.annotation.NonNull android.content.res.Configuration);
|
||||
method @android.support.annotation.UiThread @android.support.annotation.NonNull public static org.mozilla.geckoview.GeckoRuntime create(@android.support.annotation.NonNull android.content.Context);
|
||||
method @android.support.annotation.UiThread @android.support.annotation.NonNull public static org.mozilla.geckoview.GeckoRuntime create(@android.support.annotation.NonNull android.content.Context, @android.support.annotation.NonNull org.mozilla.geckoview.GeckoRuntimeSettings);
|
||||
method @android.support.annotation.UiThread @android.support.annotation.NonNull public static synchronized org.mozilla.geckoview.GeckoRuntime getDefault(@android.support.annotation.NonNull android.content.Context);
|
||||
|
@ -7,6 +7,7 @@ package org.mozilla.gecko;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.net.Uri;
|
||||
@ -31,6 +32,7 @@ public class GeckoSystemStateListener
|
||||
private ContentObserver mContentObserver;
|
||||
private static Context sApplicationContext;
|
||||
private InputManager mInputManager;
|
||||
private static boolean sIsNightMode;
|
||||
|
||||
public static GeckoSystemStateListener getInstance() {
|
||||
return listenerInstance;
|
||||
@ -59,6 +61,9 @@ public class GeckoSystemStateListener
|
||||
};
|
||||
contentResolver.registerContentObserver(animationSetting, false, mContentObserver);
|
||||
|
||||
sIsNightMode = (sApplicationContext.getResources().getConfiguration().uiMode &
|
||||
Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
@ -109,6 +114,24 @@ public class GeckoSystemStateListener
|
||||
contentResolver.notifyChange(animationSetting, null);
|
||||
}
|
||||
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
/**
|
||||
* For prefers-color-scheme media queries feature.
|
||||
*/
|
||||
private static boolean isNightMode() {
|
||||
return sIsNightMode;
|
||||
}
|
||||
|
||||
public void updateNightMode(final int newUIMode) {
|
||||
boolean isNightMode = (newUIMode & Configuration.UI_MODE_NIGHT_MASK)
|
||||
== Configuration.UI_MODE_NIGHT_YES;
|
||||
if (isNightMode == sIsNightMode) {
|
||||
return;
|
||||
}
|
||||
sIsNightMode = isNightMode;
|
||||
onDeviceChanged();
|
||||
}
|
||||
|
||||
@WrapForJNI(stubName = "OnDeviceChanged", calledFrom = "ui", dispatchTo = "gecko")
|
||||
private static native void nativeOnDeviceChanged();
|
||||
|
||||
|
@ -11,6 +11,7 @@ import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@ -433,6 +434,17 @@ public final class GeckoRuntime implements Parcelable {
|
||||
GeckoScreenOrientation.getInstance().update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Gecko that the device configuration has changed.
|
||||
* @param newConfig The new Configuration object,
|
||||
* {@link android.content.res.Configuration}.
|
||||
*/
|
||||
@UiThread
|
||||
public void configurationChanged(final @NonNull Configuration newConfig) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
GeckoSystemStateListener.getInstance().updateNightMode(newConfig.uiMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify Gecko that the screen orientation has changed.
|
||||
* @param newOrientation The new screen orientation, as retrieved e.g. from the current
|
||||
|
@ -465,6 +465,7 @@ public class GeckoView extends FrameLayout {
|
||||
// we will miss such rotations and the screen orientation will not be
|
||||
// updated.
|
||||
mRuntime.orientationChanged(newConfig.orientation);
|
||||
mRuntime.configurationChanged(newConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,12 @@ exclude: true
|
||||
|
||||
<h1> GeckoView API Changelog. </h1>
|
||||
|
||||
## v68
|
||||
- Added [`GeckoRuntime#configurationChanged`][68.1] to notify the device
|
||||
configuration has changed.
|
||||
|
||||
[68.1]: ../GeckoRuntime.html#configurationChanged
|
||||
|
||||
## v67
|
||||
- Added [`setAutomaticFontSizeAdjustment`][67.2] to
|
||||
[`GeckoRuntimeSettings`][67.3] for automatically adjusting font size settings
|
||||
@ -209,4 +215,4 @@ exclude: true
|
||||
[65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
|
||||
[65.25]: ../GeckoResult.html
|
||||
|
||||
[api-version]: 09c473360eb5e17aa801fa0f966cd8671cf2f3d2
|
||||
[api-version]: e1330c0e7cfa08420041813f07f24a9389020564
|
||||
|
@ -400,6 +400,16 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
|
||||
aResult = java::GeckoAppShell::GetAllPointerCapabilities();
|
||||
break;
|
||||
|
||||
case eIntID_SystemUsesDarkTheme:
|
||||
// Bail out if AndroidBridge hasn't initialized since we try to query
|
||||
// this vailue via nsMediaFeatures::InitSystemMetrics without initializing
|
||||
// AndroidBridge on xpcshell tests.
|
||||
if (!jni::IsAvailable()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aResult = java::GeckoSystemStateListener::IsNightMode() ? 1 : 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
aResult = 0;
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
Loading…
Reference in New Issue
Block a user