Skip to content

Commit 587c5f4

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[cleanup] Use JS private and move declarations to constructor
Also removes `Internal` suffixes and `inner` prefixes, as the `#` indicates that they are private. Bug: none Bypass-Check-License: Only updates files, no new files are added. Change-Id: I7428a699d7ff0df78420ceb360a200acdcf6a786 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6862694 Reviewed-by: Kateryna Prokopenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent c0e9060 commit 587c5f4

File tree

2 files changed

+381
-405
lines changed

2 files changed

+381
-405
lines changed

front_end/ui/legacy/ResizerWidget.ts

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,54 @@ import * as Common from '../../core/common/common.js';
77
import {elementDragStart} from './UIUtils.js';
88

99
export class ResizerWidget extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
10-
private isEnabledInternal = true;
11-
private elementsInternal = new Set<HTMLElement>();
12-
private readonly installDragOnMouseDownBound: (event: Event) => false | undefined;
13-
private cursorInternal: string;
14-
private startX?: number;
15-
private startY?: number;
10+
#isEnabled = true;
11+
#elements = new Set<HTMLElement>();
12+
readonly #installDragOnMouseDownBound: (event: Event) => false | undefined;
13+
#cursor = 'nwse-resize';
14+
#startX?: number;
15+
#startY?: number;
1616

1717
constructor() {
1818
super();
1919

20-
this.installDragOnMouseDownBound = this.installDragOnMouseDown.bind(this);
21-
this.cursorInternal = 'nwse-resize';
20+
this.#installDragOnMouseDownBound = this.#installDragOnMouseDown.bind(this);
2221
}
2322

2423
isEnabled(): boolean {
25-
return this.isEnabledInternal;
24+
return this.#isEnabled;
2625
}
2726

2827
setEnabled(enabled: boolean): void {
29-
this.isEnabledInternal = enabled;
28+
this.#isEnabled = enabled;
3029
this.updateElementCursors();
3130
}
3231

