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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Hiroyuki Ikezoe 2019-02-01 22:07:26 +00:00
parent 0706706c4e
commit b8cb200990
6 changed files with 28 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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