Skip to content

Commit 4853b34

Browse files
flamedddDevtools-frontend LUCI CQ
authored andcommitted
Add Rendering Shortcuts section in setting for Toggle force Css
preference color shortcut feature This CL 1. Add "Rendering" Shortcuts section in setting. 2. Add 'Toggle forces CSS prefers-color-scheme color' shortcut feature. User able to set shortcut, to use it to toggle CSS prefer color scheme How to test: (video record covered all steps) 1. Go to https://twitter.com/ 2. Open devtools -> Settings -> Experiments -> filter "key" word -> enable "Enable keyboard shortcut editor" 3. Reload devtools 4. Go to devtools Settings -> Shortcuts -> find "Rendings" secion -> set "Toggle force CSS ..." shortcut 5. Execute shortcut and check twitter's UI screenshots: - https://imgur.com/a/GCeyVB2 video record - https://youtu.be/Mx9gqvIzIzU Bug: 1280398 Change-Id: I9f69a46705d167bc1e1a17f8bfbe3582af8468aa Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3614398 Commit-Queue: Changhao Han <changhaohan@chromium.org> Reviewed-by: Mathias Bynens <mathias@chromium.org> Reviewed-by: Changhao Han <changhaohan@chromium.org>
1 parent ecf2a20 commit 4853b34

6 files changed

Lines changed: 55 additions & 1 deletion

File tree

front_end/core/host/UserMetrics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ export enum KeyboardShortcutAction {
549549
'layers.left' = 104,
550550
'layers.right' = 105,
551551
'help.report-translation-issue' = 106,
552-
MaxValue = 107,
552+
'rendering.toggle-prefers-color-scheme' = 107,
553+
MaxValue = 108,
553554
}
554555
/* eslint-enable @typescript-eslint/naming-convention */
555556

front_end/core/i18n/locales/en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@
899899
"entrypoints/inspector_main/inspector_main-meta.ts | showRendering": {
900900
"message": "Show Rendering"
901901
},
902+
"entrypoints/inspector_main/inspector_main-meta.ts | toggleCssPrefersColorSchemeMedia": {
903+
"message": "Toggle forces CSS prefers-color-scheme color"
904+
},
902905
"entrypoints/inspector_main/inspector_main-meta.ts | visionDeficiency": {
903906
"message": "vision deficiency"
904907
},

front_end/core/i18n/locales/en-XL.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@
899899
"entrypoints/inspector_main/inspector_main-meta.ts | showRendering": {
900900
"message": "Ŝh́ôẃ R̂én̂d́êŕîńĝ"
901901
},
902+
"entrypoints/inspector_main/inspector_main-meta.ts | toggleCssPrefersColorSchemeMedia": {
903+
"message": "T̂óĝǵl̂é f̂ór̂ćêś ĈŚŜ ṕr̂éf̂ér̂ś-ĉól̂ór̂-śĉh́êḿê ćôĺôŕ"
904+
},
902905
"entrypoints/inspector_main/inspector_main-meta.ts | visionDeficiency": {
903906
"message": "v̂íŝíôń d̂éf̂íĉíêńĉý"
904907
},

front_end/entrypoints/inspector_main/RenderingOptions.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,34 @@ export class RenderingOptionsView extends UI.Widget.VBox {
346346
this.registerCSSFiles([renderingOptionsStyles]);
347347
}
348348
}
349+
350+
let reloadActionDelegateInstance: ReloadActionDelegate;
351+
352+
export class ReloadActionDelegate implements UI.ActionRegistration.ActionDelegate {
353+
static instance(opts: {
354+
forceNew: boolean|null,
355+
} = {forceNew: null}): ReloadActionDelegate {
356+
const {forceNew} = opts;
357+
if (!reloadActionDelegateInstance || forceNew) {
358+
reloadActionDelegateInstance = new ReloadActionDelegate();
359+
}
360+
361+
return reloadActionDelegateInstance;
362+
}
363+
364+
handleAction(context: UI.Context.Context, actionId: string): boolean {
365+
const emulatedCSSMediaFeaturePrefersColorSchemeSetting =
366+
Common.Settings.Settings.instance().moduleSetting('emulatedCSSMediaFeaturePrefersColorScheme');
367+
368+
switch (actionId) {
369+
case 'rendering.toggle-prefers-color-scheme':
370+
if (emulatedCSSMediaFeaturePrefersColorSchemeSetting.get() === 'light') {
371+
emulatedCSSMediaFeaturePrefersColorSchemeSetting.set('dark');
372+
} else {
373+
emulatedCSSMediaFeaturePrefersColorSchemeSetting.set('light');
374+
}
375+
return true;
376+
}
377+
return false;
378+
}
379+
}

front_end/entrypoints/inspector_main/inspector_main-meta.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ const UIStrings = {
9999
* setting turns off this overlay.
100100
*/
101101
disablePaused: 'Disable paused state overlay',
102+
/**
103+
* @description Title of an action that toggle
104+
* "forces CSS prefers-color-scheme" color
105+
*/
106+
toggleCssPrefersColorSchemeMedia: 'Toggle forces CSS prefers-color-scheme color',
102107
};
103108
const str_ = i18n.i18n.registerUIStrings('entrypoints/inspector_main/inspector_main-meta.ts', UIStrings);
104109
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
@@ -191,6 +196,16 @@ UI.ActionRegistration.registerActionExtension({
191196
],
192197
});
193198

199+
UI.ActionRegistration.registerActionExtension({
200+
actionId: 'rendering.toggle-prefers-color-scheme',
201+
category: UI.ActionRegistration.ActionCategory.RENDERING,
202+
title: i18nLazyString(UIStrings.toggleCssPrefersColorSchemeMedia),
203+
async loadActionDelegate() {
204+
const InspectorMain = await loadInspectorMainModule();
205+
return InspectorMain.RenderingOptions.ReloadActionDelegate.instance();
206+
},
207+
});
208+
194209
Common.Settings.registerSettingExtension({
195210
category: Common.Settings.SettingCategory.NETWORK,
196211
title: i18nLazyString(UIStrings.forceAdBlocking),

front_end/ui/legacy/ActionRegistration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export const ActionCategory = {
212212
SETTINGS: 'Settings',
213213
DEBUGGER: 'Debugger',
214214
SOURCES: 'Sources',
215+
RENDERING: 'Rendering',
215216
};
216217

217218
type ActionCategory = typeof ActionCategory[keyof typeof ActionCategory];

0 commit comments

Comments
 (0)