dd20928645d9f7ed4d9282bceef8610b4d9a73dec9917fef7d83d2795938a8c16a58ae52efec2c57585dc1f9fce34a82d4e3107a6786cb27353ff3a628cbbc 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 HorizontalScrollbar 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.horizontalHasArrows ? options.arrowSize : 0), (options.horizontal === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.horizontalScrollbarSize), (options.vertical === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.verticalScrollbarSize), scrollDimensions.width, scrollDimensions.scrollWidth, scrollPosition.scrollLeft),
  18. visibility: options.horizontal,
  19. extraScrollbarClassName: 'horizontal',
  20. scrollable: scrollable,
  21. scrollByPage: options.scrollByPage
  22. });
  23. if (options.horizontalHasArrows) {
  24. const arrowDelta = (options.arrowSize - ARROW_IMG_SIZE) / 2;
  25. const scrollbarDelta = (options.horizontalScrollbarSize - ARROW_IMG_SIZE) / 2;
  26. this._createArrow({
  27. className: 'scra',
  28. icon: Codicon.scrollbarButtonLeft,
  29. top: scrollbarDelta,
  30. left: arrowDelta,
  31. bottom: undefined,
  32. right: undefined,
  33. bgWidth: options.arrowSize,
  34. bgHeight: options.horizontalScrollbarSize,
  35. onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, 1, 0)),
  36. });
  37. this._createArrow({
  38. className: 'scra',
  39. icon: Codicon.scrollbarButtonRight,
  40. top: scrollbarDelta,
  41. left: undefined,
  42. bottom: undefined,
  43. right: arrowDelta,
  44. bgWidth: options.arrowSize,
  45. bgHeight: options.horizontalScrollbarSize,
  46. onActivate: () => this._host.onMouseWheel(new StandardWheelEvent(null, -1, 0)),
  47. });
  48. }
  49. this._createSlider(Math.floor((options.horizontalScrollbarSize - options.horizontalSliderSize) / 2), 0, undefined, options.horizontalSliderSize);
  50. }
  51. _updateSlider(sliderSize, sliderPosition) {
  52. this.slider.setWidth(sliderSize);
  53. this.slider.setLeft(sliderPosition);
  54. }
  55. _renderDomNode(largeSize, smallSize) {
  56. this.domNode.setWidth(largeSize);
  57. this.domNode.setHeight(smallSize);
  58. this.domNode.setLeft(0);
  59. this.domNode.setBottom(0);
  60. }
  61. onDidScroll(e) {
  62. this._shouldRender = this._onElementScrollSize(e.scrollWidth) || this._shouldRender;
  63. this._shouldRender = this._onElementScrollPosition(e.scrollLeft) || this._shouldRender;
  64. this._shouldRender = this._onElementSize(e.width) || this._shouldRender;
  65. return this._shouldRender;
  66. }
  67. _pointerDownRelativePosition(offsetX, offsetY) {
  68. return offsetX;
  69. }
  70. _sliderPointerPosition(e) {
  71. return e.pageX;
  72. }
  73. _sliderOrthogonalPointerPosition(e) {
  74. return e.pageY;
  75. }
  76. _updateScrollbarSize(size) {
  77. this.slider.setHeight(size);
  78. }
  79. writeScrollPosition(target, scrollPosition) {
  80. target.scrollLeft = scrollPosition;
  81. }
  82. updateOptions(options) {
  83. this.updateScrollbarSize(options.horizontal === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.horizontalScrollbarSize);
  84. this._scrollbarState.setOppositeScrollbarSize(options.vertical === 2 /* ScrollbarVisibility.Hidden */ ? 0 : options.verticalScrollbarSize);
  85. this._visibilityController.setVisibility(options.horizontal);
  86. this._scrollByPage = options.scrollByPage;
  87. }
  88. }