chrome-devtools-frontend 1.0.1039659 → 1.0.1040084

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.
@@ -5,7 +5,7 @@
5
5
  import * as Protocol from '../../generated/protocol.js';
6
6
  import * as TextUtils from '../../models/text_utils/text_utils.js';
7
7
 
8
- import {cssMetadata, CustomVariableRegex, VariableRegex} from './CSSMetadata.js';
8
+ import {cssMetadata, VariableRegex} from './CSSMetadata.js';
9
9
 
10
10
  import {type CSSModel} from './CSSModel.js';
11
11
  import {type CSSProperty} from './CSSProperty.js';
@@ -618,7 +618,8 @@ class NodeCascade {
618
618
  this.propertiesState.clear();
619
619
  this.activeProperties.clear();
620
620
 
621
- for (const style of this.styles) {
621
+ for (let i = this.styles.length - 1; i >= 0; i--) {
622
+ const style = this.styles[i];
622
623
  const rule = style.parentRule;
623
624
  // Compute cascade for CSSStyleRules only.
624
625
  if (rule && !(rule instanceof CSSStyleRule)) {
@@ -637,44 +638,43 @@ class NodeCascade {
637
638
  continue;
638
639
  }
639
640
 
640
- if (!property.activeInStyle()) {
641
- this.propertiesState.set(property, PropertyState.Overloaded);
641
+ // When a property does not have a range in an otherwise ranged CSSStyleDeclaration,
642
+ // we consider it as a non-leading property (see computeLeadingProperties()), and most
643
+ // of them are computed longhands. We exclude these from activeProperties calculation,
644
+ // and use parsed longhands instead (see below).
645
+ if (style.range && !property.range) {
642
646
  continue;
643
647
  }
644
648
 
645
- const canonicalName = metadata.canonicalPropertyName(property.name);
646
- const isPropShorthand = Boolean(metadata.getLonghands(canonicalName));
647
-
648
- if (isPropShorthand) {
649
- const longhandsFromShort =
650
- (property.value.match(CustomVariableRegex) || []).map(e => e.replace(CustomVariableRegex, '$2'));
651
- longhandsFromShort.forEach(longhandProperty => {
652
- if (metadata.isCSSPropertyName(longhandProperty)) {
653
- const activeProperty = this.activeProperties.get(longhandProperty);
654
- if (!activeProperty) {
655
- this.activeProperties.set(longhandProperty, property);
656
- } else {
657
- this.propertiesState.set(activeProperty, PropertyState.Overloaded);
658
- this.activeProperties.set(longhandProperty, property);
659
- }
660
- }
661
- });
662
- }
663
-
664
- const activeProperty = this.activeProperties.get(canonicalName);
665
- if (activeProperty && (activeProperty.important || !property.important)) {
649
+ if (!property.activeInStyle()) {
666
650
  this.propertiesState.set(property, PropertyState.Overloaded);
667
651
  continue;
668
652
  }
669
653
 
670
- if (activeProperty) {
671
- this.propertiesState.set(activeProperty, PropertyState.Overloaded);
654
+ const canonicalName = metadata.canonicalPropertyName(property.name);
655
+ this.updatePropertyState(property, canonicalName);
656
+ for (const longhand of property.getLonghandProperties()) {
657
+ if (metadata.isCSSPropertyName(longhand.name)) {
658
+ this.updatePropertyState(longhand, longhand.name);
659
+ }
672
660
  }
673
- this.propertiesState.set(property, PropertyState.Active);
674
- this.activeProperties.set(canonicalName, property);
675
661
  }
676
662
  }
677
663
  }
664
+
665
+ private updatePropertyState(propertyWithHigherSpecificity: CSSProperty, canonicalName: string): void {
666
+ const activeProperty = this.activeProperties.get(canonicalName);
667
+ if (activeProperty?.important && !propertyWithHigherSpecificity.important) {
668
+ this.propertiesState.set(propertyWithHigherSpecificity, PropertyState.Overloaded);
669
+ return;
670
+ }
671
+
672
+ if (activeProperty) {
673
+ this.propertiesState.set(activeProperty, PropertyState.Overloaded);
674
+ }
675
+ this.propertiesState.set(propertyWithHigherSpecificity, PropertyState.Active);
676
+ this.activeProperties.set(canonicalName, propertyWithHigherSpecificity);
677
+ }
678
678
  }
679
679
 
680
680
  class DOMInheritanceCascade {
@@ -841,9 +841,7 @@ class DOMInheritanceCascade {
841
841
  const activeProperties = new Map<string, CSSProperty>();
842
842
  for (const nodeCascade of this.#nodeCascades) {
843
843
  nodeCascade.computeActiveProperties();
844
- for (const entry of nodeCascade.propertiesState.entries()) {
845
- const property = (entry[0] as CSSProperty);
846
- const state = (entry[1] as PropertyState);
844
+ for (const [property, state] of nodeCascade.propertiesState) {
847
845
  if (state === PropertyState.Overloaded) {
848
846
  this.#propertiesState.set(property, PropertyState.Overloaded);
849
847
  continue;
@@ -858,11 +856,9 @@ class DOMInheritanceCascade {
858
856
  }
859
857
  }
860
858
  // If every longhand of the shorthand is not active, then the shorthand is not active too.
861
- for (const entry of activeProperties.entries()) {
862
- const canonicalName = (entry[0] as string);
863
- const shorthandProperty = (entry[1] as CSSProperty);
859
+ for (const [canonicalName, shorthandProperty] of activeProperties) {
864
860
  const shorthandStyle = shorthandProperty.ownerStyle;
865
- const longhands = shorthandStyle.longhandProperties(shorthandProperty.name);
861
+ const longhands = shorthandProperty.getLonghandProperties();
866
862
  if (!longhands.length) {
867
863
  continue;
868
864
  }
@@ -27,10 +27,12 @@ export class CSSProperty {
27
27
  #nameRangeInternal: TextUtils.TextRange.TextRange|null;
28
28
  #valueRangeInternal: TextUtils.TextRange.TextRange|null;
29
29
  #invalidString?: Common.UIString.LocalizedString;
30
+ #longhandProperties: CSSProperty[] = [];
30
31
 
31
32
  constructor(
32
33
  ownerStyle: CSSStyleDeclaration, index: number, name: string, value: string, important: boolean,
33
- disabled: boolean, parsedOk: boolean, implicit: boolean, text?: string|null, range?: Protocol.CSS.SourceRange) {
34
+ disabled: boolean, parsedOk: boolean, implicit: boolean, text?: string|null, range?: Protocol.CSS.SourceRange,
35
+ longhandProperties?: Protocol.CSS.CSSProperty[]) {
34
36
  this.ownerStyle = ownerStyle;
35
37
  this.index = index;
36
38
  this.name = name;
@@ -44,6 +46,24 @@ export class CSSProperty {
44
46
  this.#active = true;
45
47
  this.#nameRangeInternal = null;
46
48
  this.#valueRangeInternal = null;
49
+
50
+ if (longhandProperties && longhandProperties.length > 0) {
51
+ for (const property of longhandProperties) {
52
+ this.#longhandProperties.push(new CSSProperty(
53
+ ownerStyle, this.#longhandProperties.length, property.name, property.value, important, disabled, parsedOk,
54
+ true));
55
+ }
56
+ } else {
57
+ // Blink would not parse shorthands containing 'var()' functions:
58
+ // https://drafts.csswg.org/css-variables/#variables-in-shorthands).
59
+ // Therefore we manually check if the current property is a shorthand,
60
+ // and fills its longhand components with empty values.
61
+ const longhandNames = cssMetadata().getLonghands(name);
62
+ for (const longhandName of longhandNames || []) {
63
+ this.#longhandProperties.push(new CSSProperty(
64
+ ownerStyle, this.#longhandProperties.length, longhandName, '', important, disabled, parsedOk, true));
65
+ }
66
+ }
47
67
  }
48
68
 
49
69
  static parsePayload(ownerStyle: CSSStyleDeclaration, index: number, payload: Protocol.CSS.CSSProperty): CSSProperty {
@@ -55,7 +75,7 @@ export class CSSProperty {
55
75
  const result = new CSSProperty(
56
76
  ownerStyle, index, payload.name, payload.value, payload.important || false, payload.disabled || false,
57
77
  ('parsedOk' in payload) ? Boolean(payload.parsedOk) : true, Boolean(payload.implicit), payload.text,
58
- payload.range);
78
+ payload.range, payload.longhandProperties);
59
79
  return result;
60
80
  }
61
81
 
@@ -302,4 +322,8 @@ export class CSSProperty {
302
322
  getInvalidStringForInvalidProperty(): Common.UIString.LocalizedString|undefined {
303
323
  return this.#invalidString;
304
324
  }
325
+
326
+ getLonghandProperties(): CSSProperty[] {
327
+ return this.#longhandProperties;
328
+ }
305
329
  }
@@ -62,19 +62,15 @@ export class CSSStyleDeclaration {
62
62
 
63
63
  if (payload.cssText && this.range) {
64
64
  const cssText = new TextUtils.Text.Text(payload.cssText);
65
- let start: {
66
- line: number,
67
- column: number,
68
- }|{
69
- line: number,
70
- column: number,
71
- } = {line: this.range.startLine, column: this.range.startColumn};
65
+ let start = {line: this.range.startLine, column: this.range.startColumn};
72
66
  for (const cssProperty of payload.cssProperties) {
73
67
  const range = cssProperty.range;
74
68
  if (range) {
75
69
  parseUnusedText.call(this, cssText, start.line, start.column, range.startLine, range.startColumn);
76
70
  start = {line: range.endLine, column: range.endColumn};
77
71
  }
72
+ // TODO(changhaohan): we should try not including longhand properties anymore, because
73
+ // they are already included in the longhandProperties field in a shorthand property.
78
74
  this.#allPropertiesInternal.push(
79
75
  CSSProperty.parsePayload(this, this.#allPropertiesInternal.length, cssProperty));
80
76
  }
@@ -303,18 +299,6 @@ export class CSSStyleDeclaration {
303
299
  return property ? property.implicit : false;
304
300
  }
305
301
 
306
- longhandProperties(name: string): CSSProperty[] {
307
- const longhands = cssMetadata().getLonghands(name.toLowerCase());
308
- const result = [];
309
- for (let i = 0; longhands && i < longhands.length; ++i) {
310
- const property = this.#activePropertyMap.get(longhands[i]);
311
- if (property) {
312
- result.push(property);
313
- }
314
- }
315
- return result;
316
- }
317
-
318
302
  propertyAt(index: number): CSSProperty|null {
319
303
  return (index < this.allProperties().length) ? this.allProperties()[index] : null;
320
304
  }
@@ -458,7 +458,7 @@ export class AppManifestView extends UI.Widget.VBox implements SDK.TargetManager
458
458
  this.presentationSection = this.reportView.appendSection(i18nString(UIStrings.presentation));
459
459
  this.protocolHandlersSection = this.reportView.appendSection(i18nString(UIStrings.protocolHandlers));
460
460
  this.protocolHandlersView = new ApplicationComponents.ProtocolHandlersView.ProtocolHandlersView();
461
- this.protocolHandlersSection.contentElement.append(this.protocolHandlersView);
461
+ this.protocolHandlersSection.appendFieldWithCustomView(this.protocolHandlersView);
462
462
  this.iconsSection = this.reportView.appendSection(i18nString(UIStrings.icons), 'report-section-icons');
463
463
  this.shortcutSections = [];
464
464
  this.screenshotsSections = [];
@@ -981,7 +981,8 @@ export class AppManifestTreeElement extends ApplicationPanelTreeElement {
981
981
  for (const section of staticSections) {
982
982
  const sectionElement = section.getTitleElement();
983
983
  const childTitle = section.title();
984
- const child = new ManifestChildTreeElement(this.resourcesPanel, sectionElement, childTitle);
984
+ const sectionFieldElement = section.getFieldElement();
985
+ const child = new ManifestChildTreeElement(this.resourcesPanel, sectionElement, childTitle, sectionFieldElement);
985
986
  this.appendChild(child);
986
987
  }
987
988
  }
@@ -998,12 +999,15 @@ export class AppManifestTreeElement extends ApplicationPanelTreeElement {
998
999
 
999
1000
  export class ManifestChildTreeElement extends ApplicationPanelTreeElement {
1000
1001
  #sectionElement: Element;
1001
- constructor(storagePanel: ResourcesPanel, element: Element, childTitle: string) {
1002
+ #sectionFieldElement: HTMLElement;
1003
+ constructor(storagePanel: ResourcesPanel, element: Element, childTitle: string, fieldElement: HTMLElement) {
1002
1004
  super(storagePanel, childTitle, false);
1003
1005
  const icon = UI.Icon.Icon.create('mediumicon-manifest', 'resource-tree-item');
1004
1006
  this.setLeadingIcons([icon]);
1005
1007
  this.#sectionElement = element;
1008
+ this.#sectionFieldElement = fieldElement;
1006
1009
  self.onInvokeElement(this.listItemElement, this.onInvoke.bind(this));
1010
+ this.listItemElement.addEventListener('keydown', this.onInvokeElementKeydown.bind(this));
1007
1011
  UI.ARIAUtils.setAccessibleName(
1008
1012
  this.listItemElement, i18nString(UIStrings.beforeInvokeAlert, {PH1: this.listItemElement.title}));
1009
1013
  }
@@ -1018,6 +1022,26 @@ export class ManifestChildTreeElement extends ApplicationPanelTreeElement {
1018
1022
  UI.ARIAUtils.alert(i18nString(UIStrings.onInvokeAlert, {PH1: this.listItemElement.title}));
1019
1023
  Host.userMetrics.manifestSectionSelected(this.listItemElement.title);
1020
1024
  }
1025
+ // direct focus to the corresponding element
1026
+ onInvokeElementKeydown(event: KeyboardEvent): void {
1027
+ if (event.key !== 'Tab' || event.shiftKey) {
1028
+ return;
1029
+ }
1030
+ const checkBoxElement = this.#sectionFieldElement.querySelector('.mask-checkbox');
1031
+ let focusableElement: HTMLElement|null = this.#sectionFieldElement.querySelector('[tabindex="0"]');
1032
+ if (checkBoxElement && checkBoxElement.shadowRoot) {
1033
+ focusableElement = checkBoxElement.shadowRoot.querySelector('input') || null;
1034
+ } else if (!focusableElement) {
1035
+ // special case for protocol handler section since it is a custom Element and has different structure than the others
1036
+ focusableElement = this.#sectionFieldElement.querySelector('devtools-protocol-handlers-view')
1037
+ ?.shadowRoot?.querySelector('[tabindex="0"]') ||
1038
+ null;
1039
+ }
1040
+ if (focusableElement) {
1041
+ focusableElement?.focus();
1042
+ event.consume(true);
1043
+ }
1044
+ }
1021
1045
  }
1022
1046
 
1023
1047
  export class ClearStorageTreeElement extends ApplicationPanelTreeElement {
@@ -971,7 +971,7 @@ export class StylePropertiesSection {
971
971
  break;
972
972
  }
973
973
  count++;
974
- const isShorthand = Boolean(style.longhandProperties(property.name).length);
974
+ const isShorthand = property.getLonghandProperties().length > 0;
975
975
  const inherited = this.isPropertyInherited(property.name);
976
976
  const overloaded = this.isPropertyOverloaded(property);
977
977
  if (style.parentRule && style.parentRule.isUserAgent() && inherited) {
@@ -558,19 +558,19 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
558
558
  return;
559
559
  }
560
560
 
561
- const longhandProperties = this.style.longhandProperties(this.name);
561
+ const longhandProperties = this.property.getLonghandProperties();
562
562
  const leadingProperties = this.style.leadingProperties();
563
563
 
564
- for (let i = 0; i < longhandProperties.length; ++i) {
565
- const name = longhandProperties[i].name;
564
+ for (const property of longhandProperties) {
565
+ const name = property.name;
566
566
  let inherited = false;
567
567
  let overloaded = false;
568
568
 
569
569
  const section = this.section();
570
570
  if (section) {
571
571
  inherited = section.isPropertyInherited(name);
572
- overloaded = this.matchedStylesInternal.propertyState(longhandProperties[i]) ===
573
- SDK.CSSMatchedStyles.PropertyState.Overloaded;
572
+ overloaded =
573
+ this.matchedStylesInternal.propertyState(property) === SDK.CSSMatchedStyles.PropertyState.Overloaded;
574
574
  }
575
575
 
576
576
  const leadingProperty = leadingProperties.find(property => property.name === name && property.activeInStyle());
@@ -579,8 +579,7 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
579
579
  }
580
580
 
581
581
  const item = new StylePropertyTreeElement(
582
- this.parentPaneInternal, this.matchedStylesInternal, longhandProperties[i], false, inherited, overloaded,
583
- false);
582
+ this.parentPaneInternal, this.matchedStylesInternal, property, false, inherited, overloaded, false);
584
583
  item.setComputedStyles(this.computedStyles);
585
584
  item.setParentsComputedStyles(this.parentsComputedStyles);
586
585
  this.appendChild(item);
@@ -130,6 +130,13 @@ export class Section extends VBox {
130
130
  return this.titleElement;
131
131
  }
132
132
 
133
+ getFieldElement(): HTMLElement {
134
+ return this.fieldList;
135
+ }
136
+ appendFieldWithCustomView(customElement: HTMLElement): void {
137
+ this.fieldList.append(customElement);
138
+ }
139
+
133
140
  setTitle(title: string, tooltip?: string): void {
134
141
  if (this.titleElement.textContent !== title) {
135
142
  this.titleElement.textContent = title;
package/package.json CHANGED
@@ -56,5 +56,5 @@
56
56
  "unittest": "scripts/test/run_unittests.py --no-text-coverage",
57
57
  "watch": "vpython third_party/node/node.py --output scripts/watch_build.js"
58
58
  },
59
- "version": "1.0.1039659"
59
+ "version": "1.0.1040084"
60
60
  }