Skip to content

Commit

Permalink
browser(firefox-stable): added reduced motion emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed May 18, 2021
1 parent a122aff commit cb65fb8
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 15 deletions.
4 changes: 2 additions & 2 deletions browser_patches/firefox-stable/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1253
Changed: aslushnikov@gmail.com Fri 14 May 2021 21:37:19 PM PDT
1254
Changed: max@schmitt.mx Di 18. Mai 21:21:37 CEST 2021
24 changes: 24 additions & 0 deletions browser_patches/firefox-stable/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class TargetRegistry {
target.updateUserAgent();
target.updateTouchOverride();
target.updateColorSchemeOverride();
target.updateReducedMotionOverride();
if (!hasExplicitSize)
target.updateViewportSize();
if (browserContext.videoRecordingOptions)
Expand Down Expand Up @@ -437,6 +438,14 @@ class PageTarget {
this._linkedBrowser.browsingContext.prefersColorSchemeOverride = this.colorScheme || this._browserContext.colorScheme || 'none';
}

setReducedMotion(reducedMotion) {
this.reducedMotion = fromProtocolReducedMotion(reducedMotion);
this.updateReducedMotionOverride();
}

updateReducedMotionOverride() {
this._linkedBrowser.browsingContext.prefersReducedMotionOverride = this.reducedMotion || this._browserContext.reducedMotion || 'none';
}

async setViewportSize(viewportSize) {
this._viewportSize = viewportSize;
Expand Down Expand Up @@ -612,6 +621,14 @@ function fromProtocolColorScheme(colorScheme) {
throw new Error('Unknown color scheme: ' + colorScheme);
}

function fromProtocolReducedMotion(reducedMotion) {
if (reducedMotion === 'reduce')
return reducedMotion;
if (reducedMotion === null || reducedMotion === 'no-preference')
return undefined;
throw new Error('Unknown reduced motion: ' + reducedMotion);
}

class BrowserContext {
constructor(registry, browserContextId, removeOnDetach) {
this._registry = registry;
Expand Down Expand Up @@ -639,6 +656,7 @@ class BrowserContext {
this.defaultUserAgent = null;
this.touchOverride = false;
this.colorScheme = 'none';
this.reducedMotion = 'none';
this.videoRecordingOptions = undefined;
this.scriptsToEvaluateOnNewDocument = [];
this.bindings = [];
Expand All @@ -652,6 +670,12 @@ class BrowserContext {
page.updateColorSchemeOverride();
}

setReducedMotion(reducedMotion) {
this.reducedMotion = fromProtocolReducedMotion(reducedMotion);
for (const page of this.pages)
page.updateReducedMotionOverride();
}

async destroy() {
if (this.userContextId !== 0) {
ContextualIdentityService.remove(this.userContextId);
Expand Down
4 changes: 4 additions & 0 deletions browser_patches/firefox-stable/juggler/content/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const applySetting = {
colorScheme: (colorScheme) => {
frameTree.setColorScheme(colorScheme);
},

reducedMotion: (reducedMotion) => {
frameTree.setReducedMotion(reducedMotion);
},
};

const channel = SimpleChannel.createForMessageManager('content::page', messageManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class BrowserHandler {
await this._targetRegistry.browserContextForId(browserContextId).setColorScheme(nullToUndefined(colorScheme));
}

async ['Browser.setReducedMotion']({browserContextId, reducedMotion}) {
await this._targetRegistry.browserContextForId(browserContextId).setReducedMotion(nullToUndefined(reducedMotion));
}

async ['Browser.setVideoRecordingOptions']({browserContextId, dir, width, height, scale}) {
await this._targetRegistry.browserContextForId(browserContextId).setVideoRecordingOptions({dir, width, height, scale});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ class PageHandler {
return await this._contentPage.send('setFileInputFiles', options);
}

async ['Page.setEmulatedMedia']({colorScheme, type}) {
async ['Page.setEmulatedMedia']({colorScheme, type, reducedMotion}) {
this._pageTarget.setColorScheme(colorScheme || null);
this._pageTarget.setReducedMotion(reducedMotion || null);
this._pageTarget.setEmulatedMedia(type);
}

Expand Down
7 changes: 7 additions & 0 deletions browser_patches/firefox-stable/juggler/protocol/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ const Browser = {
colorScheme: t.Nullable(t.Enum(['dark', 'light', 'no-preference'])),
},
},
'setReducedMotion': {
params: {
browserContextId: t.Optional(t.String),
reducedMotion: t.Nullable(t.Enum(['reduce', 'no-preference'])),
},
},
'setVideoRecordingOptions': {
params: {
browserContextId: t.Optional(t.String),
Expand Down Expand Up @@ -748,6 +754,7 @@ const Page = {
params: {
type: t.Optional(t.Enum(['screen', 'print', ''])),
colorScheme: t.Optional(t.Enum(['dark', 'light', 'no-preference'])),
reducedMotion: t.Optional(t.Enum(['reduce', 'no-preference'])),
},
},
'setCacheDisabled': {
Expand Down
Loading

0 comments on commit cb65fb8

Please sign in to comment.