Skip to content

Commit 71f0eaa

Browse files
yanlingwang23Devtools-frontend LUCI CQ
authored andcommitted
[Masonry] Support masonryContainer in CSSRuleValidator
This CL adds support for masonry container in CSSRuleValidator, resolving an issue where certain properties used within masonry containers were incorrectly greyed out in the Elements panel. Before: https://imgur.com/a/3SZbtDa After: https://imgur.com/a/vqx9OKZ Bug: 343257585 Change-Id: I34d9312f7a3fca6350b432f6cd51358b35df2cdc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6763709 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Simon Zünd <[email protected]> Reviewed-by: Changhao Han <[email protected]>
1 parent b8eaf7a commit 71f0eaa

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

front_end/panels/elements/CSSRuleValidator.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ describeWithEnvironment('CSSRuleValidator', () => {
4848
validator: () => new Elements.CSSRuleValidator.AlignContentValidator(),
4949
hintExpected: false,
5050
},
51+
{
52+
description: 'Test `align-content`, validation passes when the element is a masonry container',
53+
computedStyles: new Map<string, string>([
54+
['align-content', 'center'],
55+
['display', 'masonry'],
56+
]),
57+
validator: () => new Elements.CSSRuleValidator.AlignContentValidator(),
58+
hintExpected: false,
59+
},
5160
{
5261
description: 'Test `align-content`, validation does not pass when the element is a math container',
5362
computedStyles: new Map<string, string>([
@@ -75,6 +84,15 @@ describeWithEnvironment('CSSRuleValidator', () => {
7584
validator: () => new Elements.CSSRuleValidator.FlexGridValidator(),
7685
hintExpected: false,
7786
},
87+
{
88+
description: 'Test `justify-content`, validation passes when the element is masonry containers',
89+
computedStyles: new Map<string, string>([
90+
['display', 'masonry'],
91+
['justify-content', 'center'],
92+
]),
93+
validator: () => new Elements.CSSRuleValidator.FlexGridValidator(),
94+
hintExpected: false,
95+
},
7896
{
7997
description: 'Test `place-content`, validation passes when the element is grid containers',
8098
computedStyles: new Map<string, string>([
@@ -156,6 +174,16 @@ describeWithEnvironment('CSSRuleValidator', () => {
156174
validator: () => new Elements.CSSRuleValidator.GridContainerValidator(),
157175
hintExpected: false,
158176
},
177+
{
178+
description: 'Passes the validation when grid container properties are set to masonry container',
179+
computedStyles: new Map<string, string>([
180+
['display', 'masonry'],
181+
['grid-template-columns', 'repeat(3, 10px 15%)'],
182+
]),
183+
parentsComputedStyles: new Map<string, string>(),
184+
validator: () => new Elements.CSSRuleValidator.GridContainerValidator(),
185+
hintExpected: false,
186+
},
159187
{
160188
description: 'Reports a rule validation when grid container properties are set to non-grid container',
161189
computedStyles: new Map<string, string>([
@@ -177,6 +205,17 @@ describeWithEnvironment('CSSRuleValidator', () => {
177205
validator: () => new Elements.CSSRuleValidator.GridItemValidator(),
178206
hintExpected: false,
179207
},
208+
{
209+
description: 'Passes the validation when grid item properties are set to masonry items',
210+
computedStyles: new Map<string, string>([
211+
['grid-row', 'span 2'],
212+
]),
213+
parentsComputedStyles: new Map<string, string>([
214+
['display', 'masonry'],
215+
]),
216+
validator: () => new Elements.CSSRuleValidator.GridItemValidator(),
217+
hintExpected: false,
218+
},
180219
{
181220
description: 'Reports a rule validation when grid item properties are set to non-grid items',
182221
computedStyles: new Map<string, string>([

front_end/panels/elements/CSSRuleValidator.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
isFlexContainer,
1515
isGridContainer,
1616
isInlineElement,
17+
isMasonryContainer,
1718
isMulticolContainer,
1819
isPossiblyReplacedElement,
1920
} from './CSSRuleValidatorHelper.js';
@@ -152,7 +153,8 @@ export class AlignContentValidator extends CSSRuleValidator {
152153
return;
153154
}
154155
const isFlex = isFlexContainer(computedStyles);
155-
if (!isFlex && !isBlockContainer(computedStyles) && !isGridContainer(computedStyles)) {
156+
if (!isFlex && !isBlockContainer(computedStyles) && !isGridContainer(computedStyles) &&
157+
!isMasonryContainer(computedStyles)) {
156158
const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
157159
const affectedPropertyDeclarationCode = buildPropertyName('align-content');
158160

@@ -276,7 +278,7 @@ export class GridContainerValidator extends CSSRuleValidator {
276278
}
277279

278280
getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
279-
if (isGridContainer(computedStyles)) {
281+
if (isGridContainer(computedStyles) || isMasonryContainer(computedStyles)) {
280282
return;
281283
}
282284
const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
@@ -316,7 +318,7 @@ export class GridItemValidator extends CSSRuleValidator {
316318
if (!parentComputedStyles) {
317319
return;
318320
}
319-
if (isGridContainer(parentComputedStyles)) {
321+
if (isGridContainer(parentComputedStyles) || isMasonryContainer(parentComputedStyles)) {
320322
return;
321323
}
322324
const reasonPropertyDeclaration = buildPropertyDefinitionText('display', parentComputedStyles?.get('display'));
@@ -389,11 +391,13 @@ export class FlexGridValidator extends CSSRuleValidator {
389391
return;
390392
}
391393

392-
if (isFlexContainer(computedStyles) || isGridContainer(computedStyles)) {
394+
if (isFlexContainer(computedStyles) || isGridContainer(computedStyles) || isMasonryContainer(computedStyles)) {
393395
return;
394396
}
395397

396-
if (parentComputedStyles && (isFlexContainer(parentComputedStyles) || isGridContainer(parentComputedStyles))) {
398+
if (parentComputedStyles &&
399+
(isFlexContainer(parentComputedStyles) || isGridContainer(parentComputedStyles) ||
400+
isMasonryContainer(parentComputedStyles))) {
397401
const reasonContainerDisplayName = buildPropertyValue(parentComputedStyles.get('display') as string);
398402
const reasonPropertyName = buildPropertyName(propertyName);
399403
const reasonAlternativePropertyName = buildPropertyName('justify-self');
@@ -446,7 +450,8 @@ export class MulticolFlexGridValidator extends CSSRuleValidator {
446450
return;
447451
}
448452

449-
if (isMulticolContainer(computedStyles) || isFlexContainer(computedStyles) || isGridContainer(computedStyles)) {
453+
if (isMulticolContainer(computedStyles) || isFlexContainer(computedStyles) || isGridContainer(computedStyles) ||
454+
isMasonryContainer(computedStyles)) {
450455
return;
451456
}
452457

front_end/panels/elements/CSSRuleValidatorHelper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ export const isGridContainer = (computedStyles?: Map<string, string>): boolean =
9191
return display === 'grid' || display === 'inline-grid';
9292
};
9393

94+
export const isMasonryContainer = (computedStyles?: Map<string, string>): boolean => {
95+
if (!computedStyles) {
96+
return false;
97+
}
98+
const display = computedStyles.get('display');
99+
return display === 'masonry' || display === 'inline-masonry';
100+
};
101+
94102
export const isMulticolContainer = (computedStyles?: Map<string, string>): boolean => {
95103
if (!computedStyles) {
96104
return false;

0 commit comments

Comments
 (0)