Skip to content

Commit f6929e1

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Substitutions for registered property references
Drive-by: Do not show the icon when there is just a single row Bug: 396080529 Change-Id: Idcfdf7e756f4587281f00fd5ebdfeee16b26e184 Fixed: 404536541 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6368842 Auto-Submit: Philip Pfaffe <[email protected]> Reviewed-by: Eric Leese <[email protected]> Commit-Queue: Philip Pfaffe <[email protected]>
1 parent 061a8ff commit f6929e1

File tree

8 files changed

+97
-72
lines changed

8 files changed

+97
-72
lines changed

front_end/core/sdk/CSSMatchedStyles.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,30 @@ import {CSSMetadata, cssMetadata, CSSWideKeyword} from './CSSMetadata.js';
99
import type {CSSModel} from './CSSModel.js';
1010
import {CSSProperty} from './CSSProperty.js';
1111
import * as PropertyParser from './CSSPropertyParser.js';
12-
import {BaseVariableMatcher} from './CSSPropertyParserMatchers.js';
12+
import type {Match, Matcher} from './CSSPropertyParser.js';
13+
import {
14+
AnchorFunctionMatcher,
15+
AngleMatcher,
16+
AutoBaseMatcher,
17+
BaseVariableMatcher,
18+
BezierMatcher,
19+
BinOpMatcher,
20+
ColorMatcher,
21+
ColorMixMatcher,
22+
FlexGridMatcher,
23+
GridTemplateMatcher,
24+
LengthMatcher,
25+
LightDarkColorMatcher,
26+
LinearGradientMatcher,
27+
LinkableNameMatcher,
28+
MathFunctionMatcher,
29+
PositionAnchorMatcher,
30+
PositionTryMatcher,
31+
ShadowMatcher,
32+
StringMatcher,
33+
URLMatcher,
34+
VariableMatcher
35+
} from './CSSPropertyParserMatchers.js';
1336
import {
1437
CSSFontPaletteValuesRule,
1538
CSSKeyframesRule,
@@ -212,6 +235,17 @@ export class CSSRegisteredProperty {
212235
`"${this.#registration.syntax}"`;
213236
}
214237

238+
parseValue(matchedStyles: CSSMatchedStyles, computedStyles: Map<string, string>|null):
239+
PropertyParser.BottomUpTreeMatching|null {
240+
const value = this.initialValue();
241+
if (!value) {
242+
return null;
243+
}
244+
245+
return PropertyParser.matchDeclaration(
246+
this.propertyName(), value, matchedStyles.propertyMatchers(this.style(), computedStyles));
247+
}
248+
215249
#asCSSProperties(): Protocol.CSS.CSSProperty[] {
216250
if (this.#registration instanceof CSSPropertyRule) {
217251
return [];
@@ -808,6 +842,31 @@ export class CSSMatchedStyles {
808842
domCascade.reset();
809843
}
810844
}
845+
846+
propertyMatchers(style: CSSStyleDeclaration, computedStyles: Map<string, string>|null): Array<Matcher<Match>> {
847+
return [
848+
new VariableMatcher(this, style),
849+
new ColorMatcher(() => computedStyles?.get('color') ?? null),
850+
new ColorMixMatcher(),
851+
new URLMatcher(),
852+
new AngleMatcher(),
853+
new LinkableNameMatcher(),
854+
new BezierMatcher(),
855+
new StringMatcher(),
856+
new ShadowMatcher(),
857+
new LightDarkColorMatcher(style),
858+
new GridTemplateMatcher(),
859+
new LinearGradientMatcher(),
860+
new AnchorFunctionMatcher(),
861+
new PositionAnchorMatcher(),
862+
new FlexGridMatcher(),
863+
new PositionTryMatcher(),
864+
new LengthMatcher(),
865+
new MathFunctionMatcher(),
866+
new AutoBaseMatcher(),
867+
new BinOpMatcher(),
868+
];
869+
}
811870
}
812871

