Skip to content

Commit 62831c2

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Make ProgressIndicator a custom element.
Bypass-Check-License: only changing existing files Bug: 407750483 Change-Id: If8438b6693ed2210576c4551af9b24a0c62f0019 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6870375 Auto-Submit: Danil Somsikov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Danil Somsikov <[email protected]>
1 parent 5ab7c67 commit 62831c2

File tree

7 files changed

+64
-58
lines changed

7 files changed

+64
-58
lines changed

front_end/models/har/Writer.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import '../../ui/legacy/legacy.js';
6+
57
import * as Common from '../../core/common/common.js';
68
import * as Platform from '../../core/platform/platform.js';
79
import * as SDK from '../../core/sdk/sdk.js';
810
import type * as Protocol from '../../generated/protocol.js';
911
import {describeWithLocale} from '../../testing/EnvironmentHelpers.js';
10-
import * as UI from '../../ui/legacy/legacy.js';
1112
import * as HAR from '../har/har.js';
1213
import * as TextUtils from '../text_utils/text_utils.js';
1314

@@ -31,7 +32,7 @@ describeWithLocale('HARWriter', () => {
3132
const req2 = simulateRequestWithStartTime(req2Time.getTime() / 1000);
3233
const req3 = simulateRequestWithStartTime(req3Time.getTime() / 1000);
3334

34-
const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
35+
const progressIndicator = document.createElement('devtools-progress');
3536
const compositeProgress = new Common.Progress.CompositeProgress(progressIndicator);
3637
const result = await HAR.Writer.Writer.harStringForRequests(
3738
[

front_end/panels/console/ConsoleView.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ export class ConsoleView extends UI.Widget.VBox implements
12151215
Platform.DevToolsPath.RawPathString;
12161216
const stream = new Bindings.FileUtils.FileOutputStream();
12171217

1218-
const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
1218+
const progressIndicator = document.createElement('devtools-progress');
12191219
progressIndicator.setTitle(i18nString(UIStrings.writingFile));
12201220
progressIndicator.setTotalWork(this.itemCount());
12211221

@@ -1224,7 +1224,7 @@ export class ConsoleView extends UI.Widget.VBox implements
12241224
if (!await stream.open(filename)) {
12251225
return;
12261226
}
1227-
this.progressToolbarItem.element.appendChild(progressIndicator.element);
1227+
this.progressToolbarItem.element.appendChild(progressIndicator);
12281228

12291229
let messageIndex = 0;
12301230
while (messageIndex < this.itemCount() && !progressIndicator.isCanceled()) {
@@ -1518,10 +1518,10 @@ export class ConsoleView extends UI.Widget.VBox implements
15181518
this.searchShouldJumpBackwards = Boolean(jumpBackwards);
15191519
}
15201520

1521-
this.searchProgressIndicator = new UI.ProgressIndicator.ProgressIndicator();
1521+
this.searchProgressIndicator = document.createElement('devtools-progress');
15221522
this.searchProgressIndicator.setTitle(i18nString(UIStrings.searching));
15231523
this.searchProgressIndicator.setTotalWork(this.visibleViewMessages.length);
1524-
this.progressToolbarItem.element.appendChild(this.searchProgressIndicator.element);
1524+
this.progressToolbarItem.element.appendChild(this.searchProgressIndicator);
15251525

15261526
this.innerSearch(0);
15271527
}

front_end/panels/mobile_throttling/ThrottlingSettingsTab.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ export class CPUThrottlingCard {
258258

259259
this.textEl = this.calibrateEl.createChild('div', 'text-container');
260260

261-
this.progress = new UI.ProgressIndicator.ProgressIndicator({showStopButton: false});
262-
this.calibrateEl.append(this.progress.element);
261+
this.progress = this.calibrateEl.createChild('devtools-progress');
262+
this.progress.setAttribute('no-stop-button', '');
263263

264264
this.updateState();
265265
}
@@ -288,7 +288,7 @@ export class CPUThrottlingCard {
288288
this.calibrateButton.style.display = 'none';
289289
this.textEl.style.display = 'none';
290290
this.cancelButton.style.display = 'none';
291-
this.progress.element.style.display = 'none';
291+
this.progress.style.display = 'none';
292292

293293
if (this.state === 'cta') {
294294
this.calibrateButton.style.display = '';
@@ -314,7 +314,7 @@ export class CPUThrottlingCard {
314314
this.textEl.append(this.createTextWithIcon(i18nString(UIStrings.calibrationConfirmationPrompt), 'info'));
315315
} else if (this.state === 'calibrating') {
316316
this.cancelButton.style.display = '';
317-
this.progress.element.style.display = '';
317+
this.progress.style.display = '';
318318
}
319319

320320
const resultToString = (result: number|SDK.CPUThrottlingManager.CalibrationError|undefined): string => {

front_end/panels/network/NetworkLogView.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,7 @@ export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes,
19721972
return;
19731973
}
19741974

1975-
const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
1976-
this.progressBarContainer.appendChild(progressIndicator.element);
1975+
const progressIndicator = this.progressBarContainer.createChild('devtools-progress');
19771976
await HAR.Writer.Writer.write(stream, this.harRequests(), options, progressIndicator);
19781977
progressIndicator.done();
19791978
void stream.close();

front_end/panels/search/SearchView.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ export class SearchView extends UI.Widget.VBox {
336336
if (this.progressIndicator) {
337337
this.progressIndicator.done();
338338
}
339-
this.progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
339+
this.progressIndicator = document.createElement('devtools-progress');
340340
this.searchMessageElement.textContent = i18nString(UIStrings.indexing);
341-
this.progressIndicator.show(this.searchProgressPlaceholderElement);
341+
this.searchProgressPlaceholderElement.appendChild(this.progressIndicator);
342342
if (this.searchScope) {
343343
this.searchScope.performIndexing(
344344
new Common.Progress.ProgressProxy(this.progressIndicator, this.onIndexingFinished.bind(this)));
@@ -396,7 +396,7 @@ export class SearchView extends UI.Widget.VBox {
396396
if (this.progressIndicator) {
397397
this.progressIndicator.done();
398398
}
399-
this.progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
399+
this.progressIndicator = document.createElement('devtools-progress');
400400
this.searchStarted(this.progressIndicator);
401401
if (this.searchScope) {
402402
void this.searchScope.performSearch(
@@ -432,7 +432,7 @@ export class SearchView extends UI.Widget.VBox {
432432
}
433433
this.showPane(this.searchingView);
434434
this.searchMessageElement.textContent = i18nString(UIStrings.searching);
435-
progressIndicator.show(this.searchProgressPlaceholderElement);
435+
this.searchProgressPlaceholderElement.appendChild(progressIndicator);
436436
this.updateSearchResultsMessage();
437437
}
438438

front_end/ui/legacy/ProgressIndicator.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,80 +28,86 @@
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
/* eslint-disable rulesdir/no-imperative-dom-api */
32-
3331
import type * as Common from '../../core/common/common.js';
3432

3533
import progressIndicatorStyles from './progressIndicator.css.js';
3634
import {createShadowRootWithCoreStyles} from './UIUtils.js';
3735

38-
export class ProgressIndicator implements Common.Progress.Progress {
39-
element: HTMLDivElement;
40-
private readonly shadowRoot: ShadowRoot;
41-
private readonly contentElement: Element;
42-
private labelElement: Element;
43-
private progressElement: HTMLProgressElement;
44-
private readonly stopButton?: Element;
45-
private isCanceledInternal: boolean;
46-
private worked: number;
47-
private isDone?: boolean;
48-
49-
constructor(options = {showStopButton: true}) {
50-
this.element = document.createElement('div');
51-
this.element.classList.add('progress-indicator');
52-
this.shadowRoot = createShadowRootWithCoreStyles(this.element, {cssFile: progressIndicatorStyles});
53-
this.contentElement = this.shadowRoot.createChild('div', 'progress-indicator-shadow-container');
54-
55-
this.labelElement = this.contentElement.createChild('div', 'title');
56-
this.progressElement = this.contentElement.createChild('progress');
57-
this.progressElement.value = 0;
58-
59-
if (options.showStopButton) {
60-
this.stopButton = this.contentElement.createChild('button', 'progress-indicator-shadow-stop-button');
61-
this.stopButton.addEventListener('click', this.cancel.bind(this));
36+
export class ProgressIndicator extends HTMLElement implements Common.Progress.Progress {
37+
readonly #shadowRoot: ShadowRoot;
38+
readonly #contentElement: Element;
39+
#labelElement: Element;
40+
#progressElement: HTMLProgressElement;
41+
readonly #stopButton?: Element;
42+
#isCanceled = false;
43+
#worked: number;
44+
#isDone = false;
45+
46+
constructor() {
47+
super();
48+
this.#shadowRoot = createShadowRootWithCoreStyles(this, {cssFile: progressIndicatorStyles});
49+
this.#contentElement = this.#shadowRoot.createChild('div', 'progress-indicator-shadow-container');
50+
51+
this.#labelElement = this.#contentElement.createChild('div', 'title');
52+
this.#progressElement = this.#contentElement.createChild('progress') as HTMLProgressElement;
53+
this.#progressElement.value = 0;
54+
55+
// By default we show the stop button, but this can be controlled by
56+
// using the 'no-stop-button' attribute on the element.
57+
if (!this.hasAttribute('no-stop-button')) {
58+
this.#stopButton = this.#contentElement.createChild('button', 'progress-indicator-shadow-stop-button');
59+
this.#stopButton.addEventListener('click', this.cancel.bind(this));
6260
}
6361

64-
this.isCanceledInternal = false;
65-
this.worked = 0;
62+
this.#isCanceled = false;
63+
this.#worked = 0;
6664
}
6765

68-
show(parent: Element): void {
69-
parent.appendChild(this.element);
66+
connectedCallback(): void {
67+
this.classList.add('progress-indicator');
7068
}
7169

7270
done(): void {
73-
if (this.isDone) {
71+
if (this.#isDone) {
7472
return;
7573
}
76-
this.isDone = true;
77-
this.element.remove();
74+
this.#isDone = true;
75+
this.remove();
7876
}
7977

8078
cancel(): void {
81-
this.isCanceledInternal = true;
79+
this.#isCanceled = true;
8280
}
8381

8482
isCanceled(): boolean {
85-
return this.isCanceledInternal;
83+
return this.#isCanceled;
8684
}
8785

8886
setTitle(title: string): void {
89-
this.labelElement.textContent = title;
87+
this.#labelElement.textContent = title;
9088
}
9189

9290
setTotalWork(totalWork: number): void {
93-
this.progressElement.max = totalWork;
91+
this.#progressElement.max = totalWork;
9492
}
9593

9694
setWorked(worked: number, title?: string): void {
97-
this.worked = worked;
98-
this.progressElement.value = worked;
95+
this.#worked = worked;
96+
this.#progressElement.value = worked;
9997
if (title) {
10098
this.setTitle(title);
10199
}
102100
}
103101

104102
incrementWorked(worked?: number): void {
105-
this.setWorked(this.worked + (worked || 1));
103+
this.setWorked(this.#worked + (worked || 1));
104+
}
105+
}
106+
107+
customElements.define('devtools-progress', ProgressIndicator);
108+
109+
declare global {
110+
interface HTMLElementTagNameMap {
111+
'devtools-progress': ProgressIndicator;
106112
}
107113
}

front_end/ui/legacy/components/source_frame/SourceFrame.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,10 @@ export class SourceFrameImpl extends Common.ObjectWrapper.eventMixin<EventTypes,
551551

552552
protected async setContentDataOrError(contentDataPromise: Promise<TextUtils.ContentData.ContentDataOrError>):
553553
Promise<void> {
554-
const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
554+
const progressIndicator = document.createElement('devtools-progress');
555555
progressIndicator.setTitle(i18nString(UIStrings.loading));
556556
progressIndicator.setTotalWork(100);
557-
this.progressToolbarItem.element.appendChild(progressIndicator.element);
557+
this.progressToolbarItem.element.appendChild(progressIndicator);
558558

559559
progressIndicator.setWorked(1);
560560
const contentData = await contentDataPromise;

0 commit comments

Comments
 (0)