ec0af32b557cfa4536887c440112cf62c7893415856684c0ecf987a8401527d4689016735deafd0d77d32bf711dc4fddc821beca9fbfe2ad5cfb5158394a7b 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. import { StandardWheelEvent } from '../../mouseEvent.js';
  6. import { AbstractScrollbar } from './abstractScrollbar.js';
  7. import { ARROW_IMG_SIZE } from './scrollbarArrow.js';
  8. import { ScrollbarState } from './scrollbarState.js';
  9. import { Codicon } from '../../../common/codicons.js';
  10. export class VerticalScrollbar extends AbstractScrollbar {
  11. constructor(scrollable, options, host) {
  12. const scrollDimensions = scrollable.getScrollDimensions();
  13. const scrollPosition = scrollable.getCurrentScrollPosition();
  14. super({
  15. lazyRender: options.lazyRender,
  16. host: host,
  17. scrollbarState: new ScrollbarState((options.verticalHasArrows ? options.arrowSize : 0), (options.vertical === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.verticalScrollbarSize),
  18. // give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom
  19. 0, scrollDimensions.height, scrollDimensions.scrollHeight, scrollPosition.scrollTop),
  20. visibility: options.vertical,
  21. extraScrollbarClassName: 'vertical',
  22. scrollable: scrollable,
  23. scrollByPage: options.scrollByPage
  24. });
  25. if (options.verticalHasArrows) {
  26. const arrowDelta = (options.arrowSize - ARROW_IMG_SIZE) / 2;
  27. const scrollbarDelta = (options.verticalScrollbarSize - ARROW_IMG_SIZE) / 2;
  28. this._createArrow({
  29. className: 'scra',
  30. icon: Codicon.scrollbarButtonUp,
  31. top: arrowDelta,
  32. left: scrollbarDelta,
  33. bottom: undefined,
  34. right: undefined,
  35. bgWidth: options.verticalScrollbarSize,
  36. bgHeight: options.arrowSize,
  37. onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, 1)),
  38. });
  39. this._createArrow({
  40. className: 'scra',
  41. icon: Codicon.scrollbarButtonDown,
  42. top: undefined,
  43. left: scrollbarDelta,
  44. bottom: arrowDelta,
  45. right: undefined,
  46. bgWidth: options.verticalScrollbarSize,
  47. bgHeight: options.arrowSize,
  48. onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 0, -1)),
  49. });
  50. }
  51. this._createSlider(0, Math.floor((options.verticalScrollbarSize - options.verticalSliderSize) / 2), options.verticalSliderSize, undefined);
  52. }
  53. _updateSlider(sliderSize, sliderPosition) {
  54. this.slider.setHeight(sliderSize);
  55. this.slider.setTop(sliderPosition);
  56. }
  57. _renderDomNode(largeSize, smallSize) {
  58. this.domNode.setWidth(smallSize);
  59. this.domNode.setHeight(largeSize);
  60. this.domNode.setRight(0);
  61. this.domNode.setTop(0);
  62. }
  63. onDidScroll(e) {
  64. this._shouldRender = this._onElementScrollSize(e.scrollHeight) || this._shouldRender;
  65. this._shouldRender = this._onElementScrollPosition(e.scrollTop) || this._shouldRender;
  66. this._shouldRender = this._onElementSize(e.height) || this._shouldRender;
  67. return this._shouldRender;
  68. }
  69. _pointerDownRelativePosition(offsetX, offsetY) {
  70. return offsetY;
  71. }
  72. _sliderPointerPosition(e) {
  73. return e.pageY;
  74. }
  75. _sliderOrthogonalPointerPosition(e) {
  76. return e.pageX;
  77. }
  78. _updateScrollbarSize(size) {
  79. this.slider.setWidth(size);
  80. }
  81. writeScrollPosition(target, scrollPosition) {
  82. target.scrollTop = scrollPosition;
  83. }
  84. updateOptions(options) {
  85. this.updateScrollbarSize(options.vertical === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.verticalScrollbarSize);
  86. // give priority to vertical scroll bar over horizontal and let it scroll all the way to the bottom
  87. this._scrollbarState.setOppositeScrollbarSize(0);
  88. this._visibilityController.setVisibility(options.vertical);
  89. this._scrollByPage = options.scrollByPage;
  90. }
  91. }