Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/viewParts/viewLines/domReadingContext.ts
5281 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export class DomReadingContext {
7
8
private _didDomLayout: boolean = false;
9
private _clientRectDeltaLeft: number = 0;
10
private _clientRectScale: number = 1;
11
private _clientRectRead: boolean = false;
12
13
public get didDomLayout(): boolean {
14
return this._didDomLayout;
15
}
16
17
private readClientRect(): void {
18
if (!this._clientRectRead) {
19
this._clientRectRead = true;
20
const rect = this._domNode.getBoundingClientRect();
21
this.markDidDomLayout();
22
this._clientRectDeltaLeft = rect.left;
23
const offsetWidth = this._domNode.offsetWidth;
24
this._clientRectScale = offsetWidth > 0 ? rect.width / offsetWidth : 1;
25
}
26
}
27
28
public get clientRectDeltaLeft(): number {
29
if (!this._clientRectRead) {
30
this.readClientRect();
31
}
32
return this._clientRectDeltaLeft;
33
}
34
35
public get clientRectScale(): number {
36
if (!this._clientRectRead) {
37
this.readClientRect();
38
}
39
return this._clientRectScale;
40
}
41
42
constructor(
43
private readonly _domNode: HTMLElement,
44
public readonly endNode: HTMLElement
45
) {
46
}
47
48
public markDidDomLayout(): void {
49
this._didDomLayout = true;
50
}
51
}
52
53