Debian Codegraph @

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