Skip to content

Commit e84aed6

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[Elements] Convert StylesSidebarPane to a regular class
ElementsPanel already is a singleton and we can provide access to the StylesSidebarPanel it rendered through it. This way, we can control the lifecycle of the StylesSidebarPane directly from the ElementsPanel and do not need to have a singleton class for it. Bug: 349566291 Change-Id: Ie1ee75677a305712d482812ad910bc38c583afd9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6069998 Commit-Queue: Ergün Erdoğmuş <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]> Reviewed-by: Changhao Han <[email protected]>
1 parent 996df8a commit e84aed6

File tree

6 files changed

+11
-22
lines changed

6 files changed

+11
-22
lines changed

front_end/panels/elements/ElementsPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export class ElementsPanel extends UI.Panel.Panel implements UI.SearchableView.S
279279

280280
crumbsContainer.appendChild(this.breadcrumbs);
281281

282-
this.stylesWidget = StylesSidebarPane.instance();
282+
this.stylesWidget = new StylesSidebarPane();
283283
this.computedStyleWidget = new ComputedStyleWidget();
284284
this.metricsWidget = new MetricsSidebarPane();
285285

front_end/panels/elements/StylePropertiesSection.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describeWithMockConnection('StylesPropertySection', () => {
161161
Common.Settings.Settings.instance().moduleSetting('text-editor-indent').set(' ');
162162
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
163163
assert.exists(cssModel);
164-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
164+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
165165
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
166166
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
167167
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -214,7 +214,7 @@ describeWithMockConnection('StylesPropertySection', () => {
214214
it('updates property rule property names', async () => {
215215
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
216216
assert.exists(cssModel);
217-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
217+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
218218
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
219219
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
220220
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -274,7 +274,7 @@ describeWithMockConnection('StylesPropertySection', () => {
274274
Common.Settings.Settings.instance().moduleSetting('text-editor-indent').set(' ');
275275
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
276276
assert.exists(cssModel);
277-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
277+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
278278
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
279279
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
280280
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};
@@ -302,7 +302,7 @@ describeWithMockConnection('StylesPropertySection', () => {
302302
it('renders active and inactive position-try rule sections correctly', async () => {
303303
const cssModel = createTarget().model(SDK.CSSModel.CSSModel);
304304
assert.exists(cssModel);
305-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
305+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
306306
const origin = Protocol.CSS.StyleSheetOrigin.Regular;
307307
const styleSheetId = '0' as Protocol.CSS.StyleSheetId;
308308
const range = {startLine: 0, startColumn: 0, endLine: 0, endColumn: 6};

front_end/panels/elements/StylePropertyHighlighter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describeWithMockConnection('StylePropertyHighlighter', () => {
1717
}> {
1818
const target = createTarget();
1919
UI.Context.Context.instance().setFlavor(SDK.DOMModel.DOMNode, sinon.createStubInstance(SDK.DOMModel.DOMNode));
20-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
20+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
2121
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
2222
cssModel: target.model(SDK.CSSModel.CSSModel)!,
2323
node: stylesSidebarPane.node() as SDK.DOMModel.DOMNode,

front_end/panels/elements/StylePropertyTreeElement.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
2727
let mockVariableMap: Record<string, string>;
2828

2929
beforeEach(async () => {
30-
stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
30+
stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
3131
mockVariableMap = {
3232
'--a': 'red',
3333
'--b': 'blue',

front_end/panels/elements/StylesSidebarPane.test.ts

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

5050
describe('rebuildSectionsForMatchedStyleRulesForTest', () => {
5151
it('should add @position-try section', async () => {
52-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
52+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
5353
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
5454
cssModel: stylesSidebarPane.cssModel() as SDK.CSSModel.CSSModel,
5555
node: sinon.createStubInstance(SDK.DOMModel.DOMNode),
@@ -87,7 +87,7 @@ describe('StylesSidebarPane', () => {
8787
});
8888

8989
it('should add @font-palette-values section to the end', async () => {
90-
const stylesSidebarPane = Elements.StylesSidebarPane.StylesSidebarPane.instance({forceNew: true});
90+
const stylesSidebarPane = new Elements.StylesSidebarPane.StylesSidebarPane();
9191
const matchedStyles = await SDK.CSSMatchedStyles.CSSMatchedStyles.create({
9292
cssModel: stylesSidebarPane.cssModel() as SDK.CSSModel.CSSModel,
9393
node: sinon.createStubInstance(SDK.DOMModel.DOMNode),

front_end/panels/elements/StylesSidebarPane.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ const HIGHLIGHTABLE_PROPERTIES = [
185185
{mode: 'flexibility', properties: ['flex', 'flex-basis', 'flex-grow', 'flex-shrink']},
186186
];
187187

188-
let stylesSidebarPaneInstance: StylesSidebarPane;
189-
190188
export class StylesSidebarPane extends Common.ObjectWrapper.eventMixin<EventTypes, typeof ElementsSidebarPane>(
191189
ElementsSidebarPane) {
192190
private currentToolbarPane: UI.Widget.Widget|null;
@@ -230,13 +228,6 @@ export class StylesSidebarPane extends Common.ObjectWrapper.eventMixin<EventType
230228
#updateAbortController?: AbortController;
231229
#updateComputedStylesAbortController?: AbortController;
232230

233-
static instance(opts?: {forceNew: boolean}): StylesSidebarPane {
234-
if (!stylesSidebarPaneInstance || opts?.forceNew) {
235-
stylesSidebarPaneInstance = new StylesSidebarPane();
236-
}
237-
return stylesSidebarPaneInstance;
238-
}
239-
240231
constructor() {
241232
super(true /* delegatesFocus */);
242233
this.setMinimumSize(96, 26);
@@ -281,7 +272,6 @@ export class StylesSidebarPane extends Common.ObjectWrapper.eventMixin<EventType
281272
this.sectionBlocks = [];
282273
this.idleCallbackManager = null;
283274
this.needsForceUpdate = false;
284-
stylesSidebarPaneInstance = this;
285275
UI.Context.Context.instance().addFlavorChangeListener(SDK.DOMModel.DOMNode, this.forceUpdate, this);
286276
this.contentElement.addEventListener('copy', this.clipboardCopy.bind(this));
287277
this.resizeThrottler = new Common.Throttler.Throttler(100);
@@ -2199,7 +2189,7 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
21992189
switch (actionId) {
22002190
case 'elements.new-style-rule': {
22012191
Host.userMetrics.actionTaken(Host.UserMetrics.Action.NewStyleRuleAdded);
2202-
void StylesSidebarPane.instance().createNewRuleInViaInspectorStyleSheet();
2192+
void ElementsPanel.instance().stylesWidget.createNewRuleInViaInspectorStyleSheet();
22032193
return true;
22042194
}
22052195
}
@@ -2208,7 +2198,6 @@ export class ActionDelegate implements UI.ActionRegistration.ActionDelegate {
22082198
}
22092199

22102200
let buttonProviderInstance: ButtonProvider;
2211-
22122201
export class ButtonProvider implements UI.Toolbar.Provider {
22132202
private readonly button: UI.Toolbar.ToolbarButton;
22142203
private constructor() {
@@ -2238,7 +2227,7 @@ export class ButtonProvider implements UI.Toolbar.Provider {
22382227
}
22392228

22402229
private longClicked(event: Event): void {
2241-
StylesSidebarPane.instance().onAddButtonLongClick(event);
2230+
ElementsPanel.instance().stylesWidget.onAddButtonLongClick(event);
22422231
}
22432232

22442233
item(): UI.Toolbar.ToolbarItem {

0 commit comments

Comments
 (0)