Skip to content

Commit 7eaf391

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[Elements] Create one ComputedStyleModel instance per ElementsPanel
We're going to track ComputedStyleUpdated events for nodes when the Styles tab is open now too in addition to tracking it only when the ComputedStylesWidget is open. So, for managing this behavior, I'm moving `ComputedStyleModel` creation to ElementsPanel and will use the common model to manage the tracking of computed style updated events for nodes (Calling `trackComputedStyleUpdatesForNode`). Bug: 349566291 Change-Id: I2cededce15d6f1c6178218246144a484012b3a31 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6089092 Reviewed-by: Changhao Han <[email protected]> Auto-Submit: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Commit-Queue: Changhao Han <[email protected]>
1 parent d014fcc commit 7eaf391

11 files changed

+41
-27
lines changed

front_end/panels/elements/ComputedStyleModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export class ComputedStyleModel extends Common.ObjectWrapper.ObjectWrapper<Event
1414
private computedStylePromise?: Promise<ComputedStyle|null>;
1515
constructor() {
1616
super();
17-
this.nodeInternal = UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode);
1817
this.cssModelInternal = null;
1918
this.eventListeners = [];
19+
this.nodeInternal = UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode);
2020
UI.Context.Context.instance().addFlavorChangeListener(SDK.DOMModel.DOMNode, this.onNodeChanged, this);
2121
}
2222

front_end/panels/elements/ComputedStyleWidget.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import * as Elements from './elements.js';
1111

