Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts
3296 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
import { StandardWheelEvent } from '../../mouseEvent.js';
7
import { AbstractScrollbar, ISimplifiedPointerEvent, ScrollbarHost } from './abstractScrollbar.js';
8
import { ScrollableElementResolvedOptions } from './scrollableElementOptions.js';
9
import { ARROW_IMG_SIZE } from './scrollbarArrow.js';
10
import { ScrollbarState } from './scrollbarState.js';
11
import { Codicon } from '../../../common/codicons.js';
12
import { INewScrollPosition, Scrollable, ScrollbarVisibility, ScrollEvent } from '../../../common/scrollable.js';
13
14
15
16
export class VerticalScrollbar extends AbstractScrollbar {
17
18
constructor(scrollable: Scrollable, options: ScrollableElementResolvedOptions, host: ScrollbarHost) {
19
const scrollDimensions = scrollable.getScrollDimensions();
20
const scrollPosition = scrollable.getCurrentScrollPosition();
21
super({
22
lazyRender: options.lazyRender,
23
host: host,
24
scrollbarState: new ScrollbarState(
25
(options.verticalHasArrows ? options.arrowSize : 0),
26
(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize),
27
// give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom
28
0,
29
scrollDimensions.height,
30
scrollDimensions.scrollHeight,
31
scrollPosition.scrollTop
32
),
33
visibility: options.vertical,
34
extraScrollbarClassName: 'vertical',
35
scrollable: scrollable,
36
scrollByPage: options.scrollByPage
37
});
38
39
if (options.verticalHasArrows) {
40
const arrowDelta = (options.arrowSize - ARROW_IMG_SIZE) / 2;
41
const scrollbarDelta = (options.verticalScrollbarSize - ARROW_IMG_SIZE) / 2;
42
43
this._createArrow({
44
className: 'scra',
45
icon: Codicon.scrollbarButtonUp,
46
top: arrowDelta,
47
left: scrollbarDelta,
48
bottom: undefined,
49
right: undefined,
50
bgWidth: options.verticalScrollbarSize,
51
bgHeight: options.arrowSize,
52
onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, 1)),
53
});
54
55
this._createArrow({
56
className: 'scra',
57
icon: Codicon.scrollbarButtonDown,
58
top: undefined,
59
left: scrollbarDelta,
60
bottom: arrowDelta,
61
right: undefined,
62
bgWidth: options.verticalScrollbarSize,
63
bgHeight: options.arrowSize,
64
onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, -1)),
65
});
66
}
67
68
this._createSlider(0, Math.floor((options.verticalScrollbarSize - options.verticalSliderSize) / 2), options.verticalSliderSize, undefined);
69
}
70
71
protected _updateSlider(sliderSize: number, sliderPosition: number): void {
72
this.slider.setHeight(sliderSize);
73
this.slider.setTop(sliderPosition);
74
}
75
76
protected _renderDomNode(largeSize: number, smallSize: number): void {
77
this.domNode.setWidth(smallSize);
78
this.domNode.setHeight(largeSize);
79
this.domNode.setRight(0);
80
this.domNode.setTop(0);
81
}
82
83
public onDidScroll(e: ScrollEvent): boolean {
84
this._shouldRender = this._onElementScrollSize(e.scrollHeight) || this._shouldRender;
85
this._shouldRender = this._onElementScrollPosition(e.scrollTop) || this._shouldRender;
86
this._shouldRender = this._onElementSize(e.height) || this._shouldRender;
87
return this._shouldRender;
88
}
89
90
protected _pointerDownRelativePosition(offsetX: number, offsetY: number): number {
91
return offsetY;
92
}
93
94
protected _sliderPointerPosition(e: ISimplifiedPointerEvent): number {
95
return e.pageY;
96
}
97
98
protected _sliderOrthogonalPointerPosition(e: ISimplifiedPointerEvent): number {
99
return e.pageX;
100
}
101
102
protected _updateScrollbarSize(size: number): void {
103
this.slider.setWidth(size);
104
}
105
106
public writeScrollPosition(target: INewScrollPosition, scrollPosition: number): void {
107
target.scrollTop = scrollPosition;
108
}
109
110
public updateOptions(options: ScrollableElementResolvedOptions): void {
111
this.updateScrollbarSize(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize);
112
// give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom
113
this._scrollbarState.setOppositeScrollbarSize(0);
114
this._visibilityController.setVisibility(options.vertical);
115
this._scrollByPage = options.scrollByPage;
116
}
117
118
}
119
120