Debian Codegraph @

node/@xterm/xterm/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts

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