3332
elements(): Element[] {
34-
return [...this.elementsInternal];
33+
return [...this.#elements];
3534
}
3635

3736
addElement(element: HTMLElement): void {
38-
if (!this.elementsInternal.has(element)) {
39-
this.elementsInternal.add(element);
40-
element.addEventListener('pointerdown', this.installDragOnMouseDownBound, false);
41-
this.updateElementCursor(element);
37+
if (!this.#elements.has(element)) {
38+
this.#elements.add(element);
39+
element.addEventListener('pointerdown', this.#installDragOnMouseDownBound, false);
40+
this.#updateElementCursor(element);
4241
}
4342
}
4443

4544
removeElement(element: HTMLElement): void {
46-
if (this.elementsInternal.has(element)) {
47-
this.elementsInternal.delete(element);
48-
element.removeEventListener('pointerdown', this.installDragOnMouseDownBound, false);
45+
if (this.#elements.has(element)) {
46+
this.#elements.delete(element);
47+
element.removeEventListener('pointerdown', this.#installDragOnMouseDownBound, false);
4948
element.style.removeProperty('cursor');
5049
}
5150
}
5251

5352
updateElementCursors(): void {
54-
this.elementsInternal.forEach(this.updateElementCursor.bind(this));
53+
this.#elements.forEach(this.#updateElementCursor.bind(this));
5554
}
5655

57-
private updateElementCursor(element: HTMLElement): void {
58-
if (this.isEnabledInternal) {
56+
#updateElementCursor(element: HTMLElement): void {
57+
if (this.#isEnabled) {
5958
element.style.setProperty('cursor', this.cursor());
6059
element.style.setProperty('touch-action', 'none');
6160
} else {
@@ -65,46 +64,46 @@ export class ResizerWidget extends Common.ObjectWrapper.ObjectWrapper<EventTypes
6564
}
6665

6766
cursor(): string {
68-
return this.cursorInternal;
67+
return this.#cursor;
6968
}
7069

7170
setCursor(cursor: string): void {
72-
this.cursorInternal = cursor;
71+
this.#cursor = cursor;
7372
this.updateElementCursors();
7473
}
7574

76-
private installDragOnMouseDown(event: Event): false|undefined {
75+
#installDragOnMouseDown(event: Event): false|undefined {
7776
const element = (event.target as HTMLElement);
7877
// Only handle drags of the nodes specified.
79-
if (!this.elementsInternal.has(element)) {
78+
if (!this.#elements.has(element)) {
8079
return false;
8180
}
82-
elementDragStart(element, this.dragStart.bind(this), event => {
83-
this.drag(event);
84-
}, this.dragEnd.bind(this), this.cursor(), event);
81+
elementDragStart(element, this.#dragStart.bind(this), event => {
82+
this.#drag(event);
83+
}, this.#dragEnd.bind(this), this.cursor(), event);
8584
return undefined;
8685
}
8786

88-
private dragStart(event: MouseEvent): boolean {
89-
if (!this.isEnabledInternal) {
87+
#dragStart(event: MouseEvent): boolean {
88+
if (!this.#isEnabled) {
9089
return false;
9190
}
92-
this.startX = event.pageX;
93-
this.startY = event.pageY;
94-
this.sendDragStart(this.startX, this.startY);
91+
this.#startX = event.pageX;
92+
this.#startY = event.pageY;
93+
this.sendDragStart(this.#startX, this.#startY);
9594
return true;
9695
}
9796

9897
sendDragStart(x: number, y: number): void {
9998
this.dispatchEventToListeners(Events.RESIZE_START, {startX: x, currentX: x, startY: y, currentY: y});
10099
}
101100

102-
private drag(event: MouseEvent): boolean {
103-
if (!this.isEnabledInternal) {
104-
this.dragEnd(event);
101+
#drag(event: MouseEvent): boolean {
102+
if (!this.#isEnabled) {
103+
this.#dragEnd(event);
105104
return true; // Cancel drag.
106105
}
107-
this.sendDragMove((this.startX as number), event.pageX, (this.startY as number), event.pageY, event.shiftKey);
106+
this.sendDragMove((this.#startX as number), event.pageX, (this.#startY as number), event.pageY, event.shiftKey);
108107
event.preventDefault();
109108
return false; // Continue drag.
110109
}
@@ -113,10 +112,10 @@ export class ResizerWidget extends Common.ObjectWrapper.ObjectWrapper<EventTypes
113112
this.dispatchEventToListeners(Events.RESIZE_UPDATE_XY, {startX, currentX, startY, currentY, shiftKey});
114113
}
115114

116-
private dragEnd(_event: MouseEvent): void {
115+
#dragEnd(_event: MouseEvent): void {
117116
this.dispatchEventToListeners(Events.RESIZE_END);
118-
delete this.startX;
119-
delete this.startY;
117+
this.#startX = undefined;
118+
this.#startY = undefined;
120119
}
121120
}
122121

@@ -161,35 +160,31 @@ export interface EventTypes {
161160
}
162161

163162
export class SimpleResizerWidget extends ResizerWidget {
164-
private isVerticalInternal: boolean;
165-
constructor() {
166-
super();
167-
this.isVerticalInternal = true;
168-
}
163+
#isVertical = true;
169164

170165
isVertical(): boolean {
171-
return this.isVerticalInternal;
166+
return this.#isVertical;
172167
}
173168

174169
/**
175170
* Vertical widget resizes height (along y-axis).
176171
*/
177172
setVertical(vertical: boolean): void {
178-
this.isVerticalInternal = vertical;
173+
this.#isVertical = vertical;
179174
this.updateElementCursors();
180175
}
181176

182177
override cursor(): string {
183-
return this.isVerticalInternal ? 'ns-resize' : 'ew-resize';
178+
return this.#isVertical ? 'ns-resize' : 'ew-resize';
184179
}
185180

186181
override sendDragStart(x: number, y: number): void {
187-
const position = this.isVerticalInternal ? y : x;
182+
const position = this.#isVertical ? y : x;
188183
this.dispatchEventToListeners(Events.RESIZE_START, {startPosition: position, currentPosition: position});
189184
}
190185

191186
override sendDragMove(startX: number, currentX: number, startY: number, currentY: number, shiftKey: boolean): void {
192-
if (this.isVerticalInternal) {
187+
if (this.#isVertical) {
193188
this.dispatchEventToListeners(
194189
Events.RESIZE_UPDATE_POSITION, {startPosition: startY, currentPosition: currentY, shiftKey});
195190
} else {

0 commit comments

Comments
 (0)