1212
describeWithMockConnection('ComputedStyleWidget', () => {
1313
let target: SDK.Target.Target;
14+
let computedStyleModel: Elements.ComputedStyleModel.ComputedStyleModel;
1415
let view: Elements.ComputedStyleWidget.ComputedStyleWidget;
1516
let trackComputedStyleUpdatesForNodeSpy: sinon.SinonSpy;
1617

1718
beforeEach(() => {
1819
stubNoopSettings();
1920
target = createTarget();
21+
computedStyleModel = new Elements.ComputedStyleModel.ComputedStyleModel();
2022
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, null);
2123
trackComputedStyleUpdatesForNodeSpy =
2224
sinon.spy(SDK.CSSModel.CSSModel.prototype, 'trackComputedStyleUpdatesForNode');
@@ -34,7 +36,7 @@ describeWithMockConnection('ComputedStyleWidget', () => {
3436
assert.exists(model);
3537
const node = new SDK.DOMModel.DOMNode(model);
3638
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, node);
37-
view = new Elements.ComputedStyleWidget.ComputedStyleWidget();
39+
view = new Elements.ComputedStyleWidget.ComputedStyleWidget(computedStyleModel);
3840
view.markAsRoot();
3941
view.show(document.body);
4042

@@ -46,7 +48,7 @@ describeWithMockConnection('ComputedStyleWidget', () => {
4648
assert.exists(model);
4749
const node = new SDK.DOMModel.DOMNode(model);
4850
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, node);
49-
view = new Elements.ComputedStyleWidget.ComputedStyleWidget();
51+
view = new Elements.ComputedStyleWidget.ComputedStyleWidget(computedStyleModel);
5052
view.markAsRoot();
5153
view.show(document.body);
5254

@@ -62,7 +64,7 @@ describeWithMockConnection('ComputedStyleWidget', () => {
6264
assert.exists(model);
6365
const node = new SDK.DOMModel.DOMNode(model);
6466
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, node);
65-
view = new Elements.ComputedStyleWidget.ComputedStyleWidget();
67+
view = new Elements.ComputedStyleWidget.ComputedStyleWidget(computedStyleModel);
6668
view.markAsRoot();
6769
view.show(document.body);
6870
view.hideWidget();

front_end/panels/elements/ComputedStyleWidget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import * as UI from '../../ui/legacy/legacy.js';
4242
import * as LitHtml from '../../ui/lit-html/lit-html.js';
4343

4444
import * as ElementsComponents from './components/components.js';
45-
import {type ComputedStyle, ComputedStyleModel, Events} from './ComputedStyleModel.js';
45+
import {type ComputedStyle, type ComputedStyleModel, Events} from './ComputedStyleModel.js';
4646
import computedStyleSidebarPaneStyles from './computedStyleSidebarPane.css.js';
4747
import {ImagePreviewPopover} from './ImagePreviewPopover.js';
4848
import {PlatformFontsWidget} from './PlatformFontsWidget.js';
@@ -242,12 +242,12 @@ export class ComputedStyleWidget extends UI.ThrottledWidget.ThrottledWidget {
242242
#computedStylesTree = new TreeOutline.TreeOutline.TreeOutline<ComputedStyleData>();
243243
#treeData?: TreeOutline.TreeOutline.TreeOutlineData<ComputedStyleData>;
244244

245-
constructor() {
245+
constructor(computedStyleModel: ComputedStyleModel) {
246246
super(true);
247247

248248
this.contentElement.classList.add('styles-sidebar-computed-style-widget');
249249

250-
this.computedStyleModel = new ComputedStyleModel();
250+
this.computedStyleModel = computedStyleModel;
251251
this.computedStyleModel.addEventListener(Events.CSS_MODEL_CHANGED, this.update, this);
252252

253253
this.showInheritedComputedStylePropertiesSetting =

front_end/panels/elements/ElementsPanel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import type {AXTreeNodeData} from './AccessibilityTreeUtils.js';
4949
import {AccessibilityTreeView} from './AccessibilityTreeView.js';
5050
import {ColorSwatchPopoverIcon} from './ColorSwatchPopoverIcon.js';
5151
import * as ElementsComponents from './components/components.js';
52+
import {ComputedStyleModel} from './ComputedStyleModel.js';
5253
import {ComputedStyleWidget} from './ComputedStyleWidget.js';
5354
import elementsPanelStyles from './elementsPanel.css.js';
5455
import type {ElementsTreeElement} from './ElementsTreeElement.js';
@@ -279,9 +280,10 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
279280

280281
crumbsContainer.appendChild(this.breadcrumbs);
281282

282-
this.stylesWidget = new StylesSidebarPane();
283-
this.computedStyleWidget = new ComputedStyleWidget();
284-
this.metricsWidget = new MetricsSidebarPane();
283+
const computedStyleModel = new ComputedStyleModel();
284+
this.stylesWidget = new StylesSidebarPane(computedStyleModel);
285+
this.computedStyleWidget = new ComputedStyleWidget(computedStyleModel);
286+
this.metricsWidget = new MetricsSidebarPane(computedStyleModel);
285287

286288
Common.Settings.Settings.instance()
287289
.moduleSetting('sidebar-position')

front_end/panels/elements/ElementsSidebarPane.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import * as Common from '../../core/common/common.js';
66
import type * as SDK from '../../core/sdk/sdk.js';
77
import * as UI from '../../ui/legacy/legacy.js';
88

9-
import {ComputedStyleModel, type CSSModelChangedEvent, Events} from './ComputedStyleModel.js';
9+
import {type ComputedStyleModel, type CSSModelChangedEvent, Events} from './ComputedStyleModel.js';
1010

1111
export class ElementsSidebarPane extends UI.Widget.VBox {
1212
protected computedStyleModelInternal: ComputedStyleModel;
1313
private readonly updateThrottler: Common.Throttler.Throttler;
1414
private updateWhenVisible: boolean;
15-
constructor(delegatesFocus?: boolean) {
15+
constructor(computedStyleModel: ComputedStyleModel, delegatesFocus?: boolean) {
1616
super(true, delegatesFocus);
1717
this.element.classList.add('flex-none');
18-
this.computedStyleModelInternal = new ComputedStyleModel();
18+
this.computedStyleModelInternal = computedStyleModel;
1919
this.computedStyleModelInternal.addEventListener(Events.CSS_MODEL_CHANGED, this.onCSSModelChanged, this);
2020

2121
this.updateThrottler = new Common.Throttler.Throttler(100);

front_end/panels/elements/MetricsSidebarPane.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as SDK from '../../core/sdk/sdk.js';
3636
import * as UI from '../../ui/legacy/legacy.js';
3737
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
3838

39+
import type {ComputedStyleModel} from './ComputedStyleModel.js';
3940
import {ElementsSidebarPane} from './ElementsSidebarPane.js';
4041
import metricsSidebarPaneStyles from './metricsSidebarPane.css.js';
4142

@@ -51,8 +52,8 @@ export class MetricsSidebarPane extends ElementsSidebarPane {
5152
}[];
5253
private isEditingMetrics?: boolean;
5354

54-
constructor() {
55-
super();
55+
constructor(computedStyleModel: ComputedStyleModel) {
56+
super(computedStyleModel);
5657

5758
this.originalPropertyData = null;
5859
this.previousPropertyDataCandidate = null;

front_end/panels/elements/StylePropertiesSection.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ function setUpStyles(
8282
}
8383

8484
describeWithMockConnection('StylesPropertySection', () => {
85+
let computedStyleModel: Elements.ComputedStyleModel.ComputedStyleModel;
86+
beforeEach(() => {
87+
computedStyleModel = new Elements.ComputedStyleModel.ComputedStyleModel();
88+
});
89+
8590
it('displays the proper sourceURL origin for constructed stylesheets', async () => {
8691
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
8792
assert.exists(cssModel);
@@ -161,7 +166,7 @@ describeWithMockConnection('StylesPropertySection', () => {
161166
Common.Settings.Settings.instance().moduleSetting('text-editor-indent').set(' ');
162167
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
163168
assert.exists(cssModel);
164-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
169+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
165170
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
166171
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
167172
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -214,7 +219,7 @@ describeWithMockConnection('StylesPropertySection', () => {
214219
it('updates property rule property names', async () => {
215220
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
216221
assert.exists(cssModel);
217-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
222+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
218223
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
219224
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
220225
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -274,7 +279,7 @@ describeWithMockConnection('StylesPropertySection', () => {
274279
Common.Settings.Settings.instance().moduleSetting('text-editor-indent').set(' ');
275280
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
276281
assert.exists(cssModel);
277-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
282+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
278283
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
279284
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
280285
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -302,7 +307,7 @@ describeWithMockConnection('StylesPropertySection', () => {
302307
it('renders active and inactive position-try rule sections correctly', async () => {
303308
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
304309
assert.exists(cssModel);
305-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
310+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
306311
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
307312
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
308313
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};

front_end/panels/elements/StylePropertyHighlighter.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describeWithMockConnection('StylePropertyHighlighter', () => {
1717
}> {
1818
const target = createTarget();
1919
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, sinon.createStubInstance(SDK.DOMModel.DOMNode));
20-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
20+
const computedStyleModel = new Elements.ComputedStyleModel.ComputedStyleModel();
21+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
2122
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
2223
cssModel: target.model(SDK.CSSModel.CSSModel)!,
2324
node: stylesSidebarPane.node() as SDK.DOMModel.DOMNode,

front_end/panels/elements/StylePropertyTreeElement.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import * as Elements from './elements.js';
2121

2222
describeWithMockConnection('StylePropertyTreeElement', () => {
2323
let stylesSidebarPane: Elements.StylesSidebarPane.StylesSidebarPane;
24+
let computedStyleModel: Elements.ComputedStyleModel.ComputedStyleModel;
2425
let mockStylePropertiesSection: sinon.SinonStubbedInstance<Elements.StylePropertiesSection.StylePropertiesSection>;
2526
let mockCssStyleDeclaration: sinon.SinonStubbedInstance<SDK.CSSStyleDeclaration.CSSStyleDeclaration>;
2627
let mockMatchedStyles: sinon.SinonStubbedInstance<SDK.CSSMatchedStyles.CSSMatchedStyles>;
2728
let mockVariableMap: Record<string, string>;
2829

2930
beforeEach(async () => {
30-
stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
31+
computedStyleModel = new Elements.ComputedStyleModel.ComputedStyleModel();
32+
stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane(computedStyleModel);
3133
mockVariableMap = {
3234
'--a': 'red',
3335
'--b': 'blue',

front_end/panels/elements/StylesSidebarPane.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ describe('StylesSidebarPane', () => {
4949

5050
describe('rebuildSectionsForMatchedStyleRulesForTest', () => {
5151
it('should add @position-try section', async () => {
52-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
52+
const stylesSidebarPane =
53+
new Elements.StylesSidebarPane.StylesSidebarPane(new Elements.ComputedStyleModel.ComputedStyleModel());
5354
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
5455
cssModel: stylesSidebarPane.cssModel() as SDK.CSSModel.CSSModel,
5556
node: sinon.createStubInstance(SDK.DOMModel.DOMNode),
@@ -87,7 +88,8 @@ describe('StylesSidebarPane', () => {
8788
});
8889

8990
it('should add @font-palette-values section to the end', async () => {
90-
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
91+
const stylesSidebarPane =
92+
new Elements.StylesSidebarPane.StylesSidebarPane(new Elements.ComputedStyleModel.ComputedStyleModel());
9193
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
9294
cssModel: stylesSidebarPane.cssModel() as SDK.CSSModel.CSSModel,
9395
node: sinon.createStubInstance(SDK.DOMModel.DOMNode),

0 commit comments

Comments
 (0)