Bug 1523692 - Set the prefers-reduce-motion value for test to the instance of nsLookAndFeel in child processes. r=snorp

So that we can query the test value in the child process properly.

Note that the APIs used for setting the prefers-reduced-motion value for testing
are only used on Android and MacOSX.  As for MacOSX we have a different
machinery (see bug 1486971) to deliver the test value without spinning native
event loop in the child process so the change here is valid only for Android.

Differential Revision: https://phabricator.services.mozilla.com/D18311
This commit is contained in:
Hiroyuki Ikezoe
2019-02-01 22:07:26 +00:00
parent 8c057ab512
commit f0c3fac208
6 changed files with 28 additions and 29 deletions

View File

@@ -28,6 +28,7 @@
#include "nsIWidgetListener.h" #include "nsIWidgetListener.h"
#include "imgIContainer.h" #include "imgIContainer.h"
#include "nsView.h" #include "nsView.h"
#include "nsXPLookAndFeel.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
using namespace mozilla; using namespace mozilla;
@@ -903,10 +904,8 @@ struct CursorSurface {
IntSize mSize; IntSize mSize;
}; };
void PuppetWidget::SetCursor(nsCursor aCursor, void PuppetWidget::SetCursor(nsCursor aCursor, imgIContainer* aCursorImage,
imgIContainer* aCursorImage, uint32_t aHotspotX, uint32_t aHotspotY) {
uint32_t aHotspotX,
uint32_t aHotspotY) {
if (!mTabChild) { if (!mTabChild) {
return; return;
} }
@@ -945,7 +944,8 @@ void PuppetWidget::SetCursor(nsCursor aCursor,
mCustomCursor = nullptr; mCustomCursor = nullptr;
nsDependentCString cursorData(customCursorData ? customCursorData.get() : "", length); nsDependentCString cursorData(customCursorData ? customCursorData.get() : "",
length);
if (!mTabChild->SendSetCursor(aCursor, hasCustomCursor, cursorData, if (!mTabChild->SendSetCursor(aCursor, hasCustomCursor, cursorData,
customCursorSize.width, customCursorSize.height, customCursorSize.width, customCursorSize.height,
stride, format, aHotspotX, aHotspotY, force)) { stride, format, aHotspotX, aHotspotY, force)) {
@@ -1409,6 +1409,9 @@ nsresult PuppetWidget::SetPrefersReducedMotionOverrideForTest(bool aValue) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsXPLookAndFeel::GetInstance()->SetPrefersReducedMotionOverrideForTest(
aValue);
mTabChild->SendSetPrefersReducedMotionOverrideForTest(aValue); mTabChild->SendSetPrefersReducedMotionOverrideForTest(aValue);
return NS_OK; return NS_OK;
} }
@@ -1418,6 +1421,7 @@ nsresult PuppetWidget::ResetPrefersReducedMotionOverrideForTest() {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsXPLookAndFeel::GetInstance()->ResetPrefersReducedMotionOverrideForTest();
mTabChild->SendResetPrefersReducedMotionOverrideForTest(); mTabChild->SendResetPrefersReducedMotionOverrideForTest();
return NS_OK; return NS_OK;
} }

View File

@@ -21,9 +21,6 @@ AndroidSystemColors nsLookAndFeel::mSystemColors;
bool nsLookAndFeel::mInitializedShowPassword = false; bool nsLookAndFeel::mInitializedShowPassword = false;
bool nsLookAndFeel::mShowPassword = true; bool nsLookAndFeel::mShowPassword = true;
bool nsLookAndFeel::mIsInPrefersReducedMotionForTest = false;
bool nsLookAndFeel::mPrefersReducedMotionForTest = false;
static const char16_t UNICODE_BULLET = 0x2022; static const char16_t UNICODE_BULLET = 0x2022;
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() {} nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() {}
@@ -389,8 +386,8 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
break; break;
case eIntID_PrefersReducedMotion: case eIntID_PrefersReducedMotion:
if (mIsInPrefersReducedMotionForTest) { if (sIsInPrefersReducedMotionForTest) {
aResult = mPrefersReducedMotionForTest ? 1 : 0; aResult = sPrefersReducedMotionForTest ? 1 : 0;
break; break;
} }
aResult = java::GeckoSystemStateListener::PrefersReducedMotion() ? 1 : 0; aResult = java::GeckoSystemStateListener::PrefersReducedMotion() ? 1 : 0;

View File

@@ -27,22 +27,11 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
virtual void SetIntCacheImpl( virtual void SetIntCacheImpl(
const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override; const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
void SetPrefersReducedMotionOverrideForTest(bool aValue) {
mIsInPrefersReducedMotionForTest = true;
mPrefersReducedMotionForTest = aValue;
}
void ResetPrefersReducedMotionOverrideForTest() {
mIsInPrefersReducedMotionForTest = false;
mPrefersReducedMotionForTest = false;
}
protected: protected:
static bool mInitializedSystemColors; static bool mInitializedSystemColors;
static mozilla::AndroidSystemColors mSystemColors; static mozilla::AndroidSystemColors mSystemColors;
static bool mInitializedShowPassword; static bool mInitializedShowPassword;
static bool mShowPassword; static bool mShowPassword;
static bool mIsInPrefersReducedMotionForTest;
static bool mPrefersReducedMotionForTest;
nsresult GetSystemColors(); nsresult GetSystemColors();

View File

@@ -2186,20 +2186,15 @@ void nsWindow::RecvScreenPixels(Shmem&& aMem, const ScreenIntSize& aSize) {
} }
nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) { nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) {
nsXPLookAndFeel* xpLookAndFeel = nsLookAndFeel::GetInstance(); nsXPLookAndFeel::GetInstance()->SetPrefersReducedMotionOverrideForTest(
aValue);
static_cast<nsLookAndFeel*>(xpLookAndFeel)
->SetPrefersReducedMotionOverrideForTest(aValue);
java::GeckoSystemStateListener::NotifyPrefersReducedMotionChangedForTest(); java::GeckoSystemStateListener::NotifyPrefersReducedMotionChangedForTest();
return NS_OK; return NS_OK;
} }
nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() { nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() {
nsXPLookAndFeel* xpLookAndFeel = nsLookAndFeel::GetInstance(); nsXPLookAndFeel::GetInstance()->ResetPrefersReducedMotionOverrideForTest();
static_cast<nsLookAndFeel*>(xpLookAndFeel)
->ResetPrefersReducedMotionOverrideForTest();
return NS_OK; return NS_OK;
} }

View File

@@ -216,6 +216,8 @@ bool nsXPLookAndFeel::sInitialized = false;
bool nsXPLookAndFeel::sUseNativeColors = true; bool nsXPLookAndFeel::sUseNativeColors = true;
bool nsXPLookAndFeel::sUseStandinsForNativeColors = false; bool nsXPLookAndFeel::sUseStandinsForNativeColors = false;
bool nsXPLookAndFeel::sFindbarModalHighlight = false; bool nsXPLookAndFeel::sFindbarModalHighlight = false;
bool nsXPLookAndFeel::sIsInPrefersReducedMotionForTest = false;
bool nsXPLookAndFeel::sPrefersReducedMotionForTest = false;
nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nullptr; nsXPLookAndFeel* nsXPLookAndFeel::sInstance = nullptr;
bool nsXPLookAndFeel::sShutdown = false; bool nsXPLookAndFeel::sShutdown = false;

View File

@@ -80,6 +80,15 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
virtual void NativeInit() = 0; virtual void NativeInit() = 0;
void SetPrefersReducedMotionOverrideForTest(bool aValue) {
sIsInPrefersReducedMotionForTest = true;
sPrefersReducedMotionForTest = aValue;
}
void ResetPrefersReducedMotionOverrideForTest() {
sIsInPrefersReducedMotionForTest = false;
sPrefersReducedMotionForTest = false;
}
protected: protected:
nsXPLookAndFeel(); nsXPLookAndFeel();
@@ -112,6 +121,9 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
static nsXPLookAndFeel* sInstance; static nsXPLookAndFeel* sInstance;
static bool sShutdown; static bool sShutdown;
static bool sIsInPrefersReducedMotionForTest;
static bool sPrefersReducedMotionForTest;
// True if we shouldn't clear the cache value in RefreshImpl(). // True if we shouldn't clear the cache value in RefreshImpl().
// NOTE: This should be used only for testing. // NOTE: This should be used only for testing.
bool mShouldRetainCacheForTest; bool mShouldRetainCacheForTest;