|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 |
| -import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; |
| 6 | +import * as DOM from 'vs/base/browser/dom'; |
| 7 | +import { Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle'; |
7 | 8 | import { ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
8 | 9 | import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
|
9 | 10 | import { ICellExecutionStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
|
10 | 11 |
|
11 |
| -export abstract class CellPart extends Disposable { |
| 12 | +/** |
| 13 | + * A content part is a non-floating element that is rendered inside a cell. |
| 14 | + * The rendering of the content part is synchronous to avoid flickering. |
| 15 | + */ |
| 16 | +export abstract class CellContentPart extends Disposable { |
12 | 17 | protected currentCell: ICellViewModel | undefined;
|
13 | 18 | protected cellDisposables = new DisposableStore();
|
14 | 19 |
|
15 | 20 | constructor() {
|
16 | 21 | super();
|
17 | 22 | }
|
18 | 23 |
|
| 24 | + /** |
| 25 | + * Prepare model for cell part rendering |
| 26 | + * No DOM operations recommended within this operation |
| 27 | + */ |
| 28 | + prepareRenderCell(element: ICellViewModel): void { } |
| 29 | + |
19 | 30 | /**
|
20 | 31 | * Update the DOM for the cell `element`
|
21 | 32 | */
|
@@ -57,49 +68,149 @@ export abstract class CellPart extends Disposable {
|
57 | 68 | updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { }
|
58 | 69 | }
|
59 | 70 |
|
60 |
| -export class CellPartsCollection { |
| 71 | +/** |
| 72 | + * An overlay part renders on top of other components. |
| 73 | + * The rendering of the overlay part might be postponed to the next animation frame to avoid forced reflow. |
| 74 | + */ |
| 75 | +export abstract class CellOverlayPart extends Disposable { |
| 76 | + protected currentCell: ICellViewModel | undefined; |
| 77 | + protected readonly cellDisposables = this._register(new DisposableStore()); |
| 78 | + |
| 79 | + constructor() { |
| 80 | + super(); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Prepare model for cell part rendering |
| 85 | + * No DOM operations recommended within this operation |
| 86 | + */ |
| 87 | + prepareRenderCell(element: ICellViewModel): void { } |
| 88 | + |
| 89 | + /** |
| 90 | + * Update the DOM for the cell `element` |
| 91 | + */ |
| 92 | + renderCell(element: ICellViewModel): void { |
| 93 | + this.currentCell = element; |
| 94 | + this.didRenderCell(element); |
| 95 | + } |
| 96 | + |
| 97 | + protected didRenderCell(element: ICellViewModel): void { } |
| 98 | + |
| 99 | + /** |
| 100 | + * Dispose any disposables generated from `didRenderCell` |
| 101 | + */ |
| 102 | + unrenderCell(element: ICellViewModel): void { |
| 103 | + this.currentCell = undefined; |
| 104 | + this.cellDisposables.clear(); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Update internal DOM (top positions) per cell layout info change |
| 109 | + * Note that a cell part doesn't need to call `DOM.scheduleNextFrame`, |
| 110 | + * the list view will ensure that layout call is invoked in the right frame |
| 111 | + */ |
| 112 | + updateInternalLayoutNow(element: ICellViewModel): void { } |
| 113 | + |
| 114 | + /** |
| 115 | + * Update per cell state change |
| 116 | + */ |
| 117 | + updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void { } |
| 118 | + |
| 119 | + /** |
| 120 | + * Update per execution state change. |
| 121 | + */ |
| 122 | + updateForExecutionState(element: ICellViewModel, e: ICellExecutionStateChangedEvent): void { } |
| 123 | +} |
| 124 | + |
| 125 | +export class CellPartsCollection extends Disposable { |
| 126 | + private _scheduledOverlayRendering = this._register(new MutableDisposable()); |
| 127 | + private _scheduledOverlayUpdateState = this._register(new MutableDisposable()); |
| 128 | + private _scheduledOverlayUpdateExecutionState = this._register(new MutableDisposable()); |
61 | 129 |
|
62 | 130 | constructor(
|
63 |
| - private readonly parts: readonly CellPart[], |
64 |
| - ) { } |
| 131 | + private readonly contentParts: readonly CellContentPart[], |
| 132 | + private readonly overlayParts: readonly CellOverlayPart[] |
| 133 | + ) { |
| 134 | + super(); |
| 135 | + } |
65 | 136 |
|
66 |
| - concat(other: readonly CellPart[]): CellPartsCollection { |
67 |
| - return new CellPartsCollection(this.parts.concat(other)); |
| 137 | + concatContentPart(other: readonly CellContentPart[]): CellPartsCollection { |
| 138 | + return new CellPartsCollection(this.contentParts.concat(other), this.overlayParts); |
68 | 139 | }
|
69 | 140 |
|
70 |
| - renderCell(element: ICellViewModel): void { |
71 |
| - for (const part of this.parts) { |
| 141 | + concatOverlayPart(other: readonly CellOverlayPart[]): CellPartsCollection { |
| 142 | + return new CellPartsCollection(this.contentParts, this.overlayParts.concat(other)); |
| 143 | + } |
| 144 | + |
| 145 | + scheduleRenderCell(element: ICellViewModel): void { |
| 146 | + // prepare model |
| 147 | + for (const part of this.contentParts) { |
| 148 | + part.prepareRenderCell(element); |
| 149 | + } |
| 150 | + |
| 151 | + for (const part of this.overlayParts) { |
| 152 | + part.prepareRenderCell(element); |
| 153 | + } |
| 154 | + |
| 155 | + // render content parts |
| 156 | + for (const part of this.contentParts) { |
72 | 157 | part.renderCell(element);
|
73 | 158 | }
|
| 159 | + |
| 160 | + this._scheduledOverlayRendering.value = DOM.modify(() => { |
| 161 | + for (const part of this.overlayParts) { |
| 162 | + part.renderCell(element); |
| 163 | + } |
| 164 | + }); |
74 | 165 | }
|
75 | 166 |
|
76 | 167 | unrenderCell(element: ICellViewModel): void {
|
77 |
| - for (const part of this.parts) { |
| 168 | + for (const part of this.contentParts) { |
| 169 | + part.unrenderCell(element); |
| 170 | + } |
| 171 | + |
| 172 | + this._scheduledOverlayRendering.value = undefined; |
| 173 | + this._scheduledOverlayUpdateState.value = undefined; |
| 174 | + this._scheduledOverlayUpdateExecutionState.value = undefined; |
| 175 | + |
| 176 | + for (const part of this.overlayParts) { |
78 | 177 | part.unrenderCell(element);
|
79 | 178 | }
|
80 | 179 | }
|
81 | 180 |
|
82 | 181 | updateInternalLayoutNow(viewCell: ICellViewModel) {
|
83 |
| - for (const part of this.parts) { |
| 182 | + for (const part of this.contentParts) { |
84 | 183 | part.updateInternalLayoutNow(viewCell);
|
85 | 184 | }
|
86 | 185 | }
|
87 | 186 |
|
88 | 187 | prepareLayout() {
|
89 |
| - for (const part of this.parts) { |
| 188 | + for (const part of this.contentParts) { |
90 | 189 | part.prepareLayout();
|
91 | 190 | }
|
92 | 191 | }
|
93 | 192 |
|
94 | 193 | updateState(viewCell: ICellViewModel, e: CellViewModelStateChangeEvent) {
|
95 |
| - for (const part of this.parts) { |
| 194 | + for (const part of this.contentParts) { |
96 | 195 | part.updateState(viewCell, e);
|
97 | 196 | }
|
| 197 | + |
| 198 | + this._scheduledOverlayUpdateState.value = DOM.modify(() => { |
| 199 | + for (const part of this.overlayParts) { |
| 200 | + part.updateState(viewCell, e); |
| 201 | + } |
| 202 | + }); |
98 | 203 | }
|
99 | 204 |
|
100 | 205 | updateForExecutionState(viewCell: ICellViewModel, e: ICellExecutionStateChangedEvent) {
|
101 |
| - for (const part of this.parts) { |
| 206 | + for (const part of this.contentParts) { |
102 | 207 | part.updateForExecutionState(viewCell, e);
|
103 | 208 | }
|
| 209 | + |
| 210 | + this._scheduledOverlayUpdateExecutionState.value = DOM.modify(() => { |
| 211 | + for (const part of this.overlayParts) { |
| 212 | + part.updateForExecutionState(viewCell, e); |
| 213 | + } |
| 214 | + }); |
104 | 215 | }
|
105 | 216 | }
|
0 commit comments