chrome-devtools-frontend 1.0.1033423 → 1.0.1034802

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/config/gni/devtools_grd_files.gni +5 -0
  2. package/front_end/core/host/InspectorFrontendHostAPI.ts +1 -0
  3. package/front_end/core/host/UserMetrics.ts +23 -0
  4. package/front_end/core/root/Runtime.ts +11 -1
  5. package/front_end/core/sdk/NetworkManager.ts +19 -5
  6. package/front_end/entrypoints/lighthouse_worker/LighthouseWorkerService.ts +19 -8
  7. package/front_end/entrypoints/main/MainImpl.ts +5 -1
  8. package/front_end/models/issues_manager/AttributionReportingIssue.ts +30 -4
  9. package/front_end/models/issues_manager/CookieIssue.ts +14 -0
  10. package/front_end/models/issues_manager/descriptions/arSourceAndTriggerHeaders.md +9 -0
  11. package/front_end/models/issues_manager/descriptions/arSourceIgnored.md +13 -0
  12. package/front_end/models/issues_manager/descriptions/arTriggerIgnored.md +12 -0
  13. package/front_end/models/issues_manager/descriptions/cookieExcludeDomainNonAscii.md +11 -0
  14. package/front_end/models/issues_manager/descriptions/cookieWarnDomainNonAscii.md +11 -0
  15. package/front_end/models/persistence/NetworkPersistenceManager.ts +6 -2
  16. package/front_end/panels/console/ConsolePinPane.ts +2 -2
  17. package/front_end/panels/elements/CSSRuleValidator.ts +169 -101
  18. package/front_end/panels/elements/CSSRuleValidatorHelper.ts +13 -7
  19. package/front_end/panels/elements/StylePropertiesSection.ts +8 -0
  20. package/front_end/panels/elements/StylePropertyTreeElement.ts +35 -31
  21. package/front_end/panels/elements/StylesSidebarPane.ts +24 -0
  22. package/front_end/panels/elements/components/CSSHintDetailsView.ts +5 -5
  23. package/front_end/panels/elements/components/LayoutPane.ts +1 -1
  24. package/front_end/panels/issues/AttributionReportingIssueDetailsView.ts +10 -0
  25. package/front_end/panels/lighthouse/LighthouseProtocolService.ts +9 -6
  26. package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorController.ts +17 -1
  27. package/front_end/ui/components/markdown_view/MarkdownLinksMap.ts +1 -0
  28. package/front_end/ui/legacy/components/object_ui/JavaScriptREPL.ts +2 -2
  29. package/package.json +1 -1
@@ -2,11 +2,12 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
 
5
+ import * as Host from '../../core/host/host.js';
5
6
  import * as i18n from '../../core/i18n/i18n.js';
6
7
 
