Path: blob/main/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { StandardWheelEvent } from '../../mouseEvent.js';6import { AbstractScrollbar, ISimplifiedPointerEvent, ScrollbarHost } from './abstractScrollbar.js';7import { ScrollableElementResolvedOptions } from './scrollableElementOptions.js';8import { ARROW_IMG_SIZE } from './scrollbarArrow.js';9import { ScrollbarState } from './scrollbarState.js';10import { Codicon } from '../../../common/codicons.js';11import { INewScrollPosition, Scrollable, ScrollbarVisibility, ScrollEvent } from '../../../common/scrollable.js';12131415export class VerticalScrollbar extends AbstractScrollbar {1617constructor(scrollable: Scrollable, options: ScrollableElementResolvedOptions, host: ScrollbarHost) {18const scrollDimensions = scrollable.getScrollDimensions();19const scrollPosition = scrollable.getCurrentScrollPosition();20super({21lazyRender: options.lazyRender,22host: host,23scrollbarState: new ScrollbarState(24(options.verticalHasArrows ? options.arrowSize : 0),25(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize),26// give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom270,28scrollDimensions.height,29scrollDimensions.scrollHeight,30scrollPosition.scrollTop31),32visibility: options.vertical,33extraScrollbarClassName: 'vertical',34scrollable: scrollable,35scrollByPage: options.scrollByPage36});3738if (options.verticalHasArrows) {39const arrowDelta = (options.arrowSize - ARROW_IMG_SIZE) / 2;40const scrollbarDelta = (options.verticalScrollbarSize - ARROW_IMG_SIZE) / 2;4142this._createArrow({43className: 'scra',44icon: Codicon.scrollbarButtonUp,45top: arrowDelta,46left: scrollbarDelta,47bottom: undefined,48right: undefined,49bgWidth: options.verticalScrollbarSize,50bgHeight: options.arrowSize,51onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, 1)),52});5354this._createArrow({55className: 'scra',56icon: Codicon.scrollbarButtonDown,57top: undefined,58left: scrollbarDelta,59bottom: arrowDelta,60right: undefined,61bgWidth: options.verticalScrollbarSize,62bgHeight: options.arrowSize,63onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, -1)),64});65}6667this._createSlider(0, Math.floor((options.verticalScrollbarSize - options.verticalSliderSize) / 2), options.verticalSliderSize, undefined);68}6970protected _updateSlider(sliderSize: number, sliderPosition: number): void {71this.slider.setHeight(sliderSize);72this.slider.setTop(sliderPosition);73}7475protected _renderDomNode(largeSize: number, smallSize: number): void {76this.domNode.setWidth(smallSize);77this.domNode.setHeight(largeSize);78this.domNode.setRight(0);79this.domNode.setTop(0);80}8182public onDidScroll(e: ScrollEvent): boolean {83this._shouldRender = this._onElementScrollSize(e.scrollHeight) || this._shouldRender;84this._shouldRender = this._onElementScrollPosition(e.scrollTop) || this._shouldRender;85this._shouldRender = this._onElementSize(e.height) || this._shouldRender;86return this._shouldRender;87}8889protected _pointerDownRelativePosition(offsetX: number, offsetY: number): number {90return offsetY;91}9293protected _sliderPointerPosition(e: ISimplifiedPointerEvent): number {94return e.pageY;95}9697protected _sliderOrthogonalPointerPosition(e: ISimplifiedPointerEvent): number {98return e.pageX;99}100101protected _updateScrollbarSize(size: number): void {102this.slider.setWidth(size);103}104105public writeScrollPosition(target: INewScrollPosition, scrollPosition: number): void {106target.scrollTop = scrollPosition;107}108109public updateOptions(options: ScrollableElementResolvedOptions): void {110this.updateScrollbarSize(options.vertical === ScrollbarVisibility.Hidden ? 0 : options.verticalScrollbarSize);111// give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom112this._scrollbarState.setOppositeScrollbarSize(0);113this._visibilityController.setVisibility(options.vertical);114this._scrollByPage = options.scrollByPage;115}116117}118119120