813872
class NodeCascade {

front_end/core/sdk/CSSProperty.ts

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,7 @@ import {
1919
type Matcher,
2020
stripComments
2121
} from './CSSPropertyParser.js';
22-
import {
23-
AnchorFunctionMatcher,
24-
AngleMatcher,
25-
AutoBaseMatcher,
26-
BezierMatcher,
27-
BinOpMatcher,
28-
ColorMatcher,
29-
ColorMixMatcher,
30-
CSSWideKeywordMatcher,
31-
FlexGridMatcher,
32-
FontMatcher,
33-
GridTemplateMatcher,
34-
LengthMatcher,
35-
LightDarkColorMatcher,
36-
LinearGradientMatcher,
37-
LinkableNameMatcher,
38-
MathFunctionMatcher,
39-
PositionAnchorMatcher,
40-
PositionTryMatcher,
41-
ShadowMatcher,
42-
StringMatcher,
43-
URLMatcher,
44-
VariableMatcher
45-
} from './CSSPropertyParserMatchers.js';
22+
import {CSSWideKeywordMatcher, FontMatcher} from './CSSPropertyParserMatchers.js';
4623
import type {CSSStyleDeclaration} from './CSSStyleDeclaration.js';
4724

4825
export const enum Events {
@@ -120,37 +97,6 @@ export class CSSProperty extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
12097
return result;
12198
}
12299

123-
#matchers(matchedStyles: CSSMatchedStyles, computedStyles: Map<string, string>|null): Array<Matcher<Match>> {
124-
const matchers = [
125-
new VariableMatcher(matchedStyles, this.ownerStyle),
126-
new ColorMatcher(() => computedStyles?.get('color') ?? null),
127-
new ColorMixMatcher(),
128-
new URLMatcher(),
129-
new AngleMatcher(),
130-
new LinkableNameMatcher(),
131-
new BezierMatcher(),
132-
new StringMatcher(),
133-
new ShadowMatcher(),
134-
new CSSWideKeywordMatcher(this, matchedStyles),
135-
new LightDarkColorMatcher(this),
136-
new GridTemplateMatcher(),
137-
new LinearGradientMatcher(),
138-
new AnchorFunctionMatcher(),
139-
new PositionAnchorMatcher(),
140-
new FlexGridMatcher(),
141-
new PositionTryMatcher(),
142-
new LengthMatcher(),
143-
new MathFunctionMatcher(),
144-
new AutoBaseMatcher(),
145-
new BinOpMatcher(),
146-
];
147-
148-
if (Root.Runtime.experiments.isEnabled('font-editor')) {
149-
matchers.push(new FontMatcher());
150-
}
151-
return matchers;
152-
}
153-
154100
parseExpression(expression: string, matchedStyles: CSSMatchedStyles, computedStyles: Map<string, string>|null):
155101
BottomUpTreeMatching|null {
156102
if (!this.parsedOk) {
@@ -168,6 +114,16 @@ export class CSSProperty extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
168114
return matchDeclaration(this.name, this.value, this.#matchers(matchedStyles, computedStyles));
169115
}
170116

117+
#matchers(matchedStyles: CSSMatchedStyles, computedStyles: Map<string, string>|null): Array<Matcher<Match>> {
118+
const matchers = matchedStyles.propertyMatchers(this.ownerStyle, computedStyles);
119+
120+
matchers.push(new CSSWideKeywordMatcher(this, matchedStyles));
121+
if (Root.Runtime.experiments.isEnabled('font-editor')) {
122+
matchers.push(new FontMatcher());
123+
}
124+
return matchers;
125+
}
126+
171127
private ensureRanges(): void {
172128
if (this.#nameRangeInternal && this.#valueRangeInternal) {
173129
return;

front_end/core/sdk/CSSPropertyParserMatchers.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ describe('Matchers for SDK.CSSPropertyParser.BottomUpTreeMatching', () => {
432432
const {match, text} = matchSingleValue(
433433
'color', fail,
434434
new SDK.CSSPropertyParserMatchers.LightDarkColorMatcher(
435-
sinon.createStubInstance(SDK.CSSProperty.CSSProperty)));
435+
sinon.createStubInstance(SDK.CSSStyleDeclaration.CSSStyleDeclaration)));
436436
assert.isNull(match, text);
437437
}
438438

@@ -442,7 +442,7 @@ describe('Matchers for SDK.CSSPropertyParser.BottomUpTreeMatching', () => {
442442
const {ast, match, text} = matchSingleValue(
443443
'color', succeed,
444444
new SDK.CSSPropertyParserMatchers.LightDarkColorMatcher(
445-
sinon.createStubInstance(SDK.CSSProperty.CSSProperty)));
445+
sinon.createStubInstance(SDK.CSSStyleDeclaration.CSSStyleDeclaration)));
446446
assert.exists(ast, text);
447447
assert.exists(match, text);
448448

@@ -456,7 +456,8 @@ describe('Matchers for SDK.CSSPropertyParser.BottomUpTreeMatching', () => {
456456
// light-dark only applies to color properties
457457
const {match, text} = matchSingleValue(
458458
'width', 'light-dark(red, blue)',
459-
new SDK.CSSPropertyParserMatchers.LightDarkColorMatcher(sinon.createStubInstance(SDK.CSSProperty.CSSProperty)));
459+
new SDK.CSSPropertyParserMatchers.LightDarkColorMatcher(
460+
sinon.createStubInstance(SDK.CSSStyleDeclaration.CSSStyleDeclaration)));
460461
assert.isNull(match, text);
461462
});
462463

front_end/core/sdk/CSSPropertyParserMatchers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ export class ColorMatcher extends matcherBase(ColorMatch) {
385385
export class LightDarkColorMatch implements Match {
386386
constructor(
387387
readonly text: string, readonly node: CodeMirror.SyntaxNode, readonly light: CodeMirror.SyntaxNode[],
388-
readonly dark: CodeMirror.SyntaxNode[], readonly property: CSSProperty) {
388+
readonly dark: CodeMirror.SyntaxNode[], readonly style: CSSStyleDeclaration) {
389389
}
390390
}
391391

392392
// clang-format off
393393
export class LightDarkColorMatcher extends matcherBase(LightDarkColorMatch) {
394394
// clang-format on
395-
constructor(readonly property: CSSProperty) {
395+
constructor(readonly style: CSSStyleDeclaration) {
396396
super();
397397
}
398398
override accepts(propertyName: string): boolean {
@@ -407,7 +407,7 @@ export class LightDarkColorMatcher extends matcherBase(LightDarkColorMatch) {
407407
if (args.length !== 2 || args[0].length === 0 || args[1].length === 0) {
408408
return null;
409409
}
410-
return new LightDarkColorMatch(matching.ast.text(node), node, args[0], args[1], this.property);
410+
return new LightDarkColorMatch(matching.ast.text(node), node, args[0], args[1], this.style);
411411
}
412412
}
413413

front_end/panels/elements/CSSValueTraceView.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from './PropertyRenderer.js';
1717
import stylePropertiesTreeOutlineStyles from './stylePropertiesTreeOutline.css.js';
1818

19-
const {html, render, Directives: {ref, ifDefined}} = Lit;
19+
const {html, render, Directives: {ref, classMap, ifDefined}} = Lit;
2020

2121
export interface ViewInput {
2222
substitutions: Node[][];
@@ -40,6 +40,7 @@ function defaultView(input: ViewInput, output: ViewOutput, target: HTMLElement):
4040

4141
const hiddenSummary = !firstEvaluation || intermediateEvaluations.length === 0;
4242
const summaryTabIndex = hiddenSummary ? undefined : 0;
43+
const singleResult = input.evaluations.length === 0 && input.substitutions.length === 0;
4344
render(
4445
// clang-format off
4546
html`
@@ -79,8 +80,12 @@ function defaultView(input: ViewInput, output: ViewOutput, target: HTMLElement):
7980
</details>`}
8081
${!input.finalResult
8182
? ''
82-
: html`<span class="trace-line-icon" aria-label="is equal to"></span
83-
><span class="trace-line">${input.finalResult}</span>`}
83+
: html`<span
84+
class="trace-line-icon"
85+
aria-label="is equal to"
86+
?hidden=${singleResult}
87+
></span
88+
><span class=${classMap({ 'trace-line': true, 'full-row': singleResult})}>${input.finalResult}</span>`}
8489
</div>
8590
`,
8691
// clang-format on

front_end/panels/elements/PropertyRenderer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class TracingContext {
165165
#appliedEvaluations = 0;
166166
#hasMoreEvaluations = true;
167167
readonly #highlighting: Highlighting;
168-
#parsedValueCache = new Map<SDK.CSSProperty.CSSProperty, {
168+
#parsedValueCache = new Map<SDK.CSSProperty.CSSProperty|SDK.CSSMatchedStyles.CSSRegisteredProperty, {
169169
matchedStyles: SDK.CSSMatchedStyles.CSSMatchedStyles,
170170
computedStyles: Map<string, string>,
171171
parsedValue: SDK.CSSPropertyParser.BottomUpTreeMatching|null,
@@ -282,7 +282,8 @@ export class TracingContext {
282282
}
283283

284284
cachedParsedValue(
285-
declaration: SDK.CSSProperty.CSSProperty, matchedStyles: SDK.CSSMatchedStyles.CSSMatchedStyles,
285+
declaration: SDK.CSSProperty.CSSProperty|SDK.CSSMatchedStyles.CSSRegisteredProperty,
286+
matchedStyles: SDK.CSSMatchedStyles.CSSMatchedStyles,
286287
computedStyles: Map<string, string>): SDK.CSSPropertyParser.BottomUpTreeMatching|null {
287288
const cachedValue = this.#parsedValueCache.get(declaration);
288289
if (cachedValue?.matchedStyles === matchedStyles && cachedValue?.computedStyles === computedStyles) {

front_end/panels/elements/StylePropertyTreeElement.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,11 @@ export class VariableRenderer extends rendererBase(SDK.CSSPropertyParserMatchers
311311

312312
const substitution = context.tracing?.substitution();
313313
if (substitution) {
314-
if (declaration?.declaration instanceof SDK.CSSProperty.CSSProperty) {
314+
if (declaration?.declaration) {
315315
const {nodes, cssControls} = Renderer.renderValueNodes(
316-
declaration.declaration,
316+
{name: declaration.name, value: declaration.value ?? ''},
317317
substitution.cachedParsedValue(declaration.declaration, this.#matchedStyles, this.#computedStyles),
318-
getPropertyRenderers(
319-
declaration.declaration.ownerStyle, this.#stylesPane, this.#matchedStyles, null, this.#computedStyles),
318+
getPropertyRenderers(declaration.style, this.#stylesPane, this.#matchedStyles, null, this.#computedStyles),
320319
substitution);
321320
cssControls.forEach((value, key) => value.forEach(control => context.addControl(key, control)));
322321
return nodes;
@@ -606,7 +605,7 @@ export class LightDarkColorRenderer extends rendererBase(SDK.CSSPropertyParserMa
606605
// If the element has color-scheme set to both light and dark, we check the prefers-color-scheme media query.
607606
async #activeColor(match: SDK.CSSPropertyParserMatchers.LightDarkColorMatch):
608607
Promise<CodeMirror.SyntaxNode[]|undefined> {
609-
const activeColorSchemes = this.#matchedStyles.resolveProperty('color-scheme', match.property.ownerStyle)
608+
const activeColorSchemes = this.#matchedStyles.resolveProperty('color-scheme', match.style)
610609
?.parseValue(this.#matchedStyles, new Map())
611610
?.getComputedPropertyValueText()
612611
.split(' ') ??

front_end/panels/elements/cssValueTraceView.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
margin: 0;
7777
padding-left: var(--sys-size-4);
7878
}
79+
80+
.full-row {
81+
grid-column-start: 1;
82+
}
7983
}
8084

8185
::highlight(css-value-tracing) {

0 commit comments

Comments
 (0)