7
8
  import {
8
- buildStyledPropertyText,
9
- buildStyledRuleText,
9
+ buildPropertyDefinitionText,
10
+ buildPropertyText,
10
11
  isFlexContainer,
11
12
  isGridContainer,
12
13
  isMulticolContainer,
@@ -58,35 +59,34 @@ const UIStrings = {
58
59
  const str_ = i18n.i18n.registerUIStrings('panels/elements/CSSRuleValidator.ts', UIStrings);
59
60
  const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
60
61
 
61
- export const enum AuthoringHintType {
62
+ export const enum HintType {
62
63
  INACTIVE_PROPERTY = 'ruleValidation',
63
64
  DEPRECATED_PROPERTY = 'deprecatedProperty',
64
65
  }
65
66
 
66
- export class AuthoringHint {
67
- readonly #hintType: AuthoringHintType;
67
+ export class Hint {
68
+ readonly #hintType: HintType;
68
69
  readonly #hintMessage: string;
69
70
  readonly #possibleFixMessage: string|null;
70
71
  readonly #learnMoreLink: string|undefined;
71
72
 
72
- constructor(
73
- hintType: AuthoringHintType, hintMessage: string, possibleFixMessage: string|null, learnMoreLink?: string) {
73
+ constructor(hintType: HintType, hintMessage: string, possibleFixMessage: string|null, learnMoreLink?: string) {
74
74
  this.#hintType = hintType;
75
75
  this.#hintMessage = hintMessage;
76
76
  this.#possibleFixMessage = possibleFixMessage;
77
77
  this.#learnMoreLink = learnMoreLink;
78
78
  }
79
79
 
80
- getHintPrefix(): string {
80
+ getPrefix(): string {
81
81
  switch (this.#hintType) {
82
- case AuthoringHintType.INACTIVE_PROPERTY:
82
+ case HintType.INACTIVE_PROPERTY:
83
83
  return i18nString(UIStrings.inactivePropertyHintPrefix);
84
- case AuthoringHintType.DEPRECATED_PROPERTY:
84
+ case HintType.DEPRECATED_PROPERTY:
85
85
  return i18nString(UIStrings.deprecatedPropertyHintPrefix);
86
86
  }
87
87
  }
88
88
 
89
- getHintMessage(): string {
89
+ getMessage(): string {
90
90
  return this.#hintMessage;
91
91
  }
92
92
 
@@ -100,25 +100,23 @@ export class AuthoringHint {
100
100
  }
101
101
 
102
102
  export abstract class CSSRuleValidator {
103
+ getMetricType(): Host.UserMetrics.CSSHintType {
104
+ return Host.UserMetrics.CSSHintType.Other;
105
+ }
106
+
103
107
  readonly #affectedProperties: string[];
104
108
 
105
109
  constructor(affectedProperties: string[]) {
106
110
  this.#affectedProperties = affectedProperties;
107
111
  }
108
112
 
109
- /**
110
- * If `isRuleValid` returns false, it means there is a hint to be shown. The hint is retrieved by invoking `getAuthoringHint`.
111
- */
112
- abstract isRuleValid(computedStyles: Map<String, String>|null, parentsComputedStyles?: Map<String, String>|null):
113
- boolean;
114
-
115
- getAffectedProperties(): string[] {
113
+ getApplicableProperties(): string[] {
116
114
  return this.#affectedProperties;
117
115
  }
118
116
 
119
- abstract getAuthoringHint(
120
- propertyName: string, computedStyles: Map<String, String>|null,
121
- parentComputedStyles: Map<String, String>|null): AuthoringHint;
117
+ abstract getHint(
118
+ propertyName: string, computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): Hint
119
+ |undefined;
122
120
  }
123
121
 
124
122
  export class AlignContentValidator extends CSSRuleValidator {
@@ -126,7 +124,11 @@ export class AlignContentValidator extends CSSRuleValidator {
126
124
  super(['align-content']);
127
125
  }
128
126
 
129
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
127
+ getMetricType(): Host.UserMetrics.CSSHintType {
128
+ return Host.UserMetrics.CSSHintType.AlignContent;
129
+ }
130
+
131
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
130
132
  if (computedStyles === null || computedStyles === undefined) {
131
133
  return true;
132
134
  }
@@ -136,12 +138,15 @@ export class AlignContentValidator extends CSSRuleValidator {
136
138
  return computedStyles.get('flex-wrap') !== 'nowrap';
137
139
  }
138
140
 
139
- getAuthoringHint(): AuthoringHint {
140
- const reasonPropertyDeclaration = buildStyledPropertyText('flex-wrap');
141
- const affectedPropertyDeclarationCode = buildStyledPropertyText('align-content');
141
+ getHint(_propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
142
+ if (this.#isRuleValid(computedStyles)) {
143
+ return;
144
+ }
145
+ const reasonPropertyDeclaration = buildPropertyText('flex-wrap');
146
+ const affectedPropertyDeclarationCode = buildPropertyText('align-content');
142
147
 
143
- return new AuthoringHint(
144
- AuthoringHintType.INACTIVE_PROPERTY,
148
+ return new Hint(
149
+ HintType.INACTIVE_PROPERTY,
145
150
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
146
151
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
147
152
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -158,22 +163,28 @@ export class FlexItemValidator extends CSSRuleValidator {
158
163
  super(['flex', 'flex-basis', 'flex-grow', 'flex-shrink']);
159
164
  }
160
165
 
161
- isRuleValid(computedStyles: Map<String, String>|null, parentsComputedStyles: Map<String, String>|null): boolean {
162
- if (parentsComputedStyles === null) {
166
+ getMetricType(): Host.UserMetrics.CSSHintType {
167
+ return Host.UserMetrics.CSSHintType.FlexItem;
168
+ }
169
+
170
+ #isRuleValid(computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): boolean {
171
+ if (parentComputedStyles === null) {
163
172
  return true;
164
173
  }
165
- return isFlexContainer(parentsComputedStyles);
174
+ return isFlexContainer(parentComputedStyles);
166
175
  }
167
176
 
168
- getAuthoringHint(
169
- property: string, computedStyles: Map<String, String>|null,
170
- parentsComputedStyles: Map<String, String>|null): AuthoringHint {
171
- const reasonPropertyDeclaration = buildStyledRuleText('display', parentsComputedStyles?.get('display'));
172
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
173
- const targeParentPropertyDeclaration = buildStyledRuleText('display', 'flex');
177
+ getHint(propertyName: string, computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): Hint
178
+ |undefined {
179
+ if (this.#isRuleValid(computedStyles, parentComputedStyles)) {
180
+ return;
181
+ }
182
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', parentComputedStyles?.get('display'));
183
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
184
+ const targeParentPropertyDeclaration = buildPropertyDefinitionText('display', 'flex');
174
185
 
175
- return new AuthoringHint(
176
- AuthoringHintType.INACTIVE_PROPERTY,
186
+ return new Hint(
187
+ HintType.INACTIVE_PROPERTY,
177
188
  i18nString(UIStrings.ruleViolatedByParentElementRuleReason, {
178
189
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
179
190
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -191,20 +202,27 @@ export class FlexContainerValidator extends CSSRuleValidator {
191
202
  super(['flex-direction', 'flex-flow', 'flex-wrap', 'justify-content']);
192
203
  }
193
204
 
194
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
205
+ getMetricType(): Host.UserMetrics.CSSHintType {
206
+ return Host.UserMetrics.CSSHintType.FlexContainer;
207
+ }
208
+
209
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
195
210
  if (computedStyles === null) {
196
211
  return true;
197
212
  }
198
213
  return isFlexContainer(computedStyles);
199
214
  }
200
215
 
201
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
202
- const reasonPropertyDeclaration = buildStyledRuleText('display', computedStyles?.get('display'));
203
- const targetRuleCode = buildStyledRuleText('display', 'flex');
204
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
216
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
217
+ if (this.#isRuleValid(computedStyles)) {
218
+ return;
219
+ }
220
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
221
+ const targetRuleCode = buildPropertyDefinitionText('display', 'flex');
222
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
205
223
 
206
- return new AuthoringHint(
207
- AuthoringHintType.INACTIVE_PROPERTY,
224
+ return new Hint(
225
+ HintType.INACTIVE_PROPERTY,
208
226
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
209
227
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
210
228
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -231,20 +249,24 @@ export class GridContainerValidator extends CSSRuleValidator {
231
249
  ]);
232
250
  }
233
251
 
234
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
235
- if (computedStyles === null) {
236
- return true;
237
- }
252
+ getMetricType(): Host.UserMetrics.CSSHintType {
253
+ return Host.UserMetrics.CSSHintType.GridContainer;
254
+ }
255
+
256
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
238
257
  return isGridContainer(computedStyles);
239
258
  }
240
259
 
241
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
242
- const reasonPropertyDeclaration = buildStyledRuleText('display', computedStyles?.get('display'));
243
- const targetRuleCode = buildStyledRuleText('display', 'grid');
244
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
260
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
261
+ if (this.#isRuleValid(computedStyles)) {
262
+ return;
263
+ }
264
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
265
+ const targetRuleCode = buildPropertyDefinitionText('display', 'grid');
266
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
245
267
 
246
- return new AuthoringHint(
247
- AuthoringHintType.INACTIVE_PROPERTY,
268
+ return new Hint(
269
+ HintType.INACTIVE_PROPERTY,
248
270
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
249
271
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
250
272
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -268,22 +290,28 @@ export class GridItemValidator extends CSSRuleValidator {
268
290
  ]);
269
291
  }
270
292
 
271
- isRuleValid(computedStyles: Map<String, String>|null, parentComputedStyles: Map<String, String>|null): boolean {
272
- if (parentComputedStyles === null) {
293
+ getMetricType(): Host.UserMetrics.CSSHintType {
294
+ return Host.UserMetrics.CSSHintType.GridItem;
295
+ }
296
+
297
+ #isRuleValid(computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): boolean {
298
+ if (!parentComputedStyles) {
273
299
  return true;
274
300
  }
275
301
  return isGridContainer(parentComputedStyles);
276
302
  }
277
303
 
278
- getAuthoringHint(
279
- property: string, computedStyles: Map<String, String>|null,
280
- parentComputedStyles: Map<String, String>|null): AuthoringHint {
281
- const reasonPropertyDeclaration = buildStyledRuleText('display', parentComputedStyles?.get('display'));
282
- const targeParentPropertyDeclaration = buildStyledRuleText('display', 'grid');
283
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
304
+ getHint(propertyName: string, computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): Hint
305
+ |undefined {
306
+ if (this.#isRuleValid(computedStyles, parentComputedStyles)) {
307
+ return;
308
+ }
309
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', parentComputedStyles?.get('display'));
310
+ const targeParentPropertyDeclaration = buildPropertyDefinitionText('display', 'grid');
311
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
284
312
 
285
- return new AuthoringHint(
286
- AuthoringHintType.INACTIVE_PROPERTY,
313
+ return new Hint(
314
+ HintType.INACTIVE_PROPERTY,
287
315
  i18nString(UIStrings.ruleViolatedByParentElementRuleReason, {
288
316
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
289
317
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -306,19 +334,27 @@ export class FlexGridValidator extends CSSRuleValidator {
306
334
  ]);
307
335
  }
308
336
 
309
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
337
+ getMetricType(): Host.UserMetrics.CSSHintType {
338
+ return Host.UserMetrics.CSSHintType.FlexGrid;
339
+ }
340
+
341
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
310
342
  if (computedStyles === null) {
311
343
  return true;
312
344
  }
313
345
  return isFlexContainer(computedStyles) || isGridContainer(computedStyles);
314
346
  }
315
347
 
316
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
317
- const reasonPropertyDeclaration = buildStyledRuleText('display', computedStyles?.get('display'));
318
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
348
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
349
+ if (this.#isRuleValid(computedStyles)) {
350
+ return;
351
+ }
352
+
353
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
354
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
319
355
 
320
- return new AuthoringHint(
321
- AuthoringHintType.INACTIVE_PROPERTY,
356
+ return new Hint(
357
+ HintType.INACTIVE_PROPERTY,
322
358
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
323
359
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
324
360
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -343,19 +379,27 @@ export class MulticolFlexGridValidator extends CSSRuleValidator {
343
379
  ]);
344
380
  }
345
381
 
346
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
382
+ getMetricType(): Host.UserMetrics.CSSHintType {
383
+ return Host.UserMetrics.CSSHintType.MulticolFlexGrid;
384
+ }
385
+
386
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
347
387
  if (computedStyles === null) {
348
388
  return true;
349
389
  }
350
390
  return isMulticolContainer(computedStyles) || isFlexContainer(computedStyles) || isGridContainer(computedStyles);
351
391
  }
352
392
 
353
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
354
- const reasonPropertyDeclaration = buildStyledRuleText('display', computedStyles?.get('display'));
355
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
393
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
394
+ if (this.#isRuleValid(computedStyles)) {
395
+ return;
396
+ }
356
397
 
357
- return new AuthoringHint(
358
- AuthoringHintType.INACTIVE_PROPERTY,
398
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
399
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
400
+
401
+ return new Hint(
402
+ HintType.INACTIVE_PROPERTY,
359
403
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
360
404
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
361
405
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -378,7 +422,11 @@ export class PaddingValidator extends CSSRuleValidator {
378
422
  ]);
379
423
  }
380
424
 
381
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
425
+ getMetricType(): Host.UserMetrics.CSSHintType {
426
+ return Host.UserMetrics.CSSHintType.Padding;
427
+ }
428
+
429
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
382
430
  const display = computedStyles?.get('display');
383
431
  if (display === null || display === undefined) {
384
432
  return true;
@@ -388,12 +436,16 @@ export class PaddingValidator extends CSSRuleValidator {
388
436
  .includes(display as string);
389
437
  }
390
438
 
391
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
392
- const reasonPropertyDeclaration = buildStyledRuleText('display', computedStyles?.get('display'));
393
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
439
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
440
+ if (this.#isRuleValid(computedStyles)) {
441
+ return;
442
+ }
443
+
444
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('display', computedStyles?.get('display'));
445
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
394
446
 
395
- return new AuthoringHint(
396
- AuthoringHintType.INACTIVE_PROPERTY,
447
+ return new Hint(
448
+ HintType.INACTIVE_PROPERTY,
397
449
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
398
450
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
399
451
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -415,7 +467,11 @@ export class PositionValidator extends CSSRuleValidator {
415
467
  ]);
416
468
  }
417
469
 
418
- isRuleValid(computedStyles: Map<String, String>|null): boolean {
470
+ getMetricType(): Host.UserMetrics.CSSHintType {
471
+ return Host.UserMetrics.CSSHintType.Position;
472
+ }
473
+
474
+ #isRuleValid(computedStyles?: Map<string, string>): boolean {
419
475
  const position = computedStyles?.get('position');
420
476
  if (position === null || position === undefined) {
421
477
  return true;
@@ -423,12 +479,16 @@ export class PositionValidator extends CSSRuleValidator {
423
479
  return position !== 'static';
424
480
  }
425
481
 
426
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
427
- const reasonPropertyDeclaration = buildStyledRuleText('position', computedStyles?.get('position'));
428
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
482
+ getHint(propertyName: string, computedStyles?: Map<string, string>): Hint|undefined {
483
+ if (this.#isRuleValid(computedStyles)) {
484
+ return;
485
+ }
429
486
 
430
- return new AuthoringHint(
431
- AuthoringHintType.INACTIVE_PROPERTY,
487
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('position', computedStyles?.get('position'));
488
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
489
+
490
+ return new Hint(
491
+ HintType.INACTIVE_PROPERTY,
432
492
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
433
493
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
434
494
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -447,21 +507,29 @@ export class ZIndexValidator extends CSSRuleValidator {
447
507
  ]);
448
508
  }
449
509
 
450
- isRuleValid(computedStyles: Map<String, String>|null, parentComputedStyles: Map<String, String>|null): boolean {
510
+ getMetricType(): Host.UserMetrics.CSSHintType {
511
+ return Host.UserMetrics.CSSHintType.ZIndex;
512
+ }
513
+
514
+ #isRuleValid(computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): boolean {
451
515
  const position = computedStyles?.get('position');
452
516
  if (position === null || position === undefined) {
453
517
  return true;
454
518
  }
455
- return ['absolute', 'relative', 'fixed', 'sticky'].includes(position as string) ||
456
- isFlexContainer(parentComputedStyles);
519
+ return ['absolute', 'relative', 'fixed', 'sticky'].includes(position) || isFlexContainer(parentComputedStyles);
457
520
  }
458
521
 
459
- getAuthoringHint(property: string, computedStyles: Map<String, String>|null): AuthoringHint {
460
- const reasonPropertyDeclaration = buildStyledRuleText('position', computedStyles?.get('position'));
461
- const affectedPropertyDeclarationCode = buildStyledPropertyText(property);
522
+ getHint(propertyName: string, computedStyles?: Map<string, string>, parentComputedStyles?: Map<string, string>): Hint
523
+ |undefined {
524
+ if (this.#isRuleValid(computedStyles, parentComputedStyles)) {
525
+ return;
526
+ }
527
+
528
+ const reasonPropertyDeclaration = buildPropertyDefinitionText('position', computedStyles?.get('position'));
529
+ const affectedPropertyDeclarationCode = buildPropertyText(propertyName);
462
530
 
463
- return new AuthoringHint(
464
- AuthoringHintType.INACTIVE_PROPERTY,
531
+ return new Hint(
532
+ HintType.INACTIVE_PROPERTY,
465
533
  i18nString(UIStrings.ruleViolatedBySameElementRuleReason, {
466
534
  'REASON_PROPERTY_DECLARATION_CODE': reasonPropertyDeclaration,
467
535
  'AFFECTED_PROPERTY_DECLARATION_CODE': affectedPropertyDeclarationCode,
@@ -486,11 +554,11 @@ const CSS_RULE_VALIDATORS = [
486
554
  ZIndexValidator,
487
555
  ];
488
556
 
489
- const setupCSSRulesValidators = (): Map<String, CSSRuleValidator[]> => {
490
- const validatorsMap = new Map<String, CSSRuleValidator[]>();
557
+ const setupCSSRulesValidators = (): Map<string, CSSRuleValidator[]> => {
558
+ const validatorsMap = new Map<string, CSSRuleValidator[]>();
491
559
  for (const validatorClass of CSS_RULE_VALIDATORS) {
492
560
  const validator = new validatorClass();
493
- const affectedProperties = validator.getAffectedProperties();
561
+ const affectedProperties = validator.getApplicableProperties();
494
562
 
495
563
  for (const affectedProperty of affectedProperties) {
496
564
  let propertyValidators = validatorsMap.get(affectedProperty);
@@ -505,4 +573,4 @@ const setupCSSRulesValidators = (): Map<String, CSSRuleValidator[]> => {
505
573
  return validatorsMap;
506
574
  };
507
575
 
508
- export const cssRuleValidatorsMap: Map<String, CSSRuleValidator[]> = setupCSSRulesValidators();
576
+ export const cssRuleValidatorsMap: Map<string, CSSRuleValidator[]> = setupCSSRulesValidators();
@@ -2,31 +2,37 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
 
5
- export const buildStyledRuleText = (property: String, value: String|undefined): string => {
5
+ export const buildPropertyDefinitionText = (property: string, value?: string): string => {
6
6
  if (value === undefined) {
7
- return buildStyledPropertyText(property);
7
+ return buildPropertyText(property);
8
8
  }
9
9
  return '<code class="unbreakable-text"><span class="property">' + property + '</span>: ' + value + '</code>';
10
10
  };
11
11
 
12
- export const buildStyledPropertyText = (property: String): string => {
12
+ export const buildPropertyText = (property: string): string => {
13
13
  return '<code class="unbreakable-text"><span class="property">' + property + '</span></code>';
14
14
  };
15
15
 
16
- export const isFlexContainer = (computedStyles: Map<String, String>|null): boolean => {
17
- if (computedStyles === null) {
16
+ export const isFlexContainer = (computedStyles?: Map<string, string>): boolean => {
17
+ if (!computedStyles) {
18
18
  return false;
19
19
  }
20
20
  const display = computedStyles.get('display');
21
21
  return display === 'flex' || display === 'inline-flex';
22
22
  };
23
23
 
24
- export const isGridContainer = (computedStyles: Map<String, String>): boolean => {
24
+ export const isGridContainer = (computedStyles?: Map<string, string>): boolean => {
25
+ if (!computedStyles) {
26
+ return false;
27
+ }
25
28
  const display = computedStyles.get('display');
26
29
  return display === 'grid' || display === 'inline-grid';
27
30
  };
28
31
 
29
- export const isMulticolContainer = (computedStyles: Map<String, String>): boolean => {
32
+ export const isMulticolContainer = (computedStyles?: Map<string, string>): boolean => {
33
+ if (!computedStyles) {
34
+ return false;
35
+ }
30
36
  const columnWidth = computedStyles.get('column-width');
31
37
  const columnCount = computedStyles.get('column-count');
32
38
 
@@ -290,6 +290,14 @@ export class StylePropertiesSection {
290
290
  this.onpopulate();
291
291
  }
292
292
 
293
+ setComputedStyles(computedStyles: Map<string, string>|null): void {
294
+ this.computedStyles = computedStyles;
295
+ }
296
+
297
+ setParentsComputedStyles(parentsComputedStyles: Map<string, string>|null): void {
298
+ this.parentsComputedStyles = parentsComputedStyles;
299
+ }
300
+
293
301
  setSectionIdx(sectionIdx: number): void {
294
302
  this.sectionIdx = sectionIdx;
295
303
  this.onpopulate();
@@ -21,12 +21,12 @@ import {StyleEditorWidget} from './StyleEditorWidget.js';
21
21
  import {type StylePropertiesSection} from './StylePropertiesSection.js';
22
22
  import {CSSPropertyPrompt, StylesSidebarPane, StylesSidebarPropertyRenderer} from './StylesSidebarPane.js';
23
23
  import {getCssDeclarationAsJavascriptProperty} from './StylePropertyUtils.js';
24
- import {cssRuleValidatorsMap, type AuthoringHint} from './CSSRuleValidator.js';
24
+ import {cssRuleValidatorsMap, type Hint} from './CSSRuleValidator.js';
25
25
 
26
26
  const FlexboxEditor = ElementsComponents.StylePropertyEditor.FlexboxEditor;
27
27
  const GridEditor = ElementsComponents.StylePropertyEditor.GridEditor;
28
28
 
29
- export const activeHints = new WeakMap<Element, AuthoringHint>();
29
+ export const activeHints = new WeakMap<Element, Hint>();
30
30
 
31
31
  const UIStrings = {
32
32
  /**
@@ -717,23 +717,16 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
717
717
  }
718
718
  }
719
719
 
720
- const authoringHint = this.getAuthoringHint(this.computedStyles, this.parentsComputedStyles);
721
- const showAuthoringHint = authoringHint !== null && this.property.parsedOk;
722
- if (showAuthoringHint) {
723
- const hintIcon = UI.Icon.Icon.create('mediumicon-info', 'hint');
724
- activeHints.set(hintIcon, authoringHint);
725
- this.listItemElement.append(hintIcon);
726
- }
727
-
728
- if (!this.property.parsedOk) {
720
+ if (this.property.parsedOk) {
721
+ void this.updateFontVariationSettingsWarning();
722
+ this.updateAuthoringHint();
723
+ } else {
729
724
  // Avoid having longhands under an invalid shorthand.
730
725
  this.listItemElement.classList.add('not-parsed-ok');
731
726
 
732
727
  // Add a separate exclamation mark IMG element with a tooltip.
733
728
  this.listItemElement.insertBefore(
734
729
  StylesSidebarPane.createExclamationMark(this.property, null), this.listItemElement.firstChild);
735
- } else {
736
- void this.updateFontVariationSettingsWarning();
737
730
  }
738
731
 
739
732
  if (!this.property.activeInStyle()) {
@@ -768,6 +761,35 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
768
761
  }
769
762
  }
770
763
 
764
+ private updateAuthoringHint(): void {
765
+ if (!Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.CSS_AUTHORING_HINTS)) {
766
+ return;
767
+ }
768
+
769
+ const existingElement = this.listItemElement.querySelector('.hint');
770
+ if (existingElement) {
771
+ activeHints.delete(existingElement);
772
+ existingElement.parentElement?.removeChild(existingElement);
773
+ }
774
+ const propertyName = this.property.name;
775
+
776
+ if (!cssRuleValidatorsMap.has(propertyName)) {
777
+ return;
778
+ }
779
+
780
+ for (const validator of cssRuleValidatorsMap.get(propertyName) || []) {
781
+ const hint =
782
+ validator.getHint(propertyName, this.computedStyles || undefined, this.parentsComputedStyles || undefined);
783
+ if (hint) {
784
+ Host.userMetrics.cssHintShown(validator.getMetricType());
785
+ const hintIcon = UI.Icon.Icon.create('mediumicon-info', 'hint');
786
+ activeHints.set(hintIcon, hint);
787
+ this.listItemElement.append(hintIcon);
788
+ break;
789
+ }
790
+ }
791
+ }
792
+
771
793
  private async updateFontVariationSettingsWarning(): Promise<void> {
772
794
  if (this.property.name !== 'font-variation-settings') {
773
795
  return;
@@ -816,24 +838,6 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
816
838
  StylesSidebarPane.createExclamationMark(this.property, warnings.join(' ')), this.listItemElement.firstChild);
817
839
  }
818
840
 
819
- private getAuthoringHint(computedStyles: Map<string, string>|null, parentComputedStyles: Map<string, string>|null):
820
- AuthoringHint|null {
821
- const propertyName = this.property.name;
822
-
823
- if (!Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.CSS_AUTHORING_HINTS) ||
824
- !cssRuleValidatorsMap.has(propertyName)) {
825
- return null;
826
- }
827
-
828
- for (const validator of cssRuleValidatorsMap.get(propertyName) || []) {
829
- if (!validator.isRuleValid(computedStyles, parentComputedStyles)) {
830
- return validator.getAuthoringHint(propertyName, this.computedStyles, this.parentsComputedStyles);
831
- }
832
- }
833
-
834
- return null;
835
- }
836
-
837
841
  private mouseUp(event: MouseEvent): void {
838
842
  const activeTreeElement = parentMap.get(this.parentPaneInternal);
839
843
  parentMap.delete(this.parentPaneInternal);